4c6efab8ef37c0ef1e8dca1ebe6133adc7812a9c
[com/asn1c.git] / libasn1parser / asn1p_class.h
1 /*
2  * CLASS-related stuff.
3  */
4 #ifndef ASN1_PARSER_CLASS_H
5 #define ASN1_PARSER_CLASS_H
6
7 struct asn1p_expr_s;    /* Forward declaration */
8
9 typedef struct asn1p_ioc_row_s {
10         struct asn1p_ioc_cell_s {
11                 struct asn1p_expr_s *field;     /* may never be NULL */
12                 struct asn1p_expr_s *value;     /* may be left uninitialized */
13                 int new_ref;
14         } *column;
15         size_t columns;
16 } asn1p_ioc_row_t;
17
18 asn1p_ioc_row_t *asn1p_ioc_row_new(struct asn1p_expr_s *oclass);
19 asn1p_ioc_row_t *asn1p_ioc_row_clone(asn1p_ioc_row_t *src);
20 size_t asn1p_ioc_row_max_identifier_length(asn1p_ioc_row_t *);
21 void asn1p_ioc_row_delete(asn1p_ioc_row_t *);
22
23 typedef struct asn1p_ioc_table_s {
24     asn1p_ioc_row_t **row;
25     size_t rows;
26     int extensible; /* 0 if non-extensible (sealed). Otherwise, extensible. */
27 } asn1p_ioc_table_t;
28
29 asn1p_ioc_table_t *asn1p_ioc_table_new(void);
30 void asn1p_ioc_table_add(asn1p_ioc_table_t *, asn1p_ioc_row_t *row);
31 void asn1p_ioc_table_append(asn1p_ioc_table_t *it, asn1p_ioc_table_t *src);
32 size_t asn1p_ioc_table_max_identifier_length(asn1p_ioc_table_t *);
33 void asn1p_ioc_table_free(asn1p_ioc_table_t *);
34
35 /*
36  * Match is similar to a comparison,
37  * but -1 means error and 1 means not equal. 0 is OK
38  */
39 int asn1p_ioc_row_match(const asn1p_ioc_row_t *, const asn1p_ioc_row_t *);
40
41 struct asn1p_ioc_cell_s *asn1p_ioc_row_cell_fetch(asn1p_ioc_row_t *,
42                 const char *fieldname);
43
44 /*
45  * WITH SYNTAX free-form chunks.
46  */
47 typedef struct asn1p_wsyntx_chunk_s {
48         enum {
49                 WC_LITERAL,
50                 WC_WHITESPACE,
51                 WC_FIELD,
52                 WC_OPTIONALGROUP
53         } type;
54         /*
55          * WC_LITERAL -> {token}
56          * WC_WHITESPACE -> {token}
57          * WC_FIELD -> {token}
58          * WC_OPTIONALGROUP -> {syntax}
59          */
60         union {
61                 char *token;
62                 struct asn1p_wsyntx_s *syntax;
63         } content;
64
65         TQ_ENTRY(struct asn1p_wsyntx_chunk_s) next;
66 } asn1p_wsyntx_chunk_t;
67
68 typedef struct asn1p_wsyntx_s {
69
70         struct asn1p_wsyntx_chunk_s *parent;
71
72         TQ_HEAD(struct asn1p_wsyntx_chunk_s) chunks;
73
74 } asn1p_wsyntx_t;
75
76
77 /*
78  * Constructor, destructor and cloning function.
79  */
80 asn1p_wsyntx_chunk_t *asn1p_wsyntx_chunk_new(void);
81 void asn1p_wsyntx_chunk_free(asn1p_wsyntx_chunk_t *);
82 asn1p_wsyntx_chunk_t *asn1p_wsyntx_chunk_clone(asn1p_wsyntx_chunk_t *);
83
84 asn1p_wsyntx_t *asn1p_wsyntx_new(void);
85 void asn1p_wsyntx_free(asn1p_wsyntx_t *);
86 asn1p_wsyntx_t *asn1p_wsyntx_clone(asn1p_wsyntx_t *);
87
88 /*
89  * RETURN VALUES:
90  *       0:     Component has been added
91  *      -1:     Failure to add component (refer to errno)
92  */
93 asn1p_wsyntx_chunk_t *asn1p_wsyntx_chunk_fromstring(char *token, int _copy);
94 asn1p_wsyntx_chunk_t *asn1p_wsyntx_chunk_fromsyntax(asn1p_wsyntx_t *syntax);
95
96
97 #endif  /* ASN1_PARSER_CLASS_H */