Blame error.c

Packit Service a31ea6
/*
Packit Service a31ea6
 * error.c: module displaying/handling XML parser errors
Packit Service a31ea6
 *
Packit Service a31ea6
 * See Copyright for the status of this software.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Daniel Veillard <daniel@veillard.com>
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
#define IN_LIBXML
Packit Service a31ea6
#include "libxml.h"
Packit Service a31ea6
Packit Service a31ea6
#include <string.h>
Packit Service a31ea6
#include <stdarg.h>
Packit Service a31ea6
#include <libxml/parser.h>
Packit Service a31ea6
#include <libxml/xmlerror.h>
Packit Service a31ea6
#include <libxml/xmlmemory.h>
Packit Service a31ea6
#include <libxml/globals.h>
Packit Service a31ea6
Packit Service a31ea6
void XMLCDECL xmlGenericErrorDefaultFunc	(void *ctx ATTRIBUTE_UNUSED,
Packit Service a31ea6
				 const char *msg,
Packit Service a31ea6
				 ...) LIBXML_ATTR_FORMAT(2,3);
Packit Service a31ea6
Packit Service a31ea6
#define XML_GET_VAR_STR(msg, str) {				\
Packit Service a31ea6
    int       size, prev_size = -1;				\
Packit Service a31ea6
    int       chars;						\
Packit Service a31ea6
    char      *larger;						\
Packit Service a31ea6
    va_list   ap;						\
Packit Service a31ea6
								\
Packit Service a31ea6
    str = (char *) xmlMalloc(150);				\
Packit Service a31ea6
    if (str != NULL) {						\
Packit Service a31ea6
								\
Packit Service a31ea6
    size = 150;							\
Packit Service a31ea6
								\
Packit Service a31ea6
    while (size < 64000) {					\
Packit Service a31ea6
	va_start(ap, msg);					\
Packit Service a31ea6
	chars = vsnprintf(str, size, msg, ap);			\
Packit Service a31ea6
	va_end(ap);						\
Packit Service a31ea6
	if ((chars > -1) && (chars < size)) {			\
Packit Service a31ea6
	    if (prev_size == chars) {				\
Packit Service a31ea6
		break;						\
Packit Service a31ea6
	    } else {						\
Packit Service a31ea6
		prev_size = chars;				\
Packit Service a31ea6
	    }							\
Packit Service a31ea6
	}							\
Packit Service a31ea6
	if (chars > -1)						\
Packit Service a31ea6
	    size += chars + 1;					\
Packit Service a31ea6
	else							\
Packit Service a31ea6
	    size += 100;					\
Packit Service a31ea6
	if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\
Packit Service a31ea6
	    break;						\
Packit Service a31ea6
	}							\
Packit Service a31ea6
	str = larger;						\
Packit Service a31ea6
    }}								\
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Handling of out of context errors		*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlGenericErrorDefaultFunc:
Packit Service a31ea6
 * @ctx:  an error context
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Default handler for out of context error messages.
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
Packit Service a31ea6
    va_list args;
Packit Service a31ea6
Packit Service a31ea6
    if (xmlGenericErrorContext == NULL)
Packit Service a31ea6
	xmlGenericErrorContext = (void *) stderr;
Packit Service a31ea6
Packit Service a31ea6
    va_start(args, msg);
Packit Service a31ea6
    vfprintf((FILE *)xmlGenericErrorContext, msg, args);
Packit Service a31ea6
    va_end(args);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * initGenericErrorDefaultFunc:
Packit Service a31ea6
 * @handler:  the handler
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set or reset (if NULL) the default handler for generic errors
Packit Service a31ea6
 * to the builtin error function.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
Packit Service a31ea6
{
Packit Service a31ea6
    if (handler == NULL)
Packit Service a31ea6
        xmlGenericError = xmlGenericErrorDefaultFunc;
Packit Service a31ea6
    else
Packit Service a31ea6
        xmlGenericError = (*handler);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSetGenericErrorFunc:
Packit Service a31ea6
 * @ctx:  the new error handling context
Packit Service a31ea6
 * @handler:  the new handler function
Packit Service a31ea6
 *
Packit Service a31ea6
 * Function to reset the handler and the error context for out of
Packit Service a31ea6
 * context error messages.
Packit Service a31ea6
 * This simply means that @handler will be called for subsequent
Packit Service a31ea6
 * error messages while not parsing nor validating. And @ctx will
Packit Service a31ea6
 * be passed as first argument to @handler
Packit Service a31ea6
 * One can simply force messages to be emitted to another FILE * than
Packit Service a31ea6
 * stderr by setting @ctx to this file handle and @handler to NULL.
Packit Service a31ea6
 * For multi-threaded applications, this must be set separately for each thread.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
Packit Service a31ea6
    xmlGenericErrorContext = ctx;
Packit Service a31ea6
    if (handler != NULL)
Packit Service a31ea6
	xmlGenericError = handler;
Packit Service a31ea6
    else
Packit Service a31ea6
	xmlGenericError = xmlGenericErrorDefaultFunc;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSetStructuredErrorFunc:
Packit Service a31ea6
 * @ctx:  the new error handling context
Packit Service a31ea6
 * @handler:  the new handler function
Packit Service a31ea6
 *
Packit Service a31ea6
 * Function to reset the handler and the error context for out of
Packit Service a31ea6
 * context structured error messages.
Packit Service a31ea6
 * This simply means that @handler will be called for subsequent
Packit Service a31ea6
 * error messages while not parsing nor validating. And @ctx will
Packit Service a31ea6
 * be passed as first argument to @handler
Packit Service a31ea6
 * For multi-threaded applications, this must be set separately for each thread.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
Packit Service a31ea6
    xmlStructuredErrorContext = ctx;
Packit Service a31ea6
    xmlStructuredError = handler;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Handling of parsing errors			*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserPrintFileInfo:
Packit Service a31ea6
 * @input:  an xmlParserInputPtr input
Packit Service a31ea6
 *
Packit Service a31ea6
 * Displays the associated file and line informations for the current input
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
void
Packit Service a31ea6
xmlParserPrintFileInfo(xmlParserInputPtr input) {
Packit Service a31ea6
    if (input != NULL) {
Packit Service a31ea6
	if (input->filename)
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "%s:%d: ", input->filename,
Packit Service a31ea6
		    input->line);
Packit Service a31ea6
	else
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "Entity: line %d: ", input->line);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserPrintFileContext:
Packit Service a31ea6
 * @input:  an xmlParserInputPtr input
Packit Service a31ea6
 *
Packit Service a31ea6
 * Displays current context within the input content for error tracking
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
static void
Packit Service a31ea6
xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
Packit Service a31ea6
		xmlGenericErrorFunc channel, void *data ) {
Packit Service a31ea6
    const xmlChar *cur, *base;
Packit Service a31ea6
    unsigned int n, col;	/* GCC warns if signed, because compared with sizeof() */
