diff options
Diffstat (limited to 'relaxng.c')
-rw-r--r-- | relaxng.c | 147 |
1 files changed, 84 insertions, 63 deletions
@@ -39,9 +39,10 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *) "http://relaxng.org/ns/structure/1.0"; -#define IS_RELAXNG(node, type) \ +#define IS_RELAXNG(node, typ) \ ((node != NULL) && (node->ns != NULL) && \ - (xmlStrEqual(node->name, (const xmlChar *) type)) && \ + (node->type == XML_ELEMENT_NODE) && \ + (xmlStrEqual(node->name, (const xmlChar *) typ)) && \ (xmlStrEqual(node->ns->href, xmlRelaxNGNs))) @@ -60,7 +61,7 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *) #define DEBUG_LIST 1 -#define DEBUG_INCLUDE 1 +#define DEBUG_INCLUDE 1 #define DEBUG_ERROR 1 @@ -71,7 +72,7 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *) #define MAX_ERROR 5 -#define TODO \ +#define TODO \ xmlGenericError(xmlGenericErrorContext, \ "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__); @@ -421,7 +422,7 @@ struct _xmlRelaxNGDocument { /************************************************************************ * * - * Some factorized error routines * + * Some factorized error routines * * * ************************************************************************/ @@ -564,9 +565,9 @@ xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error, } /************************************************************************ - * * - * Preliminary type checking interfaces * - * * + * * + * Preliminary type checking interfaces * + * * ************************************************************************/ /** @@ -654,9 +655,9 @@ struct _xmlRelaxNGTypeLibrary { }; /************************************************************************ - * * - * Allocation functions * - * * + * * + * Allocation functions * + * * ************************************************************************/ static void xmlRelaxNGFreeGrammar(xmlRelaxNGGrammarPtr grammar); static void xmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr define); @@ -1094,7 +1095,7 @@ xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt, { int i; - if (state == NULL) { + if (state == NULL || states == NULL) { return (-1); } if (states->nbState >= states->maxState) { @@ -1397,9 +1398,9 @@ xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt, } /************************************************************************ - * * - * Semi internal functions * - * * + * * + * Semi internal functions * + * * ************************************************************************/ /** @@ -1429,9 +1430,9 @@ xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, int flags) } /************************************************************************ - * * - * Document functions * - * * + * * + * Document functions * + * * ************************************************************************/ static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc); @@ -2007,9 +2008,9 @@ xmlRelaxNGLoadExternalRef(xmlRelaxNGParserCtxtPtr ctxt, } /************************************************************************ - * * - * Error functions * - * * + * * + * Error functions * + * * ************************************************************************/ #define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0); @@ -2360,7 +2361,7 @@ xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt, * generate the error directly */ if (((ctxt->flags & FLAGS_IGNORABLE) == 0) || - (ctxt->flags & FLAGS_NEGATIVE)) { + (ctxt->flags & FLAGS_NEGATIVE)) { xmlNodePtr node, seq; /* @@ -2390,9 +2391,9 @@ xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt, /************************************************************************ - * * - * Type library hooks * - * * + * * + * Type library hooks * + * * ************************************************************************/ static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, const xmlChar * str); @@ -2594,13 +2595,10 @@ xmlRelaxNGSchemaTypeCompare(void *data ATTRIBUTE_UNUSED, } ret = xmlSchemaValPredefTypeNode(typ, value2, &res2, ctxt2); if (ret != 0) { - if ((comp1 == NULL) && (res1 != NULL)) + if (res1 != (xmlSchemaValPtr) comp1) xmlSchemaFreeValue(res1); return (-1); } - if (res1 == NULL) { - return (-1); - } ret = xmlSchemaCompareValues(res1, res2); if (res1 != (xmlSchemaValPtr) comp1) xmlSchemaFreeValue(res1); @@ -2847,12 +2845,12 @@ xmlRelaxNGCleanupTypes(void) } /************************************************************************ - * * - * Compiling element content into regexp * - * * + * * + * Compiling element content into regexp * + * * * Sometime the element content can be compiled into a pure regexp, * * This allows a faster execution and streamability at that level * - * * + * * ************************************************************************/ /* from automata.c but not exported */ @@ -3325,9 +3323,9 @@ xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def) } /************************************************************************ - * * - * Parsing functions * - * * + * * + * Parsing functions * + * * ************************************************************************/ static xmlRelaxNGDefinePtr xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr @@ -6602,7 +6600,7 @@ xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes) } /* - * Apply 4.17 mergingd rules to defines and starts + * Apply 4.17 merging rules to defines and starts */ xmlRelaxNGCombineStart(ctxt, ret); if (ret->defs != NULL) { @@ -6654,12 +6652,17 @@ xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) ctxt->define = NULL; if (IS_RELAXNG(node, "grammar")) { schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children); + if (schema->topgrammar == NULL) { + xmlRelaxNGFree(schema); + return (NULL); + } } else { xmlRelaxNGGrammarPtr tmp, ret; schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt); if (schema->topgrammar == NULL) { - return (schema); + xmlRelaxNGFree(schema); + return (NULL); } /* * Link the new grammar in the tree @@ -6705,9 +6708,9 @@ xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) } /************************************************************************ - * * - * Reading RelaxNGs * - * * + * * + * Reading RelaxNGs * + * * ************************************************************************/ /** @@ -7316,7 +7319,7 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) } } /* - * Thisd is not an else since "include" is transformed + * This is not an else since "include" is transformed * into a div */ if (xmlStrEqual(cur->name, BAD_CAST "div")) { @@ -7345,13 +7348,13 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) if (ns != NULL) xmlFree(ns); /* - * Since we are about to delete cur, if it's nsDef is non-NULL we + * Since we are about to delete cur, if its nsDef is non-NULL we * need to preserve it (it contains the ns definitions for the * children we just moved). We'll just stick it on to the end * of cur->parent's list, since it's never going to be re-serialized * (bug 143738). */ - if (cur->nsDef != NULL) { + if ((cur->nsDef != NULL) && (cur->parent != NULL)) { xmlNsPtr parDef = (xmlNsPtr)&cur->parent->nsDef; while (parDef->next != NULL) parDef = parDef->next; @@ -7369,7 +7372,8 @@ xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root) else if ((cur->type == XML_TEXT_NODE) || (cur->type == XML_CDATA_SECTION_NODE)) { if (IS_BLANK_NODE(cur)) { - if (cur->parent->type == XML_ELEMENT_NODE) { + if ((cur->parent != NULL) && + (cur->parent->type == XML_ELEMENT_NODE)) { if ((!xmlStrEqual(cur->parent->name, BAD_CAST "value")) && (!xmlStrEqual @@ -7521,7 +7525,7 @@ xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt) xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n", (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL); - + xmlFreeDoc(ctxt->document); ctxt->document = NULL; return (NULL); @@ -7663,9 +7667,9 @@ xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt, #ifdef LIBXML_OUTPUT_ENABLED /************************************************************************ - * * - * Dump back a compiled form * - * * + * * + * Dump back a compiled form * + * * ************************************************************************/ static void xmlRelaxNGDumpDefine(FILE * output, xmlRelaxNGDefinePtr define); @@ -7806,7 +7810,7 @@ xmlRelaxNGDumpDefine(FILE * output, xmlRelaxNGDefinePtr define) * xmlRelaxNGDumpGrammar: * @output: the file output * @grammar: a grammar structure - * @top: is this a top grammar + * @top: is this a top grammar * * Dump a RelaxNG structure back */ @@ -7899,9 +7903,9 @@ xmlRelaxNGDumpTree(FILE * output, xmlRelaxNGPtr schema) #endif /* LIBXML_OUTPUT_ENABLED */ /************************************************************************ - * * - * Validation of compiled content * - * * + * * + * Validation of compiled content * + * * ************************************************************************/ static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGDefinePtr define); @@ -8044,9 +8048,9 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt, } /************************************************************************ - * * - * Progressive validation of when possible * - * * + * * + * Progressive validation of when possible * + * * ************************************************************************/ static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGDefinePtr defines); @@ -8346,7 +8350,7 @@ xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt, * xmlRelaxNGValidatePushCData: * @ctxt: the RelaxNG validation context * @data: some character data read - * @len: the lenght of the data + * @len: the length of the data * * check the CData parsed for validation in the current stack * @@ -8480,9 +8484,9 @@ xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt, } /************************************************************************ - * * - * Generic interpreted validation implementation * - * * + * * + * Generic interpreted validation implementation * + * * ************************************************************************/ static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGDefinePtr define); @@ -9049,6 +9053,19 @@ xmlRelaxNGAttributeMatch(xmlRelaxNGValidCtxtPtr ctxt, return (ret); list = list->next; } + } else if (define->type == XML_RELAXNG_CHOICE) { + xmlRelaxNGDefinePtr list; + + list = define->nameClass; + while (list != NULL) { + ret = xmlRelaxNGAttributeMatch(ctxt, list, prop); + if (ret == 1) + return (1); + if (ret < 0) + return (ret); + list = list->next; + } + return (0); } else { TODO} return (1); @@ -9408,6 +9425,10 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt, oldstate = ctxt->state; for (i = 0; i < nbgroups; i++) { ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate); + if (ctxt->state == NULL) { + ret = -1; + break; + } group = partitions->groups[i]; if (lasts[i] != NULL) { last = lasts[i]->next; @@ -10842,9 +10863,9 @@ xmlRelaxNGCleanPSVI(xmlNodePtr node) { return; } /************************************************************************ - * * - * Validation interfaces * - * * + * * + * Validation interfaces * + * * ************************************************************************/ /** |