Reactos
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
24extern "C" {
25#endif
26
27/*
28 * Validation state added for non-determinist content model.
29 */
30typedef struct _xmlValidState xmlValidState;
31typedef 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 */
44typedef 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 */
59typedef 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 */
67typedef struct _xmlValidCtxt xmlValidCtxt;
68typedef xmlValidCtxt *xmlValidCtxtPtr;
69struct _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
104typedef struct _xmlHashTable xmlNotationTable;
105typedef xmlNotationTable *xmlNotationTablePtr;
106
107/*
108 * ALL element declarations are stored in a table.
109 * There is one table per DTD.
110 */
111
112typedef struct _xmlHashTable xmlElementTable;
113typedef xmlElementTable *xmlElementTablePtr;
114
115/*
116 * ALL attribute declarations are stored in a table.
117 * There is one table per DTD.
118 */
119
120typedef struct _xmlHashTable xmlAttributeTable;
121typedef xmlAttributeTable *xmlAttributeTablePtr;
122
123/*
124 * ALL IDs attributes are stored in a table.
125 * There is one table per document.
126 */
127
128typedef struct _xmlHashTable xmlIDTable;
129typedef xmlIDTable *xmlIDTablePtr;
130
131/*
132 * ALL Refs attributes are stored in a table.
133 * There is one table per document.
134 */
135
136typedef struct _xmlHashTable xmlRefTable;
137typedef xmlRefTable *xmlRefTablePtr;
138
139/* Notation */
140XMLPUBFUN 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
147XMLPUBFUN xmlNotationTablePtr
148 xmlCopyNotationTable (xmlNotationTablePtr table);
149#endif /* LIBXML_TREE_ENABLED */
150XMLPUBFUN void
151 xmlFreeNotationTable (xmlNotationTablePtr table);
152#ifdef LIBXML_OUTPUT_ENABLED
153XMLPUBFUN void
154 xmlDumpNotationDecl (xmlBufferPtr buf,
155 xmlNotationPtr nota);
156XMLPUBFUN 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 */
163XMLPUBFUN xmlElementContentPtr
164 xmlNewElementContent (const xmlChar *name,
165 xmlElementContentType type);
166XMLPUBFUN xmlElementContentPtr
167 xmlCopyElementContent (xmlElementContentPtr content);
168XMLPUBFUN void
169 xmlFreeElementContent (xmlElementContentPtr cur);
170/* the new versions with doc argument */
171XMLPUBFUN xmlElementContentPtr
172 xmlNewDocElementContent (xmlDocPtr doc,
173 const xmlChar *name,
174 xmlElementContentType type);
175XMLPUBFUN xmlElementContentPtr
176 xmlCopyDocElementContent(xmlDocPtr doc,
177 xmlElementContentPtr content);
178XMLPUBFUN void
179 xmlFreeDocElementContent(xmlDocPtr doc,
180 xmlElementContentPtr cur);
181XMLPUBFUN void
182 xmlSnprintfElementContent(char *buf,
183 int size,
184 xmlElementContentPtr content,
185 int englob);
186#ifdef LIBXML_OUTPUT_ENABLED
187/* DEPRECATED */
188XMLPUBFUN void
189 xmlSprintfElementContent(char *buf,
190 xmlElementContentPtr content,
191 int englob);
192#endif /* LIBXML_OUTPUT_ENABLED */
193/* DEPRECATED */
194
195/* Element */
196XMLPUBFUN xmlElementPtr
197 xmlAddElementDecl (xmlValidCtxtPtr ctxt,
198 xmlDtdPtr dtd,
199 const xmlChar *name,
200 xmlElementTypeVal type,
201 xmlElementContentPtr content);
202#ifdef LIBXML_TREE_ENABLED
203XMLPUBFUN xmlElementTablePtr
204 xmlCopyElementTable (xmlElementTablePtr table);
205#endif /* LIBXML_TREE_ENABLED */
206XMLPUBFUN void
207 xmlFreeElementTable (xmlElementTablePtr table);
208#ifdef LIBXML_OUTPUT_ENABLED
209XMLPUBFUN void
210 xmlDumpElementTable (xmlBufferPtr buf,
211 xmlElementTablePtr table);
212XMLPUBFUN void
213 xmlDumpElementDecl (xmlBufferPtr buf,
214 xmlElementPtr elem);
215#endif /* LIBXML_OUTPUT_ENABLED */
216
217/* Enumeration */
218XMLPUBFUN xmlEnumerationPtr
219 xmlCreateEnumeration (const xmlChar *name);
220XMLPUBFUN void
221 xmlFreeEnumeration (xmlEnumerationPtr cur);
222#ifdef LIBXML_TREE_ENABLED
223XMLPUBFUN xmlEnumerationPtr
224 xmlCopyEnumeration (xmlEnumerationPtr cur);
225#endif /* LIBXML_TREE_ENABLED */
226
227/* Attribute */
228XMLPUBFUN 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
239XMLPUBFUN xmlAttributeTablePtr
240 xmlCopyAttributeTable (xmlAttributeTablePtr table);
241#endif /* LIBXML_TREE_ENABLED */
242XMLPUBFUN void
243 xmlFreeAttributeTable (xmlAttributeTablePtr table);
244#ifdef LIBXML_OUTPUT_ENABLED
245XMLPUBFUN void
246 xmlDumpAttributeTable (xmlBufferPtr buf,
247 xmlAttributeTablePtr table);
248XMLPUBFUN void
249 xmlDumpAttributeDecl (xmlBufferPtr buf,
250 xmlAttributePtr attr);
251#endif /* LIBXML_OUTPUT_ENABLED */
252
253/* IDs */
254XMLPUBFUN xmlIDPtr
255 xmlAddID (xmlValidCtxtPtr ctxt,
256 xmlDocPtr doc,
257 const xmlChar *value,
258 xmlAttrPtr attr);
259XMLPUBFUN void
260 xmlFreeIDTable (xmlIDTablePtr table);
261XMLPUBFUN xmlAttrPtr
262 xmlGetID (xmlDocPtr doc,
263 const xmlChar *ID);
264XMLPUBFUN int
265 xmlIsID (xmlDocPtr doc,
266 xmlNodePtr elem,
267 xmlAttrPtr attr);
268XMLPUBFUN int
269 xmlRemoveID (xmlDocPtr doc,
270 xmlAttrPtr attr);
271
272/* IDREFs */
273XML_DEPRECATED
274XMLPUBFUN xmlRefPtr
275 xmlAddRef (xmlValidCtxtPtr ctxt,
276 xmlDocPtr doc,
277 const xmlChar *value,
278 xmlAttrPtr attr);
279XML_DEPRECATED
280XMLPUBFUN void
281 xmlFreeRefTable (xmlRefTablePtr table);
282XML_DEPRECATED
283XMLPUBFUN int
284 xmlIsRef (xmlDocPtr doc,
285 xmlNodePtr elem,
286 xmlAttrPtr attr);
287XML_DEPRECATED
288XMLPUBFUN int
289 xmlRemoveRef (xmlDocPtr doc,
290 xmlAttrPtr attr);
291XML_DEPRECATED
292XMLPUBFUN 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 */
301XMLPUBFUN xmlValidCtxtPtr
302 xmlNewValidCtxt(void);
303XMLPUBFUN void
304 xmlFreeValidCtxt(xmlValidCtxtPtr);
305
306XMLPUBFUN int
307 xmlValidateRoot (xmlValidCtxtPtr ctxt,
308 xmlDocPtr doc);
309XMLPUBFUN int
310 xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
311 xmlDocPtr doc,
312 xmlElementPtr elem);
313XMLPUBFUN xmlChar *
314 xmlValidNormalizeAttributeValue(xmlDocPtr doc,
315 xmlNodePtr elem,
316 const xmlChar *name,
317 const xmlChar *value);
318XMLPUBFUN xmlChar *
319 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
320 xmlDocPtr doc,
321 xmlNodePtr elem,
322 const xmlChar *name,
323 const xmlChar *value);
324XMLPUBFUN int
325 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
326 xmlDocPtr doc,
327 xmlAttributePtr attr);
328XMLPUBFUN int
329 xmlValidateAttributeValue(xmlAttributeType type,
330 const xmlChar *value);
331XMLPUBFUN int
332 xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
333 xmlDocPtr doc,
334 xmlNotationPtr nota);
335XMLPUBFUN int
336 xmlValidateDtd (xmlValidCtxtPtr ctxt,
337 xmlDocPtr doc,
338 xmlDtdPtr dtd);
339XMLPUBFUN int
340 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
341 xmlDocPtr doc);
342XMLPUBFUN int
343 xmlValidateDocument (xmlValidCtxtPtr ctxt,
344 xmlDocPtr doc);
345XMLPUBFUN int
346 xmlValidateElement (xmlValidCtxtPtr ctxt,
347 xmlDocPtr doc,
348 xmlNodePtr elem);
349XMLPUBFUN int
350 xmlValidateOneElement (xmlValidCtxtPtr ctxt,
351 xmlDocPtr doc,
352 xmlNodePtr elem);
353XMLPUBFUN int
354 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
355 xmlDocPtr doc,
356 xmlNodePtr elem,
357 xmlAttrPtr attr,
358 const xmlChar *value);
359XMLPUBFUN int
360 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,
361 xmlDocPtr doc,
362 xmlNodePtr elem,
363 const xmlChar *prefix,
364 xmlNsPtr ns,
365 const xmlChar *value);
366XMLPUBFUN int
367 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
368 xmlDocPtr doc);
369#endif /* LIBXML_VALID_ENABLED */
370
371#if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
372XMLPUBFUN int
373 xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
374 xmlDocPtr doc,
375 const xmlChar *notationName);
376#endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
377
378XMLPUBFUN int
379 xmlIsMixedElement (xmlDocPtr doc,
380 const xmlChar *name);
381XMLPUBFUN xmlAttributePtr
382 xmlGetDtdAttrDesc (xmlDtdPtr dtd,
383 const xmlChar *elem,
384 const xmlChar *name);
385XMLPUBFUN xmlAttributePtr
386 xmlGetDtdQAttrDesc (xmlDtdPtr dtd,
387 const xmlChar *elem,
388 const xmlChar *name,
389 const xmlChar *prefix);
390XMLPUBFUN xmlNotationPtr
391 xmlGetDtdNotationDesc (xmlDtdPtr dtd,
392 const xmlChar *name);
393XMLPUBFUN xmlElementPtr
394 xmlGetDtdQElementDesc (xmlDtdPtr dtd,
395 const xmlChar *name,
396 const xmlChar *prefix);
397XMLPUBFUN xmlElementPtr
398 xmlGetDtdElementDesc (xmlDtdPtr dtd,
399 const xmlChar *name);
400
401#ifdef LIBXML_VALID_ENABLED
402
403XMLPUBFUN int
404 xmlValidGetPotentialChildren(xmlElementContent *ctree,
405 const xmlChar **names,
406 int *len,
407 int max);
408
409XMLPUBFUN int
410 xmlValidGetValidElements(xmlNode *prev,
411 xmlNode *next,
412 const xmlChar **names,
413 int max);
414XMLPUBFUN int
415 xmlValidateNameValue (const xmlChar *value);
416XMLPUBFUN int
417 xmlValidateNamesValue (const xmlChar *value);
418XMLPUBFUN int
419 xmlValidateNmtokenValue (const xmlChar *value);
420XMLPUBFUN int
421 xmlValidateNmtokensValue(const xmlChar *value);
422
423#ifdef LIBXML_REGEXP_ENABLED
424/*
425 * Validation based on the regexp support
426 */
427XMLPUBFUN int
428 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
429 xmlElementPtr elem);
430
431XMLPUBFUN int
432 xmlValidatePushElement (xmlValidCtxtPtr ctxt,
433 xmlDocPtr doc,
434 xmlNodePtr elem,
435 const xmlChar *qname);
436XMLPUBFUN int
437 xmlValidatePushCData (xmlValidCtxtPtr ctxt,
438 const xmlChar *data,
439 int len);
440XMLPUBFUN 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__ */