blob: c44e103284cb031493de9e3efbf21ba9ae95ce22 [file] [log] [blame]
vlmfa67ddc2004-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 } */
17 AMT_OBJECT, /* FUNCTION ::= CLASS {...} */
18 AMT_OBJECTSET, /* Functions FUNCTION ::= {...} */
19 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 */
vlmfa67ddc2004-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 "..." */
vlmec8f6812004-08-22 03:19:54 +000037 A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
vlmfa67ddc2004-06-03 03:38:44 +000038 A1TC_PARAMETRIZED, /* A parametrized type declaration */
39 A1TC_VALUESET, /* Value set definition */
40 A1TC_CLASSDEF, /* Information Object Class */
41 A1TC_CLASSFIELD, /* Information Object Class field */
42 A1TC_INSTANCE, /* Instance of Object Class */
43 A1TC_TYPEID, /* Type identifier */
vlmec8f6812004-08-22 03:19:54 +000044
vlmfa67ddc2004-06-03 03:38:44 +000045 /*
46 * ASN.1 Constructed types
47 */
48#define ASN_CONSTR_MASK 0x10 /* Every constructed type */
49 ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */
50 ASN_CONSTR_CHOICE, /* CHOICE */
51 ASN_CONSTR_SET, /* SET */
52 ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */
53 ASN_CONSTR_SET_OF, /* SET OF */
vlm3ddcc1c2004-08-25 01:58:59 +000054
vlmfa67ddc2004-06-03 03:38:44 +000055 /*
56 * ASN.1 Basic types
57 */
58#define ASN_BASIC_MASK 0x20 /* Every basic type */
vlm044f7442004-09-04 04:49:21 +000059 ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */
60 ASN_BASIC_BOOLEAN,
vlmfa67ddc2004-06-03 03:38:44 +000061 ASN_BASIC_NULL,
62 ASN_BASIC_INTEGER,
63 ASN_BASIC_REAL,
64 ASN_BASIC_ENUMERATED,
65 ASN_BASIC_BIT_STRING,
66 ASN_BASIC_OCTET_STRING,
67 ASN_BASIC_OBJECT_IDENTIFIER,
68 ASN_BASIC_RELATIVE_OID,
69 ASN_BASIC_EXTERNAL,
70 ASN_BASIC_EMBEDDED_PDV,
71 ASN_BASIC_CHARACTER_STRING,
72 ASN_BASIC_UTCTime,
73 ASN_BASIC_GeneralizedTime,
vlmec8f6812004-08-22 03:19:54 +000074
vlmfa67ddc2004-06-03 03:38:44 +000075 /*
76 * ASN.1 String types
77 */
vlm3ddcc1c2004-08-25 01:58:59 +000078#define ASN_STRING_KM_MASK 0x40 /* Known multiplier */
79#define ASN_STRING_NKM_MASK 0x80 /* Not a known multiplier */
80#define ASN_STRING_MASK 0xC0 /* Every restricted string type */
81 ASN_STRING_IA5String = ASN_STRING_KM_MASK,
82 ASN_STRING_PrintableString,
83 ASN_STRING_VisibleString,
84 ASN_STRING_ISO646String, /* aka VisibleString */
85 ASN_STRING_NumericString,
86 ASN_STRING_UniversalString,
87 ASN_STRING_BMPString,
88 ASN_STRING_UTF8String = ASN_STRING_NKM_MASK,
vlmfa67ddc2004-06-03 03:38:44 +000089 ASN_STRING_GeneralString,
90 ASN_STRING_GraphicString,
vlmfa67ddc2004-06-03 03:38:44 +000091 ASN_STRING_TeletexString,
92 ASN_STRING_T61String,
vlmfa67ddc2004-06-03 03:38:44 +000093 ASN_STRING_VideotexString,
vlmfa67ddc2004-06-03 03:38:44 +000094 ASN_STRING_ObjectDescriptor,
95 ASN_EXPR_TYPE_MAX
96} asn1p_expr_type_e;
97
98#include "asn1p_expr_str.h"
99#include "asn1p_expr2uclass.h"
100
vlmec8f6812004-08-22 03:19:54 +0000101struct asn1p_module_s; /* Forward declaration */
102
vlmfa67ddc2004-06-03 03:38:44 +0000103/*
104 * A named collection of types.
105 */
106typedef struct asn1p_expr_s {
107
108 /*
109 * Human readable name.
110 */
111 char *Identifier;
112
113 /*
114 * Meta type of the expression (type, value, value set, etc).
115 */
116 asn1p_expr_meta_e meta_type;
117
118 /*
119 * ASN type of the expression.
120 */
121 asn1p_expr_type_e expr_type;
122
123 /*
vlm4053ca52005-02-18 16:34:21 +0000124 * Referenced type, defined elsewhere.
vlmfa67ddc2004-06-03 03:38:44 +0000125 * (If expr_type == A1TC_REFERENCE)
126 */
127 asn1p_ref_t *reference;
128
129 /*
130 * Constraints for the type.
131 */
132 asn1p_constraint_t *constraints;
133
134 /*
vlm9283dbe2004-08-18 04:59:12 +0000135 * This field is holding the transformed constraints, with all the
136 * parent constraints taken into account.
137 */
138 asn1p_constraint_t *combined_constraints;
139
140 /*
vlmfa67ddc2004-06-03 03:38:44 +0000141 * A list of parameters for parametrized type declaration
142 * (AMT_PARAMTYPE).
143 */
144 asn1p_paramlist_t *params;
145
146 /*
147 * The actual value (DefinedValue or inlined value).
148 */
149 asn1p_value_t *value;
150
151 /*
vlm2ec1e232005-06-02 17:40:32 +0000152 * The WITH SYNTAX clause.
vlmfa67ddc2004-06-03 03:38:44 +0000153 */
154 asn1p_wsyntx_t *with_syntax;
155
156 /*
157 * A tag.
158 */
159 struct asn1p_type_tag_s {
160 enum {
161 TC_NOCLASS,
162 TC_UNIVERSAL,
163 TC_APPLICATION,
164 TC_CONTEXT_SPECIFIC,
165 TC_PRIVATE,
166 } tag_class;
167 enum {
168 TM_DEFAULT,
169 TM_IMPLICIT,
170 TM_EXPLICIT,
171 } tag_mode;
vlmec6acd42004-09-29 13:18:09 +0000172 asn1c_integer_t tag_value;
vlmfa67ddc2004-06-03 03:38:44 +0000173 } tag;
174
vlm6ac9b0d2004-09-15 11:59:30 +0000175 struct asn1p_expr_marker_s {
176 enum asn1p_expr_marker_e {
vlm6c4a8502005-08-18 13:38:19 +0000177 EM_NOMARK,
178 EM_INDIRECT = 0x01, /* 00001 Represent as pointer */
vlm1ac75e72005-11-26 11:21:55 +0000179 EM_OMITABLE = 0x02, /* 00010 May be absent in encoding */
vlm6c4a8502005-08-18 13:38:19 +0000180 EM_OPTIONAL = 0x07, /* 00111 Optional member */
181 EM_DEFAULT = 0x0F, /* 01111 default_value */
182 EM_UNRECURSE = 0x10, /* 10000 Use safe naming */
vlm6ac9b0d2004-09-15 11:59:30 +0000183 } flags;
184 asn1p_value_t *default_value; /* For EM_DEFAULT case */
vlmd82eb012004-09-10 08:21:27 +0000185 } marker;
186 int unique; /* UNIQUE */
187
vlmfa67ddc2004-06-03 03:38:44 +0000188 /*
vlm766cf1e2005-03-04 08:48:53 +0000189 * Whether automatic tagging may be applied for subtypes.
vlmfa67ddc2004-06-03 03:38:44 +0000190 */
191 int auto_tags_OK;
192
vlmfa67ddc2004-06-03 03:38:44 +0000193 /*
194 * Members of the constructed type.
195 */
196 TQ_HEAD(struct asn1p_expr_s) members;
197
198 /*
199 * Next expression in the list.
200 */
201 TQ_ENTRY(struct asn1p_expr_s) next;
202
vlm6a02a8a2004-09-08 00:28:11 +0000203 struct asn1p_expr_s *parent_expr; /* optional */
204
205 struct asn1p_module_s *module; /* Defined in module */
206
vlmfa67ddc2004-06-03 03:38:44 +0000207 /*
208 * Line number where this structure is defined in the original
209 * grammar source.
210 */
211 int _lineno;
vlmec8f6812004-08-22 03:19:54 +0000212
vlmfa67ddc2004-06-03 03:38:44 +0000213 /*
214 * Marks are used for various purposes.
215 * Here are some predefined ones.
216 */
217 enum {
218 TM_NOMARK,
219 TM_RECURSION, /* Used to break recursion */
vlm9ad71912005-03-18 05:26:15 +0000220 TM_BROKEN, /* A warning was already issued */
vlmfa67ddc2004-06-03 03:38:44 +0000221 } _mark;
222
vlm766cf1e2005-03-04 08:48:53 +0000223 /*
224 * Some tags used by the compiler.
225 */
226 int _anonymous_type; /* This type is unnamed */
227 int _type_unique_index; /* A per top-level-type unique index */
vlm1ac75e72005-11-26 11:21:55 +0000228 int _type_referenced; /* This type is referenced from another place */
vlmec8f6812004-08-22 03:19:54 +0000229
vlmfa67ddc2004-06-03 03:38:44 +0000230 /*
231 * Opaque data may be attached to this structure,
232 * probably by compiler.
233 */
234 void *data;
235 void (*data_free)(void *data);
236} asn1p_expr_t;
237
238
239/*
240 * Constructor and destructor.
241 */
242asn1p_expr_t *asn1p_expr_new(int _lineno);
vlmec8f6812004-08-22 03:19:54 +0000243asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
vlm6a02a8a2004-09-08 00:28:11 +0000244void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
vlmfa67ddc2004-06-03 03:38:44 +0000245void asn1p_expr_free(asn1p_expr_t *expr);
246
vlm5b103032005-06-02 05:21:53 +0000247#define TAG2STRING_BUFFER_SIZE 64 /* buf should be at least this big */
248char *asn1p_tag2string(struct asn1p_type_tag_s *tag, char *opt_buf);
249
vlmfa67ddc2004-06-03 03:38:44 +0000250#endif /* ASN1_PARSER_EXPR_H */