blob: 6bcaa589aa49c2ec8ca3e28a76f5a6ca35256baf [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*
2 * A collection of data members of unspecified types.
3 */
4#ifndef ASN1_PARSER_EXPR_H
5#define ASN1_PARSER_EXPR_H
6
7/*
8 * Meta type of the ASN expression.
9 */
10typedef enum asn1p_expr_meta {
11 AMT_INVALID,
12 AMT_TYPE, /* Type1 ::= INTEGER */
13 AMT_TYPEREF, /* Type2 ::= Type1 */
14 AMT_PARAMTYPE, /* Type3{Parameter} ::= SET { ... } */
15 AMT_VALUE, /* value1 Type1 ::= 1 */
16 AMT_VALUESET, /* ValueSet Type1 ::= { value1 } */
Lev Walkin9c2285a2006-03-09 08:49:26 +000017 AMT_OBJECT, /* object CLASS ::= {...} */
18 AMT_OBJECTCLASS, /* FUNCTION ::= CLASS {...} */
Lev Walkinf15320b2004-06-03 03:38:44 +000019 AMT_OBJECTFIELD, /* ... */
20 AMT_EXPR_META_MAX
21} asn1p_expr_meta_e;
22
23/*
24 * ASN type of the expression.
25 */
26typedef enum asn1p_expr_type {
27 /*
28 * Internal types.
29 */
30 A1TC_INVALID, /* Invalid type */
31 A1TC_REFERENCE, /* Reference to the type defined elsewhere */
32 A1TC_EXPORTVAR, /* We're exporting this definition */
33 A1TC_UNIVERVAL, /* A value of an ENUMERATED, INTEGER or BS */
Lev Walkinf15320b2004-06-03 03:38:44 +000034 A1TC_BITVECTOR, /* A plain collection of bits */
35 A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
36 A1TC_EXTENSIBLE, /* An extension marker "..." */
Lev Walkin070a52d2004-08-22 03:19:54 +000037 A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
Lev Walkinf15320b2004-06-03 03:38:44 +000038 A1TC_PARAMETRIZED, /* A parametrized type declaration */
39 A1TC_VALUESET, /* Value set definition */
40 A1TC_CLASSDEF, /* Information Object Class */
Lev Walkinf15320b2004-06-03 03:38:44 +000041 A1TC_INSTANCE, /* Instance of Object Class */
Lev Walkin9c2285a2006-03-09 08:49:26 +000042
43 /*
44 * ASN.1 Class field types
45 */
46#define ASN_CLASSFIELD_MASK 0x10 /* Every class field type */
47 A1TC_CLASSFIELD_TFS = ASN_CLASSFIELD_MASK, /* TypeFieldSpec */
48 A1TC_CLASSFIELD_FTVFS, /* FixedTypeValueFieldSpec */
49 A1TC_CLASSFIELD_VTVFS, /* VariableTypeValueFieldSpec */
50 A1TC_CLASSFIELD_FTVSFS, /* FixedTypeValueSetFieldSpec */
51 A1TC_CLASSFIELD_VTVSFS, /* VariableTypeValueSetFieldSpec */
52 A1TC_CLASSFIELD_OFS, /* ObjectFieldSpec */
53 A1TC_CLASSFIELD_OSFS, /* ObjectSetFieldSpec */
Lev Walkin070a52d2004-08-22 03:19:54 +000054
Lev Walkinf15320b2004-06-03 03:38:44 +000055 /*
56 * ASN.1 Constructed types
57 */
Lev Walkin9c2285a2006-03-09 08:49:26 +000058#define ASN_CONSTR_MASK 0x20 /* Every constructed type */
Lev Walkinf15320b2004-06-03 03:38:44 +000059 ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */
60 ASN_CONSTR_CHOICE, /* CHOICE */
61 ASN_CONSTR_SET, /* SET */
62 ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */
63 ASN_CONSTR_SET_OF, /* SET OF */
Lev Walkine422e682004-08-25 01:58:59 +000064
Lev Walkinf15320b2004-06-03 03:38:44 +000065 /*
66 * ASN.1 Basic types
67 */
Lev Walkin9c2285a2006-03-09 08:49:26 +000068#define ASN_BASIC_MASK 0x40 /* Every basic type */
Lev Walkin609ccbb2004-09-04 04:49:21 +000069 ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */
70 ASN_BASIC_BOOLEAN,
Lev Walkinf15320b2004-06-03 03:38:44 +000071 ASN_BASIC_NULL,
72 ASN_BASIC_INTEGER,
73 ASN_BASIC_REAL,
74 ASN_BASIC_ENUMERATED,
75 ASN_BASIC_BIT_STRING,
76 ASN_BASIC_OCTET_STRING,
77 ASN_BASIC_OBJECT_IDENTIFIER,
78 ASN_BASIC_RELATIVE_OID,
79 ASN_BASIC_EXTERNAL,
80 ASN_BASIC_EMBEDDED_PDV,
81 ASN_BASIC_CHARACTER_STRING,
82 ASN_BASIC_UTCTime,
83 ASN_BASIC_GeneralizedTime,
Lev Walkin070a52d2004-08-22 03:19:54 +000084
Lev Walkinf15320b2004-06-03 03:38:44 +000085 /*
86 * ASN.1 String types
87 */
Lev Walkin9c2285a2006-03-09 08:49:26 +000088#define ASN_STRING_KM_MASK 0x100 /* Known multiplier */
89#define ASN_STRING_NKM_MASK 0x200 /* Not a known multiplier */
90#define ASN_STRING_MASK 0x300 /* Every restricted string type */
Lev Walkine422e682004-08-25 01:58:59 +000091 ASN_STRING_IA5String = ASN_STRING_KM_MASK,
92 ASN_STRING_PrintableString,
93 ASN_STRING_VisibleString,
94 ASN_STRING_ISO646String, /* aka VisibleString */
95 ASN_STRING_NumericString,
96 ASN_STRING_UniversalString,
97 ASN_STRING_BMPString,
98 ASN_STRING_UTF8String = ASN_STRING_NKM_MASK,
Lev Walkinf15320b2004-06-03 03:38:44 +000099 ASN_STRING_GeneralString,
100 ASN_STRING_GraphicString,
Lev Walkinf15320b2004-06-03 03:38:44 +0000101 ASN_STRING_TeletexString,
102 ASN_STRING_T61String,
Lev Walkinf15320b2004-06-03 03:38:44 +0000103 ASN_STRING_VideotexString,
Lev Walkinf15320b2004-06-03 03:38:44 +0000104 ASN_STRING_ObjectDescriptor,
105 ASN_EXPR_TYPE_MAX
106} asn1p_expr_type_e;
107
108#include "asn1p_expr_str.h"
109#include "asn1p_expr2uclass.h"
110
Lev Walkin070a52d2004-08-22 03:19:54 +0000111struct asn1p_module_s; /* Forward declaration */
112
Lev Walkinf15320b2004-06-03 03:38:44 +0000113/*
114 * A named collection of types.
115 */
116typedef struct asn1p_expr_s {
117
118 /*
119 * Human readable name.
120 */
121 char *Identifier;
122
123 /*
124 * Meta type of the expression (type, value, value set, etc).
125 */
126 asn1p_expr_meta_e meta_type;
127
128 /*
129 * ASN type of the expression.
130 */
131 asn1p_expr_type_e expr_type;
132
133 /*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000134 * Referenced type, defined elsewhere.
Lev Walkinf15320b2004-06-03 03:38:44 +0000135 * (If expr_type == A1TC_REFERENCE)
136 */
137 asn1p_ref_t *reference;
138
139 /*
140 * Constraints for the type.
141 */
142 asn1p_constraint_t *constraints;
143
144 /*
Lev Walkinf59d0752004-08-18 04:59:12 +0000145 * This field is holding the transformed constraints, with all the
146 * parent constraints taken into account.
147 */
148 asn1p_constraint_t *combined_constraints;
149
150 /*
Lev Walkinf15320b2004-06-03 03:38:44 +0000151 * A list of parameters for parametrized type declaration
152 * (AMT_PARAMTYPE).
153 */
154 asn1p_paramlist_t *params;
155
156 /*
157 * The actual value (DefinedValue or inlined value).
158 */
159 asn1p_value_t *value;
160
161 /*
Lev Walkin4cd58bd2005-06-02 17:40:32 +0000162 * The WITH SYNTAX clause.
Lev Walkinf15320b2004-06-03 03:38:44 +0000163 */
164 asn1p_wsyntx_t *with_syntax;
165
166 /*
167 * A tag.
168 */
169 struct asn1p_type_tag_s {
170 enum {
171 TC_NOCLASS,
172 TC_UNIVERSAL,
173 TC_APPLICATION,
174 TC_CONTEXT_SPECIFIC,
175 TC_PRIVATE,
176 } tag_class;
177 enum {
178 TM_DEFAULT,
179 TM_IMPLICIT,
180 TM_EXPLICIT,
181 } tag_mode;
Lev Walkind21c5052004-09-29 13:18:09 +0000182 asn1c_integer_t tag_value;
Lev Walkinf15320b2004-06-03 03:38:44 +0000183 } tag;
184
Lev Walkin5498f2d2004-09-15 11:59:30 +0000185 struct asn1p_expr_marker_s {
186 enum asn1p_expr_marker_e {
Lev Walkinb85a8132005-08-18 13:38:19 +0000187 EM_NOMARK,
188 EM_INDIRECT = 0x01, /* 00001 Represent as pointer */
Lev Walkin70853052005-11-26 11:21:55 +0000189 EM_OMITABLE = 0x02, /* 00010 May be absent in encoding */
Lev Walkinb85a8132005-08-18 13:38:19 +0000190 EM_OPTIONAL = 0x07, /* 00111 Optional member */
191 EM_DEFAULT = 0x0F, /* 01111 default_value */
192 EM_UNRECURSE = 0x10, /* 10000 Use safe naming */
Lev Walkin5498f2d2004-09-15 11:59:30 +0000193 } flags;
194 asn1p_value_t *default_value; /* For EM_DEFAULT case */
Lev Walkin6e8da2b2004-09-10 08:21:27 +0000195 } marker;
196 int unique; /* UNIQUE */
197
Lev Walkinf15320b2004-06-03 03:38:44 +0000198 /*
Lev Walkin21d00002005-03-04 08:48:53 +0000199 * Whether automatic tagging may be applied for subtypes.
Lev Walkinf15320b2004-06-03 03:38:44 +0000200 */
201 int auto_tags_OK;
202
Lev Walkinf15320b2004-06-03 03:38:44 +0000203 /*
204 * Members of the constructed type.
205 */
206 TQ_HEAD(struct asn1p_expr_s) members;
207
208 /*
209 * Next expression in the list.
210 */
211 TQ_ENTRY(struct asn1p_expr_s) next;
212
Lev Walkin1004aa92004-09-08 00:28:11 +0000213 struct asn1p_expr_s *parent_expr; /* optional */
214
215 struct asn1p_module_s *module; /* Defined in module */
216
Lev Walkinf15320b2004-06-03 03:38:44 +0000217 /*
218 * Line number where this structure is defined in the original
219 * grammar source.
220 */
221 int _lineno;
Lev Walkin070a52d2004-08-22 03:19:54 +0000222
Lev Walkinf15320b2004-06-03 03:38:44 +0000223 /*
224 * Marks are used for various purposes.
225 * Here are some predefined ones.
226 */
227 enum {
228 TM_NOMARK,
229 TM_RECURSION, /* Used to break recursion */
Lev Walkin81c5fc52005-03-18 05:26:15 +0000230 TM_BROKEN, /* A warning was already issued */
Lev Walkinf15320b2004-06-03 03:38:44 +0000231 } _mark;
232
Lev Walkin21d00002005-03-04 08:48:53 +0000233 /*
234 * Some tags used by the compiler.
235 */
236 int _anonymous_type; /* This type is unnamed */
237 int _type_unique_index; /* A per top-level-type unique index */
Lev Walkin70853052005-11-26 11:21:55 +0000238 int _type_referenced; /* This type is referenced from another place */
Lev Walkin070a52d2004-08-22 03:19:54 +0000239
Lev Walkinf15320b2004-06-03 03:38:44 +0000240 /*
241 * Opaque data may be attached to this structure,
242 * probably by compiler.
243 */
244 void *data;
245 void (*data_free)(void *data);
246} asn1p_expr_t;
247
248
249/*
250 * Constructor and destructor.
251 */
252asn1p_expr_t *asn1p_expr_new(int _lineno);
Lev Walkin070a52d2004-08-22 03:19:54 +0000253asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
Lev Walkin1004aa92004-09-08 00:28:11 +0000254void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
Lev Walkinf15320b2004-06-03 03:38:44 +0000255void asn1p_expr_free(asn1p_expr_t *expr);
256
Lev Walkin71160962005-06-02 05:21:53 +0000257#define TAG2STRING_BUFFER_SIZE 64 /* buf should be at least this big */
258char *asn1p_tag2string(struct asn1p_type_tag_s *tag, char *opt_buf);
259
Lev Walkinf15320b2004-06-03 03:38:44 +0000260#endif /* ASN1_PARSER_EXPR_H */