From e8b09e40f7ece62231641a0607e6b777db17f0d7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard <veillard@src.gnome.org> Date: Tue, 13 May 2003 22:14:13 +0000 Subject: [PATCH] added --nonet option fixing #112803 by adding --nonet when calling * xmllint.c doc/xmllint.xml: added --nonet option * doc/Makefile.am: fixing #112803 by adding --nonet when calling xsltproc or xmllint * doc/xmllint.xml doc/xmllint.1: also added --schema doc and rebuilt * HTMLparser.c: cleaned up the HTML parser context build when using an URL Daniel --- ChangeLog | 10 ++++++++++ HTMLparser.c | 31 ++++++++++++++----------------- doc/Makefile.am | 14 +++++++------- doc/xmllint.1 | 11 ++++++++++- doc/xmllint.xml | 15 +++++++++++++++ xmllint.c | 4 ++++ 6 files changed, 60 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index e112aba2..3089f26b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue May 13 18:10:38 EDT 2003 Daniel Veillard <daniel@veillard.com> + + * xmllint.c doc/xmllint.xml: added --nonet option + * doc/Makefile.am: fixing #112803 by adding --nonet when calling + xsltproc or xmllint + * doc/xmllint.xml doc/xmllint.1: also added --schema doc and + rebuilt + * HTMLparser.c: cleaned up the HTML parser context build when + using an URL + Tue May 13 16:35:04 EDT 2003 Daniel Veillard <daniel@veillard.com> * libxml.spec.in: added a comment about bug #112902 diff --git a/HTMLparser.c b/HTMLparser.c index f46cd661..f65084b5 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -5348,6 +5348,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding) htmlParserCtxtPtr ctxt; htmlParserInputPtr inputStream; xmlParserInputBufferPtr buf; + char *canonicFilename; /* htmlCharEncoding enc; */ xmlChar *content, *content_line = (xmlChar *) "charset="; @@ -5361,27 +5362,23 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding) } memset(ctxt, 0, sizeof(htmlParserCtxt)); htmlInitParserCtxt(ctxt); - inputStream = (htmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput)); - if (inputStream == NULL) { - xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); - xmlFree(ctxt); + canonicFilename = (char *) xmlCanonicPath((const xmlChar *) filename); + if (canonicFilename == NULL) { + if (xmlDefaultSAXHandler.error != NULL) { + xmlDefaultSAXHandler.error(NULL, "out of memory\n"); + } + return(NULL); + } + + inputStream = xmlLoadExternalEntity(canonicFilename, NULL, ctxt); + xmlFree(canonicFilename); + if (inputStream == NULL) { + xmlFreeParserCtxt(ctxt); return(NULL); } - memset(inputStream, 0, sizeof(htmlParserInput)); - - inputStream->filename = (char *) - xmlCanonicPath((xmlChar *)filename); - inputStream->line = 1; - inputStream->col = 1; - inputStream->buf = buf; - inputStream->directory = NULL; - - inputStream->base = inputStream->buf->buffer->content; - inputStream->cur = inputStream->buf->buffer->content; - inputStream->free = NULL; inputPush(ctxt, inputStream); - + /* set encoding */ if (encoding) { content = xmlMallocAtomic (xmlStrlen(content_line) + strlen(encoding) + 1); diff --git a/doc/Makefile.am b/doc/Makefile.am index 6a81498c..77c68453 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -33,27 +33,27 @@ web: $(PAGES) $(APIPAGES) $(PAGES): xml.html site.xsl -@(if [ -x $(bindir)/xsltproc ] ; then \ - $(bindir)/xsltproc --html $(top_srcdir)/doc/site.xsl $(top_srcdir)/doc/xml.html > index.html ; fi ); + $(bindir)/xsltproc --nonet --html $(top_srcdir)/doc/site.xsl $(top_srcdir)/doc/xml.html > index.html ; fi ); -@(if [ -x $(bindir)/xmllint ] ; then \ - $(bindir)/xmllint --valid --noout $(PAGES) ; fi ); + $(bindir)/xmllint --nonet --valid --noout $(PAGES) ; fi ); $(top_srcdir)/NEWS: $(top_srcdir)/doc/news.xsl $(top_srcdir)/doc/news.html -@(if [ -x $(bindir)/xsltproc ] ; then \ - $(bindir)/xsltproc $(top_srcdir)/doc/news.xsl $(top_srcdir)/doc/news.html > $(top_srcdir)/NEWS ; fi ); + $(bindir)/xsltproc --nonet $(top_srcdir)/doc/news.xsl $(top_srcdir)/doc/news.html > $(top_srcdir)/NEWS ; fi ); libxml2.xsa: $(top_srcdir)/doc/xsa.xsl $(top_srcdir)/doc/news.html -@(if [ -x $(bindir)/xsltproc ] ; then \ - $(bindir)/xsltproc $(top_srcdir)/doc/xsa.xsl $(top_srcdir)/doc/news.html > libxml2.xsa ; fi ); + $(bindir)/xsltproc --nonet $(top_srcdir)/doc/xsa.xsl $(top_srcdir)/doc/news.html > libxml2.xsa ; fi ); $(APIPAGES): libxml2-refs.xml site.xsl api.xsl -@(if [ -x $(bindir)/xsltproc ] ; then \ - $(bindir)/xsltproc --html $(top_srcdir)/doc/api.xsl $(top_srcdir)/doc/xml.html ; fi ); + $(bindir)/xsltproc --nonet --html $(top_srcdir)/doc/api.xsl $(top_srcdir)/doc/xml.html ; fi ); xmllint.1: xmllint.xml - -@(xsltproc xmllint.xml) + -@(xsltproc --nonet xmllint.xml) xmlcatalog.1: xmlcatalog_man.xml - -@(xsltproc xmlcatalog_man.xml) + -@(xsltproc --nonet xmlcatalog_man.xml) scan: -gtkdoc-scan --module=libxml --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="acconfig.h config.h win32config.h trio.h triostr.h triop.h config-mac.h XMLTestPrefix2.h XMLTestPrefix.h triodef.h trionan.h xlink.h libxml.h libxml2-py.h libxml_wrap.h" diff --git a/doc/xmllint.1 b/doc/xmllint.1 index 7b06defe..362ef739 100644 --- a/doc/xmllint.1 +++ b/doc/xmllint.1 @@ -31,7 +31,8 @@ xmllint \- command line XML tool | \fB--noblanks\fR | \fB--format\fR | \fB--testIO\fR | \fB--encode \fIencoding\fR\fR | \fB--catalogs\fR | \fB--nocatalogs\fR | \fB--auto\fR | \fB--xinclude\fR | \fB--loaddtd\fR | \fB--dtdattr\fR | \fB--dropdtd\fR | \fB--stream\fR - | \fB--chkregister\fR | \fB--relaxng\fR] [\fBxmlfile\fR] + | \fB--chkregister\fR | \fB--relaxng\fR | \fB--schema\fR | \fB--nonet\fR] + [\fBxmlfile\fR] .fi .SH "INTRODUCTION" @@ -188,6 +189,14 @@ Turn on node registration. Useful for developeres testing libxml2 node tracking \fB--relaxng\fR \fIschema\fR Use RelaxNG file named \fIschema\fR for validation. +.TP +\fB--schema\fR \fIschema\fR +Use a W3C XML Schema file named \fIschema\fR for validation. + +.TP +\fB--nonet\fR +Do not use the Internet to fetch DTD's or entities. + .SH "SHELL" .PP diff --git a/doc/xmllint.xml b/doc/xmllint.xml index 3ab1467d..9bb9f87e 100644 --- a/doc/xmllint.xml +++ b/doc/xmllint.xml @@ -79,6 +79,8 @@ <arg>--stream</arg> <arg>--chkregister</arg> <arg>--relaxng</arg> + <arg>--schema</arg> + <arg>--nonet</arg> </group> <arg><option><replaceable>xmlfile</replaceable></option></arg> </cmdsynopsis> @@ -441,6 +443,19 @@ validation.</simpara> </listitem> </varlistentry> + <varlistentry> + <term><option>--schema</option> <replaceable>schema</replaceable></term> + <listitem> + <simpara>Use a W3C XML Schema file named <replaceable>schema</replaceable> for validation.</simpara> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>--nonet</option></term> + <listitem> + <simpara>Do not use the Internet to fetch DTD's or entities.</simpara> + </listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/xmllint.c b/xmllint.c index 9fedb4fa..1a871155 100644 --- a/xmllint.c +++ b/xmllint.c @@ -1260,6 +1260,7 @@ static void usage(const char *name) { printf("\t--recover : output what was parsable on broken XML documents\n"); printf("\t--noent : substitute entity references by their value\n"); printf("\t--noout : don't output the result tree\n"); + printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); printf("\t--htmlout : output results as HTML\n"); printf("\t--nowrap : do not put HTML doc wrapper\n"); printf("\t--valid : validate the document in addition to std well-formed check\n"); @@ -1513,6 +1514,9 @@ main(int argc, char **argv) { schema = argv[i]; noent++; #endif + } else if ((!strcmp(argv[i], "-nonet")) || + (!strcmp(argv[i], "--nonet"))) { + xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader); } else { fprintf(stderr, "Unknown option %s\n", argv[i]); usage(argv[0]);