From eff45a92da861195551a2050487fcca0492cac7c Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 29 Oct 2004 12:10:55 +0000 Subject: [PATCH] register xmlSchemaSetValidErrors, patch from Brent Hendricks in the * python/libxml.c: register xmlSchemaSetValidErrors, patch from Brent Hendricks in the mailing-list * include/libxml/valid.h HTMLparser.c SAX2.c valid.c parserInternals.c: fix #156626 and more generally how to find out if a validation contect is part of a parsing context or not. This can probably be improved to make 100% sure that vctxt->userData is the parser context too. It's a bit hairy because we can't change the xmlValidCtxt structure without breaking the ABI since this change xmlParserCtxt information indexes. Daniel --- ChangeLog | 12 ++++++++++++ HTMLparser.c | 1 + NEWS | 4 +++- SAX2.c | 8 ++++---- configure.in | 2 ++ include/libxml/valid.h | 17 ++++++++++++++++- parserInternals.c | 1 + python/libxml.c | 1 + valid.c | 35 ++++++++++++++++++++++++++++++----- 9 files changed, 70 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7d7dc74..223f130d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Fri Oct 29 14:03:36 CEST 2004 Daniel Veillard + + * python/libxml.c: register xmlSchemaSetValidErrors, patch from + Brent Hendricks in the mailing-list + * include/libxml/valid.h HTMLparser.c SAX2.c valid.c + parserInternals.c: fix #156626 and more generally how to find out + if a validation contect is part of a parsing context or not. This + can probably be improved to make 100% sure that vctxt->userData + is the parser context too. It's a bit hairy because we can't + change the xmlValidCtxt structure without breaking the ABI since + this change xmlParserCtxt information indexes. + Wed Oct 27 19:26:20 CEST 2004 Daniel Veillard * ChangeLog NEWS configure.in doc/*: preparing release 2.6.15 diff --git a/HTMLparser.c b/HTMLparser.c index 947e4aa2..6022ed53 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -4136,6 +4136,7 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt) ctxt->replaceEntities = 0; ctxt->linenumbers = xmlLineNumbersDefaultValue; ctxt->html = 1; + ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0; ctxt->vctxt.userData = ctxt; ctxt->vctxt.error = xmlParserValidityError; ctxt->vctxt.warning = xmlParserValidityWarning; diff --git a/NEWS b/NEWS index 585a53f1..564afcb1 100644 --- a/NEWS +++ b/NEWS @@ -14,7 +14,9 @@ ChangeLog.html describes the recents commits to the CVS at http://cvs.gnome.org/viewcvs/libxml2/ - code base.There is the list of public releases:2.6.15: Oct 27 2004 - security fixes on the nanoftp and nanohttp modules + code base.There is the list of public releases: +2.6.15: Oct 27 2004: + - security fixes on the nanoftp and nanohttp modules - build fixes: xmllint detection bug in configure, building outside the source tree (Thomas Fitzsimmons) - bug fixes: HTML parser on broken ASCII chars in names (William), Python diff --git a/SAX2.c b/SAX2.c index cda9ac53..af36df9d 100644 --- a/SAX2.c +++ b/SAX2.c @@ -1562,7 +1562,7 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) * If it's the Document root, finish the DTD validation and * check the document root element for validity */ - if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) { + if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) { int chk; chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); @@ -1571,7 +1571,7 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) if (chk < 0) ctxt->wellFormed = 0; ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); - ctxt->vctxt.finishDtd = 1; + ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1; } #endif /* LIBXML_VALID_ENABLED */ @@ -2132,7 +2132,7 @@ xmlSAX2StartElementNs(void *ctx, * If it's the Document root, finish the DTD validation and * check the document root element for validity */ - if ((ctxt->validate) && (ctxt->vctxt.finishDtd == 0)) { + if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) { int chk; chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc); @@ -2141,7 +2141,7 @@ xmlSAX2StartElementNs(void *ctx, if (chk < 0) ctxt->wellFormed = 0; ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc); - ctxt->vctxt.finishDtd = 1; + ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1; } #endif /* LIBXML_VALID_ENABLED */ } diff --git a/configure.in b/configure.in index 64a6c0ea..ed6b94c4 100644 --- a/configure.in +++ b/configure.in @@ -446,7 +446,9 @@ if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XML" ]] || \ with_docbook="yes" fi fi + if test "${CC}" = "gcc" ; then CFLAGS="-g -O -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall" + fi STATIC_BINARIES="-static" dnl -Wcast-qual -ansi else diff --git a/include/libxml/valid.h b/include/libxml/valid.h index a734902e..99777d17 100644 --- a/include/libxml/valid.h +++ b/include/libxml/valid.h @@ -58,6 +58,21 @@ typedef void (*xmlValidityWarningFunc) (void *ctx, const char *msg, ...); +#ifdef IN_LIBXML +/** + * XML_CTXT_FINISH_DTD_0: + * + * Special value for finishDtd field when embedded in an xmlParserCtxt + */ +#define XML_CTXT_FINISH_DTD_0 0xabcd1234 +/** + * XML_CTXT_FINISH_DTD_1: + * + * Special value for finishDtd field when embedded in an xmlParserCtxt + */ +#define XML_CTXT_FINISH_DTD_1 0xabcd1235 +#endif + /* * xmlValidCtxt: * An xmlValidCtxt is used for error reporting when validating. @@ -75,7 +90,7 @@ struct _xmlValidCtxt { int nodeMax; /* Max depth of the parsing stack */ xmlNodePtr *nodeTab; /* array of nodes */ - int finishDtd; /* finished validating the Dtd ? */ + unsigned int finishDtd; /* finished validating the Dtd ? */ xmlDocPtr doc; /* the document */ int valid; /* temporary validity check result */ diff --git a/parserInternals.c b/parserInternals.c index 09f8bb8a..42db4115 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1630,6 +1630,7 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt) if (ctxt->keepBlanks == 0) ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace; + ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0; ctxt->vctxt.userData = ctxt; ctxt->vctxt.error = xmlParserValidityError; ctxt->vctxt.warning = xmlParserValidityWarning; diff --git a/python/libxml.c b/python/libxml.c index bb2649a4..9d33c771 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -3505,6 +3505,7 @@ static PyMethodDef libxmlMethods[] = { #ifdef LIBXML_SCHEMAS_ENABLED {(char *)"xmlRelaxNGSetValidErrors", libxml_xmlRelaxNGSetValidErrors, METH_VARARGS, NULL}, {(char *)"xmlRelaxNGFreeValidCtxt", libxml_xmlRelaxNGFreeValidCtxt, METH_VARARGS, NULL}, + {(char *)"xmlSchemaSetValidErrors", libxml_xmlSchemaSetValidErrors, METH_VARARGS, NULL}, #endif #ifdef LIBXML_C14N_ENABLED #ifdef LIBXML_OUTPUT_ENABLED diff --git a/valid.c b/valid.c index b8539929..3884c904 100644 --- a/valid.c +++ b/valid.c @@ -59,7 +59,12 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra) if (ctxt != NULL) { channel = ctxt->error; data = ctxt->userData; - pctxt = ctxt->userData; + /* Use the special values 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)) { + pctxt = ctxt->userData; + } } if (extra) __xmlRaiseError(NULL, channel, data, @@ -92,7 +97,12 @@ xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error, if (ctxt != NULL) { channel = ctxt->error; data = ctxt->userData; - pctxt = ctxt->userData; + /* Use the special values 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)) { + pctxt = ctxt->userData; + } } if (extra) __xmlRaiseError(NULL, channel, data, @@ -132,7 +142,12 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt, if (ctxt != NULL) { channel = ctxt->error; data = ctxt->userData; - pctxt = ctxt->userData; + /* Use the special values 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)) { + pctxt = ctxt->userData; + } } __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, XML_ERR_ERROR, NULL, 0, @@ -168,7 +183,12 @@ xmlErrValidNodeNr(xmlValidCtxtPtr ctxt, if (ctxt != NULL) { channel = ctxt->error; data = ctxt->userData; - pctxt = ctxt->userData; + /* Use the special values 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)) { + pctxt = ctxt->userData; + } } __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, XML_ERR_ERROR, NULL, 0, @@ -202,7 +222,12 @@ xmlErrValidWarning(xmlValidCtxtPtr ctxt, if (ctxt != NULL) { channel = ctxt->error; data = ctxt->userData; - pctxt = ctxt->userData; + /* Use the special values 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)) { + pctxt = ctxt->userData; + } } __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, XML_ERR_WARNING, NULL, 0,