2 * A collection of data members of unspecified types.
4 #ifndef ASN1_PARSER_EXPR_H
5 #define ASN1_PARSER_EXPR_H
8 * Meta type of the ASN expression.
10 typedef enum asn1p_expr_meta {
12 AMT_TYPE, /* Type1 ::= INTEGER */
13 AMT_TYPEREF, /* Type2 ::= Type1 */
14 AMT_VALUE, /* value1 Type1 ::= 1 */
15 AMT_VALUESET, /* ValueSet Type1 ::= { value1 } */
16 AMT_OBJECT, /* object CLASS ::= {...} */
17 AMT_OBJECTCLASS, /* FUNCTION ::= CLASS {...} */
18 AMT_OBJECTFIELD, /* ... */
23 * ASN type of the expression.
25 typedef enum asn1p_expr_type {
29 A1TC_INVALID, /* Invalid type */
30 A1TC_REFERENCE, /* Reference to the type defined elsewhere */
31 A1TC_EXPORTVAR, /* We're exporting this definition */
32 A1TC_UNIVERVAL, /* A value of an ENUMERATED, INTEGER or BS */
33 A1TC_BITVECTOR, /* A plain collection of bits */
34 A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
35 A1TC_EXTENSIBLE, /* An extension marker "..." */
36 A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
37 A1TC_VALUESET, /* Value set definition */
38 A1TC_CLASSDEF, /* Information Object Class */
39 A1TC_INSTANCE, /* Instance of Object Class */
42 * ASN.1 Class field types
44 #define ASN_CLASSFIELD_MASK 0x10 /* Every class field type */
45 A1TC_CLASSFIELD_TFS = ASN_CLASSFIELD_MASK, /* TypeFieldSpec */
46 A1TC_CLASSFIELD_FTVFS, /* FixedTypeValueFieldSpec */
47 A1TC_CLASSFIELD_VTVFS, /* VariableTypeValueFieldSpec */
48 A1TC_CLASSFIELD_FTVSFS, /* FixedTypeValueSetFieldSpec */
49 A1TC_CLASSFIELD_VTVSFS, /* VariableTypeValueSetFieldSpec */
50 A1TC_CLASSFIELD_OFS, /* ObjectFieldSpec */
51 A1TC_CLASSFIELD_OSFS, /* ObjectSetFieldSpec */
54 * ASN.1 Constructed types
56 #define ASN_CONSTR_MASK 0x20 /* Every constructed type */
57 ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */
58 ASN_CONSTR_CHOICE, /* CHOICE */
59 ASN_CONSTR_SET, /* SET */
60 ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */
61 ASN_CONSTR_SET_OF, /* SET OF */
67 #define ASN_BASIC_MASK 0x40 /* Every basic type */
68 ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */
75 ASN_BASIC_OCTET_STRING,
76 ASN_BASIC_OBJECT_IDENTIFIER,
77 ASN_BASIC_RELATIVE_OID,
79 ASN_BASIC_EMBEDDED_PDV,
80 ASN_BASIC_CHARACTER_STRING,
82 ASN_BASIC_GeneralizedTime,
87 #define ASN_STRING_KM_MASK 0x100 /* Known multiplier */
88 #define ASN_STRING_NKM_MASK 0x200 /* Not a known multiplier */
89 #define ASN_STRING_MASK 0x300 /* Every restricted string type */
90 ASN_STRING_IA5String = ASN_STRING_KM_MASK,
91 ASN_STRING_PrintableString,
92 ASN_STRING_VisibleString,
93 ASN_STRING_ISO646String, /* aka VisibleString */
94 ASN_STRING_NumericString,
95 ASN_STRING_UniversalString,
97 ASN_STRING_UTF8String = ASN_STRING_NKM_MASK,
98 ASN_STRING_GeneralString,
99 ASN_STRING_GraphicString,
100 ASN_STRING_TeletexString,
101 ASN_STRING_T61String,
102 ASN_STRING_VideotexString,
103 ASN_STRING_ObjectDescriptor,
107 #include "asn1p_expr_str.h"
108 #include "asn1p_expr2uclass.h"
110 struct asn1p_module_s; /* Forward declaration */
111 struct asn1p_ioc_table_s; /* Forward declaration */
114 * A named collection of types.
116 typedef struct asn1p_expr_s {
119 * Human readable name.
124 * Meta type of the expression (type, value, value set, etc).
126 asn1p_expr_meta_e meta_type;
129 * ASN type of the expression.
131 asn1p_expr_type_e expr_type;
134 * Referenced type, defined elsewhere.
135 * (If expr_type == A1TC_REFERENCE)
137 asn1p_ref_t *reference;
140 * Constraints for the type.
142 asn1p_constraint_t *constraints;
145 * This field is holding the transformed constraints, with all the
146 * parent constraints taken into account.
148 asn1p_constraint_t *combined_constraints;
151 * Left hand side parameters for parametrized type declaration
152 * Type{Param1, Param2} ::= SEQUENCE { a Param1, b Param2 }
154 asn1p_paramlist_t *lhs_params;
156 * Right hand type specialization.
157 * Type2 ::= Type{Param1}
159 struct asn1p_expr_s *rhs_pspecs; /* ->members */
161 * If lhs_params is defined, this structure represents all possible
162 * specializations of the parent expression.
165 struct asn1p_pspec_s {
166 struct asn1p_expr_s *rhs_pspecs;
167 struct asn1p_expr_s *my_clone;
169 int pspecs_count; /* Number of specializations */
171 int spec_index; /* -1, or 0-based specialization index in the parent */
174 * The actual value (DefinedValue or inlined value).
176 asn1p_value_t *value;
179 * The WITH SYNTAX clause.
181 asn1p_wsyntx_t *with_syntax;
183 /* Information Object Class table, specific for a class or object set */
184 struct asn1p_ioc_table_s *ioc_table;
189 struct asn1p_type_tag_s {
202 asn1c_integer_t tag_value;
205 struct asn1p_expr_marker_s {
206 enum asn1p_expr_marker_e {
208 EM_INDIRECT = 0x01, /* 00001 Represent as pointer */
209 EM_OMITABLE = 0x02, /* 00010 May be absent in encoding */
210 EM_OPTIONAL = 0x07, /* 00111 Optional member */
211 EM_DEFAULT = 0x0F, /* 01111 default_value */
212 EM_UNRECURSE = 0x10, /* 10000 Use safe naming */
214 asn1p_value_t *default_value; /* For EM_DEFAULT case */
216 int unique; /* UNIQUE */
217 int ref_cnt; /* reference count */
220 * Whether automatic tagging may be applied for subtypes.
225 * Members of the constructed type.
227 TQ_HEAD(struct asn1p_expr_s) members;
230 * Next expression in the list.
232 TQ_ENTRY(struct asn1p_expr_s) next;
234 struct asn1p_expr_s *parent_expr; /* optional */
236 struct asn1p_module_s *module; /* Defined in module */
239 * Line number where this structure is defined in the original
245 * Marks are used for various purposes.
246 * Here are some predefined ones.
250 TM_RECURSION = (1<<0), /* Used to break recursion */
251 TM_BROKEN = (1<<1), /* A warning was already issued */
252 TM_PERFROMCT = (1<<2), /* PER FROM() constraint tables emitted */
253 TM_NAMECLASH = (1<<3), /* Name clash found, need to add module name to resolve */
254 TM_NAMEGIVEN = (1<<4) /* The expression has already yielded a name */
258 * Some tags used by the compiler.
260 int _anonymous_type; /* This type is unnamed */
261 int _type_unique_index; /* A per top-level-type unique index */
262 int _type_referenced; /* This type is referenced from another place */
265 * Opaque data may be attached to this structure,
266 * probably by compiler.
269 void (*data_free)(void *data);
274 * Constructor and destructor.
276 asn1p_expr_t *asn1p_expr_new(int _lineno, struct asn1p_module_s *);
277 asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
278 asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *,
279 asn1p_expr_t *(*resolver)(asn1p_expr_t *to_resolve, void *resolver_arg),
281 void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
282 void asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what);
283 asn1p_expr_t *asn1p_lookup_child(asn1p_expr_t *tc, const char *name);
284 int asn1p_expr_compare(const asn1p_expr_t *, const asn1p_expr_t *);
285 void asn1p_expr_free(asn1p_expr_t *expr);
286 void asn1p_expr_set_source(asn1p_expr_t *, asn1p_module_t *, int lineno);
288 asn1p_paramlist_t *asn1p_get_namespace(asn1p_expr_t *);
290 #define TAG2STRING_BUFFER_SIZE 64 /* buf should be at least this big */
291 const char *asn1p_tag2string(const struct asn1p_type_tag_s *tag, char *opt_buf);
293 #define MODULE_NAME_OF(expr) \
295 (!(expr->_mark & TM_NAMECLASH) ? "" : \
296 (!expr->module ? "" : expr->module->ModuleName))), \
298 (!(expr->_mark & TM_NAMECLASH) ? "" : "_"))
300 #endif /* ASN1_PARSER_EXPR_H */