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 XMLPUBFUN void 152 xmlDumpNotationDecl (xmlBufferPtr buf, 153 xmlNotationPtr nota); 154 XMLPUBFUN void 155 xmlDumpNotationTable (xmlBufferPtr buf, 156 xmlNotationTablePtr table); 157 #endif /* LIBXML_OUTPUT_ENABLED */ 158 159 /* Element Content */ 160 /* the non Doc version are being deprecated */ 161 XMLPUBFUN xmlElementContentPtr 162 xmlNewElementContent (const xmlChar *name, 163 xmlElementContentType type); 164 XMLPUBFUN xmlElementContentPtr 165 xmlCopyElementContent (xmlElementContentPtr content); 166 XMLPUBFUN void 167 xmlFreeElementContent (xmlElementContentPtr cur); 168 /* the new versions with doc argument */ 169 XMLPUBFUN xmlElementContentPtr 170 xmlNewDocElementContent (xmlDocPtr doc, 171 const xmlChar *name, 172 xmlElementContentType type); 173 XMLPUBFUN xmlElementContentPtr 174 xmlCopyDocElementContent(xmlDocPtr doc, 175 xmlElementContentPtr content); 176 XMLPUBFUN void 177 xmlFreeDocElementContent(xmlDocPtr doc, 178 xmlElementContentPtr cur); 179 XMLPUBFUN void 180 xmlSnprintfElementContent(char *buf, 181 int size, 182 xmlElementContentPtr content, 183 int englob); 184 #ifdef LIBXML_OUTPUT_ENABLED 185 /* DEPRECATED */ 186 XMLPUBFUN void 187 xmlSprintfElementContent(char *buf, 188 xmlElementContentPtr content, 189 int englob); 190 #endif /* LIBXML_OUTPUT_ENABLED */ 191 /* DEPRECATED */ 192 193 /* Element */ 194 XMLPUBFUN xmlElementPtr 195 xmlAddElementDecl (xmlValidCtxtPtr ctxt, 196 xmlDtdPtr dtd, 197 const xmlChar *name, 198 xmlElementTypeVal type, 199 xmlElementContentPtr content); 200 #ifdef LIBXML_TREE_ENABLED 201 XMLPUBFUN xmlElementTablePtr 202 xmlCopyElementTable (xmlElementTablePtr table); 203 #endif /* LIBXML_TREE_ENABLED */ 204 XMLPUBFUN void 205 xmlFreeElementTable (xmlElementTablePtr table); 206 #ifdef LIBXML_OUTPUT_ENABLED 207 XMLPUBFUN void 208 xmlDumpElementTable (xmlBufferPtr buf, 209 xmlElementTablePtr table); 210 XMLPUBFUN void 211 xmlDumpElementDecl (xmlBufferPtr buf, 212 xmlElementPtr elem); 213 #endif /* LIBXML_OUTPUT_ENABLED */ 214 215 /* Enumeration */ 216 XMLPUBFUN xmlEnumerationPtr 217 xmlCreateEnumeration (const xmlChar *name); 218 XMLPUBFUN void 219 xmlFreeEnumeration (xmlEnumerationPtr cur); 220 #ifdef LIBXML_TREE_ENABLED 221 XMLPUBFUN xmlEnumerationPtr 222 xmlCopyEnumeration (xmlEnumerationPtr cur); 223 #endif /* LIBXML_TREE_ENABLED */ 224 225 /* Attribute */ 226 XMLPUBFUN xmlAttributePtr 227 xmlAddAttributeDecl (xmlValidCtxtPtr ctxt, 228 xmlDtdPtr dtd, 229 const xmlChar *elem, 230 const xmlChar *name, 231 const xmlChar *ns, 232 xmlAttributeType type, 233 xmlAttributeDefault def, 234 const xmlChar *defaultValue, 235 xmlEnumerationPtr tree); 236 #ifdef LIBXML_TREE_ENABLED 237 XMLPUBFUN xmlAttributeTablePtr 238 xmlCopyAttributeTable (xmlAttributeTablePtr table); 239 #endif /* LIBXML_TREE_ENABLED */ 240 XMLPUBFUN void 241 xmlFreeAttributeTable (xmlAttributeTablePtr table); 242 #ifdef LIBXML_OUTPUT_ENABLED 243 XMLPUBFUN void 244 xmlDumpAttributeTable (xmlBufferPtr buf, 245 xmlAttributeTablePtr table); 246 XMLPUBFUN void 247 xmlDumpAttributeDecl (xmlBufferPtr buf, 248 xmlAttributePtr attr); 249 #endif /* LIBXML_OUTPUT_ENABLED */ 250 251 /* IDs */ 252 XMLPUBFUN xmlIDPtr 253 xmlAddID (xmlValidCtxtPtr ctxt, 254 xmlDocPtr doc, 255 const xmlChar *value, 256 xmlAttrPtr attr); 257 XMLPUBFUN void 258 xmlFreeIDTable (xmlIDTablePtr table); 259 XMLPUBFUN xmlAttrPtr 260 xmlGetID (xmlDocPtr doc, 261 const xmlChar *ID); 262 XMLPUBFUN int 263 xmlIsID (xmlDocPtr doc, 264 xmlNodePtr elem, 265 xmlAttrPtr attr); 266 XMLPUBFUN int 267 xmlRemoveID (xmlDocPtr doc, 268 xmlAttrPtr attr); 269 270 /* IDREFs */ 271 XML_DEPRECATED 272 XMLPUBFUN xmlRefPtr 273 xmlAddRef (xmlValidCtxtPtr ctxt, 274 xmlDocPtr doc, 275 const xmlChar *value, 276 xmlAttrPtr attr); 277 XML_DEPRECATED 278 XMLPUBFUN void 279 xmlFreeRefTable (xmlRefTablePtr table); 280 XML_DEPRECATED 281 XMLPUBFUN int 282 xmlIsRef (xmlDocPtr doc, 283 xmlNodePtr elem, 284 xmlAttrPtr attr); 285 XML_DEPRECATED 286 XMLPUBFUN int 287 xmlRemoveRef (xmlDocPtr doc, 288 xmlAttrPtr attr); 289 XML_DEPRECATED 290 XMLPUBFUN xmlListPtr 291 xmlGetRefs (xmlDocPtr doc, 292 const xmlChar *ID); 293 294 /** 295 * The public function calls related to validity checking. 296 */ 297 #ifdef LIBXML_VALID_ENABLED 298 /* Allocate/Release Validation Contexts */ 299 XMLPUBFUN xmlValidCtxtPtr 300 xmlNewValidCtxt(void); 301 XMLPUBFUN void 302 xmlFreeValidCtxt(xmlValidCtxtPtr); 303 304 XMLPUBFUN int 305 xmlValidateRoot (xmlValidCtxtPtr ctxt, 306 xmlDocPtr doc); 307 XMLPUBFUN int 308 xmlValidateElementDecl (xmlValidCtxtPtr ctxt, 309 xmlDocPtr doc, 310 xmlElementPtr elem); 311 XMLPUBFUN xmlChar * 312 xmlValidNormalizeAttributeValue(xmlDocPtr doc, 313 xmlNodePtr elem, 314 const xmlChar *name, 315 const xmlChar *value); 316 XMLPUBFUN xmlChar * 317 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, 318 xmlDocPtr doc, 319 xmlNodePtr elem, 320 const xmlChar *name, 321 const xmlChar *value); 322 XMLPUBFUN int 323 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, 324 xmlDocPtr doc, 325 xmlAttributePtr attr); 326 XMLPUBFUN int 327 xmlValidateAttributeValue(xmlAttributeType type, 328 const xmlChar *value); 329 XMLPUBFUN int 330 xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, 331 xmlDocPtr doc, 332 xmlNotationPtr nota); 333 XMLPUBFUN int 334 xmlValidateDtd (xmlValidCtxtPtr ctxt, 335 xmlDocPtr doc, 336 xmlDtdPtr dtd); 337 XMLPUBFUN int 338 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, 339 xmlDocPtr doc); 340 XMLPUBFUN int 341 xmlValidateDocument (xmlValidCtxtPtr ctxt, 342 xmlDocPtr doc); 343 XMLPUBFUN int 344 xmlValidateElement (xmlValidCtxtPtr ctxt, 345 xmlDocPtr doc, 346 xmlNodePtr elem); 347 XMLPUBFUN int 348 xmlValidateOneElement (xmlValidCtxtPtr ctxt, 349 xmlDocPtr doc, 350 xmlNodePtr elem); 351 XMLPUBFUN int 352 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, 353 xmlDocPtr doc, 354 xmlNodePtr elem, 355 xmlAttrPtr attr, 356 const xmlChar *value); 357 XMLPUBFUN int 358 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt, 359 xmlDocPtr doc, 360 xmlNodePtr elem, 361 const xmlChar *prefix, 362 xmlNsPtr ns, 363 const xmlChar *value); 364 XMLPUBFUN int 365 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, 366 xmlDocPtr doc); 367 #endif /* LIBXML_VALID_ENABLED */ 368 369 #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) 370 XMLPUBFUN int 371 xmlValidateNotationUse (xmlValidCtxtPtr ctxt, 372 xmlDocPtr doc, 373 const xmlChar *notationName); 374 #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */ 375 376 XMLPUBFUN int 377 xmlIsMixedElement (xmlDocPtr doc, 378 const xmlChar *name); 379 XMLPUBFUN xmlAttributePtr 380 xmlGetDtdAttrDesc (xmlDtdPtr dtd, 381 const xmlChar *elem, 382 const xmlChar *name); 383 XMLPUBFUN xmlAttributePtr 384 xmlGetDtdQAttrDesc (xmlDtdPtr dtd, 385 const xmlChar *elem, 386 const xmlChar *name, 387 const xmlChar *prefix); 388 XMLPUBFUN xmlNotationPtr 389 xmlGetDtdNotationDesc (xmlDtdPtr dtd, 390 const xmlChar *name); 391 XMLPUBFUN xmlElementPtr 392 xmlGetDtdQElementDesc (xmlDtdPtr dtd, 393 const xmlChar *name, 394 const xmlChar *prefix); 395 XMLPUBFUN xmlElementPtr 396 xmlGetDtdElementDesc (xmlDtdPtr dtd, 397 const xmlChar *name); 398 399 #ifdef LIBXML_VALID_ENABLED 400 401 XMLPUBFUN int 402 xmlValidGetPotentialChildren(xmlElementContent *ctree, 403 const xmlChar **names, 404 int *len, 405 int max); 406 407 XMLPUBFUN int 408 xmlValidGetValidElements(xmlNode *prev, 409 xmlNode *next, 410 const xmlChar **names, 411 int max); 412 XMLPUBFUN int 413 xmlValidateNameValue (const xmlChar *value); 414 XMLPUBFUN int 415 xmlValidateNamesValue (const xmlChar *value); 416 XMLPUBFUN int 417 xmlValidateNmtokenValue (const xmlChar *value); 418 XMLPUBFUN int 419 xmlValidateNmtokensValue(const xmlChar *value); 420 421 #ifdef LIBXML_REGEXP_ENABLED 422 /* 423 * Validation based on the regexp support 424 */ 425 XMLPUBFUN int 426 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, 427 xmlElementPtr elem); 428 429 XMLPUBFUN int 430 xmlValidatePushElement (xmlValidCtxtPtr ctxt, 431 xmlDocPtr doc, 432 xmlNodePtr elem, 433 const xmlChar *qname); 434 XMLPUBFUN int 435 xmlValidatePushCData (xmlValidCtxtPtr ctxt, 436 const xmlChar *data, 437 int len); 438 XMLPUBFUN int 439 xmlValidatePopElement (xmlValidCtxtPtr ctxt, 440 xmlDocPtr doc, 441 xmlNodePtr elem, 442 const xmlChar *qname); 443 #endif /* LIBXML_REGEXP_ENABLED */ 444 #endif /* LIBXML_VALID_ENABLED */ 445 #ifdef __cplusplus 446 } 447 #endif 448 #endif /* __XML_VALID_H__ */ 449