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