2001-02-23 17:55:21 +00:00
|
|
|
/*
|
|
|
|
* error.c: module displaying/handling XML parser errors
|
|
|
|
*
|
|
|
|
* See Copyright for the status of this software.
|
|
|
|
*
|
2001-06-24 12:13:24 +00:00
|
|
|
* Daniel Veillard <daniel@veillard.com>
|
2001-02-23 17:55:21 +00:00
|
|
|
*/
|
|
|
|
|
2002-03-18 19:37:11 +00:00
|
|
|
#define IN_LIBXML
|
2001-04-21 16:57:29 +00:00
|
|
|
#include "libxml.h"
|
2001-02-23 17:55:21 +00:00
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
#include <string.h>
|
2001-02-23 17:55:21 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xmlerror.h>
|
2001-03-10 12:32:04 +00:00
|
|
|
#include <libxml/xmlmemory.h>
|
2001-02-23 17:55:21 +00:00
|
|
|
|
2022-08-26 01:22:33 +02:00
|
|
|
#include "private/error.h"
|
2023-12-18 19:12:08 +01:00
|
|
|
#include "private/string.h"
|
2001-10-29 11:48:19 +00:00
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Error struct *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
xmlVSetError(xmlError *err,
|
|
|
|
void *ctxt, xmlNodePtr node,
|
|
|
|
int domain, int code, xmlErrorLevel level,
|
|
|
|
const char *file, int line,
|
|
|
|
const char *str1, const char *str2, const char *str3,
|
|
|
|
int int1, int col,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
char *message = NULL;
|
|
|
|
char *fileCopy = NULL;
|
|
|
|
char *str1Copy = NULL;
|
|
|
|
char *str2Copy = NULL;
|
|
|
|
char *str3Copy = NULL;
|
|
|
|
|
|
|
|
if (code == XML_ERR_OK) {
|
|
|
|
xmlResetError(err);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Formatting the message
|
|
|
|
*/
|
|
|
|
if (fmt == NULL) {
|
|
|
|
message = xmlMemStrdup("No error message provided");
|
|
|
|
} else {
|
|
|
|
xmlChar *tmp;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = xmlStrVASPrintf(&tmp, MAX_ERR_MSG_SIZE, fmt, ap);
|
|
|
|
if (res < 0)
|
|
|
|
goto err_memory;
|
|
|
|
message = (char *) tmp;
|
|
|
|
}
|
|
|
|
if (message == NULL)
|
|
|
|
goto err_memory;
|
|
|
|
|
|
|
|
if (file != NULL) {
|
|
|
|
fileCopy = (char *) xmlStrdup((const xmlChar *) file);
|
|
|
|
if (fileCopy == NULL)
|
|
|
|
goto err_memory;
|
|
|
|
}
|
|
|
|
if (str1 != NULL) {
|
|
|
|
str1Copy = (char *) xmlStrdup((const xmlChar *) str1);
|
|
|
|
if (str1Copy == NULL)
|
|
|
|
goto err_memory;
|
|
|
|
}
|
|
|
|
if (str2 != NULL) {
|
|
|
|
str2Copy = (char *) xmlStrdup((const xmlChar *) str2);
|
|
|
|
if (str2Copy == NULL)
|
|
|
|
goto err_memory;
|
|
|
|
}
|
|
|
|
if (str3 != NULL) {
|
|
|
|
str3Copy = (char *) xmlStrdup((const xmlChar *) str3);
|
|
|
|
if (str3Copy == NULL)
|
|
|
|
goto err_memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlResetError(err);
|
|
|
|
|
|
|
|
err->domain = domain;
|
|
|
|
err->code = code;
|
|
|
|
err->message = message;
|
|
|
|
err->level = level;
|
|
|
|
err->file = fileCopy;
|
|
|
|
err->line = line;
|
|
|
|
err->str1 = str1Copy;
|
|
|
|
err->str2 = str2Copy;
|
|
|
|
err->str3 = str3Copy;
|
|
|
|
err->int1 = int1;
|
|
|
|
err->int2 = col;
|
|
|
|
err->node = node;
|
|
|
|
err->ctxt = ctxt;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
err_memory:
|
|
|
|
xmlFree(message);
|
|
|
|
xmlFree(fileCopy);
|
|
|
|
xmlFree(str1Copy);
|
|
|
|
xmlFree(str2Copy);
|
|
|
|
xmlFree(str3Copy);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LIBXML_ATTR_FORMAT(14,15)
|
|
|
|
xmlSetError(xmlError *err,
|
|
|
|
void *ctxt, xmlNodePtr node,
|
|
|
|
int domain, int code, xmlErrorLevel level,
|
|
|
|
const char *file, int line,
|
|
|
|
const char *str1, const char *str2, const char *str3,
|
|
|
|
int int1, int col,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
res = xmlVSetError(err, ctxt, node, domain, code, level, file, line,
|
|
|
|
str1, str2, str3, int1, col, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xmlVUpdateError(xmlError *err,
|
|
|
|
void *ctxt, xmlNodePtr node,
|
|
|
|
int domain, int code, xmlErrorLevel level,
|
|
|
|
const char *file, int line,
|
|
|
|
const char *str1, const char *str2, const char *str3,
|
|
|
|
int int1, int col,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find first element parent.
|
|
|
|
*/
|
|
|
|
if (node != NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
if ((node->type == XML_ELEMENT_NODE) ||
|
|
|
|
(node->parent == NULL))
|
2023-12-10 15:46:53 +01:00
|
|
|
break;
|
2023-12-18 19:12:08 +01:00
|
|
|
node = node->parent;
|
2023-12-10 15:46:53 +01:00
|
|
|
}
|
2023-12-18 19:12:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get file and line from node.
|
|
|
|
*/
|
|
|
|
if (node != NULL) {
|
|
|
|
if ((file == NULL) && (node->doc != NULL))
|
|
|
|
file = (const char *) node->doc->URL;
|
|
|
|
|
|
|
|
if (line == 0) {
|
|
|
|
if (node->type == XML_ELEMENT_NODE)
|
|
|
|
line = node->line;
|
|
|
|
if ((line == 0) || (line == 65535))
|
|
|
|
line = xmlGetLineNo(node);
|
2023-12-10 15:46:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
res = xmlVSetError(err, ctxt, node, domain, code, level, file, line,
|
|
|
|
str1, str2, str3, int1, col, fmt, ap);
|
|
|
|
|
|
|
|
return(res);
|
2001-06-05 17:12:52 +00:00
|
|
|
}
|
2001-06-05 12:45:55 +00:00
|
|
|
|
2001-02-23 17:55:21 +00:00
|
|
|
/************************************************************************
|
2012-09-11 13:26:36 +08:00
|
|
|
* *
|
|
|
|
* Handling of out of context errors *
|
|
|
|
* *
|
2001-02-23 17:55:21 +00:00
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlGenericErrorDefaultFunc:
|
|
|
|
* @ctx: an error context
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Default handler for out of context error messages.
|
|
|
|
*/
|
2022-12-08 02:43:17 +01:00
|
|
|
void
|
2001-03-26 16:28:29 +00:00
|
|
|
xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
|
2001-02-23 17:55:21 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (xmlGenericErrorContext == NULL)
|
|
|
|
xmlGenericErrorContext = (void *) stderr;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
|
|
|
vfprintf((FILE *)xmlGenericErrorContext, msg, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2002-01-22 18:15:52 +00:00
|
|
|
/**
|
|
|
|
* initGenericErrorDefaultFunc:
|
|
|
|
* @handler: the handler
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2022-09-09 01:44:00 +02:00
|
|
|
* DEPRECATED: Use xmlSetGenericErrorFunc.
|
|
|
|
*
|
2002-01-22 18:15:52 +00:00
|
|
|
* Set or reset (if NULL) the default handler for generic errors
|
2003-01-24 14:14:52 +00:00
|
|
|
* to the builtin error function.
|
2002-01-22 18:15:52 +00:00
|
|
|
*/
|
2001-10-13 09:15:48 +00:00
|
|
|
void
|
2002-01-18 11:49:26 +00:00
|
|
|
initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
|
2001-10-13 09:15:48 +00:00
|
|
|
{
|
2002-01-18 11:49:26 +00:00
|
|
|
if (handler == NULL)
|
|
|
|
xmlGenericError = xmlGenericErrorDefaultFunc;
|
|
|
|
else
|
2004-04-20 09:45:26 +00:00
|
|
|
xmlGenericError = (*handler);
|
2001-10-13 09:15:48 +00:00
|
|
|
}
|
2001-02-23 17:55:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlSetGenericErrorFunc:
|
|
|
|
* @ctx: the new error handling context
|
|
|
|
* @handler: the new handler function
|
|
|
|
*
|
|
|
|
* Function to reset the handler and the error context for out of
|
|
|
|
* context 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
|
|
|
|
* One can simply force messages to be emitted to another FILE * than
|
|
|
|
* stderr by setting @ctx to this file handle and @handler to NULL.
|
2004-08-14 11:15:13 +00:00
|
|
|
* For multi-threaded applications, this must be set separately for each thread.
|
2001-02-23 17:55:21 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
|
|
|
|
xmlGenericErrorContext = ctx;
|
|
|
|
if (handler != NULL)
|
|
|
|
xmlGenericError = handler;
|
|
|
|
else
|
|
|
|
xmlGenericError = xmlGenericErrorDefaultFunc;
|
|
|
|
}
|
|
|
|
|
2003-10-10 14:10:40 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2004-08-14 11:15:13 +00:00
|
|
|
* For multi-threaded applications, this must be set separately for each thread.
|
2003-10-10 14:10:40 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
|
2009-08-24 17:34:25 +02:00
|
|
|
xmlStructuredErrorContext = ctx;
|
2003-10-10 14:10:40 +00:00
|
|
|
xmlStructuredError = handler;
|
|
|
|
}
|
|
|
|
|
2001-02-23 17:55:21 +00:00
|
|
|
/************************************************************************
|
2012-09-11 13:26:36 +08:00
|
|
|
* *
|
|
|
|
* Handling of parsing errors *
|
|
|
|
* *
|
2001-02-23 17:55:21 +00:00
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlParserPrintFileInfo:
|
|
|
|
* @input: an xmlParserInputPtr input
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2020-03-08 17:19:42 +01:00
|
|
|
* Displays the associated file and line information for the current input
|
2001-02-23 17:55:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
xmlParserPrintFileInfo(xmlParserInputPtr input) {
|
|
|
|
if (input != NULL) {
|
|
|
|
if (input->filename)
|
|
|
|
xmlGenericError(xmlGenericErrorContext,
|
|
|
|
"%s:%d: ", input->filename,
|
|
|
|
input->line);
|
|
|
|
else
|
|
|
|
xmlGenericError(xmlGenericErrorContext,
|
|
|
|
"Entity: line %d: ", input->line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-04 23:01:00 +01:00
|
|
|
* xmlParserPrintFileContextInternal:
|
2001-02-23 17:55:21 +00:00
|
|
|
* @input: an xmlParserInputPtr input
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Displays current context within the input content for error tracking
|
|
|
|
*/
|
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
static void
|
2012-09-11 13:26:36 +08:00
|
|
|
xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
|
2003-10-02 22:28:19 +00:00
|
|
|
xmlGenericErrorFunc channel, void *data ) {
|
2022-12-04 23:01:00 +01:00
|
|
|
const xmlChar *cur, *base, *start;
|
2003-08-05 15:52:22 +00:00
|
|
|
unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
|
2003-05-13 02:06:18 +00:00
|
|
|
xmlChar content[81]; /* space for 80 chars + line terminator */
|
2001-03-27 00:32:28 +00:00
|
|
|
xmlChar *ctnt;
|
2001-02-23 17:55:21 +00:00
|
|
|
|
2015-12-01 13:24:44 +01:00
|
|
|
if ((input == NULL) || (input->cur == NULL))
|
|
|
|
return;
|
2015-11-20 15:01:22 +08:00
|
|
|
|
2001-02-23 17:55:21 +00:00
|
|
|
cur = input->cur;
|
|
|
|
base = input->base;
|
2001-03-27 00:32:28 +00:00
|
|
|
/* skip backwards over any end-of-lines */
|
2003-08-05 15:52:22 +00:00
|
|
|
while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
|
2002-03-20 21:55:57 +00:00
|
|
|
cur--;
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
|
|
|
n = 0;
|
2003-05-13 02:06:18 +00:00
|
|
|
/* search backwards for beginning-of-line (to max buff size) */
|
2023-01-22 12:00:59 +01:00
|
|
|
while ((n < sizeof(content) - 1) && (cur > base) &&
|
|
|
|
(*cur != '\n') && (*cur != '\r')) {
|
2001-02-23 17:55:21 +00:00
|
|
|
cur--;
|
2023-01-22 12:00:59 +01:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) {
|
2022-12-04 23:01:00 +01:00
|
|
|
cur++;
|
|
|
|
} else {
|
|
|
|
/* skip over continuation bytes */
|
|
|
|
while ((cur < input->cur) && ((*cur & 0xC0) == 0x80))
|
|
|
|
cur++;
|
|
|
|
}
|
2003-05-13 02:06:18 +00:00
|
|
|
/* calculate the error position in terms of the current position */
|
|
|
|
col = input->cur - cur;
|
|
|
|
/* search forward for end-of-line (to max buff size) */
|
2001-02-23 17:55:21 +00:00
|
|
|
n = 0;
|
2022-12-04 23:01:00 +01:00
|
|
|
start = cur;
|
2003-05-13 02:06:18 +00:00
|
|
|
/* copy selected text to our buffer */
|
2022-12-04 23:01:00 +01:00
|
|
|
while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) {
|
|
|
|
int len = input->end - cur;
|
|
|
|
int c = xmlGetUTF8Char(cur, &len);
|
|
|
|
|
|
|
|
if ((c < 0) || (n + len > sizeof(content)-1))
|
|
|
|
break;
|
|
|
|
cur += len;
|
|
|
|
n += len;
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
2022-12-04 23:01:00 +01:00
|
|
|
memcpy(content, start, n);
|
|
|
|
content[n] = 0;
|
2003-05-13 02:06:18 +00:00
|
|
|
/* print out the selected text */
|
2003-10-02 22:28:19 +00:00
|
|
|
channel(data ,"%s\n", content);
|
2001-03-27 00:32:28 +00:00
|
|
|
/* create blank line with problem pointer */
|
2001-02-23 17:55:21 +00:00
|
|
|
n = 0;
|
2001-04-24 15:52:00 +00:00
|
|
|
ctnt = content;
|
2003-05-13 02:06:18 +00:00
|
|
|
/* (leave buffer space for pointer + line terminator) */
|
|
|
|
while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
|
2003-08-05 15:52:22 +00:00
|
|
|
if (*(ctnt) != '\t')
|
|
|
|
*(ctnt) = ' ';
|
2003-09-22 00:24:51 +00:00
|
|
|
ctnt++;
|
2002-03-20 21:55:57 +00:00
|
|
|
}
|
2003-05-13 02:06:18 +00:00
|
|
|
*ctnt++ = '^';
|
|
|
|
*ctnt = 0;
|
2003-10-02 22:28:19 +00:00
|
|
|
channel(data ,"%s\n", content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlParserPrintFileContext:
|
|
|
|
* @input: an xmlParserInputPtr input
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2003-10-02 22:28:19 +00:00
|
|
|
* Displays current context within the input content for error tracking
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlParserPrintFileContext(xmlParserInputPtr input) {
|
|
|
|
xmlParserPrintFileContextInternal(input, xmlGenericError,
|
|
|
|
xmlGenericErrorContext);
|
2002-03-20 21:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-10-02 22:28:19 +00:00
|
|
|
* xmlReportError:
|
2003-10-03 22:21:51 +00:00
|
|
|
* @err: the error
|
2003-10-02 22:28:19 +00:00
|
|
|
* @ctx: the parser context or NULL
|
|
|
|
* @str: the formatted error message
|
2002-03-20 21:55:57 +00:00
|
|
|
*
|
2019-09-30 17:04:54 +02:00
|
|
|
* Report an error with its context, replace the 4 old error/warning
|
2003-10-02 22:28:19 +00:00
|
|
|
* routines.
|
2002-03-20 21:55:57 +00:00
|
|
|
*/
|
2003-10-02 22:28:19 +00:00
|
|
|
static void
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlReportError(xmlParserCtxtPtr ctxt, const xmlError *err)
|
2003-10-03 22:21:51 +00:00
|
|
|
{
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlGenericErrorFunc channel;
|
|
|
|
void *data;
|
|
|
|
const char *message;
|
|
|
|
const char *file;
|
|
|
|
int line;
|
|
|
|
int code;
|
2003-10-02 22:28:19 +00:00
|
|
|
int domain;
|
2003-10-07 11:33:24 +00:00
|
|
|
const xmlChar *name = NULL;
|
|
|
|
xmlNodePtr node;
|
2003-10-02 22:28:19 +00:00
|
|
|
xmlErrorLevel level;
|
|
|
|
xmlParserInputPtr input = NULL;
|
|
|
|
xmlParserInputPtr cur = NULL;
|
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
if (err == NULL) {
|
|
|
|
if (ctxt == NULL)
|
|
|
|
return;
|
|
|
|
err = &ctxt->lastError;
|
2003-10-07 11:33:24 +00:00
|
|
|
}
|
2023-12-18 19:12:08 +01:00
|
|
|
|
|
|
|
channel = xmlGenericError;
|
|
|
|
data = xmlGenericErrorContext;
|
|
|
|
|
|
|
|
message = err->message;
|
2003-10-03 22:21:51 +00:00
|
|
|
file = err->file;
|
|
|
|
line = err->line;
|
|
|
|
code = err->code;
|
|
|
|
domain = err->domain;
|
|
|
|
level = err->level;
|
2003-10-07 11:33:24 +00:00
|
|
|
node = err->node;
|
2003-10-03 22:21:51 +00:00
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
if (code == XML_ERR_OK)
|
|
|
|
return;
|
|
|
|
|
2003-10-07 11:33:24 +00:00
|
|
|
if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
|
|
|
|
name = node->name;
|
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
/*
|
|
|
|
* Maintain the compatibility with the legacy error handling
|
|
|
|
*/
|
2023-12-10 15:46:53 +01:00
|
|
|
if ((ctxt != NULL) && (ctxt->input != NULL)) {
|
2003-10-03 22:21:51 +00:00
|
|
|
input = ctxt->input;
|
2023-12-10 15:46:53 +01:00
|
|
|
if ((input->filename == NULL) &&
|
2003-10-03 22:21:51 +00:00
|
|
|
(ctxt->inputNr > 1)) {
|
|
|
|
cur = input;
|
|
|
|
input = ctxt->inputTab[ctxt->inputNr - 2];
|
|
|
|
}
|
2023-12-10 15:46:53 +01:00
|
|
|
if (input->filename)
|
|
|
|
channel(data, "%s:%d: ", input->filename, input->line);
|
|
|
|
else if ((line != 0) && (domain == XML_FROM_PARSER))
|
|
|
|
channel(data, "Entity: line %d: ", input->line);
|
2003-10-03 22:21:51 +00:00
|
|
|
} else {
|
|
|
|
if (file != NULL)
|
|
|
|
channel(data, "%s:%d: ", file, line);
|
2012-09-11 13:26:36 +08:00
|
|
|
else if ((line != 0) &&
|
2012-08-14 11:01:07 +08:00
|
|
|
((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)||
|
|
|
|
(domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) ||
|
|
|
|
(domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV)))
|
2003-10-03 22:21:51 +00:00
|
|
|
channel(data, "Entity: line %d: ", line);
|
2003-10-02 22:28:19 +00:00
|
|
|
}
|
2003-10-07 11:33:24 +00:00
|
|
|
if (name != NULL) {
|
|
|
|
channel(data, "element %s: ", name);
|
|
|
|
}
|
2003-10-02 22:28:19 +00:00
|
|
|
switch (domain) {
|
|
|
|
case XML_FROM_PARSER:
|
|
|
|
channel(data, "parser ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_NAMESPACE:
|
|
|
|
channel(data, "namespace ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_DTD:
|
2003-10-28 15:44:17 +00:00
|
|
|
case XML_FROM_VALID:
|
2003-10-02 22:28:19 +00:00
|
|
|
channel(data, "validity ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_HTML:
|
|
|
|
channel(data, "HTML parser ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_MEMORY:
|
|
|
|
channel(data, "memory ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_OUTPUT:
|
|
|
|
channel(data, "output ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_IO:
|
|
|
|
channel(data, "I/O ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_XINCLUDE:
|
|
|
|
channel(data, "XInclude ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_XPATH:
|
|
|
|
channel(data, "XPath ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_XPOINTER:
|
|
|
|
channel(data, "parser ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_REGEXP:
|
|
|
|
channel(data, "regexp ");
|
|
|
|
break;
|
2005-01-04 15:10:22 +00:00
|
|
|
case XML_FROM_MODULE:
|
|
|
|
channel(data, "module ");
|
|
|
|
break;
|
2003-10-10 00:49:42 +00:00
|
|
|
case XML_FROM_SCHEMASV:
|
2003-10-10 10:52:58 +00:00
|
|
|
channel(data, "Schemas validity ");
|
2003-10-10 00:49:42 +00:00
|
|
|
break;
|
|
|
|
case XML_FROM_SCHEMASP:
|
2003-10-10 10:52:58 +00:00
|
|
|
channel(data, "Schemas parser ");
|
2003-10-02 22:28:19 +00:00
|
|
|
break;
|
2003-10-07 11:33:24 +00:00
|
|
|
case XML_FROM_RELAXNGP:
|
|
|
|
channel(data, "Relax-NG parser ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_RELAXNGV:
|
2003-10-10 00:49:42 +00:00
|
|
|
channel(data, "Relax-NG validity ");
|
2003-10-02 22:28:19 +00:00
|
|
|
break;
|
|
|
|
case XML_FROM_CATALOG:
|
|
|
|
channel(data, "Catalog ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_C14N:
|
|
|
|
channel(data, "C14N ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_XSLT:
|
|
|
|
channel(data, "XSLT ");
|
|
|
|
break;
|
2005-08-24 12:46:09 +00:00
|
|
|
case XML_FROM_I18N:
|
|
|
|
channel(data, "encoding ");
|
|
|
|
break;
|
2012-07-24 11:44:23 +08:00
|
|
|
case XML_FROM_SCHEMATRONV:
|
|
|
|
channel(data, "schematron ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_BUFFER:
|
|
|
|
channel(data, "internal buffer ");
|
|
|
|
break;
|
|
|
|
case XML_FROM_URI:
|
|
|
|
channel(data, "URI ");
|
|
|
|
break;
|
2003-10-02 22:28:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (level) {
|
|
|
|
case XML_ERR_NONE:
|
|
|
|
channel(data, ": ");
|
2003-10-03 22:21:51 +00:00
|
|
|
break;
|
2003-10-02 22:28:19 +00:00
|
|
|
case XML_ERR_WARNING:
|
|
|
|
channel(data, "warning : ");
|
2003-10-03 22:21:51 +00:00
|
|
|
break;
|
2003-10-02 22:28:19 +00:00
|
|
|
case XML_ERR_ERROR:
|
|
|
|
channel(data, "error : ");
|
2003-10-03 22:21:51 +00:00
|
|
|
break;
|
2003-10-02 22:28:19 +00:00
|
|
|
case XML_ERR_FATAL:
|
|
|
|
channel(data, "error : ");
|
2003-10-03 22:21:51 +00:00
|
|
|
break;
|
2003-10-02 22:28:19 +00:00
|
|
|
}
|
2023-12-18 19:12:08 +01:00
|
|
|
if (message != NULL) {
|
2003-10-08 19:19:10 +00:00
|
|
|
int len;
|
2023-12-18 19:12:08 +01:00
|
|
|
len = xmlStrlen((const xmlChar *) message);
|
|
|
|
if ((len > 0) && (message[len - 1] != '\n'))
|
|
|
|
channel(data, "%s\n", message);
|
2003-10-08 19:26:03 +00:00
|
|
|
else
|
2023-12-18 19:12:08 +01:00
|
|
|
channel(data, "%s", message);
|
2003-10-02 22:28:19 +00:00
|
|
|
} else {
|
2023-12-18 19:12:08 +01:00
|
|
|
channel(data, "%s\n", "No error message provided");
|
2001-03-10 12:32:04 +00:00
|
|
|
}
|
2003-10-02 22:28:19 +00:00
|
|
|
|
|
|
|
if (ctxt != NULL) {
|
|
|
|
xmlParserPrintFileContextInternal(input, channel, data);
|
|
|
|
if (cur != NULL) {
|
|
|
|
if (cur->filename)
|
|
|
|
channel(data, "%s:%d: \n", cur->filename, cur->line);
|
2003-10-07 21:25:12 +00:00
|
|
|
else if ((line != 0) && (domain == XML_FROM_PARSER))
|
2003-10-02 22:28:19 +00:00
|
|
|
channel(data, "Entity: line %d: \n", cur->line);
|
|
|
|
xmlParserPrintFileContextInternal(cur, channel, data);
|
|
|
|
}
|
|
|
|
}
|
2003-10-07 21:25:12 +00:00
|
|
|
if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
|
|
|
|
(err->int1 < 100) &&
|
|
|
|
(err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
|
|
|
|
xmlChar buf[150];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
channel(data, "%s\n", err->str1);
|
|
|
|
for (i=0;i < err->int1;i++)
|
|
|
|
buf[i] = ' ';
|
|
|
|
buf[i++] = '^';
|
|
|
|
buf[i] = 0;
|
|
|
|
channel(data, "%s\n", buf);
|
|
|
|
}
|
2003-10-02 22:28:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
/**
|
|
|
|
* xmlRaiseMemoryError:
|
|
|
|
* @schannel: the structured callback channel
|
|
|
|
* @channel: the old callback channel
|
|
|
|
* @data: the callback data
|
|
|
|
* @domain: the domain for the error
|
|
|
|
* @error: optional error struct to be filled
|
|
|
|
*
|
|
|
|
* Update the global and optional error structure, then forward the
|
|
|
|
* error to an error handler.
|
|
|
|
*
|
|
|
|
* This function doesn't make memory allocations which are likely
|
|
|
|
* to fail after an OOM error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel,
|
|
|
|
void *data, int domain, xmlError *error)
|
|
|
|
{
|
|
|
|
xmlError *lastError = &xmlLastError;
|
|
|
|
|
|
|
|
xmlResetLastError();
|
|
|
|
lastError->domain = domain;
|
|
|
|
lastError->code = XML_ERR_NO_MEMORY;
|
|
|
|
lastError->level = XML_ERR_FATAL;
|
|
|
|
|
|
|
|
if (error != NULL) {
|
|
|
|
xmlResetError(error);
|
|
|
|
error->domain = domain;
|
|
|
|
error->code = XML_ERR_NO_MEMORY;
|
|
|
|
error->level = XML_ERR_FATAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schannel != NULL) {
|
|
|
|
schannel(data, lastError);
|
|
|
|
} else if (xmlStructuredError != NULL) {
|
|
|
|
xmlStructuredError(xmlStructuredErrorContext, lastError);
|
|
|
|
} else if (channel != NULL) {
|
|
|
|
channel(data, "libxml2: out of memory\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
/**
|
2023-12-10 15:46:53 +01:00
|
|
|
* xmlVRaiseError:
|
2004-05-16 03:12:08 +00:00
|
|
|
* @schannel: the structured callback channel
|
2003-10-10 14:10:40 +00:00
|
|
|
* @channel: the old callback channel
|
2003-10-03 22:21:51 +00:00
|
|
|
* @data: the callback data
|
|
|
|
* @ctx: the parser context or NULL
|
2003-10-02 22:28:19 +00:00
|
|
|
* @ctx: the parser context or NULL
|
|
|
|
* @domain: the domain for the error
|
|
|
|
* @code: the code for the error
|
|
|
|
* @level: the xmlErrorLevel for the error
|
|
|
|
* @file: the file source of the error (or NULL)
|
|
|
|
* @line: the line of the error or 0 if N/A
|
|
|
|
* @str1: extra string info
|
|
|
|
* @str2: extra string info
|
|
|
|
* @str3: extra string info
|
|
|
|
* @int1: extra int info
|
2012-09-11 13:26:36 +08:00
|
|
|
* @col: column number of the error or 0 if N/A
|
2003-10-02 22:28:19 +00:00
|
|
|
* @msg: the message to display/transmit
|
2023-12-10 15:46:53 +01:00
|
|
|
* @ap: extra parameters for the message display
|
2003-10-02 22:28:19 +00:00
|
|
|
*
|
2004-05-16 03:12:08 +00:00
|
|
|
* Update the appropriate global or contextual error structure,
|
2003-10-02 22:28:19 +00:00
|
|
|
* then forward the error message down the parser or generic
|
|
|
|
* error callback handler
|
2023-12-10 15:46:53 +01:00
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 if a memory allocation failed.
|
2003-10-02 22:28:19 +00:00
|
|
|
*/
|
2023-12-10 15:46:53 +01:00
|
|
|
int
|
|
|
|
xmlVRaiseError(xmlStructuredErrorFunc schannel,
|
|
|
|
xmlGenericErrorFunc channel, void *data, void *ctx,
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlNode *node, int domain, int code, xmlErrorLevel level,
|
2023-12-10 15:46:53 +01:00
|
|
|
const char *file, int line, const char *str1,
|
|
|
|
const char *str2, const char *str3, int int1, int col,
|
|
|
|
const char *msg, va_list ap)
|
2003-10-02 22:28:19 +00:00
|
|
|
{
|
2003-10-08 22:38:13 +00:00
|
|
|
xmlParserCtxtPtr ctxt = NULL;
|
2023-12-10 15:46:53 +01:00
|
|
|
/* xmlLastError is a macro retrieving the per-thread global. */
|
|
|
|
xmlErrorPtr lastError = &xmlLastError;
|
|
|
|
xmlErrorPtr to = lastError;
|
2003-10-02 22:28:19 +00:00
|
|
|
|
2011-02-23 22:14:19 +08:00
|
|
|
if (code == XML_ERR_OK)
|
2023-12-10 15:46:53 +01:00
|
|
|
return(0);
|
2003-12-08 17:41:29 +00:00
|
|
|
if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING))
|
2023-12-10 15:46:53 +01:00
|
|
|
return(0);
|
2023-12-18 19:12:08 +01:00
|
|
|
|
2003-10-08 22:38:13 +00:00
|
|
|
if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
|
|
|
|
(domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
|
2004-10-25 16:23:56 +00:00
|
|
|
(domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
|
2003-10-08 22:38:13 +00:00
|
|
|
ctxt = (xmlParserCtxtPtr) ctx;
|
2003-10-07 11:33:24 +00:00
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
if (ctxt != NULL)
|
|
|
|
to = &ctxt->lastError;
|
2003-10-02 22:28:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
if (xmlVUpdateError(to, ctxt, node, domain, code, level, file, line,
|
|
|
|
str1, str2, str3, int1, col, msg, ap))
|
|
|
|
return(-1);
|
2003-10-02 22:28:19 +00:00
|
|
|
|
2023-12-10 15:46:53 +01:00
|
|
|
if (to != lastError) {
|
|
|
|
if (xmlCopyError(to, lastError) < 0)
|
2023-12-18 19:12:08 +01:00
|
|
|
return(-1);
|
2023-12-10 15:46:53 +01:00
|
|
|
}
|
2004-01-02 20:26:01 +00:00
|
|
|
|
2011-02-23 22:44:05 +08:00
|
|
|
if (schannel != NULL) {
|
|
|
|
schannel(data, to);
|
2023-12-18 19:12:08 +01:00
|
|
|
} else if (xmlStructuredError != NULL) {
|
|
|
|
xmlStructuredError(xmlStructuredErrorContext, to);
|
|
|
|
} else if (channel != NULL) {
|
|
|
|
channel(data, "%s", to->message);
|
2003-10-10 14:10:40 +00:00
|
|
|
}
|
2023-12-10 15:46:53 +01:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __xmlRaiseError:
|
|
|
|
* @schannel: the structured callback channel
|
|
|
|
* @channel: the old callback channel
|
|
|
|
* @data: the callback data
|
|
|
|
* @ctx: the parser context or NULL
|
|
|
|
* @nod: the node or NULL
|
|
|
|
* @domain: the domain for the error
|
|
|
|
* @code: the code for the error
|
|
|
|
* @level: the xmlErrorLevel for the error
|
|
|
|
* @file: the file source of the error (or NULL)
|
|
|
|
* @line: the line of the error or 0 if N/A
|
|
|
|
* @str1: extra string info
|
|
|
|
* @str2: extra string info
|
|
|
|
* @str3: extra string info
|
|
|
|
* @int1: extra int info
|
|
|
|
* @col: column number of the error or 0 if N/A
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
|
|
|
*
|
|
|
|
* Update the appropriate global or contextual error structure,
|
|
|
|
* then forward the error message down the parser or generic
|
|
|
|
* error callback handler
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 if a memory allocation failed.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__xmlRaiseError(xmlStructuredErrorFunc schannel,
|
|
|
|
xmlGenericErrorFunc channel, void *data, void *ctx,
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlNode *node, int domain, int code, xmlErrorLevel level,
|
2023-12-10 15:46:53 +01:00
|
|
|
const char *file, int line, const char *str1,
|
|
|
|
const char *str2, const char *str3, int int1, int col,
|
|
|
|
const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
2023-12-18 19:12:08 +01:00
|
|
|
res = xmlVRaiseError(schannel, channel, data, ctx, node, domain, code,
|
2023-12-10 15:46:53 +01:00
|
|
|
level, file, line, str1, str2, str3, int1, col, msg,
|
|
|
|
ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return(res);
|
2001-03-10 12:32:04 +00:00
|
|
|
}
|
|
|
|
|
2001-02-23 17:55:21 +00:00
|
|
|
/**
|
|
|
|
* xmlParserError:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Display and format an error messages, gives file, line, position and
|
|
|
|
* extra parameters.
|
|
|
|
*/
|
2022-12-08 02:43:17 +01:00
|
|
|
void
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlParserError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
2001-02-23 17:55:21 +00:00
|
|
|
{
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlReportError(ctx, NULL);
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlParserWarning:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Display and format a warning messages, gives file, line, position and
|
|
|
|
* extra parameters.
|
|
|
|
*/
|
2022-12-08 02:43:17 +01:00
|
|
|
void
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlParserWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
2001-02-23 17:55:21 +00:00
|
|
|
{
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlReportError(ctx, NULL);
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlParserValidityError:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Display and format an validity error messages, gives file,
|
|
|
|
* line, position and extra parameters.
|
|
|
|
*/
|
2022-12-08 02:43:17 +01:00
|
|
|
void
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlParserValidityError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
2001-02-23 17:55:21 +00:00
|
|
|
{
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlReportError(ctx, NULL);
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlParserValidityWarning:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
* @msg: the message to display/transmit
|
|
|
|
* @...: extra parameters for the message display
|
2012-09-11 13:26:36 +08:00
|
|
|
*
|
2001-02-23 17:55:21 +00:00
|
|
|
* Display and format a validity warning messages, gives file, line,
|
|
|
|
* position and extra parameters.
|
|
|
|
*/
|
2022-12-08 02:43:17 +01:00
|
|
|
void
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlParserValidityWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
2001-02-23 17:55:21 +00:00
|
|
|
{
|
2023-12-18 19:12:08 +01:00
|
|
|
xmlReportError(ctx, NULL);
|
2001-02-23 17:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Extended Error Handling *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlGetLastError:
|
|
|
|
*
|
|
|
|
* Get the last global error registered. This is per thread if compiled
|
|
|
|
* with thread support.
|
|
|
|
*
|
2023-09-21 23:52:52 +02:00
|
|
|
* Returns a pointer to the error
|
2003-10-02 22:28:19 +00:00
|
|
|
*/
|
2023-09-21 23:52:52 +02:00
|
|
|
const xmlError *
|
2003-10-02 22:28:19 +00:00
|
|
|
xmlGetLastError(void)
|
|
|
|
{
|
|
|
|
if (xmlLastError.code == XML_ERR_OK)
|
|
|
|
return (NULL);
|
|
|
|
return (&xmlLastError);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlResetError:
|
|
|
|
* @err: pointer to the error.
|
|
|
|
*
|
|
|
|
* Cleanup the error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlResetError(xmlErrorPtr err)
|
|
|
|
{
|
|
|
|
if (err == NULL)
|
|
|
|
return;
|
|
|
|
if (err->code == XML_ERR_OK)
|
|
|
|
return;
|
|
|
|
if (err->message != NULL)
|
|
|
|
xmlFree(err->message);
|
|
|
|
if (err->file != NULL)
|
|
|
|
xmlFree(err->file);
|
|
|
|
if (err->str1 != NULL)
|
|
|
|
xmlFree(err->str1);
|
|
|
|
if (err->str2 != NULL)
|
|
|
|
xmlFree(err->str2);
|
|
|
|
if (err->str3 != NULL)
|
|
|
|
xmlFree(err->str3);
|
|
|
|
memset(err, 0, sizeof(xmlError));
|
|
|
|
err->code = XML_ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlResetLastError:
|
|
|
|
*
|
|
|
|
* Cleanup the last global error registered. For parsing error
|
|
|
|
* this does not change the well-formedness result.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlResetLastError(void)
|
|
|
|
{
|
|
|
|
if (xmlLastError.code == XML_ERR_OK)
|
|
|
|
return;
|
|
|
|
xmlResetError(&xmlLastError);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlCtxtGetLastError:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
*
|
|
|
|
* Get the last parsing error registered.
|
|
|
|
*
|
2017-06-17 16:15:09 +02:00
|
|
|
* Returns NULL if no error occurred or a pointer to the error
|
2003-10-02 22:28:19 +00:00
|
|
|
*/
|
2023-10-24 15:02:36 +02:00
|
|
|
const xmlError *
|
2003-10-02 22:28:19 +00:00
|
|
|
xmlCtxtGetLastError(void *ctx)
|
|
|
|
{
|
|
|
|
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
|
|
|
|
|
|
|
if (ctxt == NULL)
|
|
|
|
return (NULL);
|
|
|
|
if (ctxt->lastError.code == XML_ERR_OK)
|
|
|
|
return (NULL);
|
|
|
|
return (&ctxt->lastError);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlCtxtResetLastError:
|
|
|
|
* @ctx: an XML parser context
|
|
|
|
*
|
|
|
|
* Cleanup the last global error registered. For parsing error
|
|
|
|
* this does not change the well-formedness result.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xmlCtxtResetLastError(void *ctx)
|
|
|
|
{
|
|
|
|
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
|
|
|
|
|
|
|
if (ctxt == NULL)
|
|
|
|
return;
|
2010-03-15 15:59:07 +01:00
|
|
|
ctxt->errNo = XML_ERR_OK;
|
2003-10-02 22:28:19 +00:00
|
|
|
if (ctxt->lastError.code == XML_ERR_OK)
|
|
|
|
return;
|
|
|
|
xmlResetError(&ctxt->lastError);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlCopyError:
|
|
|
|
* @from: a source error
|
|
|
|
* @to: a target error
|
|
|
|
*
|
|
|
|
* Save the original error to the new place.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success and -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
2023-09-21 23:52:52 +02:00
|
|
|
xmlCopyError(const xmlError *from, xmlErrorPtr to) {
|
2023-12-18 19:12:08 +01:00
|
|
|
const char *fmt = NULL;
|
2004-07-31 16:24:01 +00:00
|
|
|
|
2003-10-02 22:28:19 +00:00
|
|
|
if ((from == NULL) || (to == NULL))
|
|
|
|
return(-1);
|
2004-07-31 16:24:01 +00:00
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
if (from->message != NULL)
|
|
|
|
fmt = "%s";
|
2023-12-10 15:46:53 +01:00
|
|
|
|
2023-12-18 19:12:08 +01:00
|
|
|
return(xmlSetError(to, from->ctxt, from->node,
|
|
|
|
from->domain, from->code, from->level,
|
|
|
|
from->file, from->line,
|
|
|
|
from->str1, from->str2, from->str3,
|
|
|
|
from->int1, from->int2,
|
|
|
|
fmt, from->message));
|
2003-10-02 22:28:19 +00:00
|
|
|
}
|
|
|
|
|