Commit 659e71ec authored by Daniel Veillard's avatar Daniel Veillard
Browse files

Setting up the framework for structured error reporting, touches a lot of

* HTMLparser.c c14n.c catalog.c error.c globals.c parser.c
  parserInternals.c relaxng.c valid.c xinclude.c xmlIO.c xmlregexp.c
  xmlschemas.c xpath.c xpointer.c include/libxml/globals.h
  include/libxml/parser.h include/libxml/valid.h
  include/libxml/xmlerror.h: Setting up the framework for structured
  error reporting, touches a lot of modules, but little code now
  the error handling trail has been cleaned up.
Daniel
parent d96cce1a
Fri Oct 10 16:08:02 CEST 2003 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c c14n.c catalog.c error.c globals.c parser.c
parserInternals.c relaxng.c valid.c xinclude.c xmlIO.c xmlregexp.c
xmlschemas.c xpath.c xpointer.c include/libxml/globals.h
include/libxml/parser.h include/libxml/valid.h
include/libxml/xmlerror.h: Setting up the framework for structured
error reporting, touches a lot of modules, but little code now
the error handling trail has been cleaned up.
Fri Oct 10 14:29:42 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
* c14n.c include/libxml/xmlerror.h: converted the C14N module too
......
......@@ -79,12 +79,12 @@ htmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
ctxt->disableSAX = 1;
}
if (extra)
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
}
......@@ -104,7 +104,7 @@ htmlParseErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1, const xmlChar *str2)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str2,
NULL, 0, 0,
......@@ -126,7 +126,7 @@ htmlParseErrInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, int val)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_HTML, error,
XML_ERR_ERROR, NULL, 0, NULL, NULL,
NULL, val, 0, msg, val);
ctxt->wellFormed = 0;
......
......@@ -132,7 +132,7 @@ static xmlChar *xmlC11NNormalizeString(const xmlChar * input,
static void
xmlC14NErrMemory(const char *extra)
{
__xmlRaiseError(NULL, NULL, NULL, NULL, XML_FROM_C14N,
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N,
XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
......@@ -154,7 +154,7 @@ xmlC14NErr(xmlC14NCtxPtr ctxt, xmlNodePtr node, int error,
{
if (ctxt != NULL)
ctxt->error = error;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, node, XML_FROM_C14N, error,
XML_ERR_ERROR, NULL, 0,
NULL, NULL, NULL, 0, 0, msg);
......@@ -1490,7 +1490,7 @@ xmlC14NNewCtx(xmlDocPtr doc,
int exclusive, xmlChar ** inclusive_ns_prefixes,
int with_comments, xmlOutputBufferPtr buf)
{
xmlC14NCtxPtr ctx;
xmlC14NCtxPtr ctx = NULL;
if ((doc == NULL) || (buf == NULL)) {
#ifdef DEBUG_C14N
......
......@@ -197,7 +197,7 @@ static int xmlCatalogInitialized = 0;
static void
xmlCatalogErrMemory(const char *extra)
{
__xmlRaiseError(NULL, NULL, NULL, NULL, XML_FROM_CATALOG,
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_CATALOG,
XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0,
extra, NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
......@@ -217,7 +217,7 @@ xmlCatalogErr(xmlCatalogEntryPtr catal, xmlNodePtr node, int error,
const char *msg, const xmlChar *str1, const xmlChar *str2,
const xmlChar *str3)
{
__xmlRaiseError(NULL, NULL, catal, node, XML_FROM_CATALOG,
__xmlRaiseError(NULL, NULL, NULL, catal, node, XML_FROM_CATALOG,
error, XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str2,
(const char *) str3, 0, 0,
......
......@@ -112,6 +112,23 @@ xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
xmlGenericError = xmlGenericErrorDefaultFunc;
}
/**
* xmlSetStructuredErrorFunc:
* @ctx: the new error handling context
* @handler: the new handler function
*
* Function to reset the handler and the error context for out of
* context structured error messages.
* This simply means that @handler will be called for subsequent
* error messages while not parsing nor validating. And @ctx will
* be passed as first argument to @handler
*/
void
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
xmlGenericErrorContext = ctx;
xmlStructuredError = handler;
}
/************************************************************************
* *
* Handling of parsing errors *
......@@ -392,7 +409,8 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
/**
* __xmlRaiseError:
* @channel: the callback channel
* @channel: the structured callback channel
* @channel: the old callback channel
* @data: the callback data
* @ctx: the parser context or NULL
* @ctx: the parser context or NULL
......@@ -414,7 +432,8 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
* error callback handler
*/
void
__xmlRaiseError(xmlGenericErrorFunc channel, void *data, void *ctx,
__xmlRaiseError(xmlStructuredErrorFunc schannel,
xmlGenericErrorFunc channel, void *data, void *ctx,
void *nod, int domain, int code, xmlErrorLevel level,
const char *file, int line, const char *str1,
const char *str2, const char *str3, int int1, int int2,
......@@ -431,6 +450,9 @@ __xmlRaiseError(xmlGenericErrorFunc channel, void *data, void *ctx,
(domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
(domain == XML_FROM_IO)) {
ctxt = (xmlParserCtxtPtr) ctx;
if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
(ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
}
if (code == XML_ERR_OK)
return;
......@@ -512,9 +534,16 @@ __xmlRaiseError(xmlGenericErrorFunc channel, void *data, void *ctx,
channel = ctxt->sax->error;
data = ctxt->userData;
} else if (channel == NULL) {
channel = xmlGenericError;
if (xmlStructuredError != NULL)
schannel = xmlStructuredError;
else
channel = xmlGenericError;
data = xmlGenericErrorContext;
}
if (schannel != NULL) {
schannel(data, to);
return;
}
if (channel == NULL)
return;
......@@ -546,16 +575,16 @@ __xmlSimpleError(int domain, int code, xmlNodePtr node,
if (code == XML_ERR_NO_MEMORY) {
if (extra)
__xmlRaiseError(NULL, NULL, NULL, node, domain,
__xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(NULL, NULL, NULL, node, domain,
__xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
} else {
__xmlRaiseError(NULL, NULL, NULL, node, domain,
__xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
code, XML_ERR_ERROR, NULL, 0, extra,
NULL, NULL, 0, 0, msg, extra);
}
......
......@@ -136,6 +136,7 @@ xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
#undef xmlDefaultSAXLocator
#undef xmlDoValidityCheckingDefaultValue
#undef xmlGenericError
#undef xmlStructuredError
#undef xmlGenericErrorContext
#undef xmlGetWarningsDefaultValue
#undef xmlIndentTreeOutput
......@@ -287,6 +288,13 @@ void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED,
*/
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
/**
* xmlStructuredError:
*
* Global setting: function used for structured error callbacks
*/
xmlStructuredErrorFunc xmlStructuredError = NULL;
static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL;
/**
* xmlGenericErrorContext:
*
......@@ -523,6 +531,7 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
xmlSubstituteEntitiesDefaultValueThrDef;
gs->xmlGenericError = xmlGenericErrorThrDef;
gs->xmlStructuredError = xmlStructuredErrorThrDef;
gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
......@@ -542,6 +551,14 @@ xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
xmlMutexUnlock(xmlThrDefMutex);
}
void
xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
xmlMutexLock(xmlThrDefMutex);
xmlGenericErrorContextThrDef = ctx;
xmlStructuredErrorThrDef = handler;
xmlMutexUnlock(xmlThrDefMutex);
}
/**
* xmlRegisterNodeDefault:
* @func: function pointer to the new RegisterNodeFunc
......@@ -736,6 +753,15 @@ __xmlGenericError(void) {
return (&xmlGetGlobalState()->xmlGenericError);
}
#undef xmlStructuredError
xmlStructuredErrorFunc *
__xmlStructuredError(void) {
if (IS_MAIN_THREAD)
return (&xmlStructuredError);
else
return (&xmlGetGlobalState()->xmlStructuredError);
}
#undef xmlGenericErrorContext
void * *
__xmlGenericErrorContext(void) {
......
......@@ -42,6 +42,7 @@ XMLPUBFUN void XMLCALL xmlCleanupGlobals(void);
#undef xmlDoValidityCheckingDefaultValue
#undef xmlFree
#undef xmlGenericError
#undef xmlStructuredError
#undef xmlGenericErrorContext
#undef xmlGetWarningsDefaultValue
#undef xmlIndentTreeOutput
......@@ -82,6 +83,7 @@ struct _xmlGlobalState
xmlReallocFunc xmlRealloc;
xmlGenericErrorFunc xmlGenericError;
xmlStructuredErrorFunc xmlStructuredError;
void *xmlGenericErrorContext;
int oldXMLWDcompatibility;
......@@ -121,6 +123,8 @@ XMLPUBFUN void XMLCALL xmlInitializeGlobalState(xmlGlobalStatePtr gs);
XMLPUBFUN void XMLCALL xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
XMLPUBFUN void XMLCALL xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler);
XMLPUBFUN xmlRegisterNodeFunc XMLCALL xmlRegisterNodeDefault(xmlRegisterNodeFunc func);
XMLPUBFUN xmlRegisterNodeFunc XMLCALL xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func);
XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func);
......@@ -279,6 +283,14 @@ XMLPUBFUN xmlGenericErrorFunc * XMLCALL __xmlGenericError(void);
XMLPUBVAR xmlGenericErrorFunc xmlGenericError;
#endif
XMLPUBFUN xmlStructuredErrorFunc * XMLCALL __xmlStructuredError(void);
#ifdef LIBXML_THREAD_ENABLED
#define xmlStructuredError \
(*(__xmlStructuredError()))
#else
XMLPUBVAR xmlStructuredErrorFunc xmlStructuredError;
#endif
XMLPUBFUN void * * XMLCALL __xmlGenericErrorContext(void);
#ifdef LIBXML_THREAD_ENABLED
#define xmlGenericErrorContext \
......
......@@ -716,6 +716,7 @@ struct _xmlSAXHandler {
void *_private;
startElementNsSAX2Func startElementNs;
endElementNsSAX2Func endElementNs;
xmlStructuredErrorFunc serror;
};
/*
......
......@@ -11,6 +11,7 @@
#define __XML_VALID_H__
#include <libxml/xmlversion.h>
#include <libxml/xmlerror.h>
#include <libxml/tree.h>
#include <libxml/list.h>
#include <libxml/xmlautomata.h>
......@@ -86,6 +87,8 @@ struct _xmlValidCtxt {
void *am;
void *state;
#endif
xmlStructuredErrorFunc serror; /* structured error reporting capability */
};
/*
......
......@@ -580,6 +580,9 @@ XMLPUBFUN void XMLCALL
XMLPUBFUN void XMLCALL
initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);
XMLPUBFUN void XMLCALL
xmlSetStructuredErrorFunc (void *ctx,
xmlStructuredErrorFunc handler);
/*
* Default message routines used by SAX and Valid context for error
* and warning reporting.
......@@ -627,7 +630,8 @@ XMLPUBFUN int XMLCALL
* Internal callback reporting routine
*/
XMLPUBFUN void XMLCALL
__xmlRaiseError (xmlGenericErrorFunc channel,
__xmlRaiseError (xmlStructuredErrorFunc schannel,
xmlGenericErrorFunc channel,
void *data,
void *ctx,
void *node,
......
......@@ -142,12 +142,12 @@ xmlErrAttributeDup(xmlParserCtxtPtr ctxt, const xmlChar * prefix,
{
ctxt->errNo = XML_ERR_ATTRIBUTE_REDEFINED;
if (prefix == NULL)
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
ctxt->errNo, XML_ERR_FATAL, NULL, 0,
(const char *) localname, NULL, NULL, 0, 0,
"Attribute %s redefined\n", localname);
else
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
ctxt->errNo, XML_ERR_FATAL, NULL, 0,
(const char *) prefix, (const char *) localname,
NULL, 0, 0, "Attribute %s:%s redefined\n", prefix,
......@@ -350,7 +350,7 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
errmsg = "Unregistered error message\n";
}
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg,
info);
ctxt->wellFormed = 0;
......@@ -371,7 +371,7 @@ xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0)
......@@ -393,7 +393,9 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1, const xmlChar *str2)
{
ctxt->errNo = error;
__xmlRaiseError((ctxt->sax) ? ctxt->sax->warning : NULL, ctxt->userData,
__xmlRaiseError((ctxt->sax) ? ctxt->sax->serror : NULL,
(ctxt->sax) ? ctxt->sax->warning : NULL,
ctxt->userData,
ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_WARNING, NULL, 0,
(const char *) str1, (const char *) str2, NULL, 0, 0,
......@@ -414,7 +416,8 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1)
{
ctxt->errNo = error;
__xmlRaiseError(ctxt->vctxt.error, ctxt->vctxt.userData,
__xmlRaiseError(ctxt->vctxt.serror,
ctxt->vctxt.error, ctxt->vctxt.userData,
ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1,
NULL, NULL, 0, 0,
......@@ -436,7 +439,7 @@ xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, int val)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
ctxt->wellFormed = 0;
......@@ -461,7 +464,7 @@ xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const xmlChar *str2)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, (const char *) str1, (const char *) str2,
NULL, val, 0, msg, str1, val, str2);
......@@ -484,7 +487,7 @@ xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar * val)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg,
val);
......@@ -507,7 +510,7 @@ xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar * val)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL,
XML_FROM_PARSER, error, XML_ERR_ERROR,
NULL, 0, (const char *) val, NULL, NULL, 0, 0, msg,
val);
......@@ -530,7 +533,7 @@ xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const xmlChar * info3)
{
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
XML_ERR_ERROR, NULL, 0, (const char *) info1,
(const char *) info2, (const char *) info3, 0, 0, msg,
info1, info2, info3);
......
......@@ -110,12 +110,12 @@ xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
ctxt->disableSAX = 1;
}
if (extra)
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
}
......@@ -136,7 +136,7 @@ xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors error,
{
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, (const char *) str1, (const char *) str2,
NULL, 0, 0, msg, str1, str2);
......@@ -160,7 +160,7 @@ xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str)
{
if (ctxt != NULL)
ctxt->errNo = XML_ERR_INTERNAL_ERROR;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, XML_ERR_INTERNAL_ERROR,
XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
0, 0, msg, str);
......@@ -186,7 +186,7 @@ xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
{
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL,
__xmlRaiseError(NULL, NULL, NULL,
ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
if (ctxt != NULL) {
......
......@@ -202,6 +202,7 @@ struct _xmlRelaxNGParserCtxt {
void *userData; /* user specific data block */
xmlRelaxNGValidityErrorFunc error; /* the callback in case of errors */
xmlRelaxNGValidityWarningFunc warning; /* the callback in case of warning */
xmlStructuredErrorFunc serror;
xmlRelaxNGValidErr err;
xmlRelaxNGPtr schema; /* The schema in use */
......@@ -342,6 +343,7 @@ struct _xmlRelaxNGValidCtxt {
void *userData; /* user specific data block */
xmlRelaxNGValidityErrorFunc error; /* the callback in case of errors */
xmlRelaxNGValidityWarningFunc warning; /* the callback in case of warning */
xmlStructuredErrorFunc serror;
int nbErrors; /* number of errors in validation */
xmlRelaxNGPtr schema; /* The schema in use */
......@@ -425,6 +427,7 @@ struct _xmlRelaxNGDocument {
static void
xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
......@@ -432,15 +435,16 @@ xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra)
channel = ctxt->error;
data = ctxt->userData;
ctxt->nbErrors++;
schannel = ctxt->serror;
}
if (extra)
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, NULL, XML_FROM_RELAXNGP,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, NULL, XML_FROM_RELAXNGP,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
......@@ -456,6 +460,7 @@ xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra)
static void
xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt, const char *extra)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
......@@ -463,15 +468,16 @@ xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt, const char *extra)
channel = ctxt->error;
data = ctxt->userData;
ctxt->nbErrors++;
schannel = ctxt->serror;
}
if (extra)
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, NULL, XML_FROM_RELAXNGV,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, NULL, XML_FROM_RELAXNGV,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "Memory allocation failed\n");
......@@ -492,6 +498,7 @@ static void
xmlRngPErr(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node, int error,
const char *msg, const xmlChar * str1, const xmlChar * str2)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
......@@ -499,8 +506,9 @@ xmlRngPErr(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node, int error,
channel = ctxt->error;
data = ctxt->userData;
ctxt->nbErrors++;
schannel = ctxt->serror;
}
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, node, XML_FROM_RELAXNGP,
error, XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str2, NULL, 0, 0,
......@@ -522,6 +530,7 @@ static void
xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error,
const char *msg, const xmlChar * str1, const xmlChar * str2)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
void *data = NULL;
......@@ -529,8 +538,9 @@ xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error,
channel = ctxt->error;
data = ctxt->userData;
ctxt->nbErrors++;
schannel = ctxt->serror;
}
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
NULL, node, XML_FROM_RELAXNGV,
error, XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str2, NULL, 0, 0,
......
......@@ -53,6 +53,7 @@ static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name,
static void
xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
xmlParserCtxtPtr pctxt = NULL;
void *data = NULL;
......@@ -61,14 +62,15 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)
channel = ctxt->error;
data = ctxt->userData;
pctxt = ctxt->userData;
schannel = ctxt->serror;
}
if (extra)
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
pctxt, NULL, XML_FROM_DTD, XML_ERR_NO_MEMORY,
XML_ERR_FATAL, NULL, 0, extra, NULL, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
else
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
pctxt, NULL, XML_FROM_DTD, XML_ERR_NO_MEMORY,
XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0,
"Memory allocation failed\n");
......@@ -86,22 +88,24 @@ static void
xmlErrValid(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlParserErrors error,
const char *msg, const char *extra)
{
xmlStructuredErrorFunc schannel = NULL;
xmlGenericErrorFunc channel = NULL;
xmlParserCtxtPtr pctxt = NULL;
void *data = NULL;
if (ctxt != NULL) {
channel = ctxt->error;
schannel = ctxt->serror;
data = ctxt->userData;
pctxt = ctxt->userData;
}
if (extra)
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
pctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, extra, NULL, NULL, 0, 0,
msg, extra);
else
__xmlRaiseError(channel, data,
__xmlRaiseError(schannel, channel, data,
pctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0,