Packit Service a31ea6
    xmlChar  content[81]; /* space for 80 chars + line terminator */
Packit Service a31ea6
    xmlChar *ctnt;
Packit Service a31ea6
Packit Service a31ea6
    if ((input == NULL) || (input->cur == NULL))
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
    cur = input->cur;
Packit Service a31ea6
    base = input->base;
Packit Service a31ea6
    /* skip backwards over any end-of-lines */
Packit Service a31ea6
    while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
Packit Service a31ea6
	cur--;
Packit Service a31ea6
    }
Packit Service a31ea6
    n = 0;
Packit Service a31ea6
    /* search backwards for beginning-of-line (to max buff size) */
Packit Service a31ea6
    while ((n++ < (sizeof(content)-1)) && (cur > base) &&
Packit Service a31ea6
	   (*(cur) != '\n') && (*(cur) != '\r'))
Packit Service a31ea6
        cur--;
Packit Service a31ea6
    if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
Packit Service a31ea6
    /* calculate the error position in terms of the current position */
Packit Service a31ea6
    col = input->cur - cur;
Packit Service a31ea6
    /* search forward for end-of-line (to max buff size) */
Packit Service a31ea6
    n = 0;
Packit Service a31ea6
    ctnt = content;
Packit Service a31ea6
    /* copy selected text to our buffer */
Packit Service a31ea6
    while ((*cur != 0) && (*(cur) != '\n') &&
Packit Service a31ea6
	   (*(cur) != '\r') && (n < sizeof(content)-1)) {
Packit Service a31ea6
		*ctnt++ = *cur++;
Packit Service a31ea6
	n++;
Packit Service a31ea6
    }
Packit Service a31ea6
    *ctnt = 0;
Packit Service a31ea6
    /* print out the selected text */
Packit Service a31ea6
    channel(data ,"%s\n", content);
Packit Service a31ea6
    /* create blank line with problem pointer */
Packit Service a31ea6
    n = 0;
Packit Service a31ea6
    ctnt = content;
Packit Service a31ea6
    /* (leave buffer space for pointer + line terminator) */
