607bb27ceef4d3742720e92b509047c3439cbf59
[ric-app/kpimon.git] / asn1c_defs / all-defs / constr_TYPE.h
1 /*\r
2  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
3  * Redistribution and modifications are permitted subject to BSD license.\r
4  */\r
5 /*\r
6  * This file contains the declaration structure called "ASN.1 Type Definition",\r
7  * which holds all information necessary for encoding and decoding routines.\r
8  * This structure even contains pointer to these encoding and decoding routines\r
9  * for each defined ASN.1 type.\r
10  */\r
11 #ifndef _CONSTR_TYPE_H_\r
12 #define _CONSTR_TYPE_H_\r
13 \r
14 #include <ber_tlv_length.h>\r
15 #include <ber_tlv_tag.h>\r
16 \r
17 #ifdef __cplusplus\r
18 extern "C" {\r
19 #endif\r
20 \r
21 struct asn_TYPE_descriptor_s;   /* Forward declaration */\r
22 struct asn_TYPE_member_s;       /* Forward declaration */\r
23 \r
24 /*\r
25  * This type provides the context information for various ASN.1 routines,\r
26  * primarily ones doing decoding. A member _asn_ctx of this type must be\r
27  * included into certain target language's structures, such as compound types.\r
28  */\r
29 typedef struct asn_struct_ctx_s {\r
30         short phase;            /* Decoding phase */\r
31         short step;             /* Elementary step of a phase */\r
32         int context;            /* Other context information */\r
33         void *ptr;              /* Decoder-specific stuff (stack elements) */\r
34         ber_tlv_len_t left;     /* Number of bytes left, -1 for indefinite */\r
35 } asn_struct_ctx_t;\r
36 \r
37 #include <ber_decoder.h>        /* Basic Encoding Rules decoder */\r
38 #include <der_encoder.h>        /* Distinguished Encoding Rules encoder */\r
39 #include <xer_decoder.h>        /* Decoder of XER (XML, text) */\r
40 #include <xer_encoder.h>        /* Encoder into XER (XML, text) */\r
41 #include <per_decoder.h>        /* Packet Encoding Rules decoder */\r
42 #include <per_encoder.h>        /* Packet Encoding Rules encoder */\r
43 #include <constraints.h>        /* Subtype constraints support */\r
44 #include <asn_random_fill.h>    /* Random structures support */\r
45 \r
46 #ifdef  ASN_DISABLE_OER_SUPPORT\r
47 typedef void (oer_type_decoder_f)(void);\r
48 typedef void (oer_type_encoder_f)(void);\r
49 typedef void asn_oer_constraints_t;\r
50 #else\r
51 #include <oer_decoder.h>        /* Octet Encoding Rules encoder */\r
52 #include <oer_encoder.h>        /* Octet Encoding Rules encoder */\r
53 #endif\r
54 \r
55 /*\r
56  * Free the structure according to its specification.\r
57  * Use one of ASN_STRUCT_{FREE,RESET,CONTENTS_ONLY} macros instead.\r
58  * Do not use directly.\r
59  */\r
60 enum asn_struct_free_method {\r
61     ASFM_FREE_EVERYTHING,   /* free(struct_ptr) and underlying members */\r
62     ASFM_FREE_UNDERLYING,   /* free underlying members */\r
63     ASFM_FREE_UNDERLYING_AND_RESET   /* FREE_UNDERLYING + memset(0) */\r
64 };\r
65 typedef void (asn_struct_free_f)(\r
66                 const struct asn_TYPE_descriptor_s *type_descriptor,\r
67                 void *struct_ptr, enum asn_struct_free_method);\r
68 \r
69 /*\r
70  * Free the structure including freeing the memory pointed to by ptr itself.\r
71  */\r
72 #define ASN_STRUCT_FREE(asn_DEF, ptr) \\r
73     (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_EVERYTHING)\r
74 \r
75 /*\r
76  * Free the memory used by the members of the structure without freeing the\r
77  * the structure pointer itself.\r
78  * ZERO-OUT the structure to the safe clean state.\r
79  * (Retaining the pointer may be useful in case the structure is allocated\r
80  *  statically or arranged on the stack, yet its elements are dynamic.)\r
81  */\r
82 #define ASN_STRUCT_RESET(asn_DEF, ptr) \\r
83     (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_UNDERLYING_AND_RESET)\r
84 \r
85 /*\r
86  * Free memory used by the members of the structure without freeing\r
87  * the structure pointer itself.\r
88  * (Retaining the pointer may be useful in case the structure is allocated\r
89  *  statically or arranged on the stack, yet its elements are dynamic.)\r
90  * AVOID using it in the application code;\r
91  * Use a safer ASN_STRUCT_RESET() instead.\r
92  */\r
93 #define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \\r
94     (asn_DEF).op->free_struct(&(asn_DEF), (ptr), ASFM_FREE_UNDERLYING)\r
95 \r
96 /*\r
97  * Print the structure according to its specification.\r
98  */\r
99 typedef int(asn_struct_print_f)(\r
100     const struct asn_TYPE_descriptor_s *type_descriptor,\r
101     const void *struct_ptr,\r
102     int level, /* Indentation level */\r
103     asn_app_consume_bytes_f *callback, void *app_key);\r
104 \r
105 /*\r
106  * Compare two structs between each other.\r
107  * Returns <0 if struct_A is "smaller" than struct_B, >0 if "greater",\r
108  * and =0 if "equal to", for some type-specific, stable definition of\r
109  * "smaller", "greater" and "equal to".\r
110  */\r
111 typedef int (asn_struct_compare_f)(\r
112                 const struct asn_TYPE_descriptor_s *type_descriptor,\r
113                 const void *struct_A,\r
114                 const void *struct_B);\r
115 \r
116 /*\r
117  * Return the outmost tag of the type.\r
118  * If the type is untagged CHOICE, the dynamic operation is performed.\r
119  * NOTE: This function pointer type is only useful internally.\r
120  * Do not use it in your application.\r
121  */\r
122 typedef ber_tlv_tag_t (asn_outmost_tag_f)(\r
123                 const struct asn_TYPE_descriptor_s *type_descriptor,\r
124                 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);\r
125 /* The instance of the above function type; used internally. */\r
126 asn_outmost_tag_f asn_TYPE_outmost_tag;\r
127 \r
128 /*\r
129  * Fetch the desired type of the Open Type based on the\r
130  * Information Object Set driven constraints.\r
131  */\r
132 typedef struct asn_type_selector_result_s {\r
133     const struct asn_TYPE_descriptor_s *type_descriptor; /* Type encoded. */\r
134     unsigned presence_index; /* Associated choice variant. */\r
135 } asn_type_selector_result_t;\r
136 typedef asn_type_selector_result_t(asn_type_selector_f)(\r
137     const struct asn_TYPE_descriptor_s *parent_type_descriptor,\r
138     const void *parent_structure_ptr);\r
139 \r
140 /*\r
141  * Generalized functions for dealing with the speciic type.\r
142  * May be directly invoked by applications.\r
143  */\r
144 typedef struct asn_TYPE_operation_s {\r
145     asn_struct_free_f *free_struct;     /* Free the structure */\r
146     asn_struct_print_f *print_struct;   /* Human readable output */\r
147     asn_struct_compare_f *compare_struct; /* Compare two structures */\r
148     ber_type_decoder_f *ber_decoder;      /* Generic BER decoder */\r
149     der_type_encoder_f *der_encoder;      /* Canonical DER encoder */\r
150     xer_type_decoder_f *xer_decoder;      /* Generic XER decoder */\r
151     xer_type_encoder_f *xer_encoder;      /* [Canonical] XER encoder */\r
152     oer_type_decoder_f *oer_decoder;      /* Generic OER decoder */\r
153     oer_type_encoder_f *oer_encoder;      /* Canonical OER encoder */\r
154     per_type_decoder_f *uper_decoder;     /* Unaligned PER decoder */\r
155     per_type_encoder_f *uper_encoder;     /* Unaligned PER encoder */\r
156     per_type_decoder_f *aper_decoder;     /* Aligned PER decoder */\r
157     per_type_encoder_f *aper_encoder;     /* Aligned PER encoder */\r
158     asn_random_fill_f *random_fill;       /* Initialize with a random value */\r
159     asn_outmost_tag_f *outmost_tag;       /* <optional, internal> */\r
160 } asn_TYPE_operation_t;\r
161 \r
162 /*\r
163  * A constraints tuple specifying both the OER and PER constraints.\r
164  */\r
165 typedef struct asn_encoding_constraints_s {\r
166     const struct asn_oer_constraints_s *oer_constraints;\r
167     const struct asn_per_constraints_s *per_constraints;\r
168     asn_constr_check_f *general_constraints;\r
169 } asn_encoding_constraints_t;\r
170 \r
171 /*\r
172  * The definitive description of the destination language's structure.\r
173  */\r
174 typedef struct asn_TYPE_descriptor_s {\r
175     const char *name;       /* A name of the ASN.1 type. "" in some cases. */\r
176     const char *xml_tag;    /* Name used in XML tag */\r
177 \r
178     /*\r
179      * Generalized functions for dealing with the specific type.\r
180      * May be directly invoked by applications.\r
181      */\r
182     asn_TYPE_operation_t *op;\r
183 \r
184     /***********************************************************************\r
185      * Internally useful members. Not to be used by applications directly. *\r
186      **********************************************************************/\r
187 \r
188     /*\r
189      * Tags that are expected to occur.\r
190      */\r
191     const ber_tlv_tag_t *tags;      /* Effective tags sequence for this type */\r
192     unsigned tags_count;            /* Number of tags which are expected */\r
193     const ber_tlv_tag_t *all_tags;  /* Every tag for BER/containment */\r
194     unsigned all_tags_count;        /* Number of tags */\r
195 \r
196     /* OER, PER, and general constraints */\r
197     asn_encoding_constraints_t encoding_constraints;\r
198 \r
199     /*\r
200      * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).\r
201      */\r
202     struct asn_TYPE_member_s *elements;\r
203     unsigned elements_count;\r
204 \r
205     /*\r
206      * Additional information describing the type, used by appropriate\r
207      * functions above.\r
208      */\r
209     const void *specifics;\r
210 } asn_TYPE_descriptor_t;\r
211 \r
212 /*\r
213  * This type describes an element of the constructed type,\r
214  * i.e. SEQUENCE, SET, CHOICE, etc.\r
215  */\r
216   enum asn_TYPE_flags_e {\r
217     ATF_NOFLAGS,\r
218     ATF_POINTER = 0x01,   /* Represented by the pointer */\r
219     ATF_OPEN_TYPE = 0x02, /* Open Type */\r
220     ATF_ANY_TYPE = 0x04   /* ANY type (deprecated!) */\r
221   };\r
222 typedef struct asn_TYPE_member_s {\r
223     enum asn_TYPE_flags_e flags; /* Element's presentation flags */\r
224     unsigned optional;      /* Following optional members, including current */\r
225     unsigned memb_offset;   /* Offset of the element */\r
226     ber_tlv_tag_t tag;      /* Outmost (most immediate) tag */\r
227     int tag_mode;           /* IMPLICIT/no/EXPLICIT tag at current level */\r
228     asn_TYPE_descriptor_t *type;            /* Member type descriptor */\r
229     asn_type_selector_f *type_selector;     /* IoS runtime type selector */\r
230     asn_encoding_constraints_t encoding_constraints;\r
231     int (*default_value_cmp)(const void *sptr); /* Compare DEFAULT <value> */\r
232     int (*default_value_set)(void **sptr);      /* Set DEFAULT <value> */\r
233     const char *name; /* ASN.1 identifier of the element */\r
234 } asn_TYPE_member_t;\r
235 \r
236 /*\r
237  * BER tag to element number mapping.\r
238  */\r
239 typedef struct asn_TYPE_tag2member_s {\r
240     ber_tlv_tag_t el_tag;   /* Outmost tag of the member */\r
241     unsigned el_no;         /* Index of the associated member, base 0 */\r
242     int toff_first;         /* First occurence of the el_tag, relative */\r
243     int toff_last;          /* Last occurence of the el_tag, relative */\r
244 } asn_TYPE_tag2member_t;\r
245 \r
246 /*\r
247  * This function prints out the contents of the target language's structure\r
248  * (struct_ptr) into the file pointer (stream) in human readable form.\r
249  * RETURN VALUES:\r
250  *       0: The structure is printed.\r
251  *      -1: Problem dumping the structure.\r
252  * (See also xer_fprint() in xer_encoder.h)\r
253  */\r
254 int asn_fprint(FILE *stream, /* Destination stream descriptor */\r
255                const asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */\r
256                const void *struct_ptr);         /* Structure to be printed */\r
257 \r
258 #ifdef __cplusplus\r
259 }\r
260 #endif\r
261 \r
262 #endif  /* _CONSTR_TYPE_H_ */\r