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 3254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6595 ctxt->grammar = ret; | 6593 ctxt->grammar = ret; |
6596 if (ctxt->grammar == NULL) { | 6594 if (ctxt->grammar == NULL) { |
6597 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT, | 6595 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT, |
6598 "Failed to parse <grammar> content\n", NULL, NULL); | 6596 "Failed to parse <grammar> content\n", NULL, NULL); |
6599 } else if (ctxt->grammar->start == NULL) { | 6597 } else if (ctxt->grammar->start == NULL) { |
6600 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START, | 6598 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START, |
6601 "Element <grammar> has no <start>\n", NULL, NULL); | 6599 "Element <grammar> has no <start>\n", NULL, NULL); |
6602 } | 6600 } |
6603 | 6601 |
6604 /* | 6602 /* |
6605 * Apply 4.17 mergingd rules to defines and starts | 6603 * Apply 4.17 merging rules to defines and starts |
6606 */ | 6604 */ |
6607 xmlRelaxNGCombineStart(ctxt, ret); | 6605 xmlRelaxNGCombineStart(ctxt, ret); |
6608 if (ret->defs != NULL) { | 6606 if (ret->defs != NULL) { |
6609 xmlHashScan(ret->defs, (xmlHashScanner) xmlRelaxNGCheckCombine, | 6607 xmlHashScan(ret->defs, (xmlHashScanner) xmlRelaxNGCheckCombine, |
6610 ctxt); | 6608 ctxt); |
6611 } | 6609 } |
6612 | 6610 |
6613 /* | 6611 /* |
6614 * link together defines and refs in this grammar | 6612 * link together defines and refs in this grammar |
6615 */ | 6613 */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6647 return (NULL); | 6645 return (NULL); |
6648 | 6646 |
6649 schema = xmlRelaxNGNewRelaxNG(ctxt); | 6647 schema = xmlRelaxNGNewRelaxNG(ctxt); |
6650 if (schema == NULL) | 6648 if (schema == NULL) |
6651 return (NULL); | 6649 return (NULL); |
6652 | 6650 |
6653 olddefine = ctxt->define; | 6651 olddefine = ctxt->define; |
6654 ctxt->define = NULL; | 6652 ctxt->define = NULL; |
6655 if (IS_RELAXNG(node, "grammar")) { | 6653 if (IS_RELAXNG(node, "grammar")) { |
6656 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children); | 6654 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children); |
| 6655 if (schema->topgrammar == NULL) { |
| 6656 xmlRelaxNGFree(schema); |
| 6657 return (NULL); |
| 6658 } |
6657 } else { | 6659 } else { |
6658 xmlRelaxNGGrammarPtr tmp, ret; | 6660 xmlRelaxNGGrammarPtr tmp, ret; |
6659 | 6661 |
6660 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt); | 6662 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt); |
6661 if (schema->topgrammar == NULL) { | 6663 if (schema->topgrammar == NULL) { |
6662 return (schema); | 6664 xmlRelaxNGFree(schema); |
| 6665 return (NULL); |
6663 } | 6666 } |
6664 /* | 6667 /* |
6665 * Link the new grammar in the tree | 6668 * Link the new grammar in the tree |
6666 */ | 6669 */ |
6667 ret->parent = ctxt->grammar; | 6670 ret->parent = ctxt->grammar; |
6668 if (ctxt->grammar != NULL) { | 6671 if (ctxt->grammar != NULL) { |
6669 tmp = ctxt->grammar->children; | 6672 tmp = ctxt->grammar->children; |
6670 if (tmp == NULL) { | 6673 if (tmp == NULL) { |
6671 ctxt->grammar->children = ret; | 6674 ctxt->grammar->children = ret; |
6672 } else { | 6675 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
6698 #ifdef DEBUG | 6701 #ifdef DEBUG |
6699 if (schema == NULL) | 6702 if (schema == NULL) |
6700 xmlGenericError(xmlGenericErrorContext, | 6703 xmlGenericError(xmlGenericErrorContext, |
6701 "xmlRelaxNGParseDocument() failed\n"); | 6704 "xmlRelaxNGParseDocument() failed\n"); |
6702 #endif | 6705 #endif |
6703 | 6706 |
6704 return (schema); | 6707 return (schema); |
6705 } | 6708 } |
6706 | 6709 |
6707 /************************************************************************ | 6710 /************************************************************************ |
6708 * » » » » » » » » » * | 6711 *» » » » » » » » » * |
6709 * » » » Reading RelaxNGs» » » » * | 6712 *» » » Reading RelaxNGs» » » » * |
6710 * » » » » » » » » » * | 6713 *» » » » » » » » » * |
6711 ************************************************************************/ | 6714 ************************************************************************/ |
6712 | 6715 |
6713 /** | 6716 /** |
6714 * xmlRelaxNGNewParserCtxt: | 6717 * xmlRelaxNGNewParserCtxt: |
6715 * @URL: the location of the schema | 6718 * @URL: the location of the schema |
6716 * | 6719 * |
6717 * Create an XML RelaxNGs parse context for that file/resource expected | 6720 * Create an XML RelaxNGs parse context for that file/resource expected |
6718 * to contain an XML RelaxNGs file. | 6721 * to contain an XML RelaxNGs file. |
6719 * | 6722 * |
6720 * Returns the parser context or NULL in case of error | 6723 * 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", | 7312 "Found anyName/except//anyName forbidden cons
truct\n", |
7310 NULL, NULL); | 7313 NULL, NULL); |
7311 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) { | 7314 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) { |
7312 xmlRngPErr(ctxt, cur, | 7315 xmlRngPErr(ctxt, cur, |
7313 XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME, | 7316 XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME, |
7314 "Found nsName/except//anyName forbidden const
ruct\n", | 7317 "Found nsName/except//anyName forbidden const
ruct\n", |
7315 NULL, NULL); | 7318 NULL, NULL); |
7316 } | 7319 } |
7317 } | 7320 } |
7318 /* | 7321 /* |
7319 * Thisd is not an else since "include" is transformed | 7322 * This is not an else since "include" is transformed |
7320 * into a div | 7323 * into a div |
7321 */ | 7324 */ |
7322 if (xmlStrEqual(cur->name, BAD_CAST "div")) { | 7325 if (xmlStrEqual(cur->name, BAD_CAST "div")) { |
7323 xmlChar *ns; | 7326 xmlChar *ns; |
7324 xmlNodePtr child, ins, tmp; | 7327 xmlNodePtr child, ins, tmp; |
7325 | 7328 |
7326 /* | 7329 /* |
7327 * implements rule 4.11 | 7330 * implements rule 4.11 |
7328 */ | 7331 */ |
7329 | 7332 |
7330 ns = xmlGetProp(cur, BAD_CAST "ns"); | 7333 ns = xmlGetProp(cur, BAD_CAST "ns"); |
7331 | 7334 |
7332 child = cur->children; | 7335 child = cur->children; |
7333 ins = cur; | 7336 ins = cur; |
7334 while (child != NULL) { | 7337 while (child != NULL) { |
7335 if (ns != NULL) { | 7338 if (ns != NULL) { |
7336 if (!xmlHasProp(child, BAD_CAST "ns")) { | 7339 if (!xmlHasProp(child, BAD_CAST "ns")) { |
7337 xmlSetProp(child, BAD_CAST "ns", ns); | 7340 xmlSetProp(child, BAD_CAST "ns", ns); |
7338 } | 7341 } |
7339 } | 7342 } |
7340 tmp = child->next; | 7343 tmp = child->next; |
7341 xmlUnlinkNode(child); | 7344 xmlUnlinkNode(child); |
7342 ins = xmlAddNextSibling(ins, child); | 7345 ins = xmlAddNextSibling(ins, child); |
7343 child = tmp; | 7346 child = tmp; |
7344 } | 7347 } |
7345 if (ns != NULL) | 7348 if (ns != NULL) |
7346 xmlFree(ns); | 7349 xmlFree(ns); |
7347 /* | 7350 /* |
7348 » » * Since we are about to delete cur, if it's nsDef is non-NU
LL we | 7351 » » * 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 | 7352 * 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 | 7353 * 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 | 7354 * of cur->parent's list, since it's never going to be re-se
rialized |
7352 * (bug 143738). | 7355 * (bug 143738). |
7353 */ | 7356 */ |
7354 » » if (cur->nsDef != NULL) { | 7357 » » if ((cur->nsDef != NULL) && (cur->parent != NULL)) { |
7355 xmlNsPtr parDef = (xmlNsPtr)&cur->parent->nsDef; | 7358 xmlNsPtr parDef = (xmlNsPtr)&cur->parent->nsDef; |
7356 while (parDef->next != NULL) | 7359 while (parDef->next != NULL) |
7357 parDef = parDef->next; | 7360 parDef = parDef->next; |
7358 parDef->next = cur->nsDef; | 7361 parDef->next = cur->nsDef; |
7359 cur->nsDef = NULL; | 7362 cur->nsDef = NULL; |
7360 } | 7363 } |
7361 delete = cur; | 7364 delete = cur; |
7362 goto skip_children; | 7365 goto skip_children; |
7363 } | 7366 } |
7364 } | 7367 } |
7365 } | 7368 } |
7366 /* | 7369 /* |
7367 * Simplification 4.2 whitespaces | 7370 * Simplification 4.2 whitespaces |
7368 */ | 7371 */ |
7369 else if ((cur->type == XML_TEXT_NODE) || | 7372 else if ((cur->type == XML_TEXT_NODE) || |
7370 (cur->type == XML_CDATA_SECTION_NODE)) { | 7373 (cur->type == XML_CDATA_SECTION_NODE)) { |
7371 if (IS_BLANK_NODE(cur)) { | 7374 if (IS_BLANK_NODE(cur)) { |
7372 if (cur->parent->type == XML_ELEMENT_NODE) { | 7375 if ((cur->parent != NULL) && |
| 7376 » » (cur->parent->type == XML_ELEMENT_NODE)) { |
7373 if ((!xmlStrEqual(cur->parent->name, BAD_CAST "value")) | 7377 if ((!xmlStrEqual(cur->parent->name, BAD_CAST "value")) |
7374 && | 7378 && |
7375 (!xmlStrEqual | 7379 (!xmlStrEqual |
7376 (cur->parent->name, BAD_CAST "param"))) | 7380 (cur->parent->name, BAD_CAST "param"))) |
7377 delete = cur; | 7381 delete = cur; |
7378 } else { | 7382 } else { |
7379 delete = cur; | 7383 delete = cur; |
7380 goto skip_children; | 7384 goto skip_children; |
7381 } | 7385 } |
7382 } | 7386 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7514 } | 7518 } |
7515 | 7519 |
7516 /* | 7520 /* |
7517 * Then do the parsing for good | 7521 * Then do the parsing for good |
7518 */ | 7522 */ |
7519 root = xmlDocGetRootElement(doc); | 7523 root = xmlDocGetRootElement(doc); |
7520 if (root == NULL) { | 7524 if (root == NULL) { |
7521 xmlRngPErr(ctxt, (xmlNodePtr) doc, | 7525 xmlRngPErr(ctxt, (xmlNodePtr) doc, |
7522 XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", | 7526 XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", |
7523 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); | 7527 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); |
7524 » | 7528 |
7525 xmlFreeDoc(ctxt->document); | 7529 xmlFreeDoc(ctxt->document); |
7526 ctxt->document = NULL; | 7530 ctxt->document = NULL; |
7527 return (NULL); | 7531 return (NULL); |
7528 } | 7532 } |
7529 ret = xmlRelaxNGParseDocument(ctxt, root); | 7533 ret = xmlRelaxNGParseDocument(ctxt, root); |
7530 if (ret == NULL) { | 7534 if (ret == NULL) { |
7531 xmlFreeDoc(ctxt->document); | 7535 xmlFreeDoc(ctxt->document); |
7532 ctxt->document = NULL; | 7536 ctxt->document = NULL; |
7533 return (NULL); | 7537 return (NULL); |
7534 } | 7538 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7656 return; | 7660 return; |
7657 ctxt->serror = serror; | 7661 ctxt->serror = serror; |
7658 ctxt->error = NULL; | 7662 ctxt->error = NULL; |
7659 ctxt->warning = NULL; | 7663 ctxt->warning = NULL; |
7660 ctxt->userData = ctx; | 7664 ctxt->userData = ctx; |
7661 } | 7665 } |
7662 | 7666 |
7663 #ifdef LIBXML_OUTPUT_ENABLED | 7667 #ifdef LIBXML_OUTPUT_ENABLED |
7664 | 7668 |
7665 /************************************************************************ | 7669 /************************************************************************ |
7666 * » » » » » » » » » * | 7670 *» » » » » » » » » * |
7667 * » » » Dump back a compiled form» » » * | 7671 *» » » Dump back a compiled form» » » * |
7668 * » » » » » » » » » * | 7672 *» » » » » » » » » * |
7669 ************************************************************************/ | 7673 ************************************************************************/ |
7670 static void xmlRelaxNGDumpDefine(FILE * output, | 7674 static void xmlRelaxNGDumpDefine(FILE * output, |
7671 xmlRelaxNGDefinePtr define); | 7675 xmlRelaxNGDefinePtr define); |
7672 | 7676 |
7673 /** | 7677 /** |
7674 * xmlRelaxNGDumpDefines: | 7678 * xmlRelaxNGDumpDefines: |
7675 * @output: the file output | 7679 * @output: the file output |
7676 * @defines: a list of define structures | 7680 * @defines: a list of define structures |
7677 * | 7681 * |
7678 * Dump a RelaxNG structure back | 7682 * Dump a RelaxNG structure back |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7799 case XML_RELAXNG_NOOP: | 7803 case XML_RELAXNG_NOOP: |
7800 xmlRelaxNGDumpDefines(output, define->content); | 7804 xmlRelaxNGDumpDefines(output, define->content); |
7801 break; | 7805 break; |
7802 } | 7806 } |
7803 } | 7807 } |
7804 | 7808 |
7805 /** | 7809 /** |
7806 * xmlRelaxNGDumpGrammar: | 7810 * xmlRelaxNGDumpGrammar: |
7807 * @output: the file output | 7811 * @output: the file output |
7808 * @grammar: a grammar structure | 7812 * @grammar: a grammar structure |
7809 * @top: is this a top grammar | 7813 * @top: is this a top grammar |
7810 * | 7814 * |
7811 * Dump a RelaxNG structure back | 7815 * Dump a RelaxNG structure back |
7812 */ | 7816 */ |
7813 static void | 7817 static void |
7814 xmlRelaxNGDumpGrammar(FILE * output, xmlRelaxNGGrammarPtr grammar, int top) | 7818 xmlRelaxNGDumpGrammar(FILE * output, xmlRelaxNGGrammarPtr grammar, int top) |
7815 { | 7819 { |
7816 if (grammar == NULL) | 7820 if (grammar == NULL) |
7817 return; | 7821 return; |
7818 | 7822 |
7819 fprintf(output, "<grammar"); | 7823 fprintf(output, "<grammar"); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7892 } | 7896 } |
7893 if (schema->doc == NULL) { | 7897 if (schema->doc == NULL) { |
7894 fprintf(output, "no document\n"); | 7898 fprintf(output, "no document\n"); |
7895 } else { | 7899 } else { |
7896 xmlDocDump(output, schema->doc); | 7900 xmlDocDump(output, schema->doc); |
7897 } | 7901 } |
7898 } | 7902 } |
7899 #endif /* LIBXML_OUTPUT_ENABLED */ | 7903 #endif /* LIBXML_OUTPUT_ENABLED */ |
7900 | 7904 |
7901 /************************************************************************ | 7905 /************************************************************************ |
7902 * » » » » » » » » » * | 7906 *» » » » » » » » » * |
7903 * » » Validation of compiled content» » » » * | 7907 *» » Validation of compiled content» » » » * |
7904 * » » » » » » » » » * | 7908 *» » » » » » » » » * |
7905 ************************************************************************/ | 7909 ************************************************************************/ |
7906 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, | 7910 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, |
7907 xmlRelaxNGDefinePtr define); | 7911 xmlRelaxNGDefinePtr define); |
7908 | 7912 |
7909 /** | 7913 /** |
7910 * xmlRelaxNGValidateCompiledCallback: | 7914 * xmlRelaxNGValidateCompiledCallback: |
7911 * @exec: the regular expression instance | 7915 * @exec: the regular expression instance |
7912 * @token: the token which matched | 7916 * @token: the token which matched |
7913 * @transdata: callback data, the define for the subelement if available | 7917 * @transdata: callback data, the define for the subelement if available |
7914 @ @inputdata: callback data, the Relax NG validation context | 7918 @ @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. | 8041 * regexp validation, e.g. for attribute values. |
8038 */ | 8042 */ |
8039 if ((ret == 0) && (ctxt->perr != 0)) { | 8043 if ((ret == 0) && (ctxt->perr != 0)) { |
8040 ret = ctxt->perr; | 8044 ret = ctxt->perr; |
8041 } | 8045 } |
8042 ctxt->perr = oldperr; | 8046 ctxt->perr = oldperr; |
8043 return (ret); | 8047 return (ret); |
8044 } | 8048 } |
8045 | 8049 |
8046 /************************************************************************ | 8050 /************************************************************************ |
8047 * » » » » » » » » » * | 8051 *» » » » » » » » » * |
8048 * » » Progressive validation of when possible»» » * | 8052 *» » Progressive validation of when possible»» » * |
8049 * » » » » » » » » » * | 8053 *» » » » » » » » » * |
8050 ************************************************************************/ | 8054 ************************************************************************/ |
8051 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, | 8055 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, |
8052 xmlRelaxNGDefinePtr defines); | 8056 xmlRelaxNGDefinePtr defines); |
8053 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, | 8057 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, |
8054 int dolog); | 8058 int dolog); |
8055 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt); | 8059 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt); |
8056 | 8060 |
8057 /** | 8061 /** |
8058 * xmlRelaxNGElemPush: | 8062 * xmlRelaxNGElemPush: |
8059 * @ctxt: the validation context | 8063 * @ctxt: the validation context |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8339 xmlGenericError(xmlGenericErrorContext, "PushElem %s failed\n", | 8343 xmlGenericError(xmlGenericErrorContext, "PushElem %s failed\n", |
8340 elem->name); | 8344 elem->name); |
8341 #endif | 8345 #endif |
8342 return (ret); | 8346 return (ret); |
8343 } | 8347 } |
8344 | 8348 |
8345 /** | 8349 /** |
8346 * xmlRelaxNGValidatePushCData: | 8350 * xmlRelaxNGValidatePushCData: |
8347 * @ctxt: the RelaxNG validation context | 8351 * @ctxt: the RelaxNG validation context |
8348 * @data: some character data read | 8352 * @data: some character data read |
8349 * @len: the lenght of the data | 8353 * @len: the length of the data |
8350 * | 8354 * |
8351 * check the CData parsed for validation in the current stack | 8355 * check the CData parsed for validation in the current stack |
8352 * | 8356 * |
8353 * returns 1 if no validation problem was found or -1 otherwise | 8357 * returns 1 if no validation problem was found or -1 otherwise |
8354 */ | 8358 */ |
8355 int | 8359 int |
8356 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, | 8360 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt, |
8357 const xmlChar * data, int len ATTRIBUTE_UNUSED) | 8361 const xmlChar * data, int len ATTRIBUTE_UNUSED) |
8358 { | 8362 { |
8359 int ret = 1; | 8363 int ret = 1; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8473 ctxt->state = NULL; | 8477 ctxt->state = NULL; |
8474 #ifdef DEBUG_PROGRESSIVE | 8478 #ifdef DEBUG_PROGRESSIVE |
8475 if (ret < 0) | 8479 if (ret < 0) |
8476 xmlGenericError(xmlGenericErrorContext, "FullElem %s failed\n", | 8480 xmlGenericError(xmlGenericErrorContext, "FullElem %s failed\n", |
8477 elem->name); | 8481 elem->name); |
8478 #endif | 8482 #endif |
8479 return (ret); | 8483 return (ret); |
8480 } | 8484 } |
8481 | 8485 |
8482 /************************************************************************ | 8486 /************************************************************************ |
8483 * » » » » » » » » » * | 8487 *» » » » » » » » » * |
8484 * » » Generic interpreted validation implementation» » * | 8488 *» » Generic interpreted validation implementation» » * |
8485 * » » » » » » » » » * | 8489 *» » » » » » » » » * |
8486 ************************************************************************/ | 8490 ************************************************************************/ |
8487 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, | 8491 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, |
8488 xmlRelaxNGDefinePtr define); | 8492 xmlRelaxNGDefinePtr define); |
8489 | 8493 |
8490 /** | 8494 /** |
8491 * xmlRelaxNGSkipIgnored: | 8495 * xmlRelaxNGSkipIgnored: |
8492 * @ctxt: a schema validation context | 8496 * @ctxt: a schema validation context |
8493 * @node: the top node. | 8497 * @node: the top node. |
8494 * | 8498 * |
8495 * Skip ignorable nodes in that context | 8499 * Skip ignorable nodes in that context |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8877 } | 8881 } |
8878 case XML_RELAXNG_ONEORMORE: | 8882 case XML_RELAXNG_ONEORMORE: |
8879 ret = xmlRelaxNGValidateValueList(ctxt, define->content); | 8883 ret = xmlRelaxNGValidateValueList(ctxt, define->content); |
8880 if (ret != 0) { | 8884 if (ret != 0) { |
8881 break; | 8885 break; |
8882 } | 8886 } |
8883 /* no break on purpose */ | 8887 /* no break on purpose */ |
8884 case XML_RELAXNG_ZEROORMORE:{ | 8888 case XML_RELAXNG_ZEROORMORE:{ |
8885 xmlChar *cur, *temp; | 8889 xmlChar *cur, *temp; |
8886 | 8890 |
| 8891 if ((ctxt->state->value == NULL) || |
| 8892 (*ctxt->state->value == 0)) { |
| 8893 ret = 0; |
| 8894 break; |
| 8895 } |
8887 oldflags = ctxt->flags; | 8896 oldflags = ctxt->flags; |
8888 ctxt->flags |= FLAGS_IGNORABLE; | 8897 ctxt->flags |= FLAGS_IGNORABLE; |
8889 cur = ctxt->state->value; | 8898 cur = ctxt->state->value; |
8890 temp = NULL; | 8899 temp = NULL; |
8891 while ((cur != NULL) && (cur != ctxt->state->endvalue) && | 8900 while ((cur != NULL) && (cur != ctxt->state->endvalue) && |
8892 (temp != cur)) { | 8901 (temp != cur)) { |
8893 temp = cur; | 8902 temp = cur; |
8894 ret = | 8903 ret = |
8895 xmlRelaxNGValidateValueList(ctxt, define->content); | 8904 xmlRelaxNGValidateValueList(ctxt, define->content); |
8896 if (ret != 0) { | 8905 if (ret != 0) { |
8897 ctxt->state->value = temp; | 8906 ctxt->state->value = temp; |
8898 ret = 0; | 8907 ret = 0; |
8899 break; | 8908 break; |
8900 } | 8909 } |
8901 cur = ctxt->state->value; | 8910 cur = ctxt->state->value; |
8902 } | 8911 } |
8903 ctxt->flags = oldflags; | 8912 ctxt->flags = oldflags; |
8904 if (ctxt->errNr > 0) | 8913 if (ctxt->errNr > 0) |
8905 xmlRelaxNGPopErrors(ctxt, 0); | 8914 xmlRelaxNGPopErrors(ctxt, 0); |
8906 break; | 8915 break; |
8907 } | 8916 } |
| 8917 case XML_RELAXNG_OPTIONAL:{ |
| 8918 xmlChar *temp; |
| 8919 |
| 8920 if ((ctxt->state->value == NULL) || |
| 8921 (*ctxt->state->value == 0)) { |
| 8922 ret = 0; |
| 8923 break; |
| 8924 } |
| 8925 oldflags = ctxt->flags; |
| 8926 ctxt->flags |= FLAGS_IGNORABLE; |
| 8927 temp = ctxt->state->value; |
| 8928 ret = xmlRelaxNGValidateValue(ctxt, define->content); |
| 8929 ctxt->flags = oldflags; |
| 8930 if (ret != 0) { |
| 8931 ctxt->state->value = temp; |
| 8932 if (ctxt->errNr > 0) |
| 8933 xmlRelaxNGPopErrors(ctxt, 0); |
| 8934 ret = 0; |
| 8935 break; |
| 8936 } |
| 8937 if (ctxt->errNr > 0) |
| 8938 xmlRelaxNGPopErrors(ctxt, 0); |
| 8939 break; |
| 8940 } |
8908 case XML_RELAXNG_EXCEPT:{ | 8941 case XML_RELAXNG_EXCEPT:{ |
8909 xmlRelaxNGDefinePtr list; | 8942 xmlRelaxNGDefinePtr list; |
8910 | 8943 |
8911 list = define->content; | 8944 list = define->content; |
8912 while (list != NULL) { | 8945 while (list != NULL) { |
8913 ret = xmlRelaxNGValidateValue(ctxt, list); | 8946 ret = xmlRelaxNGValidateValue(ctxt, list); |
8914 if (ret == 0) { | 8947 if (ret == 0) { |
8915 ret = -1; | 8948 ret = -1; |
8916 break; | 8949 break; |
8917 } else | 8950 } else |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9013 | 9046 |
9014 list = define->content; | 9047 list = define->content; |
9015 while (list != NULL) { | 9048 while (list != NULL) { |
9016 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); | 9049 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); |
9017 if (ret == 1) | 9050 if (ret == 1) |
9018 return (0); | 9051 return (0); |
9019 if (ret < 0) | 9052 if (ret < 0) |
9020 return (ret); | 9053 return (ret); |
9021 list = list->next; | 9054 list = list->next; |
9022 } | 9055 } |
| 9056 } else if (define->type == XML_RELAXNG_CHOICE) { |
| 9057 xmlRelaxNGDefinePtr list; |
| 9058 |
| 9059 list = define->nameClass; |
| 9060 while (list != NULL) { |
| 9061 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); |
| 9062 if (ret == 1) |
| 9063 return (1); |
| 9064 if (ret < 0) |
| 9065 return (ret); |
| 9066 list = list->next; |
| 9067 } |
| 9068 return (0); |
9023 } else { | 9069 } else { |
9024 TODO} | 9070 TODO} |
9025 return (1); | 9071 return (1); |
9026 } | 9072 } |
9027 | 9073 |
9028 /** | 9074 /** |
9029 * xmlRelaxNGValidateAttribute: | 9075 * xmlRelaxNGValidateAttribute: |
9030 * @ctxt: a Relax-NG validation context | 9076 * @ctxt: a Relax-NG validation context |
9031 * @define: the definition to verify | 9077 * @define: the definition to verify |
9032 * | 9078 * |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9372 } | 9418 } |
9373 if (ret != 0) { | 9419 if (ret != 0) { |
9374 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ); | 9420 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ); |
9375 ret = -1; | 9421 ret = -1; |
9376 goto done; | 9422 goto done; |
9377 } | 9423 } |
9378 lastelem = cur; | 9424 lastelem = cur; |
9379 oldstate = ctxt->state; | 9425 oldstate = ctxt->state; |
9380 for (i = 0; i < nbgroups; i++) { | 9426 for (i = 0; i < nbgroups; i++) { |
9381 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate); | 9427 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate); |
| 9428 if (ctxt->state == NULL) { |
| 9429 ret = -1; |
| 9430 break; |
| 9431 } |
9382 group = partitions->groups[i]; | 9432 group = partitions->groups[i]; |
9383 if (lasts[i] != NULL) { | 9433 if (lasts[i] != NULL) { |
9384 last = lasts[i]->next; | 9434 last = lasts[i]->next; |
9385 lasts[i]->next = NULL; | 9435 lasts[i]->next = NULL; |
9386 } | 9436 } |
9387 ctxt->state->seq = list[i]; | 9437 ctxt->state->seq = list[i]; |
9388 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule); | 9438 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule); |
9389 if (ret != 0) | 9439 if (ret != 0) |
9390 break; | 9440 break; |
9391 if (ctxt->state != NULL) { | 9441 if (ctxt->state != NULL) { |
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10806 } | 10856 } |
10807 if (cur->next != NULL) { | 10857 if (cur->next != NULL) { |
10808 cur = cur->next; | 10858 cur = cur->next; |
10809 break; | 10859 break; |
10810 } | 10860 } |
10811 } while (cur != NULL); | 10861 } while (cur != NULL); |
10812 } | 10862 } |
10813 return; | 10863 return; |
10814 } | 10864 } |
10815 /************************************************************************ | 10865 /************************************************************************ |
10816 * » » » » » » » » » * | 10866 *» » » » » » » » » * |
10817 * » » » Validation interfaces» » » » * | 10867 *» » » Validation interfaces» » » » * |
10818 * » » » » » » » » » * | 10868 *» » » » » » » » » * |
10819 ************************************************************************/ | 10869 ************************************************************************/ |
10820 | 10870 |
10821 /** | 10871 /** |
10822 * xmlRelaxNGNewValidCtxt: | 10872 * xmlRelaxNGNewValidCtxt: |
10823 * @schema: a precompiled XML RelaxNGs | 10873 * @schema: a precompiled XML RelaxNGs |
10824 * | 10874 * |
10825 * Create an XML RelaxNGs validation context based on the given schema | 10875 * Create an XML RelaxNGs validation context based on the given schema |
10826 * | 10876 * |
10827 * Returns the validation context or NULL in case of error | 10877 * Returns the validation context or NULL in case of error |
10828 */ | 10878 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10994 * TODO: build error codes | 11044 * TODO: build error codes |
10995 */ | 11045 */ |
10996 if (ret == -1) | 11046 if (ret == -1) |
10997 return (1); | 11047 return (1); |
10998 return (ret); | 11048 return (ret); |
10999 } | 11049 } |
11000 | 11050 |
11001 #define bottom_relaxng | 11051 #define bottom_relaxng |
11002 #include "elfgcchack.h" | 11052 #include "elfgcchack.h" |
11003 #endif /* LIBXML_SCHEMAS_ENABLED */ | 11053 #endif /* LIBXML_SCHEMAS_ENABLED */ |
OLD | NEW |