blob: dbc8f878bfc5785859b629afed9accc1b0469058 [file] [log] [blame]
Lev Walkind9221842017-08-22 01:44:56 -07001/*
2 * Generic reference to the yet unknown type defined elsewhere.
3 */
4#ifndef ASN1_REFERENCE_H
5#define ASN1_REFERENCE_H
6
7struct asn1p_module_s;
8
9typedef struct asn1p_ref_s {
10
11 /*
12 * A set of reference name components.
13 * A reference name consists of several components separated by dots:
14 * "OBJECT-CLASS.&Algorithm.&id"
15 */
16 struct asn1p_ref_component_s {
17 enum asn1p_ref_lex_type_e {
18 RLT_UNKNOWN, /* Invalid? */
19 /*
20 * Object class reference "OCLASS1",
21 * type reference "Type1",
22 * value reference "id",
23 * type field reference "&Type1",
24 * value field reference "&id",
25 * "OBJECT-CLASS"
26 */
27 RLT_CAPITALS,
28 RLT_Uppercase,
29 RLT_lowercase,
30 RLT_AmpUppercase,
31 RLT_Amplowercase,
32 RLT_Atlowercase,
33 RLT_AtDotlowercase,
34 RLT_MAX
35 } lex_type; /* Inferred lexical type of the identifier */
36 char *name; /* An identifier */
37 } *components;
38
39 size_t comp_count; /* Number of the components in the reference name. */
40 size_t comp_size; /* Number of allocated structures */
41
42 struct asn1p_module_s *module; /* Defined in module */
43 int _lineno; /* Number of line in the file */
44} asn1p_ref_t;
45
46/*
47 * Constructor and destructor.
48 */
49asn1p_ref_t *asn1p_ref_new(int _lineno, struct asn1p_module_s *mod);
50void asn1p_ref_free(asn1p_ref_t *);
51
52asn1p_ref_t *asn1p_ref_clone(asn1p_ref_t *ref);
53
54void asn1p_ref_set_source(asn1p_ref_t *, struct asn1p_module_s *module,
55 int lineno);
56
57
58/*
59 * Lexicographically compare references.
60 */
61int asn1p_ref_compare(const asn1p_ref_t *, const asn1p_ref_t *);
62
63/*
64 * Return a pointer to a statically allocated buffer representing the
65 * complete reference.
66 */
67const char *asn1p_ref_string(const asn1p_ref_t *);
68
69/*
70 * Add a new reference component to the existing reference structure.
71 *
72 * RETURN VALUES:
73 * 0: All clear.
74 * -1/EINVAL: Invalid arguments
75 * -1/ENOMEM: Memory allocation failed
76 */
77int asn1p_ref_add_component(asn1p_ref_t *,
78 const char *name, enum asn1p_ref_lex_type_e);
79
80#endif /* ASN1_REFERENCE_H */