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 (xmlDocPtr doc, 259 const xmlChar *value, 260 xmlAttrPtr attr, 261 int streaming, 262 xmlIDPtr *id); 263 XMLPUBFUN xmlIDPtr 264 xmlAddID (xmlValidCtxtPtr ctxt, 265 xmlDocPtr doc, 266 const xmlChar *value, 267 xmlAttrPtr attr); 268 XMLPUBFUN void 269 xmlFreeIDTable (xmlIDTablePtr table); 270 XMLPUBFUN xmlAttrPtr 271 xmlGetID (xmlDocPtr doc, 272 const xmlChar *ID); 273 XMLPUBFUN int 274 xmlIsID (xmlDocPtr doc, 275 xmlNodePtr elem, 276 xmlAttrPtr attr); 277 XMLPUBFUN int 278 xmlRemoveID (xmlDocPtr doc, 279 xmlAttrPtr attr); 280 281 /* IDREFs */ 282 XML_DEPRECATED 283 XMLPUBFUN xmlRefPtr 284 xmlAddRef (xmlValidCtxtPtr ctxt, 285 xmlDocPtr doc, 286 const xmlChar *value, 287 xmlAttrPtr attr); 288 XML_DEPRECATED 289 XMLPUBFUN void 290 xmlFreeRefTable (xmlRefTablePtr table); 291 XML_DEPRECATED 292 XMLPUBFUN int 293 xmlIsRef (xmlDocPtr doc, 294 xmlNodePtr elem, 295 xmlAttrPtr attr); 296 XML_DEPRECATED 297 XMLPUBFUN int 298 xmlRemoveRef (xmlDocPtr doc, 299 xmlAttrPtr attr); 300 XML_DEPRECATED 301 XMLPUBFUN xmlListPtr 302 xmlGetRefs (xmlDocPtr doc, 303 const xmlChar *ID); 304 305 /** 306 * The public function calls related to validity checking. 307 */ 308 #ifdef LIBXML_VALID_ENABLED 309 /* Allocate/Release Validation Contexts */ 310 XMLPUBFUN xmlValidCtxtPtr 311 xmlNewValidCtxt(void); 312 XMLPUBFUN void 313 xmlFreeValidCtxt(xmlValidCtxtPtr); 314 315 XMLPUBFUN int 316 xmlValidateRoot (xmlValidCtxtPtr ctxt, 317 xmlDocPtr doc); 318 XMLPUBFUN int 319 xmlValidateElementDecl (xmlValidCtxtPtr ctxt, 320 xmlDocPtr doc, 321 xmlElementPtr elem); 322 XMLPUBFUN xmlChar * 323 xmlValidNormalizeAttributeValue(xmlDocPtr doc, 324 xmlNodePtr elem, 325 const xmlChar *name, 326 const xmlChar *value); 327 XMLPUBFUN xmlChar * 328 xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, 329 xmlDocPtr doc, 330 xmlNodePtr elem, 331 const xmlChar *name, 332 const xmlChar *value); 333 XMLPUBFUN int 334 xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, 335 xmlDocPtr doc, 336 xmlAttributePtr attr); 337 XMLPUBFUN int 338 xmlValidateAttributeValue(xmlAttributeType type, 339 const xmlChar *value); 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 XMLPUBFUN int 349 xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, 350 xmlDocPtr doc); 351 XMLPUBFUN int 352 xmlValidateDocument (xmlValidCtxtPtr ctxt, 353 xmlDocPtr doc); 354 XMLPUBFUN int 355 xmlValidateElement (xmlValidCtxtPtr ctxt, 356 xmlDocPtr doc, 357 xmlNodePtr elem); 358 XMLPUBFUN int 359 xmlValidateOneElement (xmlValidCtxtPtr ctxt, 360 xmlDocPtr doc, 361 xmlNodePtr elem); 362 XMLPUBFUN int 363 xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, 364 xmlDocPtr doc, 365 xmlNodePtr elem, 366 xmlAttrPtr attr, 367 const xmlChar *value); 368 XMLPUBFUN int 369 xmlValidateOneNamespace (xmlValidCtxtPtr ctxt, 370 xmlDocPtr doc, 371 xmlNodePtr elem, 372 const xmlChar *prefix, 373 xmlNsPtr ns, 374 const xmlChar *value); 375 XMLPUBFUN int 376 xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, 377 xmlDocPtr doc); 378 #endif /* LIBXML_VALID_ENABLED */ 379 380 #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) 381 XMLPUBFUN int 382 xmlValidateNotationUse (xmlValidCtxtPtr ctxt, 383 xmlDocPtr doc, 384 const xmlChar *notationName); 385 #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */ 386 387 XMLPUBFUN int 388 xmlIsMixedElement (xmlDocPtr doc, 389 const xmlChar *name); 390 XMLPUBFUN xmlAttributePtr 391 xmlGetDtdAttrDesc (xmlDtdPtr dtd, 392 const xmlChar *elem, 393 const xmlChar *name); 394 XMLPUBFUN xmlAttributePtr 395 xmlGetDtdQAttrDesc (xmlDtdPtr dtd, 396 const xmlChar *elem, 397 const xmlChar *name, 398 const xmlChar *prefix); 399 XMLPUBFUN xmlNotationPtr 400 xmlGetDtdNotationDesc (xmlDtdPtr dtd, 401 const xmlChar *name); 402 XMLPUBFUN xmlElementPtr 403 xmlGetDtdQElementDesc (xmlDtdPtr dtd, 404 const xmlChar *name, 405 const xmlChar *prefix); 406 XMLPUBFUN xmlElementPtr 407 xmlGetDtdElementDesc (xmlDtdPtr dtd, 408 const xmlChar *name); 409 410 #ifdef LIBXML_VALID_ENABLED 411 412 XMLPUBFUN int 413 xmlValidGetPotentialChildren(xmlElementContent *ctree, 414 const xmlChar **names, 415 int *len, 416 int max); 417 418 XMLPUBFUN int 419 xmlValidGetValidElements(xmlNode *prev, 420 xmlNode *next, 421 const xmlChar **names, 422 int max); 423 XMLPUBFUN int 424 xmlValidateNameValue (const xmlChar *value); 425 XMLPUBFUN int 426 xmlValidateNamesValue (const xmlChar *value); 427 XMLPUBFUN int 428 xmlValidateNmtokenValue (const xmlChar *value); 429 XMLPUBFUN int 430 xmlValidateNmtokensValue(const xmlChar *value); 431 432 #ifdef LIBXML_REGEXP_ENABLED 433 /* 434 * Validation based on the regexp support 435 */ 436 XMLPUBFUN int 437 xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, 438 xmlElementPtr elem); 439 440 XMLPUBFUN int 441 xmlValidatePushElement (xmlValidCtxtPtr ctxt, 442 xmlDocPtr doc, 443 xmlNodePtr elem, 444 const xmlChar *qname); 445 XMLPUBFUN int 446 xmlValidatePushCData (xmlValidCtxtPtr ctxt, 447 const xmlChar *data, 448 int len); 449 XMLPUBFUN int 450 xmlValidatePopElement (xmlValidCtxtPtr ctxt, 451 xmlDocPtr doc, 452 xmlNodePtr elem, 453 const xmlChar *qname); 454 #endif /* LIBXML_REGEXP_ENABLED */ 455 #endif /* LIBXML_VALID_ENABLED */ 456 #ifdef __cplusplus 457 } 458 #endif 459 #endif /* __XML_VALID_H__ */ 460