From 28c52ab518d34a36fd8da6870a5850088f129a6a Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 18 Mar 2003 11:39:17 +0000 Subject: [PATCH] fixed error msg cleanup deallocation added a function to handle lists of * relaxng.c: fixed error msg cleanup deallocation * xmlschemastypes.c: added a function to handle lists of atomic types, added support for IDREFS Daniel --- ChangeLog | 6 ++++ relaxng.c | 38 +++++++++++++++++++---- xmlschemastypes.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f83fa1cf..dae25b8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Mar 18 12:36:22 CET 2003 Daniel Veillard + + * relaxng.c: fixed error msg cleanup deallocation + * xmlschemastypes.c: added a function to handle lists of + atomic types, added support for IDREFS + Tue Mar 18 01:28:15 CET 2003 Daniel Veillard * relaxng.c valid.c xmlschemastypes.c: added Datatype ID diff --git a/relaxng.c b/relaxng.c index 8249a964..0fd8b40c 100644 --- a/relaxng.c +++ b/relaxng.c @@ -1878,6 +1878,32 @@ xmlRelaxNGShowValidError(xmlRelaxNGValidCtxtPtr ctxt, xmlRelaxNGValidErr err, xmlFree(msg); } +/** + * xmlRelaxNGPopErrors: + * @ctxt: the validation context + * @level: the error level in the stack + * + * pop and discard all errors until the given level is reached + */ +static void +xmlRelaxNGPopErrors(xmlRelaxNGValidCtxtPtr ctxt, int level) { + int i; + xmlRelaxNGValidErrorPtr err; + + for (i = level;i < ctxt->errNr;i++) { + err = &ctxt->errTab[i]; + if (err->flags & ERROR_IS_DUP) { + if (err->arg1 != NULL) + xmlFree((xmlChar *)err->arg1); + err->arg1 = NULL; + if (err->arg2 != NULL) + xmlFree((xmlChar *)err->arg2); + err->arg2 = NULL; + err->flags = 0; + } + } + ctxt->errNr = level; +} /** * xmlRelaxNGDumpValidError: * @ctxt: the validation context @@ -6925,7 +6951,7 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGDumpValidError(ctxt); } else { - ctxt->errNr = 0; + if (ctxt->errNr > 0) xmlRelaxNGPopErrors(ctxt, 0); } if (ret == 0) xmlRelaxNGNextValue(ctxt); @@ -7030,7 +7056,7 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt, if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGDumpValidError(ctxt); } else { - ctxt->errNr = 0; + if (ctxt->errNr > 0) xmlRelaxNGPopErrors(ctxt, 0); } break; } @@ -7498,7 +7524,7 @@ done: cur = cur->prev; } if (ret == 0) { - ctxt->errNr = errNr; + if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr); } xmlFree(list); @@ -7632,7 +7658,7 @@ xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt, if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGDumpValidError(ctxt); } else { - ctxt->errNr = 0; + if (ctxt->errNr > 0) xmlRelaxNGPopErrors(ctxt, 0); } ret = 0; ctxt->flags = oldflags; @@ -7836,7 +7862,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGDumpValidError(ctxt); } else { - ctxt->errNr = errNr; + if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr); } #ifdef DEBUG @@ -8057,7 +8083,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, if ((ctxt->flags & FLAGS_IGNORABLE) == 0) xmlRelaxNGDumpValidError(ctxt); } else if ((ctxt->flags & FLAGS_IGNORABLE) == 0) { - ctxt->errNr = errNr; + if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr); } break; } diff --git a/xmlschemastypes.c b/xmlschemastypes.c index a477bccf..05086993 100644 --- a/xmlschemastypes.c +++ b/xmlschemastypes.c @@ -1056,6 +1056,73 @@ error: } +/** + * xmlSchemaValAtomicListNode: + * @type: the predefined atomic type for a token in the list + * @value: the list value to check + * @ret: the return computed value + * @node: the node containing the value + * + * Check that a value conforms to the lexical space of the predefined + * list type. if true a value is computed and returned in @ret. + * + * Returns 0 if this validates, a positive error code number otherwise + * and -1 in case of internal or API error. + */ +static int +xmlSchemaValAtomicListNode(xmlSchemaTypePtr type, const xmlChar *value, + xmlSchemaValPtr *ret, xmlNodePtr node) { + xmlChar *val, *cur, *endval; + int nb_values = 0; + int tmp; + + if (value == NULL) { + return(-1); + } + val = xmlStrdup(value); + if (val == NULL) { + return(-1); + } + cur = val; + /* + * Split the list + */ + while (IS_BLANK(*cur)) cur++; + while (*cur != 0) { + if (IS_BLANK(*cur)) { + *cur = 0; + cur++; + while (IS_BLANK(*cur)) *cur++ = 0; + } else { + nb_values++; + cur++; + while ((*cur != 0) && (!IS_BLANK(*cur))) cur++; + } + } + if (nb_values == 0) { + if (ret != NULL) { + TODO + } + xmlFree(val); + return(0); + } + endval = cur; + cur = val; + while ((*cur == 0) && (cur != endval)) cur++; + while (cur != endval) { + tmp = xmlSchemaValPredefTypeNode(type, cur, NULL, node); + if (tmp != 0) + break; + while (*cur != 0) cur++; + while ((*cur == 0) && (cur != endval)) cur++; + } + xmlFree(val); + if (ret != NULL) { + TODO + } + return(tmp); +} + /** * xmlSchemaValPredefTypeNode: * @type: the predefined type @@ -1425,6 +1492,16 @@ xmlSchemaValPredefTypeNode(xmlSchemaTypePtr type, const xmlChar *value, attr->atype = XML_ATTRIBUTE_IDREF; } return(ret); + } else if (type == xmlSchemaTypeIdrefsDef) { + ret = xmlSchemaValAtomicListNode(xmlSchemaTypeIdrefDef, + value, val, node); + if ((ret == 0) && (node != NULL) && + (node->type == XML_ATTRIBUTE_NODE)) { + xmlAttrPtr attr = (xmlAttrPtr) node; + + attr->atype = XML_ATTRIBUTE_IDREFS; + } + return(ret); } else if (type == xmlSchemaTypeIdDef) { ret = xmlValidateNCName(value, 1); if ((ret == 0) && (val != NULL)) {