summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/error.c b/error.c
index 05cc5b3..8eb6161 100644
--- a/error.c
+++ b/error.c
@@ -102,6 +102,7 @@ initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
* be passed as first argument to @handler
* One can simply force messages to be emitted to another FILE * than
* stderr by setting @ctx to this file handle and @handler to NULL.
+ * For multi-threaded applications, this must be set separately for each thread.
*/
void
xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
@@ -122,6 +123,7 @@ xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
* 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
+ * For multi-threaded applications, this must be set separately for each thread.
*/
void
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
@@ -457,8 +459,17 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
(ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
}
- if (schannel == NULL)
+ /*
+ * Check if structured error handler set
+ */
+ if (schannel == NULL) {
schannel = xmlStructuredError;
+ /*
+ * if user has defined handler, change data ptr to user's choice
+ */
+ if (schannel != NULL)
+ data = xmlGenericErrorContext;
+ }
if ((domain == XML_FROM_VALID) &&
((channel == xmlParserValidityError) ||
(channel == xmlParserValidityWarning))) {
@@ -541,9 +552,9 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
xmlCopyError(to,&xmlLastError);
/*
- * Find the callback channel.
+ * Find the callback channel if channel param is NULL
*/
- if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL)) {
+ if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (ctxt->sax != NULL)) {
if (level == XML_ERR_WARNING)
channel = ctxt->sax->warning;
else
@@ -891,8 +902,17 @@ xmlCtxtResetLastError(void *ctx)
*/
int
xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
+ char *message, *file, *str1, *str2, *str3;
+
if ((from == NULL) || (to == NULL))
return(-1);
+
+ message = (char *) xmlStrdup((xmlChar *) from->message);
+ file = (char *) xmlStrdup ((xmlChar *) from->file);
+ str1 = (char *) xmlStrdup ((xmlChar *) from->str1);
+ str2 = (char *) xmlStrdup ((xmlChar *) from->str2);
+ str3 = (char *) xmlStrdup ((xmlChar *) from->str3);
+
if (to->message != NULL)
xmlFree(to->message);
if (to->file != NULL)
@@ -912,26 +932,12 @@ xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
to->int2 = from->int2;
to->node = from->node;
to->ctxt = from->ctxt;
- if (from->message != NULL)
- to->message = (char *) xmlStrdup((xmlChar *) from->message);
- else
- to->message = NULL;
- if (from->file != NULL)
- to->file = (char *) xmlStrdup((xmlChar *) from->file);
- else
- to->file = NULL;
- if (from->str1 != NULL)
- to->str1 = (char *) xmlStrdup((xmlChar *) from->str1);
- else
- to->str1 = NULL;
- if (from->str2 != NULL)
- to->str2 = (char *) xmlStrdup((xmlChar *) from->str2);
- else
- to->str2 = NULL;
- if (from->str3 != NULL)
- to->str3 = (char *) xmlStrdup((xmlChar *) from->str3);
- else
- to->str3 = NULL;
- return(0);
+ to->message = message;
+ to->file = file;
+ to->str1 = str1;
+ to->str2 = str2;
+ to->str3 = str3;
+
+ return 0;
}