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