OLD | NEW |
1 /* | 1 /* |
2 * relaxng.c : implementation of the Relax-NG handling and validity checking | 2 * relaxng.c : implementation of the Relax-NG handling and validity checking |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * Daniel Veillard <veillard@redhat.com> | 6 * Daniel Veillard <veillard@redhat.com> |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * TODO: | 10 * TODO: |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include <libxml/xmlautomata.h> | 32 #include <libxml/xmlautomata.h> |
33 #include <libxml/xmlregexp.h> | 33 #include <libxml/xmlregexp.h> |
34 #include <libxml/xmlschemastypes.h> | 34 #include <libxml/xmlschemastypes.h> |
35 | 35 |
36 /* | 36 /* |
37 * The Relax-NG namespace | 37 * The Relax-NG namespace |
38 */ | 38 */ |
39 static const xmlChar *xmlRelaxNGNs = (const xmlChar *) | 39 static const xmlChar *xmlRelaxNGNs = (const xmlChar *) |
40 "http://relaxng.org/ns/structure/1.0"; | 40 "http://relaxng.org/ns/structure/1.0"; |
41 | 41 |
42 #define IS_RELAXNG(node, type)» » » » » » \ | 42 #define IS_RELAXNG(node, typ)» » » » » » \ |
43 ((node != NULL) && (node->ns != NULL) && \ | 43 ((node != NULL) && (node->ns != NULL) && \ |
44 (xmlStrEqual(node->name, (const xmlChar *) type)) &&» » \ | 44 (node->type == XML_ELEMENT_NODE) &&»» » » » \ |
| 45 (xmlStrEqual(node->name, (const xmlChar *) typ)) &&»» \ |
45 (xmlStrEqual(node->ns->href, xmlRelaxNGNs))) | 46 (xmlStrEqual(node->ns->href, xmlRelaxNGNs))) |
46 | 47 |
47 | 48 |
48 #if 0 | 49 #if 0 |
49 #define DEBUG 1 | 50 #define DEBUG 1 |
50 | 51 |
51 #define DEBUG_GRAMMAR 1 | 52 #define DEBUG_GRAMMAR 1 |
52 | 53 |
53 #define DEBUG_CONTENT 1 | 54 #define DEBUG_CONTENT 1 |
54 | 55 |
55 #define DEBUG_TYPE 1 | 56 #define DEBUG_TYPE 1 |
56 | 57 |
57 #define DEBUG_VALID 1 | 58 #define DEBUG_VALID 1 |
58 | 59 |
59 #define DEBUG_INTERLEAVE 1 | 60 #define DEBUG_INTERLEAVE 1 |
60 | 61 |
61 #define DEBUG_LIST 1 | 62 #define DEBUG_LIST 1 |
62 | 63 |
63 #define DEBUG_INCLUDE 1 | 64 #define DEBUG_INCLUDE 1 |
64 | 65 |
65 #define DEBUG_ERROR 1 | 66 #define DEBUG_ERROR 1 |
66 | 67 |
67 #define DEBUG_COMPILE 1 | 68 #define DEBUG_COMPILE 1 |
68 | 69 |
69 #define DEBUG_PROGRESSIVE 1 | 70 #define DEBUG_PROGRESSIVE 1 |
70 #endif | 71 #endif |
71 | 72 |
72 #define MAX_ERROR 5 | 73 #define MAX_ERROR 5 |
73 | 74 |
74 #define TODO » » » » » » » » \ | 75 #define TODO» » » » » » » » \ |
75 xmlGenericError(xmlGenericErrorContext, \ | 76 xmlGenericError(xmlGenericErrorContext, \ |
76 "Unimplemented block at %s:%d\n", \ | 77 "Unimplemented block at %s:%d\n", \ |
77 __FILE__, __LINE__); | 78 __FILE__, __LINE__); |
78 | 79 |
79 typedef struct _xmlRelaxNGSchema xmlRelaxNGSchema; | 80 typedef struct _xmlRelaxNGSchema xmlRelaxNGSchema; |
80 typedef xmlRelaxNGSchema *xmlRelaxNGSchemaPtr; | 81 typedef xmlRelaxNGSchema *xmlRelaxNGSchemaPtr; |
81 | 82 |
82 typedef struct _xmlRelaxNGDefine xmlRelaxNGDefine; | 83 typedef struct _xmlRelaxNGDefine xmlRelaxNGDefine; |
83 typedef xmlRelaxNGDefine *xmlRelaxNGDefinePtr; | 84 typedef xmlRelaxNGDefine *xmlRelaxNGDefinePtr; |
84 | 85 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 xmlChar *href; /* the normalized href value */ | 415 xmlChar *href; /* the normalized href value */ |
415 xmlDocPtr doc; /* the associated XML document */ | 416 xmlDocPtr doc; /* the associated XML document */ |
416 xmlRelaxNGDefinePtr content; /* the definitions */ | 417 xmlRelaxNGDefinePtr content; /* the definitions */ |
417 xmlRelaxNGPtr schema; /* the schema */ | 418 xmlRelaxNGPtr schema; /* the schema */ |
418 int externalRef; /* 1 if an external ref */ | 419 int externalRef; /* 1 if an external ref */ |
419 }; | 420 }; |
420 | 421 |
421 | 422 |
422 /************************************************************************ | 423 /************************************************************************ |
423 * * | 424 * * |
424 * » » Some factorized error routines» » » » * | 425 *» » Some factorized error routines» » » » * |
425 * * | 426 * * |
426 ************************************************************************/ | 427 ************************************************************************/ |
427 | 428 |
428 /** | 429 /** |
429 * xmlRngPErrMemory: | 430 * xmlRngPErrMemory: |
430 * @ctxt: an Relax-NG parser context | 431 * @ctxt: an Relax-NG parser context |
431 * @extra: extra informations | 432 * @extra: extra informations |
432 * | 433 * |
433 * Handle a redefinition of attribute error | 434 * Handle a redefinition of attribute error |
434 */ | 435 */ |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 ctxt->nbErrors++; | 558 ctxt->nbErrors++; |
558 } | 559 } |
559 __xmlRaiseError(schannel, channel, data, | 560 __xmlRaiseError(schannel, channel, data, |
560 NULL, node, XML_FROM_RELAXNGV, | 561 NULL, node, XML_FROM_RELAXNGV, |
561 error, XML_ERR_ERROR, NULL, 0, | 562 error, XML_ERR_ERROR, NULL, 0, |
562 (const char *) str1, (const char *) str2, NULL, 0, 0, | 563 (const char *) str1, (const char *) str2, NULL, 0, 0, |
563 msg, str1, str2); | 564 msg, str1, str2); |
564 } | 565 } |
565 | 566 |
566 /************************************************************************ | 567 /************************************************************************ |
567 * » » » » » » » » » * | 568 *» » » » » » » » » * |
568 * » » Preliminary type checking interfaces» » » * | 569 *» » Preliminary type checking interfaces» » » * |
569 * » » » » » » » » » * | 570 *» » » » » » » » » * |
570 ************************************************************************/ | 571 ************************************************************************/ |
571 | 572 |
572 /** | 573 /** |
573 * xmlRelaxNGTypeHave: | 574 * xmlRelaxNGTypeHave: |
574 * @data: data needed for the library | 575 * @data: data needed for the library |
575 * @type: the type name | 576 * @type: the type name |
576 * @value: the value to check | 577 * @value: the value to check |
577 * | 578 * |
578 * Function provided by a type library to check if a type is exported | 579 * Function provided by a type library to check if a type is exported |
579 * | 580 * |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 const xmlChar *namespace; /* the datatypeLibrary value */ | 648 const xmlChar *namespace; /* the datatypeLibrary value */ |
648 void *data; /* data needed for the library */ | 649 void *data; /* data needed for the library */ |
649 xmlRelaxNGTypeHave have; /* the export function */ | 650 xmlRelaxNGTypeHave have; /* the export function */ |
650 xmlRelaxNGTypeCheck check; /* the checking function */ | 651 xmlRelaxNGTypeCheck check; /* the checking function */ |
651 xmlRelaxNGTypeCompare comp; /* the compare function */ | 652 xmlRelaxNGTypeCompare comp; /* the compare function */ |
652 xmlRelaxNGFacetCheck facet; /* the facet check function */ | 653 xmlRelaxNGFacetCheck facet; /* the facet check function */ |
653 xmlRelaxNGTypeFree freef; /* the freeing function */ | 654 xmlRelaxNGTypeFree freef; /* the freeing function */ |
654 }; | 655 }; |
655 | 656 |
656 /************************************************************************ | 657 /************************************************************************ |
657 * » » » » » » » » » * | 658 *» » » » » » » » » * |
658 * » » » Allocation functions» » » » * | 659 *» » » Allocation functions» » » » * |
659 * » » » » » » » » » * | 660 *» » » » » » » » » * |
660 ************************************************************************/ | 661 ************************************************************************/ |
661 static void xmlRelaxNGFreeGrammar(xmlRelaxNGGrammarPtr grammar); | 662 static void xmlRelaxNGFreeGrammar(xmlRelaxNGGrammarPtr grammar); |
662 static void xmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr define); | 663 static void xmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr define); |
663 static void xmlRelaxNGNormExtSpace(xmlChar * value); | 664 static void xmlRelaxNGNormExtSpace(xmlChar * value); |
664 static void xmlRelaxNGFreeInnerSchema(xmlRelaxNGPtr schema); | 665 static void xmlRelaxNGFreeInnerSchema(xmlRelaxNGPtr schema); |
665 static int xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt | 666 static int xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt |
666 ATTRIBUTE_UNUSED, | 667 ATTRIBUTE_UNUSED, |
667 xmlRelaxNGValidStatePtr state1, | 668 xmlRelaxNGValidStatePtr state1, |
668 xmlRelaxNGValidStatePtr state2); | 669 xmlRelaxNGValidStatePtr state2); |
669 static void xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt, | 670 static void xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt, |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 * | 1088 * |
1088 * Return 1 in case of success and 0 if this is a duplicate and -1 on error | 1089 * Return 1 in case of success and 0 if this is a duplicate and -1 on error |
1089 */ | 1090 */ |
1090 static int | 1091 static int |
1091 xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt, | 1092 xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt, |
1092 xmlRelaxNGStatesPtr states, | 1093 xmlRelaxNGStatesPtr states, |
1093 xmlRelaxNGValidStatePtr state) | 1094 xmlRelaxNGValidStatePtr state) |
1094 { | 1095 { |
1095 int i; | 1096 int i; |
1096 | 1097 |
1097 if (state == NULL) { | 1098 if (state == NULL || states == NULL) { |
1098 return (-1); | 1099 return (-1); |
1099 } | 1100 } |
1100 if (states->nbState >= states->maxState) { | 1101 if (states->nbState >= states->maxState) { |
1101 xmlRelaxNGValidStatePtr *tmp; | 1102 xmlRelaxNGValidStatePtr *tmp; |
1102 int size; | 1103 int size; |
1103 | 1104 |
1104 size = states->maxState * 2; | 1105 size = states->maxState * 2; |
1105 tmp = (xmlRelaxNGValidStatePtr *) xmlRealloc(states->tabState, | 1106 tmp = (xmlRelaxNGValidStatePtr *) xmlRealloc(states->tabState, |
1106 (size) * | 1107 (size) * |
1107 sizeof | 1108 sizeof |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 if ((ctxt == NULL) || (ctxt->freeState == NULL)) { | 1391 if ((ctxt == NULL) || (ctxt->freeState == NULL)) { |
1391 if (state->attrs != NULL) | 1392 if (state->attrs != NULL) |
1392 xmlFree(state->attrs); | 1393 xmlFree(state->attrs); |
1393 xmlFree(state); | 1394 xmlFree(state); |
1394 } else { | 1395 } else { |
1395 xmlRelaxNGAddStatesUniq(ctxt, ctxt->freeState, state); | 1396 xmlRelaxNGAddStatesUniq(ctxt, ctxt->freeState, state); |
1396 } | 1397 } |
1397 } | 1398 } |
1398 | 1399 |
1399 /************************************************************************ | 1400 /************************************************************************ |
1400 * » » » » » » » » » * | 1401 *» » » » » » » » » * |
1401 * » » » Semi internal functions»» » » * | 1402 *» » » Semi internal functions»» » » * |
1402 * » » » » » » » » » * | 1403 *» » » » » » » » » * |
1403 ************************************************************************/ | 1404 ************************************************************************/ |
1404 | 1405 |
1405 /** | 1406 /** |
1406 * xmlRelaxParserSetFlag: | 1407 * xmlRelaxParserSetFlag: |
1407 * @ctxt: a RelaxNG parser context | 1408 * @ctxt: a RelaxNG parser context |
1408 * @flags: a set of flags values | 1409 * @flags: a set of flags values |
1409 * | 1410 * |
1410 * Semi private function used to pass informations to a parser context | 1411 * Semi private function used to pass informations to a parser context |
1411 * which are a combination of xmlRelaxNGParserFlag . | 1412 * which are a combination of xmlRelaxNGParserFlag . |
1412 * | 1413 * |
1413 * Returns 0 if success and -1 in case of error | 1414 * Returns 0 if success and -1 in case of error |
1414 */ | 1415 */ |
1415 int | 1416 int |
1416 xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, int flags) | 1417 xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, int flags) |
1417 { | 1418 { |
1418 if (ctxt == NULL) return(-1); | 1419 if (ctxt == NULL) return(-1); |
1419 if (flags & XML_RELAXNGP_FREE_DOC) { | 1420 if (flags & XML_RELAXNGP_FREE_DOC) { |
1420 ctxt->crng |= XML_RELAXNGP_FREE_DOC; | 1421 ctxt->crng |= XML_RELAXNGP_FREE_DOC; |
1421 flags -= XML_RELAXNGP_FREE_DOC; | 1422 flags -= XML_RELAXNGP_FREE_DOC; |
1422 } | 1423 } |
1423 if (flags & XML_RELAXNGP_CRNG) { | 1424 if (flags & XML_RELAXNGP_CRNG) { |
1424 ctxt->crng |= XML_RELAXNGP_CRNG; | 1425 ctxt->crng |= XML_RELAXNGP_CRNG; |
1425 flags -= XML_RELAXNGP_CRNG; | 1426 flags -= XML_RELAXNGP_CRNG; |
1426 } | 1427 } |
1427 if (flags != 0) return(-1); | 1428 if (flags != 0) return(-1); |
1428 return(0); | 1429 return(0); |
1429 } | 1430 } |
1430 | 1431 |
1431 /************************************************************************ | 1432 /************************************************************************ |
1432 * » » » » » » » » » * | 1433 *» » » » » » » » » * |
1433 * » » » Document functions» » » » * | 1434 *» » » Document functions» » » » * |
1434 * » » » » » » » » » * | 1435 *» » » » » » » » » * |
1435 ************************************************************************/ | 1436 ************************************************************************/ |
1436 static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, | 1437 static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, |
1437 xmlDocPtr doc); | 1438 xmlDocPtr doc); |
1438 | 1439 |
1439 /** | 1440 /** |
1440 * xmlRelaxNGIncludePush: | 1441 * xmlRelaxNGIncludePush: |
1441 * @ctxt: the parser context | 1442 * @ctxt: the parser context |
1442 * @value: the element doc | 1443 * @value: the element doc |
1443 * | 1444 * |
1444 * Pushes a new include on top of the include stack | 1445 * Pushes a new include on top of the include stack |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 | 1555 |
1555 if ((inc != NULL) && (inc->doc != NULL) && | 1556 if ((inc != NULL) && (inc->doc != NULL) && |
1556 (inc->doc->children != NULL)) { | 1557 (inc->doc->children != NULL)) { |
1557 | 1558 |
1558 if (xmlStrEqual | 1559 if (xmlStrEqual |
1559 (inc->doc->children->name, BAD_CAST "grammar")) { | 1560 (inc->doc->children->name, BAD_CAST "grammar")) { |
1560 #ifdef DEBUG_INCLUDE | 1561 #ifdef DEBUG_INCLUDE |
1561 href = xmlGetProp(tmp, BAD_CAST "href"); | 1562 href = xmlGetProp(tmp, BAD_CAST "href"); |
1562 #endif | 1563 #endif |
1563 if (xmlRelaxNGRemoveRedefine(ctxt, href, | 1564 if (xmlRelaxNGRemoveRedefine(ctxt, href, |
1564 inc->doc->children-> | 1565 xmlDocGetRootElement(inc->doc)-
>children, |
1565 children, name) == 1) { | 1566 name) == 1) { |
1566 found = 1; | 1567 found = 1; |
1567 } | 1568 } |
1568 #ifdef DEBUG_INCLUDE | 1569 #ifdef DEBUG_INCLUDE |
1569 if (href != NULL) | 1570 if (href != NULL) |
1570 xmlFree(href); | 1571 xmlFree(href); |
1571 #endif | 1572 #endif |
1572 } | 1573 } |
1573 } | 1574 } |
1574 } | 1575 } |
1575 tmp = tmp2; | 1576 tmp = tmp2; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2000 ctxt->doc = NULL; | 2001 ctxt->doc = NULL; |
2001 return (NULL); | 2002 return (NULL); |
2002 } | 2003 } |
2003 | 2004 |
2004 xmlRelaxNGDocumentPop(ctxt); | 2005 xmlRelaxNGDocumentPop(ctxt); |
2005 | 2006 |
2006 return (ret); | 2007 return (ret); |
2007 } | 2008 } |
2008 | 2009 |
2009 /************************************************************************ | 2010 /************************************************************************ |
2010 * » » » » » » » » » * | 2011 *» » » » » » » » » * |
2011 * » » » Error functions»» » » » * | 2012 *» » » Error functions»» » » » * |
2012 * » » » » » » » » » * | 2013 *» » » » » » » » » * |
2013 ************************************************************************/ | 2014 ************************************************************************/ |
2014 | 2015 |
2015 #define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0); | 2016 #define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0); |
2016 #define VALID_ERR2(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 0); | 2017 #define VALID_ERR2(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 0); |
2017 #define VALID_ERR3(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 0); | 2018 #define VALID_ERR3(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 0); |
2018 #define VALID_ERR2P(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 1); | 2019 #define VALID_ERR2P(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 1); |
2019 #define VALID_ERR3P(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 1); | 2020 #define VALID_ERR3P(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 1); |
2020 | 2021 |
2021 static const char * | 2022 static const char * |
2022 xmlRelaxNGDefName(xmlRelaxNGDefinePtr def) | 2023 xmlRelaxNGDefName(xmlRelaxNGDefinePtr def) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 if (ctxt->flags & FLAGS_NOERROR) | 2354 if (ctxt->flags & FLAGS_NOERROR) |
2354 return; | 2355 return; |
2355 | 2356 |
2356 #ifdef DEBUG_ERROR | 2357 #ifdef DEBUG_ERROR |
2357 xmlGenericError(xmlGenericErrorContext, "Adding error %d\n", err); | 2358 xmlGenericError(xmlGenericErrorContext, "Adding error %d\n", err); |
2358 #endif | 2359 #endif |
2359 /* | 2360 /* |
2360 * generate the error directly | 2361 * generate the error directly |
2361 */ | 2362 */ |
2362 if (((ctxt->flags & FLAGS_IGNORABLE) == 0) || | 2363 if (((ctxt->flags & FLAGS_IGNORABLE) == 0) || |
2363 » (ctxt->flags & FLAGS_NEGATIVE)) { | 2364 » (ctxt->flags & FLAGS_NEGATIVE)) { |
2364 xmlNodePtr node, seq; | 2365 xmlNodePtr node, seq; |
2365 | 2366 |
2366 /* | 2367 /* |
2367 * Flush first any stacked error which might be the | 2368 * Flush first any stacked error which might be the |
2368 * real cause of the problem. | 2369 * real cause of the problem. |
2369 */ | 2370 */ |
2370 if (ctxt->errNr != 0) | 2371 if (ctxt->errNr != 0) |
2371 xmlRelaxNGDumpValidError(ctxt); | 2372 xmlRelaxNGDumpValidError(ctxt); |
2372 if (ctxt->state != NULL) { | 2373 if (ctxt->state != NULL) { |
2373 node = ctxt->state->node; | 2374 node = ctxt->state->node; |
2374 seq = ctxt->state->seq; | 2375 seq = ctxt->state->seq; |
2375 } else { | 2376 } else { |
2376 node = seq = NULL; | 2377 node = seq = NULL; |
2377 } | 2378 } |
2378 if ((node == NULL) && (seq == NULL)) { | 2379 if ((node == NULL) && (seq == NULL)) { |
2379 node = ctxt->pnode; | 2380 node = ctxt->pnode; |
2380 } | 2381 } |
2381 xmlRelaxNGShowValidError(ctxt, err, node, seq, arg1, arg2); | 2382 xmlRelaxNGShowValidError(ctxt, err, node, seq, arg1, arg2); |
2382 } | 2383 } |
2383 /* | 2384 /* |
2384 * Stack the error for later processing if needed | 2385 * Stack the error for later processing if needed |
2385 */ | 2386 */ |
2386 else { | 2387 else { |
2387 xmlRelaxNGValidErrorPush(ctxt, err, arg1, arg2, dup); | 2388 xmlRelaxNGValidErrorPush(ctxt, err, arg1, arg2, dup); |
2388 } | 2389 } |
2389 } | 2390 } |
2390 | 2391 |
2391 | 2392 |
2392 /************************************************************************ | 2393 /************************************************************************ |
2393 * » » » » » » » » » * | 2394 *» » » » » » » » » * |
2394 * » » » Type library hooks» » » » * | 2395 *» » » Type library hooks» » » » * |
2395 * » » » » » » » » » * | 2396 *» » » » » » » » » * |
2396 ************************************************************************/ | 2397 ************************************************************************/ |
2397 static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, | 2398 static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, |
2398 const xmlChar * str); | 2399 const xmlChar * str); |
2399 | 2400 |
2400 /** | 2401 /** |
2401 * xmlRelaxNGSchemaTypeHave: | 2402 * xmlRelaxNGSchemaTypeHave: |
2402 * @data: data needed for the library | 2403 * @data: data needed for the library |
2403 * @type: the type name | 2404 * @type: the type name |
2404 * | 2405 * |
2405 * Check if the given type is provided by | 2406 * Check if the given type is provided by |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 ret = xmlSchemaValPredefTypeNode(typ, value1, &res1, ctxt1); | 2588 ret = xmlSchemaValPredefTypeNode(typ, value1, &res1, ctxt1); |
2588 if (ret != 0) | 2589 if (ret != 0) |
2589 return (-1); | 2590 return (-1); |
2590 if (res1 == NULL) | 2591 if (res1 == NULL) |
2591 return (-1); | 2592 return (-1); |
2592 } else { | 2593 } else { |
2593 res1 = (xmlSchemaValPtr) comp1; | 2594 res1 = (xmlSchemaValPtr) comp1; |
2594 } | 2595 } |
2595 ret = xmlSchemaValPredefTypeNode(typ, value2, &res2, ctxt2); | 2596 ret = xmlSchemaValPredefTypeNode(typ, value2, &res2, ctxt2); |
2596 if (ret != 0) { | 2597 if (ret != 0) { |
2597 » if ((comp1 == NULL) && (res1 != NULL)) | 2598 » if (res1 != (xmlSchemaValPtr) comp1) |
2598 xmlSchemaFreeValue(res1); | 2599 xmlSchemaFreeValue(res1); |
2599 return (-1); | 2600 return (-1); |
2600 } | 2601 } |
2601 if (res1 == NULL) { | |
2602 return (-1); | |
2603 } | |
2604 ret = xmlSchemaCompareValues(res1, res2); | 2602 ret = xmlSchemaCompareValues(res1, res2); |
2605 if (res1 != (xmlSchemaValPtr) comp1) | 2603 if (res1 != (xmlSchemaValPtr) comp1) |
2606 xmlSchemaFreeValue(res1); | 2604 xmlSchemaFreeValue(res1); |
2607 xmlSchemaFreeValue(res2); | 2605 xmlSchemaFreeValue(res2); |
2608 if (ret == -2) | 2606 if (ret == -2) |
2609 return (-1); | 2607 return (-1); |
2610 if (ret == 0) | 2608 if (ret == 0) |
2611 return (1); | 2609 return (1); |
2612 return (0); | 2610 return (0); |
2613 } | 2611 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2840 { | 2838 { |
2841 xmlSchemaCleanupTypes(); | 2839 xmlSchemaCleanupTypes(); |
2842 if (xmlRelaxNGTypeInitialized == 0) | 2840 if (xmlRelaxNGTypeInitialized == 0) |
2843 return; | 2841 return; |
2844 xmlHashFree(xmlRelaxNGRegisteredTypes, (xmlHashDeallocator) | 2842 xmlHashFree(xmlRelaxNGRegisteredTypes, (xmlHashDeallocator) |
2845 xmlRelaxNGFreeTypeLibrary); | 2843 xmlRelaxNGFreeTypeLibrary); |
2846 xmlRelaxNGTypeInitialized = 0; | 2844 xmlRelaxNGTypeInitialized = 0; |
2847 } | 2845 } |
2848 | 2846 |
2849 /************************************************************************ | 2847 /************************************************************************ |
2850 * » » » » » » » » » * | 2848 *» » » » » » » » » * |
2851 * » » Compiling element content into regexp» » » * | 2849 *» » Compiling element content into regexp» » » * |
2852 * » » » » » » » » » * | 2850 *» » » » » » » » » * |
2853 * Sometime the element content can be compiled into a pure regexp, * | 2851 * Sometime the element content can be compiled into a pure regexp, * |
2854 * This allows a faster execution and streamability at that level * | 2852 * This allows a faster execution and streamability at that level * |
2855 * » » » » » » » » » * | 2853 *» » » » » » » » » * |
2856 ************************************************************************/ | 2854 ************************************************************************/ |
2857 | 2855 |
2858 /* from automata.c but not exported */ | 2856 /* from automata.c but not exported */ |
2859 void xmlAutomataSetFlags(xmlAutomataPtr am, int flags); | 2857 void xmlAutomataSetFlags(xmlAutomataPtr am, int flags); |
2860 | 2858 |
2861 | 2859 |
2862 static int xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, | 2860 static int xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, |
2863 xmlRelaxNGDefinePtr def); | 2861 xmlRelaxNGDefinePtr def); |
2864 | 2862 |
2865 /** | 2863 /** |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3052 * thing of exploring both choices. | 3050 * thing of exploring both choices. |
3053 */ | 3051 */ |
3054 xmlAutomataSetFlags(ctxt->am, 1); | 3052 xmlAutomataSetFlags(ctxt->am, 1); |
3055 | 3053 |
3056 ctxt->state = xmlAutomataGetInitState(ctxt->am); | 3054 ctxt->state = xmlAutomataGetInitState(ctxt->am); |
3057 while (list != NULL) { | 3055 while (list != NULL) { |
3058 xmlRelaxNGCompile(ctxt, list); | 3056 xmlRelaxNGCompile(ctxt, list); |
3059 list = list->next; | 3057 list = list->next; |
3060 } | 3058 } |
3061 xmlAutomataSetFinalState(ctxt->am, ctxt->state); | 3059 xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
3062 def->contModel = xmlAutomataCompile(ctxt->am); | 3060 if (xmlAutomataIsDeterminist(ctxt->am)) |
3063 xmlRegexpIsDeterminist(def->contModel); | 3061 def->contModel = xmlAutomataCompile(ctxt->am); |
3064 | 3062 |
3065 xmlFreeAutomata(ctxt->am); | 3063 xmlFreeAutomata(ctxt->am); |
3066 ctxt->state = oldstate; | 3064 ctxt->state = oldstate; |
3067 ctxt->am = oldam; | 3065 ctxt->am = oldam; |
3068 } | 3066 } |
3069 break; | 3067 break; |
3070 case XML_RELAXNG_ELEMENT: | 3068 case XML_RELAXNG_ELEMENT: |
3071 if ((ctxt->am != NULL) && (def->name != NULL)) { | 3069 if ((ctxt->am != NULL) && (def->name != NULL)) { |
3072 ctxt->state = xmlAutomataNewTransition2(ctxt->am, | 3070 ctxt->state = xmlAutomataNewTransition2(ctxt->am, |
3073 ctxt->state, NULL, | 3071 ctxt->state, NULL, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3318 case XML_RELAXNG_ATTRIBUTE: | 3316 case XML_RELAXNG_ATTRIBUTE: |
3319 case XML_RELAXNG_INTERLEAVE: | 3317 case XML_RELAXNG_INTERLEAVE: |
3320 case XML_RELAXNG_NOT_ALLOWED: | 3318 case XML_RELAXNG_NOT_ALLOWED: |
3321 ret = 0; | 3319 ret = 0; |
3322 break; | 3320 break; |
3323 } | 3321 } |
3324 return (ret); | 3322 return (ret); |
3325 } | 3323 } |
3326 | 3324 |
3327 /************************************************************************ | 3325 /************************************************************************ |
3328 * » » » » » » » » » * | 3326 *» » » » » » » » » * |
3329 * » » » Parsing functions» » » » * | 3327 *» » » Parsing functions» » » » * |
3330 * » » » » » » » » » * | 3328 *» » » » » » » » » * |
3331 ************************************************************************/ | 3329 ************************************************************************/ |
3332 | 3330 |
3333 static xmlRelaxNGDefinePtr xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr | 3331 static xmlRelaxNGDefinePtr xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr |
3334 ctxt, xmlNodePtr node); | 3332 ctxt, xmlNodePtr node); |
3335 static xmlRelaxNGDefinePtr xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr | 3333 static xmlRelaxNGDefinePtr xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr |
3336 ctxt, xmlNodePtr node); | 3334 ctxt, xmlNodePtr node); |
3337 static xmlRelaxNGDefinePtr xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr | 3335 static xmlRelaxNGDefinePtr xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr |
3338 ctxt, xmlNodePtr nodes, | 3336 ctxt, xmlNodePtr nodes, |
3339 int group); | 3337 int group); |
3340 static xmlRelaxNGDefinePtr xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr | 3338 static xmlRelaxNGDefinePtr xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3814 ret = 0; | 3812 ret = 0; |
3815 } | 3813 } |
3816 } else { | 3814 } else { |
3817 ret = 1; | 3815 ret = 1; |
3818 } | 3816 } |
3819 } else if (def1->type == XML_RELAXNG_TEXT) { | 3817 } else if (def1->type == XML_RELAXNG_TEXT) { |
3820 if (def2->type == XML_RELAXNG_TEXT) | 3818 if (def2->type == XML_RELAXNG_TEXT) |
3821 return (0); | 3819 return (0); |
3822 return (1); | 3820 return (1); |
3823 } else if (def1->type == XML_RELAXNG_EXCEPT) { | 3821 } else if (def1->type == XML_RELAXNG_EXCEPT) { |
3824 TODO ret = 0; | 3822 ret = xmlRelaxNGCompareNameClasses(def1->content, def2); |
| 3823 » if (ret == 0) |
| 3824 » ret = 1; |
| 3825 » else if (ret == 1) |
| 3826 » ret = 0; |
3825 } else { | 3827 } else { |
3826 TODO ret = 0; | 3828 TODO ret = 0; |
3827 } | 3829 } |
3828 if (ret == 0) | 3830 if (ret == 0) |
3829 return (ret); | 3831 return (ret); |
3830 if ((def2->type == XML_RELAXNG_ELEMENT) || | 3832 if ((def2->type == XML_RELAXNG_ELEMENT) || |
3831 (def2->type == XML_RELAXNG_ATTRIBUTE)) { | 3833 (def2->type == XML_RELAXNG_ATTRIBUTE)) { |
3832 if (def2->name != NULL) { | 3834 if (def2->name != NULL) { |
3833 node.name = def2->name; | 3835 node.name = def2->name; |
3834 } else { | 3836 } else { |
(...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6595 ctxt->grammar = ret; | 6597 ctxt->grammar = ret; |
6596 if (ctxt->grammar == NULL) { | 6598 if (ctxt->grammar == NULL) { |
6597 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT, | 6599 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT, |
6598 "Failed to parse <grammar> content\n", NULL, NULL); | 6600 "Failed to parse <grammar> content\n", NULL, NULL); |
6599 } else if (ctxt->grammar->start == NULL) { | 6601 } else if (ctxt->grammar->start == NULL) { |
6600 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START, | 6602 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START, |
6601 "Element <grammar> has no <start>\n", NULL, NULL); | 6603 "Element <grammar> has no <start>\n", NULL, NULL); |
6602 } | 6604 } |
6603 | 6605 |
6604 /* | 6606 /* |
6605 * Apply 4.17 mergingd rules to defines and starts | 6607 * Apply 4.17 merging rules to defines and starts |
6606 */ | 6608 */ |
6607 xmlRelaxNGCombineStart(ctxt, ret); | 6609 xmlRelaxNGCombineStart(ctxt, ret); |
6608 if (ret->defs != NULL) { | 6610 if (ret->defs != NULL) { |
6609 xmlHashScan(ret->defs, (xmlHashScanner) xmlRelaxNGCheckCombine, | 6611 xmlHashScan(ret->defs, (xmlHashScanner) xmlRelaxNGCheckCombine, |
6610 ctxt); | 6612 ctxt); |
6611 } | 6613 } |
6612 | 6614 |
6613 /* | 6615 /* |
6614 * link together defines and refs in this grammar | 6616 * link together defines and refs in this grammar |
6615 */ | 6617 */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6647 return (NULL); | 6649 return (NULL); |
6648 | 6650 |
6649 schema = xmlRelaxNGNewRelaxNG(ctxt); | 6651 schema = xmlRelaxNGNewRelaxNG(ctxt); |
6650 if (schema == NULL) | 6652 if (schema == NULL) |
6651 return (NULL); | 6653 return (NULL); |
6652 | 6654 |
6653 olddefine = ctxt->define; | 6655 olddefine = ctxt->define; |
6654 ctxt->define = NULL; | 6656 ctxt->define = NULL; |
6655 if (IS_RELAXNG(node, "grammar")) { | 6657 if (IS_RELAXNG(node, "grammar")) { |
6656 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children); | 6658 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children); |
| 6659 if (schema->topgrammar == NULL) { |
| 6660 xmlRelaxNGFree(schema); |
| 6661 return (NULL); |
| 6662 } |
6657 } else { | 6663 } else { |
6658 xmlRelaxNGGrammarPtr tmp, ret; | 6664 xmlRelaxNGGrammarPtr tmp, ret; |
6659 | 6665 |
6660 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt); | 6666 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt); |
6661 if (schema->topgrammar == NULL) { | 6667 if (schema->topgrammar == NULL) { |
6662 return (schema); | 6668 xmlRelaxNGFree(schema); |
| 6669 return (NULL); |
6663 } | 6670 } |
6664 /* | 6671 /* |
6665 * Link the new grammar in the tree | 6672 * Link the new grammar in the tree |
6666 */ | 6673 */ |
6667 ret->parent = ctxt->grammar; | 6674 ret->parent = ctxt->grammar; |
6668 if (ctxt->grammar != NULL) { | 6675 if (ctxt->grammar != NULL) { |
6669 tmp = ctxt->grammar->children; | 6676 tmp = ctxt->grammar->children; |
6670 if (tmp == NULL) { | 6677 if (tmp == NULL) { |
6671 ctxt->grammar->children = ret; | 6678 ctxt->grammar->children = ret; |
6672 } else { | 6679 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
6698 #ifdef DEBUG | 6705 #ifdef DEBUG |
6699 if (schema == NULL) | 6706 if (schema == NULL) |
6700 xmlGenericError(xmlGenericErrorContext, | 6707 xmlGenericError(xmlGenericErrorContext, |
6701 "xmlRelaxNGParseDocument() failed\n"); | 6708 "xmlRelaxNGParseDocument() failed\n"); |
6702 #endif | 6709 #endif |
6703 | 6710 |
6704 return (schema); | 6711 return (schema); |
6705 } | 6712 } |
6706 | 6713 |
6707 /************************************************************************ | 6714 /************************************************************************ |
6708 * » » » » » » » » » * | 6715 *» » » » » » » » » * |
6709 * » » » Reading RelaxNGs» » » » * | 6716 *» » » Reading RelaxNGs» » » » * |
6710 * » » » » » » » » » * | 6717 *» » » » » » » » » * |
6711 ************************************************************************/ | 6718 ************************************************************************/ |
6712 | 6719 |
6713 /** | 6720 /** |
6714 * xmlRelaxNGNewParserCtxt: | 6721 * xmlRelaxNGNewParserCtxt: |
6715 * @URL: the location of the schema | 6722 * @URL: the location of the schema |
6716 * | 6723 * |
6717 * Create an XML RelaxNGs parse context for that file/resource expected | 6724 * Create an XML RelaxNGs parse context for that file/resource expected |
6718 * to contain an XML RelaxNGs file. | 6725 * to contain an XML RelaxNGs file. |
6719 * | 6726 * |
6720 * Returns the parser context or NULL in case of error | 6727 * Returns the parser context or NULL in case of error |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7309 "Found anyName/except//anyName forbidden cons
truct\n", | 7316 "Found anyName/except//anyName forbidden cons
truct\n", |
7310 NULL, NULL); | 7317 NULL, NULL); |
7311 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) { | 7318 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) { |
7312 xmlRngPErr(ctxt, cur, | 7319 xmlRngPErr(ctxt, cur, |
7313 XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME, | 7320 XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME, |
7314 "Found nsName/except//anyName forbidden const
ruct\n", | 7321 "Found nsName/except//anyName forbidden const
ruct\n", |
7315 NULL, NULL); | 7322 NULL, NULL); |
7316 } | 7323 } |
7317 } | 7324 } |
7318 /* | 7325 /* |
7319 * Thisd is not an else since "include" is transformed | 7326 * This is not an else since "include" is transformed |
7320 * into a div | 7327 * into a div |
7321 */ | 7328 */ |
7322 if (xmlStrEqual(cur->name, BAD_CAST "div")) { | 7329 if (xmlStrEqual(cur->name, BAD_CAST "div")) { |
7323 xmlChar *ns; | 7330 xmlChar *ns; |
7324 xmlNodePtr child, ins, tmp; | 7331 xmlNodePtr child, ins, tmp; |
7325 | 7332 |
7326 /* | 7333 /* |
7327 * implements rule 4.11 | 7334 * implements rule 4.11 |
7328 */ | 7335 */ |
7329 | 7336 |
7330 ns = xmlGetProp(cur, BAD_CAST "ns"); | 7337 ns = xmlGetProp(cur, BAD_CAST "ns"); |
7331 | 7338 |
7332 child = cur->children; | 7339 child = cur->children; |
7333 ins = cur; | 7340 ins = cur; |
7334 while (child != NULL) { | 7341 while (child != NULL) { |
7335 if (ns != NULL) { | 7342 if (ns != NULL) { |
7336 if (!xmlHasProp(child, BAD_CAST "ns")) { | 7343 if (!xmlHasProp(child, BAD_CAST "ns")) { |
7337 xmlSetProp(child, BAD_CAST "ns", ns); | 7344 xmlSetProp(child, BAD_CAST "ns", ns); |
7338 } | 7345 } |
7339 } | 7346 } |
7340 tmp = child->next; | 7347 tmp = child->next; |
7341 xmlUnlinkNode(child); | 7348 xmlUnlinkNode(child); |
7342 ins = xmlAddNextSibling(ins, child); | 7349 ins = xmlAddNextSibling(ins, child); |
7343 child = tmp; | 7350 child = tmp; |
7344 } | 7351 } |
7345 if (ns != NULL) | 7352 if (ns != NULL) |
7346 xmlFree(ns); | 7353 xmlFree(ns); |
7347 /* | 7354 /* |
7348 » » * Since we are about to delete cur, if it's nsDef is non-NU
LL we | 7355 » » * Since we are about to delete cur, if its nsDef is non-NUL
L we |
7349 * need to preserve it (it contains the ns definitions for t
he | 7356 * need to preserve it (it contains the ns definitions for t
he |
7350 * children we just moved). We'll just stick it on to the e
nd | 7357 * children we just moved). We'll just stick it on to the e
nd |
7351 * of cur->parent's list, since it's never going to be re-se
rialized | 7358 * of cur->parent's list, since it's never going to be re-se
rialized |
7352 * (bug 143738). | 7359 * (bug 143738). |
7353 */ | 7360 */ |
7354 » » if (cur->nsDef != NULL) { | 7361 » » if ((cur->nsDef != NULL) && (cur->parent != NULL)) { |
7355 xmlNsPtr parDef = (xmlNsPtr)&cur->parent->nsDef; | 7362 xmlNsPtr parDef = (xmlNsPtr)&cur->parent->nsDef; |
7356 while (parDef->next != NULL) | 7363 while (parDef->next != NULL) |
7357 parDef = parDef->next; | 7364 parDef = parDef->next; |
7358 parDef->next = cur->nsDef; | 7365 parDef->next = cur->nsDef; |
7359 cur->nsDef = NULL; | 7366 cur->nsDef = NULL; |
7360 } | 7367 } |
7361 delete = cur; | 7368 delete = cur; |
7362 goto skip_children; | 7369 goto skip_children; |
7363 } | 7370 } |
7364 } | 7371 } |
7365 } | 7372 } |
7366 /* | 7373 /* |
7367 * Simplification 4.2 whitespaces | 7374 * Simplification 4.2 whitespaces |
7368 */ | 7375 */ |
7369 else if ((cur->type == XML_TEXT_NODE) || | 7376 else if ((cur->type == XML_TEXT_NODE) || |
7370 (cur->type == XML_CDATA_SECTION_NODE)) { | 7377 (cur->type == XML_CDATA_SECTION_NODE)) { |
7371 if (IS_BLANK_NODE(cur)) { | 7378 if (IS_BLANK_NODE(cur)) { |
7372 if (cur->parent->type == XML_ELEMENT_NODE) { | 7379 if ((cur->parent != NULL) && |
| 7380 » » (cur->parent->type == XML_ELEMENT_NODE)) { |
7373 if ((!xmlStrEqual(cur->parent->name, BAD_CAST "value")) | 7381 if ((!xmlStrEqual(cur->parent->name, BAD_CAST "value")) |
7374 && | 7382 && |
7375 (!xmlStrEqual | 7383 (!xmlStrEqual |
7376 (cur->parent->name, BAD_CAST "param"))) | 7384 (cur->parent->name, BAD_CAST "param"))) |
7377 delete = cur; | 7385 delete = cur; |
7378 } else { | 7386 } else { |
7379 delete = cur; | 7387 delete = cur; |
7380 goto skip_children; | 7388 goto skip_children; |
7381 } | 7389 } |
7382 } | 7390 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7514 } | 7522 } |
7515 | 7523 |
7516 /* | 7524 /* |
7517 * Then do the parsing for good | 7525 * Then do the parsing for good |
7518 */ | 7526 */ |
7519 root = xmlDocGetRootElement(doc); | 7527 root = xmlDocGetRootElement(doc); |
7520 if (root == NULL) { | 7528 if (root == NULL) { |
7521 xmlRngPErr(ctxt, (xmlNodePtr) doc, | 7529 xmlRngPErr(ctxt, (xmlNodePtr) doc, |
7522 XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", | 7530 XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", |
7523 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); | 7531 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); |
7524 » | 7532 |
7525 xmlFreeDoc(ctxt->document); | 7533 xmlFreeDoc(ctxt->document); |
7526 ctxt->document = NULL; | 7534 ctxt->document = NULL; |
7527 return (NULL); | 7535 return (NULL); |
7528 } | 7536 } |
7529 ret = xmlRelaxNGParseDocument(ctxt, root); | 7537 ret = xmlRelaxNGParseDocument(ctxt, root); |
7530 if (ret == NULL) { | 7538 if (ret == NULL) { |
7531 xmlFreeDoc(ctxt->document); | 7539 xmlFreeDoc(ctxt->document); |
7532 ctxt->document = NULL; | 7540 ctxt->document = NULL; |
7533 return (NULL); | 7541 return (NULL); |
7534 } | 7542 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7656 return; | 7664 return; |
7657 ctxt->serror = serror; | 7665 ctxt->serror = serror; |
7658 ctxt->error = NULL; | 7666 ctxt->error = NULL; |
7659 ctxt->warning = NULL; | 7667 ctxt->warning = NULL; |
7660 ctxt->userData = ctx; | 7668 ctxt->userData = ctx; |
7661 } | 7669 } |
7662 | 7670 |
7663 #ifdef LIBXML_OUTPUT_ENABLED | 7671 #ifdef LIBXML_OUTPUT_ENABLED |
7664 | 7672 |
7665 /************************************************************************ | 7673 /************************************************************************ |
7666 * » » » » » » » » » * | 7674 *» » » » » » » » » * |
7667 * » » » Dump back a compiled form» » » * | 7675 *» » » Dump back a compiled form» » » * |
7668 * » » » » » » » » » * | 7676 *» » » » » » » » » * |
7669 ************************************************************************/ | 7677 ************************************************************************/ |
7670 static void xmlRelaxNGDumpDefine(FILE * output, | 7678 static void xmlRelaxNGDumpDefine(FILE * output, |
7671 xmlRelaxNGDefinePtr define); | 7679 xmlRelaxNGDefinePtr define); |
7672 | 7680 |
7673 /** | 7681 /** |
7674 * xmlRelaxNGDumpDefines: | 7682 * xmlRelaxNGDumpDefines: |
7675 * @output: the file output | 7683 * @output: the file output |
7676 * @defines: a list of define structures | 7684 * @defines: a list of define structures |
7677 * | 7685 * |
7678 * Dump a RelaxNG structure back | 7686 * Dump a RelaxNG structure back |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7799 case XML_RELAXNG_NOOP: | 7807 case XML_RELAXNG_NOOP: |
7800 xmlRelaxNGDumpDefines(output, define->content); | 7808 xmlRelaxNGDumpDefines(output, define->content); |
7801 break; | 7809 break; |
7802 } | 7810 } |
7803 } | 7811 } |
7804 | 7812 |
7805 /** | 7813 /** |
7806 * xmlRelaxNGDumpGrammar: | 7814 * xmlRelaxNGDumpGrammar: |
7807 * @output: the file output | 7815 * @output: the file output |
7808 * @grammar: a grammar structure | 7816 * @grammar: a grammar structure |
7809 * @top: is this a top grammar | 7817 * @top: is this a top grammar |
7810 * | 7818 * |
7811 * Dump a RelaxNG structure back | 7819 * Dump a RelaxNG structure back |
7812 */ | 7820 */ |
7813 static void | 7821 static void |
7814 xmlRelaxNGDumpGrammar(FILE * output, xmlRelaxNGGrammarPtr grammar, int top) | 7822 xmlRelaxNGDumpGrammar(FILE * output, xmlRelaxNGGrammarPtr grammar, int top) |
7815 { | 7823 { |
7816 if (grammar == NULL) | 7824 if (grammar == NULL) |
7817 return; | 7825 return; |
7818 | 7826 |
7819 fprintf(output, "<grammar"); | 7827 fprintf(output, "<grammar"); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7892 } | 7900 } |
7893 if (schema->doc == NULL) { | 7901 if (schema->doc == NULL) { |
7894 fprintf(output, "no document\n"); | 7902 fprintf(output, "no document\n"); |
7895 } else { | 7903 } else { |
7896 xmlDocDump(output, schema->doc); | 7904 xmlDocDump(output, schema->doc); |
7897 } | 7905 } |
7898 } | 7906 } |
7899 #endif /* LIBXML_OUTPUT_ENABLED */ | 7907 #endif /* LIBXML_OUTPUT_ENABLED */ |
7900 | 7908 |
7901 /************************************************************************ | 7909 /************************************************************************ |
7902 * » » » » » » » » » * | 7910 *» » » » » » » » » * |
7903 * » » Validation of compiled content» » » » * | 7911 *» » Validation of compiled content» » » » * |
7904 * » » » » » » » » » * | 7912 *» » » » » » » » » * |
7905 ************************************************************************/ | 7913 ************************************************************************/ |
7906 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, | 7914 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, |
7907 xmlRelaxNGDefinePtr define); | 7915 xmlRelaxNGDefinePtr define); |
7908 | 7916 |
7909 /** | 7917 /** |
7910 * xmlRelaxNGValidateCompiledCallback: | 7918 * xmlRelaxNGValidateCompiledCallback: |
7911 * @exec: the regular expression instance | 7919 * @exec: the regular expression instance |
7912 * @token: the token which matched | 7920 * @token: the token which matched |
7913 * @transdata: callback data, the define for the subelement if available | 7921 * @transdata: callback data, the define for the subelement if available |
7914 @ @inputdata: callback data, the Relax NG validation context | 7922 @ @inputdata: callback data, the Relax NG validation context |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8037 * regexp validation, e.g. for attribute values. | 8045 * regexp validation, e.g. for attribute values. |
8038 */ | 8046 */ |
8039 if ((ret == 0) && (ctxt->perr != 0)) { | 8047 if ((ret == 0) && (ctxt->perr != 0)) { |
8040 ret = ctxt->perr; | 8048 ret = ctxt->perr; |
8041 } | 8049 } |
8042 ctxt->perr = oldperr; | 8050 ctxt->perr = oldperr; |
8043 return (ret); | 8051 return (ret); |
8044 } | 8052 } |
8045 | 8053 |
8046 /************************************************************************ | 8054 /************************************************************************ |
8047 * » » » » » » » » » * | 8055 *» » » » » » » » » * |
8048 * » » Progressive validation of when possible»» » * | 8056 *» » Progressive validation of when possible»» » * |
8049 * » » » » » » » » » * | 8057 *» » » » » » » » » * |
8050 ************************************************************************/ | 8058 ************************************************************************/ |
8051 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, | 8059 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, |
8052 xmlRelaxNGDefinePtr defines); | 8060 xmlRelaxNGDefinePtr defines); |
8053 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, | 8061 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, |
8054 int dolog); | 8062 int dolog); |
8055 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt); | 8063 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt); |
8056 | 8064 |
8057 /** | 8065 /** |
8058 * xmlRelaxNGElemPush: | 8066 * xmlRelaxNGElemPush: |
8059 * @ctxt: the validation context | 8067 * @ctxt: the validation context |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8339 xmlGenericError(xmlGenericErrorContext, "PushElem %s failed\n", | 8347 xmlGenericError(xmlGenericErrorContext, "PushElem %s failed\n", |
8340 elem->name); | 8348 elem->name); |
8341 #endif | 8349 #endif |
8342 return (ret); | 8350 return (ret); |
8343 } | 8351 } |
8344 | 8352 |
8345 /** | 8353 /** |
8346 * xmlRelaxNGValidatePushCData: | 8354 * xmlRelaxNGValidatePushCData: |
8347 * @ctxt: the RelaxNG validation context | 8355 * @ctxt: the RelaxNG validation context |
8348 * @data: some character data read | 8356 * @data: some character data read |
8349 * @len: the lenght of the data | 8357 * @len: the length of the data |
8350 * | 8358 * |
8351 * check the CData parsed for validation in the current stack | 8359 * check the CData parsed for validation in the current stack |
8352 * | 8360 * |
8353 * returns 1 if no validation problem was found or -1 otherwise | 8361 * returns 1 if no validation problem was found or -1 otherwise |
8354 */ | 8362 */ |
8355 int | 8363 int |
8356 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, | 8364 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, |
8357 const xmlChar * data, int len ATTRIBUTE_UNUSED) | 8365 const xmlChar * data, int len ATTRIBUTE_UNUSED) |
8358 { | 8366 { |
8359 int ret = 1; | 8367 int ret = 1; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8473 ctxt->state = NULL; | 8481 ctxt->state = NULL; |
8474 #ifdef DEBUG_PROGRESSIVE | 8482 #ifdef DEBUG_PROGRESSIVE |
8475 if (ret < 0) | 8483 if (ret < 0) |
8476 xmlGenericError(xmlGenericErrorContext, "FullElem %s failed\n", | 8484 xmlGenericError(xmlGenericErrorContext, "FullElem %s failed\n", |
8477 elem->name); | 8485 elem->name); |
8478 #endif | 8486 #endif |
8479 return (ret); | 8487 return (ret); |
8480 } | 8488 } |
8481 | 8489 |
8482 /************************************************************************ | 8490 /************************************************************************ |
8483 * » » » » » » » » » * | 8491 *» » » » » » » » » * |
8484 * » » Generic interpreted validation implementation» » * | 8492 *» » Generic interpreted validation implementation» » * |
8485 * » » » » » » » » » * | 8493 *» » » » » » » » » * |
8486 ************************************************************************/ | 8494 ************************************************************************/ |
8487 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, | 8495 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, |
8488 xmlRelaxNGDefinePtr define); | 8496 xmlRelaxNGDefinePtr define); |
8489 | 8497 |
8490 /** | 8498 /** |
8491 * xmlRelaxNGSkipIgnored: | 8499 * xmlRelaxNGSkipIgnored: |
8492 * @ctxt: a schema validation context | 8500 * @ctxt: a schema validation context |
8493 * @node: the top node. | 8501 * @node: the top node. |
8494 * | 8502 * |
8495 * Skip ignorable nodes in that context | 8503 * Skip ignorable nodes in that context |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8877 } | 8885 } |
8878 case XML_RELAXNG_ONEORMORE: | 8886 case XML_RELAXNG_ONEORMORE: |
8879 ret = xmlRelaxNGValidateValueList(ctxt, define->content); | 8887 ret = xmlRelaxNGValidateValueList(ctxt, define->content); |
8880 if (ret != 0) { | 8888 if (ret != 0) { |
8881 break; | 8889 break; |
8882 } | 8890 } |
8883 /* no break on purpose */ | 8891 /* no break on purpose */ |
8884 case XML_RELAXNG_ZEROORMORE:{ | 8892 case XML_RELAXNG_ZEROORMORE:{ |
8885 xmlChar *cur, *temp; | 8893 xmlChar *cur, *temp; |
8886 | 8894 |
| 8895 if ((ctxt->state->value == NULL) || |
| 8896 (*ctxt->state->value == 0)) { |
| 8897 ret = 0; |
| 8898 break; |
| 8899 } |
8887 oldflags = ctxt->flags; | 8900 oldflags = ctxt->flags; |
8888 ctxt->flags |= FLAGS_IGNORABLE; | 8901 ctxt->flags |= FLAGS_IGNORABLE; |
8889 cur = ctxt->state->value; | 8902 cur = ctxt->state->value; |
8890 temp = NULL; | 8903 temp = NULL; |
8891 while ((cur != NULL) && (cur != ctxt->state->endvalue) && | 8904 while ((cur != NULL) && (cur != ctxt->state->endvalue) && |
8892 (temp != cur)) { | 8905 (temp != cur)) { |
8893 temp = cur; | 8906 temp = cur; |
8894 ret = | 8907 ret = |
8895 xmlRelaxNGValidateValueList(ctxt, define->content); | 8908 xmlRelaxNGValidateValueList(ctxt, define->content); |
8896 if (ret != 0) { | 8909 if (ret != 0) { |
8897 ctxt->state->value = temp; | 8910 ctxt->state->value = temp; |
8898 ret = 0; | 8911 ret = 0; |
8899 break; | 8912 break; |
8900 } | 8913 } |
8901 cur = ctxt->state->value; | 8914 cur = ctxt->state->value; |
8902 } | 8915 } |
8903 ctxt->flags = oldflags; | 8916 ctxt->flags = oldflags; |
8904 if (ctxt->errNr > 0) | 8917 if (ctxt->errNr > 0) |
8905 xmlRelaxNGPopErrors(ctxt, 0); | 8918 xmlRelaxNGPopErrors(ctxt, 0); |
8906 break; | 8919 break; |
8907 } | 8920 } |
| 8921 case XML_RELAXNG_OPTIONAL:{ |
| 8922 xmlChar *temp; |
| 8923 |
| 8924 if ((ctxt->state->value == NULL) || |
| 8925 (*ctxt->state->value == 0)) { |
| 8926 ret = 0; |
| 8927 break; |
| 8928 } |
| 8929 oldflags = ctxt->flags; |
| 8930 ctxt->flags |= FLAGS_IGNORABLE; |
| 8931 temp = ctxt->state->value; |
| 8932 ret = xmlRelaxNGValidateValue(ctxt, define->content); |
| 8933 ctxt->flags = oldflags; |
| 8934 if (ret != 0) { |
| 8935 ctxt->state->value = temp; |
| 8936 if (ctxt->errNr > 0) |
| 8937 xmlRelaxNGPopErrors(ctxt, 0); |
| 8938 ret = 0; |
| 8939 break; |
| 8940 } |
| 8941 if (ctxt->errNr > 0) |
| 8942 xmlRelaxNGPopErrors(ctxt, 0); |
| 8943 break; |
| 8944 } |
8908 case XML_RELAXNG_EXCEPT:{ | 8945 case XML_RELAXNG_EXCEPT:{ |
8909 xmlRelaxNGDefinePtr list; | 8946 xmlRelaxNGDefinePtr list; |
8910 | 8947 |
8911 list = define->content; | 8948 list = define->content; |
8912 while (list != NULL) { | 8949 while (list != NULL) { |
8913 ret = xmlRelaxNGValidateValue(ctxt, list); | 8950 ret = xmlRelaxNGValidateValue(ctxt, list); |
8914 if (ret == 0) { | 8951 if (ret == 0) { |
8915 ret = -1; | 8952 ret = -1; |
8916 break; | 8953 break; |
8917 } else | 8954 } else |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9013 | 9050 |
9014 list = define->content; | 9051 list = define->content; |
9015 while (list != NULL) { | 9052 while (list != NULL) { |
9016 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); | 9053 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); |
9017 if (ret == 1) | 9054 if (ret == 1) |
9018 return (0); | 9055 return (0); |
9019 if (ret < 0) | 9056 if (ret < 0) |
9020 return (ret); | 9057 return (ret); |
9021 list = list->next; | 9058 list = list->next; |
9022 } | 9059 } |
| 9060 } else if (define->type == XML_RELAXNG_CHOICE) { |
| 9061 xmlRelaxNGDefinePtr list; |
| 9062 |
| 9063 list = define->nameClass; |
| 9064 while (list != NULL) { |
| 9065 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); |
| 9066 if (ret == 1) |
| 9067 return (1); |
| 9068 if (ret < 0) |
| 9069 return (ret); |
| 9070 list = list->next; |
| 9071 } |
| 9072 return (0); |
9023 } else { | 9073 } else { |
9024 TODO} | 9074 TODO} |
9025 return (1); | 9075 return (1); |
9026 } | 9076 } |
9027 | 9077 |
9028 /** | 9078 /** |
9029 * xmlRelaxNGValidateAttribute: | 9079 * xmlRelaxNGValidateAttribute: |
9030 * @ctxt: a Relax-NG validation context | 9080 * @ctxt: a Relax-NG validation context |
9031 * @define: the definition to verify | 9081 * @define: the definition to verify |
9032 * | 9082 * |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9372 } | 9422 } |
9373 if (ret != 0) { | 9423 if (ret != 0) { |
9374 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ); | 9424 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ); |
9375 ret = -1; | 9425 ret = -1; |
9376 goto done; | 9426 goto done; |
9377 } | 9427 } |
9378 lastelem = cur; | 9428 lastelem = cur; |
9379 oldstate = ctxt->state; | 9429 oldstate = ctxt->state; |
9380 for (i = 0; i < nbgroups; i++) { | 9430 for (i = 0; i < nbgroups; i++) { |
9381 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate); | 9431 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate); |
| 9432 if (ctxt->state == NULL) { |
| 9433 ret = -1; |
| 9434 break; |
| 9435 } |
9382 group = partitions->groups[i]; | 9436 group = partitions->groups[i]; |
9383 if (lasts[i] != NULL) { | 9437 if (lasts[i] != NULL) { |
9384 last = lasts[i]->next; | 9438 last = lasts[i]->next; |
9385 lasts[i]->next = NULL; | 9439 lasts[i]->next = NULL; |
9386 } | 9440 } |
9387 ctxt->state->seq = list[i]; | 9441 ctxt->state->seq = list[i]; |
9388 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule); | 9442 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule); |
9389 if (ret != 0) | 9443 if (ret != 0) |
9390 break; | 9444 break; |
9391 if (ctxt->state != NULL) { | 9445 if (ctxt->state != NULL) { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9802 if (define->name != NULL) | 9856 if (define->name != NULL) |
9803 xmlGenericError(xmlGenericErrorContext, "%s ", define->name); | 9857 xmlGenericError(xmlGenericErrorContext, "%s ", define->name); |
9804 if ((node != NULL) && (node->name != NULL)) | 9858 if ((node != NULL) && (node->name != NULL)) |
9805 xmlGenericError(xmlGenericErrorContext, "on %s\n", node->name); | 9859 xmlGenericError(xmlGenericErrorContext, "on %s\n", node->name); |
9806 else | 9860 else |
9807 xmlGenericError(xmlGenericErrorContext, "\n"); | 9861 xmlGenericError(xmlGenericErrorContext, "\n"); |
9808 #endif | 9862 #endif |
9809 ctxt->depth++; | 9863 ctxt->depth++; |
9810 switch (define->type) { | 9864 switch (define->type) { |
9811 case XML_RELAXNG_EMPTY: | 9865 case XML_RELAXNG_EMPTY: |
9812 node = xmlRelaxNGSkipIgnored(ctxt, node); | 9866 xmlRelaxNGSkipIgnored(ctxt, node); |
9813 ret = 0; | 9867 ret = 0; |
9814 break; | 9868 break; |
9815 case XML_RELAXNG_NOT_ALLOWED: | 9869 case XML_RELAXNG_NOT_ALLOWED: |
9816 ret = -1; | 9870 ret = -1; |
9817 break; | 9871 break; |
9818 case XML_RELAXNG_TEXT: | 9872 case XML_RELAXNG_TEXT: |
9819 while ((node != NULL) && | 9873 while ((node != NULL) && |
9820 ((node->type == XML_TEXT_NODE) || | 9874 ((node->type == XML_TEXT_NODE) || |
9821 (node->type == XML_COMMENT_NODE) || | 9875 (node->type == XML_COMMENT_NODE) || |
9822 (node->type == XML_PI_NODE) || | 9876 (node->type == XML_PI_NODE) || |
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10806 } | 10860 } |
10807 if (cur->next != NULL) { | 10861 if (cur->next != NULL) { |
10808 cur = cur->next; | 10862 cur = cur->next; |
10809 break; | 10863 break; |
10810 } | 10864 } |
10811 } while (cur != NULL); | 10865 } while (cur != NULL); |
10812 } | 10866 } |
10813 return; | 10867 return; |
10814 } | 10868 } |
10815 /************************************************************************ | 10869 /************************************************************************ |
10816 * » » » » » » » » » * | 10870 *» » » » » » » » » * |
10817 * » » » Validation interfaces» » » » * | 10871 *» » » Validation interfaces» » » » * |
10818 * » » » » » » » » » * | 10872 *» » » » » » » » » * |
10819 ************************************************************************/ | 10873 ************************************************************************/ |
10820 | 10874 |
10821 /** | 10875 /** |
10822 * xmlRelaxNGNewValidCtxt: | 10876 * xmlRelaxNGNewValidCtxt: |
10823 * @schema: a precompiled XML RelaxNGs | 10877 * @schema: a precompiled XML RelaxNGs |
10824 * | 10878 * |
10825 * Create an XML RelaxNGs validation context based on the given schema | 10879 * Create an XML RelaxNGs validation context based on the given schema |
10826 * | 10880 * |
10827 * Returns the validation context or NULL in case of error | 10881 * Returns the validation context or NULL in case of error |
10828 */ | 10882 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10994 * TODO: build error codes | 11048 * TODO: build error codes |
10995 */ | 11049 */ |
10996 if (ret == -1) | 11050 if (ret == -1) |
10997 return (1); | 11051 return (1); |
10998 return (ret); | 11052 return (ret); |
10999 } | 11053 } |
11000 | 11054 |
11001 #define bottom_relaxng | 11055 #define bottom_relaxng |
11002 #include "elfgcchack.h" | 11056 #include "elfgcchack.h" |
11003 #endif /* LIBXML_SCHEMAS_ENABLED */ | 11057 #endif /* LIBXML_SCHEMAS_ENABLED */ |
OLD | NEW |