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 <libxml/xmlversion.h>
15 #include <libxml/xmlerror.h>
16 #define XML_TREE_INTERNALS
17 #include <libxml/tree.h>
18 #undef XML_TREE_INTERNALS
19 #include <libxml/list.h>
20 #include <libxml/xmlautomata.h>
21 #include <libxml/xmlregexp.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /*
28 * Validation state added for non-determinist content model.
29 */
30 typedef struct _xmlValidState xmlValidState;
31 typedef xmlValidState *xmlValidStatePtr;
32
33 /**
34 * xmlValidityErrorFunc:
35 * @ctx: usually an xmlValidCtxtPtr to a validity error context,
36 * but comes from ctxt->userData (which normally contains such
37 * a pointer); ctxt->userData can be changed by the user.
38 * @msg: the string to format *printf like vararg
39 * @...: remaining arguments to the format
40 *
41 * Callback called when a validity error is found. This is a message
42 * oriented function similar to an *printf function.
43 */
44 typedef void (*xmlValidityErrorFunc) (void *ctx,
45 const char *msg,
46 ...) LIBXML_ATTR_FORMAT(2,3);
47
48 /**
49 * xmlValidityWarningFunc:
50 * @ctx: usually an xmlValidCtxtPtr to a validity error context,
51 * but comes from ctxt->userData (which normally contains such
52 * a pointer); ctxt->userData can be changed by the user.
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 ...) LIBXML_ATTR_FORMAT(2,3);
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 unsigned int flags; /* internal flags */
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 /* Notation */
140 XMLPUBFUN xmlNotationPtr
141 xmlAddNotationDecl (xmlValidCtxtPtr ctxt,
142 xmlDtdPtr dtd,
143 const xmlChar *name,
144 const xmlChar *PublicID,
145 const xmlChar *SystemID);
146 #ifdef LIBXML_TREE_ENABLED
147 XMLPUBFUN xmlNotationTablePtr
148 xmlCopyNotationTable (xmlNotationTablePtr table);
149 #endif /* LIBXML_TREE_ENABLED */
150 XMLPUBFUN void
151 xmlFreeNotationTable (xmlNotationTablePtr table);
152 #ifdef LIBXML_OUTPUT_ENABLED
153 XMLPUBFUN void
154 xmlDumpNotationDecl (xmlBufferPtr buf,
155 xmlNotationPtr nota);
156 XMLPUBFUN void
157 xmlDumpNotationTable (xmlBufferPtr buf,
158 xmlNotationTablePtr table);
159 #endif /* LIBXML_OUTPUT_ENABLED */
160
161 /* Element Content */
162 /* the non Doc version are being deprecated */
163 XMLPUBFUN xmlElementContentPtr
164 xmlNewElementContent (const xmlChar *name,
165 xmlElementContentType type);
166 XMLPUBFUN xmlElementContentPtr
167 xmlCopyElementContent (xmlElementContentPtr content);
168 XMLPUBFUN void
169 xmlFreeElementContent (xmlElementContentPtr cur);
170 /* the new versions with doc argument */
171 XMLPUBFUN xmlElementContentPtr
172 xmlNewDocElementContent (xmlDocPtr doc,
173 const xmlChar *name,
174 xmlElementContentType type);
175 XMLPUBFUN xmlElementContentPtr
176 xmlCopyDocElementContent(xmlDocPtr doc,
177 xmlElementContentPtr content);
178 XMLPUBFUN void
179 xmlFreeDocElementContent(xmlDocPtr doc,
180 xmlElementContentPtr cur);
181 XMLPUBFUN void
182 xmlSnprintfElementContent(char *buf,
183 int size,
184 xmlElementContentPtr content,
185 int englob);
186 #ifdef LIBXML_OUTPUT_ENABLED
187 /* DEPRECATED */
188 XMLPUBFUN void
189 xmlSprintfElementContent(char *buf,
190 xmlElementContentPtr content,
191 int englob);
192 #endif /* LIBXML_OUTPUT_ENABLED */
193 /* DEPRECATED */
194
195 /* Element */
196 XMLPUBFUN xmlElementPtr
197 xmlAddElementDecl (xmlValidCtxtPtr ctxt,
198 xmlDtdPtr dtd,
199 const xmlChar *name,
200 xmlElementTypeVal type,
201 xmlElementContentPtr content);
202 #ifdef LIBXML_TREE_ENABLED
203 XMLPUBFUN xmlElementTablePtr
204 xmlCopyElementTable (xmlElementTablePtr table);
205 #endif /* LIBXML_TREE_ENABLED */
206 XMLPUBFUN void
207 xmlFreeElementTable (xmlElementTablePtr table);
208 #ifdef LIBXML_OUTPUT_ENABLED
209 XMLPUBFUN void
210 xmlDumpElementTable (xmlBufferPtr buf,
211 xmlElementTablePtr table);
212 XMLPUBFUN void
213 xmlDumpElementDecl (xmlBufferPtr buf,
214 xmlElementPtr elem);
215 #endif /* LIBXML_OUTPUT_ENABLED */
216
217 /* Enumeration */
218 XMLPUBFUN xmlEnumerationPtr
219 xmlCreateEnumeration (const xmlChar *name);
220 XMLPUBFUN void
221 xmlFreeEnumeration (xmlEnumerationPtr cur);
222 #ifdef LIBXML_TREE_ENABLED
223 XMLPUBFUN xmlEnumerationPtr
224 xmlCopyEnumeration (xmlEnumerationPtr cur);
225 #endif /* LIBXML_TREE_ENABLED */
226
227 /* Attribute */
228 XMLPUBFUN xmlAttributePtr
229 xmlAddAttributeDecl (xmlValidCtxtPtr ctxt,
230 xmlDtdPtr dtd,
231 const xmlChar *elem,
232 const xmlChar *name,
233 const xmlChar *ns,
234 xmlAttributeType type,
235 xmlAttributeDefault def,
236 const xmlChar *defaultValue,
237 xmlEnumerationPtr tree);
238 #ifdef LIBXML_TREE_ENABLED
239 XMLPUBFUN xmlAttributeTablePtr
240 xmlCopyAttributeTable (xmlAttributeTablePtr table);
241 #endif /* LIBXML_TREE_ENABLED */
242 XMLPUBFUN void
243 xmlFreeAttributeTable (xmlAttributeTablePtr table);
244 #ifdef LIBXML_OUTPUT_ENABLED
245 XMLPUBFUN void
246 xmlDumpAttributeTable (xmlBufferPtr buf,
247 xmlAttributeTablePtr table);
248 XMLPUBFUN void
249 xmlDumpAttributeDecl (xmlBufferPtr buf,
250 xmlAttributePtr attr);
251 #endif /* LIBXML_OUTPUT_ENABLED */
252
253 /* IDs */
254 XMLPUBFUN xmlIDPtr
255 xmlAddID (xmlValidCtxtPtr ctxt,
256 xmlDocPtr doc,
257 const xmlChar *value,
258 xmlAttrPtr attr);
259 XMLPUBFUN void
260 xmlFreeIDTable (xmlIDTablePtr table);
261 XMLPUBFUN xmlAttrPtr
262 xmlGetID (xmlDocPtr doc,
263 const xmlChar *ID);
264 XMLPUBFUN int
265 xmlIsID (xmlDocPtr doc,
266 xmlNodePtr elem,
267 xmlAttrPtr attr);
268 XMLPUBFUN int
269 xmlRemoveID (xmlDocPtr doc,
270 xmlAttrPtr attr);
271
272 /* IDREFs */
273 XML_DEPRECATED
274 XMLPUBFUN xmlRefPtr
275 xmlAddRef (xmlValidCtxtPtr ctxt,
276 xmlDocPtr doc,
277 const xmlChar *value,
278 xmlAttrPtr attr);
279 XML_DEPRECATED
280 XMLPUBFUN void
281 xmlFreeRefTable (xmlRefTablePtr table);
282 XML_DEPRECATED
283 XMLPUBFUN int
284 xmlIsRef (xmlDocPtr doc,
285 xmlNodePtr elem,
286 xmlAttrPtr attr);
287 XML_DEPRECATED
288 XMLPUBFUN int
289 xmlRemoveRef (xmlDocPtr doc,
290 xmlAttrPtr attr);
291 XML_DEPRECATED
292 XMLPUBFUN xmlListPtr
293 xmlGetRefs (xmlDocPtr doc,
294 const xmlChar *ID);
295
296 /**
297 * The public function calls related to validity checking.
298 */
299 #ifdef LIBXML_VALID_ENABLED
300 /* Allocate/Release Validation Contexts */
301 XMLPUBFUN xmlValidCtxtPtr
302 xmlNewValidCtxt(void);
303 XMLPUBFUN void
304 xmlFreeValidCtxt(xmlValidCtxtPtr);
305
306 XMLPUBFUN int
307 xmlValidateRoot (xmlValidCtxtPtr ctxt,
308 xmlDocPtr doc);
309 XMLPUBFUN int
310 xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
311 xmlDocPtr doc,
312 xmlElementPtr elem);
313 XMLPUBFUN xmlChar *
314 xmlValidNormalizeAttributeValue(xmlDocPtr doc,
315 xmlNodePtr elem,
316 const xmlChar *name,
317 const xmlChar *value);
318 XMLPUBFUN xmlChar *
319 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
320 xmlDocPtr doc,
321 xmlNodePtr elem,
322 const xmlChar *name,
323 const xmlChar *value);
324 XMLPUBFUN int
325 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
326 xmlDocPtr doc,
327 xmlAttributePtr attr);
328 XMLPUBFUN int
329 xmlValidateAttributeValue(xmlAttributeType type,
330 const xmlChar *value);
331 XMLPUBFUN int
332 xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
333 xmlDocPtr doc,
334 xmlNotationPtr nota);
335 XMLPUBFUN int
336 xmlValidateDtd (xmlValidCtxtPtr ctxt,
337 xmlDocPtr doc,
338 xmlDtdPtr dtd);
339 XMLPUBFUN int
340 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
341 xmlDocPtr doc);
342 XMLPUBFUN int
343 xmlValidateDocument (xmlValidCtxtPtr ctxt,
344 xmlDocPtr doc);
345 XMLPUBFUN int
346 xmlValidateElement (xmlValidCtxtPtr ctxt,
347 xmlDocPtr doc,
348 xmlNodePtr elem);
349 XMLPUBFUN int
350 xmlValidateOneElement (xmlValidCtxtPtr ctxt,
351 xmlDocPtr doc,
352 xmlNodePtr elem);
353 XMLPUBFUN int
354 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
355 xmlDocPtr doc,
356 xmlNodePtr elem,
357 xmlAttrPtr attr,
358 const xmlChar *value);
359 XMLPUBFUN int
360 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,
361 xmlDocPtr doc,
362 xmlNodePtr elem,
363 const xmlChar *prefix,
364 xmlNsPtr ns,
365 const xmlChar *value);
366 XMLPUBFUN int
367 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
368 xmlDocPtr doc);
369 #endif /* LIBXML_VALID_ENABLED */
370
371 #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
372 XMLPUBFUN int
373 xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
374 xmlDocPtr doc,
375 const xmlChar *notationName);
376 #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
377
378 XMLPUBFUN int
379 xmlIsMixedElement (xmlDocPtr doc,
380 const xmlChar *name);
381 XMLPUBFUN xmlAttributePtr
382 xmlGetDtdAttrDesc (xmlDtdPtr dtd,
383 const xmlChar *elem,
384 const xmlChar *name);
385 XMLPUBFUN xmlAttributePtr
386 xmlGetDtdQAttrDesc (xmlDtdPtr dtd,
387 const xmlChar *elem,
388 const xmlChar *name,
389 const xmlChar *prefix);
390 XMLPUBFUN xmlNotationPtr
391 xmlGetDtdNotationDesc (xmlDtdPtr dtd,
392 const xmlChar *name);
393 XMLPUBFUN xmlElementPtr
394 xmlGetDtdQElementDesc (xmlDtdPtr dtd,
395 const xmlChar *name,
396 const xmlChar *prefix);
397 XMLPUBFUN xmlElementPtr
398 xmlGetDtdElementDesc (xmlDtdPtr dtd,
399 const xmlChar *name);
400
401 #ifdef LIBXML_VALID_ENABLED
402
403 XMLPUBFUN int
404 xmlValidGetPotentialChildren(xmlElementContent *ctree,
405 const xmlChar **names,
406 int *len,
407 int max);
408
409 XMLPUBFUN int
410 xmlValidGetValidElements(xmlNode *prev,
411 xmlNode *next,
412 const xmlChar **names,
413 int max);
414 XMLPUBFUN int
415 xmlValidateNameValue (const xmlChar *value);
416 XMLPUBFUN int
417 xmlValidateNamesValue (const xmlChar *value);
418 XMLPUBFUN int
419 xmlValidateNmtokenValue (const xmlChar *value);
420 XMLPUBFUN int
421 xmlValidateNmtokensValue(const xmlChar *value);
422
423 #ifdef LIBXML_REGEXP_ENABLED
424 /*
425 * Validation based on the regexp support
426 */
427 XMLPUBFUN int
428 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
429 xmlElementPtr elem);
430
431 XMLPUBFUN int
432 xmlValidatePushElement (xmlValidCtxtPtr ctxt,
433 xmlDocPtr doc,
434 xmlNodePtr elem,
435 const xmlChar *qname);
436 XMLPUBFUN int
437 xmlValidatePushCData (xmlValidCtxtPtr ctxt,
438 const xmlChar *data,
439 int len);
440 XMLPUBFUN int
441 xmlValidatePopElement (xmlValidCtxtPtr ctxt,
442 xmlDocPtr doc,
443 xmlNodePtr elem,
444 const xmlChar *qname);
445 #endif /* LIBXML_REGEXP_ENABLED */
446 #endif /* LIBXML_VALID_ENABLED */
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif /* __XML_VALID_H__ */