blob: 67f9c55ec20d0fd325f5ba7438190fa23ebf59c2 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _CONSTR_TYPE_H_
6#define _CONSTR_TYPE_H_
7
8#include <asn_types.h> /* System-dependent types */
9#include <ber_tlv_length.h>
10#include <ber_tlv_tag.h>
11#include <ber_decoder.h>
12#include <der_encoder.h>
13#include <constraints.h>
14
15struct asn1_TYPE_descriptor_s; /* Forward declaration */
vlme413c122004-08-20 13:23:42 +000016struct asn1_TYPE_member_s; /* Forward declaration */
vlmfa67ddc2004-06-03 03:38:44 +000017
18/*
19 * Free the structure according to its specification.
20 * If (free_contents_only) is set, the wrapper structure itself (struct_ptr)
21 * will not be freed. (It may be useful in case the structure is allocated
22 * statically or arranged on the stack, yet its elements are allocated
23 * dynamically.)
24 */
25typedef void (asn_struct_free_f)(
26 struct asn1_TYPE_descriptor_s *type_descriptor,
27 void *struct_ptr, int free_contents_only);
28
29/*
30 * Print the structure according to its specification.
31 */
32typedef int (asn_struct_print_f)(
33 struct asn1_TYPE_descriptor_s *type_descriptor,
34 const void *struct_ptr,
35 int level, /* Indentation level */
36 asn_app_consume_bytes_f *callback, void *app_key);
37
38/*
39 * Return the outmost tag of the type.
40 * If the type is untagged CHOICE, the dynamic operation is performed.
41 * NOTE: This function pointer type is only useful internally.
42 * Do not use it in your application.
43 */
44typedef ber_tlv_tag_t (asn_outmost_tag_f)(
45 struct asn1_TYPE_descriptor_s *type_descriptor,
46 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);
vlme413c122004-08-20 13:23:42 +000047/* The instance of the above function type; used internally. */
vlmfa67ddc2004-06-03 03:38:44 +000048asn_outmost_tag_f asn1_TYPE_outmost_tag;
49
50
51/*
52 * The definitive description of the destination language's structure.
53 */
54typedef struct asn1_TYPE_descriptor_s {
55 char *name; /* A name of the ASN.1 type */
56
57 /*
58 * Generalized functions for dealing with the specific type.
59 * May be directly invoked by applications.
60 */
61 asn_constr_check_f *check_constraints; /* Constraints validator */
62 ber_type_decoder_f *ber_decoder; /* Free-form BER decoder */
63 der_type_encoder_f *der_encoder; /* Canonical DER encoder */
64 asn_struct_print_f *print_struct; /* Human readable output */
65 asn_struct_free_f *free_struct; /* Free the structure */
66
67 /*
68 * Functions used internally. Should not be used by applications.
69 */
70 asn_outmost_tag_f *outmost_tag; /* <optional, internal> */
71
72 /*
73 * Tags that are expected, with some of their vital properties.
74 */
75 ber_tlv_tag_t *tags; /* At least one tag must be specified */
76 int tags_count; /* Number of tags which are expected */
77 int tags_impl_skip; /* Tags to skip in implicit mode */
78 int last_tag_form; /* Acceptable form of the tag (prim, constr) */
79
80 /*
vlme413c122004-08-20 13:23:42 +000081 * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
82 */
83 struct asn1_TYPE_member_s *elements;
84 int elements_count;
85
86 /*
vlmfa67ddc2004-06-03 03:38:44 +000087 * Additional information describing the type, used by appropriate
88 * functions above.
89 */
90 void *specifics;
91} asn1_TYPE_descriptor_t;
92
93/*
vlme413c122004-08-20 13:23:42 +000094 * An element of the constructed type, i.e. SEQUENCE, SET, CHOICE.
95 */
96typedef struct asn1_TYPE_member_s {
97 int optional; /* Whether the element is optional */
98 int memb_offset; /* Offset of the element */
99 ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
100 int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
101 asn1_TYPE_descriptor_t *type; /* Member type descriptor */
102 asn_constr_check_f *memb_constraints; /* Constraints validator */
103 char *name; /* ASN.1 identifier of the element */
104} asn1_TYPE_member_t;
105
106/*
vlm31473082004-06-06 07:20:02 +0000107 * BER tag to element number mapping.
108 */
109typedef struct asn1_TYPE_tag2member_s {
110 ber_tlv_tag_t el_tag; /* Outmost tag of the member */
111 int el_no; /* Index of the associated member, base 0 */
vlmc8aeab42004-06-14 13:09:45 +0000112 int toff_first; /* First occurence of the el_tag, relative */
113 int toff_last; /* Last occurence of the el_tag, relatvie */
vlm31473082004-06-06 07:20:02 +0000114} asn1_TYPE_tag2member_t;
115
116
vlm31473082004-06-06 07:20:02 +0000117/*
vlmfa67ddc2004-06-03 03:38:44 +0000118 * This function is a wrapper around (td)->print_struct, which prints out
119 * the contents of the target language's structure (struct_ptr) into the
120 * file pointer (stream) in human readable form.
121 * RETURN VALUES:
122 * 0: The structure is printed.
123 * -1: Problem dumping the structure.
124 */
125int asn_fprint(FILE *stream, /* Destination stream descriptor */
126 asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
127 const void *struct_ptr); /* Structure to be printed */
128
129#endif /* _CONSTR_TYPE_H_ */