Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * valid.h : interface to the DTD handling and the validity checking |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef __XML_VALID_H__ |
| 11 | #define __XML_VALID_H__ |
| 12 | |
| 13 | #include <libxml/tree.h> |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 14 | #include <libxml/list.h> |
Daniel Veillard | aeb258a | 2002-09-13 14:48:12 +0000 | [diff] [blame] | 15 | #include <libxml/xmlautomata.h> |
| 16 | #include <libxml/xmlregexp.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 22 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 23 | * Validation state added for non-determinist content model. |
Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 24 | */ |
| 25 | typedef struct _xmlValidState xmlValidState; |
| 26 | typedef xmlValidState *xmlValidStatePtr; |
| 27 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 28 | /** |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 29 | * xmlValidityErrorFunc: |
| 30 | * @ctx: an xmlValidCtxtPtr validity error context |
| 31 | * @msg: the string to format *printf like vararg |
| 32 | * @...: remaining arguments to the format |
| 33 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 34 | * Callback called when a validity error is found. This is a message |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 35 | * oriented function similar to an *printf function. |
| 36 | */ |
| 37 | typedef void (*xmlValidityErrorFunc) (void *ctx, |
| 38 | const char *msg, |
| 39 | ...); |
| 40 | |
| 41 | /** |
| 42 | * xmlValidityWarningFunc: |
| 43 | * @ctx: an xmlValidCtxtPtr validity error context |
| 44 | * @msg: the string to format *printf like vararg |
| 45 | * @...: remaining arguments to the format |
| 46 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 47 | * Callback called when a validity warning is found. This is a message |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 48 | * oriented function similar to an *printf function. |
| 49 | */ |
| 50 | typedef void (*xmlValidityWarningFunc) (void *ctx, |
| 51 | const char *msg, |
| 52 | ...); |
| 53 | |
| 54 | /** |
| 55 | * xmlValidCtxt: |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 56 | * An xmlValidCtxt is used for error reporting when validating. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 57 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 58 | typedef struct _xmlValidCtxt xmlValidCtxt; |
| 59 | typedef xmlValidCtxt *xmlValidCtxtPtr; |
| 60 | struct _xmlValidCtxt { |
| 61 | void *userData; /* user specific data block */ |
| 62 | xmlValidityErrorFunc error; /* the callback in case of errors */ |
| 63 | xmlValidityWarningFunc warning; /* the callback in case of warning */ |
| 64 | |
| 65 | /* Node analysis stack used when validating within entities */ |
| 66 | xmlNodePtr node; /* Current parsed Node */ |
| 67 | int nodeNr; /* Depth of the parsing stack */ |
| 68 | int nodeMax; /* Max depth of the parsing stack */ |
| 69 | xmlNodePtr *nodeTab; /* array of nodes */ |
| 70 | |
| 71 | int finishDtd; /* finished validating the Dtd ? */ |
| 72 | xmlDocPtr doc; /* the document */ |
| 73 | int valid; /* temporary validity check result */ |
Daniel Veillard | dab4cb3 | 2001-04-20 13:03:48 +0000 | [diff] [blame] | 74 | |
| 75 | /* state state used for non-determinist content validation */ |
| 76 | xmlValidState *vstate; /* current state */ |
| 77 | int vstateNr; /* Depth of the validation stack */ |
| 78 | int vstateMax; /* Max depth of the validation stack */ |
| 79 | xmlValidState *vstateTab; /* array of validation states */ |
Daniel Veillard | aeb258a | 2002-09-13 14:48:12 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef LIBXML_REGEXP_ENABLED |
| 82 | xmlAutomataPtr am; /* the automata */ |
| 83 | xmlAutomataStatePtr state; /* used to build the automata */ |
| 84 | #else |
| 85 | void *am; |
| 86 | void *state; |
| 87 | #endif |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 91 | * ALL notation declarations are stored in a table. |
| 92 | * There is one table per DTD. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 93 | */ |
| 94 | |
| 95 | typedef struct _xmlHashTable xmlNotationTable; |
| 96 | typedef xmlNotationTable *xmlNotationTablePtr; |
| 97 | |
| 98 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 99 | * ALL element declarations are stored in a table. |
| 100 | * There is one table per DTD. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 101 | */ |
| 102 | |
| 103 | typedef struct _xmlHashTable xmlElementTable; |
| 104 | typedef xmlElementTable *xmlElementTablePtr; |
| 105 | |
| 106 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 107 | * ALL attribute declarations are stored in a table. |
| 108 | * There is one table per DTD. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 109 | */ |
| 110 | |
| 111 | typedef struct _xmlHashTable xmlAttributeTable; |
| 112 | typedef xmlAttributeTable *xmlAttributeTablePtr; |
| 113 | |
| 114 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 115 | * ALL IDs attributes are stored in a table. |
| 116 | * There is one table per document. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 117 | */ |
| 118 | |
| 119 | typedef struct _xmlHashTable xmlIDTable; |
| 120 | typedef xmlIDTable *xmlIDTablePtr; |
| 121 | |
| 122 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 123 | * ALL Refs attributes are stored in a table. |
| 124 | * There is one table per document. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 125 | */ |
| 126 | |
| 127 | typedef struct _xmlHashTable xmlRefTable; |
| 128 | typedef xmlRefTable *xmlRefTablePtr; |
| 129 | |
| 130 | /* helper */ |
| 131 | xmlChar * xmlSplitQName2 (const xmlChar *name, |
| 132 | xmlChar **prefix); |
| 133 | |
| 134 | /* Notation */ |
| 135 | xmlNotationPtr xmlAddNotationDecl (xmlValidCtxtPtr ctxt, |
| 136 | xmlDtdPtr dtd, |
| 137 | const xmlChar *name, |
| 138 | const xmlChar *PublicID, |
| 139 | const xmlChar *SystemID); |
| 140 | xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); |
| 141 | void xmlFreeNotationTable(xmlNotationTablePtr table); |
| 142 | void xmlDumpNotationDecl (xmlBufferPtr buf, |
| 143 | xmlNotationPtr nota); |
| 144 | void xmlDumpNotationTable(xmlBufferPtr buf, |
| 145 | xmlNotationTablePtr table); |
| 146 | |
| 147 | /* Element Content */ |
| 148 | xmlElementContentPtr xmlNewElementContent (xmlChar *name, |
| 149 | xmlElementContentType type); |
| 150 | xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content); |
| 151 | void xmlFreeElementContent(xmlElementContentPtr cur); |
Daniel Veillard | d3d0672 | 2001-08-15 12:06:36 +0000 | [diff] [blame] | 152 | void xmlSnprintfElementContent(char *buf, |
| 153 | int size, |
| 154 | xmlElementContentPtr content, |
| 155 | int glob); |
| 156 | /* DEPRECATED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 157 | void xmlSprintfElementContent(char *buf, |
| 158 | xmlElementContentPtr content, |
| 159 | int glob); |
Daniel Veillard | d3d0672 | 2001-08-15 12:06:36 +0000 | [diff] [blame] | 160 | /* DEPRECATED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 161 | |
| 162 | /* Element */ |
| 163 | xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt, |
| 164 | xmlDtdPtr dtd, |
| 165 | const xmlChar *name, |
| 166 | xmlElementTypeVal type, |
| 167 | xmlElementContentPtr content); |
| 168 | xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table); |
| 169 | void xmlFreeElementTable (xmlElementTablePtr table); |
| 170 | void xmlDumpElementTable (xmlBufferPtr buf, |
| 171 | xmlElementTablePtr table); |
| 172 | void xmlDumpElementDecl (xmlBufferPtr buf, |
| 173 | xmlElementPtr elem); |
| 174 | |
| 175 | /* Enumeration */ |
| 176 | xmlEnumerationPtr xmlCreateEnumeration (xmlChar *name); |
| 177 | void xmlFreeEnumeration (xmlEnumerationPtr cur); |
| 178 | xmlEnumerationPtr xmlCopyEnumeration (xmlEnumerationPtr cur); |
| 179 | |
| 180 | /* Attribute */ |
| 181 | xmlAttributePtr xmlAddAttributeDecl (xmlValidCtxtPtr ctxt, |
| 182 | xmlDtdPtr dtd, |
| 183 | const xmlChar *elem, |
| 184 | const xmlChar *name, |
| 185 | const xmlChar *ns, |
| 186 | xmlAttributeType type, |
| 187 | xmlAttributeDefault def, |
| 188 | const xmlChar *defaultValue, |
| 189 | xmlEnumerationPtr tree); |
| 190 | xmlAttributeTablePtr xmlCopyAttributeTable (xmlAttributeTablePtr table); |
| 191 | void xmlFreeAttributeTable (xmlAttributeTablePtr table); |
| 192 | void xmlDumpAttributeTable (xmlBufferPtr buf, |
| 193 | xmlAttributeTablePtr table); |
| 194 | void xmlDumpAttributeDecl (xmlBufferPtr buf, |
| 195 | xmlAttributePtr attr); |
| 196 | |
| 197 | /* IDs */ |
| 198 | xmlIDPtr xmlAddID (xmlValidCtxtPtr ctxt, |
| 199 | xmlDocPtr doc, |
| 200 | const xmlChar *value, |
| 201 | xmlAttrPtr attr); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 202 | void xmlFreeIDTable (xmlIDTablePtr table); |
| 203 | xmlAttrPtr xmlGetID (xmlDocPtr doc, |
| 204 | const xmlChar *ID); |
| 205 | int xmlIsID (xmlDocPtr doc, |
| 206 | xmlNodePtr elem, |
| 207 | xmlAttrPtr attr); |
| 208 | int xmlRemoveID (xmlDocPtr doc, xmlAttrPtr attr); |
| 209 | |
| 210 | /* IDREFs */ |
| 211 | xmlRefPtr xmlAddRef (xmlValidCtxtPtr ctxt, |
| 212 | xmlDocPtr doc, |
| 213 | const xmlChar *value, |
| 214 | xmlAttrPtr attr); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 215 | void xmlFreeRefTable (xmlRefTablePtr table); |
| 216 | int xmlIsRef (xmlDocPtr doc, |
| 217 | xmlNodePtr elem, |
| 218 | xmlAttrPtr attr); |
| 219 | int xmlRemoveRef (xmlDocPtr doc, xmlAttrPtr attr); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 220 | xmlListPtr xmlGetRefs (xmlDocPtr doc, |
| 221 | const xmlChar *ID); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 222 | |
| 223 | /** |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 224 | * The public function calls related to validity checking. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 225 | */ |
| 226 | |
| 227 | int xmlValidateRoot (xmlValidCtxtPtr ctxt, |
| 228 | xmlDocPtr doc); |
| 229 | int xmlValidateElementDecl (xmlValidCtxtPtr ctxt, |
| 230 | xmlDocPtr doc, |
| 231 | xmlElementPtr elem); |
| 232 | xmlChar * xmlValidNormalizeAttributeValue(xmlDocPtr doc, |
| 233 | xmlNodePtr elem, |
| 234 | const xmlChar *name, |
| 235 | const xmlChar *value); |
Daniel Veillard | 8dc16a6 | 2002-02-19 21:08:48 +0000 | [diff] [blame] | 236 | xmlChar * xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, |
| 237 | xmlDocPtr doc, |
| 238 | xmlNodePtr elem, |
| 239 | const xmlChar *name, |
| 240 | const xmlChar *value); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 241 | int xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, |
| 242 | xmlDocPtr doc, |
| 243 | xmlAttributePtr attr); |
| 244 | int xmlValidateAttributeValue(xmlAttributeType type, |
| 245 | const xmlChar *value); |
| 246 | int xmlValidateNotationDecl (xmlValidCtxtPtr ctxt, |
| 247 | xmlDocPtr doc, |
| 248 | xmlNotationPtr nota); |
| 249 | int xmlValidateDtd (xmlValidCtxtPtr ctxt, |
| 250 | xmlDocPtr doc, |
| 251 | xmlDtdPtr dtd); |
| 252 | int xmlValidateDtdFinal (xmlValidCtxtPtr ctxt, |
| 253 | xmlDocPtr doc); |
| 254 | int xmlValidateDocument (xmlValidCtxtPtr ctxt, |
| 255 | xmlDocPtr doc); |
| 256 | int xmlValidateElement (xmlValidCtxtPtr ctxt, |
| 257 | xmlDocPtr doc, |
| 258 | xmlNodePtr elem); |
| 259 | int xmlValidateOneElement (xmlValidCtxtPtr ctxt, |
| 260 | xmlDocPtr doc, |
| 261 | xmlNodePtr elem); |
| 262 | int xmlValidateOneAttribute (xmlValidCtxtPtr ctxt, |
| 263 | xmlDocPtr doc, |
| 264 | xmlNodePtr elem, |
| 265 | xmlAttrPtr attr, |
| 266 | const xmlChar *value); |
Daniel Veillard | 90d68fb | 2002-09-26 16:10:21 +0000 | [diff] [blame^] | 267 | int xmlValidateOneNamespace (xmlValidCtxtPtr ctxt, |
| 268 | xmlDocPtr doc, |
| 269 | xmlNodePtr elem, |
| 270 | const xmlChar *prefix, |
| 271 | xmlNsPtr ns, |
| 272 | const xmlChar *value); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 273 | int xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, |
| 274 | xmlDocPtr doc); |
| 275 | int xmlValidateNotationUse (xmlValidCtxtPtr ctxt, |
| 276 | xmlDocPtr doc, |
| 277 | const xmlChar *notationName); |
| 278 | int xmlIsMixedElement (xmlDocPtr doc, |
| 279 | const xmlChar *name); |
| 280 | xmlAttributePtr xmlGetDtdAttrDesc (xmlDtdPtr dtd, |
| 281 | const xmlChar *elem, |
| 282 | const xmlChar *name); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 283 | xmlAttributePtr xmlGetDtdQAttrDesc (xmlDtdPtr dtd, |
| 284 | const xmlChar *elem, |
| 285 | const xmlChar *name, |
| 286 | const xmlChar *prefix); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 287 | xmlNotationPtr xmlGetDtdNotationDesc (xmlDtdPtr dtd, |
| 288 | const xmlChar *name); |
Daniel Veillard | 48da910 | 2001-08-07 01:10:10 +0000 | [diff] [blame] | 289 | xmlElementPtr xmlGetDtdQElementDesc (xmlDtdPtr dtd, |
| 290 | const xmlChar *name, |
| 291 | const xmlChar *prefix); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 292 | xmlElementPtr xmlGetDtdElementDesc (xmlDtdPtr dtd, |
| 293 | const xmlChar *name); |
| 294 | |
| 295 | int xmlValidGetValidElements(xmlNode *prev, |
| 296 | xmlNode *next, |
| 297 | const xmlChar **list, |
| 298 | int max); |
| 299 | int xmlValidGetPotentialChildren(xmlElementContent *ctree, |
| 300 | const xmlChar **list, |
| 301 | int *len, |
| 302 | int max); |
Daniel Veillard | 9b731d7 | 2002-04-14 12:56:08 +0000 | [diff] [blame] | 303 | int xmlValidateNameValue (const xmlChar *value); |
| 304 | int xmlValidateNamesValue (const xmlChar *value); |
| 305 | int xmlValidateNmtokenValue (const xmlChar *value); |
| 306 | int xmlValidateNmtokensValue(const xmlChar *value); |
Daniel Veillard | 84d70a4 | 2002-09-16 10:51:38 +0000 | [diff] [blame] | 307 | |
| 308 | #ifdef LIBXML_REGEXP_ENABLED |
| 309 | /* |
| 310 | * Validation based on the regexp support |
| 311 | */ |
| 312 | int xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, |
| 313 | xmlElementPtr elem); |
| 314 | |
| 315 | #endif /* LIBXML_REGEXP_ENABLED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 316 | #ifdef __cplusplus |
| 317 | } |
| 318 | #endif |
| 319 | #endif /* __XML_VALID_H__ */ |