Index: third_party/libxml/src/xmllint.c |
diff --git a/third_party/libxml/src/xmllint.c b/third_party/libxml/src/xmllint.c |
index 2a75e3bd53d69145c5f53d94159754a82062bc24..b297ded12f57bf0ab578f85ed03718e67da9b433 100644 |
--- a/third_party/libxml/src/xmllint.c |
+++ b/third_party/libxml/src/xmllint.c |
@@ -130,6 +130,7 @@ static int copy = 0; |
#endif /* LIBXML_TREE_ENABLED */ |
static int recovery = 0; |
static int noent = 0; |
+static int noenc = 0; |
static int noblanks = 0; |
static int noout = 0; |
static int nowrap = 0; |
@@ -162,10 +163,14 @@ static int html = 0; |
static int xmlout = 0; |
#endif |
static int htmlout = 0; |
+#if defined(LIBXML_HTML_ENABLED) |
+static int nodefdtd = 0; |
+#endif |
#ifdef LIBXML_PUSH_ENABLED |
static int push = 0; |
+static int pushsize = 4096; |
#endif /* LIBXML_PUSH_ENABLED */ |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
static int memory = 0; |
#endif |
static int testIO = 0; |
@@ -205,7 +210,7 @@ static xmlStreamCtxtPtr patstream = NULL; |
#ifdef LIBXML_XPATH_ENABLED |
static const char *xpathquery = NULL; |
#endif |
-static int options = XML_PARSE_COMPACT; |
+static int options = XML_PARSE_COMPACT | XML_PARSE_BIG_LINES; |
static int sax = 0; |
static int oldxml10 = 0; |
@@ -516,10 +521,11 @@ endTimer(char *format, ...) |
* We cannot do anything because we don't have a timing function |
*/ |
#ifdef HAVE_STDARG_H |
+ va_list ap; |
va_start(ap, format); |
vfprintf(stderr, format, ap); |
va_end(ap); |
- fprintf(stderr, " was not timed\n", msec); |
+ fprintf(stderr, " was not timed\n"); |
#else |
/* We don't have gettimeofday, time or stdarg.h, what crazy world is |
* this ?! |
@@ -1664,6 +1670,7 @@ testSAX(const char *filename) { |
(xmlSchemaValidityErrorFunc) fprintf, |
(xmlSchemaValidityWarningFunc) fprintf, |
stderr); |
+ xmlSchemaValidateSetFilename(vctxt, filename); |
ret = xmlSchemaValidateStream(vctxt, buf, 0, handler, |
(void *)user_data); |
@@ -1818,7 +1825,7 @@ static void processNode(xmlTextReaderPtr reader) { |
static void streamFile(char *filename) { |
xmlTextReaderPtr reader; |
int ret; |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
int fd = -1; |
struct stat info; |
const char *base = NULL; |
@@ -1830,8 +1837,12 @@ static void streamFile(char *filename) { |
if ((fd = open(filename, O_RDONLY)) < 0) |
return; |
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
- if (base == (void *) MAP_FAILED) |
+ if (base == (void *) MAP_FAILED) { |
+ close(fd); |
+ fprintf(stderr, "mmap failure for file %s\n", filename); |
+ progresult = XMLLINT_ERR_RDFILE; |
return; |
+ } |
reader = xmlReaderForMemory(base, info.st_size, filename, |
NULL, options); |
@@ -1868,7 +1879,8 @@ static void streamFile(char *filename) { |
xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); |
else |
#endif /* LIBXML_VALID_ENABLED */ |
- xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); |
+ if (loaddtd) |
+ xmlTextReaderSetParserProp(reader, XML_PARSER_LOADDTD, 1); |
#ifdef LIBXML_SCHEMAS_ENABLED |
if (relaxng != NULL) { |
if ((timing) && (!repeat)) { |
@@ -1969,7 +1981,7 @@ static void streamFile(char *filename) { |
patstream = NULL; |
} |
#endif |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
if (memory) { |
xmlFreeParserInputBuffer(input); |
munmap((char *) base, info.st_size); |
@@ -2069,7 +2081,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) { |
#ifdef LIBXML_OUTPUT_ENABLED |
xmlSaveCtxtPtr ctxt; |
- if (cur->nodesetval->nodeNr <= 0) { |
+ if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) { |
fprintf(stderr, "XPath set is empty\n"); |
progresult = XMLLINT_ERR_XPATH; |
break; |
@@ -2134,7 +2146,7 @@ static void doXPathQuery(xmlDocPtr doc, const char *query) { |
progresult = XMLLINT_ERR_MEM; |
return; |
} |
- ctxt->node = xmlDocGetRootElement(doc); |
+ ctxt->node = (xmlNodePtr) doc; |
res = xmlXPathEval(BAD_CAST query, ctxt); |
xmlXPathFreeContext(ctxt); |
@@ -2182,21 +2194,22 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
f = fopen(filename, "rb"); |
+#elif defined(__OS400__) |
+ f = fopen(filename, "rb"); |
#else |
f = fopen(filename, "r"); |
#endif |
if (f != NULL) { |
- int res, size = 3; |
+ int res; |
char chars[4096]; |
htmlParserCtxtPtr ctxt; |
- /* if (repeat) */ |
- size = 4096; |
res = fread(chars, 1, 4, f); |
if (res > 0) { |
ctxt = htmlCreatePushParserCtxt(NULL, NULL, |
chars, res, filename, XML_CHAR_ENCODING_NONE); |
- while ((res = fread(chars, 1, size, f)) > 0) { |
+ xmlCtxtUseOptions(ctxt, options); |
+ while ((res = fread(chars, 1, pushsize, f)) > 0) { |
htmlParseChunk(ctxt, chars, res, 0); |
} |
htmlParseChunk(ctxt, chars, 0, 1); |
@@ -2207,7 +2220,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
} |
} |
#endif /* LIBXML_PUSH_ENABLED */ |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
else if ((html) && (memory)) { |
int fd; |
struct stat info; |
@@ -2217,8 +2230,12 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
if ((fd = open(filename, O_RDONLY)) < 0) |
return; |
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
- if (base == (void *) MAP_FAILED) |
+ if (base == (void *) MAP_FAILED) { |
+ close(fd); |
+ fprintf(stderr, "mmap failure for file %s\n", filename); |
+ progresult = XMLLINT_ERR_RDFILE; |
return; |
+ } |
doc = htmlReadMemory((char *) base, info.st_size, filename, |
NULL, options); |
@@ -2245,6 +2262,8 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
} else { |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
f = fopen(filename, "rb"); |
+#elif defined(__OS400__) |
+ f = fopen(filename, "rb"); |
#else |
f = fopen(filename, "r"); |
#endif |
@@ -2286,6 +2305,8 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
f = fopen(filename, "rb"); |
+#elif defined(__OS400__) |
+ f = fopen(filename, "rb"); |
#else |
f = fopen(filename, "r"); |
#endif |
@@ -2322,7 +2343,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
if (rectxt == NULL) |
xmlFreeParserCtxt(ctxt); |
} |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
} else if (memory) { |
int fd; |
struct stat info; |
@@ -2332,8 +2353,12 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
if ((fd = open(filename, O_RDONLY)) < 0) |
return; |
base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; |
- if (base == (void *) MAP_FAILED) |
+ if (base == (void *) MAP_FAILED) { |
+ close(fd); |
+ fprintf(stderr, "mmap failure for file %s\n", filename); |
+ progresult = XMLLINT_ERR_RDFILE; |
return; |
+ } |
if (rectxt == NULL) |
doc = xmlReadMemory((char *) base, info.st_size, |
@@ -2507,14 +2532,14 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
htmlSaveFile(output ? output : "-", doc); |
} |
else if (encoding != NULL) { |
- if ( format ) { |
+ if (format == 1) { |
htmlSaveFileFormat(output ? output : "-", doc, encoding, 1); |
} |
else { |
htmlSaveFileFormat(output ? output : "-", doc, encoding, 0); |
} |
} |
- else if (format) { |
+ else if (format == 1) { |
htmlSaveFileFormat(output ? output : "-", doc, NULL, 1); |
} |
else { |
@@ -2547,19 +2572,23 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_0, NULL, 1, &result); |
if (size >= 0) { |
- write(1, result, size); |
+ if (write(1, result, size) == -1) { |
+ fprintf(stderr, "Can't write data\n"); |
+ } |
xmlFree(result); |
} else { |
fprintf(stderr, "Failed to canonicalize\n"); |
progresult = XMLLINT_ERR_OUT; |
} |
- } else if (canonical) { |
+ } else if (canonical_11) { |
xmlChar *result = NULL; |
int size; |
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_1, NULL, 1, &result); |
if (size >= 0) { |
- write(1, result, size); |
+ if (write(1, result, size) == -1) { |
+ fprintf(stderr, "Can't write data\n"); |
+ } |
xmlFree(result); |
} else { |
fprintf(stderr, "Failed to canonicalize\n"); |
@@ -2572,7 +2601,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_EXCLUSIVE_1_0, NULL, 1, &result); |
if (size >= 0) { |
- write(1, result, size); |
+ if (write(1, result, size) == -1) { |
+ fprintf(stderr, "Can't write data\n"); |
+ } |
xmlFree(result); |
} else { |
fprintf(stderr, "Failed to canonicalize\n"); |
@@ -2580,19 +2611,19 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
} |
} else |
#endif |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
if (memory) { |
xmlChar *result; |
int len; |
if (encoding != NULL) { |
- if ( format ) { |
+ if (format == 1) { |
xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); |
} else { |
xmlDocDumpMemoryEnc(doc, &result, &len, encoding); |
} |
} else { |
- if (format) |
+ if (format == 1) |
xmlDocDumpFormatMemory(doc, &result, &len, 1); |
else |
xmlDocDumpMemory(doc, &result, &len); |
@@ -2601,17 +2632,19 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
fprintf(stderr, "Failed to save\n"); |
progresult = XMLLINT_ERR_OUT; |
} else { |
- write(1, result, len); |
+ if (write(1, result, len) == -1) { |
+ fprintf(stderr, "Can't write data\n"); |
+ } |
xmlFree(result); |
} |
} else |
-#endif /* HAVE_SYS_MMAN_H */ |
+#endif /* HAVE_MMAP */ |
if (compress) { |
xmlSaveFile(output ? output : "-", doc); |
} else if (oldout) { |
if (encoding != NULL) { |
- if ( format ) { |
+ if (format == 1) { |
ret = xmlSaveFormatFileEnc(output ? output : "-", doc, |
encoding, 1); |
} |
@@ -2624,7 +2657,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
output ? output : "-"); |
progresult = XMLLINT_ERR_OUT; |
} |
- } else if (format) { |
+ } else if (format == 1) { |
ret = xmlSaveFormatFile(output ? output : "-", doc, 1); |
if (ret < 0) { |
fprintf(stderr, "failed save to %s\n", |
@@ -2653,8 +2686,10 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { |
xmlSaveCtxtPtr ctxt; |
int saveOpts = 0; |
- if (format) |
+ if (format == 1) |
saveOpts |= XML_SAVE_FORMAT; |
+ else if (format == 2) |
+ saveOpts |= XML_SAVE_WSNONSIG; |
#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED) |
if (xmlout) |
@@ -2944,6 +2979,7 @@ static void showVersion(const char *name) { |
if (xmlHasFeature(XML_WITH_DEBUG_MEM)) fprintf(stderr, "MemDebug "); |
if (xmlHasFeature(XML_WITH_DEBUG_RUN)) fprintf(stderr, "RunDebug "); |
if (xmlHasFeature(XML_WITH_ZLIB)) fprintf(stderr, "Zlib "); |
+ if (xmlHasFeature(XML_WITH_LZMA)) fprintf(stderr, "Lzma "); |
fprintf(stderr, "\n"); |
} |
@@ -2970,9 +3006,10 @@ static void usage(const char *name) { |
printf("\t--recover : output what was parsable on broken XML documents\n"); |
printf("\t--huge : remove any internal arbitrary parser limits\n"); |
printf("\t--noent : substitute entity references by their value\n"); |
+ printf("\t--noenc : ignore any encoding specified inside the document\n"); |
printf("\t--noout : don't output the result tree\n"); |
printf("\t--path 'paths': provide a set of paths for resources\n"); |
- printf("\t--load-trace : print trace of all external entites loaded\n"); |
+ printf("\t--load-trace : print trace of all external entities loaded\n"); |
printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); |
printf("\t--nocompact : do not generate compact text nodes\n"); |
printf("\t--htmlout : output results as HTML\n"); |
@@ -2995,11 +3032,13 @@ static void usage(const char *name) { |
#ifdef LIBXML_HTML_ENABLED |
printf("\t--html : use the HTML parser\n"); |
printf("\t--xmlout : force to use the XML serializer when using --html\n"); |
+ printf("\t--nodefdtd : do not default HTML doctype\n"); |
#endif |
#ifdef LIBXML_PUSH_ENABLED |
printf("\t--push : use the push mode of the parser\n"); |
+ printf("\t--pushsmall : use the push mode of the parser using tiny increments\n"); |
#endif /* LIBXML_PUSH_ENABLED */ |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
printf("\t--memory : parse from memory\n"); |
#endif |
printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n"); |
@@ -3010,6 +3049,10 @@ static void usage(const char *name) { |
printf("\t--format : reformat/reindent the input\n"); |
printf("\t--encode encoding : output in the given encoding\n"); |
printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); |
+ printf("\t--pretty STYLE : pretty-print in a particular style\n"); |
+ printf("\t 0 Do not pretty print\n"); |
+ printf("\t 1 Format the XML content, as --format\n"); |
+ printf("\t 2 Add whitespace inside tags, preserving content\n"); |
#endif /* LIBXML_OUTPUT_ENABLED */ |
printf("\t--c14n : save in W3C canonical format v1.0 (with comments)\n"); |
printf("\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n"); |
@@ -3053,7 +3096,7 @@ static void usage(const char *name) { |
printf("\t--sax: do not build a tree but work just at the SAX level\n"); |
printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n"); |
#ifdef LIBXML_XPATH_ENABLED |
- printf("\t--xpath expr: evaluate the XPath expression, inply --noout\n"); |
+ printf("\t--xpath expr: evaluate the XPath expression, imply --noout\n"); |
#endif |
printf("\nLibxml project home page: http://xmlsoft.org/\n"); |
@@ -3063,6 +3106,10 @@ static void usage(const char *name) { |
static void registerNode(xmlNodePtr node) |
{ |
node->_private = malloc(sizeof(long)); |
+ if (node->_private == NULL) { |
+ fprintf(stderr, "Out of memory in xmllint:registerNode()\n"); |
+ exit(XMLLINT_ERR_MEM); |
+ } |
*(long*)node->_private = (long) 0x81726354; |
nbregister++; |
} |
@@ -3119,6 +3166,10 @@ main(int argc, char **argv) { |
(!strcmp(argv[i], "--noent"))) { |
noent++; |
options |= XML_PARSE_NOENT; |
+ } else if ((!strcmp(argv[i], "-noenc")) || |
+ (!strcmp(argv[i], "--noenc"))) { |
+ noenc++; |
+ options |= XML_PARSE_IGNORE_ENC; |
} else if ((!strcmp(argv[i], "-nsclean")) || |
(!strcmp(argv[i], "--nsclean"))) { |
options |= XML_PARSE_NSCLEAN; |
@@ -3157,6 +3208,10 @@ main(int argc, char **argv) { |
else if ((!strcmp(argv[i], "-xmlout")) || |
(!strcmp(argv[i], "--xmlout"))) { |
xmlout++; |
+ } else if ((!strcmp(argv[i], "-nodefdtd")) || |
+ (!strcmp(argv[i], "--nodefdtd"))) { |
+ nodefdtd++; |
+ options |= HTML_PARSE_NODEFDTD; |
} |
#endif /* LIBXML_HTML_ENABLED */ |
else if ((!strcmp(argv[i], "-loaddtd")) || |
@@ -3216,8 +3271,13 @@ main(int argc, char **argv) { |
else if ((!strcmp(argv[i], "-push")) || |
(!strcmp(argv[i], "--push"))) |
push++; |
+ else if ((!strcmp(argv[i], "-pushsmall")) || |
+ (!strcmp(argv[i], "--pushsmall"))) { |
+ push++; |
+ pushsize = 10; |
+ } |
#endif /* LIBXML_PUSH_ENABLED */ |
-#ifdef HAVE_SYS_MMAN_H |
+#ifdef HAVE_MMAP |
else if ((!strcmp(argv[i], "-memory")) || |
(!strcmp(argv[i], "--memory"))) |
memory++; |
@@ -3309,8 +3369,9 @@ main(int argc, char **argv) { |
} |
else if ((!strcmp(argv[i], "-noblanks")) || |
(!strcmp(argv[i], "--noblanks"))) { |
- noblanks++; |
- xmlKeepBlanksDefault(0); |
+ noblanks++; |
+ xmlKeepBlanksDefault(0); |
+ options |= XML_PARSE_NOBLANKS; |
} |
else if ((!strcmp(argv[i], "-maxmem")) || |
(!strcmp(argv[i], "--maxmem"))) { |
@@ -3326,10 +3387,23 @@ main(int argc, char **argv) { |
(!strcmp(argv[i], "--format"))) { |
noblanks++; |
#ifdef LIBXML_OUTPUT_ENABLED |
- format++; |
+ format = 1; |
#endif /* LIBXML_OUTPUT_ENABLED */ |
xmlKeepBlanksDefault(0); |
} |
+ else if ((!strcmp(argv[i], "-pretty")) || |
+ (!strcmp(argv[i], "--pretty"))) { |
+ i++; |
+#ifdef LIBXML_OUTPUT_ENABLED |
+ if (argv[i] != NULL) { |
+ format = atoi(argv[i]); |
+ if (format == 1) { |
+ noblanks++; |
+ xmlKeepBlanksDefault(0); |
+ } |
+ } |
+#endif /* LIBXML_OUTPUT_ENABLED */ |
+ } |
#ifdef LIBXML_READER_ENABLED |
else if ((!strcmp(argv[i], "-stream")) || |
(!strcmp(argv[i], "--stream"))) { |
@@ -3616,6 +3690,11 @@ main(int argc, char **argv) { |
i++; |
continue; |
} |
+ if ((!strcmp(argv[i], "-pretty")) || |
+ (!strcmp(argv[i], "--pretty"))) { |
+ i++; |
+ continue; |
+ } |
if ((!strcmp(argv[i], "-schema")) || |
(!strcmp(argv[i], "--schema"))) { |
i++; |