summaryrefslogtreecommitdiff
path: root/chromium/third_party/libxml/src/valid.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libxml/src/valid.c')
-rw-r--r--chromium/third_party/libxml/src/valid.c132
1 files changed, 73 insertions, 59 deletions
diff --git a/chromium/third_party/libxml/src/valid.c b/chromium/third_party/libxml/src/valid.c
index 5ee391c0418..16fa9238bc3 100644
--- a/chromium/third_party/libxml/src/valid.c
+++ b/chromium/third_party/libxml/src/valid.c
@@ -11,10 +11,7 @@
#include "libxml.h"
#include <string.h>
-
-#ifdef HAVE_STDLIB_H
#include <stdlib.h>
-#endif
#include <libxml/xmlmemory.h>
#include <libxml/hash.h>
@@ -64,10 +61,9 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)
if (ctxt != NULL) {
channel = ctxt->error;
data = ctxt->userData;
- /* Use the special values to detect if it is part of a parsing
+ /* Look up flag to detect if it is part of a parsing
context */
- if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) {
+ if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
long delta = (char *) ctxt - (char *) ctxt->userData;
if ((delta > 0) && (delta < 250))
pctxt = ctxt->userData;
@@ -104,10 +100,9 @@ xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error,
if (ctxt != NULL) {
channel = ctxt->error;
data = ctxt->userData;
- /* Use the special values to detect if it is part of a parsing
+ /* Look up flag to detect if it is part of a parsing
context */
- if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) {
+ if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
long delta = (char *) ctxt - (char *) ctxt->userData;
if ((delta > 0) && (delta < 250))
pctxt = ctxt->userData;
@@ -151,10 +146,9 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
if (ctxt != NULL) {
channel = ctxt->error;
data = ctxt->userData;
- /* Use the special values to detect if it is part of a parsing
+ /* Look up flag to detect if it is part of a parsing
context */
- if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) {
+ if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
long delta = (char *) ctxt - (char *) ctxt->userData;
if ((delta > 0) && (delta < 250))
pctxt = ctxt->userData;
@@ -194,10 +188,9 @@ xmlErrValidNodeNr(xmlValidCtxtPtr ctxt,
if (ctxt != NULL) {
channel = ctxt->error;
data = ctxt->userData;
- /* Use the special values to detect if it is part of a parsing
+ /* Look up flag to detect if it is part of a parsing
context */
- if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) {
+ if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
long delta = (char *) ctxt - (char *) ctxt->userData;
if ((delta > 0) && (delta < 250))
pctxt = ctxt->userData;
@@ -235,10 +228,9 @@ xmlErrValidWarning(xmlValidCtxtPtr ctxt,
if (ctxt != NULL) {
channel = ctxt->warning;
data = ctxt->userData;
- /* Use the special values to detect if it is part of a parsing
+ /* Look up flag to detect if it is part of a parsing
context */
- if ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1)) {
+ if (ctxt->flags & XML_VCTXT_USE_PCTXT) {
long delta = (char *) ctxt - (char *) ctxt->userData;
if ((delta > 0) && (delta < 250))
pctxt = ctxt->userData;
@@ -1613,9 +1605,7 @@ xmlAddElementDecl(xmlValidCtxtPtr ctxt,
* and flag it by setting a special parent value
* so the parser doesn't unallocate it.
*/
- if ((ctxt != NULL) &&
- ((ctxt->finishDtd == XML_CTXT_FINISH_DTD_0) ||
- (ctxt->finishDtd == XML_CTXT_FINISH_DTD_1))) {
+ if ((ctxt != NULL) && (ctxt->flags & XML_VCTXT_USE_PCTXT)) {
ret->content = content;
if (content != NULL)
content->parent = (xmlElementContentPtr) 1;
@@ -2608,6 +2598,47 @@ xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) {
xmlFree((char *)(str));
/**
+ * xmlValidNormalizeString:
+ * @str: a string
+ *
+ * Normalize a string in-place.
+ */
+static void
+xmlValidNormalizeString(xmlChar *str) {
+ xmlChar *dst;
+ const xmlChar *src;
+
+ if (str == NULL)
+ return;
+ src = str;
+ dst = str;
+
+ while (*src == 0x20) src++;
+ while (*src != 0) {
+ if (*src == 0x20) {
+ while (*src == 0x20) src++;
+ if (*src != 0)
+ *dst++ = 0x20;
+ } else {
+ *dst++ = *src++;
+ }
+ }
+ *dst = 0;
+}
+
+static int
+xmlIsStreaming(xmlValidCtxtPtr ctxt) {
+ xmlParserCtxtPtr pctxt;
+
+ if (ctxt == NULL)
+ return(0);
+ if ((ctxt->flags & XML_VCTXT_USE_PCTXT) == 0)
+ return(0);
+ pctxt = ctxt->userData;
+ return(pctxt->parseMode == XML_PARSE_READER);
+}
+
+/**
* xmlFreeID:
* @not: A id
*
@@ -2650,7 +2681,7 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
if (doc == NULL) {
return(NULL);
}
- if (value == NULL) {
+ if ((value == NULL) || (value[0] == 0)) {
return(NULL);
}
if (attr == NULL) {
@@ -2681,7 +2712,7 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
*/
ret->value = xmlStrdup(value);
ret->doc = doc;
- if ((ctxt != NULL) && (ctxt->vstateNr != 0)) {
+ if (xmlIsStreaming(ctxt)) {
/*
* Operating in streaming mode, attr is gonna disappear
*/
@@ -2820,6 +2851,7 @@ xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr) {
ID = xmlNodeListGetString(doc, attr->children, 1);
if (ID == NULL)
return(-1);
+ xmlValidNormalizeString(ID);
id = xmlHashLookup(table, ID);
if (id == NULL || id->attr != attr) {
@@ -2965,6 +2997,8 @@ xmlDummyCompare(const void *data0 ATTRIBUTE_UNUSED,
* @value: the value name
* @attr: the attribute holding the Ref
*
+ * DEPRECATED, do not use. This function will be removed from the public API.
+ *
* Register a new ref declaration
*
* Returns NULL if not, otherwise the new xmlRefPtr
@@ -3009,7 +3043,7 @@ xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
* fill the structure.
*/
ret->value = xmlStrdup(value);
- if ((ctxt != NULL) && (ctxt->vstateNr != 0)) {
+ if (xmlIsStreaming(ctxt)) {
/*
* Operating in streaming mode, attr is gonna disappear
*/
@@ -3065,6 +3099,8 @@ failed:
* xmlFreeRefTable:
* @table: An ref table
*
+ * DEPRECATED, do not use. This function will be removed from the public API.
+ *
* Deallocate the memory used by an Ref hash table.
*/
void
@@ -3078,6 +3114,8 @@ xmlFreeRefTable(xmlRefTablePtr table) {
* @elem: the element carrying the attribute
* @attr: the attribute
*
+ * DEPRECATED, do not use. This function will be removed from the public API.
+ *
* Determine whether an attribute is of type Ref. In case we have DTD(s)
* then this is simple, otherwise we use an heuristic: name Ref (upper
* or lowercase).
@@ -3120,6 +3158,8 @@ xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) {
* @doc: the document
* @attr: the attribute
*
+ * DEPRECATED, do not use. This function will be removed from the public API.
+ *
* Remove the given attribute from the Ref table maintained internally.
*
* Returns -1 if the lookup failed and 0 otherwise
@@ -3176,6 +3216,8 @@ xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
* @doc: pointer to the document
* @ID: the ID value
*
+ * DEPRECATED, do not use. This function will be removed from the public API.
+ *
* Find the set of references for the supplied ID.
*
* Returns NULL if not found, otherwise node set for the ID.
@@ -4028,8 +4070,7 @@ xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlChar *
xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlNodePtr elem, const xmlChar *name, const xmlChar *value) {
- xmlChar *ret, *dst;
- const xmlChar *src;
+ xmlChar *ret;
xmlAttributePtr attrDecl = NULL;
int extsubset = 0;
@@ -4070,19 +4111,7 @@ xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
ret = xmlStrdup(value);
if (ret == NULL)
return(NULL);
- src = value;
- dst = ret;
- while (*src == 0x20) src++;
- while (*src != 0) {
- if (*src == 0x20) {
- while (*src == 0x20) src++;
- if (*src != 0)
- *dst++ = 0x20;
- } else {
- *dst++ = *src++;
- }
- }
- *dst = 0;
+ xmlValidNormalizeString(ret);
if ((doc->standalone) && (extsubset == 1) && (!xmlStrEqual(value, ret))) {
xmlErrValidNode(ctxt, elem, XML_DTD_NOT_STANDALONE,
"standalone: %s on %s value had to be normalized based on external subset declaration\n",
@@ -4114,8 +4143,7 @@ xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlChar *
xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem,
const xmlChar *name, const xmlChar *value) {
- xmlChar *ret, *dst;
- const xmlChar *src;
+ xmlChar *ret;
xmlAttributePtr attrDecl = NULL;
if (doc == NULL) return(NULL);
@@ -4145,19 +4173,7 @@ xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem,
ret = xmlStrdup(value);
if (ret == NULL)
return(NULL);
- src = value;
- dst = ret;
- while (*src == 0x20) src++;
- while (*src != 0) {
- if (*src == 0x20) {
- while (*src == 0x20) src++;
- if (*src != 0)
- *dst++ = 0x20;
- } else {
- *dst++ = *src++;
- }
- }
- *dst = 0;
+ xmlValidNormalizeString(ret);
return(ret);
}
@@ -6655,8 +6671,8 @@ xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
}
/* trick to get correct line id report */
- save = ctxt->finishDtd;
- ctxt->finishDtd = 0;
+ save = ctxt->flags;
+ ctxt->flags &= ~XML_VCTXT_USE_PCTXT;
/*
* Check all the NOTATION/NOTATIONS attributes
@@ -6672,7 +6688,7 @@ xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) {
ctxt->valid = 1;
xmlHashScan(table, xmlValidateCheckRefCallback, ctxt);
- ctxt->finishDtd = save;
+ ctxt->flags = save;
return(ctxt->valid);
}
@@ -7134,5 +7150,3 @@ xmlValidGetValidElements(xmlNode *prev, xmlNode *next, const xmlChar **names,
}
#endif /* LIBXML_VALID_ENABLED */
-#define bottom_valid
-#include "elfgcchack.h"