]> mj.ucw.cz Git - libucw.git/blob - ucw-xml/dtd.h
Build: Fixed debian/mk --archonly on debian stretch.
[libucw.git] / ucw-xml / dtd.h
1 /*
2  *      UCW Library -- A simple XML parser
3  *
4  *      (c) 2007--2008 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_XML_DTD_H
11 #define _UCW_XML_DTD_H
12
13 #include <ucw-xml/xml.h>
14
15 #ifdef CONFIG_UCW_CLEAN_ABI
16 #define xml_dtd_cleanup ucw_xml_dtd_cleanup
17 #define xml_dtd_find_attr ucw_xml_dtd_find_attr
18 #define xml_dtd_find_elem ucw_xml_dtd_find_elem
19 #define xml_dtd_find_entity ucw_xml_dtd_find_entity
20 #define xml_dtd_find_notn ucw_xml_dtd_find_notn
21 #define xml_dtd_finish ucw_xml_dtd_finish
22 #define xml_dtd_init ucw_xml_dtd_init
23 #endif
24
25 struct xml_dtd {
26   struct mempool *pool;                 /* Memory pool where to allocate DTD */
27   slist ents;                           /* Link list of general entities */
28   slist pents;                          /* Link list of parameter entities */
29   slist notns;                          /* Link list of notations */
30   slist elems;                          /* Link list of elements */
31   void *tab_ents;                       /* Hash table of general entities */
32   void *tab_pents;                      /* Hash table of parameter entities */
33   void *tab_notns;                      /* Hash table of notations */
34   void *tab_elems;                      /* Hash table of elements */
35   void *tab_enodes;                     /* Hash table of element sons */
36   void *tab_attrs;                      /* Hash table of element attributes */
37   void *tab_evals;                      /* Hash table of enumerated attribute values */
38   void *tab_enotns;                     /* hash table of enumerated attribute notations */
39 };
40
41 /* Notations */
42
43 enum xml_dtd_notn_flags {
44   XML_DTD_NOTN_DECLARED = 0x1,          /* The notation has been declared (internal usage) */
45 };
46
47 struct xml_dtd_notn {
48   snode n;                              /* Node in xml_dtd.notns */
49   uint flags;                           /* XML_DTD_NOTN_x */
50   char *name;                           /* Notation name */
51   char *system_id;                      /* External ID */
52   char *public_id;
53   void *user;                           /* User-defined */
54 };
55
56 struct xml_dtd_notn *xml_dtd_find_notn(struct xml_context *ctx, char *name);
57
58 /* Entities */
59
60 enum xml_dtd_entity_flags {
61   XML_DTD_ENTITY_DECLARED = 0x1,        /* The entity has been declared (internal usage) */
62   XML_DTD_ENTITY_VISITED = 0x2,         /* Cycle detection (internal usage) */
63   XML_DTD_ENTITY_PARAMETER = 0x4,       /* Parameter entity, general otherwise */
64   XML_DTD_ENTITY_EXTERNAL = 0x8,        /* External entity, internal otherwise */
65   XML_DTD_ENTITY_UNPARSED = 0x10,       /* Unparsed entity, parsed otherwise */
66   XML_DTD_ENTITY_TRIVIAL = 0x20,        /* Replacement text is a sequence of characters and character references */
67 };
68
69 struct xml_dtd_entity {
70   snode n;                              /* Node in xml_dtd.[gp]ents */
71   uint flags;                           /* XML_DTD_ENT_x */
72   char *name;                           /* Entity name */
73   char *text;                           /* Replacement text / expanded replacement text (XML_DTD_ENT_TRIVIAL) */
74   uint len;                             /* Text length */
75   char *system_id;                      /* External ID */
76   char *public_id;
77   struct xml_dtd_notn *notn;            /* Notation (XML_DTD_ENT_UNPARSED only) */
78   void *user;                           /* User-defined */
79 };
80
81 struct xml_dtd_entity *xml_dtd_find_entity(struct xml_context *ctx, char *name);
82
83 /* Elements */
84
85 enum xml_dtd_elem_flags {
86   XML_DTD_ELEM_DECLARED = 0x1,          /* The element has been declared (internal usage) */
87 };
88
89 enum xml_dtd_elem_type {
90   XML_DTD_ELEM_EMPTY,
91   XML_DTD_ELEM_ANY,
92   XML_DTD_ELEM_MIXED,
93   XML_DTD_ELEM_CHILDREN,
94 };
95
96 struct xml_dtd_elem {
97   snode n;
98   uint flags;
99   uint type;
100   char *name;
101   struct xml_dtd_elem_node *node;
102   slist attrs;
103   void *user;                           /* User-defined */
104 };
105
106 struct xml_dtd_elem_node {
107   snode n;
108   struct xml_dtd_elem_node *parent;
109   struct xml_dtd_elem *elem;
110   slist sons;
111   uint type;
112   uint occur;
113   void *user;                           /* User-defined */
114 };
115
116 enum xml_dtd_elem_node_type {
117   XML_DTD_ELEM_PCDATA,
118   XML_DTD_ELEM_SEQ,
119   XML_DTD_ELEM_OR,
120 };
121
122 enum xml_dtd_elem_node_occur {
123   XML_DTD_ELEM_OCCUR_ONCE,
124   XML_DTD_ELEM_OCCUR_OPT,
125   XML_DTD_ELEM_OCCUR_MULT,
126   XML_DTD_ELEM_OCCUR_PLUS,
127 };
128
129 struct xml_dtd_elem *xml_dtd_find_elem(struct xml_context *ctx, char *name);
130
131 /* Attributes */
132
133 enum xml_dtd_attr_default {
134   XML_ATTR_NONE,
135   XML_ATTR_REQUIRED,
136   XML_ATTR_IMPLIED,
137   XML_ATTR_FIXED,
138 };
139
140 enum xml_dtd_attr_type {
141   XML_ATTR_CDATA,
142   XML_ATTR_ID,
143   XML_ATTR_IDREF,
144   XML_ATTR_IDREFS,
145   XML_ATTR_ENTITY,
146   XML_ATTR_ENTITIES,
147   XML_ATTR_NMTOKEN,
148   XML_ATTR_NMTOKENS,
149   XML_ATTR_ENUM,
150   XML_ATTR_NOTATION,
151 };
152
153 struct xml_dtd_attr {
154   snode n;
155   char *name;                           /* Attribute name */
156   struct xml_dtd_elem *elem;            /* Owner element */
157   uint type;                            /* See enum xml_dtd_attr_type */
158   uint default_mode;                    /* See enum xml_dtd_attr_default */
159   char *default_value;                  /* The default value defined in DTD (or NULL) */
160 };
161
162 struct xml_dtd_eval {
163   struct xml_dtd_attr *attr;
164   char *val;
165 };
166
167 struct xml_dtd_enotn {
168   struct xml_dtd_attr *attr;
169   struct xml_dtd_notn *notn;
170 };
171
172 void xml_dtd_init(struct xml_context *ctx);
173 void xml_dtd_cleanup(struct xml_context *ctx);
174 void xml_dtd_finish(struct xml_context *ctx);
175
176 struct xml_dtd_attr *xml_dtd_find_attr(struct xml_context *ctx, struct xml_dtd_elem *elem, char *name);
177
178 #endif