| File: | valid.c |
| Location: | line 5298, column 29 |
| Description: | Value stored to 'ret' is never read |
| 1 | /* |
| 2 | * valid.c : part of the code use to do the DTD handling and the validity |
| 3 | * checking |
| 4 | * |
| 5 | * See Copyright for the status of this software. |
| 6 | * |
| 7 | * daniel@veillard.com |
| 8 | */ |
| 9 | |
| 10 | #define IN_LIBXML |
| 11 | #include "libxml.h" |
| 12 | |
| 13 | #include <string.h> |
| 14 | |
| 15 | #ifdef HAVE_STDLIB_H1 |
| 16 | #include <stdlib.h> |
| 17 | #endif |
| 18 | |
| 19 | #include <libxml/xmlmemory.h> |
| 20 | #include <libxml/hash.h> |
| 21 | #include <libxml/uri.h> |
| 22 | #include <libxml/valid.h> |
| 23 | #include <libxml/parser.h> |
| 24 | #include <libxml/parserInternals.h> |
| 25 | #include <libxml/xmlerror.h> |
| 26 | #include <libxml/list.h> |
| 27 | #include <libxml/globals.h> |
| 28 | |
| 29 | static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name, |
| 30 | int create); |
| 31 | /* #define DEBUG_VALID_ALGO */ |
| 32 | /* #define DEBUG_REGEXP_ALGO */ |
| 33 | |
| 34 | #define TODO(*(__xmlGenericError__internal_alias()))((*(__xmlGenericErrorContext__internal_alias ())), "Unimplemented block at %s:%d\n", "valid.c", 34); \ |
| 35 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), \ |
| 36 | "Unimplemented block at %s:%d\n", \ |
| 37 | __FILE__"valid.c", __LINE__37); |
| 38 | |
| 39 | #ifdef LIBXML_VALID_ENABLED |
| 40 | static int |
| 41 | xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type, |
| 42 | const xmlChar *value); |
| 43 | #endif |
| 44 | /************************************************************************ |
| 45 | * * |
| 46 | * Error handling routines * |
| 47 | * * |
| 48 | ************************************************************************/ |
| 49 | |
| 50 | /** |
| 51 | * xmlVErrMemory: |
| 52 | * @ctxt: an XML validation parser context |
| 53 | * @extra: extra informations |
| 54 | * |
| 55 | * Handle an out of memory error |
| 56 | */ |
| 57 | static void |
| 58 | xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra) |
| 59 | { |
| 60 | xmlGenericErrorFunc channel = NULL((void*)0); |
| 61 | xmlParserCtxtPtr pctxt = NULL((void*)0); |
| 62 | void *data = NULL((void*)0); |
| 63 | |
| 64 | if (ctxt != NULL((void*)0)) { |
| 65 | channel = ctxt->error; |
| 66 | data = ctxt->userData; |
| 67 | /* Use the special values to detect if it is part of a parsing |
| 68 | context */ |
| 69 | if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 70 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235)) { |
| 71 | long delta = (char *) ctxt - (char *) ctxt->userData; |
| 72 | if ((delta > 0) && (delta < 250)) |
| 73 | pctxt = ctxt->userData; |
| 74 | } |
| 75 | } |
| 76 | if (extra) |
| 77 | __xmlRaiseError(NULL((void*)0), channel, data, |
| 78 | pctxt, NULL((void*)0), XML_FROM_VALID, XML_ERR_NO_MEMORY, |
| 79 | XML_ERR_FATAL, NULL((void*)0), 0, extra, NULL((void*)0), NULL((void*)0), 0, 0, |
| 80 | "Memory allocation failed : %s\n", extra); |
| 81 | else |
| 82 | __xmlRaiseError(NULL((void*)0), channel, data, |
| 83 | pctxt, NULL((void*)0), XML_FROM_VALID, XML_ERR_NO_MEMORY, |
| 84 | XML_ERR_FATAL, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), NULL((void*)0), 0, 0, |
| 85 | "Memory allocation failed\n"); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * xmlErrValid: |
| 90 | * @ctxt: an XML validation parser context |
| 91 | * @error: the error number |
| 92 | * @extra: extra informations |
| 93 | * |
| 94 | * Handle a validation error |
| 95 | */ |
| 96 | static void |
| 97 | xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error, |
| 98 | const char *msg, const char *extra) |
| 99 | { |
| 100 | xmlGenericErrorFunc channel = NULL((void*)0); |
| 101 | xmlParserCtxtPtr pctxt = NULL((void*)0); |
| 102 | void *data = NULL((void*)0); |
| 103 | |
| 104 | if (ctxt != NULL((void*)0)) { |
| 105 | channel = ctxt->error; |
| 106 | data = ctxt->userData; |
| 107 | /* Use the special values to detect if it is part of a parsing |
| 108 | context */ |
| 109 | if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 110 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235)) { |
| 111 | long delta = (char *) ctxt - (char *) ctxt->userData; |
| 112 | if ((delta > 0) && (delta < 250)) |
| 113 | pctxt = ctxt->userData; |
| 114 | } |
| 115 | } |
| 116 | if (extra) |
| 117 | __xmlRaiseError(NULL((void*)0), channel, data, |
| 118 | pctxt, NULL((void*)0), XML_FROM_VALID, error, |
| 119 | XML_ERR_ERROR, NULL((void*)0), 0, extra, NULL((void*)0), NULL((void*)0), 0, 0, |
| 120 | msg, extra); |
| 121 | else |
| 122 | __xmlRaiseError(NULL((void*)0), channel, data, |
| 123 | pctxt, NULL((void*)0), XML_FROM_VALID, error, |
| 124 | XML_ERR_ERROR, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), NULL((void*)0), 0, 0, |
| 125 | "%s", msg); |
| 126 | } |
| 127 | |
| 128 | #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| 129 | /** |
| 130 | * xmlErrValidNode: |
| 131 | * @ctxt: an XML validation parser context |
| 132 | * @node: the node raising the error |
| 133 | * @error: the error number |
| 134 | * @str1: extra informations |
| 135 | * @str2: extra informations |
| 136 | * @str3: extra informations |
| 137 | * |
| 138 | * Handle a validation error, provide contextual informations |
| 139 | */ |
| 140 | static void |
| 141 | xmlErrValidNode(xmlValidCtxtPtr ctxt, |
| 142 | xmlNodePtr node, xmlParserErrors error, |
| 143 | const char *msg, const xmlChar * str1, |
| 144 | const xmlChar * str2, const xmlChar * str3) |
| 145 | { |
| 146 | xmlStructuredErrorFunc schannel = NULL((void*)0); |
| 147 | xmlGenericErrorFunc channel = NULL((void*)0); |
| 148 | xmlParserCtxtPtr pctxt = NULL((void*)0); |
| 149 | void *data = NULL((void*)0); |
| 150 | |
| 151 | if (ctxt != NULL((void*)0)) { |
| 152 | channel = ctxt->error; |
| 153 | data = ctxt->userData; |
| 154 | /* Use the special values to detect if it is part of a parsing |
| 155 | context */ |
| 156 | if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 157 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235)) { |
| 158 | long delta = (char *) ctxt - (char *) ctxt->userData; |
| 159 | if ((delta > 0) && (delta < 250)) |
| 160 | pctxt = ctxt->userData; |
| 161 | } |
| 162 | } |
| 163 | __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, |
| 164 | XML_ERR_ERROR, NULL((void*)0), 0, |
| 165 | (const char *) str1, |
| 166 | (const char *) str1, |
| 167 | (const char *) str3, 0, 0, msg, str1, str2, str3); |
| 168 | } |
| 169 | #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */ |
| 170 | |
| 171 | #ifdef LIBXML_VALID_ENABLED |
| 172 | /** |
| 173 | * xmlErrValidNodeNr: |
| 174 | * @ctxt: an XML validation parser context |
| 175 | * @node: the node raising the error |
| 176 | * @error: the error number |
| 177 | * @str1: extra informations |
| 178 | * @int2: extra informations |
| 179 | * @str3: extra informations |
| 180 | * |
| 181 | * Handle a validation error, provide contextual informations |
| 182 | */ |
| 183 | static void |
| 184 | xmlErrValidNodeNr(xmlValidCtxtPtr ctxt, |
| 185 | xmlNodePtr node, xmlParserErrors error, |
| 186 | const char *msg, const xmlChar * str1, |
| 187 | int int2, const xmlChar * str3) |
| 188 | { |
| 189 | xmlStructuredErrorFunc schannel = NULL((void*)0); |
| 190 | xmlGenericErrorFunc channel = NULL((void*)0); |
| 191 | xmlParserCtxtPtr pctxt = NULL((void*)0); |
| 192 | void *data = NULL((void*)0); |
| 193 | |
| 194 | if (ctxt != NULL((void*)0)) { |
| 195 | channel = ctxt->error; |
| 196 | data = ctxt->userData; |
| 197 | /* Use the special values to detect if it is part of a parsing |
| 198 | context */ |
| 199 | if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 200 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235)) { |
| 201 | long delta = (char *) ctxt - (char *) ctxt->userData; |
| 202 | if ((delta > 0) && (delta < 250)) |
| 203 | pctxt = ctxt->userData; |
| 204 | } |
| 205 | } |
| 206 | __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, |
| 207 | XML_ERR_ERROR, NULL((void*)0), 0, |
| 208 | (const char *) str1, |
| 209 | (const char *) str3, |
| 210 | NULL((void*)0), int2, 0, msg, str1, int2, str3); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * xmlErrValidWarning: |
| 215 | * @ctxt: an XML validation parser context |
| 216 | * @node: the node raising the error |
| 217 | * @error: the error number |
| 218 | * @str1: extra information |
| 219 | * @str2: extra information |
| 220 | * @str3: extra information |
| 221 | * |
| 222 | * Handle a validation error, provide contextual information |
| 223 | */ |
| 224 | static void |
| 225 | xmlErrValidWarning(xmlValidCtxtPtr ctxt, |
| 226 | xmlNodePtr node, xmlParserErrors error, |
| 227 | const char *msg, const xmlChar * str1, |
| 228 | const xmlChar * str2, const xmlChar * str3) |
| 229 | { |
| 230 | xmlStructuredErrorFunc schannel = NULL((void*)0); |
| 231 | xmlGenericErrorFunc channel = NULL((void*)0); |
| 232 | xmlParserCtxtPtr pctxt = NULL((void*)0); |
| 233 | void *data = NULL((void*)0); |
| 234 | |
| 235 | if (ctxt != NULL((void*)0)) { |
| 236 | channel = ctxt->warning; |
| 237 | data = ctxt->userData; |
| 238 | /* Use the special values to detect if it is part of a parsing |
| 239 | context */ |
| 240 | if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 241 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235)) { |
| 242 | long delta = (char *) ctxt - (char *) ctxt->userData; |
| 243 | if ((delta > 0) && (delta < 250)) |
| 244 | pctxt = ctxt->userData; |
| 245 | } |
| 246 | } |
| 247 | __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, |
| 248 | XML_ERR_WARNING, NULL((void*)0), 0, |
| 249 | (const char *) str1, |
| 250 | (const char *) str1, |
| 251 | (const char *) str3, 0, 0, msg, str1, str2, str3); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | |
| 256 | #ifdef LIBXML_REGEXP_ENABLED |
| 257 | /* |
| 258 | * If regexp are enabled we can do continuous validation without the |
| 259 | * need of a tree to validate the content model. this is done in each |
| 260 | * callbacks. |
| 261 | * Each xmlValidState represent the validation state associated to the |
| 262 | * set of nodes currently open from the document root to the current element. |
| 263 | */ |
| 264 | |
| 265 | |
| 266 | typedef struct _xmlValidState { |
| 267 | xmlElementPtr elemDecl; /* pointer to the content model */ |
| 268 | xmlNodePtr node; /* pointer to the current node */ |
| 269 | xmlRegExecCtxtPtr exec; /* regexp runtime */ |
| 270 | } _xmlValidState; |
| 271 | |
| 272 | |
| 273 | static int |
| 274 | vstateVPush(xmlValidCtxtPtr ctxt, xmlElementPtr elemDecl, xmlNodePtr node) { |
| 275 | if ((ctxt->vstateMax == 0) || (ctxt->vstateTab == NULL((void*)0))) { |
| 276 | ctxt->vstateMax = 10; |
| 277 | ctxt->vstateTab = (xmlValidState *) xmlMalloc(ctxt->vstateMax * |
| 278 | sizeof(ctxt->vstateTab[0])); |
| 279 | if (ctxt->vstateTab == NULL((void*)0)) { |
| 280 | xmlVErrMemory(ctxt, "malloc failed"); |
| 281 | return(-1); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if (ctxt->vstateNr >= ctxt->vstateMax) { |
| 286 | xmlValidState *tmp; |
| 287 | |
| 288 | tmp = (xmlValidState *) xmlRealloc(ctxt->vstateTab, |
| 289 | 2 * ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); |
| 290 | if (tmp == NULL((void*)0)) { |
| 291 | xmlVErrMemory(ctxt, "realloc failed"); |
| 292 | return(-1); |
| 293 | } |
| 294 | ctxt->vstateMax *= 2; |
| 295 | ctxt->vstateTab = tmp; |
| 296 | } |
| 297 | ctxt->vstate = &ctxt->vstateTab[ctxt->vstateNr]; |
| 298 | ctxt->vstateTab[ctxt->vstateNr].elemDecl = elemDecl; |
| 299 | ctxt->vstateTab[ctxt->vstateNr].node = node; |
| 300 | if ((elemDecl != NULL((void*)0)) && (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT)) { |
| 301 | if (elemDecl->contModel == NULL((void*)0)) |
| 302 | xmlValidBuildContentModel(ctxt, elemDecl); |
| 303 | if (elemDecl->contModel != NULL((void*)0)) { |
| 304 | ctxt->vstateTab[ctxt->vstateNr].exec = |
| 305 | xmlRegNewExecCtxtxmlRegNewExecCtxt__internal_alias(elemDecl->contModel, NULL((void*)0), NULL((void*)0)); |
| 306 | } else { |
| 307 | ctxt->vstateTab[ctxt->vstateNr].exec = NULL((void*)0); |
| 308 | xmlErrValidNode(ctxt, (xmlNodePtr) elemDecl, |
| 309 | XML_ERR_INTERNAL_ERROR, |
| 310 | "Failed to build content model regexp for %s\n", |
| 311 | node->name, NULL((void*)0), NULL((void*)0)); |
| 312 | } |
| 313 | } |
| 314 | return(ctxt->vstateNr++); |
| 315 | } |
| 316 | |
| 317 | static int |
| 318 | vstateVPop(xmlValidCtxtPtr ctxt) { |
| 319 | xmlElementPtr elemDecl; |
| 320 | |
| 321 | if (ctxt->vstateNr < 1) return(-1); |
| 322 | ctxt->vstateNr--; |
| 323 | elemDecl = ctxt->vstateTab[ctxt->vstateNr].elemDecl; |
| 324 | ctxt->vstateTab[ctxt->vstateNr].elemDecl = NULL((void*)0); |
| 325 | ctxt->vstateTab[ctxt->vstateNr].node = NULL((void*)0); |
| 326 | if ((elemDecl != NULL((void*)0)) && (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT)) { |
| 327 | xmlRegFreeExecCtxtxmlRegFreeExecCtxt__internal_alias(ctxt->vstateTab[ctxt->vstateNr].exec); |
| 328 | } |
| 329 | ctxt->vstateTab[ctxt->vstateNr].exec = NULL((void*)0); |
| 330 | if (ctxt->vstateNr >= 1) |
| 331 | ctxt->vstate = &ctxt->vstateTab[ctxt->vstateNr - 1]; |
| 332 | else |
| 333 | ctxt->vstate = NULL((void*)0); |
| 334 | return(ctxt->vstateNr); |
| 335 | } |
| 336 | |
| 337 | #else /* not LIBXML_REGEXP_ENABLED */ |
| 338 | /* |
| 339 | * If regexp are not enabled, it uses a home made algorithm less |
| 340 | * complex and easier to |
| 341 | * debug/maintain than a generic NFA -> DFA state based algo. The |
| 342 | * only restriction is on the deepness of the tree limited by the |
| 343 | * size of the occurs bitfield |
| 344 | * |
| 345 | * this is the content of a saved state for rollbacks |
| 346 | */ |
| 347 | |
| 348 | #define ROLLBACK_OR 0 |
| 349 | #define ROLLBACK_PARENT 1 |
| 350 | |
| 351 | typedef struct _xmlValidState { |
| 352 | xmlElementContentPtr cont; /* pointer to the content model subtree */ |
| 353 | xmlNodePtr node; /* pointer to the current node in the list */ |
| 354 | long occurs;/* bitfield for multiple occurrences */ |
| 355 | unsigned char depth; /* current depth in the overall tree */ |
| 356 | unsigned char state; /* ROLLBACK_XXX */ |
| 357 | } _xmlValidState; |
| 358 | |
| 359 | #define MAX_RECURSE 25000 |
| 360 | #define MAX_DEPTH ((sizeof(_xmlValidState.occurs)) * 8) |
| 361 | #define CONT ctxt->vstate->cont |
| 362 | #define NODE ctxt->vstate->node |
| 363 | #define DEPTH ctxt->vstate->depth |
| 364 | #define OCCURS ctxt->vstate->occurs |
| 365 | #define STATE ctxt->vstate->state |
| 366 | |
| 367 | #define OCCURRENCE (ctxt->vstate->occurs & (1 << DEPTH)) |
| 368 | #define PARENT_OCCURRENCE (ctxt->vstate->occurs & ((1 << DEPTH) - 1)) |
| 369 | |
| 370 | #define SET_OCCURRENCE ctxt->vstate->occurs |= (1 << DEPTH) |
| 371 | #define RESET_OCCURRENCE ctxt->vstate->occurs &= ((1 << DEPTH) - 1) |
| 372 | |
| 373 | static int |
| 374 | vstateVPush(xmlValidCtxtPtr ctxt, xmlElementContentPtr cont, |
| 375 | xmlNodePtr node, unsigned char depth, long occurs, |
| 376 | unsigned char state) { |
| 377 | int i = ctxt->vstateNr - 1; |
| 378 | |
| 379 | if (ctxt->vstateNr > MAX_RECURSE) { |
| 380 | return(-1); |
| 381 | } |
| 382 | if (ctxt->vstateTab == NULL((void*)0)) { |
| 383 | ctxt->vstateMax = 8; |
| 384 | ctxt->vstateTab = (xmlValidState *) xmlMalloc( |
| 385 | ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); |
| 386 | if (ctxt->vstateTab == NULL((void*)0)) { |
| 387 | xmlVErrMemory(ctxt, "malloc failed"); |
| 388 | return(-1); |
| 389 | } |
| 390 | } |
| 391 | if (ctxt->vstateNr >= ctxt->vstateMax) { |
| 392 | xmlValidState *tmp; |
| 393 | |
| 394 | tmp = (xmlValidState *) xmlRealloc(ctxt->vstateTab, |
| 395 | 2 * ctxt->vstateMax * sizeof(ctxt->vstateTab[0])); |
| 396 | if (tmp == NULL((void*)0)) { |
| 397 | xmlVErrMemory(ctxt, "malloc failed"); |
| 398 | return(-1); |
| 399 | } |
| 400 | ctxt->vstateMax *= 2; |
| 401 | ctxt->vstateTab = tmp; |
| 402 | ctxt->vstate = &ctxt->vstateTab[0]; |
| 403 | } |
| 404 | /* |
| 405 | * Don't push on the stack a state already here |
| 406 | */ |
| 407 | if ((i >= 0) && (ctxt->vstateTab[i].cont == cont) && |
| 408 | (ctxt->vstateTab[i].node == node) && |
| 409 | (ctxt->vstateTab[i].depth == depth) && |
| 410 | (ctxt->vstateTab[i].occurs == occurs) && |
| 411 | (ctxt->vstateTab[i].state == state)) |
| 412 | return(ctxt->vstateNr); |
| 413 | ctxt->vstateTab[ctxt->vstateNr].cont = cont; |
| 414 | ctxt->vstateTab[ctxt->vstateNr].node = node; |
| 415 | ctxt->vstateTab[ctxt->vstateNr].depth = depth; |
| 416 | ctxt->vstateTab[ctxt->vstateNr].occurs = occurs; |
| 417 | ctxt->vstateTab[ctxt->vstateNr].state = state; |
| 418 | return(ctxt->vstateNr++); |
| 419 | } |
| 420 | |
| 421 | static int |
| 422 | vstateVPop(xmlValidCtxtPtr ctxt) { |
| 423 | if (ctxt->vstateNr <= 1) return(-1); |
| 424 | ctxt->vstateNr--; |
| 425 | ctxt->vstate = &ctxt->vstateTab[0]; |
| 426 | ctxt->vstate->cont = ctxt->vstateTab[ctxt->vstateNr].cont; |
| 427 | ctxt->vstate->node = ctxt->vstateTab[ctxt->vstateNr].node; |
| 428 | ctxt->vstate->depth = ctxt->vstateTab[ctxt->vstateNr].depth; |
| 429 | ctxt->vstate->occurs = ctxt->vstateTab[ctxt->vstateNr].occurs; |
| 430 | ctxt->vstate->state = ctxt->vstateTab[ctxt->vstateNr].state; |
| 431 | return(ctxt->vstateNr); |
| 432 | } |
| 433 | |
| 434 | #endif /* LIBXML_REGEXP_ENABLED */ |
| 435 | |
| 436 | static int |
| 437 | nodeVPush(xmlValidCtxtPtr ctxt, xmlNodePtr value) |
| 438 | { |
| 439 | if (ctxt->nodeMax <= 0) { |
| 440 | ctxt->nodeMax = 4; |
| 441 | ctxt->nodeTab = |
| 442 | (xmlNodePtr *) xmlMalloc(ctxt->nodeMax * |
| 443 | sizeof(ctxt->nodeTab[0])); |
| 444 | if (ctxt->nodeTab == NULL((void*)0)) { |
| 445 | xmlVErrMemory(ctxt, "malloc failed"); |
| 446 | ctxt->nodeMax = 0; |
| 447 | return (0); |
| 448 | } |
| 449 | } |
| 450 | if (ctxt->nodeNr >= ctxt->nodeMax) { |
| 451 | xmlNodePtr *tmp; |
| 452 | tmp = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab, |
| 453 | ctxt->nodeMax * 2 * sizeof(ctxt->nodeTab[0])); |
| 454 | if (tmp == NULL((void*)0)) { |
| 455 | xmlVErrMemory(ctxt, "realloc failed"); |
| 456 | return (0); |
| 457 | } |
| 458 | ctxt->nodeMax *= 2; |
| 459 | ctxt->nodeTab = tmp; |
| 460 | } |
| 461 | ctxt->nodeTab[ctxt->nodeNr] = value; |
| 462 | ctxt->node = value; |
| 463 | return (ctxt->nodeNr++); |
| 464 | } |
| 465 | static xmlNodePtr |
| 466 | nodeVPop(xmlValidCtxtPtr ctxt) |
| 467 | { |
| 468 | xmlNodePtr ret; |
| 469 | |
| 470 | if (ctxt->nodeNr <= 0) |
| 471 | return (NULL((void*)0)); |
| 472 | ctxt->nodeNr--; |
| 473 | if (ctxt->nodeNr > 0) |
| 474 | ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1]; |
| 475 | else |
| 476 | ctxt->node = NULL((void*)0); |
| 477 | ret = ctxt->nodeTab[ctxt->nodeNr]; |
| 478 | ctxt->nodeTab[ctxt->nodeNr] = NULL((void*)0); |
| 479 | return (ret); |
| 480 | } |
| 481 | |
| 482 | #ifdef DEBUG_VALID_ALGO |
| 483 | static void |
| 484 | xmlValidPrintNode(xmlNodePtr cur) { |
| 485 | if (cur == NULL((void*)0)) { |
| 486 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "null"); |
| 487 | return; |
| 488 | } |
| 489 | switch (cur->type) { |
| 490 | case XML_ELEMENT_NODE: |
| 491 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s ", cur->name); |
| 492 | break; |
| 493 | case XML_TEXT_NODE: |
| 494 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "text "); |
| 495 | break; |
| 496 | case XML_CDATA_SECTION_NODE: |
| 497 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "cdata "); |
| 498 | break; |
| 499 | case XML_ENTITY_REF_NODE: |
| 500 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "&%s; ", cur->name); |
| 501 | break; |
| 502 | case XML_PI_NODE: |
| 503 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "pi(%s) ", cur->name); |
| 504 | break; |
| 505 | case XML_COMMENT_NODE: |
| 506 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "comment "); |
| 507 | break; |
| 508 | case XML_ATTRIBUTE_NODE: |
| 509 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?attr? "); |
| 510 | break; |
| 511 | case XML_ENTITY_NODE: |
| 512 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?ent? "); |
| 513 | break; |
| 514 | case XML_DOCUMENT_NODE: |
| 515 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?doc? "); |
| 516 | break; |
| 517 | case XML_DOCUMENT_TYPE_NODE: |
| 518 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?doctype? "); |
| 519 | break; |
| 520 | case XML_DOCUMENT_FRAG_NODE: |
| 521 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?frag? "); |
| 522 | break; |
| 523 | case XML_NOTATION_NODE: |
| 524 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?nota? "); |
| 525 | break; |
| 526 | case XML_HTML_DOCUMENT_NODE: |
| 527 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?html? "); |
| 528 | break; |
| 529 | #ifdef LIBXML_DOCB_ENABLED |
| 530 | case XML_DOCB_DOCUMENT_NODE: |
| 531 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?docb? "); |
| 532 | break; |
| 533 | #endif |
| 534 | case XML_DTD_NODE: |
| 535 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?dtd? "); |
| 536 | break; |
| 537 | case XML_ELEMENT_DECL: |
| 538 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?edecl? "); |
| 539 | break; |
| 540 | case XML_ATTRIBUTE_DECL: |
| 541 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?adecl? "); |
| 542 | break; |
| 543 | case XML_ENTITY_DECL: |
| 544 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?entdecl? "); |
| 545 | break; |
| 546 | case XML_NAMESPACE_DECL: |
| 547 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "?nsdecl? "); |
| 548 | break; |
| 549 | case XML_XINCLUDE_START: |
| 550 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "incstart "); |
| 551 | break; |
| 552 | case XML_XINCLUDE_END: |
| 553 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "incend "); |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | static void |
| 559 | xmlValidPrintNodeList(xmlNodePtr cur) { |
| 560 | if (cur == NULL((void*)0)) |
| 561 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "null "); |
| 562 | while (cur != NULL((void*)0)) { |
| 563 | xmlValidPrintNode(cur); |
| 564 | cur = cur->next; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static void |
| 569 | xmlValidDebug(xmlNodePtr cur, xmlElementContentPtr cont) { |
| 570 | char expr[5000]; |
| 571 | |
| 572 | expr[0] = 0; |
| 573 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "valid: "); |
| 574 | xmlValidPrintNodeList(cur); |
| 575 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "against "); |
| 576 | xmlSnprintfElementContent(expr, 5000, cont, 1); |
| 577 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s\n", expr); |
| 578 | } |
| 579 | |
| 580 | static void |
| 581 | xmlValidDebugState(xmlValidStatePtr state) { |
| 582 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "("); |
| 583 | if (state->cont == NULL((void*)0)) |
| 584 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "null,"); |
| 585 | else |
| 586 | switch (state->cont->type) { |
| 587 | case XML_ELEMENT_CONTENT_PCDATA: |
| 588 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "pcdata,"); |
| 589 | break; |
| 590 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 591 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s,", |
| 592 | state->cont->name); |
| 593 | break; |
| 594 | case XML_ELEMENT_CONTENT_SEQ: |
| 595 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "seq,"); |
| 596 | break; |
| 597 | case XML_ELEMENT_CONTENT_OR: |
| 598 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "or,"); |
| 599 | break; |
| 600 | } |
| 601 | xmlValidPrintNode(state->node); |
| 602 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), ",%d,%X,%d)", |
| 603 | state->depth, state->occurs, state->state); |
| 604 | } |
| 605 | |
| 606 | static void |
| 607 | xmlValidStateDebug(xmlValidCtxtPtr ctxt) { |
| 608 | int i, j; |
| 609 | |
| 610 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "state: "); |
| 611 | xmlValidDebugState(ctxt->vstate); |
| 612 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), " stack: %d ", |
| 613 | ctxt->vstateNr - 1); |
| 614 | for (i = 0, j = ctxt->vstateNr - 1;(i < 3) && (j > 0);i++,j--) |
| 615 | xmlValidDebugState(&ctxt->vstateTab[j]); |
| 616 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "\n"); |
| 617 | } |
| 618 | |
| 619 | /***** |
| 620 | #define DEBUG_VALID_STATE(n,c) xmlValidDebug(n,c); |
| 621 | *****/ |
| 622 | |
| 623 | #define DEBUG_VALID_STATE(n,c) xmlValidStateDebug(ctxt); |
| 624 | #define DEBUG_VALID_MSG(m) \ |
| 625 | xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s\n", m); |
| 626 | |
| 627 | #else |
| 628 | #define DEBUG_VALID_STATE(n,c) |
| 629 | #define DEBUG_VALID_MSG(m) |
| 630 | #endif |
| 631 | |
| 632 | /* TODO: use hash table for accesses to elem and attribute definitions */ |
| 633 | |
| 634 | |
| 635 | #define CHECK_DTDif (doc == ((void*)0)) return(0); else if ((doc->intSubset == ((void*)0)) && (doc->extSubset == ((void*)0))) return(0) \ |
| 636 | if (doc == NULL((void*)0)) return(0); \ |
| 637 | else if ((doc->intSubset == NULL((void*)0)) && \ |
| 638 | (doc->extSubset == NULL((void*)0))) return(0) |
| 639 | |
| 640 | #ifdef LIBXML_REGEXP_ENABLED |
| 641 | |
| 642 | /************************************************************************ |
| 643 | * * |
| 644 | * Content model validation based on the regexps * |
| 645 | * * |
| 646 | ************************************************************************/ |
| 647 | |
| 648 | /** |
| 649 | * xmlValidBuildAContentModel: |
| 650 | * @content: the content model |
| 651 | * @ctxt: the schema parser context |
| 652 | * @name: the element name whose content is being built |
| 653 | * |
| 654 | * Generate the automata sequence needed for that type |
| 655 | * |
| 656 | * Returns 1 if successful or 0 in case of error. |
| 657 | */ |
| 658 | static int |
| 659 | xmlValidBuildAContentModel(xmlElementContentPtr content, |
| 660 | xmlValidCtxtPtr ctxt, |
| 661 | const xmlChar *name) { |
| 662 | if (content == NULL((void*)0)) { |
| 663 | xmlErrValidNode(ctxt, NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 664 | "Found NULL content in content model of %s\n", |
| 665 | name, NULL((void*)0), NULL((void*)0)); |
| 666 | return(0); |
| 667 | } |
| 668 | switch (content->type) { |
| 669 | case XML_ELEMENT_CONTENT_PCDATA: |
| 670 | xmlErrValidNode(ctxt, NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 671 | "Found PCDATA in content model of %s\n", |
| 672 | name, NULL((void*)0), NULL((void*)0)); |
| 673 | return(0); |
| 674 | break; |
| 675 | case XML_ELEMENT_CONTENT_ELEMENT: { |
| 676 | xmlAutomataStatePtr oldstate = ctxt->state; |
| 677 | xmlChar fn[50]; |
| 678 | xmlChar *fullname; |
| 679 | |
| 680 | fullname = xmlBuildQNamexmlBuildQName__internal_alias(content->name, content->prefix, fn, 50); |
| 681 | if (fullname == NULL((void*)0)) { |
| 682 | xmlVErrMemory(ctxt, "Building content model"); |
| 683 | return(0); |
| 684 | } |
| 685 | |
| 686 | switch (content->ocur) { |
| 687 | case XML_ELEMENT_CONTENT_ONCE: |
| 688 | ctxt->state = xmlAutomataNewTransitionxmlAutomataNewTransition__internal_alias(ctxt->am, |
| 689 | ctxt->state, NULL((void*)0), fullname, NULL((void*)0)); |
| 690 | break; |
| 691 | case XML_ELEMENT_CONTENT_OPT: |
| 692 | ctxt->state = xmlAutomataNewTransitionxmlAutomataNewTransition__internal_alias(ctxt->am, |
| 693 | ctxt->state, NULL((void*)0), fullname, NULL((void*)0)); |
| 694 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, ctxt->state); |
| 695 | break; |
| 696 | case XML_ELEMENT_CONTENT_PLUS: |
| 697 | ctxt->state = xmlAutomataNewTransitionxmlAutomataNewTransition__internal_alias(ctxt->am, |
| 698 | ctxt->state, NULL((void*)0), fullname, NULL((void*)0)); |
| 699 | xmlAutomataNewTransitionxmlAutomataNewTransition__internal_alias(ctxt->am, ctxt->state, |
| 700 | ctxt->state, fullname, NULL((void*)0)); |
| 701 | break; |
| 702 | case XML_ELEMENT_CONTENT_MULT: |
| 703 | ctxt->state = xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, |
| 704 | ctxt->state, NULL((void*)0)); |
| 705 | xmlAutomataNewTransitionxmlAutomataNewTransition__internal_alias(ctxt->am, |
| 706 | ctxt->state, ctxt->state, fullname, NULL((void*)0)); |
| 707 | break; |
| 708 | } |
| 709 | if ((fullname != fn) && (fullname != content->name)) |
| 710 | xmlFree(fullname); |
| 711 | break; |
| 712 | } |
| 713 | case XML_ELEMENT_CONTENT_SEQ: { |
| 714 | xmlAutomataStatePtr oldstate, oldend; |
| 715 | xmlElementContentOccur ocur; |
| 716 | |
| 717 | /* |
| 718 | * Simply iterate over the content |
| 719 | */ |
| 720 | oldstate = ctxt->state; |
| 721 | ocur = content->ocur; |
| 722 | if (ocur != XML_ELEMENT_CONTENT_ONCE) { |
| 723 | ctxt->state = xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, NULL((void*)0)); |
| 724 | oldstate = ctxt->state; |
| 725 | } |
| 726 | do { |
| 727 | xmlValidBuildAContentModel(content->c1, ctxt, name); |
| 728 | content = content->c2; |
| 729 | } while ((content->type == XML_ELEMENT_CONTENT_SEQ) && |
| 730 | (content->ocur == XML_ELEMENT_CONTENT_ONCE)); |
| 731 | xmlValidBuildAContentModel(content, ctxt, name); |
| 732 | oldend = ctxt->state; |
| 733 | ctxt->state = xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, NULL((void*)0)); |
| 734 | switch (ocur) { |
| 735 | case XML_ELEMENT_CONTENT_ONCE: |
| 736 | break; |
| 737 | case XML_ELEMENT_CONTENT_OPT: |
| 738 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, ctxt->state); |
| 739 | break; |
| 740 | case XML_ELEMENT_CONTENT_MULT: |
| 741 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, ctxt->state); |
| 742 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, oldstate); |
| 743 | break; |
| 744 | case XML_ELEMENT_CONTENT_PLUS: |
| 745 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, oldstate); |
| 746 | break; |
| 747 | } |
| 748 | break; |
| 749 | } |
| 750 | case XML_ELEMENT_CONTENT_OR: { |
| 751 | xmlAutomataStatePtr oldstate, oldend; |
| 752 | xmlElementContentOccur ocur; |
| 753 | |
| 754 | ocur = content->ocur; |
| 755 | if ((ocur == XML_ELEMENT_CONTENT_PLUS) || |
| 756 | (ocur == XML_ELEMENT_CONTENT_MULT)) { |
| 757 | ctxt->state = xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, |
| 758 | ctxt->state, NULL((void*)0)); |
| 759 | } |
| 760 | oldstate = ctxt->state; |
| 761 | oldend = xmlAutomataNewStatexmlAutomataNewState__internal_alias(ctxt->am); |
| 762 | |
| 763 | /* |
| 764 | * iterate over the subtypes and remerge the end with an |
| 765 | * epsilon transition |
| 766 | */ |
| 767 | do { |
| 768 | ctxt->state = oldstate; |
| 769 | xmlValidBuildAContentModel(content->c1, ctxt, name); |
| 770 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, ctxt->state, oldend); |
| 771 | content = content->c2; |
| 772 | } while ((content->type == XML_ELEMENT_CONTENT_OR) && |
| 773 | (content->ocur == XML_ELEMENT_CONTENT_ONCE)); |
| 774 | ctxt->state = oldstate; |
| 775 | xmlValidBuildAContentModel(content, ctxt, name); |
| 776 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, ctxt->state, oldend); |
| 777 | ctxt->state = xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, NULL((void*)0)); |
| 778 | switch (ocur) { |
| 779 | case XML_ELEMENT_CONTENT_ONCE: |
| 780 | break; |
| 781 | case XML_ELEMENT_CONTENT_OPT: |
| 782 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, ctxt->state); |
| 783 | break; |
| 784 | case XML_ELEMENT_CONTENT_MULT: |
| 785 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldstate, ctxt->state); |
| 786 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, oldstate); |
| 787 | break; |
| 788 | case XML_ELEMENT_CONTENT_PLUS: |
| 789 | xmlAutomataNewEpsilonxmlAutomataNewEpsilon__internal_alias(ctxt->am, oldend, oldstate); |
| 790 | break; |
| 791 | } |
| 792 | break; |
| 793 | } |
| 794 | default: |
| 795 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 796 | "ContentModel broken for element %s\n", |
| 797 | (const char *) name); |
| 798 | return(0); |
| 799 | } |
| 800 | return(1); |
| 801 | } |
| 802 | /** |
| 803 | * xmlValidBuildContentModel: |
| 804 | * @ctxt: a validation context |
| 805 | * @elem: an element declaration node |
| 806 | * |
| 807 | * (Re)Build the automata associated to the content model of this |
| 808 | * element |
| 809 | * |
| 810 | * Returns 1 in case of success, 0 in case of error |
| 811 | */ |
| 812 | int |
| 813 | xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { |
| 814 | |
| 815 | if ((ctxt == NULL((void*)0)) || (elem == NULL((void*)0))) |
| 816 | return(0); |
| 817 | if (elem->type != XML_ELEMENT_DECL) |
| 818 | return(0); |
| 819 | if (elem->etype != XML_ELEMENT_TYPE_ELEMENT) |
| 820 | return(1); |
| 821 | /* TODO: should we rebuild in this case ? */ |
| 822 | if (elem->contModel != NULL((void*)0)) { |
| 823 | if (!xmlRegexpIsDeterministxmlRegexpIsDeterminist__internal_alias(elem->contModel)) { |
| 824 | ctxt->valid = 0; |
| 825 | return(0); |
| 826 | } |
| 827 | return(1); |
| 828 | } |
| 829 | |
| 830 | ctxt->am = xmlNewAutomataxmlNewAutomata__internal_alias(); |
| 831 | if (ctxt->am == NULL((void*)0)) { |
| 832 | xmlErrValidNode(ctxt, (xmlNodePtr) elem, |
| 833 | XML_ERR_INTERNAL_ERROR, |
| 834 | "Cannot create automata for element %s\n", |
| 835 | elem->name, NULL((void*)0), NULL((void*)0)); |
| 836 | return(0); |
| 837 | } |
| 838 | ctxt->state = xmlAutomataGetInitStatexmlAutomataGetInitState__internal_alias(ctxt->am); |
| 839 | xmlValidBuildAContentModel(elem->content, ctxt, elem->name); |
| 840 | xmlAutomataSetFinalStatexmlAutomataSetFinalState__internal_alias(ctxt->am, ctxt->state); |
| 841 | elem->contModel = xmlAutomataCompilexmlAutomataCompile__internal_alias(ctxt->am); |
| 842 | if (xmlRegexpIsDeterministxmlRegexpIsDeterminist__internal_alias(elem->contModel) != 1) { |
| 843 | char expr[5000]; |
| 844 | expr[0] = 0; |
| 845 | xmlSnprintfElementContent(expr, 5000, elem->content, 1); |
| 846 | xmlErrValidNode(ctxt, (xmlNodePtr) elem, |
| 847 | XML_DTD_CONTENT_NOT_DETERMINIST, |
| 848 | "Content model of %s is not determinist: %s\n", |
| 849 | elem->name, BAD_CAST(xmlChar *) expr, NULL((void*)0)); |
| 850 | #ifdef DEBUG_REGEXP_ALGO |
| 851 | xmlRegexpPrintxmlRegexpPrint__internal_alias(stderrstderr, elem->contModel); |
| 852 | #endif |
| 853 | ctxt->valid = 0; |
| 854 | ctxt->state = NULL((void*)0); |
| 855 | xmlFreeAutomataxmlFreeAutomata__internal_alias(ctxt->am); |
| 856 | ctxt->am = NULL((void*)0); |
| 857 | return(0); |
| 858 | } |
| 859 | ctxt->state = NULL((void*)0); |
| 860 | xmlFreeAutomataxmlFreeAutomata__internal_alias(ctxt->am); |
| 861 | ctxt->am = NULL((void*)0); |
| 862 | return(1); |
| 863 | } |
| 864 | |
| 865 | #endif /* LIBXML_REGEXP_ENABLED */ |
| 866 | |
| 867 | /**************************************************************** |
| 868 | * * |
| 869 | * Util functions for data allocation/deallocation * |
| 870 | * * |
| 871 | ****************************************************************/ |
| 872 | |
| 873 | /** |
| 874 | * xmlNewValidCtxt: |
| 875 | * |
| 876 | * Allocate a validation context structure. |
| 877 | * |
| 878 | * Returns NULL if not, otherwise the new validation context structure |
| 879 | */ |
| 880 | xmlValidCtxtPtr xmlNewValidCtxt(void) { |
| 881 | xmlValidCtxtPtr ret; |
| 882 | |
| 883 | if ((ret = xmlMalloc(sizeof (xmlValidCtxt))) == NULL((void*)0)) { |
| 884 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 885 | return (NULL((void*)0)); |
| 886 | } |
| 887 | |
| 888 | (void) memset(ret, 0, sizeof (xmlValidCtxt)); |
| 889 | |
| 890 | return (ret); |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * xmlFreeValidCtxt: |
| 895 | * @cur: the validation context to free |
| 896 | * |
| 897 | * Free a validation context structure. |
| 898 | */ |
| 899 | void |
| 900 | xmlFreeValidCtxt(xmlValidCtxtPtr cur) { |
| 901 | if (cur->vstateTab != NULL((void*)0)) |
| 902 | xmlFree(cur->vstateTab); |
| 903 | if (cur->nodeTab != NULL((void*)0)) |
| 904 | xmlFree(cur->nodeTab); |
| 905 | xmlFree(cur); |
| 906 | } |
| 907 | |
| 908 | #endif /* LIBXML_VALID_ENABLED */ |
| 909 | |
| 910 | /** |
| 911 | * xmlNewDocElementContent: |
| 912 | * @doc: the document |
| 913 | * @name: the subelement name or NULL |
| 914 | * @type: the type of element content decl |
| 915 | * |
| 916 | * Allocate an element content structure for the document. |
| 917 | * |
| 918 | * Returns NULL if not, otherwise the new element content structure |
| 919 | */ |
| 920 | xmlElementContentPtr |
| 921 | xmlNewDocElementContent(xmlDocPtr doc, const xmlChar *name, |
| 922 | xmlElementContentType type) { |
| 923 | xmlElementContentPtr ret; |
| 924 | xmlDictPtr dict = NULL((void*)0); |
| 925 | |
| 926 | if (doc != NULL((void*)0)) |
| 927 | dict = doc->dict; |
| 928 | |
| 929 | switch(type) { |
| 930 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 931 | if (name == NULL((void*)0)) { |
| 932 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 933 | "xmlNewElementContent : name == NULL !\n", |
| 934 | NULL((void*)0)); |
| 935 | } |
| 936 | break; |
| 937 | case XML_ELEMENT_CONTENT_PCDATA: |
| 938 | case XML_ELEMENT_CONTENT_SEQ: |
| 939 | case XML_ELEMENT_CONTENT_OR: |
| 940 | if (name != NULL((void*)0)) { |
| 941 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 942 | "xmlNewElementContent : name != NULL !\n", |
| 943 | NULL((void*)0)); |
| 944 | } |
| 945 | break; |
| 946 | default: |
| 947 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 948 | "Internal: ELEMENT content corrupted invalid type\n", |
| 949 | NULL((void*)0)); |
| 950 | return(NULL((void*)0)); |
| 951 | } |
| 952 | ret = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent)); |
| 953 | if (ret == NULL((void*)0)) { |
| 954 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 955 | return(NULL((void*)0)); |
| 956 | } |
| 957 | memset(ret, 0, sizeof(xmlElementContent)); |
| 958 | ret->type = type; |
| 959 | ret->ocur = XML_ELEMENT_CONTENT_ONCE; |
| 960 | if (name != NULL((void*)0)) { |
| 961 | int l; |
| 962 | const xmlChar *tmp; |
| 963 | |
| 964 | tmp = xmlSplitQName3xmlSplitQName3__internal_alias(name, &l); |
| 965 | if (tmp == NULL((void*)0)) { |
| 966 | if (dict == NULL((void*)0)) |
| 967 | ret->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 968 | else |
| 969 | ret->name = xmlDictLookupxmlDictLookup__internal_alias(dict, name, -1); |
| 970 | } else { |
| 971 | if (dict == NULL((void*)0)) { |
| 972 | ret->prefix = xmlStrndupxmlStrndup__internal_alias(name, l); |
| 973 | ret->name = xmlStrdupxmlStrdup__internal_alias(tmp); |
| 974 | } else { |
| 975 | ret->prefix = xmlDictLookupxmlDictLookup__internal_alias(dict, name, l); |
| 976 | ret->name = xmlDictLookupxmlDictLookup__internal_alias(dict, tmp, -1); |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | return(ret); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * xmlNewElementContent: |
| 985 | * @name: the subelement name or NULL |
| 986 | * @type: the type of element content decl |
| 987 | * |
| 988 | * Allocate an element content structure. |
| 989 | * Deprecated in favor of xmlNewDocElementContent |
| 990 | * |
| 991 | * Returns NULL if not, otherwise the new element content structure |
| 992 | */ |
| 993 | xmlElementContentPtr |
| 994 | xmlNewElementContent(const xmlChar *name, xmlElementContentType type) { |
| 995 | return(xmlNewDocElementContent(NULL((void*)0), name, type)); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * xmlCopyDocElementContent: |
| 1000 | * @doc: the document owning the element declaration |
| 1001 | * @cur: An element content pointer. |
| 1002 | * |
| 1003 | * Build a copy of an element content description. |
| 1004 | * |
| 1005 | * Returns the new xmlElementContentPtr or NULL in case of error. |
| 1006 | */ |
| 1007 | xmlElementContentPtr |
| 1008 | xmlCopyDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur) { |
| 1009 | xmlElementContentPtr ret = NULL((void*)0), prev = NULL((void*)0), tmp; |
| 1010 | xmlDictPtr dict = NULL((void*)0); |
| 1011 | |
| 1012 | if (cur == NULL((void*)0)) return(NULL((void*)0)); |
| 1013 | |
| 1014 | if (doc != NULL((void*)0)) |
| 1015 | dict = doc->dict; |
| 1016 | |
| 1017 | ret = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent)); |
| 1018 | if (ret == NULL((void*)0)) { |
| 1019 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 1020 | return(NULL((void*)0)); |
| 1021 | } |
| 1022 | memset(ret, 0, sizeof(xmlElementContent)); |
| 1023 | ret->type = cur->type; |
| 1024 | ret->ocur = cur->ocur; |
| 1025 | if (cur->name != NULL((void*)0)) { |
| 1026 | if (dict) |
| 1027 | ret->name = xmlDictLookupxmlDictLookup__internal_alias(dict, cur->name, -1); |
| 1028 | else |
| 1029 | ret->name = xmlStrdupxmlStrdup__internal_alias(cur->name); |
| 1030 | } |
| 1031 | |
| 1032 | if (cur->prefix != NULL((void*)0)) { |
| 1033 | if (dict) |
| 1034 | ret->prefix = xmlDictLookupxmlDictLookup__internal_alias(dict, cur->prefix, -1); |
| 1035 | else |
| 1036 | ret->prefix = xmlStrdupxmlStrdup__internal_alias(cur->prefix); |
| 1037 | } |
| 1038 | if (cur->c1 != NULL((void*)0)) |
| 1039 | ret->c1 = xmlCopyDocElementContent(doc, cur->c1); |
| 1040 | if (ret->c1 != NULL((void*)0)) |
| 1041 | ret->c1->parent = ret; |
| 1042 | if (cur->c2 != NULL((void*)0)) { |
| 1043 | prev = ret; |
| 1044 | cur = cur->c2; |
| 1045 | while (cur != NULL((void*)0)) { |
| 1046 | tmp = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent)); |
| 1047 | if (tmp == NULL((void*)0)) { |
| 1048 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 1049 | return(ret); |
| 1050 | } |
| 1051 | memset(tmp, 0, sizeof(xmlElementContent)); |
| 1052 | tmp->type = cur->type; |
| 1053 | tmp->ocur = cur->ocur; |
| 1054 | prev->c2 = tmp; |
| 1055 | if (cur->name != NULL((void*)0)) { |
| 1056 | if (dict) |
| 1057 | tmp->name = xmlDictLookupxmlDictLookup__internal_alias(dict, cur->name, -1); |
| 1058 | else |
| 1059 | tmp->name = xmlStrdupxmlStrdup__internal_alias(cur->name); |
| 1060 | } |
| 1061 | |
| 1062 | if (cur->prefix != NULL((void*)0)) { |
| 1063 | if (dict) |
| 1064 | tmp->prefix = xmlDictLookupxmlDictLookup__internal_alias(dict, cur->prefix, -1); |
| 1065 | else |
| 1066 | tmp->prefix = xmlStrdupxmlStrdup__internal_alias(cur->prefix); |
| 1067 | } |
| 1068 | if (cur->c1 != NULL((void*)0)) |
| 1069 | tmp->c1 = xmlCopyDocElementContent(doc,cur->c1); |
| 1070 | if (tmp->c1 != NULL((void*)0)) |
| 1071 | tmp->c1->parent = ret; |
| 1072 | prev = tmp; |
| 1073 | cur = cur->c2; |
| 1074 | } |
| 1075 | } |
| 1076 | return(ret); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * xmlCopyElementContent: |
| 1081 | * @cur: An element content pointer. |
| 1082 | * |
| 1083 | * Build a copy of an element content description. |
| 1084 | * Deprecated, use xmlCopyDocElementContent instead |
| 1085 | * |
| 1086 | * Returns the new xmlElementContentPtr or NULL in case of error. |
| 1087 | */ |
| 1088 | xmlElementContentPtr |
| 1089 | xmlCopyElementContent(xmlElementContentPtr cur) { |
| 1090 | return(xmlCopyDocElementContent(NULL((void*)0), cur)); |
| 1091 | } |
| 1092 | |
| 1093 | /** |
| 1094 | * xmlFreeDocElementContent: |
| 1095 | * @doc: the document owning the element declaration |
| 1096 | * @cur: the element content tree to free |
| 1097 | * |
| 1098 | * Free an element content structure. The whole subtree is removed. |
| 1099 | */ |
| 1100 | void |
| 1101 | xmlFreeDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur) { |
| 1102 | xmlElementContentPtr next; |
| 1103 | xmlDictPtr dict = NULL((void*)0); |
| 1104 | |
| 1105 | if (doc != NULL((void*)0)) |
| 1106 | dict = doc->dict; |
| 1107 | |
| 1108 | while (cur != NULL((void*)0)) { |
| 1109 | next = cur->c2; |
| 1110 | switch (cur->type) { |
| 1111 | case XML_ELEMENT_CONTENT_PCDATA: |
| 1112 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 1113 | case XML_ELEMENT_CONTENT_SEQ: |
| 1114 | case XML_ELEMENT_CONTENT_OR: |
| 1115 | break; |
| 1116 | default: |
| 1117 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 1118 | "Internal: ELEMENT content corrupted invalid type\n", |
| 1119 | NULL((void*)0)); |
| 1120 | return; |
| 1121 | } |
| 1122 | if (cur->c1 != NULL((void*)0)) xmlFreeDocElementContent(doc, cur->c1); |
| 1123 | if (dict) { |
| 1124 | if ((cur->name != NULL((void*)0)) && (!xmlDictOwnsxmlDictOwns__internal_alias(dict, cur->name))) |
| 1125 | xmlFree((xmlChar *) cur->name); |
| 1126 | if ((cur->prefix != NULL((void*)0)) && (!xmlDictOwnsxmlDictOwns__internal_alias(dict, cur->prefix))) |
| 1127 | xmlFree((xmlChar *) cur->prefix); |
| 1128 | } else { |
| 1129 | if (cur->name != NULL((void*)0)) xmlFree((xmlChar *) cur->name); |
| 1130 | if (cur->prefix != NULL((void*)0)) xmlFree((xmlChar *) cur->prefix); |
| 1131 | } |
| 1132 | xmlFree(cur); |
| 1133 | cur = next; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * xmlFreeElementContent: |
| 1139 | * @cur: the element content tree to free |
| 1140 | * |
| 1141 | * Free an element content structure. The whole subtree is removed. |
| 1142 | * Deprecated, use xmlFreeDocElementContent instead |
| 1143 | */ |
| 1144 | void |
| 1145 | xmlFreeElementContent(xmlElementContentPtr cur) { |
| 1146 | xmlFreeDocElementContent(NULL((void*)0), cur); |
| 1147 | } |
| 1148 | |
| 1149 | #ifdef LIBXML_OUTPUT_ENABLED |
| 1150 | /** |
| 1151 | * xmlDumpElementContent: |
| 1152 | * @buf: An XML buffer |
| 1153 | * @content: An element table |
| 1154 | * @glob: 1 if one must print the englobing parenthesis, 0 otherwise |
| 1155 | * |
| 1156 | * This will dump the content of the element table as an XML DTD definition |
| 1157 | */ |
| 1158 | static void |
| 1159 | xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) { |
| 1160 | if (content == NULL((void*)0)) return; |
| 1161 | |
| 1162 | if (glob) xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "("); |
| 1163 | switch (content->type) { |
| 1164 | case XML_ELEMENT_CONTENT_PCDATA: |
| 1165 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "#PCDATA"); |
| 1166 | break; |
| 1167 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 1168 | if (content->prefix != NULL((void*)0)) { |
| 1169 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, content->prefix); |
| 1170 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 1171 | } |
| 1172 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, content->name); |
| 1173 | break; |
| 1174 | case XML_ELEMENT_CONTENT_SEQ: |
| 1175 | if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || |
| 1176 | (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) |
| 1177 | xmlDumpElementContent(buf, content->c1, 1); |
| 1178 | else |
| 1179 | xmlDumpElementContent(buf, content->c1, 0); |
| 1180 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " , "); |
| 1181 | if ((content->c2->type == XML_ELEMENT_CONTENT_OR) || |
| 1182 | ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) && |
| 1183 | (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) |
| 1184 | xmlDumpElementContent(buf, content->c2, 1); |
| 1185 | else |
| 1186 | xmlDumpElementContent(buf, content->c2, 0); |
| 1187 | break; |
| 1188 | case XML_ELEMENT_CONTENT_OR: |
| 1189 | if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || |
| 1190 | (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) |
| 1191 | xmlDumpElementContent(buf, content->c1, 1); |
| 1192 | else |
| 1193 | xmlDumpElementContent(buf, content->c1, 0); |
| 1194 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " | "); |
| 1195 | if ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) || |
| 1196 | ((content->c2->type == XML_ELEMENT_CONTENT_OR) && |
| 1197 | (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) |
| 1198 | xmlDumpElementContent(buf, content->c2, 1); |
| 1199 | else |
| 1200 | xmlDumpElementContent(buf, content->c2, 0); |
| 1201 | break; |
| 1202 | default: |
| 1203 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 1204 | "Internal: ELEMENT content corrupted invalid type\n", |
| 1205 | NULL((void*)0)); |
| 1206 | } |
| 1207 | if (glob) |
| 1208 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ")"); |
| 1209 | switch (content->ocur) { |
| 1210 | case XML_ELEMENT_CONTENT_ONCE: |
| 1211 | break; |
| 1212 | case XML_ELEMENT_CONTENT_OPT: |
| 1213 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "?"); |
| 1214 | break; |
| 1215 | case XML_ELEMENT_CONTENT_MULT: |
| 1216 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "*"); |
| 1217 | break; |
| 1218 | case XML_ELEMENT_CONTENT_PLUS: |
| 1219 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "+"); |
| 1220 | break; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * xmlSprintfElementContent: |
| 1226 | * @buf: an output buffer |
| 1227 | * @content: An element table |
| 1228 | * @englob: 1 if one must print the englobing parenthesis, 0 otherwise |
| 1229 | * |
| 1230 | * Deprecated, unsafe, use xmlSnprintfElementContent |
| 1231 | */ |
| 1232 | void |
| 1233 | xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1234 | xmlElementContentPtr content ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1235 | int englob ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 1236 | } |
| 1237 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1238 | |
| 1239 | /** |
| 1240 | * xmlSnprintfElementContent: |
| 1241 | * @buf: an output buffer |
| 1242 | * @size: the buffer size |
| 1243 | * @content: An element table |
| 1244 | * @englob: 1 if one must print the englobing parenthesis, 0 otherwise |
| 1245 | * |
| 1246 | * This will dump the content of the element content definition |
| 1247 | * Intended just for the debug routine |
| 1248 | */ |
| 1249 | void |
| 1250 | xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int englob) { |
| 1251 | int len; |
| 1252 | |
| 1253 | if (content == NULL((void*)0)) return; |
| 1254 | len = strlen(buf); |
| 1255 | if (size - len < 50) { |
| 1256 | if ((size - len > 4) && (buf[len - 1] != '.')) |
| 1257 | strcat(buf, " ..."); |
| 1258 | return; |
| 1259 | } |
| 1260 | if (englob) strcat(buf, "("); |
| 1261 | switch (content->type) { |
| 1262 | case XML_ELEMENT_CONTENT_PCDATA: |
| 1263 | strcat(buf, "#PCDATA"); |
| 1264 | break; |
| 1265 | case XML_ELEMENT_CONTENT_ELEMENT: |
| 1266 | if (content->prefix != NULL((void*)0)) { |
| 1267 | if (size - len < xmlStrlenxmlStrlen__internal_alias(content->prefix) + 10) { |
| 1268 | strcat(buf, " ..."); |
| 1269 | return; |
| 1270 | } |
| 1271 | strcat(buf, (char *) content->prefix); |
| 1272 | strcat(buf, ":"); |
| 1273 | } |
| 1274 | if (size - len < xmlStrlenxmlStrlen__internal_alias(content->name) + 10) { |
| 1275 | strcat(buf, " ..."); |
| 1276 | return; |
| 1277 | } |
| 1278 | if (content->name != NULL((void*)0)) |
| 1279 | strcat(buf, (char *) content->name); |
| 1280 | break; |
| 1281 | case XML_ELEMENT_CONTENT_SEQ: |
| 1282 | if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || |
| 1283 | (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) |
| 1284 | xmlSnprintfElementContent(buf, size, content->c1, 1); |
| 1285 | else |
| 1286 | xmlSnprintfElementContent(buf, size, content->c1, 0); |
| 1287 | len = strlen(buf); |
| 1288 | if (size - len < 50) { |
| 1289 | if ((size - len > 4) && (buf[len - 1] != '.')) |
| 1290 | strcat(buf, " ..."); |
| 1291 | return; |
| 1292 | } |
| 1293 | strcat(buf, " , "); |
| 1294 | if (((content->c2->type == XML_ELEMENT_CONTENT_OR) || |
| 1295 | (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) && |
| 1296 | (content->c2->type != XML_ELEMENT_CONTENT_ELEMENT)) |
| 1297 | xmlSnprintfElementContent(buf, size, content->c2, 1); |
| 1298 | else |
| 1299 | xmlSnprintfElementContent(buf, size, content->c2, 0); |
| 1300 | break; |
| 1301 | case XML_ELEMENT_CONTENT_OR: |
| 1302 | if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || |
| 1303 | (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) |
| 1304 | xmlSnprintfElementContent(buf, size, content->c1, 1); |
| 1305 | else |
| 1306 | xmlSnprintfElementContent(buf, size, content->c1, 0); |
| 1307 | len = strlen(buf); |
| 1308 | if (size - len < 50) { |
| 1309 | if ((size - len > 4) && (buf[len - 1] != '.')) |
| 1310 | strcat(buf, " ..."); |
| 1311 | return; |
| 1312 | } |
| 1313 | strcat(buf, " | "); |
| 1314 | if (((content->c2->type == XML_ELEMENT_CONTENT_SEQ) || |
| 1315 | (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) && |
| 1316 | (content->c2->type != XML_ELEMENT_CONTENT_ELEMENT)) |
| 1317 | xmlSnprintfElementContent(buf, size, content->c2, 1); |
| 1318 | else |
| 1319 | xmlSnprintfElementContent(buf, size, content->c2, 0); |
| 1320 | break; |
| 1321 | } |
| 1322 | if (englob) |
| 1323 | strcat(buf, ")"); |
| 1324 | switch (content->ocur) { |
| 1325 | case XML_ELEMENT_CONTENT_ONCE: |
| 1326 | break; |
| 1327 | case XML_ELEMENT_CONTENT_OPT: |
| 1328 | strcat(buf, "?"); |
| 1329 | break; |
| 1330 | case XML_ELEMENT_CONTENT_MULT: |
| 1331 | strcat(buf, "*"); |
| 1332 | break; |
| 1333 | case XML_ELEMENT_CONTENT_PLUS: |
| 1334 | strcat(buf, "+"); |
| 1335 | break; |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | /**************************************************************** |
| 1340 | * * |
| 1341 | * Registration of DTD declarations * |
| 1342 | * * |
| 1343 | ****************************************************************/ |
| 1344 | |
| 1345 | /** |
| 1346 | * xmlFreeElement: |
| 1347 | * @elem: An element |
| 1348 | * |
| 1349 | * Deallocate the memory used by an element definition |
| 1350 | */ |
| 1351 | static void |
| 1352 | xmlFreeElement(xmlElementPtr elem) { |
| 1353 | if (elem == NULL((void*)0)) return; |
| 1354 | xmlUnlinkNodexmlUnlinkNode__internal_alias((xmlNodePtr) elem); |
| 1355 | xmlFreeDocElementContent(elem->doc, elem->content); |
| 1356 | if (elem->name != NULL((void*)0)) |
| 1357 | xmlFree((xmlChar *) elem->name); |
| 1358 | if (elem->prefix != NULL((void*)0)) |
| 1359 | xmlFree((xmlChar *) elem->prefix); |
| 1360 | #ifdef LIBXML_REGEXP_ENABLED |
| 1361 | if (elem->contModel != NULL((void*)0)) |
| 1362 | xmlRegFreeRegexpxmlRegFreeRegexp__internal_alias(elem->contModel); |
| 1363 | #endif |
| 1364 | xmlFree(elem); |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | /** |
| 1369 | * xmlAddElementDecl: |
| 1370 | * @ctxt: the validation context |
| 1371 | * @dtd: pointer to the DTD |
| 1372 | * @name: the entity name |
| 1373 | * @type: the element type |
| 1374 | * @content: the element content tree or NULL |
| 1375 | * |
| 1376 | * Register a new element declaration |
| 1377 | * |
| 1378 | * Returns NULL if not, otherwise the entity |
| 1379 | */ |
| 1380 | xmlElementPtr |
| 1381 | xmlAddElementDecl(xmlValidCtxtPtr ctxt, |
| 1382 | xmlDtdPtr dtd, const xmlChar *name, |
| 1383 | xmlElementTypeVal type, |
| 1384 | xmlElementContentPtr content) { |
| 1385 | xmlElementPtr ret; |
| 1386 | xmlElementTablePtr table; |
| 1387 | xmlAttributePtr oldAttributes = NULL((void*)0); |
| 1388 | xmlChar *ns, *uqname; |
| 1389 | |
| 1390 | if (dtd == NULL((void*)0)) { |
| 1391 | return(NULL((void*)0)); |
| 1392 | } |
| 1393 | if (name == NULL((void*)0)) { |
| 1394 | return(NULL((void*)0)); |
| 1395 | } |
| 1396 | |
| 1397 | switch (type) { |
| 1398 | case XML_ELEMENT_TYPE_EMPTY: |
| 1399 | if (content != NULL((void*)0)) { |
| 1400 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1401 | "xmlAddElementDecl: content != NULL for EMPTY\n", |
| 1402 | NULL((void*)0)); |
| 1403 | return(NULL((void*)0)); |
| 1404 | } |
| 1405 | break; |
| 1406 | case XML_ELEMENT_TYPE_ANY: |
| 1407 | if (content != NULL((void*)0)) { |
| 1408 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1409 | "xmlAddElementDecl: content != NULL for ANY\n", |
| 1410 | NULL((void*)0)); |
| 1411 | return(NULL((void*)0)); |
| 1412 | } |
| 1413 | break; |
| 1414 | case XML_ELEMENT_TYPE_MIXED: |
| 1415 | if (content == NULL((void*)0)) { |
| 1416 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1417 | "xmlAddElementDecl: content == NULL for MIXED\n", |
| 1418 | NULL((void*)0)); |
| 1419 | return(NULL((void*)0)); |
| 1420 | } |
| 1421 | break; |
| 1422 | case XML_ELEMENT_TYPE_ELEMENT: |
| 1423 | if (content == NULL((void*)0)) { |
| 1424 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1425 | "xmlAddElementDecl: content == NULL for ELEMENT\n", |
| 1426 | NULL((void*)0)); |
| 1427 | return(NULL((void*)0)); |
| 1428 | } |
| 1429 | break; |
| 1430 | default: |
| 1431 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1432 | "Internal: ELEMENT decl corrupted invalid type\n", |
| 1433 | NULL((void*)0)); |
| 1434 | return(NULL((void*)0)); |
| 1435 | } |
| 1436 | |
| 1437 | /* |
| 1438 | * check if name is a QName |
| 1439 | */ |
| 1440 | uqname = xmlSplitQName2xmlSplitQName2__internal_alias(name, &ns); |
| 1441 | if (uqname != NULL((void*)0)) |
| 1442 | name = uqname; |
| 1443 | |
| 1444 | /* |
| 1445 | * Create the Element table if needed. |
| 1446 | */ |
| 1447 | table = (xmlElementTablePtr) dtd->elements; |
| 1448 | if (table == NULL((void*)0)) { |
| 1449 | xmlDictPtr dict = NULL((void*)0); |
| 1450 | |
| 1451 | if (dtd->doc != NULL((void*)0)) |
| 1452 | dict = dtd->doc->dict; |
| 1453 | table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, dict); |
| 1454 | dtd->elements = (void *) table; |
| 1455 | } |
| 1456 | if (table == NULL((void*)0)) { |
| 1457 | xmlVErrMemory(ctxt, |
| 1458 | "xmlAddElementDecl: Table creation failed!\n"); |
| 1459 | if (uqname != NULL((void*)0)) |
| 1460 | xmlFree(uqname); |
| 1461 | if (ns != NULL((void*)0)) |
| 1462 | xmlFree(ns); |
| 1463 | return(NULL((void*)0)); |
| 1464 | } |
| 1465 | |
| 1466 | /* |
| 1467 | * lookup old attributes inserted on an undefined element in the |
| 1468 | * internal subset. |
| 1469 | */ |
| 1470 | if ((dtd->doc != NULL((void*)0)) && (dtd->doc->intSubset != NULL((void*)0))) { |
| 1471 | ret = xmlHashLookup2xmlHashLookup2__internal_alias(dtd->doc->intSubset->elements, name, ns); |
| 1472 | if ((ret != NULL((void*)0)) && (ret->etype == XML_ELEMENT_TYPE_UNDEFINED)) { |
| 1473 | oldAttributes = ret->attributes; |
| 1474 | ret->attributes = NULL((void*)0); |
| 1475 | xmlHashRemoveEntry2xmlHashRemoveEntry2__internal_alias(dtd->doc->intSubset->elements, name, ns, NULL((void*)0)); |
| 1476 | xmlFreeElement(ret); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | /* |
| 1481 | * The element may already be present if one of its attribute |
| 1482 | * was registered first |
| 1483 | */ |
| 1484 | ret = xmlHashLookup2xmlHashLookup2__internal_alias(table, name, ns); |
| 1485 | if (ret != NULL((void*)0)) { |
| 1486 | if (ret->etype != XML_ELEMENT_TYPE_UNDEFINED) { |
| 1487 | #ifdef LIBXML_VALID_ENABLED |
| 1488 | /* |
| 1489 | * The element is already defined in this DTD. |
| 1490 | */ |
| 1491 | xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED, |
| 1492 | "Redefinition of element %s\n", |
| 1493 | name, NULL((void*)0), NULL((void*)0)); |
| 1494 | #endif /* LIBXML_VALID_ENABLED */ |
| 1495 | if (uqname != NULL((void*)0)) |
| 1496 | xmlFree(uqname); |
| 1497 | if (ns != NULL((void*)0)) |
| 1498 | xmlFree(ns); |
| 1499 | return(NULL((void*)0)); |
| 1500 | } |
| 1501 | if (ns != NULL((void*)0)) { |
| 1502 | xmlFree(ns); |
| 1503 | ns = NULL((void*)0); |
| 1504 | } |
| 1505 | } else { |
| 1506 | ret = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); |
| 1507 | if (ret == NULL((void*)0)) { |
| 1508 | xmlVErrMemory(ctxt, "malloc failed"); |
| 1509 | if (uqname != NULL((void*)0)) |
| 1510 | xmlFree(uqname); |
| 1511 | if (ns != NULL((void*)0)) |
| 1512 | xmlFree(ns); |
| 1513 | return(NULL((void*)0)); |
| 1514 | } |
| 1515 | memset(ret, 0, sizeof(xmlElement)); |
| 1516 | ret->type = XML_ELEMENT_DECL; |
| 1517 | |
| 1518 | /* |
| 1519 | * fill the structure. |
| 1520 | */ |
| 1521 | ret->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 1522 | if (ret->name == NULL((void*)0)) { |
| 1523 | xmlVErrMemory(ctxt, "malloc failed"); |
| 1524 | if (uqname != NULL((void*)0)) |
| 1525 | xmlFree(uqname); |
| 1526 | if (ns != NULL((void*)0)) |
| 1527 | xmlFree(ns); |
| 1528 | xmlFree(ret); |
| 1529 | return(NULL((void*)0)); |
| 1530 | } |
| 1531 | ret->prefix = ns; |
| 1532 | |
| 1533 | /* |
| 1534 | * Validity Check: |
| 1535 | * Insertion must not fail |
| 1536 | */ |
| 1537 | if (xmlHashAddEntry2xmlHashAddEntry2__internal_alias(table, name, ns, ret)) { |
| 1538 | #ifdef LIBXML_VALID_ENABLED |
| 1539 | /* |
| 1540 | * The element is already defined in this DTD. |
| 1541 | */ |
| 1542 | xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED, |
| 1543 | "Redefinition of element %s\n", |
| 1544 | name, NULL((void*)0), NULL((void*)0)); |
| 1545 | #endif /* LIBXML_VALID_ENABLED */ |
| 1546 | xmlFreeElement(ret); |
| 1547 | if (uqname != NULL((void*)0)) |
| 1548 | xmlFree(uqname); |
| 1549 | return(NULL((void*)0)); |
| 1550 | } |
| 1551 | /* |
| 1552 | * For new element, may have attributes from earlier |
| 1553 | * definition in internal subset |
| 1554 | */ |
| 1555 | ret->attributes = oldAttributes; |
| 1556 | } |
| 1557 | |
| 1558 | /* |
| 1559 | * Finish to fill the structure. |
| 1560 | */ |
| 1561 | ret->etype = type; |
| 1562 | /* |
| 1563 | * Avoid a stupid copy when called by the parser |
| 1564 | * and flag it by setting a special parent value |
| 1565 | * so the parser doesn't unallocate it. |
| 1566 | */ |
| 1567 | if ((ctxt != NULL((void*)0)) && |
| 1568 | ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_00xabcd1234) || |
| 1569 | (ctxt->finishDtd == XML_CTXT_FINISH_DTD_10xabcd1235))) { |
| 1570 | ret->content = content; |
| 1571 | if (content != NULL((void*)0)) |
| 1572 | content->parent = (xmlElementContentPtr) 1; |
| 1573 | } else { |
| 1574 | ret->content = xmlCopyDocElementContent(dtd->doc, content); |
| 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * Link it to the DTD |
| 1579 | */ |
| 1580 | ret->parent = dtd; |
| 1581 | ret->doc = dtd->doc; |
| 1582 | if (dtd->last == NULL((void*)0)) { |
| 1583 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 1584 | } else { |
| 1585 | dtd->last->next = (xmlNodePtr) ret; |
| 1586 | ret->prev = dtd->last; |
| 1587 | dtd->last = (xmlNodePtr) ret; |
| 1588 | } |
| 1589 | if (uqname != NULL((void*)0)) |
| 1590 | xmlFree(uqname); |
| 1591 | return(ret); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * xmlFreeElementTable: |
| 1596 | * @table: An element table |
| 1597 | * |
| 1598 | * Deallocate the memory used by an element hash table. |
| 1599 | */ |
| 1600 | void |
| 1601 | xmlFreeElementTable(xmlElementTablePtr table) { |
| 1602 | xmlHashFreexmlHashFree__internal_alias(table, (xmlHashDeallocator) xmlFreeElement); |
| 1603 | } |
| 1604 | |
| 1605 | #ifdef LIBXML_TREE_ENABLED |
| 1606 | /** |
| 1607 | * xmlCopyElement: |
| 1608 | * @elem: An element |
| 1609 | * |
| 1610 | * Build a copy of an element. |
| 1611 | * |
| 1612 | * Returns the new xmlElementPtr or NULL in case of error. |
| 1613 | */ |
| 1614 | static xmlElementPtr |
| 1615 | xmlCopyElement(xmlElementPtr elem) { |
| 1616 | xmlElementPtr cur; |
| 1617 | |
| 1618 | cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); |
| 1619 | if (cur == NULL((void*)0)) { |
| 1620 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 1621 | return(NULL((void*)0)); |
| 1622 | } |
| 1623 | memset(cur, 0, sizeof(xmlElement)); |
| 1624 | cur->type = XML_ELEMENT_DECL; |
| 1625 | cur->etype = elem->etype; |
| 1626 | if (elem->name != NULL((void*)0)) |
| 1627 | cur->name = xmlStrdupxmlStrdup__internal_alias(elem->name); |
| 1628 | else |
| 1629 | cur->name = NULL((void*)0); |
| 1630 | if (elem->prefix != NULL((void*)0)) |
| 1631 | cur->prefix = xmlStrdupxmlStrdup__internal_alias(elem->prefix); |
| 1632 | else |
| 1633 | cur->prefix = NULL((void*)0); |
| 1634 | cur->content = xmlCopyElementContent(elem->content); |
| 1635 | /* TODO : rebuild the attribute list on the copy */ |
| 1636 | cur->attributes = NULL((void*)0); |
| 1637 | return(cur); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * xmlCopyElementTable: |
| 1642 | * @table: An element table |
| 1643 | * |
| 1644 | * Build a copy of an element table. |
| 1645 | * |
| 1646 | * Returns the new xmlElementTablePtr or NULL in case of error. |
| 1647 | */ |
| 1648 | xmlElementTablePtr |
| 1649 | xmlCopyElementTable(xmlElementTablePtr table) { |
| 1650 | return((xmlElementTablePtr) xmlHashCopyxmlHashCopy__internal_alias(table, |
| 1651 | (xmlHashCopier) xmlCopyElement)); |
| 1652 | } |
| 1653 | #endif /* LIBXML_TREE_ENABLED */ |
| 1654 | |
| 1655 | #ifdef LIBXML_OUTPUT_ENABLED |
| 1656 | /** |
| 1657 | * xmlDumpElementDecl: |
| 1658 | * @buf: the XML buffer output |
| 1659 | * @elem: An element table |
| 1660 | * |
| 1661 | * This will dump the content of the element declaration as an XML |
| 1662 | * DTD definition |
| 1663 | */ |
| 1664 | void |
| 1665 | xmlDumpElementDecl(xmlBufferPtr buf, xmlElementPtr elem) { |
| 1666 | if ((buf == NULL((void*)0)) || (elem == NULL((void*)0))) |
| 1667 | return; |
| 1668 | switch (elem->etype) { |
| 1669 | case XML_ELEMENT_TYPE_EMPTY: |
| 1670 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!ELEMENT "); |
| 1671 | if (elem->prefix != NULL((void*)0)) { |
| 1672 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->prefix); |
| 1673 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 1674 | } |
| 1675 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->name); |
| 1676 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " EMPTY>\n"); |
| 1677 | break; |
| 1678 | case XML_ELEMENT_TYPE_ANY: |
| 1679 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!ELEMENT "); |
| 1680 | if (elem->prefix != NULL((void*)0)) { |
| 1681 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->prefix); |
| 1682 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 1683 | } |
| 1684 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->name); |
| 1685 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " ANY>\n"); |
| 1686 | break; |
| 1687 | case XML_ELEMENT_TYPE_MIXED: |
| 1688 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!ELEMENT "); |
| 1689 | if (elem->prefix != NULL((void*)0)) { |
| 1690 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->prefix); |
| 1691 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 1692 | } |
| 1693 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->name); |
| 1694 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " "); |
| 1695 | xmlDumpElementContent(buf, elem->content, 1); |
| 1696 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ">\n"); |
| 1697 | break; |
| 1698 | case XML_ELEMENT_TYPE_ELEMENT: |
| 1699 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!ELEMENT "); |
| 1700 | if (elem->prefix != NULL((void*)0)) { |
| 1701 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->prefix); |
| 1702 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 1703 | } |
| 1704 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, elem->name); |
| 1705 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " "); |
| 1706 | xmlDumpElementContent(buf, elem->content, 1); |
| 1707 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ">\n"); |
| 1708 | break; |
| 1709 | default: |
| 1710 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 1711 | "Internal: ELEMENT struct corrupted invalid type\n", |
| 1712 | NULL((void*)0)); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * xmlDumpElementDeclScan: |
| 1718 | * @elem: An element table |
| 1719 | * @buf: the XML buffer output |
| 1720 | * |
| 1721 | * This routine is used by the hash scan function. It just reverses |
| 1722 | * the arguments. |
| 1723 | */ |
| 1724 | static void |
| 1725 | xmlDumpElementDeclScan(xmlElementPtr elem, xmlBufferPtr buf) { |
| 1726 | xmlDumpElementDecl(buf, elem); |
| 1727 | } |
| 1728 | |
| 1729 | /** |
| 1730 | * xmlDumpElementTable: |
| 1731 | * @buf: the XML buffer output |
| 1732 | * @table: An element table |
| 1733 | * |
| 1734 | * This will dump the content of the element table as an XML DTD definition |
| 1735 | */ |
| 1736 | void |
| 1737 | xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { |
| 1738 | if ((buf == NULL((void*)0)) || (table == NULL((void*)0))) |
| 1739 | return; |
| 1740 | xmlHashScanxmlHashScan__internal_alias(table, (xmlHashScanner) xmlDumpElementDeclScan, buf); |
| 1741 | } |
| 1742 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1743 | |
| 1744 | /** |
| 1745 | * xmlCreateEnumeration: |
| 1746 | * @name: the enumeration name or NULL |
| 1747 | * |
| 1748 | * create and initialize an enumeration attribute node. |
| 1749 | * |
| 1750 | * Returns the xmlEnumerationPtr just created or NULL in case |
| 1751 | * of error. |
| 1752 | */ |
| 1753 | xmlEnumerationPtr |
| 1754 | xmlCreateEnumeration(const xmlChar *name) { |
| 1755 | xmlEnumerationPtr ret; |
| 1756 | |
| 1757 | ret = (xmlEnumerationPtr) xmlMalloc(sizeof(xmlEnumeration)); |
| 1758 | if (ret == NULL((void*)0)) { |
| 1759 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 1760 | return(NULL((void*)0)); |
| 1761 | } |
| 1762 | memset(ret, 0, sizeof(xmlEnumeration)); |
| 1763 | |
| 1764 | if (name != NULL((void*)0)) |
| 1765 | ret->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 1766 | return(ret); |
| 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * xmlFreeEnumeration: |
| 1771 | * @cur: the tree to free. |
| 1772 | * |
| 1773 | * free an enumeration attribute node (recursive). |
| 1774 | */ |
| 1775 | void |
| 1776 | xmlFreeEnumeration(xmlEnumerationPtr cur) { |
| 1777 | if (cur == NULL((void*)0)) return; |
| 1778 | |
| 1779 | if (cur->next != NULL((void*)0)) xmlFreeEnumeration(cur->next); |
| 1780 | |
| 1781 | if (cur->name != NULL((void*)0)) xmlFree((xmlChar *) cur->name); |
| 1782 | xmlFree(cur); |
| 1783 | } |
| 1784 | |
| 1785 | #ifdef LIBXML_TREE_ENABLED |
| 1786 | /** |
| 1787 | * xmlCopyEnumeration: |
| 1788 | * @cur: the tree to copy. |
| 1789 | * |
| 1790 | * Copy an enumeration attribute node (recursive). |
| 1791 | * |
| 1792 | * Returns the xmlEnumerationPtr just created or NULL in case |
| 1793 | * of error. |
| 1794 | */ |
| 1795 | xmlEnumerationPtr |
| 1796 | xmlCopyEnumeration(xmlEnumerationPtr cur) { |
| 1797 | xmlEnumerationPtr ret; |
| 1798 | |
| 1799 | if (cur == NULL((void*)0)) return(NULL((void*)0)); |
| 1800 | ret = xmlCreateEnumeration((xmlChar *) cur->name); |
| 1801 | |
| 1802 | if (cur->next != NULL((void*)0)) ret->next = xmlCopyEnumeration(cur->next); |
| 1803 | else ret->next = NULL((void*)0); |
| 1804 | |
| 1805 | return(ret); |
| 1806 | } |
| 1807 | #endif /* LIBXML_TREE_ENABLED */ |
| 1808 | |
| 1809 | #ifdef LIBXML_OUTPUT_ENABLED |
| 1810 | /** |
| 1811 | * xmlDumpEnumeration: |
| 1812 | * @buf: the XML buffer output |
| 1813 | * @enum: An enumeration |
| 1814 | * |
| 1815 | * This will dump the content of the enumeration |
| 1816 | */ |
| 1817 | static void |
| 1818 | xmlDumpEnumeration(xmlBufferPtr buf, xmlEnumerationPtr cur) { |
| 1819 | if ((buf == NULL((void*)0)) || (cur == NULL((void*)0))) |
| 1820 | return; |
| 1821 | |
| 1822 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, cur->name); |
| 1823 | if (cur->next == NULL((void*)0)) |
| 1824 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ")"); |
| 1825 | else { |
| 1826 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " | "); |
| 1827 | xmlDumpEnumeration(buf, cur->next); |
| 1828 | } |
| 1829 | } |
| 1830 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1831 | |
| 1832 | #ifdef LIBXML_VALID_ENABLED |
| 1833 | /** |
| 1834 | * xmlScanIDAttributeDecl: |
| 1835 | * @ctxt: the validation context |
| 1836 | * @elem: the element name |
| 1837 | * @err: whether to raise errors here |
| 1838 | * |
| 1839 | * Verify that the element don't have too many ID attributes |
| 1840 | * declared. |
| 1841 | * |
| 1842 | * Returns the number of ID attributes found. |
| 1843 | */ |
| 1844 | static int |
| 1845 | xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem, int err) { |
| 1846 | xmlAttributePtr cur; |
| 1847 | int ret = 0; |
| 1848 | |
| 1849 | if (elem == NULL((void*)0)) return(0); |
| 1850 | cur = elem->attributes; |
| 1851 | while (cur != NULL((void*)0)) { |
| 1852 | if (cur->atype == XML_ATTRIBUTE_ID) { |
| 1853 | ret ++; |
| 1854 | if ((ret > 1) && (err)) |
| 1855 | xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID, |
| 1856 | "Element %s has too many ID attributes defined : %s\n", |
| 1857 | elem->name, cur->name, NULL((void*)0)); |
| 1858 | } |
| 1859 | cur = cur->nexth; |
| 1860 | } |
| 1861 | return(ret); |
| 1862 | } |
| 1863 | #endif /* LIBXML_VALID_ENABLED */ |
| 1864 | |
| 1865 | /** |
| 1866 | * xmlFreeAttribute: |
| 1867 | * @elem: An attribute |
| 1868 | * |
| 1869 | * Deallocate the memory used by an attribute definition |
| 1870 | */ |
| 1871 | static void |
| 1872 | xmlFreeAttribute(xmlAttributePtr attr) { |
| 1873 | xmlDictPtr dict; |
| 1874 | |
| 1875 | if (attr == NULL((void*)0)) return; |
| 1876 | if (attr->doc != NULL((void*)0)) |
| 1877 | dict = attr->doc->dict; |
| 1878 | else |
| 1879 | dict = NULL((void*)0); |
| 1880 | xmlUnlinkNodexmlUnlinkNode__internal_alias((xmlNodePtr) attr); |
| 1881 | if (attr->tree != NULL((void*)0)) |
| 1882 | xmlFreeEnumeration(attr->tree); |
| 1883 | if (dict) { |
| 1884 | if ((attr->elem != NULL((void*)0)) && (!xmlDictOwnsxmlDictOwns__internal_alias(dict, attr->elem))) |
| 1885 | xmlFree((xmlChar *) attr->elem); |
| 1886 | if ((attr->name != NULL((void*)0)) && (!xmlDictOwnsxmlDictOwns__internal_alias(dict, attr->name))) |
| 1887 | xmlFree((xmlChar *) attr->name); |
| 1888 | if ((attr->prefix != NULL((void*)0)) && (!xmlDictOwnsxmlDictOwns__internal_alias(dict, attr->prefix))) |
| 1889 | xmlFree((xmlChar *) attr->prefix); |
| 1890 | if ((attr->defaultValue != NULL((void*)0)) && |
| 1891 | (!xmlDictOwnsxmlDictOwns__internal_alias(dict, attr->defaultValue))) |
| 1892 | xmlFree((xmlChar *) attr->defaultValue); |
| 1893 | } else { |
| 1894 | if (attr->elem != NULL((void*)0)) |
| 1895 | xmlFree((xmlChar *) attr->elem); |
| 1896 | if (attr->name != NULL((void*)0)) |
| 1897 | xmlFree((xmlChar *) attr->name); |
| 1898 | if (attr->defaultValue != NULL((void*)0)) |
| 1899 | xmlFree((xmlChar *) attr->defaultValue); |
| 1900 | if (attr->prefix != NULL((void*)0)) |
| 1901 | xmlFree((xmlChar *) attr->prefix); |
| 1902 | } |
| 1903 | xmlFree(attr); |
| 1904 | } |
| 1905 | |
| 1906 | |
| 1907 | /** |
| 1908 | * xmlAddAttributeDecl: |
| 1909 | * @ctxt: the validation context |
| 1910 | * @dtd: pointer to the DTD |
| 1911 | * @elem: the element name |
| 1912 | * @name: the attribute name |
| 1913 | * @ns: the attribute namespace prefix |
| 1914 | * @type: the attribute type |
| 1915 | * @def: the attribute default type |
| 1916 | * @defaultValue: the attribute default value |
| 1917 | * @tree: if it's an enumeration, the associated list |
| 1918 | * |
| 1919 | * Register a new attribute declaration |
| 1920 | * Note that @tree becomes the ownership of the DTD |
| 1921 | * |
| 1922 | * Returns NULL if not new, otherwise the attribute decl |
| 1923 | */ |
| 1924 | xmlAttributePtr |
| 1925 | xmlAddAttributeDecl(xmlValidCtxtPtr ctxt, |
| 1926 | xmlDtdPtr dtd, const xmlChar *elem, |
| 1927 | const xmlChar *name, const xmlChar *ns, |
| 1928 | xmlAttributeType type, xmlAttributeDefault def, |
| 1929 | const xmlChar *defaultValue, xmlEnumerationPtr tree) { |
| 1930 | xmlAttributePtr ret; |
| 1931 | xmlAttributeTablePtr table; |
| 1932 | xmlElementPtr elemDef; |
| 1933 | xmlDictPtr dict = NULL((void*)0); |
| 1934 | |
| 1935 | if (dtd == NULL((void*)0)) { |
| 1936 | xmlFreeEnumeration(tree); |
| 1937 | return(NULL((void*)0)); |
| 1938 | } |
| 1939 | if (name == NULL((void*)0)) { |
| 1940 | xmlFreeEnumeration(tree); |
| 1941 | return(NULL((void*)0)); |
| 1942 | } |
| 1943 | if (elem == NULL((void*)0)) { |
| 1944 | xmlFreeEnumeration(tree); |
| 1945 | return(NULL((void*)0)); |
| 1946 | } |
| 1947 | if (dtd->doc != NULL((void*)0)) |
| 1948 | dict = dtd->doc->dict; |
| 1949 | |
| 1950 | #ifdef LIBXML_VALID_ENABLED |
| 1951 | /* |
| 1952 | * Check the type and possibly the default value. |
| 1953 | */ |
| 1954 | switch (type) { |
| 1955 | case XML_ATTRIBUTE_CDATA: |
| 1956 | break; |
| 1957 | case XML_ATTRIBUTE_ID: |
| 1958 | break; |
| 1959 | case XML_ATTRIBUTE_IDREF: |
| 1960 | break; |
| 1961 | case XML_ATTRIBUTE_IDREFS: |
| 1962 | break; |
| 1963 | case XML_ATTRIBUTE_ENTITY: |
| 1964 | break; |
| 1965 | case XML_ATTRIBUTE_ENTITIES: |
| 1966 | break; |
| 1967 | case XML_ATTRIBUTE_NMTOKEN: |
| 1968 | break; |
| 1969 | case XML_ATTRIBUTE_NMTOKENS: |
| 1970 | break; |
| 1971 | case XML_ATTRIBUTE_ENUMERATION: |
| 1972 | break; |
| 1973 | case XML_ATTRIBUTE_NOTATION: |
| 1974 | break; |
| 1975 | default: |
| 1976 | xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, |
| 1977 | "Internal: ATTRIBUTE struct corrupted invalid type\n", |
| 1978 | NULL((void*)0)); |
| 1979 | xmlFreeEnumeration(tree); |
| 1980 | return(NULL((void*)0)); |
| 1981 | } |
| 1982 | if ((defaultValue != NULL((void*)0)) && |
| 1983 | (!xmlValidateAttributeValueInternal(dtd->doc, type, defaultValue))) { |
| 1984 | xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT, |
| 1985 | "Attribute %s of %s: invalid default value\n", |
| 1986 | elem, name, defaultValue); |
| 1987 | defaultValue = NULL((void*)0); |
| 1988 | if (ctxt != NULL((void*)0)) |
| 1989 | ctxt->valid = 0; |
| 1990 | } |
| 1991 | #endif /* LIBXML_VALID_ENABLED */ |
| 1992 | |
| 1993 | /* |
| 1994 | * Check first that an attribute defined in the external subset wasn't |
| 1995 | * already defined in the internal subset |
| 1996 | */ |
| 1997 | if ((dtd->doc != NULL((void*)0)) && (dtd->doc->extSubset == dtd) && |
| 1998 | (dtd->doc->intSubset != NULL((void*)0)) && |
| 1999 | (dtd->doc->intSubset->attributes != NULL((void*)0))) { |
| 2000 | ret = xmlHashLookup3xmlHashLookup3__internal_alias(dtd->doc->intSubset->attributes, name, ns, elem); |
| 2001 | if (ret != NULL((void*)0)) { |
| 2002 | xmlFreeEnumeration(tree); |
| 2003 | return(NULL((void*)0)); |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * Create the Attribute table if needed. |
| 2009 | */ |
| 2010 | table = (xmlAttributeTablePtr) dtd->attributes; |
| 2011 | if (table == NULL((void*)0)) { |
| 2012 | table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, dict); |
| 2013 | dtd->attributes = (void *) table; |
| 2014 | } |
| 2015 | if (table == NULL((void*)0)) { |
| 2016 | xmlVErrMemory(ctxt, |
| 2017 | "xmlAddAttributeDecl: Table creation failed!\n"); |
| 2018 | xmlFreeEnumeration(tree); |
| 2019 | return(NULL((void*)0)); |
| 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute)); |
| 2024 | if (ret == NULL((void*)0)) { |
| 2025 | xmlVErrMemory(ctxt, "malloc failed"); |
| 2026 | xmlFreeEnumeration(tree); |
| 2027 | return(NULL((void*)0)); |
| 2028 | } |
| 2029 | memset(ret, 0, sizeof(xmlAttribute)); |
| 2030 | ret->type = XML_ATTRIBUTE_DECL; |
| 2031 | |
| 2032 | /* |
| 2033 | * fill the structure. |
| 2034 | */ |
| 2035 | ret->atype = type; |
| 2036 | /* |
| 2037 | * doc must be set before possible error causes call |
| 2038 | * to xmlFreeAttribute (because it's used to check on |
| 2039 | * dict use) |
| 2040 | */ |
| 2041 | ret->doc = dtd->doc; |
| 2042 | if (dict) { |
| 2043 | ret->name = xmlDictLookupxmlDictLookup__internal_alias(dict, name, -1); |
| 2044 | ret->prefix = xmlDictLookupxmlDictLookup__internal_alias(dict, ns, -1); |
| 2045 | ret->elem = xmlDictLookupxmlDictLookup__internal_alias(dict, elem, -1); |
| 2046 | } else { |
| 2047 | ret->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 2048 | ret->prefix = xmlStrdupxmlStrdup__internal_alias(ns); |
| 2049 | ret->elem = xmlStrdupxmlStrdup__internal_alias(elem); |
| 2050 | } |
| 2051 | ret->def = def; |
| 2052 | ret->tree = tree; |
| 2053 | if (defaultValue != NULL((void*)0)) { |
| 2054 | if (dict) |
| 2055 | ret->defaultValue = xmlDictLookupxmlDictLookup__internal_alias(dict, defaultValue, -1); |
| 2056 | else |
| 2057 | ret->defaultValue = xmlStrdupxmlStrdup__internal_alias(defaultValue); |
| 2058 | } |
| 2059 | |
| 2060 | /* |
| 2061 | * Validity Check: |
| 2062 | * Search the DTD for previous declarations of the ATTLIST |
| 2063 | */ |
| 2064 | if (xmlHashAddEntry3xmlHashAddEntry3__internal_alias(table, ret->name, ret->prefix, ret->elem, ret) < 0) { |
| 2065 | #ifdef LIBXML_VALID_ENABLED |
| 2066 | /* |
| 2067 | * The attribute is already defined in this DTD. |
| 2068 | */ |
| 2069 | xmlErrValidWarning(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_REDEFINED, |
| 2070 | "Attribute %s of element %s: already defined\n", |
| 2071 | name, elem, NULL((void*)0)); |
| 2072 | #endif /* LIBXML_VALID_ENABLED */ |
| 2073 | xmlFreeAttribute(ret); |
| 2074 | return(NULL((void*)0)); |
| 2075 | } |
| 2076 | |
| 2077 | /* |
| 2078 | * Validity Check: |
| 2079 | * Multiple ID per element |
| 2080 | */ |
| 2081 | elemDef = xmlGetDtdElementDesc2(dtd, elem, 1); |
| 2082 | if (elemDef != NULL((void*)0)) { |
| 2083 | |
| 2084 | #ifdef LIBXML_VALID_ENABLED |
| 2085 | if ((type == XML_ATTRIBUTE_ID) && |
| 2086 | (xmlScanIDAttributeDecl(NULL((void*)0), elemDef, 1) != 0)) { |
| 2087 | xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_MULTIPLE_ID, |
| 2088 | "Element %s has too may ID attributes defined : %s\n", |
| 2089 | elem, name, NULL((void*)0)); |
| 2090 | if (ctxt != NULL((void*)0)) |
| 2091 | ctxt->valid = 0; |
| 2092 | } |
| 2093 | #endif /* LIBXML_VALID_ENABLED */ |
| 2094 | |
| 2095 | /* |
| 2096 | * Insert namespace default def first they need to be |
| 2097 | * processed first. |
| 2098 | */ |
| 2099 | if ((xmlStrEqualxmlStrEqual__internal_alias(ret->name, BAD_CAST(xmlChar *) "xmlns")) || |
| 2100 | ((ret->prefix != NULL((void*)0) && |
| 2101 | (xmlStrEqualxmlStrEqual__internal_alias(ret->prefix, BAD_CAST(xmlChar *) "xmlns"))))) { |
| 2102 | ret->nexth = elemDef->attributes; |
| 2103 | elemDef->attributes = ret; |
| 2104 | } else { |
| 2105 | xmlAttributePtr tmp = elemDef->attributes; |
| 2106 | |
| 2107 | while ((tmp != NULL((void*)0)) && |
| 2108 | ((xmlStrEqualxmlStrEqual__internal_alias(tmp->name, BAD_CAST(xmlChar *) "xmlns")) || |
| 2109 | ((ret->prefix != NULL((void*)0) && |
| 2110 | (xmlStrEqualxmlStrEqual__internal_alias(ret->prefix, BAD_CAST(xmlChar *) "xmlns")))))) { |
| 2111 | if (tmp->nexth == NULL((void*)0)) |
| 2112 | break; |
| 2113 | tmp = tmp->nexth; |
| 2114 | } |
| 2115 | if (tmp != NULL((void*)0)) { |
| 2116 | ret->nexth = tmp->nexth; |
| 2117 | tmp->nexth = ret; |
| 2118 | } else { |
| 2119 | ret->nexth = elemDef->attributes; |
| 2120 | elemDef->attributes = ret; |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | /* |
| 2126 | * Link it to the DTD |
| 2127 | */ |
| 2128 | ret->parent = dtd; |
| 2129 | if (dtd->last == NULL((void*)0)) { |
| 2130 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 2131 | } else { |
| 2132 | dtd->last->next = (xmlNodePtr) ret; |
| 2133 | ret->prev = dtd->last; |
| 2134 | dtd->last = (xmlNodePtr) ret; |
| 2135 | } |
| 2136 | return(ret); |
| 2137 | } |
| 2138 | |
| 2139 | /** |
| 2140 | * xmlFreeAttributeTable: |
| 2141 | * @table: An attribute table |
| 2142 | * |
| 2143 | * Deallocate the memory used by an entities hash table. |
| 2144 | */ |
| 2145 | void |
| 2146 | xmlFreeAttributeTable(xmlAttributeTablePtr table) { |
| 2147 | xmlHashFreexmlHashFree__internal_alias(table, (xmlHashDeallocator) xmlFreeAttribute); |
| 2148 | } |
| 2149 | |
| 2150 | #ifdef LIBXML_TREE_ENABLED |
| 2151 | /** |
| 2152 | * xmlCopyAttribute: |
| 2153 | * @attr: An attribute |
| 2154 | * |
| 2155 | * Build a copy of an attribute. |
| 2156 | * |
| 2157 | * Returns the new xmlAttributePtr or NULL in case of error. |
| 2158 | */ |
| 2159 | static xmlAttributePtr |
| 2160 | xmlCopyAttribute(xmlAttributePtr attr) { |
| 2161 | xmlAttributePtr cur; |
| 2162 | |
| 2163 | cur = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute)); |
| 2164 | if (cur == NULL((void*)0)) { |
| 2165 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 2166 | return(NULL((void*)0)); |
| 2167 | } |
| 2168 | memset(cur, 0, sizeof(xmlAttribute)); |
| 2169 | cur->type = XML_ATTRIBUTE_DECL; |
| 2170 | cur->atype = attr->atype; |
| 2171 | cur->def = attr->def; |
| 2172 | cur->tree = xmlCopyEnumeration(attr->tree); |
| 2173 | if (attr->elem != NULL((void*)0)) |
| 2174 | cur->elem = xmlStrdupxmlStrdup__internal_alias(attr->elem); |
| 2175 | if (attr->name != NULL((void*)0)) |
| 2176 | cur->name = xmlStrdupxmlStrdup__internal_alias(attr->name); |
| 2177 | if (attr->prefix != NULL((void*)0)) |
| 2178 | cur->prefix = xmlStrdupxmlStrdup__internal_alias(attr->prefix); |
| 2179 | if (attr->defaultValue != NULL((void*)0)) |
| 2180 | cur->defaultValue = xmlStrdupxmlStrdup__internal_alias(attr->defaultValue); |
| 2181 | return(cur); |
| 2182 | } |
| 2183 | |
| 2184 | /** |
| 2185 | * xmlCopyAttributeTable: |
| 2186 | * @table: An attribute table |
| 2187 | * |
| 2188 | * Build a copy of an attribute table. |
| 2189 | * |
| 2190 | * Returns the new xmlAttributeTablePtr or NULL in case of error. |
| 2191 | */ |
| 2192 | xmlAttributeTablePtr |
| 2193 | xmlCopyAttributeTable(xmlAttributeTablePtr table) { |
| 2194 | return((xmlAttributeTablePtr) xmlHashCopyxmlHashCopy__internal_alias(table, |
| 2195 | (xmlHashCopier) xmlCopyAttribute)); |
| 2196 | } |
| 2197 | #endif /* LIBXML_TREE_ENABLED */ |
| 2198 | |
| 2199 | #ifdef LIBXML_OUTPUT_ENABLED |
| 2200 | /** |
| 2201 | * xmlDumpAttributeDecl: |
| 2202 | * @buf: the XML buffer output |
| 2203 | * @attr: An attribute declaration |
| 2204 | * |
| 2205 | * This will dump the content of the attribute declaration as an XML |
| 2206 | * DTD definition |
| 2207 | */ |
| 2208 | void |
| 2209 | xmlDumpAttributeDecl(xmlBufferPtr buf, xmlAttributePtr attr) { |
| 2210 | if ((buf == NULL((void*)0)) || (attr == NULL((void*)0))) |
| 2211 | return; |
| 2212 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!ATTLIST "); |
| 2213 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, attr->elem); |
| 2214 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " "); |
| 2215 | if (attr->prefix != NULL((void*)0)) { |
| 2216 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, attr->prefix); |
| 2217 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ":"); |
| 2218 | } |
| 2219 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, attr->name); |
| 2220 | switch (attr->atype) { |
| 2221 | case XML_ATTRIBUTE_CDATA: |
| 2222 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " CDATA"); |
| 2223 | break; |
| 2224 | case XML_ATTRIBUTE_ID: |
| 2225 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " ID"); |
| 2226 | break; |
| 2227 | case XML_ATTRIBUTE_IDREF: |
| 2228 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " IDREF"); |
| 2229 | break; |
| 2230 | case XML_ATTRIBUTE_IDREFS: |
| 2231 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " IDREFS"); |
| 2232 | break; |
| 2233 | case XML_ATTRIBUTE_ENTITY: |
| 2234 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " ENTITY"); |
| 2235 | break; |
| 2236 | case XML_ATTRIBUTE_ENTITIES: |
| 2237 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " ENTITIES"); |
| 2238 | break; |
| 2239 | case XML_ATTRIBUTE_NMTOKEN: |
| 2240 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " NMTOKEN"); |
| 2241 | break; |
| 2242 | case XML_ATTRIBUTE_NMTOKENS: |
| 2243 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " NMTOKENS"); |
| 2244 | break; |
| 2245 | case XML_ATTRIBUTE_ENUMERATION: |
| 2246 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " ("); |
| 2247 | xmlDumpEnumeration(buf, attr->tree); |
| 2248 | break; |
| 2249 | case XML_ATTRIBUTE_NOTATION: |
| 2250 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " NOTATION ("); |
| 2251 | xmlDumpEnumeration(buf, attr->tree); |
| 2252 | break; |
| 2253 | default: |
| 2254 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 2255 | "Internal: ATTRIBUTE struct corrupted invalid type\n", |
| 2256 | NULL((void*)0)); |
| 2257 | } |
| 2258 | switch (attr->def) { |
| 2259 | case XML_ATTRIBUTE_NONE: |
| 2260 | break; |
| 2261 | case XML_ATTRIBUTE_REQUIRED: |
| 2262 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " #REQUIRED"); |
| 2263 | break; |
| 2264 | case XML_ATTRIBUTE_IMPLIED: |
| 2265 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " #IMPLIED"); |
| 2266 | break; |
| 2267 | case XML_ATTRIBUTE_FIXED: |
| 2268 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " #FIXED"); |
| 2269 | break; |
| 2270 | default: |
| 2271 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 2272 | "Internal: ATTRIBUTE struct corrupted invalid def\n", |
| 2273 | NULL((void*)0)); |
| 2274 | } |
| 2275 | if (attr->defaultValue != NULL((void*)0)) { |
| 2276 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " "); |
| 2277 | xmlBufferWriteQuotedStringxmlBufferWriteQuotedString__internal_alias(buf, attr->defaultValue); |
| 2278 | } |
| 2279 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, ">\n"); |
| 2280 | } |
| 2281 | |
| 2282 | /** |
| 2283 | * xmlDumpAttributeDeclScan: |
| 2284 | * @attr: An attribute declaration |
| 2285 | * @buf: the XML buffer output |
| 2286 | * |
| 2287 | * This is used with the hash scan function - just reverses arguments |
| 2288 | */ |
| 2289 | static void |
| 2290 | xmlDumpAttributeDeclScan(xmlAttributePtr attr, xmlBufferPtr buf) { |
| 2291 | xmlDumpAttributeDecl(buf, attr); |
| 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * xmlDumpAttributeTable: |
| 2296 | * @buf: the XML buffer output |
| 2297 | * @table: An attribute table |
| 2298 | * |
| 2299 | * This will dump the content of the attribute table as an XML DTD definition |
| 2300 | */ |
| 2301 | void |
| 2302 | xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { |
| 2303 | if ((buf == NULL((void*)0)) || (table == NULL((void*)0))) |
| 2304 | return; |
| 2305 | xmlHashScanxmlHashScan__internal_alias(table, (xmlHashScanner) xmlDumpAttributeDeclScan, buf); |
| 2306 | } |
| 2307 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2308 | |
| 2309 | /************************************************************************ |
| 2310 | * * |
| 2311 | * NOTATIONs * |
| 2312 | * * |
| 2313 | ************************************************************************/ |
| 2314 | /** |
| 2315 | * xmlFreeNotation: |
| 2316 | * @not: A notation |
| 2317 | * |
| 2318 | * Deallocate the memory used by an notation definition |
| 2319 | */ |
| 2320 | static void |
| 2321 | xmlFreeNotation(xmlNotationPtr nota) { |
| 2322 | if (nota == NULL((void*)0)) return; |
| 2323 | if (nota->name != NULL((void*)0)) |
| 2324 | xmlFree((xmlChar *) nota->name); |
| 2325 | if (nota->PublicID != NULL((void*)0)) |
| 2326 | xmlFree((xmlChar *) nota->PublicID); |
| 2327 | if (nota->SystemID != NULL((void*)0)) |
| 2328 | xmlFree((xmlChar *) nota->SystemID); |
| 2329 | xmlFree(nota); |
| 2330 | } |
| 2331 | |
| 2332 | |
| 2333 | /** |
| 2334 | * xmlAddNotationDecl: |
| 2335 | * @dtd: pointer to the DTD |
| 2336 | * @ctxt: the validation context |
| 2337 | * @name: the entity name |
| 2338 | * @PublicID: the public identifier or NULL |
| 2339 | * @SystemID: the system identifier or NULL |
| 2340 | * |
| 2341 | * Register a new notation declaration |
| 2342 | * |
| 2343 | * Returns NULL if not, otherwise the entity |
| 2344 | */ |
| 2345 | xmlNotationPtr |
| 2346 | xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, |
| 2347 | const xmlChar *name, |
| 2348 | const xmlChar *PublicID, const xmlChar *SystemID) { |
| 2349 | xmlNotationPtr ret; |
| 2350 | xmlNotationTablePtr table; |
| 2351 | |
| 2352 | if (dtd == NULL((void*)0)) { |
| 2353 | return(NULL((void*)0)); |
| 2354 | } |
| 2355 | if (name == NULL((void*)0)) { |
| 2356 | return(NULL((void*)0)); |
| 2357 | } |
| 2358 | if ((PublicID == NULL((void*)0)) && (SystemID == NULL((void*)0))) { |
| 2359 | return(NULL((void*)0)); |
| 2360 | } |
| 2361 | |
| 2362 | /* |
| 2363 | * Create the Notation table if needed. |
| 2364 | */ |
| 2365 | table = (xmlNotationTablePtr) dtd->notations; |
| 2366 | if (table == NULL((void*)0)) { |
| 2367 | xmlDictPtr dict = NULL((void*)0); |
| 2368 | if (dtd->doc != NULL((void*)0)) |
| 2369 | dict = dtd->doc->dict; |
| 2370 | |
| 2371 | dtd->notations = table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, dict); |
| 2372 | } |
| 2373 | if (table == NULL((void*)0)) { |
| 2374 | xmlVErrMemory(ctxt, |
| 2375 | "xmlAddNotationDecl: Table creation failed!\n"); |
| 2376 | return(NULL((void*)0)); |
| 2377 | } |
| 2378 | |
| 2379 | ret = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation)); |
| 2380 | if (ret == NULL((void*)0)) { |
| 2381 | xmlVErrMemory(ctxt, "malloc failed"); |
| 2382 | return(NULL((void*)0)); |
| 2383 | } |
| 2384 | memset(ret, 0, sizeof(xmlNotation)); |
| 2385 | |
| 2386 | /* |
| 2387 | * fill the structure. |
| 2388 | */ |
| 2389 | ret->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 2390 | if (SystemID != NULL((void*)0)) |
| 2391 | ret->SystemID = xmlStrdupxmlStrdup__internal_alias(SystemID); |
| 2392 | if (PublicID != NULL((void*)0)) |
| 2393 | ret->PublicID = xmlStrdupxmlStrdup__internal_alias(PublicID); |
| 2394 | |
| 2395 | /* |
| 2396 | * Validity Check: |
| 2397 | * Check the DTD for previous declarations of the ATTLIST |
| 2398 | */ |
| 2399 | if (xmlHashAddEntryxmlHashAddEntry__internal_alias(table, name, ret)) { |
| 2400 | #ifdef LIBXML_VALID_ENABLED |
| 2401 | xmlErrValid(NULL((void*)0), XML_DTD_NOTATION_REDEFINED, |
| 2402 | "xmlAddNotationDecl: %s already defined\n", |
| 2403 | (const char *) name); |
| 2404 | #endif /* LIBXML_VALID_ENABLED */ |
| 2405 | xmlFreeNotation(ret); |
| 2406 | return(NULL((void*)0)); |
| 2407 | } |
| 2408 | return(ret); |
| 2409 | } |
| 2410 | |
| 2411 | /** |
| 2412 | * xmlFreeNotationTable: |
| 2413 | * @table: An notation table |
| 2414 | * |
| 2415 | * Deallocate the memory used by an entities hash table. |
| 2416 | */ |
| 2417 | void |
| 2418 | xmlFreeNotationTable(xmlNotationTablePtr table) { |
| 2419 | xmlHashFreexmlHashFree__internal_alias(table, (xmlHashDeallocator) xmlFreeNotation); |
| 2420 | } |
| 2421 | |
| 2422 | #ifdef LIBXML_TREE_ENABLED |
| 2423 | /** |
| 2424 | * xmlCopyNotation: |
| 2425 | * @nota: A notation |
| 2426 | * |
| 2427 | * Build a copy of a notation. |
| 2428 | * |
| 2429 | * Returns the new xmlNotationPtr or NULL in case of error. |
| 2430 | */ |
| 2431 | static xmlNotationPtr |
| 2432 | xmlCopyNotation(xmlNotationPtr nota) { |
| 2433 | xmlNotationPtr cur; |
| 2434 | |
| 2435 | cur = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation)); |
| 2436 | if (cur == NULL((void*)0)) { |
| 2437 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 2438 | return(NULL((void*)0)); |
| 2439 | } |
| 2440 | if (nota->name != NULL((void*)0)) |
| 2441 | cur->name = xmlStrdupxmlStrdup__internal_alias(nota->name); |
| 2442 | else |
| 2443 | cur->name = NULL((void*)0); |
| 2444 | if (nota->PublicID != NULL((void*)0)) |
| 2445 | cur->PublicID = xmlStrdupxmlStrdup__internal_alias(nota->PublicID); |
| 2446 | else |
| 2447 | cur->PublicID = NULL((void*)0); |
| 2448 | if (nota->SystemID != NULL((void*)0)) |
| 2449 | cur->SystemID = xmlStrdupxmlStrdup__internal_alias(nota->SystemID); |
| 2450 | else |
| 2451 | cur->SystemID = NULL((void*)0); |
| 2452 | return(cur); |
| 2453 | } |
| 2454 | |
| 2455 | /** |
| 2456 | * xmlCopyNotationTable: |
| 2457 | * @table: A notation table |
| 2458 | * |
| 2459 | * Build a copy of a notation table. |
| 2460 | * |
| 2461 | * Returns the new xmlNotationTablePtr or NULL in case of error. |
| 2462 | */ |
| 2463 | xmlNotationTablePtr |
| 2464 | xmlCopyNotationTable(xmlNotationTablePtr table) { |
| 2465 | return((xmlNotationTablePtr) xmlHashCopyxmlHashCopy__internal_alias(table, |
| 2466 | (xmlHashCopier) xmlCopyNotation)); |
| 2467 | } |
| 2468 | #endif /* LIBXML_TREE_ENABLED */ |
| 2469 | |
| 2470 | #ifdef LIBXML_OUTPUT_ENABLED |
| 2471 | /** |
| 2472 | * xmlDumpNotationDecl: |
| 2473 | * @buf: the XML buffer output |
| 2474 | * @nota: A notation declaration |
| 2475 | * |
| 2476 | * This will dump the content the notation declaration as an XML DTD definition |
| 2477 | */ |
| 2478 | void |
| 2479 | xmlDumpNotationDecl(xmlBufferPtr buf, xmlNotationPtr nota) { |
| 2480 | if ((buf == NULL((void*)0)) || (nota == NULL((void*)0))) |
| 2481 | return; |
| 2482 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, "<!NOTATION "); |
| 2483 | xmlBufferWriteCHARxmlBufferWriteCHAR__internal_alias(buf, nota->name); |
| 2484 | if (nota->PublicID != NULL((void*)0)) { |
| 2485 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " PUBLIC "); |
| 2486 | xmlBufferWriteQuotedStringxmlBufferWriteQuotedString__internal_alias(buf, nota->PublicID); |
| 2487 | if (nota->SystemID != NULL((void*)0)) { |
| 2488 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " "); |
| 2489 | xmlBufferWriteQuotedStringxmlBufferWriteQuotedString__internal_alias(buf, nota->SystemID); |
| 2490 | } |
| 2491 | } else { |
| 2492 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " SYSTEM "); |
| 2493 | xmlBufferWriteQuotedStringxmlBufferWriteQuotedString__internal_alias(buf, nota->SystemID); |
| 2494 | } |
| 2495 | xmlBufferWriteCharxmlBufferWriteChar__internal_alias(buf, " >\n"); |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * xmlDumpNotationDeclScan: |
| 2500 | * @nota: A notation declaration |
| 2501 | * @buf: the XML buffer output |
| 2502 | * |
| 2503 | * This is called with the hash scan function, and just reverses args |
| 2504 | */ |
| 2505 | static void |
| 2506 | xmlDumpNotationDeclScan(xmlNotationPtr nota, xmlBufferPtr buf) { |
| 2507 | xmlDumpNotationDecl(buf, nota); |
| 2508 | } |
| 2509 | |
| 2510 | /** |
| 2511 | * xmlDumpNotationTable: |
| 2512 | * @buf: the XML buffer output |
| 2513 | * @table: A notation table |
| 2514 | * |
| 2515 | * This will dump the content of the notation table as an XML DTD definition |
| 2516 | */ |
| 2517 | void |
| 2518 | xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { |
| 2519 | if ((buf == NULL((void*)0)) || (table == NULL((void*)0))) |
| 2520 | return; |
| 2521 | xmlHashScanxmlHashScan__internal_alias(table, (xmlHashScanner) xmlDumpNotationDeclScan, buf); |
| 2522 | } |
| 2523 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2524 | |
| 2525 | /************************************************************************ |
| 2526 | * * |
| 2527 | * IDs * |
| 2528 | * * |
| 2529 | ************************************************************************/ |
| 2530 | /** |
| 2531 | * DICT_FREE: |
| 2532 | * @str: a string |
| 2533 | * |
| 2534 | * Free a string if it is not owned by the "dict" dictionnary in the |
| 2535 | * current scope |
| 2536 | */ |
| 2537 | #define DICT_FREE(str)if ((str) && ((!dict) || (xmlDictOwns__internal_alias (dict, (const xmlChar *)(str)) == 0))) xmlFree((char *)(str)) ; \ |
| 2538 | if ((str) && ((!dict) || \ |
| 2539 | (xmlDictOwnsxmlDictOwns__internal_alias(dict, (const xmlChar *)(str)) == 0))) \ |
| 2540 | xmlFree((char *)(str)); |
| 2541 | |
| 2542 | /** |
| 2543 | * xmlFreeID: |
| 2544 | * @not: A id |
| 2545 | * |
| 2546 | * Deallocate the memory used by an id definition |
| 2547 | */ |
| 2548 | static void |
| 2549 | xmlFreeID(xmlIDPtr id) { |
| 2550 | xmlDictPtr dict = NULL((void*)0); |
| 2551 | |
| 2552 | if (id == NULL((void*)0)) return; |
| 2553 | |
| 2554 | if (id->doc != NULL((void*)0)) |
| 2555 | dict = id->doc->dict; |
| 2556 | |
| 2557 | if (id->value != NULL((void*)0)) |
| 2558 | DICT_FREE(id->value)if ((id->value) && ((!dict) || (xmlDictOwns__internal_alias (dict, (const xmlChar *)(id->value)) == 0))) xmlFree((char *)(id->value)); |
| 2559 | if (id->name != NULL((void*)0)) |
| 2560 | DICT_FREE(id->name)if ((id->name) && ((!dict) || (xmlDictOwns__internal_alias (dict, (const xmlChar *)(id->name)) == 0))) xmlFree((char * )(id->name)); |
| 2561 | xmlFree(id); |
| 2562 | } |
| 2563 | |
| 2564 | |
| 2565 | /** |
| 2566 | * xmlAddID: |
| 2567 | * @ctxt: the validation context |
| 2568 | * @doc: pointer to the document |
| 2569 | * @value: the value name |
| 2570 | * @attr: the attribute holding the ID |
| 2571 | * |
| 2572 | * Register a new id declaration |
| 2573 | * |
| 2574 | * Returns NULL if not, otherwise the new xmlIDPtr |
| 2575 | */ |
| 2576 | xmlIDPtr |
| 2577 | xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, |
| 2578 | xmlAttrPtr attr) { |
| 2579 | xmlIDPtr ret; |
| 2580 | xmlIDTablePtr table; |
| 2581 | |
| 2582 | if (doc == NULL((void*)0)) { |
| 2583 | return(NULL((void*)0)); |
| 2584 | } |
| 2585 | if (value == NULL((void*)0)) { |
| 2586 | return(NULL((void*)0)); |
| 2587 | } |
| 2588 | if (attr == NULL((void*)0)) { |
| 2589 | return(NULL((void*)0)); |
| 2590 | } |
| 2591 | |
| 2592 | /* |
| 2593 | * Create the ID table if needed. |
| 2594 | */ |
| 2595 | table = (xmlIDTablePtr) doc->ids; |
| 2596 | if (table == NULL((void*)0)) { |
| 2597 | doc->ids = table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, doc->dict); |
| 2598 | } |
| 2599 | if (table == NULL((void*)0)) { |
| 2600 | xmlVErrMemory(ctxt, |
| 2601 | "xmlAddID: Table creation failed!\n"); |
| 2602 | return(NULL((void*)0)); |
| 2603 | } |
| 2604 | |
| 2605 | ret = (xmlIDPtr) xmlMalloc(sizeof(xmlID)); |
| 2606 | if (ret == NULL((void*)0)) { |
| 2607 | xmlVErrMemory(ctxt, "malloc failed"); |
| 2608 | return(NULL((void*)0)); |
| 2609 | } |
| 2610 | |
| 2611 | /* |
| 2612 | * fill the structure. |
| 2613 | */ |
| 2614 | ret->value = xmlStrdupxmlStrdup__internal_alias(value); |
| 2615 | ret->doc = doc; |
| 2616 | if ((ctxt != NULL((void*)0)) && (ctxt->vstateNr != 0)) { |
| 2617 | /* |
| 2618 | * Operating in streaming mode, attr is gonna disapear |
| 2619 | */ |
| 2620 | if (doc->dict != NULL((void*)0)) |
| 2621 | ret->name = xmlDictLookupxmlDictLookup__internal_alias(doc->dict, attr->name, -1); |
| 2622 | else |
| 2623 | ret->name = xmlStrdupxmlStrdup__internal_alias(attr->name); |
| 2624 | ret->attr = NULL((void*)0); |
| 2625 | } else { |
| 2626 | ret->attr = attr; |
| 2627 | ret->name = NULL((void*)0); |
| 2628 | } |
| 2629 | ret->lineno = xmlGetLineNoxmlGetLineNo__internal_alias(attr->parent); |
| 2630 | |
| 2631 | if (xmlHashAddEntryxmlHashAddEntry__internal_alias(table, value, ret) < 0) { |
| 2632 | #ifdef LIBXML_VALID_ENABLED |
| 2633 | /* |
| 2634 | * The id is already defined in this DTD. |
| 2635 | */ |
| 2636 | if ((ctxt != NULL((void*)0)) && (ctxt->error != NULL((void*)0))) { |
| 2637 | xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED, |
| 2638 | "ID %s already defined\n", |
| 2639 | value, NULL((void*)0), NULL((void*)0)); |
| 2640 | } |
| 2641 | #endif /* LIBXML_VALID_ENABLED */ |
| 2642 | xmlFreeID(ret); |
| 2643 | return(NULL((void*)0)); |
| 2644 | } |
| 2645 | if (attr != NULL((void*)0)) |
| 2646 | attr->atype = XML_ATTRIBUTE_ID; |
| 2647 | return(ret); |
| 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * xmlFreeIDTable: |
| 2652 | * @table: An id table |
| 2653 | * |
| 2654 | * Deallocate the memory used by an ID hash table. |
| 2655 | */ |
| 2656 | void |
| 2657 | xmlFreeIDTable(xmlIDTablePtr table) { |
| 2658 | xmlHashFreexmlHashFree__internal_alias(table, (xmlHashDeallocator) xmlFreeID); |
| 2659 | } |
| 2660 | |
| 2661 | /** |
| 2662 | * xmlIsID: |
| 2663 | * @doc: the document |
| 2664 | * @elem: the element carrying the attribute |
| 2665 | * @attr: the attribute |
| 2666 | * |
| 2667 | * Determine whether an attribute is of type ID. In case we have DTD(s) |
| 2668 | * then this is done if DTD loading has been requested. In the case |
| 2669 | * of HTML documents parsed with the HTML parser, then ID detection is |
| 2670 | * done systematically. |
| 2671 | * |
| 2672 | * Returns 0 or 1 depending on the lookup result |
| 2673 | */ |
| 2674 | int |
| 2675 | xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { |
| 2676 | if ((attr == NULL((void*)0)) || (attr->name == NULL((void*)0))) return(0); |
| 2677 | if ((attr->ns != NULL((void*)0)) && (attr->ns->prefix != NULL((void*)0)) && |
| 2678 | (!strcmp((char *) attr->name, "id")) && |
| 2679 | (!strcmp((char *) attr->ns->prefix, "xml"))) |
| 2680 | return(1); |
| 2681 | if (doc == NULL((void*)0)) return(0); |
| 2682 | if ((doc->intSubset == NULL((void*)0)) && (doc->extSubset == NULL((void*)0))) { |
| 2683 | return(0); |
| 2684 | } else if (doc->type == XML_HTML_DOCUMENT_NODE) { |
| 2685 | if ((xmlStrEqualxmlStrEqual__internal_alias(BAD_CAST(xmlChar *) "id", attr->name)) || |
| 2686 | ((xmlStrEqualxmlStrEqual__internal_alias(BAD_CAST(xmlChar *) "name", attr->name)) && |
| 2687 | ((elem == NULL((void*)0)) || (xmlStrEqualxmlStrEqual__internal_alias(elem->name, BAD_CAST(xmlChar *) "a"))))) |
| 2688 | return(1); |
| 2689 | return(0); |
| 2690 | } else if (elem == NULL((void*)0)) { |
| 2691 | return(0); |
| 2692 | } else { |
| 2693 | xmlAttributePtr attrDecl = NULL((void*)0); |
| 2694 | |
| 2695 | xmlChar felem[50], fattr[50]; |
| 2696 | xmlChar *fullelemname, *fullattrname; |
| 2697 | |
| 2698 | fullelemname = (elem->ns != NULL((void*)0) && elem->ns->prefix != NULL((void*)0)) ? |
| 2699 | xmlBuildQNamexmlBuildQName__internal_alias(elem->name, elem->ns->prefix, felem, 50) : |
| 2700 | (xmlChar *)elem->name; |
| 2701 | |
| 2702 | fullattrname = (attr->ns != NULL((void*)0) && attr->ns->prefix != NULL((void*)0)) ? |
| 2703 | xmlBuildQNamexmlBuildQName__internal_alias(attr->name, attr->ns->prefix, fattr, 50) : |
| 2704 | (xmlChar *)attr->name; |
| 2705 | |
| 2706 | if (fullelemname != NULL((void*)0) && fullattrname != NULL((void*)0)) { |
| 2707 | attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullelemname, |
| 2708 | fullattrname); |
| 2709 | if ((attrDecl == NULL((void*)0)) && (doc->extSubset != NULL((void*)0))) |
| 2710 | attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullelemname, |
| 2711 | fullattrname); |
| 2712 | } |
| 2713 | |
| 2714 | if ((fullattrname != fattr) && (fullattrname != attr->name)) |
| 2715 | xmlFree(fullattrname); |
| 2716 | if ((fullelemname != felem) && (fullelemname != elem->name)) |
| 2717 | xmlFree(fullelemname); |
| 2718 | |
| 2719 | if ((attrDecl != NULL((void*)0)) && (attrDecl->atype == XML_ATTRIBUTE_ID)) |
| 2720 | return(1); |
| 2721 | } |
| 2722 | return(0); |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * xmlRemoveID: |
| 2727 | * @doc: the document |
| 2728 | * @attr: the attribute |
| 2729 | * |
| 2730 | * Remove the given attribute from the ID table maintained internally. |
| 2731 | * |
| 2732 | * Returns -1 if the lookup failed and 0 otherwise |
| 2733 | */ |
| 2734 | int |
| 2735 | xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr) { |
| 2736 | xmlIDTablePtr table; |
| 2737 | xmlIDPtr id; |
| 2738 | xmlChar *ID; |
| 2739 | |
| 2740 | if (doc == NULL((void*)0)) return(-1); |
| 2741 | if (attr == NULL((void*)0)) return(-1); |
| 2742 | table = (xmlIDTablePtr) doc->ids; |
| 2743 | if (table == NULL((void*)0)) |
| 2744 | return(-1); |
| 2745 | |
| 2746 | if (attr == NULL((void*)0)) |
| 2747 | return(-1); |
| 2748 | ID = xmlNodeListGetStringxmlNodeListGetString__internal_alias(doc, attr->children, 1); |
| 2749 | if (ID == NULL((void*)0)) |
| 2750 | return(-1); |
| 2751 | id = xmlHashLookupxmlHashLookup__internal_alias(table, ID); |
| 2752 | if (id == NULL((void*)0) || id->attr != attr) { |
| 2753 | xmlFree(ID); |
| 2754 | return(-1); |
| 2755 | } |
| 2756 | xmlHashRemoveEntryxmlHashRemoveEntry__internal_alias(table, ID, (xmlHashDeallocator) xmlFreeID); |
| 2757 | xmlFree(ID); |
| 2758 | attr->atype = 0; |
| 2759 | return(0); |
| 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * xmlGetID: |
| 2764 | * @doc: pointer to the document |
| 2765 | * @ID: the ID value |
| 2766 | * |
| 2767 | * Search the attribute declaring the given ID |
| 2768 | * |
| 2769 | * Returns NULL if not found, otherwise the xmlAttrPtr defining the ID |
| 2770 | */ |
| 2771 | xmlAttrPtr |
| 2772 | xmlGetID(xmlDocPtr doc, const xmlChar *ID) { |
| 2773 | xmlIDTablePtr table; |
| 2774 | xmlIDPtr id; |
| 2775 | |
| 2776 | if (doc == NULL((void*)0)) { |
| 2777 | return(NULL((void*)0)); |
| 2778 | } |
| 2779 | |
| 2780 | if (ID == NULL((void*)0)) { |
| 2781 | return(NULL((void*)0)); |
| 2782 | } |
| 2783 | |
| 2784 | table = (xmlIDTablePtr) doc->ids; |
| 2785 | if (table == NULL((void*)0)) |
| 2786 | return(NULL((void*)0)); |
| 2787 | |
| 2788 | id = xmlHashLookupxmlHashLookup__internal_alias(table, ID); |
| 2789 | if (id == NULL((void*)0)) |
| 2790 | return(NULL((void*)0)); |
| 2791 | if (id->attr == NULL((void*)0)) { |
| 2792 | /* |
| 2793 | * We are operating on a stream, return a well known reference |
| 2794 | * since the attribute node doesn't exist anymore |
| 2795 | */ |
| 2796 | return((xmlAttrPtr) doc); |
| 2797 | } |
| 2798 | return(id->attr); |
| 2799 | } |
| 2800 | |
| 2801 | /************************************************************************ |
| 2802 | * * |
| 2803 | * Refs * |
| 2804 | * * |
| 2805 | ************************************************************************/ |
| 2806 | typedef struct xmlRemoveMemo_t |
| 2807 | { |
| 2808 | xmlListPtr l; |
| 2809 | xmlAttrPtr ap; |
| 2810 | } xmlRemoveMemo; |
| 2811 | |
| 2812 | typedef xmlRemoveMemo *xmlRemoveMemoPtr; |
| 2813 | |
| 2814 | typedef struct xmlValidateMemo_t |
| 2815 | { |
| 2816 | xmlValidCtxtPtr ctxt; |
| 2817 | const xmlChar *name; |
| 2818 | } xmlValidateMemo; |
| 2819 | |
| 2820 | typedef xmlValidateMemo *xmlValidateMemoPtr; |
| 2821 | |
| 2822 | /** |
| 2823 | * xmlFreeRef: |
| 2824 | * @lk: A list link |
| 2825 | * |
| 2826 | * Deallocate the memory used by a ref definition |
| 2827 | */ |
| 2828 | static void |
| 2829 | xmlFreeRef(xmlLinkPtr lk) { |
| 2830 | xmlRefPtr ref = (xmlRefPtr)xmlLinkGetDataxmlLinkGetData__internal_alias(lk); |
| 2831 | if (ref == NULL((void*)0)) return; |
| 2832 | if (ref->value != NULL((void*)0)) |
| 2833 | xmlFree((xmlChar *)ref->value); |
| 2834 | if (ref->name != NULL((void*)0)) |
| 2835 | xmlFree((xmlChar *)ref->name); |
| 2836 | xmlFree(ref); |
| 2837 | } |
| 2838 | |
| 2839 | /** |
| 2840 | * xmlFreeRefList: |
| 2841 | * @list_ref: A list of references. |
| 2842 | * |
| 2843 | * Deallocate the memory used by a list of references |
| 2844 | */ |
| 2845 | static void |
| 2846 | xmlFreeRefList(xmlListPtr list_ref) { |
| 2847 | if (list_ref == NULL((void*)0)) return; |
| 2848 | xmlListDeletexmlListDelete__internal_alias(list_ref); |
| 2849 | } |
| 2850 | |
| 2851 | /** |
| 2852 | * xmlWalkRemoveRef: |
| 2853 | * @data: Contents of current link |
| 2854 | * @user: Value supplied by the user |
| 2855 | * |
| 2856 | * Returns 0 to abort the walk or 1 to continue |
| 2857 | */ |
| 2858 | static int |
| 2859 | xmlWalkRemoveRef(const void *data, const void *user) |
| 2860 | { |
| 2861 | xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr; |
| 2862 | xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap; |
| 2863 | xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l; |
| 2864 | |
| 2865 | if (attr0 == attr1) { /* Matched: remove and terminate walk */ |
| 2866 | xmlListRemoveFirstxmlListRemoveFirst__internal_alias(ref_list, (void *)data); |
| 2867 | return 0; |
| 2868 | } |
| 2869 | return 1; |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * xmlDummyCompare |
| 2874 | * @data0: Value supplied by the user |
| 2875 | * @data1: Value supplied by the user |
| 2876 | * |
| 2877 | * Do nothing, return 0. Used to create unordered lists. |
| 2878 | */ |
| 2879 | static int |
| 2880 | xmlDummyCompare(const void *data0 ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2881 | const void *data1 ATTRIBUTE_UNUSED__attribute__((unused))) |
| 2882 | { |
| 2883 | return (0); |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * xmlAddRef: |
| 2888 | * @ctxt: the validation context |
| 2889 | * @doc: pointer to the document |
| 2890 | * @value: the value name |
| 2891 | * @attr: the attribute holding the Ref |
| 2892 | * |
| 2893 | * Register a new ref declaration |
| 2894 | * |
| 2895 | * Returns NULL if not, otherwise the new xmlRefPtr |
| 2896 | */ |
| 2897 | xmlRefPtr |
| 2898 | xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, |
| 2899 | xmlAttrPtr attr) { |
| 2900 | xmlRefPtr ret; |
| 2901 | xmlRefTablePtr table; |
| 2902 | xmlListPtr ref_list; |
| 2903 | |
| 2904 | if (doc == NULL((void*)0)) { |
| 2905 | return(NULL((void*)0)); |
| 2906 | } |
| 2907 | if (value == NULL((void*)0)) { |
| 2908 | return(NULL((void*)0)); |
| 2909 | } |
| 2910 | if (attr == NULL((void*)0)) { |
| 2911 | return(NULL((void*)0)); |
| 2912 | } |
| 2913 | |
| 2914 | /* |
| 2915 | * Create the Ref table if needed. |
| 2916 | */ |
| 2917 | table = (xmlRefTablePtr) doc->refs; |
| 2918 | if (table == NULL((void*)0)) { |
| 2919 | doc->refs = table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, doc->dict); |
| 2920 | } |
| 2921 | if (table == NULL((void*)0)) { |
| 2922 | xmlVErrMemory(ctxt, |
| 2923 | "xmlAddRef: Table creation failed!\n"); |
| 2924 | return(NULL((void*)0)); |
| 2925 | } |
| 2926 | |
| 2927 | ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef)); |
| 2928 | if (ret == NULL((void*)0)) { |
| 2929 | xmlVErrMemory(ctxt, "malloc failed"); |
| 2930 | return(NULL((void*)0)); |
| 2931 | } |
| 2932 | |
| 2933 | /* |
| 2934 | * fill the structure. |
| 2935 | */ |
| 2936 | ret->value = xmlStrdupxmlStrdup__internal_alias(value); |
| 2937 | if ((ctxt != NULL((void*)0)) && (ctxt->vstateNr != 0)) { |
| 2938 | /* |
| 2939 | * Operating in streaming mode, attr is gonna disapear |
| 2940 | */ |
| 2941 | ret->name = xmlStrdupxmlStrdup__internal_alias(attr->name); |
| 2942 | ret->attr = NULL((void*)0); |
| 2943 | } else { |
| 2944 | ret->name = NULL((void*)0); |
| 2945 | ret->attr = attr; |
| 2946 | } |
| 2947 | ret->lineno = xmlGetLineNoxmlGetLineNo__internal_alias(attr->parent); |
| 2948 | |
| 2949 | /* To add a reference :- |
| 2950 | * References are maintained as a list of references, |
| 2951 | * Lookup the entry, if no entry create new nodelist |
| 2952 | * Add the owning node to the NodeList |
| 2953 | * Return the ref |
| 2954 | */ |
| 2955 | |
| 2956 | if (NULL((void*)0) == (ref_list = xmlHashLookupxmlHashLookup__internal_alias(table, value))) { |
| 2957 | if (NULL((void*)0) == (ref_list = xmlListCreatexmlListCreate__internal_alias(xmlFreeRef, xmlDummyCompare))) { |
| 2958 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 2959 | "xmlAddRef: Reference list creation failed!\n", |
| 2960 | NULL((void*)0)); |
| 2961 | goto failed; |
| 2962 | } |
| 2963 | if (xmlHashAddEntryxmlHashAddEntry__internal_alias(table, value, ref_list) < 0) { |
| 2964 | xmlListDeletexmlListDelete__internal_alias(ref_list); |
| 2965 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 2966 | "xmlAddRef: Reference list insertion failed!\n", |
| 2967 | NULL((void*)0)); |
| 2968 | goto failed; |
| 2969 | } |
| 2970 | } |
| 2971 | if (xmlListAppendxmlListAppend__internal_alias(ref_list, ret) != 0) { |
| 2972 | xmlErrValid(NULL((void*)0), XML_ERR_INTERNAL_ERROR, |
| 2973 | "xmlAddRef: Reference list insertion failed!\n", |
| 2974 | NULL((void*)0)); |
| 2975 | goto failed; |
| 2976 | } |
| 2977 | return(ret); |
| 2978 | failed: |
| 2979 | if (ret != NULL((void*)0)) { |
| 2980 | if (ret->value != NULL((void*)0)) |
| 2981 | xmlFree((char *)ret->value); |
| 2982 | if (ret->name != NULL((void*)0)) |
| 2983 | xmlFree((char *)ret->name); |
| 2984 | xmlFree(ret); |
| 2985 | } |
| 2986 | return(NULL((void*)0)); |
| 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * xmlFreeRefTable: |
| 2991 | * @table: An ref table |
| 2992 | * |
| 2993 | * Deallocate the memory used by an Ref hash table. |
| 2994 | */ |
| 2995 | void |
| 2996 | xmlFreeRefTable(xmlRefTablePtr table) { |
| 2997 | xmlHashFreexmlHashFree__internal_alias(table, (xmlHashDeallocator) xmlFreeRefList); |
| 2998 | } |
| 2999 | |
| 3000 | /** |
| 3001 | * xmlIsRef: |
| 3002 | * @doc: the document |
| 3003 | * @elem: the element carrying the attribute |
| 3004 | * @attr: the attribute |
| 3005 | * |
| 3006 | * Determine whether an attribute is of type Ref. In case we have DTD(s) |
| 3007 | * then this is simple, otherwise we use an heuristic: name Ref (upper |
| 3008 | * or lowercase). |
| 3009 | * |
| 3010 | * Returns 0 or 1 depending on the lookup result |
| 3011 | */ |
| 3012 | int |
| 3013 | xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { |
| 3014 | if (attr == NULL((void*)0)) |
| 3015 | return(0); |
| 3016 | if (doc == NULL((void*)0)) { |
| 3017 | doc = attr->doc; |
| 3018 | if (doc == NULL((void*)0)) return(0); |
| 3019 | } |
| 3020 | |
| 3021 | if ((doc->intSubset == NULL((void*)0)) && (doc->extSubset == NULL((void*)0))) { |
| 3022 | return(0); |
| 3023 | } else if (doc->type == XML_HTML_DOCUMENT_NODE) { |
| 3024 | /* TODO @@@ */ |
| 3025 | return(0); |
| 3026 | } else { |
| 3027 | xmlAttributePtr attrDecl; |
| 3028 | |
| 3029 | if (elem == NULL((void*)0)) return(0); |
| 3030 | attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name); |
| 3031 | if ((attrDecl == NULL((void*)0)) && (doc->extSubset != NULL((void*)0))) |
| 3032 | attrDecl = xmlGetDtdAttrDesc(doc->extSubset, |
| 3033 | elem->name, attr->name); |
| 3034 | |
| 3035 | if ((attrDecl != NULL((void*)0)) && |
| 3036 | (attrDecl->atype == XML_ATTRIBUTE_IDREF || |
| 3037 | attrDecl->atype == XML_ATTRIBUTE_IDREFS)) |
| 3038 | return(1); |
| 3039 | } |
| 3040 | return(0); |
| 3041 | } |
| 3042 | |
| 3043 | /** |
| 3044 | * xmlRemoveRef: |
| 3045 | * @doc: the document |
| 3046 | * @attr: the attribute |
| 3047 | * |
| 3048 | * Remove the given attribute from the Ref table maintained internally. |
| 3049 | * |
| 3050 | * Returns -1 if the lookup failed and 0 otherwise |
| 3051 | */ |
| 3052 | int |
| 3053 | xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) { |
| 3054 | xmlListPtr ref_list; |
| 3055 | xmlRefTablePtr table; |
| 3056 | xmlChar *ID; |
| 3057 | xmlRemoveMemo target; |
| 3058 | |
| 3059 | if (doc == NULL((void*)0)) return(-1); |
| 3060 | if (attr == NULL((void*)0)) return(-1); |
| 3061 | table = (xmlRefTablePtr) doc->refs; |
| 3062 | if (table == NULL((void*)0)) |
| 3063 | return(-1); |
| 3064 | |
| 3065 | if (attr == NULL((void*)0)) |
| 3066 | return(-1); |
| 3067 | ID = xmlNodeListGetStringxmlNodeListGetString__internal_alias(doc, attr->children, 1); |
| 3068 | if (ID == NULL((void*)0)) |
| 3069 | return(-1); |
| 3070 | ref_list = xmlHashLookupxmlHashLookup__internal_alias(table, ID); |
| 3071 | |
| 3072 | if(ref_list == NULL((void*)0)) { |
| 3073 | xmlFree(ID); |
| 3074 | return (-1); |
| 3075 | } |
| 3076 | /* At this point, ref_list refers to a list of references which |
| 3077 | * have the same key as the supplied attr. Our list of references |
| 3078 | * is ordered by reference address and we don't have that information |
| 3079 | * here to use when removing. We'll have to walk the list and |
| 3080 | * check for a matching attribute, when we find one stop the walk |
| 3081 | * and remove the entry. |
| 3082 | * The list is ordered by reference, so that means we don't have the |
| 3083 | * key. Passing the list and the reference to the walker means we |
| 3084 | * will have enough data to be able to remove the entry. |
| 3085 | */ |
| 3086 | target.l = ref_list; |
| 3087 | target.ap = attr; |
| 3088 | |
| 3089 | /* Remove the supplied attr from our list */ |
| 3090 | xmlListWalkxmlListWalk__internal_alias(ref_list, xmlWalkRemoveRef, &target); |
| 3091 | |
| 3092 | /*If the list is empty then remove the list entry in the hash */ |
| 3093 | if (xmlListEmptyxmlListEmpty__internal_alias(ref_list)) |
| 3094 | xmlHashUpdateEntryxmlHashUpdateEntry__internal_alias(table, ID, NULL((void*)0), (xmlHashDeallocator) |
| 3095 | xmlFreeRefList); |
| 3096 | xmlFree(ID); |
| 3097 | return(0); |
| 3098 | } |
| 3099 | |
| 3100 | /** |
| 3101 | * xmlGetRefs: |
| 3102 | * @doc: pointer to the document |
| 3103 | * @ID: the ID value |
| 3104 | * |
| 3105 | * Find the set of references for the supplied ID. |
| 3106 | * |
| 3107 | * Returns NULL if not found, otherwise node set for the ID. |
| 3108 | */ |
| 3109 | xmlListPtr |
| 3110 | xmlGetRefs(xmlDocPtr doc, const xmlChar *ID) { |
| 3111 | xmlRefTablePtr table; |
| 3112 | |
| 3113 | if (doc == NULL((void*)0)) { |
| 3114 | return(NULL((void*)0)); |
| 3115 | } |
| 3116 | |
| 3117 | if (ID == NULL((void*)0)) { |
| 3118 | return(NULL((void*)0)); |
| 3119 | } |
| 3120 | |
| 3121 | table = (xmlRefTablePtr) doc->refs; |
| 3122 | if (table == NULL((void*)0)) |
| 3123 | return(NULL((void*)0)); |
| 3124 | |
| 3125 | return (xmlHashLookupxmlHashLookup__internal_alias(table, ID)); |
| 3126 | } |
| 3127 | |
| 3128 | /************************************************************************ |
| 3129 | * * |
| 3130 | * Routines for validity checking * |
| 3131 | * * |
| 3132 | ************************************************************************/ |
| 3133 | |
| 3134 | /** |
| 3135 | * xmlGetDtdElementDesc: |
| 3136 | * @dtd: a pointer to the DtD to search |
| 3137 | * @name: the element name |
| 3138 | * |
| 3139 | * Search the DTD for the description of this element |
| 3140 | * |
| 3141 | * returns the xmlElementPtr if found or NULL |
| 3142 | */ |
| 3143 | |
| 3144 | xmlElementPtr |
| 3145 | xmlGetDtdElementDesc(xmlDtdPtr dtd, const xmlChar *name) { |
| 3146 | xmlElementTablePtr table; |
| 3147 | xmlElementPtr cur; |
| 3148 | xmlChar *uqname = NULL((void*)0), *prefix = NULL((void*)0); |
| 3149 | |
| 3150 | if ((dtd == NULL((void*)0)) || (name == NULL((void*)0))) return(NULL((void*)0)); |
| 3151 | if (dtd->elements == NULL((void*)0)) |
| 3152 | return(NULL((void*)0)); |
| 3153 | table = (xmlElementTablePtr) dtd->elements; |
| 3154 | |
| 3155 | uqname = xmlSplitQName2xmlSplitQName2__internal_alias(name, &prefix); |
| 3156 | if (uqname != NULL((void*)0)) |
| 3157 | name = uqname; |
| 3158 | cur = xmlHashLookup2xmlHashLookup2__internal_alias(table, name, prefix); |
| 3159 | if (prefix != NULL((void*)0)) xmlFree(prefix); |
| 3160 | if (uqname != NULL((void*)0)) xmlFree(uqname); |
| 3161 | return(cur); |
| 3162 | } |
| 3163 | /** |
| 3164 | * xmlGetDtdElementDesc2: |
| 3165 | * @dtd: a pointer to the DtD to search |
| 3166 | * @name: the element name |
| 3167 | * @create: create an empty description if not found |
| 3168 | * |
| 3169 | * Search the DTD for the description of this element |
| 3170 | * |
| 3171 | * returns the xmlElementPtr if found or NULL |
| 3172 | */ |
| 3173 | |
| 3174 | static xmlElementPtr |
| 3175 | xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name, int create) { |
| 3176 | xmlElementTablePtr table; |
| 3177 | xmlElementPtr cur; |
| 3178 | xmlChar *uqname = NULL((void*)0), *prefix = NULL((void*)0); |
| 3179 | |
| 3180 | if (dtd == NULL((void*)0)) return(NULL((void*)0)); |
| 3181 | if (dtd->elements == NULL((void*)0)) { |
| 3182 | xmlDictPtr dict = NULL((void*)0); |
| 3183 | |
| 3184 | if (dtd->doc != NULL((void*)0)) |
| 3185 | dict = dtd->doc->dict; |
| 3186 | |
| 3187 | if (!create) |
| 3188 | return(NULL((void*)0)); |
| 3189 | /* |
| 3190 | * Create the Element table if needed. |
| 3191 | */ |
| 3192 | table = (xmlElementTablePtr) dtd->elements; |
| 3193 | if (table == NULL((void*)0)) { |
| 3194 | table = xmlHashCreateDictxmlHashCreateDict__internal_alias(0, dict); |
| 3195 | dtd->elements = (void *) table; |
| 3196 | } |
| 3197 | if (table == NULL((void*)0)) { |
| 3198 | xmlVErrMemory(NULL((void*)0), "element table allocation failed"); |
| 3199 | return(NULL((void*)0)); |
| 3200 | } |
| 3201 | } |
| 3202 | table = (xmlElementTablePtr) dtd->elements; |
| 3203 | |
| 3204 | uqname = xmlSplitQName2xmlSplitQName2__internal_alias(name, &prefix); |
| 3205 | if (uqname != NULL((void*)0)) |
| 3206 | name = uqname; |
| 3207 | cur = xmlHashLookup2xmlHashLookup2__internal_alias(table, name, prefix); |
| 3208 | if ((cur == NULL((void*)0)) && (create)) { |
| 3209 | cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); |
| 3210 | if (cur == NULL((void*)0)) { |
| 3211 | xmlVErrMemory(NULL((void*)0), "malloc failed"); |
| 3212 | return(NULL((void*)0)); |
| 3213 | } |
| 3214 | memset(cur, 0, sizeof(xmlElement)); |
| 3215 | cur->type = XML_ELEMENT_DECL; |
| 3216 | |
| 3217 | /* |
| 3218 | * fill the structure. |
| 3219 | */ |
| 3220 | cur->name = xmlStrdupxmlStrdup__internal_alias(name); |
| 3221 | cur->prefix = xmlStrdupxmlStrdup__internal_alias(prefix); |
| 3222 | cur->etype = XML_ELEMENT_TYPE_UNDEFINED; |
| 3223 | |
| 3224 | xmlHashAddEntry2xmlHashAddEntry2__internal_alias(table, name, prefix, cur); |
| 3225 | } |
| 3226 | if (prefix != NULL((void*)0)) xmlFree(prefix); |
| 3227 | if (uqname != NULL((void*)0)) xmlFree(uqname); |
| 3228 | return(cur); |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * xmlGetDtdQElementDesc: |
| 3233 | * @dtd: a pointer to the DtD to search |
| 3234 | * @name: the element name |
| 3235 | * @prefix: the element namespace prefix |
| 3236 | * |
| 3237 | * Search the DTD for the description of this element |
| 3238 | * |
| 3239 | * returns the xmlElementPtr if found or NULL |
| 3240 | */ |
| 3241 | |
| 3242 | xmlElementPtr |
| 3243 | xmlGetDtdQElementDesc(xmlDtdPtr dtd, const xmlChar *name, |
| 3244 | const xmlChar *prefix) { |
| 3245 | xmlElementTablePtr table; |
| 3246 | |
| 3247 | if (dtd == NULL((void*)0)) return(NULL((void*)0)); |
| 3248 | if (dtd->elements == NULL((void*)0)) return(NULL((void*)0)); |
| 3249 | table = (xmlElementTablePtr) dtd->elements; |
| 3250 | |
| 3251 | return(xmlHashLookup2xmlHashLookup2__internal_alias(table, name, prefix)); |
| 3252 | } |
| 3253 | |
| 3254 | /** |
| 3255 | * xmlGetDtdAttrDesc: |
| 3256 | * @dtd: a pointer to the DtD to search |
| 3257 | * @elem: the element name |
| 3258 | * @name: the attribute name |
| 3259 | * |
| 3260 | * Search the DTD for the description of this attribute on |
| 3261 | * this element. |
| 3262 | * |
| 3263 | * returns the xmlAttributePtr if found or NULL |
| 3264 | */ |
| 3265 | |
| 3266 | xmlAttributePtr |
| 3267 | xmlGetDtdAttrDesc(xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name) { |
| 3268 | xmlAttributeTablePtr table; |
| 3269 | xmlAttributePtr cur; |
| 3270 | xmlChar *uqname = NULL((void*)0), *prefix = NULL((void*)0); |
| 3271 | |
| 3272 | if (dtd == NULL((void*)0)) return(NULL((void*)0)); |
| 3273 | if (dtd->attributes == NULL((void*)0)) return(NULL((void*)0)); |
| 3274 | |
| 3275 | table = (xmlAttributeTablePtr) dtd->attributes; |
| 3276 | if (table == NULL((void*)0)) |
| 3277 | return(NULL((void*)0)); |
| 3278 | |
| 3279 | uqname = xmlSplitQName2xmlSplitQName2__internal_alias(name, &prefix); |
| 3280 | |
| 3281 | if (uqname != NULL((void*)0)) { |
| 3282 | cur = xmlHashLookup3xmlHashLookup3__internal_alias(table, uqname, prefix, elem); |
| 3283 | if (prefix != NULL((void*)0)) xmlFree(prefix); |
| 3284 | if (uqname != NULL((void*)0)) xmlFree(uqname); |
| 3285 | } else |
| 3286 | cur = xmlHashLookup3xmlHashLookup3__internal_alias(table, name, NULL((void*)0), elem); |
| 3287 | return(cur); |
| 3288 | } |
| 3289 | |
| 3290 | /** |
| 3291 | * xmlGetDtdQAttrDesc: |
| 3292 | * @dtd: a pointer to the DtD to search |
| 3293 | * @elem: the element name |
| 3294 | * @name: the attribute name |
| 3295 | * @prefix: the attribute namespace prefix |
| 3296 | * |
| 3297 | * Search the DTD for the description of this qualified attribute on |
| 3298 | * this element. |
| 3299 | * |
| 3300 | * returns the xmlAttributePtr if found or NULL |
| 3301 | */ |
| 3302 | |
| 3303 | xmlAttributePtr |
| 3304 | xmlGetDtdQAttrDesc(xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name, |
| 3305 | const xmlChar *prefix) { |
| 3306 | xmlAttributeTablePtr table; |
| 3307 | |
| 3308 | if (dtd == NULL((void*)0)) return(NULL((void*)0)); |
| 3309 | if (dtd->attributes == NULL((void*)0)) return(NULL((void*)0)); |
| 3310 | table = (xmlAttributeTablePtr) dtd->attributes; |
| 3311 | |
| 3312 | return(xmlHashLookup3xmlHashLookup3__internal_alias(table, name, prefix, elem)); |
| 3313 | } |
| 3314 | |
| 3315 | /** |
| 3316 | * xmlGetDtdNotationDesc: |
| 3317 | * @dtd: a pointer to the DtD to search |
| 3318 | * @name: the notation name |
| 3319 | * |
| 3320 | * Search the DTD for the description of this notation |
| 3321 | * |
| 3322 | * returns the xmlNotationPtr if found or NULL |
| 3323 | */ |
| 3324 | |
| 3325 | xmlNotationPtr |
| 3326 | xmlGetDtdNotationDesc(xmlDtdPtr dtd, const xmlChar *name) { |
| 3327 | xmlNotationTablePtr table; |
| 3328 | |
| 3329 | if (dtd == NULL((void*)0)) return(NULL((void*)0)); |
| 3330 | if (dtd->notations == NULL((void*)0)) return(NULL((void*)0)); |
| 3331 | table = (xmlNotationTablePtr) dtd->notations; |
| 3332 | |
| 3333 | return(xmlHashLookupxmlHashLookup__internal_alias(table, name)); |
| 3334 | } |
| 3335 | |
| 3336 | #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| 3337 | /** |
| 3338 | * xmlValidateNotationUse: |
| 3339 | * @ctxt: the validation context |
| 3340 | * @doc: the document |
| 3341 | * @notationName: the notation name to check |
| 3342 | * |
| 3343 | * Validate that the given name match a notation declaration. |
| 3344 | * - [ VC: Notation Declared ] |
| 3345 | * |
| 3346 | * returns 1 if valid or 0 otherwise |
| 3347 | */ |
| 3348 | |
| 3349 | int |
| 3350 | xmlValidateNotationUse(xmlValidCtxtPtr ctxt, xmlDocPtr doc, |
| 3351 | const xmlChar *notationName) { |
| 3352 | xmlNotationPtr notaDecl; |
| 3353 | if ((doc == NULL((void*)0)) || (doc->intSubset == NULL((void*)0)) || |
| 3354 | (notationName == NULL((void*)0))) return(-1); |
| 3355 | |
| 3356 | notaDecl = xmlGetDtdNotationDesc(doc->intSubset, notationName); |
| 3357 | if ((notaDecl == NULL((void*)0)) && (doc->extSubset != NULL((void*)0))) |
| 3358 | notaDecl = xmlGetDtdNotationDesc(doc->extSubset, notationName); |
| 3359 | |
| 3360 | if ((notaDecl == NULL((void*)0)) && (ctxt != NULL((void*)0))) { |
| 3361 | xmlErrValidNode(ctxt, (xmlNodePtr) doc, XML_DTD_UNKNOWN_NOTATION, |
| 3362 | "NOTATION %s is not declared\n", |
| 3363 | notationName, NULL((void*)0), NULL((void*)0)); |
| 3364 | return(0); |
| 3365 | } |
| 3366 | return(1); |
| 3367 | } |
| 3368 | #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */ |
| 3369 | |
| 3370 | /** |
| 3371 | * xmlIsMixedElement: |
| 3372 | * @doc: the document |
| 3373 | * @name: the element name |
| 3374 | * |
| 3375 | * Search in the DtDs whether an element accept Mixed content (or ANY) |
| 3376 | * basically if it is supposed to accept text childs |
| 3377 | * |
| 3378 | * returns 0 if no, 1 if yes, and -1 if no element description is available |
| 3379 | */ |
| 3380 | |
| 3381 | int |
| 3382 | xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) { |
| 3383 | xmlElementPtr elemDecl; |
| 3384 | |
| 3385 | if ((doc == NULL((void*)0)) || (doc->intSubset == NULL((void*)0))) return(-1); |
| 3386 | |
| 3387 | elemDecl = xmlGetDtdElementDesc(doc->intSubset, name); |
| 3388 | if ((elemDecl == NULL((void*)0)) && (doc->extSubset != NULL((void*)0))) |
| 3389 | elemDecl = xmlGetDtdElementDesc(doc->extSubset, name); |
| 3390 | if (elemDecl == NULL((void*)0)) return(-1); |
| 3391 | switch (elemDecl->etype) { |
| 3392 | case XML_ELEMENT_TYPE_UNDEFINED: |
| 3393 | return(-1); |
| 3394 | case XML_ELEMENT_TYPE_ELEMENT: |
| 3395 | return(0); |
| 3396 | case XML_ELEMENT_TYPE_EMPTY: |
| 3397 | /* |
| 3398 | * return 1 for EMPTY since we want VC error to pop up |
| 3399 | * on <empty> </empty> for example |
| 3400 | */ |
| 3401 | case XML_ELEMENT_TYPE_ANY: |
| 3402 | case XML_ELEMENT_TYPE_MIXED: |
| 3403 | return(1); |
| 3404 | } |
| 3405 | return(1); |
| 3406 | } |
| 3407 | |
| 3408 | #ifdef LIBXML_VALID_ENABLED |
| 3409 | |
| 3410 | static int |
| 3411 | xmlIsDocNameStartChar(xmlDocPtr doc, int c) { |
| 3412 | if ((doc == NULL((void*)0)) || (doc->properties & XML_DOC_OLD10) == 0) { |
| 3413 | /* |
| 3414 | * Use the new checks of production [4] [4a] amd [5] of the |
| 3415 | * Update 5 of XML-1.0 |
| 3416 | */ |
| 3417 | if (((c >= 'a') && (c <= 'z')) || |
| 3418 | ((c >= 'A') && (c <= 'Z')) || |
| 3419 | (c == '_') || (c == ':') || |
| 3420 | ((c >= 0xC0) && (c <= 0xD6)) || |
| 3421 | ((c >= 0xD8) && (c <= 0xF6)) || |
| 3422 | ((c >= 0xF8) && (c <= 0x2FF)) || |
| 3423 | ((c >= 0x370) && (c <= 0x37D)) || |
| 3424 | ((c >= 0x37F) && (c <= 0x1FFF)) || |
| 3425 | ((c >= 0x200C) && (c <= 0x200D)) || |
| 3426 | ((c >= 0x2070) && (c <= 0x218F)) || |
| 3427 | ((c >= 0x2C00) && (c <= 0x2FEF)) || |
| 3428 | ((c >= 0x3001) && (c <= 0xD7FF)) || |
| 3429 | ((c >= 0xF900) && (c <= 0xFDCF)) || |
| 3430 | ((c >= 0xFDF0) && (c <= 0xFFFD)) || |
| 3431 | ((c >= 0x10000) && (c <= 0xEFFFF))) |
| 3432 | return(1); |
| 3433 | } else { |
| 3434 | if (IS_LETTER(c)((((c) < 0x100) ? (((0x41 <= ((c))) && (((c)) <= 0x5a)) || ((0x61 <= ((c))) && (((c)) <= 0x7a)) || ((0xc0 <= ((c))) && (((c)) <= 0xd6)) || ((0xd8 <= ((c))) && (((c)) <= 0xf6)) || (0xf8 <= ( (c)))) : xmlCharInRange__internal_alias((c), &xmlIsBaseCharGroup )) || (((c) < 0x100) ? 0 : (((0x4e00 <= (c)) && ((c) <= 0x9fa5)) || ((c) == 0x3007) || ((0x3021 <= (c) ) && ((c) <= 0x3029))))) || (c == '_') || (c == ':')) |
| 3435 | return(1); |
| 3436 | } |
| 3437 | return(0); |
| 3438 | } |
| 3439 | |
| 3440 | static int |
| 3441 | xmlIsDocNameChar(xmlDocPtr doc, int c) { |
| 3442 | if ((doc == NULL((void*)0)) || (doc->properties & XML_DOC_OLD10) == 0) { |
| 3443 | /* |
| 3444 | * Use the new checks of production [4] [4a] amd [5] of the |
| 3445 | * Update 5 of XML-1.0 |
| 3446 | */ |
| 3447 | if (((c >= 'a') && (c <= 'z')) || |
| 3448 | ((c >= 'A') && (c <= 'Z')) || |
| 3449 | ((c >= '0') && (c <= '9')) || /* !start */ |
| 3450 | (c == '_') || (c == ':') || |
| 3451 | (c == '-') || (c == '.') || (c == 0xB7) || /* !start */ |
| 3452 | ((c >= 0xC0) && (c <= 0xD6)) || |
| 3453 | ((c >= 0xD8) && (c <= 0xF6)) || |
| 3454 | ((c >= 0xF8) && (c <= 0x2FF)) || |
| 3455 | ((c >= 0x300) && (c <= 0x36F)) || /* !start */ |
| 3456 | ((c >= 0x370) && (c <= 0x37D)) || |
| 3457 | ((c >= 0x37F) && (c <= 0x1FFF)) || |
| 3458 | ((c >= 0x200C) && (c <= 0x200D)) || |
| 3459 | ((c >= 0x203F) && (c <= 0x2040)) || /* !start */ |
| 3460 | ((c >= 0x2070) && (c <= 0x218F)) || |
| 3461 | ((c >= 0x2C00) && (c <= 0x2FEF)) || |
| 3462 | ((c >= 0x3001) && (c <= 0xD7FF)) || |
| 3463 | ((c >= 0xF900) && (c <= 0xFDCF)) || |
| 3464 | ((c >= 0xFDF0) && (c <= 0xFFFD)) || |
| 3465 | ((c >= 0x10000) && (c <= 0xEFFFF))) |
| 3466 | return(1); |
| 3467 | } else { |
| 3468 | if ((IS_LETTER(c)((((c) < 0x100) ? (((0x41 <= ((c))) && (((c)) <= 0x5a)) || ((0x61 <= ((c))) && (((c)) <= 0x7a)) || ((0xc0 <= ((c))) && (((c)) <= 0xd6)) || ((0xd8 <= ((c))) && (((c)) <= 0xf6)) || (0xf8 <= ( (c)))) : xmlCharInRange__internal_alias((c), &xmlIsBaseCharGroup )) || (((c) < 0x100) ? 0 : (((0x4e00 <= (c)) && ((c) <= 0x9fa5)) || ((c) == 0x3007) || ((0x3021 <= (c) ) && ((c) <= 0x3029)))))) || (IS_DIGIT(c)(((c) < 0x100) ? (((0x30 <= ((c))) && (((c)) <= 0x39))) : xmlCharInRange__internal_alias((c), &xmlIsDigitGroup ))) || |
| 3469 | (c == '.') || (c == '-') || |
| 3470 | (c == '_') || (c == ':') || |
| 3471 | (IS_COMBINING(c)(((c) < 0x100) ? 0 : xmlCharInRange__internal_alias((c), & xmlIsCombiningGroup))) || |
| 3472 | (IS_EXTENDER(c)(((c) < 0x100) ? ((((c)) == 0xb7)) : xmlCharInRange__internal_alias ((c), &xmlIsExtenderGroup)))) |
| 3473 | return(1); |
| 3474 | } |
| 3475 | return(0); |
| 3476 | } |
| 3477 | |
| 3478 | /** |
| 3479 | * xmlValidateNameValue: |
| 3480 | * @doc: pointer to the document or NULL |
| 3481 | * @value: an Name value |
| 3482 | * |
| 3483 | * Validate that the given value match Name production |
| 3484 | * |
| 3485 | * returns 1 if valid or 0 otherwise |
| 3486 | */ |
| 3487 | |
| 3488 | static int |
| 3489 | xmlValidateNameValueInternal(xmlDocPtr doc, const xmlChar *value) { |
| 3490 | const xmlChar *cur; |
| 3491 | int val, len; |
| 3492 | |
| 3493 | if (value == NULL((void*)0)) return(0); |
| 3494 | cur = value; |
| 3495 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3496 | cur += len; |
| 3497 | if (!xmlIsDocNameStartChar(doc, val)) |
| 3498 | return(0); |
| 3499 | |
| 3500 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3501 | cur += len; |
| 3502 | while (xmlIsDocNameChar(doc, val)) { |
| 3503 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3504 | cur += len; |
| 3505 | } |
| 3506 | |
| 3507 | if (val != 0) return(0); |
| 3508 | |
| 3509 | return(1); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * xmlValidateNameValue: |
| 3514 | * @value: an Name value |
| 3515 | * |
| 3516 | * Validate that the given value match Name production |
| 3517 | * |
| 3518 | * returns 1 if valid or 0 otherwise |
| 3519 | */ |
| 3520 | |
| 3521 | int |
| 3522 | xmlValidateNameValue(const xmlChar *value) { |
| 3523 | return(xmlValidateNameValueInternal(NULL((void*)0), value)); |
| 3524 | } |
| 3525 | |
| 3526 | /** |
| 3527 | * xmlValidateNamesValueInternal: |
| 3528 | * @doc: pointer to the document or NULL |
| 3529 | * @value: an Names value |
| 3530 | * |
| 3531 | * Validate that the given value match Names production |
| 3532 | * |
| 3533 | * returns 1 if valid or 0 otherwise |
| 3534 | */ |
| 3535 | |
| 3536 | static int |
| 3537 | xmlValidateNamesValueInternal(xmlDocPtr doc, const xmlChar *value) { |
| 3538 | const xmlChar *cur; |
| 3539 | int val, len; |
| 3540 | |
| 3541 | if (value == NULL((void*)0)) return(0); |
| 3542 | cur = value; |
| 3543 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3544 | cur += len; |
| 3545 | |
| 3546 | if (!xmlIsDocNameStartChar(doc, val)) |
| 3547 | return(0); |
| 3548 | |
| 3549 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3550 | cur += len; |
| 3551 | while (xmlIsDocNameChar(doc, val)) { |
| 3552 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3553 | cur += len; |
| 3554 | } |
| 3555 | |
| 3556 | /* Should not test IS_BLANK(val) here -- see erratum E20*/ |
| 3557 | while (val == 0x20) { |
| 3558 | while (val == 0x20) { |
| 3559 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3560 | cur += len; |
| 3561 | } |
| 3562 | |
| 3563 | if (!xmlIsDocNameStartChar(doc, val)) |
| 3564 | return(0); |
| 3565 | |
| 3566 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3567 | cur += len; |
| 3568 | |
| 3569 | while (xmlIsDocNameChar(doc, val)) { |
| 3570 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3571 | cur += len; |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | if (val != 0) return(0); |
| 3576 | |
| 3577 | return(1); |
| 3578 | } |
| 3579 | |
| 3580 | /** |
| 3581 | * xmlValidateNamesValue: |
| 3582 | * @value: an Names value |
| 3583 | * |
| 3584 | * Validate that the given value match Names production |
| 3585 | * |
| 3586 | * returns 1 if valid or 0 otherwise |
| 3587 | */ |
| 3588 | |
| 3589 | int |
| 3590 | xmlValidateNamesValue(const xmlChar *value) { |
| 3591 | return(xmlValidateNamesValueInternal(NULL((void*)0), value)); |
| 3592 | } |
| 3593 | |
| 3594 | /** |
| 3595 | * xmlValidateNmtokenValueInternal: |
| 3596 | * @doc: pointer to the document or NULL |
| 3597 | * @value: an Nmtoken value |
| 3598 | * |
| 3599 | * Validate that the given value match Nmtoken production |
| 3600 | * |
| 3601 | * [ VC: Name Token ] |
| 3602 | * |
| 3603 | * returns 1 if valid or 0 otherwise |
| 3604 | */ |
| 3605 | |
| 3606 | static int |
| 3607 | xmlValidateNmtokenValueInternal(xmlDocPtr doc, const xmlChar *value) { |
| 3608 | const xmlChar *cur; |
| 3609 | int val, len; |
| 3610 | |
| 3611 | if (value == NULL((void*)0)) return(0); |
| 3612 | cur = value; |
| 3613 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3614 | cur += len; |
| 3615 | |
| 3616 | if (!xmlIsDocNameChar(doc, val)) |
| 3617 | return(0); |
| 3618 | |
| 3619 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3620 | cur += len; |
| 3621 | while (xmlIsDocNameChar(doc, val)) { |
| 3622 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3623 | cur += len; |
| 3624 | } |
| 3625 | |
| 3626 | if (val != 0) return(0); |
| 3627 | |
| 3628 | return(1); |
| 3629 | } |
| 3630 | |
| 3631 | /** |
| 3632 | * xmlValidateNmtokenValue: |
| 3633 | * @value: an Nmtoken value |
| 3634 | * |
| 3635 | * Validate that the given value match Nmtoken production |
| 3636 | * |
| 3637 | * [ VC: Name Token ] |
| 3638 | * |
| 3639 | * returns 1 if valid or 0 otherwise |
| 3640 | */ |
| 3641 | |
| 3642 | int |
| 3643 | xmlValidateNmtokenValue(const xmlChar *value) { |
| 3644 | return(xmlValidateNmtokenValueInternal(NULL((void*)0), value)); |
| 3645 | } |
| 3646 | |
| 3647 | /** |
| 3648 | * xmlValidateNmtokensValueInternal: |
| 3649 | * @doc: pointer to the document or NULL |
| 3650 | * @value: an Nmtokens value |
| 3651 | * |
| 3652 | * Validate that the given value match Nmtokens production |
| 3653 | * |
| 3654 | * [ VC: Name Token ] |
| 3655 | * |
| 3656 | * returns 1 if valid or 0 otherwise |
| 3657 | */ |
| 3658 | |
| 3659 | static int |
| 3660 | xmlValidateNmtokensValueInternal(xmlDocPtr doc, const xmlChar *value) { |
| 3661 | const xmlChar *cur; |
| 3662 | int val, len; |
| 3663 | |
| 3664 | if (value == NULL((void*)0)) return(0); |
| 3665 | cur = value; |
| 3666 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3667 | cur += len; |
| 3668 | |
| 3669 | while (IS_BLANK(val)(((val) < 0x100) ? ((((val)) == 0x20) || ((0x9 <= ((val ))) && (((val)) <= 0xa)) || (((val)) == 0xd)) : 0)) { |
| 3670 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3671 | cur += len; |
| 3672 | } |
| 3673 | |
| 3674 | if (!xmlIsDocNameChar(doc, val)) |
| 3675 | return(0); |
| 3676 | |
| 3677 | while (xmlIsDocNameChar(doc, val)) { |
| 3678 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3679 | cur += len; |
| 3680 | } |
| 3681 | |
| 3682 | /* Should not test IS_BLANK(val) here -- see erratum E20*/ |
| 3683 | while (val == 0x20) { |
| 3684 | while (val == 0x20) { |
| 3685 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3686 | cur += len; |
| 3687 | } |
| 3688 | if (val == 0) return(1); |
| 3689 | |
| 3690 | if (!xmlIsDocNameChar(doc, val)) |
| 3691 | return(0); |
| 3692 | |
| 3693 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3694 | cur += len; |
| 3695 | |
| 3696 | while (xmlIsDocNameChar(doc, val)) { |
| 3697 | val = xmlStringCurrentCharxmlStringCurrentChar__internal_alias(NULL((void*)0), cur, &len); |
| 3698 | cur += len; |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | if (val != 0) return(0); |
| 3703 | |
| 3704 | return(1); |
| 3705 | } |
| 3706 | |
| 3707 | /** |
| 3708 | * xmlValidateNmtokensValue: |
| 3709 | * @value: an Nmtokens value |
| 3710 | * |
| 3711 | * Validate that the given value match Nmtokens production |
| 3712 | * |
| 3713 | * [ VC: Name Token ] |
| 3714 | * |
| 3715 | * returns 1 if valid or 0 otherwise |
| 3716 | */ |
| 3717 | |
| 3718 | int |
| 3719 | xmlValidateNmtokensValue(const xmlChar *value) { |
| 3720 | return(xmlValidateNmtokensValueInternal(NULL((void*)0), value)); |
| 3721 | } |
| 3722 | |
| 3723 | /** |
| 3724 | * xmlValidateNotationDecl: |
| 3725 | * @ctxt: the validation context |
| 3726 | * @doc: a document instance |
| 3727 | * @nota: a notation definition |
| 3728 | * |
| 3729 | * Try to validate a single notation definition |
| 3730 | * basically it does the following checks as described by the |
| 3731 | * XML-1.0 recommendation: |
| 3732 | * - it seems that no validity constraint exists on notation declarations |
| 3733 | * But this function get called anyway ... |
| 3734 | * |
| 3735 | * returns 1 if valid or 0 otherwise |
| 3736 | */ |
| 3737 | |
| 3738 | int |
| 3739 | xmlValidateNotationDecl(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED__attribute__((unused)), xmlDocPtr doc ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3740 | xmlNotationPtr nota ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 3741 | int ret = 1; |
| 3742 | |
| 3743 | return(ret); |
| 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * xmlValidateAttributeValueInternal: |
| 3748 | * @doc: the document |
| 3749 | * @type: an attribute type |
| 3750 | * @value: an attribute value |
| 3751 | * |
| 3752 | * Validate that the given attribute value match the proper production |
| 3753 | * |
| 3754 | * returns 1 if valid or 0 otherwise |
| 3755 | */ |
| 3756 | |
| 3757 | static int |
| 3758 | xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type, |
| 3759 | const xmlChar *value) { |
| 3760 | switch (type) { |
| 3761 | case XML_ATTRIBUTE_ENTITIES: |
| 3762 | case XML_ATTRIBUTE_IDREFS: |
| 3763 | return(xmlValidateNamesValueInternal(doc, value)); |
| 3764 | case XML_ATTRIBUTE_ENTITY: |
| 3765 | case XML_ATTRIBUTE_IDREF: |
| 3766 | case XML_ATTRIBUTE_ID: |
| 3767 | case XML_ATTRIBUTE_NOTATION: |
| 3768 | return(xmlValidateNameValueInternal(doc, value)); |
| 3769 | case XML_ATTRIBUTE_NMTOKENS: |
| 3770 | case XML_ATTRIBUTE_ENUMERATION: |
| 3771 | return(xmlValidateNmtokensValueInternal(doc, value)); |
| 3772 | case XML_ATTRIBUTE_NMTOKEN: |
| 3773 | return(xmlValidateNmtokenValueInternal(doc, value)); |
| 3774 | case XML_ATTRIBUTE_CDATA: |
| 3775 | break; |
| 3776 | } |
| 3777 | return(1); |
| 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * xmlValidateAttributeValue: |
| 3782 | * @type: an attribute type |
| 3783 | * @value: an attribute value |
| 3784 | * |
| 3785 | * Validate that the given attribute value match the proper production |
| 3786 | * |
| 3787 | * [ VC: ID ] |
| 3788 | * Values of type ID must match the Name production.... |
| 3789 | * |
| 3790 | * [ VC: IDREF ] |
| 3791 | * Values of type IDREF must match the Name production, and values |
| 3792 | * of type IDREFS must match Names ... |
| 3793 | * |
| 3794 | * [ VC: Entity Name ] |
| 3795 | * Values of type ENTITY must match the Name production, values |
| 3796 | * of type ENTITIES must match Names ... |
| 3797 | * |
| 3798 | * [ VC: Name Token ] |
| 3799 | * Values of type NMTOKEN must match the Nmtoken production; values |
| 3800 | * of type NMTOKENS must match Nmtokens. |
| 3801 | * |
| 3802 | * returns 1 if valid or 0 otherwise |
| 3803 | */ |
| 3804 | int |
| 3805 | xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) { |
| 3806 | return(xmlValidateAttributeValueInternal(NULL((void*)0), type, value)); |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * xmlValidateAttributeValue2: |
| 3811 | * @ctxt: the validation context |
| 3812 | * @doc: the document |
| 3813 | * @name: the attribute name (used for error reporting only) |
| 3814 | * @type: the attribute type |
| 3815 | * @value: the attribute value |
| 3816 | * |
| 3817 | * Validate that the given attribute value match a given type. |
| 3818 | * This typically cannot be done before having finished parsing |
| 3819 | * the subsets. |
| 3820 | * |
| 3821 | * [ VC: IDREF ] |
| 3822 | * Values of type IDREF must match one of the declared IDs |
| 3823 | * Values of type IDREFS must match a sequence of the declared IDs |
| 3824 | * each Name must match the value of an ID attribute on some element |
| 3825 | * in the XML document; i.e. IDREF values must match the value of |
| 3826 | * some ID attribute |
| 3827 | * |
| 3828 | * [ VC: Entity Name ] |
| 3829 | * Values of type ENTITY must match one declared entity |
| 3830 | * Values of type ENTITIES must match a sequence of declared entities |
| 3831 | * |
| 3832 | * [ VC: Notation Attributes ] |
| 3833 | * all notation names in the declaration must be declared. |
| 3834 | * |
| 3835 | * returns 1 if valid or 0 otherwise |
| 3836 | */ |
| 3837 | |
| 3838 | static int |
| 3839 | xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc, |
| 3840 | const xmlChar *name, xmlAttributeType type, const xmlChar *value) { |
| 3841 | int ret = 1; |
| 3842 | switch (type) { |
| 3843 | case XML_ATTRIBUTE_IDREFS: |
| 3844 | case XML_ATTRIBUTE_IDREF: |
| 3845 | case XML_ATTRIBUTE_ID: |
| 3846 | case XML_ATTRIBUTE_NMTOKENS: |
| 3847 | case XML_ATTRIBUTE_ENUMERATION: |
| 3848 | case XML_ATTRIBUTE_NMTOKEN: |
| 3849 | case XML_ATTRIBUTE_CDATA: |
| 3850 | break; |
| 3851 | case XML_ATTRIBUTE_ENTITY: { |
| 3852 | xmlEntityPtr ent; |
| 3853 | |
| 3854 | ent = xmlGetDocEntityxmlGetDocEntity__internal_alias(doc, value); |
| 3855 | /* yeah it's a bit messy... */ |
| 3856 | if ((ent == NULL((void*)0)) && (doc->standalone == 1)) { |
| 3857 | doc->standalone = 0; |
| 3858 | ent = xmlGetDocEntityxmlGetDocEntity__internal_alias(doc, value); |
| 3859 | } |
| 3860 | if (ent == NULL((void*)0)) { |
| 3861 | xmlErrValidNode(ctxt, (xmlNodePtr) doc, |
| 3862 | XML_DTD_UNKNOWN_ENTITY, |
| 3863 | "ENTITY attribute %s reference an unknown entity \"%s\"\n", |
| 3864 | name, value, NULL((void*)0)); |
| 3865 | ret = 0; |
| 3866 | } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
| 3867 | xmlErrValidNode(ctxt, (xmlNodePtr) doc, |
| 3868 | XML_DTD_ENTITY_TYPE, |
| 3869 | "ENTITY attribute %s reference an entity \"%s\" of wrong type\n", |
| 3870 | name, value, NULL((void*)0)); |
| 3871 | ret = 0; |
| 3872 | } |
| 3873 | break; |
| 3874 | } |
| 3875 | case XML_ATTRIBUTE_ENTITIES: { |
| 3876 | xmlChar *dup, *nam = NULL((void*)0), *cur, save; |
| 3877 | xmlEntityPtr ent; |
| 3878 | |
| 3879 | dup = xmlStrdupxmlStrdup__internal_alias(value); |
| 3880 | if (dup == NULL((void*)0)) |
| 3881 | return(0); |
| 3882 | cur = dup; |
| 3883 | while (*cur != 0) { |
| 3884 | nam = cur; |
| 3885 | while ((*cur != 0) && (!IS_BLANK_CH(*cur)(((*cur) == 0x20) || ((0x9 <= (*cur)) && ((*cur) <= 0xa)) || ((*cur) == 0xd)))) cur++; |
| 3886 | save = *cur; |
| 3887 | *cur = 0; |
| 3888 | ent = xmlGetDocEntityxmlGetDocEntity__internal_alias(doc, nam); |
| 3889 | if (ent == NULL((void*)0)) { |
| 3890 | xmlErrValidNode(ctxt, (xmlNodePtr) doc, |
| 3891 | XML_DTD_UNKNOWN_ENTITY, |
| 3892 | "ENTITIES attribute %s reference an unknown entity \"%s\"\n", |