Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Type constraints. |
| 3 | */ |
| 4 | #ifndef ASN1_PARSER_CONSTRAINT_H |
| 5 | #define ASN1_PARSER_CONSTRAINT_H |
| 6 | |
| 7 | typedef struct asn1p_constraint_s { |
| 8 | |
| 9 | enum asn1p_constraint_type_e { |
| 10 | ACT_INVALID, /* for assertions */ |
| 11 | /* |
| 12 | * Constraint elements. |
| 13 | */ |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 14 | ACT_EL_TYPE, /* T (contained subtype) */ |
| 15 | ACT_EL_VALUE, /* 123, "A", (elementary value) */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 16 | ACT_EL_RANGE, /* 1..2 (elementary range) */ |
| 17 | ACT_EL_LLRANGE, /* 1<..2 (elementary range) */ |
| 18 | ACT_EL_RLRANGE, /* 1..<2 (elementary range) */ |
| 19 | ACT_EL_ULRANGE, /* 1<..<2 (elementary range) */ |
| 20 | ACT_EL_EXT, /* ... (extensibility mark) */ |
| 21 | /* |
| 22 | * Constraint types. |
| 23 | */ |
| 24 | ACT_CT_SIZE, /* SIZE constraint type */ |
| 25 | ACT_CT_FROM, /* FROM constraint type */ |
| 26 | ACT_CT_WCOMP, /* WITH COMPONENT */ |
| 27 | ACT_CT_WCOMPS, /* WITH COMPONENTS */ |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 28 | ACT_CT_CTDBY, /* CONSTRAINED BY */ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 29 | ACT_CT_CTNG, /* CONTAINING Type */ |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 30 | ACT_CT_PATTERN, /* PATTERN Value */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | /* |
| 32 | * Arrays of constraints. |
| 33 | */ |
| 34 | ACT_CA_SET, /* A set of constraints: (c1)(c2) */ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 35 | ACT_CA_CRC, /* Comp. relation c-t: ({a}{@b}) */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | ACT_CA_CSV, /* Comma-separated constraints array */ |
| 37 | ACT_CA_UNI, /* UNION (|) */ |
| 38 | ACT_CA_INT, /* INTERSECTION (^) */ |
| 39 | ACT_CA_EXC, /* EXCEPT */ |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 40 | ACT_CA_AEX, /* ALL EXCEPT */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | } type; |
| 42 | |
| 43 | enum asn1p_constr_pres_e { |
| 44 | ACPRES_DEFAULT, |
| 45 | ACPRES_PRESENT, |
| 46 | ACPRES_ABSENT, |
| 47 | ACPRES_OPTIONAL, |
| 48 | } presence; |
| 49 | |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 50 | struct asn1p_constraint_s *parent_ct; /* optional */ |
| 51 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | /* |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 53 | * Separate types and values. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 54 | */ |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 55 | asn1p_value_t *containedSubtype; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | asn1p_value_t *value; |
| 57 | asn1p_value_t *range_start; |
| 58 | asn1p_value_t *range_stop; |
| 59 | |
| 60 | /* |
| 61 | * A collection of constraint elements. |
| 62 | */ |
| 63 | struct asn1p_constraint_s **elements; |
Lev Walkin | e972d93 | 2004-09-05 10:40:28 +0000 | [diff] [blame] | 64 | unsigned int el_count; /* Number of meaningful elements */ |
| 65 | unsigned int el_size; /* Size of the allocated (elements) */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 67 | struct asn1p_module_s *module; /* Defined in module */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 68 | int _lineno; /* Position in a source file */ |
| 69 | } asn1p_constraint_t; |
| 70 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 71 | /* Human-readable constraint type description */ |
Lev Walkin | fc4f37a | 2017-07-31 19:57:45 -0700 | [diff] [blame] | 72 | const char *asn1p_constraint_type2str(enum asn1p_constraint_type_e); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Constructors and a recursive destructor. |
| 76 | */ |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 77 | asn1p_constraint_t *asn1p_constraint_new(int _lineno, asn1p_module_t *mod); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 78 | void asn1p_constraint_free(asn1p_constraint_t *); |
| 79 | |
| 80 | /* |
| 81 | * Clone the constraint and all its children. |
| 82 | */ |
| 83 | asn1p_constraint_t *asn1p_constraint_clone(asn1p_constraint_t *source_to_clone); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 84 | asn1p_constraint_t *asn1p_constraint_clone_with_resolver( |
| 85 | asn1p_constraint_t *source_to_clone, |
| 86 | asn1p_value_t *(*resolver)(asn1p_value_t *, void *), void *); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Insert additional element into the element array of a (to) constraint. |
| 90 | */ |
| 91 | int asn1p_constraint_insert(asn1p_constraint_t *into, asn1p_constraint_t *what); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 92 | int asn1p_constraint_prepend(asn1p_constraint_t *before, asn1p_constraint_t *what); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | |
| 94 | #endif /* ASN1_PARSER_CONSTRAINT_H */ |