mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-03 08:58:17 +03:00
hum try to avoid some troubles when the library is not initialized and one
* 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. Daniel
This commit is contained in:
parent
41e6bed5d8
commit
70bcb0ea24
@ -1,3 +1,12 @@
|
||||
Fri Aug 8 15:56:32 CEST 2003 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* 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 <wbrack@mmm.com.hk>
|
||||
|
||||
* win32/defgen.xsl, win32/libxml2.def.src: Bug 119343
|
||||
|
16
HTMLtree.c
16
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;
|
||||
|
||||
|
1
result/schemas/hexbinary_0_0
Normal file
1
result/schemas/hexbinary_0_0
Normal file
@ -0,0 +1 @@
|
||||
./test/schemas/hexbinary_0.xml validates
|
0
result/schemas/hexbinary_0_0.err
Normal file
0
result/schemas/hexbinary_0_0.err
Normal file
1
result/schemas/hexbinary_0_1
Normal file
1
result/schemas/hexbinary_0_1
Normal file
@ -0,0 +1 @@
|
||||
./test/schemas/hexbinary_1.xml fails to validate
|
9
result/schemas/hexbinary_0_1.err
Normal file
9
result/schemas/hexbinary_0_1.err
Normal file
@ -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
|
20
test/schemas/hexbinary_0.xml
Normal file
20
test/schemas/hexbinary_0.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<xsd_hexBinary>
|
||||
<hex>00</hex>
|
||||
<hex>0123456789ABCDEF</hex>
|
||||
<hex>abcdef0123456789</hex>
|
||||
<hex>0123456789abcdef</hex>
|
||||
<hex>0123456789ABCDEF</hex>
|
||||
<hex>0123456789abcdef0123456789ABCDEF</hex>
|
||||
<hex>0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF</hex>
|
||||
<hex>01234567899876543210</hex>
|
||||
<hex>00112233445566778899aAbBcCdDeEfF</hex>
|
||||
<hex>A0B1C2D3E4F5</hex>
|
||||
<!-- minLength and maxLength -->
|
||||
<hex2>00</hex2>
|
||||
<hex2>0000000000000000</hex2>
|
||||
<hex2>1122334455667788</hex2>
|
||||
<!-- length -->
|
||||
<hex3>abcd</hex3>
|
||||
<hex3>0ed0</hex3>
|
||||
</xsd_hexBinary>
|
35
test/schemas/hexbinary_0.xsd
Normal file
35
test/schemas/hexbinary_0.xsd
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0"?>
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="unqualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation xml:lang="en">
|
||||
Testing hexBinary data types
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:element name="xsd_hexBinary">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:element name="hex" type="xsd:hexBinary"/>
|
||||
<xsd:element name="hex2">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:hexBinary">
|
||||
<xsd:maxLength value="8"/>
|
||||
<xsd:minLength value="1"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:element>
|
||||
<xsd:element name="hex3">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:hexBinary">
|
||||
<xsd:length value="2"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
|
15
test/schemas/hexbinary_1.xml
Normal file
15
test/schemas/hexbinary_1.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- all should fail to validate -->
|
||||
<xsd_hexBinary>
|
||||
<hex></hex>
|
||||
<hex/>
|
||||
<hex>0</hex>
|
||||
<hex>0123456789ABCDEFGH</hex>
|
||||
<hex>+abcdef0123456789</hex>
|
||||
<hex>-0123456789abcdef</hex>
|
||||
<!-- minLength and maxLength -->
|
||||
<hex2>112233445566778899</hex2>
|
||||
<!-- length -->
|
||||
<hex3>ab</hex3>
|
||||
<hex3>00fedc</hex3>
|
||||
</xsd_hexBinary>
|
@ -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
|
||||
|
10
tree.c
10
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, "<?xml version=");
|
||||
if (cur->version != NULL)
|
||||
xmlBufferWriteQuotedString(buf->buffer, cur->version);
|
||||
|
@ -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,65 +1931,48 @@ 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++;
|
||||
|
||||
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;
|
||||
|
||||
if (val != NULL) {
|
||||
|
||||
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 */
|
||||
|
||||
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;
|
||||
base = (xmlChar *)cur;
|
||||
while (i-- > 0) {
|
||||
if (*base >= 'a')
|
||||
*base = *base - ('a' - 'A');
|
||||
base++;
|
||||
}
|
||||
|
||||
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;
|
||||
v->value.hex.str = (xmlChar *)cur;
|
||||
v->value.hex.total = total;
|
||||
*val = v;
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
goto return0;
|
||||
}
|
||||
@ -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,7 +3283,7 @@ 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) {
|
||||
case XML_SCHEMAS_IDREF:
|
||||
|
Loading…
x
Reference in New Issue
Block a user