--- embedaddon/libxml2/relaxng.c 2012/02/21 23:37:58 1.1 +++ embedaddon/libxml2/relaxng.c 2014/06/15 19:53:31 1.1.1.3 @@ -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 nod } /************************************************************************ - * * - * 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); @@ -1397,9 +1398,9 @@ xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt, } /************************************************************************ - * * - * Semi internal functions * - * * + * * + * Semi internal functions * + * * ************************************************************************/ /** @@ -1429,9 +1430,9 @@ xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, in } /************************************************************************ - * * - * Document functions * - * * + * * + * Document functions * + * * ************************************************************************/ static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc); @@ -1561,8 +1562,8 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt, href = xmlGetProp(tmp, BAD_CAST "href"); #endif if (xmlRelaxNGRemoveRedefine(ctxt, href, - inc->doc->children-> - children, name) == 1) { + xmlDocGetRootElement(inc->doc)->children, + name) == 1) { found = 1; } #ifdef DEBUG_INCLUDE @@ -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); @@ -2847,12 +2848,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 */ @@ -3059,8 +3060,8 @@ xmlRelaxNGCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRel list = list->next; } xmlAutomataSetFinalState(ctxt->am, ctxt->state); - def->contModel = xmlAutomataCompile(ctxt->am); - xmlRegexpIsDeterminist(def->contModel); + if (xmlAutomataIsDeterminist(ctxt->am)) + def->contModel = xmlAutomataCompile(ctxt->am); xmlFreeAutomata(ctxt->am); ctxt->state = oldstate; @@ -3325,9 +3326,9 @@ xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, xml } /************************************************************************ - * * - * Parsing functions * - * * + * * + * Parsing functions * + * * ************************************************************************/ static xmlRelaxNGDefinePtr xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr @@ -6705,9 +6706,9 @@ xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt, } /************************************************************************ - * * - * Reading RelaxNGs * - * * + * * + * Reading RelaxNGs * + * * ************************************************************************/ /** @@ -7521,7 +7522,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 +7664,9 @@ xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCt #ifdef LIBXML_OUTPUT_ENABLED /************************************************************************ - * * - * Dump back a compiled form * - * * + * * + * Dump back a compiled form * + * * ************************************************************************/ static void xmlRelaxNGDumpDefine(FILE * output, xmlRelaxNGDefinePtr define); @@ -7806,7 +7807,7 @@ xmlRelaxNGDumpDefine(FILE * output, xmlRelaxNGDefinePt * 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 +7900,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 +8045,9 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtP } /************************************************************************ - * * - * Progressive validation of when possible * - * * + * * + * Progressive validation of when possible * + * * ************************************************************************/ static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGDefinePtr defines); @@ -8346,7 +8347,7 @@ xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr c * 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 +8481,9 @@ xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr c } /************************************************************************ - * * - * Generic interpreted validation implementation * - * * + * * + * Generic interpreted validation implementation * + * * ************************************************************************/ static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGDefinePtr define); @@ -8884,6 +8885,11 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, case XML_RELAXNG_ZEROORMORE:{ xmlChar *cur, *temp; + if ((ctxt->state->value == NULL) || + (*ctxt->state->value == 0)) { + ret = 0; + break; + } oldflags = ctxt->flags; ctxt->flags |= FLAGS_IGNORABLE; cur = ctxt->state->value; @@ -8905,6 +8911,30 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGPopErrors(ctxt, 0); break; } + case XML_RELAXNG_OPTIONAL:{ + xmlChar *temp; + + if ((ctxt->state->value == NULL) || + (*ctxt->state->value == 0)) { + ret = 0; + break; + } + oldflags = ctxt->flags; + ctxt->flags |= FLAGS_IGNORABLE; + temp = ctxt->state->value; + ret = xmlRelaxNGValidateValue(ctxt, define->content); + ctxt->flags = oldflags; + if (ret != 0) { + ctxt->state->value = temp; + if (ctxt->errNr > 0) + xmlRelaxNGPopErrors(ctxt, 0); + ret = 0; + break; + } + if (ctxt->errNr > 0) + xmlRelaxNGPopErrors(ctxt, 0); + break; + } case XML_RELAXNG_EXCEPT:{ xmlRelaxNGDefinePtr list; @@ -10813,9 +10843,9 @@ xmlRelaxNGCleanPSVI(xmlNodePtr node) { return; } /************************************************************************ - * * - * Validation interfaces * - * * + * * + * Validation interfaces * + * * ************************************************************************/ /**