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 */ |
| 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 | */ |
| 26 | typedef 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 */ |
| 34 | A1TC_BOOLBITPOS, /* A bit position in a BIT STRING */ |
| 35 | A1TC_BITVECTOR, /* A plain collection of bits */ |
| 36 | A1TC_OPAQUE, /* Opaque data encoded as a bitvector */ |
| 37 | A1TC_EXTENSIBLE, /* An extension marker "..." */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 38 | A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 39 | A1TC_PARAMETRIZED, /* A parametrized type declaration */ |
| 40 | A1TC_VALUESET, /* Value set definition */ |
| 41 | A1TC_CLASSDEF, /* Information Object Class */ |
| 42 | A1TC_CLASSFIELD, /* Information Object Class field */ |
| 43 | A1TC_INSTANCE, /* Instance of Object Class */ |
| 44 | A1TC_TYPEID, /* Type identifier */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 45 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | /* |
| 47 | * ASN.1 Constructed types |
| 48 | */ |
| 49 | #define ASN_CONSTR_MASK 0x10 /* Every constructed type */ |
| 50 | ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */ |
| 51 | ASN_CONSTR_CHOICE, /* CHOICE */ |
| 52 | ASN_CONSTR_SET, /* SET */ |
| 53 | ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */ |
| 54 | ASN_CONSTR_SET_OF, /* SET OF */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 55 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | /* |
| 57 | * ASN.1 Basic types |
| 58 | */ |
| 59 | #define ASN_BASIC_MASK 0x20 /* Every basic type */ |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 60 | ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */ |
| 61 | ASN_BASIC_BOOLEAN, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | ASN_BASIC_NULL, |
| 63 | ASN_BASIC_INTEGER, |
| 64 | ASN_BASIC_REAL, |
| 65 | ASN_BASIC_ENUMERATED, |
| 66 | ASN_BASIC_BIT_STRING, |
| 67 | ASN_BASIC_OCTET_STRING, |
| 68 | ASN_BASIC_OBJECT_IDENTIFIER, |
| 69 | ASN_BASIC_RELATIVE_OID, |
| 70 | ASN_BASIC_EXTERNAL, |
| 71 | ASN_BASIC_EMBEDDED_PDV, |
| 72 | ASN_BASIC_CHARACTER_STRING, |
| 73 | ASN_BASIC_UTCTime, |
| 74 | ASN_BASIC_GeneralizedTime, |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 75 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 76 | /* |
| 77 | * ASN.1 String types |
| 78 | */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 79 | #define ASN_STRING_KM_MASK 0x40 /* Known multiplier */ |
| 80 | #define ASN_STRING_NKM_MASK 0x80 /* Not a known multiplier */ |
| 81 | #define ASN_STRING_MASK 0xC0 /* Every restricted string type */ |
| 82 | ASN_STRING_IA5String = ASN_STRING_KM_MASK, |
| 83 | ASN_STRING_PrintableString, |
| 84 | ASN_STRING_VisibleString, |
| 85 | ASN_STRING_ISO646String, /* aka VisibleString */ |
| 86 | ASN_STRING_NumericString, |
| 87 | ASN_STRING_UniversalString, |
| 88 | ASN_STRING_BMPString, |
| 89 | ASN_STRING_UTF8String = ASN_STRING_NKM_MASK, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 90 | ASN_STRING_GeneralString, |
| 91 | ASN_STRING_GraphicString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 92 | ASN_STRING_TeletexString, |
| 93 | ASN_STRING_T61String, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 94 | ASN_STRING_VideotexString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 95 | ASN_STRING_ObjectDescriptor, |
| 96 | ASN_EXPR_TYPE_MAX |
| 97 | } asn1p_expr_type_e; |
| 98 | |
| 99 | #include "asn1p_expr_str.h" |
| 100 | #include "asn1p_expr2uclass.h" |
| 101 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 102 | struct asn1p_module_s; /* Forward declaration */ |
| 103 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 104 | /* |
| 105 | * A named collection of types. |
| 106 | */ |
| 107 | typedef struct asn1p_expr_s { |
| 108 | |
| 109 | /* |
| 110 | * Human readable name. |
| 111 | */ |
| 112 | char *Identifier; |
| 113 | |
| 114 | /* |
| 115 | * Meta type of the expression (type, value, value set, etc). |
| 116 | */ |
| 117 | asn1p_expr_meta_e meta_type; |
| 118 | |
| 119 | /* |
| 120 | * ASN type of the expression. |
| 121 | */ |
| 122 | asn1p_expr_type_e expr_type; |
| 123 | |
| 124 | /* |
| 125 | * Referenced type, if defined elsewhere. |
| 126 | * (If expr_type == A1TC_REFERENCE) |
| 127 | */ |
| 128 | asn1p_ref_t *reference; |
| 129 | |
| 130 | /* |
| 131 | * Constraints for the type. |
| 132 | */ |
| 133 | asn1p_constraint_t *constraints; |
| 134 | |
| 135 | /* |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 136 | * This field is holding the transformed constraints, with all the |
| 137 | * parent constraints taken into account. |
| 138 | */ |
| 139 | asn1p_constraint_t *combined_constraints; |
| 140 | |
| 141 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 142 | * A list of parameters for parametrized type declaration |
| 143 | * (AMT_PARAMTYPE). |
| 144 | */ |
| 145 | asn1p_paramlist_t *params; |
| 146 | |
| 147 | /* |
| 148 | * The actual value (DefinedValue or inlined value). |
| 149 | */ |
| 150 | asn1p_value_t *value; |
| 151 | |
| 152 | /* |
| 153 | * The WITH SYHTAX clause. |
| 154 | */ |
| 155 | asn1p_wsyntx_t *with_syntax; |
| 156 | |
| 157 | /* |
| 158 | * A tag. |
| 159 | */ |
| 160 | struct asn1p_type_tag_s { |
| 161 | enum { |
| 162 | TC_NOCLASS, |
| 163 | TC_UNIVERSAL, |
| 164 | TC_APPLICATION, |
| 165 | TC_CONTEXT_SPECIFIC, |
| 166 | TC_PRIVATE, |
| 167 | } tag_class; |
| 168 | enum { |
| 169 | TM_DEFAULT, |
| 170 | TM_IMPLICIT, |
| 171 | TM_EXPLICIT, |
| 172 | } tag_mode; |
Lev Walkin | d21c505 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 173 | asn1c_integer_t tag_value; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 174 | } tag; |
| 175 | |
Lev Walkin | 5498f2d | 2004-09-15 11:59:30 +0000 | [diff] [blame] | 176 | struct asn1p_expr_marker_s { |
| 177 | enum asn1p_expr_marker_e { |
| 178 | EM_NOMARK, |
| 179 | EM_INDIRECT = 0x01, /* 0001: Represent as pointer */ |
| 180 | EM_OPTIONAL = 0x03, /* 0011: Optional member */ |
| 181 | EM_DEFAULT = 0x07, /* 0111: default_value */ |
| 182 | } flags; |
| 183 | asn1p_value_t *default_value; /* For EM_DEFAULT case */ |
Lev Walkin | 6e8da2b | 2004-09-10 08:21:27 +0000 | [diff] [blame] | 184 | } marker; |
| 185 | int unique; /* UNIQUE */ |
| 186 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 187 | /* |
| 188 | * Whether automatic tagging is applicable for subtypes. |
| 189 | */ |
| 190 | int auto_tags_OK; |
| 191 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 192 | /* |
| 193 | * Members of the constructed type. |
| 194 | */ |
| 195 | TQ_HEAD(struct asn1p_expr_s) members; |
| 196 | |
| 197 | /* |
| 198 | * Next expression in the list. |
| 199 | */ |
| 200 | TQ_ENTRY(struct asn1p_expr_s) next; |
| 201 | |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 202 | struct asn1p_expr_s *parent_expr; /* optional */ |
| 203 | |
| 204 | struct asn1p_module_s *module; /* Defined in module */ |
| 205 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 206 | /* |
| 207 | * Line number where this structure is defined in the original |
| 208 | * grammar source. |
| 209 | */ |
| 210 | int _lineno; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 211 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Marks are used for various purposes. |
| 214 | * Here are some predefined ones. |
| 215 | */ |
| 216 | enum { |
| 217 | TM_NOMARK, |
| 218 | TM_RECURSION, /* Used to break recursion */ |
| 219 | } _mark; |
| 220 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 221 | int _anonymous_type; /* Used by the compiler */ |
| 222 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 223 | /* |
| 224 | * Opaque data may be attached to this structure, |
| 225 | * probably by compiler. |
| 226 | */ |
| 227 | void *data; |
| 228 | void (*data_free)(void *data); |
| 229 | } asn1p_expr_t; |
| 230 | |
| 231 | |
| 232 | /* |
| 233 | * Constructor and destructor. |
| 234 | */ |
| 235 | asn1p_expr_t *asn1p_expr_new(int _lineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 236 | asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 237 | void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 238 | void asn1p_expr_free(asn1p_expr_t *expr); |
| 239 | |
| 240 | #endif /* ASN1_PARSER_EXPR_H */ |