Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 10 | typedef enum asn1p_expr_meta { |
| 11 | AMT_INVALID, |
| 12 | AMT_TYPE, /* Type1 ::= INTEGER */ |
| 13 | AMT_TYPEREF, /* Type2 ::= Type1 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | AMT_VALUE, /* value1 Type1 ::= 1 */ |
| 15 | AMT_VALUESET, /* ValueSet Type1 ::= { value1 } */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 16 | AMT_OBJECT, /* object CLASS ::= {...} */ |
| 17 | AMT_OBJECTCLASS, /* FUNCTION ::= CLASS {...} */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | AMT_OBJECTFIELD, /* ... */ |
| 19 | AMT_EXPR_META_MAX |
| 20 | } asn1p_expr_meta_e; |
| 21 | |
| 22 | /* |
| 23 | * ASN type of the expression. |
| 24 | */ |
| 25 | typedef enum asn1p_expr_type { |
| 26 | /* |
| 27 | * Internal types. |
| 28 | */ |
| 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 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | A1TC_BITVECTOR, /* A plain collection of bits */ |
| 34 | A1TC_OPAQUE, /* Opaque data encoded as a bitvector */ |
| 35 | A1TC_EXTENSIBLE, /* An extension marker "..." */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 36 | A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | A1TC_VALUESET, /* Value set definition */ |
| 38 | A1TC_CLASSDEF, /* Information Object Class */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 39 | A1TC_INSTANCE, /* Instance of Object Class */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * ASN.1 Class field types |
| 43 | */ |
| 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 */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 52 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 53 | /* |
| 54 | * ASN.1 Constructed types |
| 55 | */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 56 | #define ASN_CONSTR_MASK 0x20 /* Every constructed type */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 62 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 63 | /* |
| 64 | * ASN.1 Basic types |
| 65 | */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 66 | #define ASN_BASIC_MASK 0x40 /* Every basic type */ |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 67 | ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */ |
| 68 | ASN_BASIC_BOOLEAN, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | ASN_BASIC_NULL, |
| 70 | ASN_BASIC_INTEGER, |
| 71 | ASN_BASIC_REAL, |
| 72 | ASN_BASIC_ENUMERATED, |
| 73 | ASN_BASIC_BIT_STRING, |
| 74 | ASN_BASIC_OCTET_STRING, |
| 75 | ASN_BASIC_OBJECT_IDENTIFIER, |
| 76 | ASN_BASIC_RELATIVE_OID, |
| 77 | ASN_BASIC_EXTERNAL, |
| 78 | ASN_BASIC_EMBEDDED_PDV, |
| 79 | ASN_BASIC_CHARACTER_STRING, |
| 80 | ASN_BASIC_UTCTime, |
| 81 | ASN_BASIC_GeneralizedTime, |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 82 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 83 | /* |
| 84 | * ASN.1 String types |
| 85 | */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 86 | #define ASN_STRING_KM_MASK 0x100 /* Known multiplier */ |
| 87 | #define ASN_STRING_NKM_MASK 0x200 /* Not a known multiplier */ |
| 88 | #define ASN_STRING_MASK 0x300 /* Every restricted string type */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 89 | ASN_STRING_IA5String = ASN_STRING_KM_MASK, |
| 90 | ASN_STRING_PrintableString, |
| 91 | ASN_STRING_VisibleString, |
| 92 | ASN_STRING_ISO646String, /* aka VisibleString */ |
| 93 | ASN_STRING_NumericString, |
| 94 | ASN_STRING_UniversalString, |
| 95 | ASN_STRING_BMPString, |
| 96 | ASN_STRING_UTF8String = ASN_STRING_NKM_MASK, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 97 | ASN_STRING_GeneralString, |
| 98 | ASN_STRING_GraphicString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 99 | ASN_STRING_TeletexString, |
| 100 | ASN_STRING_T61String, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 101 | ASN_STRING_VideotexString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 102 | ASN_STRING_ObjectDescriptor, |
| 103 | ASN_EXPR_TYPE_MAX |
| 104 | } asn1p_expr_type_e; |
| 105 | |
| 106 | #include "asn1p_expr_str.h" |
| 107 | #include "asn1p_expr2uclass.h" |
| 108 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 109 | struct asn1p_module_s; /* Forward declaration */ |
| 110 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 111 | /* |
| 112 | * A named collection of types. |
| 113 | */ |
| 114 | typedef struct asn1p_expr_s { |
| 115 | |
| 116 | /* |
| 117 | * Human readable name. |
| 118 | */ |
| 119 | char *Identifier; |
| 120 | |
| 121 | /* |
| 122 | * Meta type of the expression (type, value, value set, etc). |
| 123 | */ |
| 124 | asn1p_expr_meta_e meta_type; |
| 125 | |
| 126 | /* |
| 127 | * ASN type of the expression. |
| 128 | */ |
| 129 | asn1p_expr_type_e expr_type; |
| 130 | |
| 131 | /* |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 132 | * Referenced type, defined elsewhere. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 133 | * (If expr_type == A1TC_REFERENCE) |
| 134 | */ |
| 135 | asn1p_ref_t *reference; |
| 136 | |
| 137 | /* |
| 138 | * Constraints for the type. |
| 139 | */ |
| 140 | asn1p_constraint_t *constraints; |
| 141 | |
| 142 | /* |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 143 | * This field is holding the transformed constraints, with all the |
| 144 | * parent constraints taken into account. |
| 145 | */ |
| 146 | asn1p_constraint_t *combined_constraints; |
| 147 | |
| 148 | /* |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 149 | * Left hand side parameters for parametrized type declaration |
| 150 | * Type{Param1, Param2} ::= SEQUENCE { a Param1, b Param2 } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 151 | */ |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 152 | asn1p_paramlist_t *lhs_params; |
| 153 | /* |
| 154 | * Right hand type specialization. |
| 155 | * Type2 ::= Type{Param1} |
| 156 | */ |
| 157 | struct asn1p_expr_s *rhs_pspecs; /* ->members */ |
| 158 | /* |
| 159 | * If lhs_params is defined, this structure represents all possible |
| 160 | * specializations of the parent expression. |
| 161 | */ |
| 162 | struct { |
| 163 | struct asn1p_pspec_s { |
| 164 | struct asn1p_expr_s *rhs_pspecs; |
| 165 | struct asn1p_expr_s *my_clone; |
| 166 | } *pspec; |
| 167 | int pspecs_count; /* Number of specializations */ |
| 168 | } specializations; |
| 169 | int spec_index; /* -1, or 0-based specialization index in the parent */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * The actual value (DefinedValue or inlined value). |
| 173 | */ |
| 174 | asn1p_value_t *value; |
| 175 | |
| 176 | /* |
Lev Walkin | 4cd58bd | 2005-06-02 17:40:32 +0000 | [diff] [blame] | 177 | * The WITH SYNTAX clause. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 178 | */ |
| 179 | asn1p_wsyntx_t *with_syntax; |
| 180 | |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 181 | /* Information Object Class matrix, specific for this class */ |
| 182 | struct asn1p_ioc_matrix_s { |
| 183 | asn1p_ioc_row_t **row; |
| 184 | int rows; |
| 185 | int max_identifier_length; |
| 186 | } object_class_matrix; |
| 187 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 188 | /* |
| 189 | * A tag. |
| 190 | */ |
| 191 | struct asn1p_type_tag_s { |
| 192 | enum { |
| 193 | TC_NOCLASS, |
| 194 | TC_UNIVERSAL, |
| 195 | TC_APPLICATION, |
| 196 | TC_CONTEXT_SPECIFIC, |
| 197 | TC_PRIVATE, |
| 198 | } tag_class; |
| 199 | enum { |
| 200 | TM_DEFAULT, |
| 201 | TM_IMPLICIT, |
| 202 | TM_EXPLICIT, |
| 203 | } tag_mode; |
Lev Walkin | d21c505 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 204 | asn1c_integer_t tag_value; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 205 | } tag; |
| 206 | |
Lev Walkin | 5498f2d | 2004-09-15 11:59:30 +0000 | [diff] [blame] | 207 | struct asn1p_expr_marker_s { |
| 208 | enum asn1p_expr_marker_e { |
Lev Walkin | b85a813 | 2005-08-18 13:38:19 +0000 | [diff] [blame] | 209 | EM_NOMARK, |
| 210 | EM_INDIRECT = 0x01, /* 00001 Represent as pointer */ |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 211 | EM_OMITABLE = 0x02, /* 00010 May be absent in encoding */ |
Lev Walkin | b85a813 | 2005-08-18 13:38:19 +0000 | [diff] [blame] | 212 | EM_OPTIONAL = 0x07, /* 00111 Optional member */ |
| 213 | EM_DEFAULT = 0x0F, /* 01111 default_value */ |
| 214 | EM_UNRECURSE = 0x10, /* 10000 Use safe naming */ |
Lev Walkin | 5498f2d | 2004-09-15 11:59:30 +0000 | [diff] [blame] | 215 | } flags; |
| 216 | asn1p_value_t *default_value; /* For EM_DEFAULT case */ |
Lev Walkin | 6e8da2b | 2004-09-10 08:21:27 +0000 | [diff] [blame] | 217 | } marker; |
| 218 | int unique; /* UNIQUE */ |
Bi-Ruei, Chiu | b9adfc5 | 2016-11-09 00:17:25 +0800 | [diff] [blame] | 219 | int ref_cnt; /* reference count */ |
Lev Walkin | 6e8da2b | 2004-09-10 08:21:27 +0000 | [diff] [blame] | 220 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 221 | /* |
Lev Walkin | 21d0000 | 2005-03-04 08:48:53 +0000 | [diff] [blame] | 222 | * Whether automatic tagging may be applied for subtypes. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 223 | */ |
| 224 | int auto_tags_OK; |
| 225 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 226 | /* |
| 227 | * Members of the constructed type. |
| 228 | */ |
| 229 | TQ_HEAD(struct asn1p_expr_s) members; |
| 230 | |
| 231 | /* |
| 232 | * Next expression in the list. |
| 233 | */ |
| 234 | TQ_ENTRY(struct asn1p_expr_s) next; |
| 235 | |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 236 | struct asn1p_expr_s *parent_expr; /* optional */ |
| 237 | |
| 238 | struct asn1p_module_s *module; /* Defined in module */ |
| 239 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 240 | /* |
| 241 | * Line number where this structure is defined in the original |
| 242 | * grammar source. |
| 243 | */ |
| 244 | int _lineno; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 245 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 246 | /* |
| 247 | * Marks are used for various purposes. |
| 248 | * Here are some predefined ones. |
| 249 | */ |
| 250 | enum { |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 251 | TM_NOMARK = 0, |
| 252 | TM_RECURSION = (1<<0), /* Used to break recursion */ |
| 253 | TM_BROKEN = (1<<1), /* A warning was already issued */ |
| 254 | TM_PERFROMCT = (1<<2), /* PER FROM() constraint tables emitted */ |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 255 | TM_NAMECLASH = (1<<3) /* Name clash found, need to add module name to resolve */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 256 | } _mark; |
| 257 | |
Lev Walkin | 21d0000 | 2005-03-04 08:48:53 +0000 | [diff] [blame] | 258 | /* |
| 259 | * Some tags used by the compiler. |
| 260 | */ |
| 261 | int _anonymous_type; /* This type is unnamed */ |
| 262 | int _type_unique_index; /* A per top-level-type unique index */ |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 263 | int _type_referenced; /* This type is referenced from another place */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 264 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 265 | /* |
| 266 | * Opaque data may be attached to this structure, |
| 267 | * probably by compiler. |
| 268 | */ |
| 269 | void *data; |
| 270 | void (*data_free)(void *data); |
| 271 | } asn1p_expr_t; |
| 272 | |
| 273 | |
| 274 | /* |
| 275 | * Constructor and destructor. |
| 276 | */ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 277 | asn1p_expr_t *asn1p_expr_new(int _lineno, struct asn1p_module_s *); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 278 | asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 279 | asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *, |
| 280 | asn1p_expr_t *(*resolver)(asn1p_expr_t *to_resolve, void *resolver_arg), |
| 281 | void *resolver_arg); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 282 | void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what); |
Lev Walkin | 0e90aa0 | 2013-03-19 16:17:13 -0700 | [diff] [blame] | 283 | void asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 284 | void asn1p_expr_free(asn1p_expr_t *expr); |
| 285 | |
Lev Walkin | 7116096 | 2005-06-02 05:21:53 +0000 | [diff] [blame] | 286 | #define TAG2STRING_BUFFER_SIZE 64 /* buf should be at least this big */ |
| 287 | char *asn1p_tag2string(struct asn1p_type_tag_s *tag, char *opt_buf); |
| 288 | |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 289 | #define MODULE_NAME_OF(expr) \ |
| 290 | ((!expr) ? "" : \ |
| 291 | (!(expr->_mark & TM_NAMECLASH) ? "" : \ |
| 292 | (!expr->module ? "" : expr->module->ModuleName))), \ |
| 293 | ((!expr) ? "" : \ |
| 294 | (!(expr->_mark & TM_NAMECLASH) ? "" : "_")) |
| 295 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 296 | #endif /* ASN1_PARSER_EXPR_H */ |