diff --git a/ChangeLog b/ChangeLog index a8bebd7f..67aa7d49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Aug 8 15:56:32 CEST 2003 Daniel Veillard + + * HTMLtree.c tree.c threads.c: hum try to avoid some troubles + when the library is not initialized and one try to save, the + locks in threaded env might not been initialized, playing safe + * xmlschemastypes.c: apply patch for hexBinary from Charles Bozeman + * test/schemas/hexbinary_* result/schemas/hexbinary_*: also added + his tests to the regression suite. + Fri Aug 8 18:47:38 HKT 2003 William Brack * win32/defgen.xsl, win32/libxml2.def.src: Bug 119343 diff --git a/HTMLtree.c b/HTMLtree.c index 1d2f6de7..4efce27f 100644 --- a/HTMLtree.c +++ b/HTMLtree.c @@ -383,6 +383,8 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, */ int htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) { + xmlInitParser(); + return(htmlNodeDumpFormat(buf, doc, cur, 1)); } @@ -407,6 +409,8 @@ htmlNodeDumpFileFormat(FILE *out, xmlDocPtr doc, xmlCharEncodingHandlerPtr handler = NULL; int ret; + xmlInitParser(); + if (encoding != NULL) { xmlCharEncoding enc; @@ -467,6 +471,8 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { xmlCharEncodingHandlerPtr handler = NULL; const char *encoding; + xmlInitParser(); + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -695,6 +701,8 @@ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, const char *encoding, int format) { const htmlElemDesc * info; + xmlInitParser(); + if (cur == NULL) { xmlGenericError(xmlGenericErrorContext, "htmlNodeDumpFormatOutput : node == NULL\n"); @@ -889,6 +897,8 @@ htmlDocContentDumpFormatOutput(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding, int format) { int type; + xmlInitParser(); + /* * force to output the stuff as HTML, especially for entities */ @@ -940,6 +950,8 @@ htmlDocDump(FILE *f, xmlDocPtr cur) { const char *encoding; int ret; + xmlInitParser(); + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -1000,6 +1012,8 @@ htmlSaveFile(const char *filename, xmlDocPtr cur) { const char *encoding; int ret; + xmlInitParser(); + encoding = (const char *) htmlGetMetaEncoding(cur); if (encoding != NULL) { @@ -1058,6 +1072,8 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr cur, xmlCharEncodingHandlerPtr handler = NULL; int ret; + xmlInitParser(); + if (encoding != NULL) { xmlCharEncoding enc; diff --git a/result/schemas/hexbinary_0_0 b/result/schemas/hexbinary_0_0 new file mode 100644 index 00000000..783bab4c --- /dev/null +++ b/result/schemas/hexbinary_0_0 @@ -0,0 +1 @@ +./test/schemas/hexbinary_0.xml validates diff --git a/result/schemas/hexbinary_0_0.err b/result/schemas/hexbinary_0_0.err new file mode 100644 index 00000000..e69de29b diff --git a/result/schemas/hexbinary_0_1 b/result/schemas/hexbinary_0_1 new file mode 100644 index 00000000..37b10d1a --- /dev/null +++ b/result/schemas/hexbinary_0_1 @@ -0,0 +1 @@ +./test/schemas/hexbinary_1.xml fails to validate diff --git a/result/schemas/hexbinary_0_1.err b/result/schemas/hexbinary_0_1.err new file mode 100644 index 00000000..028f36df --- /dev/null +++ b/result/schemas/hexbinary_0_1.err @@ -0,0 +1,9 @@ +Element hex: failed to validate basic type hexBinary +Element hex: failed to validate basic type hexBinary +Element hex: failed to validate basic type hexBinary +Element hex: failed to validate basic type hexBinary +Element hex: failed to validate basic type hexBinary +Element hex: failed to validate basic type hexBinary +Failed to validate type with facet maxLength +Failed to validate type with facet length +Failed to validate type with facet length diff --git a/test/schemas/hexbinary_0.xml b/test/schemas/hexbinary_0.xml new file mode 100644 index 00000000..9513445b --- /dev/null +++ b/test/schemas/hexbinary_0.xml @@ -0,0 +1,20 @@ + + + 00 + 0123456789ABCDEF + abcdef0123456789 + 0123456789abcdef + 0123456789ABCDEF + 0123456789abcdef0123456789ABCDEF + 0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF + 01234567899876543210 + 00112233445566778899aAbBcCdDeEfF + A0B1C2D3E4F5 + + 00 + 0000000000000000 + 1122334455667788 + + abcd + 0ed0 + diff --git a/test/schemas/hexbinary_0.xsd b/test/schemas/hexbinary_0.xsd new file mode 100644 index 00000000..60a6bec1 --- /dev/null +++ b/test/schemas/hexbinary_0.xsd @@ -0,0 +1,35 @@ + + + + + Testing hexBinary data types + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/schemas/hexbinary_1.xml b/test/schemas/hexbinary_1.xml new file mode 100644 index 00000000..b9d69234 --- /dev/null +++ b/test/schemas/hexbinary_1.xml @@ -0,0 +1,15 @@ + + + + + + 0 + 0123456789ABCDEFGH + +abcdef0123456789 + -0123456789abcdef + + 112233445566778899 + + ab + 00fedc + diff --git a/threads.c b/threads.c index 3a879fca..8e7a08cb 100644 --- a/threads.c +++ b/threads.c @@ -151,8 +151,10 @@ xmlFreeMutex(xmlMutexPtr tok) * xmlMutexLock() is used to lock a libxml2 token. */ void -xmlMutexLock(xmlMutexPtr tok ATTRIBUTE_UNUSED) +xmlMutexLock(xmlMutexPtr tok) { + if (tok == NULL) + return; #ifdef HAVE_PTHREAD_H pthread_mutex_lock(&tok->lock); #elif defined HAVE_WIN32_THREADS diff --git a/tree.c b/tree.c index e76b348c..4dd1027e 100644 --- a/tree.c +++ b/tree.c @@ -6831,6 +6831,8 @@ xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, int ret; xmlOutputBufferPtr outbuf; + xmlInitParser(); + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -6879,6 +6881,8 @@ xmlElemDump(FILE * f, xmlDocPtr doc, xmlNodePtr cur) { xmlOutputBufferPtr outbuf; + xmlInitParser(); + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -7302,7 +7306,11 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, #ifdef LIBXML_HTML_ENABLED xmlDtdPtr dtd; int is_xhtml = 0; +#endif + xmlInitParser(); + +#ifdef LIBXML_HTML_ENABLED dtd = xmlGetIntSubset(doc); if (dtd != NULL) { is_xhtml = xmlIsXHTML(dtd->SystemID, dtd->ExternalID); @@ -7345,6 +7353,8 @@ xmlDocContentDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr cur, int is_xhtml = 0; #endif + xmlInitParser(); + xmlOutputBufferWriteString(buf, "version != NULL) xmlBufferWriteQuotedString(buf->buffer, cur->version); diff --git a/xmlschemastypes.c b/xmlschemastypes.c index 8103f7ad..53c6e156 100644 --- a/xmlschemastypes.c +++ b/xmlschemastypes.c @@ -134,6 +134,13 @@ struct _xmlSchemaValQName { xmlChar *uri; }; +typedef struct _xmlSchemaValHex xmlSchemaValHex; +typedef xmlSchemaValHex *xmlSchemaValHexPtr; +struct _xmlSchemaValHex { + xmlChar *str; + unsigned int total; +}; + struct _xmlSchemaVal { xmlSchemaValType type; union { @@ -141,6 +148,7 @@ struct _xmlSchemaVal { xmlSchemaValDate date; xmlSchemaValDuration dur; xmlSchemaValQName qname; + xmlSchemaValHex hex; float f; double d; int b; @@ -413,6 +421,10 @@ xmlSchemaFreeValue(xmlSchemaValPtr value) { if (value->value.qname.name != NULL) xmlFree(value->value.qname.name); break; + case XML_SCHEMAS_HEXBINARY: + if (value->value.hex.str != NULL) + xmlFree(value->value.hex.str); + break; default: break; } @@ -1919,66 +1931,49 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar *value, goto return0; } case XML_SCHEMAS_HEXBINARY: { - const xmlChar *tmp, *cur = value; + const xmlChar *cur = value; + xmlChar *base; int total, i = 0; - unsigned long lo = 0, mi = 0, hi = 0; - unsigned long *base; - if (cur == NULL) - goto return1; - tmp = cur; - while (((*tmp >= '0') && (*tmp <= '9')) || - ((*tmp >= 'A') && (*tmp <= 'F')) || - ((*tmp >= 'a') && (*tmp <= 'f'))) { - i++;tmp++; + if (cur == NULL) + goto return1; + + while (((*cur >= '0') && (*cur <= '9')) || + ((*cur >= 'A') && (*cur <= 'F')) || + ((*cur >= 'a') && (*cur <= 'f'))) { + i++;cur++; } - if (*tmp != 0) - goto return1; - if (i > 24) + if (*cur != 0) goto return1; if ((i % 2) != 0) goto return1; - total = i / 2; /* number of octets */ - - if (i >= 16) - base = &hi; - else if (i >= 8) - base = &mi; - else - base = &lo; - - while (i > 0) { - if ((*cur >= '0') && (*cur <= '9')) { - *base = *base * 16 + (*cur - '0'); - } else if ((*cur >= 'A') && (*cur <= 'F')) { - *base = *base * 16 + (*cur - 'A') + 10; - } else if ((*cur >= 'a') && (*cur <= 'f')) { - *base = *base * 16 + (*cur - 'a') + 10; - } else - break; - - cur++; - i--; - if (i == 16) - base = &mi; - else if (i == 8) - base = &lo; - } - if (val != NULL) { - v = xmlSchemaNewValue(XML_SCHEMAS_HEXBINARY); - if (v != NULL) { - v->value.decimal.lo = lo; - v->value.decimal.mi = mi; - v->value.decimal.hi = hi; - v->value.decimal.total = total; - *val = v; - } else { + + v = xmlSchemaNewValue(XML_SCHEMAS_HEXBINARY); + if (v == NULL) goto error; - } - } + + cur = xmlStrdup(value); + if (cur == NULL) { + xmlFree(v); + goto return1; + } + + total = i / 2; /* number of octets */ + + base = (xmlChar *)cur; + while (i-- > 0) { + if (*base >= 'a') + *base = *base - ('a' - 'A'); + base++; + } + + v->value.hex.str = (xmlChar *)cur; + v->value.hex.total = total; + *val = v; + } goto return0; } case XML_SCHEMAS_INTEGER: @@ -3129,8 +3124,19 @@ xmlSchemaCompareValues(xmlSchemaValPtr x, xmlSchemaValPtr y) { } return (-2); case XML_SCHEMAS_HEXBINARY: - if (y->type == XML_SCHEMAS_HEXBINARY) - return (xmlSchemaCompareDecimals(x, y)); + if (y->type == XML_SCHEMAS_HEXBINARY) { + if (x->value.hex.total == y->value.hex.total) { + int ret = xmlStrcmp(x->value.hex.str, y->value.hex.str); + if (ret > 0) + return(1); + else if (ret == 0) + return(0); + } + else if (x->value.hex.total > y->value.hex.total) + return(1); + + return(-1); + } return (-2); case XML_SCHEMAS_STRING: case XML_SCHEMAS_IDREFS: @@ -3277,9 +3283,9 @@ xmlSchemaValidateFacet(xmlSchemaTypePtr base ATTRIBUTE_UNUSED, return(-1); } if ((val != NULL) && (val->type == XML_SCHEMAS_HEXBINARY)) - len = val->value.decimal.total; + len = val->value.hex.total; else { - switch (base->flags) { + switch (base->flags) { case XML_SCHEMAS_IDREF: case XML_SCHEMAS_NORMSTRING: case XML_SCHEMAS_TOKEN: @@ -3288,14 +3294,14 @@ xmlSchemaValidateFacet(xmlSchemaTypePtr base ATTRIBUTE_UNUSED, case XML_SCHEMAS_NAME: case XML_SCHEMAS_NCNAME: case XML_SCHEMAS_ID: - len = xmlSchemaNormLen(value); - break; + len = xmlSchemaNormLen(value); + break; case XML_SCHEMAS_STRING: - len = xmlUTF8Strlen(value); - break; + len = xmlUTF8Strlen(value); + break; default: TODO - } + } } if (facet->type == XML_SCHEMA_FACET_LENGTH) { if (len != facet->val->value.decimal.lo)