Packit Service a31ea6
    while ((n
Packit Service a31ea6
	if (*(ctnt) != '\t')
Packit Service a31ea6
	    *(ctnt) = ' ';
Packit Service a31ea6
	ctnt++;
Packit Service a31ea6
    }
Packit Service a31ea6
    *ctnt++ = '^';
Packit Service a31ea6
    *ctnt = 0;
Packit Service a31ea6
    channel(data ,"%s\n", content);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserPrintFileContext:
Packit Service a31ea6
 * @input:  an xmlParserInputPtr input
Packit Service a31ea6
 *
Packit Service a31ea6
 * Displays current context within the input content for error tracking
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlParserPrintFileContext(xmlParserInputPtr input) {
Packit Service a31ea6
   xmlParserPrintFileContextInternal(input, xmlGenericError,
Packit Service a31ea6
                                     xmlGenericErrorContext);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlReportError:
Packit Service a31ea6
 * @err: the error
Packit Service a31ea6
 * @ctx: the parser context or NULL
Packit Service a31ea6
 * @str: the formatted error message
Packit Service a31ea6
 *
Packit Service a31ea6
 * Report an erro with its context, replace the 4 old error/warning
Packit Service a31ea6
 * routines.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
Packit Service a31ea6
               xmlGenericErrorFunc channel, void *data)
Packit Service a31ea6
{
Packit Service a31ea6
    char *file = NULL;
Packit Service a31ea6
    int line = 0;
Packit Service a31ea6
    int code = -1;
Packit Service a31ea6
    int domain;
Packit Service a31ea6
    const xmlChar *name = NULL;
Packit Service a31ea6
    xmlNodePtr node;
Packit Service a31ea6
    xmlErrorLevel level;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    xmlParserInputPtr cur = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (err == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
    if (channel == NULL) {
Packit Service a31ea6
	channel = xmlGenericError;
Packit Service a31ea6
	data = xmlGenericErrorContext;
Packit Service a31ea6
    }
Packit Service a31ea6
    file = err->file;
Packit Service a31ea6
    line = err->line;
Packit Service a31ea6
    code = err->code;
Packit Service a31ea6
    domain = err->domain;
Packit Service a31ea6
    level = err->level;
Packit Service a31ea6
    node = err->node;
Packit Service a31ea6
Packit Service a31ea6
    if (code == XML_ERR_OK)
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
    if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
Packit Service a31ea6
        name = node->name;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Maintain the compatibility with the legacy error handling
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        input = ctxt->input;
Packit Service a31ea6
        if ((input != NULL) && (input->filename == NULL) &&
Packit Service a31ea6
            (ctxt->inputNr > 1)) {
Packit Service a31ea6
            cur = input;
Packit Service a31ea6
            input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
        }
Packit Service a31ea6
        if (input != NULL) {
Packit Service a31ea6
            if (input->filename)
Packit Service a31ea6
                channel(data, "%s:%d: ", input->filename, input->line);
Packit Service a31ea6
            else if ((line != 0) && (domain == XML_FROM_PARSER))
Packit Service a31ea6
                channel(data, "Entity: line %d: ", input->line);
Packit Service a31ea6
        }
Packit Service a31ea6
    } else {
Packit Service a31ea6
        if (file != NULL)
Packit Service a31ea6
            channel(data, "%s:%d: ", file, line);
Packit Service a31ea6
        else if ((line != 0) &&
Packit Service a31ea6
	         ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)||
Packit Service a31ea6
		  (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) ||
Packit Service a31ea6
		  (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV)))
Packit Service a31ea6
            channel(data, "Entity: line %d: ", line);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (name != NULL) {
Packit Service a31ea6
        channel(data, "element %s: ", name);
Packit Service a31ea6
    }
Packit Service a31ea6
    switch (domain) {
Packit Service a31ea6
        case XML_FROM_PARSER:
Packit Service a31ea6
            channel(data, "parser ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_NAMESPACE:
Packit Service a31ea6
            channel(data, "namespace ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_DTD:
Packit Service a31ea6
        case XML_FROM_VALID:
Packit Service a31ea6
            channel(data, "validity ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_HTML:
Packit Service a31ea6
            channel(data, "HTML parser ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_MEMORY:
Packit Service a31ea6
            channel(data, "memory ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_OUTPUT:
Packit Service a31ea6
            channel(data, "output ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_IO:
Packit Service a31ea6
            channel(data, "I/O ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_XINCLUDE:
Packit Service a31ea6
            channel(data, "XInclude ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_XPATH:
Packit Service a31ea6
            channel(data, "XPath ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_XPOINTER:
Packit Service a31ea6
            channel(data, "parser ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_REGEXP:
Packit Service a31ea6
            channel(data, "regexp ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_MODULE:
Packit Service a31ea6
            channel(data, "module ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_SCHEMASV:
Packit Service a31ea6
            channel(data, "Schemas validity ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_SCHEMASP:
Packit Service a31ea6
            channel(data, "Schemas parser ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_RELAXNGP:
Packit Service a31ea6
            channel(data, "Relax-NG parser ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_RELAXNGV:
Packit Service a31ea6
            channel(data, "Relax-NG validity ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_CATALOG:
Packit Service a31ea6
            channel(data, "Catalog ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_C14N:
Packit Service a31ea6
            channel(data, "C14N ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_XSLT:
Packit Service a31ea6
            channel(data, "XSLT ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_I18N:
Packit Service a31ea6
            channel(data, "encoding ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_SCHEMATRONV:
Packit Service a31ea6
            channel(data, "schematron ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_BUFFER:
Packit Service a31ea6
            channel(data, "internal buffer ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_FROM_URI:
Packit Service a31ea6
            channel(data, "URI ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        default:
Packit Service a31ea6
            break;
Packit Service a31ea6
    }
Packit Service a31ea6
    switch (level) {
Packit Service a31ea6
        case XML_ERR_NONE:
Packit Service a31ea6
            channel(data, ": ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ERR_WARNING:
Packit Service a31ea6
            channel(data, "warning : ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ERR_ERROR:
Packit Service a31ea6
            channel(data, "error : ");
Packit Service a31ea6
            break;
Packit Service a31ea6
        case XML_ERR_FATAL:
Packit Service a31ea6
            channel(data, "error : ");
Packit Service a31ea6
            break;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (str != NULL) {
Packit Service a31ea6
        int len;
Packit Service a31ea6
	len = xmlStrlen((const xmlChar *)str);
Packit Service a31ea6
	if ((len > 0) && (str[len - 1] != '\n'))
Packit Service a31ea6
	    channel(data, "%s\n", str);
Packit Service a31ea6
	else
Packit Service a31ea6
	    channel(data, "%s", str);
Packit Service a31ea6
    } else {
Packit Service a31ea6
        channel(data, "%s\n", "out of memory error");
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        xmlParserPrintFileContextInternal(input, channel, data);
Packit Service a31ea6
        if (cur != NULL) {
Packit Service a31ea6
            if (cur->filename)
Packit Service a31ea6
                channel(data, "%s:%d: \n", cur->filename, cur->line);
Packit Service a31ea6
            else if ((line != 0) && (domain == XML_FROM_PARSER))
Packit Service a31ea6
                channel(data, "Entity: line %d: \n", cur->line);
Packit Service a31ea6
            xmlParserPrintFileContextInternal(cur, channel, data);
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
Packit Service a31ea6
        (err->int1 < 100) &&
Packit Service a31ea6
	(err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
Packit Service a31ea6
	xmlChar buf[150];
Packit Service a31ea6
	int i;
Packit Service a31ea6
Packit Service a31ea6
	channel(data, "%s\n", err->str1);
Packit Service a31ea6
	for (i=0;i < err->int1;i++)
Packit Service a31ea6
	     buf[i] = ' ';
Packit Service a31ea6
	buf[i++] = '^';
Packit Service a31ea6
	buf[i] = 0;
Packit Service a31ea6
	channel(data, "%s\n", buf);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * __xmlRaiseError:
Packit Service a31ea6
 * @schannel: the structured callback channel
Packit Service a31ea6
 * @channel: the old callback channel
Packit Service a31ea6
 * @data: the callback data
Packit Service a31ea6
 * @ctx: the parser context or NULL
Packit Service a31ea6
 * @ctx: the parser context or NULL
Packit Service a31ea6
 * @domain: the domain for the error
Packit Service a31ea6
 * @code: the code for the error
Packit Service a31ea6
 * @level: the xmlErrorLevel for the error
Packit Service a31ea6
 * @file: the file source of the error (or NULL)
Packit Service a31ea6
 * @line: the line of the error or 0 if N/A
Packit Service a31ea6
 * @str1: extra string info
Packit Service a31ea6
 * @str2: extra string info
Packit Service a31ea6
 * @str3: extra string info
Packit Service a31ea6
 * @int1: extra int info
Packit Service a31ea6
 * @col: column number of the error or 0 if N/A
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Update the appropriate global or contextual error structure,
Packit Service a31ea6
 * then forward the error message down the parser or generic
Packit Service a31ea6
 * error callback handler
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
__xmlRaiseError(xmlStructuredErrorFunc schannel,
Packit Service a31ea6
              xmlGenericErrorFunc channel, void *data, void *ctx,
Packit Service a31ea6
              void *nod, int domain, int code, xmlErrorLevel level,
Packit Service a31ea6
              const char *file, int line, const char *str1,
Packit Service a31ea6
              const char *str2, const char *str3, int int1, int col,
Packit Service a31ea6
	      const char *msg, ...)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = NULL;
Packit Service a31ea6
    xmlNodePtr node = (xmlNodePtr) nod;
Packit Service a31ea6
    char *str = NULL;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    xmlErrorPtr to = &xmlLastError;
Packit Service a31ea6
    xmlNodePtr baseptr = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (code == XML_ERR_OK)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING))
Packit Service a31ea6
        return;
Packit Service a31ea6
    if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
Packit Service a31ea6
        (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
Packit Service a31ea6
	(domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
Packit Service a31ea6
	ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
	if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
Packit Service a31ea6
	    (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
Packit Service a31ea6
	    (ctxt->sax->serror != NULL)) {
Packit Service a31ea6
	    schannel = ctxt->sax->serror;
Packit Service a31ea6
	    data = ctxt->userData;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Check if structured error handler set
Packit Service a31ea6
     */
Packit Service a31ea6
    if (schannel == NULL) {
Packit Service a31ea6
	schannel = xmlStructuredError;
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * if user has defined handler, change data ptr to user's choice
Packit Service a31ea6
	 */
Packit Service a31ea6
	if (schannel != NULL)
Packit Service a31ea6
	    data = xmlStructuredErrorContext;
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Formatting the message
Packit Service a31ea6
     */
Packit Service a31ea6
    if (msg == NULL) {
Packit Service a31ea6
        str = (char *) xmlStrdup(BAD_CAST "No error message provided");
Packit Service a31ea6
    } else {
Packit Service a31ea6
        XML_GET_VAR_STR(msg, str);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * specific processing if a parser context is provided
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        if (file == NULL) {
Packit Service a31ea6
            input = ctxt->input;
Packit Service a31ea6
            if ((input != NULL) && (input->filename == NULL) &&
Packit Service a31ea6
                (ctxt->inputNr > 1)) {
Packit Service a31ea6
                input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
            }
Packit Service a31ea6
            if (input != NULL) {
Packit Service a31ea6
                file = input->filename;
Packit Service a31ea6
                line = input->line;
Packit Service a31ea6
                col = input->col;
Packit Service a31ea6
            }
Packit Service a31ea6
        }
Packit Service a31ea6
        to = &ctxt->lastError;
Packit Service a31ea6
    } else if ((node != NULL) && (file == NULL)) {
Packit Service a31ea6
	int i;
Packit Service a31ea6
Packit Service a31ea6
	if ((node->doc != NULL) && (node->doc->URL != NULL)) {
Packit Service a31ea6
	    baseptr = node;
Packit Service a31ea6
/*	    file = (const char *) node->doc->URL; */
Packit Service a31ea6
	}
Packit Service a31ea6
	for (i = 0;
Packit Service a31ea6
	     ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE));
Packit Service a31ea6
	     i++)
Packit Service a31ea6
	     node = node->parent;
Packit Service a31ea6
        if ((baseptr == NULL) && (node != NULL) &&
Packit Service a31ea6
	    (node->doc != NULL) && (node->doc->URL != NULL))
Packit Service a31ea6
	    baseptr = node;
Packit Service a31ea6
Packit Service a31ea6
	if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
Packit Service a31ea6
	    line = node->line;
Packit Service a31ea6
	if ((line == 0) || (line == 65535))
Packit Service a31ea6
	    line = xmlGetLineNo(node);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Save the information about the error
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlResetError(to);
Packit Service a31ea6
    to->domain = domain;
Packit Service a31ea6
    to->code = code;
Packit Service a31ea6
    to->message = str;
Packit Service a31ea6
    to->level = level;
Packit Service a31ea6
    if (file != NULL)
Packit Service a31ea6
        to->file = (char *) xmlStrdup((const xmlChar *) file);
Packit Service a31ea6
    else if (baseptr != NULL) {
Packit Service a31ea6
#ifdef LIBXML_XINCLUDE_ENABLED
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * We check if the error is within an XInclude section and,
Packit Service a31ea6
	 * if so, attempt to print out the href of the XInclude instead
Packit Service a31ea6
	 * of the usual "base" (doc->URL) for the node (bug 152623).
Packit Service a31ea6
	 */
Packit Service a31ea6
        xmlNodePtr prev = baseptr;
Packit Service a31ea6
	int inclcount = 0;
Packit Service a31ea6
	while (prev != NULL) {
Packit Service a31ea6
	    if (prev->prev == NULL)
Packit Service a31ea6
	        prev = prev->parent;
Packit Service a31ea6
	    else {
Packit Service a31ea6
	        prev = prev->prev;
Packit Service a31ea6
		if (prev->type == XML_XINCLUDE_START) {
Packit Service a31ea6
		    if (--inclcount < 0)
Packit Service a31ea6
		        break;
Packit Service a31ea6
		} else if (prev->type == XML_XINCLUDE_END)
Packit Service a31ea6
		    inclcount++;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
	if (prev != NULL) {
Packit Service a31ea6
	    if (prev->type == XML_XINCLUDE_START) {
Packit Service a31ea6
		prev->type = XML_ELEMENT_NODE;
Packit Service a31ea6
		to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
Packit Service a31ea6
		prev->type = XML_XINCLUDE_START;
Packit Service a31ea6
	    } else {
Packit Service a31ea6
		to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else
Packit Service a31ea6
#endif
Packit Service a31ea6
	    to->file = (char *) xmlStrdup(baseptr->doc->URL);
Packit Service a31ea6
	if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) {
Packit Service a31ea6
	    to->file = (char *) xmlStrdup(node->doc->URL);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    to->line = line;
Packit Service a31ea6
    if (str1 != NULL)
Packit Service a31ea6
        to->str1 = (char *) xmlStrdup((const xmlChar *) str1);
Packit Service a31ea6
    if (str2 != NULL)
Packit Service a31ea6
        to->str2 = (char *) xmlStrdup((const xmlChar *) str2);
Packit Service a31ea6
    if (str3 != NULL)
Packit Service a31ea6
        to->str3 = (char *) xmlStrdup((const xmlChar *) str3);
Packit Service a31ea6
    to->int1 = int1;
Packit Service a31ea6
    to->int2 = col;
Packit Service a31ea6
    to->node = node;
Packit Service a31ea6
    to->ctxt = ctx;
Packit Service a31ea6
Packit Service a31ea6
    if (to != &xmlLastError)
Packit Service a31ea6
        xmlCopyError(to,&xmlLastError);
Packit Service a31ea6
Packit Service a31ea6
    if (schannel != NULL) {
Packit Service a31ea6
	schannel(data, to);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Find the callback channel if channel param is NULL
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt != NULL) && (channel == NULL) &&
Packit Service a31ea6
        (xmlStructuredError == NULL) && (ctxt->sax != NULL)) {
Packit Service a31ea6
        if (level == XML_ERR_WARNING)
Packit Service a31ea6
	    channel = ctxt->sax->warning;
Packit Service a31ea6
        else
Packit Service a31ea6
	    channel = ctxt->sax->error;
Packit Service a31ea6
	data = ctxt->userData;
Packit Service a31ea6
    } else if (channel == NULL) {
Packit Service a31ea6
	channel = xmlGenericError;
Packit Service a31ea6
	if (ctxt != NULL) {
Packit Service a31ea6
	    data = ctxt;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    data = xmlGenericErrorContext;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (channel == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
    if ((channel == xmlParserError) ||
Packit Service a31ea6
        (channel == xmlParserWarning) ||
Packit Service a31ea6
	(channel == xmlParserValidityError) ||
Packit Service a31ea6
	(channel == xmlParserValidityWarning))
Packit Service a31ea6
	xmlReportError(to, ctxt, str, NULL, NULL);
Packit Service a31ea6
    else if ((channel == (xmlGenericErrorFunc) fprintf) ||
Packit Service a31ea6
             (channel == xmlGenericErrorDefaultFunc))
Packit Service a31ea6
	xmlReportError(to, ctxt, str, channel, data);
Packit Service a31ea6
    else
Packit Service a31ea6
	channel(data, "%s", str);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * __xmlSimpleError:
Packit Service a31ea6
 * @domain: where the error comes from
Packit Service a31ea6
 * @code: the error code
Packit Service a31ea6
 * @node: the context node
Packit Service a31ea6
 * @extra:  extra informations
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle an out of memory condition
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
__xmlSimpleError(int domain, int code, xmlNodePtr node,
Packit Service a31ea6
                 const char *msg, const char *extra)
Packit Service a31ea6
{
Packit Service a31ea6
Packit Service a31ea6
    if (code == XML_ERR_NO_MEMORY) {
Packit Service a31ea6
	if (extra)
Packit Service a31ea6
	    __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Packit Service a31ea6
			    XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
Packit Service a31ea6
			    NULL, NULL, 0, 0,
Packit Service a31ea6
			    "Memory allocation failed : %s\n", extra);
Packit Service a31ea6
	else
Packit Service a31ea6
	    __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Packit Service a31ea6
			    XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
Packit Service a31ea6
			    NULL, NULL, 0, 0, "Memory allocation failed\n");
Packit Service a31ea6
    } else {
Packit Service a31ea6
	__xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Packit Service a31ea6
			code, XML_ERR_ERROR, NULL, 0, extra,
Packit Service a31ea6
			NULL, NULL, 0, 0, msg, extra);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserError:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Display and format an error messages, gives file, line, position and
Packit Service a31ea6
 * extra parameters.
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
xmlParserError(void *ctx, const char *msg, ...)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    xmlParserInputPtr cur = NULL;
Packit Service a31ea6
    char * str;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	input = ctxt->input;
Packit Service a31ea6
	if ((input != NULL) && (input->filename == NULL) &&
Packit Service a31ea6
	    (ctxt->inputNr > 1)) {
Packit Service a31ea6
	    cur = input;
Packit Service a31ea6
	    input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
	}
Packit Service a31ea6
	xmlParserPrintFileInfo(input);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "error: ");
Packit Service a31ea6
    XML_GET_VAR_STR(msg, str);
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "%s", str);
Packit Service a31ea6
    if (str != NULL)
Packit Service a31ea6
	xmlFree(str);
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	xmlParserPrintFileContext(input);
Packit Service a31ea6
	if (cur != NULL) {
Packit Service a31ea6
	    xmlParserPrintFileInfo(cur);
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext, "\n");
Packit Service a31ea6
	    xmlParserPrintFileContext(cur);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserWarning:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Display and format a warning messages, gives file, line, position and
Packit Service a31ea6
 * extra parameters.
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
xmlParserWarning(void *ctx, const char *msg, ...)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    xmlParserInputPtr cur = NULL;
Packit Service a31ea6
    char * str;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	input = ctxt->input;
Packit Service a31ea6
	if ((input != NULL) && (input->filename == NULL) &&
Packit Service a31ea6
	    (ctxt->inputNr > 1)) {
Packit Service a31ea6
	    cur = input;
Packit Service a31ea6
	    input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
	}
Packit Service a31ea6
	xmlParserPrintFileInfo(input);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "warning: ");
Packit Service a31ea6
    XML_GET_VAR_STR(msg, str);
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "%s", str);
Packit Service a31ea6
    if (str != NULL)
Packit Service a31ea6
	xmlFree(str);
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	xmlParserPrintFileContext(input);
Packit Service a31ea6
	if (cur != NULL) {
Packit Service a31ea6
	    xmlParserPrintFileInfo(cur);
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext, "\n");
Packit Service a31ea6
	    xmlParserPrintFileContext(cur);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Handling of validation errors			*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserValidityError:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Display and format an validity error messages, gives file,
Packit Service a31ea6
 * line, position and extra parameters.
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
xmlParserValidityError(void *ctx, const char *msg, ...)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    char * str;
Packit Service a31ea6
    int len = xmlStrlen((const xmlChar *) msg);
Packit Service a31ea6
    static int had_info = 0;
Packit Service a31ea6
Packit Service a31ea6
    if ((len > 1) && (msg[len - 2] != ':')) {
Packit Service a31ea6
	if (ctxt != NULL) {
Packit Service a31ea6
	    input = ctxt->input;
Packit Service a31ea6
	    if ((input->filename == NULL) && (ctxt->inputNr > 1))
Packit Service a31ea6
		input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
Packit Service a31ea6
	    if (had_info == 0) {
Packit Service a31ea6
		xmlParserPrintFileInfo(input);
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext, "validity error: ");
Packit Service a31ea6
	had_info = 0;
Packit Service a31ea6
    } else {
Packit Service a31ea6
	had_info = 1;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    XML_GET_VAR_STR(msg, str);
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "%s", str);
Packit Service a31ea6
    if (str != NULL)
Packit Service a31ea6
	xmlFree(str);
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt != NULL) && (input != NULL)) {
Packit Service a31ea6
	xmlParserPrintFileContext(input);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserValidityWarning:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 * @msg:  the message to display/transmit
Packit Service a31ea6
 * @...:  extra parameters for the message display
Packit Service a31ea6
 *
Packit Service a31ea6
 * Display and format a validity warning messages, gives file, line,
Packit Service a31ea6
 * position and extra parameters.
Packit Service a31ea6
 */
Packit Service a31ea6
void XMLCDECL
Packit Service a31ea6
xmlParserValidityWarning(void *ctx, const char *msg, ...)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserInputPtr input = NULL;
Packit Service a31ea6
    char * str;
Packit Service a31ea6
    int len = xmlStrlen((const xmlChar *) msg);
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) {
Packit Service a31ea6
	input = ctxt->input;
Packit Service a31ea6
	if ((input->filename == NULL) && (ctxt->inputNr > 1))
Packit Service a31ea6
	    input = ctxt->inputTab[ctxt->inputNr - 2];
Packit Service a31ea6
Packit Service a31ea6
	xmlParserPrintFileInfo(input);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "validity warning: ");
Packit Service a31ea6
    XML_GET_VAR_STR(msg, str);
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "%s", str);
Packit Service a31ea6
    if (str != NULL)
Packit Service a31ea6
	xmlFree(str);
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	xmlParserPrintFileContext(input);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *			Extended Error Handling				*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlGetLastError:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Get the last global error registered. This is per thread if compiled
Packit Service a31ea6
 * with thread support.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns NULL if no error occurred or a pointer to the error
Packit Service a31ea6
 */
Packit Service a31ea6
xmlErrorPtr
Packit Service a31ea6
xmlGetLastError(void)
Packit Service a31ea6
{
Packit Service a31ea6
    if (xmlLastError.code == XML_ERR_OK)
Packit Service a31ea6
        return (NULL);
Packit Service a31ea6
    return (&xmlLastError);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlResetError:
Packit Service a31ea6
 * @err: pointer to the error.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Cleanup the error.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlResetError(xmlErrorPtr err)
Packit Service a31ea6
{
Packit Service a31ea6
    if (err == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (err->code == XML_ERR_OK)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (err->message != NULL)
Packit Service a31ea6
        xmlFree(err->message);
Packit Service a31ea6
    if (err->file != NULL)
Packit Service a31ea6
        xmlFree(err->file);
Packit Service a31ea6
    if (err->str1 != NULL)
Packit Service a31ea6
        xmlFree(err->str1);
Packit Service a31ea6
    if (err->str2 != NULL)
Packit Service a31ea6
        xmlFree(err->str2);
Packit Service a31ea6
    if (err->str3 != NULL)
Packit Service a31ea6
        xmlFree(err->str3);
Packit Service a31ea6
    memset(err, 0, sizeof(xmlError));
Packit Service a31ea6
    err->code = XML_ERR_OK;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlResetLastError:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Cleanup the last global error registered. For parsing error
Packit Service a31ea6
 * this does not change the well-formedness result.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlResetLastError(void)
Packit Service a31ea6
{
Packit Service a31ea6
    if (xmlLastError.code == XML_ERR_OK)
Packit Service a31ea6
        return;
Packit Service a31ea6
    xmlResetError(&xmlLastError);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtGetLastError:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Get the last parsing error registered.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns NULL if no error occurred or a pointer to the error
Packit Service a31ea6
 */
Packit Service a31ea6
xmlErrorPtr
Packit Service a31ea6
xmlCtxtGetLastError(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt == NULL)
Packit Service a31ea6
        return (NULL);
Packit Service a31ea6
    if (ctxt->lastError.code == XML_ERR_OK)
Packit Service a31ea6
        return (NULL);
Packit Service a31ea6
    return (&ctxt->lastError);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCtxtResetLastError:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Cleanup the last global error registered. For parsing error
Packit Service a31ea6
 * this does not change the well-formedness result.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlCtxtResetLastError(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    ctxt->errNo = XML_ERR_OK;
Packit Service a31ea6
    if (ctxt->lastError.code == XML_ERR_OK)
Packit Service a31ea6
        return;
Packit Service a31ea6
    xmlResetError(&ctxt->lastError);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCopyError:
Packit Service a31ea6
 * @from:  a source error
Packit Service a31ea6
 * @to:  a target error
Packit Service a31ea6
 *
Packit Service a31ea6
 * Save the original error to the new place.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success and -1 in case of error.
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
Packit Service a31ea6
    char *message, *file, *str1, *str2, *str3;
Packit Service a31ea6
Packit Service a31ea6
    if ((from == NULL) || (to == NULL))
Packit Service a31ea6
        return(-1);
Packit Service a31ea6
Packit Service a31ea6
    message = (char *) xmlStrdup((xmlChar *) from->message);
Packit Service a31ea6
    file = (char *) xmlStrdup ((xmlChar *) from->file);
Packit Service a31ea6
    str1 = (char *) xmlStrdup ((xmlChar *) from->str1);
Packit Service a31ea6
    str2 = (char *) xmlStrdup ((xmlChar *) from->str2);
Packit Service a31ea6
    str3 = (char *) xmlStrdup ((xmlChar *) from->str3);
Packit Service a31ea6
Packit Service a31ea6
    if (to->message != NULL)
Packit Service a31ea6
        xmlFree(to->message);
Packit Service a31ea6
    if (to->file != NULL)
Packit Service a31ea6
        xmlFree(to->file);
Packit Service a31ea6
    if (to->str1 != NULL)
Packit Service a31ea6
        xmlFree(to->str1);
Packit Service a31ea6
    if (to->str2 != NULL)
Packit Service a31ea6
        xmlFree(to->str2);
Packit Service a31ea6
    if (to->str3 != NULL)
Packit Service a31ea6
        xmlFree(to->str3);
Packit Service a31ea6
    to->domain = from->domain;
Packit Service a31ea6
    to->code = from->code;
Packit Service a31ea6
    to->level = from->level;
Packit Service a31ea6
    to->line = from->line;
Packit Service a31ea6
    to->node = from->node;
Packit Service a31ea6
    to->int1 = from->int1;
Packit Service a31ea6
    to->int2 = from->int2;
Packit Service a31ea6
    to->node = from->node;
Packit Service a31ea6
    to->ctxt = from->ctxt;
Packit Service a31ea6
    to->message = message;
Packit Service a31ea6
    to->file = file;
Packit Service a31ea6
    to->str1 = str1;
Packit Service a31ea6
    to->str2 = str2;
Packit Service a31ea6
    to->str3 = str3;
Packit Service a31ea6
Packit Service a31ea6
    return 0;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#define bottom_error
Packit Service a31ea6
#include "elfgcchack.h"