|
1 /* |
|
2 * Summary: The DTD validation |
|
3 * Description: API for the DTD handling and the validity checking |
|
4 * |
|
5 * Copy: See Copyright for the status of this software. |
|
6 * |
|
7 * Author: Daniel Veillard |
|
8 */ |
|
9 |
|
10 |
|
11 #ifndef __XML_VALID_H__ |
|
12 #define __XML_VALID_H__ |
|
13 |
|
14 //#include "Libxml2_xmlversion.h" |
|
15 #include "Libxml2_xmlerror.h" |
|
16 #include "Libxml2_tree.h" |
|
17 #include "Libxml2_list.h" |
|
18 |
|
19 #ifdef LIBXML_AUTOMATA_ENABLED |
|
20 #include <xmlautomata.h> |
|
21 #endif |
|
22 |
|
23 #ifdef LIBXML_REGEXP_ENABLED |
|
24 #include <xmlregexp.h> |
|
25 #endif |
|
26 |
|
27 #ifdef __cplusplus |
|
28 extern "C" { |
|
29 #endif |
|
30 |
|
31 /* |
|
32 * Validation state added for non-determinist content model. |
|
33 */ |
|
34 typedef struct _xmlValidState xmlValidState; |
|
35 typedef xmlValidState *xmlValidStatePtr; |
|
36 |
|
37 /** |
|
38 * xmlValidityErrorFunc: |
|
39 * @ctx: an xmlValidCtxtPtr validity error context |
|
40 * @msg: the string to format *printf like vararg |
|
41 * @...: remaining arguments to the format |
|
42 * |
|
43 * Callback called when a validity error is found. This is a message |
|
44 * oriented function similar to an *printf function. |
|
45 */ |
|
46 typedef void (*xmlValidityErrorFunc) (void *ctx, |
|
47 const char *msg, |
|
48 ...); |
|
49 |
|
50 /** |
|
51 * xmlValidityWarningFunc: |
|
52 * @ctx: an xmlValidCtxtPtr validity error context |
|
53 * @msg: the string to format *printf like vararg |
|
54 * @...: remaining arguments to the format |
|
55 * |
|
56 * Callback called when a validity warning is found. This is a message |
|
57 * oriented function similar to an *printf function. |
|
58 */ |
|
59 typedef void (*xmlValidityWarningFunc) (void *ctx, |
|
60 const char *msg, |
|
61 ...); |
|
62 |
|
63 /* |
|
64 * xmlValidCtxt: |
|
65 * An xmlValidCtxt is used for error reporting when validating. |
|
66 */ |
|
67 typedef struct _xmlValidCtxt xmlValidCtxt; |
|
68 typedef xmlValidCtxt *xmlValidCtxtPtr; |
|
69 struct _xmlValidCtxt { |
|
70 void *userData; /* user specific data block */ |
|
71 xmlValidityErrorFunc error; /* the callback in case of errors */ |
|
72 xmlValidityWarningFunc warning; /* the callback in case of warning */ |
|
73 |
|
74 /* Node analysis stack used when validating within entities */ |
|
75 xmlNodePtr node; /* Current parsed Node */ |
|
76 int nodeNr; /* Depth of the parsing stack */ |
|
77 int nodeMax; /* Max depth of the parsing stack */ |
|
78 xmlNodePtr *nodeTab; /* array of nodes */ |
|
79 |
|
80 int finishDtd; /* finished validating the Dtd ? */ |
|
81 xmlDocPtr doc; /* the document */ |
|
82 int valid; /* temporary validity check result */ |
|
83 |
|
84 /* state state used for non-determinist content validation */ |
|
85 xmlValidState *vstate; /* current state */ |
|
86 int vstateNr; /* Depth of the validation stack */ |
|
87 int vstateMax; /* Max depth of the validation stack */ |
|
88 xmlValidState *vstateTab; /* array of validation states */ |
|
89 |
|
90 #ifdef LIBXML_REGEXP_ENABLED |
|
91 xmlAutomataPtr am; /* the automata */ |
|
92 xmlAutomataStatePtr state; /* used to build the automata */ |
|
93 #else |
|
94 void *am; |
|
95 void *state; |
|
96 #endif |
|
97 }; |
|
98 |
|
99 /* |
|
100 * ALL notation declarations are stored in a table. |
|
101 * There is one table per DTD. |
|
102 */ |
|
103 |
|
104 typedef struct _xmlHashTable xmlNotationTable; |
|
105 typedef xmlNotationTable *xmlNotationTablePtr; |
|
106 |
|
107 /* |
|
108 * ALL element declarations are stored in a table. |
|
109 * There is one table per DTD. |
|
110 */ |
|
111 |
|
112 typedef struct _xmlHashTable xmlElementTable; |
|
113 typedef xmlElementTable *xmlElementTablePtr; |
|
114 |
|
115 /* |
|
116 * ALL attribute declarations are stored in a table. |
|
117 * There is one table per DTD. |
|
118 */ |
|
119 |
|
120 typedef struct _xmlHashTable xmlAttributeTable; |
|
121 typedef xmlAttributeTable *xmlAttributeTablePtr; |
|
122 |
|
123 /* |
|
124 * ALL IDs attributes are stored in a table. |
|
125 * There is one table per document. |
|
126 */ |
|
127 |
|
128 typedef struct _xmlHashTable xmlIDTable; |
|
129 typedef xmlIDTable *xmlIDTablePtr; |
|
130 |
|
131 /* |
|
132 * ALL Refs attributes are stored in a table. |
|
133 * There is one table per document. |
|
134 */ |
|
135 |
|
136 typedef struct _xmlHashTable xmlRefTable; |
|
137 typedef xmlRefTable *xmlRefTablePtr; |
|
138 |
|
139 /* Allocate/Release Validation Contexts */ |
|
140 XMLPUBFUN xmlValidCtxtPtr XMLCALL |
|
141 xmlNewValidCtxt(void); |
|
142 XMLPUBFUN void XMLCALL |
|
143 xmlFreeValidCtxt(xmlValidCtxtPtr); |
|
144 |
|
145 /* Notation */ |
|
146 XMLPUBFUN xmlNotationPtr XMLCALL |
|
147 xmlAddNotationDecl (xmlValidCtxtPtr ctxt, |
|
148 xmlDtdPtr dtd, |
|
149 const xmlChar *name, |
|
150 const xmlChar *PublicID, |
|
151 const xmlChar *SystemID); |
|
152 XMLPUBFUN xmlNotationTablePtr XMLCALL |
|
153 xmlCopyNotationTable (xmlNotationTablePtr table); |
|
154 XMLPUBFUN void XMLCALL |
|
155 xmlFreeNotationTable (xmlNotationTablePtr table); |
|
156 #ifdef LIBXML_OUTPUT_ENABLED |
|
157 XMLPUBFUN void XMLCALL |
|
158 xmlDumpNotationDecl (xmlBufferPtr buf, |
|
159 xmlNotationPtr nota); |
|
160 XMLPUBFUN void XMLCALL |
|
161 xmlDumpNotationTable (xmlBufferPtr buf, |
|
162 xmlNotationTablePtr table); |
|
163 #endif /* LIBXML_OUTPUT_ENABLED */ |
|
164 |
|
165 /* Element Content */ |
|
166 XMLPUBFUN xmlElementContentPtr XMLCALL |
|
167 xmlNewElementContent (const xmlChar *name, |
|
168 xmlElementContentType type); |
|
169 XMLPUBFUN xmlElementContentPtr XMLCALL |
|
170 xmlCopyElementContent (xmlElementContentPtr content); |
|
171 XMLPUBFUN void XMLCALL |
|
172 xmlFreeElementContent (xmlElementContentPtr cur); |
|
173 XMLPUBFUN void XMLCALL |
|
174 xmlSnprintfElementContent(char *buf, |
|
175 int size, |
|
176 xmlElementContentPtr content, |
|
177 int glob); |
|
178 /* DEPRECATED */ |
|
179 XMLPUBFUN void XMLCALL |
|
180 xmlSprintfElementContent(char *buf, |
|
181 xmlElementContentPtr content, |
|
182 int glob); |
|
183 /* DEPRECATED */ |
|
184 |
|
185 /* Element */ |
|
186 XMLPUBFUN xmlElementPtr XMLCALL |
|
187 xmlAddElementDecl (xmlValidCtxtPtr ctxt, |
|
188 xmlDtdPtr dtd, |
|
189 const xmlChar *name, |
|
190 xmlElementTypeVal type, |
|
191 xmlElementContentPtr content); |
|
192 XMLPUBFUN xmlElementTablePtr XMLCALL |
|
193 xmlCopyElementTable (xmlElementTablePtr table); |
|
194 XMLPUBFUN void XMLCALL |
|
195 xmlFreeElementTable (xmlElementTablePtr table); |
|
196 #ifdef LIBXML_OUTPUT_ENABLED |
|
197 XMLPUBFUN void XMLCALL |
|
198 xmlDumpElementTable (xmlBufferPtr buf, |
|
199 xmlElementTablePtr table); |
|
200 XMLPUBFUN void XMLCALL |
|
201 xmlDumpElementDecl (xmlBufferPtr buf, |
|
202 xmlElementPtr elem); |
|
203 #endif /* LIBXML_OUTPUT_ENABLED */ |
|
204 |
|
205 /* Enumeration */ |
|
206 XMLPUBFUN xmlEnumerationPtr XMLCALL |
|
207 xmlCreateEnumeration (const xmlChar *name); |
|
208 XMLPUBFUN void XMLCALL |
|
209 xmlFreeEnumeration (xmlEnumerationPtr cur); |
|
210 XMLPUBFUN xmlEnumerationPtr XMLCALL |
|
211 xmlCopyEnumeration (xmlEnumerationPtr cur); |
|
212 |
|
213 /* Attribute */ |
|
214 XMLPUBFUN xmlAttributePtr XMLCALL |
|
215 xmlAddAttributeDecl (xmlValidCtxtPtr ctxt, |
|
216 xmlDtdPtr dtd, |
|
217 const xmlChar *elem, |
|
218 const xmlChar *name, |
|
219 const xmlChar *ns, |
|
220 xmlAttributeType type, |
|
221 xmlAttributeDefault def, |
|
222 const xmlChar *defaultValue, |
|
223 xmlEnumerationPtr tree); |
|
224 XMLPUBFUN xmlAttributeTablePtr XMLCALL |
|
225 xmlCopyAttributeTable (xmlAttributeTablePtr table); |
|
226 XMLPUBFUN void XMLCALL |
|
227 xmlFreeAttributeTable (xmlAttributeTablePtr table); |
|
228 #ifdef LIBXML_OUTPUT_ENABLED |
|
229 XMLPUBFUN void XMLCALL |
|
230 xmlDumpAttributeTable (xmlBufferPtr buf, |
|
231 xmlAttributeTablePtr table); |
|
232 XMLPUBFUN void XMLCALL |
|
233 xmlDumpAttributeDecl (xmlBufferPtr buf, |
|
234 xmlAttributePtr attr); |
|
235 #endif /* LIBXML_OUTPUT_ENABLED */ |
|
236 |
|
237 /* IDs */ |
|
238 XMLPUBFUN xmlIDPtr XMLCALL |
|
239 xmlAddID (xmlValidCtxtPtr ctxt, |
|
240 xmlDocPtr doc, |
|
241 const xmlChar *value, |
|
242 xmlAttrPtr attr); |
|
243 XMLPUBFUN void XMLCALL |
|
244 xmlFreeIDTable (xmlIDTablePtr table); |
|
245 XMLPUBFUN xmlAttrPtr XMLCALL |
|
246 xmlGetID (xmlDocPtr doc, |
|
247 const xmlChar *ID); |
|
248 XMLPUBFUN int XMLCALL |
|
249 xmlIsID (xmlDocPtr doc, |
|
250 xmlNodePtr elem, |
|
251 xmlAttrPtr attr); |
|
252 XMLPUBFUN int XMLCALL |
|
253 xmlRemoveID (xmlDocPtr doc, |
|
254 xmlAttrPtr attr); |
|
255 |
|
256 /* IDREFs */ |
|
257 XMLPUBFUN xmlRefPtr XMLCALL |
|
258 xmlAddRef (xmlValidCtxtPtr ctxt, |
|
259 xmlDocPtr doc, |
|
260 const xmlChar *value, |
|
261 xmlAttrPtr attr); |
|
262 XMLPUBFUN void XMLCALL |
|
263 xmlFreeRefTable (xmlRefTablePtr table); |
|
264 XMLPUBFUN int XMLCALL |
|
265 xmlIsRef (xmlDocPtr doc, |
|
266 xmlNodePtr elem, |
|
267 xmlAttrPtr attr); |
|
268 XMLPUBFUN int XMLCALL |
|
269 xmlRemoveRef (xmlDocPtr doc, |
|
270 xmlAttrPtr attr); |
|
271 |
|
272 #ifndef XMLENGINE_EXCLUDE_UNUSED |
|
273 XMLPUBFUN xmlListPtr XMLCALL |
|
274 xmlGetRefs (xmlDocPtr doc, const xmlChar *ID); |
|
275 #endif /* ifndef XMLENGINE_EXCLUDE_UNUSED */ |
|
276 |
|
277 /** |
|
278 * The public function calls related to validity checking. |
|
279 */ |
|
280 |
|
281 XMLPUBFUN int XMLCALL |
|
282 xmlValidateRoot (xmlValidCtxtPtr ctxt, |
|
283 xmlDocPtr doc); |
|
284 XMLPUBFUN int XMLCALL |
|
285 xmlValidateElementDecl (xmlValidCtxtPtr ctxt, |
|
286 xmlDocPtr doc, |
|
287 xmlElementPtr elem); |
|
288 XMLPUBFUN xmlChar * XMLCALL |
|
289 xmlValidNormalizeAttributeValue(xmlDocPtr doc, |
|
290 xmlNodePtr elem, |
|
291 const xmlChar *name, |
|
292 const xmlChar *value); |
|
293 XMLPUBFUN xmlChar * XMLCALL |
|
294 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, |
|
295 xmlDocPtr doc, |
|
296 xmlNodePtr elem, |
|
297 const xmlChar *name, |
|
298 const xmlChar *value); |
|
299 XMLPUBFUN int XMLCALL |
|
300 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, |
|
301 xmlDocPtr doc, |
|
302 xmlAttributePtr attr); |
|
303 XMLPUBFUN int XMLCALL |
|
304 xmlValidateAttributeValue(xmlAttributeType type, |
|
305 const xmlChar *value); |
|
306 XMLPUBFUN int XMLCALL |
|
307 xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, |
|
308 xmlDocPtr doc, |
|
309 xmlNotationPtr nota); |
|
310 XMLPUBFUN int XMLCALL |
|
311 xmlValidateDtd (xmlValidCtxtPtr ctxt, |
|
312 xmlDocPtr doc, |
|
313 xmlDtdPtr dtd); |
|
314 XMLPUBFUN int XMLCALL |
|
315 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, |
|
316 xmlDocPtr doc); |
|
317 XMLPUBFUN int XMLCALL |
|
318 xmlValidateDocument (xmlValidCtxtPtr ctxt, |
|
319 xmlDocPtr doc); |
|
320 XMLPUBFUN int XMLCALL |
|
321 xmlValidateElement (xmlValidCtxtPtr ctxt, |
|
322 xmlDocPtr doc, |
|
323 xmlNodePtr elem); |
|
324 XMLPUBFUN int XMLCALL |
|
325 xmlValidateOneElement (xmlValidCtxtPtr ctxt, |
|
326 xmlDocPtr doc, |
|
327 xmlNodePtr elem); |
|
328 XMLPUBFUN int XMLCALL |
|
329 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, |
|
330 xmlDocPtr doc, |
|
331 xmlNodePtr elem, |
|
332 xmlAttrPtr attr, |
|
333 const xmlChar *value); |
|
334 XMLPUBFUN int XMLCALL |
|
335 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt, |
|
336 xmlDocPtr doc, |
|
337 xmlNodePtr elem, |
|
338 const xmlChar *prefix, |
|
339 xmlNsPtr ns, |
|
340 const xmlChar *value); |
|
341 XMLPUBFUN int XMLCALL |
|
342 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, |
|
343 xmlDocPtr doc); |
|
344 XMLPUBFUN int XMLCALL |
|
345 xmlValidateNotationUse (xmlValidCtxtPtr ctxt, |
|
346 xmlDocPtr doc, |
|
347 const xmlChar *notationName); |
|
348 XMLPUBFUN int XMLCALL |
|
349 xmlIsMixedElement (xmlDocPtr doc, |
|
350 const xmlChar *name); |
|
351 XMLPUBFUN xmlAttributePtr XMLCALL |
|
352 xmlGetDtdAttrDesc (xmlDtdPtr dtd, |
|
353 const xmlChar *elem, |
|
354 const xmlChar *name); |
|
355 XMLPUBFUN xmlAttributePtr XMLCALL |
|
356 xmlGetDtdQAttrDesc (xmlDtdPtr dtd, |
|
357 const xmlChar *elem, |
|
358 const xmlChar *name, |
|
359 const xmlChar *prefix); |
|
360 XMLPUBFUN xmlNotationPtr XMLCALL |
|
361 xmlGetDtdNotationDesc (xmlDtdPtr dtd, |
|
362 const xmlChar *name); |
|
363 XMLPUBFUN xmlElementPtr XMLCALL |
|
364 xmlGetDtdQElementDesc (xmlDtdPtr dtd, |
|
365 const xmlChar *name, |
|
366 const xmlChar *prefix); |
|
367 XMLPUBFUN xmlElementPtr XMLCALL |
|
368 xmlGetDtdElementDesc (xmlDtdPtr dtd, |
|
369 const xmlChar *name); |
|
370 |
|
371 XMLPUBFUN int XMLCALL |
|
372 xmlValidGetValidElements(xmlNode *prev, |
|
373 xmlNode *next, |
|
374 const xmlChar **names, |
|
375 int max); |
|
376 XMLPUBFUN int XMLCALL |
|
377 xmlValidGetPotentialChildren(xmlElementContent *ctree, |
|
378 const xmlChar **list, |
|
379 int *len, |
|
380 int max); |
|
381 XMLPUBFUN int XMLCALL |
|
382 xmlValidateNameValue (const xmlChar *value); |
|
383 XMLPUBFUN int XMLCALL |
|
384 xmlValidateNamesValue (const xmlChar *value); |
|
385 XMLPUBFUN int XMLCALL |
|
386 xmlValidateNmtokenValue (const xmlChar *value); |
|
387 XMLPUBFUN int XMLCALL |
|
388 xmlValidateNmtokensValue(const xmlChar *value); |
|
389 |
|
390 #ifdef LIBXML_REGEXP_ENABLED |
|
391 /* |
|
392 * Validation based on the regexp support |
|
393 */ |
|
394 XMLPUBFUN int XMLCALL |
|
395 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, |
|
396 xmlElementPtr elem); |
|
397 |
|
398 XMLPUBFUN int XMLCALL |
|
399 xmlValidatePushElement (xmlValidCtxtPtr ctxt, |
|
400 xmlDocPtr doc, |
|
401 xmlNodePtr elem, |
|
402 const xmlChar *qname); |
|
403 XMLPUBFUN int XMLCALL |
|
404 xmlValidatePushCData (xmlValidCtxtPtr ctxt, |
|
405 const xmlChar *data, |
|
406 int len); |
|
407 XMLPUBFUN int XMLCALL |
|
408 xmlValidatePopElement (xmlValidCtxtPtr ctxt, |
|
409 xmlDocPtr doc, |
|
410 xmlNodePtr elem, |
|
411 const xmlChar *qname); |
|
412 #endif /* LIBXML_REGEXP_ENABLED */ |
|
413 #ifdef __cplusplus |
|
414 } |
|
415 #endif |
|
416 #endif /* __XML_VALID_H__ */ |
|
417 |