• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <libxml/tree.h>
17 #include <libxml/list.h>
18 #include <libxml/xmlautomata.h>
19 #include <libxml/xmlregexp.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /*
26  * Validation state added for non-determinist content model.
27  */
28 typedef struct _xmlValidState xmlValidState;
29 typedef xmlValidState *xmlValidStatePtr;
30 
31 /**
32  * xmlValidityErrorFunc:
33  * @ctx:  usually an xmlValidCtxtPtr to a validity error context,
34  *        but comes from ctxt->userData (which normally contains such
35  *        a pointer); ctxt->userData can be changed by the user.
36  * @msg:  the string to format *printf like vararg
37  * @...:  remaining arguments to the format
38  *
39  * Callback called when a validity error is found. This is a message
40  * oriented function similar to an *printf function.
41  */
42 typedef void (*xmlValidityErrorFunc) (void *ctx,
43 			     const char *msg,
44 			     ...) LIBXML_ATTR_FORMAT(2,3);
45 
46 /**
47  * xmlValidityWarningFunc:
48  * @ctx:  usually an xmlValidCtxtPtr to a validity error context,
49  *        but comes from ctxt->userData (which normally contains such
50  *        a pointer); ctxt->userData can be changed by the user.
51  * @msg:  the string to format *printf like vararg
52  * @...:  remaining arguments to the format
53  *
54  * Callback called when a validity warning is found. This is a message
55  * oriented function similar to an *printf function.
56  */
57 typedef void (*xmlValidityWarningFunc) (void *ctx,
58 			       const char *msg,
59 			       ...) LIBXML_ATTR_FORMAT(2,3);
60 
61 /*
62  * xmlValidCtxt:
63  * An xmlValidCtxt is used for error reporting when validating.
64  */
65 typedef struct _xmlValidCtxt xmlValidCtxt;
66 typedef xmlValidCtxt *xmlValidCtxtPtr;
67 struct _xmlValidCtxt {
68     void *userData;			/* user specific data block */
69     xmlValidityErrorFunc error;		/* the callback in case of errors */
70     xmlValidityWarningFunc warning;	/* the callback in case of warning */
71 
72     /* Node analysis stack used when validating within entities */
73     xmlNodePtr         node;          /* Current parsed Node */
74     int                nodeNr;        /* Depth of the parsing stack */
75     int                nodeMax;       /* Max depth of the parsing stack */
76     xmlNodePtr        *nodeTab;       /* array of nodes */
77 
78     unsigned int         flags;       /* internal flags */
79     xmlDocPtr              doc;       /* the document */
80     int                  valid;       /* temporary validity check result */
81 
82     /* state state used for non-determinist content validation */
83     xmlValidState     *vstate;        /* current state */
84     int                vstateNr;      /* Depth of the validation stack */
85     int                vstateMax;     /* Max depth of the validation stack */
86     xmlValidState     *vstateTab;     /* array of validation states */
87 
88 #ifdef LIBXML_REGEXP_ENABLED
89     xmlAutomataPtr            am;     /* the automata */
90     xmlAutomataStatePtr    state;     /* used to build the automata */
91 #else
92     void                     *am;
93     void                  *state;
94 #endif
95 };
96 
97 /*
98  * ALL notation declarations are stored in a table.
99  * There is one table per DTD.
100  */
101 
102 typedef struct _xmlHashTable xmlNotationTable;
103 typedef xmlNotationTable *xmlNotationTablePtr;
104 
105 /*
106  * ALL element declarations are stored in a table.
107  * There is one table per DTD.
108  */
109 
110 typedef struct _xmlHashTable xmlElementTable;
111 typedef xmlElementTable *xmlElementTablePtr;
112 
113 /*
114  * ALL attribute declarations are stored in a table.
115  * There is one table per DTD.
116  */
117 
118 typedef struct _xmlHashTable xmlAttributeTable;
119 typedef xmlAttributeTable *xmlAttributeTablePtr;
120 
121 /*
122  * ALL IDs attributes are stored in a table.
123  * There is one table per document.
124  */
125 
126 typedef struct _xmlHashTable xmlIDTable;
127 typedef xmlIDTable *xmlIDTablePtr;
128 
129 /*
130  * ALL Refs attributes are stored in a table.
131  * There is one table per document.
132  */
133 
134 typedef struct _xmlHashTable xmlRefTable;
135 typedef xmlRefTable *xmlRefTablePtr;
136 
137 /* Notation */
138 XMLPUBFUN xmlNotationPtr
139 		xmlAddNotationDecl	(xmlValidCtxtPtr ctxt,
140 					 xmlDtdPtr dtd,
141 					 const xmlChar *name,
142 					 const xmlChar *PublicID,
143 					 const xmlChar *SystemID);
144 #ifdef LIBXML_TREE_ENABLED
145 XMLPUBFUN xmlNotationTablePtr
146 		xmlCopyNotationTable	(xmlNotationTablePtr table);
147 #endif /* LIBXML_TREE_ENABLED */
148 XMLPUBFUN void
149 		xmlFreeNotationTable	(xmlNotationTablePtr table);
150 #ifdef LIBXML_OUTPUT_ENABLED
151 XML_DEPRECATED
152 XMLPUBFUN void
153 		xmlDumpNotationDecl	(xmlBufferPtr buf,
154 					 xmlNotationPtr nota);
155 /* XML_DEPRECATED, still used in lxml */
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 XML_DEPRECATED
188 XMLPUBFUN void
189 		xmlSprintfElementContent(char *buf,
190 	                                 xmlElementContentPtr content,
191 					 int englob);
192 #endif /* LIBXML_OUTPUT_ENABLED */
193 
194 /* Element */
195 XMLPUBFUN xmlElementPtr
196 		xmlAddElementDecl	(xmlValidCtxtPtr ctxt,
197 					 xmlDtdPtr dtd,
198 					 const xmlChar *name,
199 					 xmlElementTypeVal type,
200 					 xmlElementContentPtr content);
201 #ifdef LIBXML_TREE_ENABLED
202 XMLPUBFUN xmlElementTablePtr
203 		xmlCopyElementTable	(xmlElementTablePtr table);
204 #endif /* LIBXML_TREE_ENABLED */
205 XMLPUBFUN void
206 		xmlFreeElementTable	(xmlElementTablePtr table);
207 #ifdef LIBXML_OUTPUT_ENABLED
208 XML_DEPRECATED
209 XMLPUBFUN void
210 		xmlDumpElementTable	(xmlBufferPtr buf,
211 					 xmlElementTablePtr table);
212 XML_DEPRECATED
213 XMLPUBFUN void
214 		xmlDumpElementDecl	(xmlBufferPtr buf,
215 					 xmlElementPtr elem);
216 #endif /* LIBXML_OUTPUT_ENABLED */
217 
218 /* Enumeration */
219 XMLPUBFUN xmlEnumerationPtr
220 		xmlCreateEnumeration	(const xmlChar *name);
221 XMLPUBFUN void
222 		xmlFreeEnumeration	(xmlEnumerationPtr cur);
223 #ifdef LIBXML_TREE_ENABLED
224 XMLPUBFUN xmlEnumerationPtr
225 		xmlCopyEnumeration	(xmlEnumerationPtr cur);
226 #endif /* LIBXML_TREE_ENABLED */
227 
228 /* Attribute */
229 XMLPUBFUN xmlAttributePtr
230 		xmlAddAttributeDecl	(xmlValidCtxtPtr ctxt,
231 					 xmlDtdPtr dtd,
232 					 const xmlChar *elem,
233 					 const xmlChar *name,
234 					 const xmlChar *ns,
235 					 xmlAttributeType type,
236 					 xmlAttributeDefault def,
237 					 const xmlChar *defaultValue,
238 					 xmlEnumerationPtr tree);
239 #ifdef LIBXML_TREE_ENABLED
240 XMLPUBFUN xmlAttributeTablePtr
241 		xmlCopyAttributeTable  (xmlAttributeTablePtr table);
242 #endif /* LIBXML_TREE_ENABLED */
243 XMLPUBFUN void
244 		xmlFreeAttributeTable  (xmlAttributeTablePtr table);
245 #ifdef LIBXML_OUTPUT_ENABLED
246 XML_DEPRECATED
247 XMLPUBFUN void
248 		xmlDumpAttributeTable  (xmlBufferPtr buf,
249 					xmlAttributeTablePtr table);
250 XML_DEPRECATED
251 XMLPUBFUN void
252 		xmlDumpAttributeDecl   (xmlBufferPtr buf,
253 					xmlAttributePtr attr);
254 #endif /* LIBXML_OUTPUT_ENABLED */
255 
256 /* IDs */
257 XMLPUBFUN int
258 		xmlAddIDSafe	       (xmlAttrPtr attr,
259 					const xmlChar *value);
260 XMLPUBFUN xmlIDPtr
261 		xmlAddID	       (xmlValidCtxtPtr ctxt,
262 					xmlDocPtr doc,
263 					const xmlChar *value,
264 					xmlAttrPtr attr);
265 XMLPUBFUN void
266 		xmlFreeIDTable	       (xmlIDTablePtr table);
267 XMLPUBFUN xmlAttrPtr
268 		xmlGetID	       (xmlDocPtr doc,
269 					const xmlChar *ID);
270 XMLPUBFUN int
271 		xmlIsID		       (xmlDocPtr doc,
272 					xmlNodePtr elem,
273 					xmlAttrPtr attr);
274 XMLPUBFUN int
275 		xmlRemoveID	       (xmlDocPtr doc,
276 					xmlAttrPtr attr);
277 
278 /* IDREFs */
279 XML_DEPRECATED
280 XMLPUBFUN xmlRefPtr
281 		xmlAddRef	       (xmlValidCtxtPtr ctxt,
282 					xmlDocPtr doc,
283 					const xmlChar *value,
284 					xmlAttrPtr attr);
285 XML_DEPRECATED
286 XMLPUBFUN void
287 		xmlFreeRefTable	       (xmlRefTablePtr table);
288 XML_DEPRECATED
289 XMLPUBFUN int
290 		xmlIsRef	       (xmlDocPtr doc,
291 					xmlNodePtr elem,
292 					xmlAttrPtr attr);
293 XML_DEPRECATED
294 XMLPUBFUN int
295 		xmlRemoveRef	       (xmlDocPtr doc,
296 					xmlAttrPtr attr);
297 XML_DEPRECATED
298 XMLPUBFUN xmlListPtr
299 		xmlGetRefs	       (xmlDocPtr doc,
300 					const xmlChar *ID);
301 
302 /**
303  * The public function calls related to validity checking.
304  */
305 #ifdef LIBXML_VALID_ENABLED
306 /* Allocate/Release Validation Contexts */
307 XMLPUBFUN xmlValidCtxtPtr
308 		xmlNewValidCtxt(void);
309 XMLPUBFUN void
310 		xmlFreeValidCtxt(xmlValidCtxtPtr);
311 
312 XML_DEPRECATED
313 XMLPUBFUN int
314 		xmlValidateRoot		(xmlValidCtxtPtr ctxt,
315 					 xmlDocPtr doc);
316 XML_DEPRECATED
317 XMLPUBFUN int
318 		xmlValidateElementDecl	(xmlValidCtxtPtr ctxt,
319 					 xmlDocPtr doc,
320 		                         xmlElementPtr elem);
321 XML_DEPRECATED
322 XMLPUBFUN xmlChar *
323 		xmlValidNormalizeAttributeValue(xmlDocPtr doc,
324 					 xmlNodePtr elem,
325 					 const xmlChar *name,
326 					 const xmlChar *value);
327 XML_DEPRECATED
328 XMLPUBFUN xmlChar *
329 		xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
330 					 xmlDocPtr doc,
331 					 xmlNodePtr elem,
332 					 const xmlChar *name,
333 					 const xmlChar *value);
334 XML_DEPRECATED
335 XMLPUBFUN int
336 		xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
337 					 xmlDocPtr doc,
338 		                         xmlAttributePtr attr);
339 XML_DEPRECATED
340 XMLPUBFUN int
341 		xmlValidateAttributeValue(xmlAttributeType type,
342 					 const xmlChar *value);
343 XML_DEPRECATED
344 XMLPUBFUN int
345 		xmlValidateNotationDecl	(xmlValidCtxtPtr ctxt,
346 					 xmlDocPtr doc,
347 		                         xmlNotationPtr nota);
348 XMLPUBFUN int
349 		xmlValidateDtd		(xmlValidCtxtPtr ctxt,
350 					 xmlDocPtr doc,
351 					 xmlDtdPtr dtd);
352 XML_DEPRECATED
353 XMLPUBFUN int
354 		xmlValidateDtdFinal	(xmlValidCtxtPtr ctxt,
355 					 xmlDocPtr doc);
356 XMLPUBFUN int
357 		xmlValidateDocument	(xmlValidCtxtPtr ctxt,
358 					 xmlDocPtr doc);
359 XMLPUBFUN int
360 		xmlValidateElement	(xmlValidCtxtPtr ctxt,
361 					 xmlDocPtr doc,
362 					 xmlNodePtr elem);
363 XML_DEPRECATED
364 XMLPUBFUN int
365 		xmlValidateOneElement	(xmlValidCtxtPtr ctxt,
366 					 xmlDocPtr doc,
367 		                         xmlNodePtr elem);
368 XML_DEPRECATED
369 XMLPUBFUN int
370 		xmlValidateOneAttribute	(xmlValidCtxtPtr ctxt,
371 					 xmlDocPtr doc,
372 					 xmlNodePtr	elem,
373 					 xmlAttrPtr attr,
374 					 const xmlChar *value);
375 XML_DEPRECATED
376 XMLPUBFUN int
377 		xmlValidateOneNamespace	(xmlValidCtxtPtr ctxt,
378 					 xmlDocPtr doc,
379 					 xmlNodePtr elem,
380 					 const xmlChar *prefix,
381 					 xmlNsPtr ns,
382 					 const xmlChar *value);
383 XML_DEPRECATED
384 XMLPUBFUN int
385 		xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
386 					 xmlDocPtr doc);
387 #endif /* LIBXML_VALID_ENABLED */
388 
389 #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
390 XML_DEPRECATED
391 XMLPUBFUN int
392 		xmlValidateNotationUse	(xmlValidCtxtPtr ctxt,
393 					 xmlDocPtr doc,
394 					 const xmlChar *notationName);
395 #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
396 
397 XMLPUBFUN int
398 		xmlIsMixedElement	(xmlDocPtr doc,
399 					 const xmlChar *name);
400 XMLPUBFUN xmlAttributePtr
401 		xmlGetDtdAttrDesc	(xmlDtdPtr dtd,
402 					 const xmlChar *elem,
403 					 const xmlChar *name);
404 XMLPUBFUN xmlAttributePtr
405 		xmlGetDtdQAttrDesc	(xmlDtdPtr dtd,
406 					 const xmlChar *elem,
407 					 const xmlChar *name,
408 					 const xmlChar *prefix);
409 XMLPUBFUN xmlNotationPtr
410 		xmlGetDtdNotationDesc	(xmlDtdPtr dtd,
411 					 const xmlChar *name);
412 XMLPUBFUN xmlElementPtr
413 		xmlGetDtdQElementDesc	(xmlDtdPtr dtd,
414 					 const xmlChar *name,
415 					 const xmlChar *prefix);
416 XMLPUBFUN xmlElementPtr
417 		xmlGetDtdElementDesc	(xmlDtdPtr dtd,
418 					 const xmlChar *name);
419 
420 #ifdef LIBXML_VALID_ENABLED
421 
422 XMLPUBFUN int
423 		xmlValidGetPotentialChildren(xmlElementContent *ctree,
424 					 const xmlChar **names,
425 					 int *len,
426 					 int max);
427 
428 XMLPUBFUN int
429 		xmlValidGetValidElements(xmlNode *prev,
430 					 xmlNode *next,
431 					 const xmlChar **names,
432 					 int max);
433 XMLPUBFUN int
434 		xmlValidateNameValue	(const xmlChar *value);
435 XMLPUBFUN int
436 		xmlValidateNamesValue	(const xmlChar *value);
437 XMLPUBFUN int
438 		xmlValidateNmtokenValue	(const xmlChar *value);
439 XMLPUBFUN int
440 		xmlValidateNmtokensValue(const xmlChar *value);
441 
442 #ifdef LIBXML_REGEXP_ENABLED
443 /*
444  * Validation based on the regexp support
445  */
446 XML_DEPRECATED
447 XMLPUBFUN int
448 		xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
449 					 xmlElementPtr elem);
450 
451 XML_DEPRECATED
452 XMLPUBFUN int
453 		xmlValidatePushElement	(xmlValidCtxtPtr ctxt,
454 					 xmlDocPtr doc,
455 					 xmlNodePtr elem,
456 					 const xmlChar *qname);
457 XML_DEPRECATED
458 XMLPUBFUN int
459 		xmlValidatePushCData	(xmlValidCtxtPtr ctxt,
460 					 const xmlChar *data,
461 					 int len);
462 XML_DEPRECATED
463 XMLPUBFUN int
464 		xmlValidatePopElement	(xmlValidCtxtPtr ctxt,
465 					 xmlDocPtr doc,
466 					 xmlNodePtr elem,
467 					 const xmlChar *qname);
468 #endif /* LIBXML_REGEXP_ENABLED */
469 #endif /* LIBXML_VALID_ENABLED */
470 #ifdef __cplusplus
471 }
472 #endif
473 #endif /* __XML_VALID_H__ */
474