Blame parserInternals.c

Packit Service a31ea6
/*
Packit Service a31ea6
 * parserInternals.c : Internal routines (and obsolete ones) needed for the
Packit Service a31ea6
 *                     XML and HTML parsers.
Packit Service a31ea6
 *
Packit Service a31ea6
 * See Copyright for the status of this software.
Packit Service a31ea6
 *
Packit Service a31ea6
 * 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
#if defined(_WIN32) && !defined (__CYGWIN__)
Packit Service a31ea6
#define XML_DIR_SEP '\\'
Packit Service a31ea6
#else
Packit Service a31ea6
#define XML_DIR_SEP '/'
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
#include <string.h>
Packit Service a31ea6
#ifdef HAVE_CTYPE_H
Packit Service a31ea6
#include <ctype.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_STDLIB_H
Packit Service a31ea6
#include <stdlib.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_SYS_STAT_H
Packit Service a31ea6
#include <sys/stat.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_FCNTL_H
Packit Service a31ea6
#include <fcntl.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_UNISTD_H
Packit Service a31ea6
#include <unistd.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#ifdef HAVE_ZLIB_H
Packit Service a31ea6
#include <zlib.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
#include <libxml/xmlmemory.h>
Packit Service a31ea6
#include <libxml/tree.h>
Packit Service a31ea6
#include <libxml/parser.h>
Packit Service a31ea6
#include <libxml/parserInternals.h>
Packit Service a31ea6
#include <libxml/valid.h>
Packit Service a31ea6
#include <libxml/entities.h>
Packit Service a31ea6
#include <libxml/xmlerror.h>
Packit Service a31ea6
#include <libxml/encoding.h>
Packit Service a31ea6
#include <libxml/valid.h>
Packit Service a31ea6
#include <libxml/xmlIO.h>
Packit Service a31ea6
#include <libxml/uri.h>
Packit Service a31ea6
#include <libxml/dict.h>
Packit Service a31ea6
#include <libxml/SAX.h>
Packit Service a31ea6
#ifdef LIBXML_CATALOG_ENABLED
Packit Service a31ea6
#include <libxml/catalog.h>
Packit Service a31ea6
#endif
Packit Service a31ea6
#include <libxml/globals.h>
Packit Service a31ea6
#include <libxml/chvalid.h>
Packit Service a31ea6
Packit Service a31ea6
#define CUR(ctxt) ctxt->input->cur
Packit Service a31ea6
#define END(ctxt) ctxt->input->end
Packit Service a31ea6
#define VALID_CTXT(ctxt) (CUR(ctxt) <= END(ctxt))
Packit Service a31ea6
Packit Service a31ea6
#include "buf.h"
Packit Service a31ea6
#include "enc.h"
Packit Service a31ea6
Packit Service a31ea6
/*
Packit Service a31ea6
 * Various global defaults for parsing
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCheckVersion:
Packit Service a31ea6
 * @version: the include version number
Packit Service a31ea6
 *
Packit Service a31ea6
 * check the compiled lib version against the include one.
Packit Service a31ea6
 * This can warn or immediately kill the application
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlCheckVersion(int version) {
Packit Service a31ea6
    int myversion = (int) LIBXML_VERSION;
Packit Service a31ea6
Packit Service a31ea6
    xmlInitParser();
Packit Service a31ea6
Packit Service a31ea6
    if ((myversion / 10000) != (version / 10000)) {
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"Fatal: program compiled against libxml %d using libxml %d\n",
Packit Service a31ea6
		(version / 10000), (myversion / 10000));
Packit Service a31ea6
	fprintf(stderr,
Packit Service a31ea6
		"Fatal: program compiled against libxml %d using libxml %d\n",
Packit Service a31ea6
		(version / 10000), (myversion / 10000));
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((myversion / 100) < (version / 100)) {
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"Warning: program compiled against libxml %d using older %d\n",
Packit Service a31ea6
		(version / 100), (myversion / 100));
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Some factorized error routines				*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlErrMemory:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @extra:  extra informations
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a redefinition of attribute error
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
Packit Service a31ea6
        (ctxt->instate == XML_PARSER_EOF))
Packit Service a31ea6
	return;
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        ctxt->errNo = XML_ERR_NO_MEMORY;
Packit Service a31ea6
        ctxt->instate = XML_PARSER_EOF;
Packit Service a31ea6
        ctxt->disableSAX = 1;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (extra)
Packit Service a31ea6
        __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
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, ctxt, NULL, XML_FROM_PARSER,
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
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * __xmlErrEncoding:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @xmlerr:  the error number
Packit Service a31ea6
 * @msg:  the error message
Packit Service a31ea6
 * @str1:  an string info
Packit Service a31ea6
 * @str2:  an string info
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle an encoding error
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
__xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr,
Packit Service a31ea6
                 const char *msg, const xmlChar * str1, const xmlChar * str2)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
Packit Service a31ea6
        (ctxt->instate == XML_PARSER_EOF))
Packit Service a31ea6
	return;
Packit Service a31ea6
    if (ctxt != NULL)
Packit Service a31ea6
        ctxt->errNo = xmlerr;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
                    ctxt, NULL, XML_FROM_PARSER, xmlerr, XML_ERR_FATAL,
Packit Service a31ea6
                    NULL, 0, (const char *) str1, (const char *) str2,
Packit Service a31ea6
                    NULL, 0, 0, msg, str1, str2);
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        ctxt->wellFormed = 0;
Packit Service a31ea6
        if (ctxt->recovery == 0)
Packit Service a31ea6
            ctxt->disableSAX = 1;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlErrInternal:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @msg:  the error message
Packit Service a31ea6
 * @str:  error informations
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle an internal error
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(2,0)
Packit Service a31ea6
xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
Packit Service a31ea6
        (ctxt->instate == XML_PARSER_EOF))
Packit Service a31ea6
	return;
Packit Service a31ea6
    if (ctxt != NULL)
Packit Service a31ea6
        ctxt->errNo = XML_ERR_INTERNAL_ERROR;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
                    ctxt, NULL, XML_FROM_PARSER, XML_ERR_INTERNAL_ERROR,
Packit Service a31ea6
                    XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
Packit Service a31ea6
                    0, 0, msg, str);
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        ctxt->wellFormed = 0;
Packit Service a31ea6
        if (ctxt->recovery == 0)
Packit Service a31ea6
            ctxt->disableSAX = 1;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlErrEncodingInt:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @error:  the error number
Packit Service a31ea6
 * @msg:  the error message
Packit Service a31ea6
 * @val:  an integer value
Packit Service a31ea6
 *
Packit Service a31ea6
 * n encoding error
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
Packit Service a31ea6
                  const char *msg, int val)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
Packit Service a31ea6
        (ctxt->instate == XML_PARSER_EOF))
Packit Service a31ea6
	return;
Packit Service a31ea6
    if (ctxt != NULL)
Packit Service a31ea6
        ctxt->errNo = error;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL,
Packit Service a31ea6
                    ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
Packit Service a31ea6
                    NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
        ctxt->wellFormed = 0;
Packit Service a31ea6
        if (ctxt->recovery == 0)
Packit Service a31ea6
            ctxt->disableSAX = 1;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlIsLetter:
Packit Service a31ea6
 * @c:  an unicode character (int)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Check whether the character is allowed by the production
Packit Service a31ea6
 * [84] Letter ::= BaseChar | Ideographic
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 if not, non-zero otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlIsLetter(int c) {
Packit Service a31ea6
    return(IS_BASECHAR(c) || IS_IDEOGRAPHIC(c));
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Input handling functions for progressive parsing	*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/* #define DEBUG_INPUT */
Packit Service a31ea6
/* #define DEBUG_STACK */
Packit Service a31ea6
/* #define DEBUG_PUSH */
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/* we need to keep enough input to show errors in context */
Packit Service a31ea6
#define LINE_LEN        80
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_INPUT
Packit Service a31ea6
#define CHECK_BUFFER(in) check_buffer(in)
Packit Service a31ea6
Packit Service a31ea6
static
Packit Service a31ea6
void check_buffer(xmlParserInputPtr in) {
Packit Service a31ea6
    if (in->base != xmlBufContent(in->buf->buffer)) {
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"xmlParserInput: base mismatch problem\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (in->cur < in->base) {
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"xmlParserInput: cur < base problem\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    if (in->cur > in->base + xmlBufUse(in->buf->buffer)) {
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"xmlParserInput: cur > base + use problem\n");
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,"buffer %x : content %x, cur %d, use %d\n",
Packit Service a31ea6
            (int) in, (int) xmlBufContent(in->buf->buffer), in->cur - in->base,
Packit Service a31ea6
	    xmlBufUse(in->buf->buffer));
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#else
Packit Service a31ea6
#define CHECK_BUFFER(in)
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserInputRead:
Packit Service a31ea6
 * @in:  an XML parser input
Packit Service a31ea6
 * @len:  an indicative size for the lookahead
Packit Service a31ea6
 *
Packit Service a31ea6
 * This function was internal and is deprecated.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns -1 as this is an error to use it.
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlParserInputRead(xmlParserInputPtr in ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED) {
Packit Service a31ea6
    return(-1);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserInputGrow:
Packit Service a31ea6
 * @in:  an XML parser input
Packit Service a31ea6
 * @len:  an indicative size for the lookahead
Packit Service a31ea6
 *
Packit Service a31ea6
 * This function increase the input for the parser. It tries to
Packit Service a31ea6
 * preserve pointers to the input buffer, and keep already read data
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the amount of char read, or -1 in case of error, 0 indicate the
Packit Service a31ea6
 * end of this entity
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlParserInputGrow(xmlParserInputPtr in, int len) {
Packit Service a31ea6
    int ret;
Packit Service a31ea6
    size_t indx;
Packit Service a31ea6
    const xmlChar *content;
Packit Service a31ea6
Packit Service a31ea6
    if ((in == NULL) || (len < 0)) return(-1);
Packit Service a31ea6
#ifdef DEBUG_INPUT
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "Grow\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (in->buf == NULL) return(-1);
Packit Service a31ea6
    if (in->base == NULL) return(-1);
Packit Service a31ea6
    if (in->cur == NULL) return(-1);
Packit Service a31ea6
    if (in->buf->buffer == NULL) return(-1);
Packit Service a31ea6
Packit Service a31ea6
    CHECK_BUFFER(in);
Packit Service a31ea6
Packit Service a31ea6
    indx = in->cur - in->base;
Packit Service a31ea6
    if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) {
Packit Service a31ea6
Packit Service a31ea6
	CHECK_BUFFER(in);
Packit Service a31ea6
Packit Service a31ea6
        return(0);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (in->buf->readcallback != NULL) {
Packit Service a31ea6
	ret = xmlParserInputBufferGrow(in->buf, len);
Packit Service a31ea6
    } else
Packit Service a31ea6
        return(0);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * NOTE : in->base may be a "dangling" i.e. freed pointer in this
Packit Service a31ea6
     *        block, but we use it really as an integer to do some
Packit Service a31ea6
     *        pointer arithmetic. Insure will raise it as a bug but in
Packit Service a31ea6
     *        that specific case, that's not !
Packit Service a31ea6
     */
Packit Service a31ea6
Packit Service a31ea6
    content = xmlBufContent(in->buf->buffer);
Packit Service a31ea6
    if (in->base != content) {
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * the buffer has been reallocated
Packit Service a31ea6
	 */
Packit Service a31ea6
	indx = in->cur - in->base;
Packit Service a31ea6
	in->base = content;
Packit Service a31ea6
	in->cur = &content[indx];
Packit Service a31ea6
    }
Packit Service a31ea6
    in->end = xmlBufEnd(in->buf->buffer);
Packit Service a31ea6
Packit Service a31ea6
    CHECK_BUFFER(in);
Packit Service a31ea6
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserInputShrink:
Packit Service a31ea6
 * @in:  an XML parser input
Packit Service a31ea6
 *
Packit Service a31ea6
 * This function removes used input for the parser.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlParserInputShrink(xmlParserInputPtr in) {
Packit Service a31ea6
    size_t used;
Packit Service a31ea6
    size_t ret;
Packit Service a31ea6
    size_t indx;
Packit Service a31ea6
    const xmlChar *content;
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_INPUT
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "Shrink\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (in == NULL) return;
Packit Service a31ea6
    if (in->buf == NULL) return;
Packit Service a31ea6
    if (in->base == NULL) return;
Packit Service a31ea6
    if (in->cur == NULL) return;
Packit Service a31ea6
    if (in->buf->buffer == NULL) return;
Packit Service a31ea6
Packit Service a31ea6
    CHECK_BUFFER(in);
Packit Service a31ea6
Packit Service a31ea6
    used = in->cur - xmlBufContent(in->buf->buffer);
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Do not shrink on large buffers whose only a tiny fraction
Packit Service a31ea6
     * was consumed
Packit Service a31ea6
     */
Packit Service a31ea6
    if (used > INPUT_CHUNK) {
Packit Service a31ea6
	ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
Packit Service a31ea6
	if (ret > 0) {
Packit Service a31ea6
	    in->cur -= ret;
Packit Service a31ea6
	    in->consumed += ret;
Packit Service a31ea6
	}
Packit Service a31ea6
	in->end = xmlBufEnd(in->buf->buffer);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    CHECK_BUFFER(in);
Packit Service a31ea6
Packit Service a31ea6
    if (xmlBufUse(in->buf->buffer) > INPUT_CHUNK) {
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlParserInputBufferRead(in->buf, 2 * INPUT_CHUNK);
Packit Service a31ea6
    content = xmlBufContent(in->buf->buffer);
Packit Service a31ea6
    if (in->base != content) {
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * the buffer has been reallocated
Packit Service a31ea6
	 */
Packit Service a31ea6
	indx = in->cur - in->base;
Packit Service a31ea6
	in->base = content;
Packit Service a31ea6
	in->cur = &content[indx];
Packit Service a31ea6
    }
Packit Service a31ea6
    in->end = xmlBufEnd(in->buf->buffer);
Packit Service a31ea6
Packit Service a31ea6
    CHECK_BUFFER(in);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		UTF8 character input and related functions		*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNextChar:
Packit Service a31ea6
 * @ctxt:  the XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Skip to the next char input char.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
void
Packit Service a31ea6
xmlNextChar(xmlParserCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->instate == XML_PARSER_EOF) ||
Packit Service a31ea6
        (ctxt->input == NULL))
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
    if (!(VALID_CTXT(ctxt))) {
Packit Service a31ea6
        xmlErrInternal(ctxt, "Parser input data memory error\n", NULL);
Packit Service a31ea6
	ctxt->errNo = XML_ERR_INTERNAL_ERROR;
Packit Service a31ea6
        xmlStopParser(ctxt);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if ((*ctxt->input->cur == 0) &&
Packit Service a31ea6
        (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
Packit Service a31ea6
        const unsigned char *cur;
Packit Service a31ea6
        unsigned char c;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         *   2.11 End-of-Line Handling
Packit Service a31ea6
         *   the literal two-character sequence "#xD#xA" or a standalone
Packit Service a31ea6
         *   literal #xD, an XML processor must pass to the application
Packit Service a31ea6
         *   the single character #xA.
Packit Service a31ea6
         */
Packit Service a31ea6
        if (*(ctxt->input->cur) == '\n') {
Packit Service a31ea6
            ctxt->input->line++; ctxt->input->col = 1;
Packit Service a31ea6
        } else
Packit Service a31ea6
            ctxt->input->col++;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * We are supposed to handle UTF8, check it's valid
Packit Service a31ea6
         * From rfc2044: encoding of the Unicode values on UTF-8:
Packit Service a31ea6
         *
Packit Service a31ea6
         * UCS-4 range (hex.)           UTF-8 octet sequence (binary)
Packit Service a31ea6
         * 0000 0000-0000 007F   0xxxxxxx
Packit Service a31ea6
         * 0000 0080-0000 07FF   110xxxxx 10xxxxxx
Packit Service a31ea6
         * 0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
Packit Service a31ea6
         *
Packit Service a31ea6
         * Check for the 0x110000 limit too
Packit Service a31ea6
         */
Packit Service a31ea6
        cur = ctxt->input->cur;
Packit Service a31ea6
Packit Service a31ea6
        c = *cur;
Packit Service a31ea6
        if (c & 0x80) {
Packit Service a31ea6
            if (c == 0xC0)
Packit Service a31ea6
	        goto encoding_error;
Packit Service a31ea6
            if (cur[1] == 0) {
Packit Service a31ea6
                xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                cur = ctxt->input->cur;
Packit Service a31ea6
            }
Packit Service a31ea6
            if ((cur[1] & 0xc0) != 0x80)
Packit Service a31ea6
                goto encoding_error;
Packit Service a31ea6
            if ((c & 0xe0) == 0xe0) {
Packit Service a31ea6
                unsigned int val;
Packit Service a31ea6
Packit Service a31ea6
                if (cur[2] == 0) {
Packit Service a31ea6
                    xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                    cur = ctxt->input->cur;
Packit Service a31ea6
                }
Packit Service a31ea6
                if ((cur[2] & 0xc0) != 0x80)
Packit Service a31ea6
                    goto encoding_error;
Packit Service a31ea6
                if ((c & 0xf0) == 0xf0) {
Packit Service a31ea6
                    if (cur[3] == 0) {
Packit Service a31ea6
                        xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                        cur = ctxt->input->cur;
Packit Service a31ea6
                    }
Packit Service a31ea6
                    if (((c & 0xf8) != 0xf0) ||
Packit Service a31ea6
                        ((cur[3] & 0xc0) != 0x80))
Packit Service a31ea6
                        goto encoding_error;
Packit Service a31ea6
                    /* 4-byte code */
Packit Service a31ea6
                    ctxt->input->cur += 4;
Packit Service a31ea6
                    val = (cur[0] & 0x7) << 18;
Packit Service a31ea6
                    val |= (cur[1] & 0x3f) << 12;
Packit Service a31ea6
                    val |= (cur[2] & 0x3f) << 6;
Packit Service a31ea6
                    val |= cur[3] & 0x3f;
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    /* 3-byte code */
Packit Service a31ea6
                    ctxt->input->cur += 3;
Packit Service a31ea6
                    val = (cur[0] & 0xf) << 12;
Packit Service a31ea6
                    val |= (cur[1] & 0x3f) << 6;
Packit Service a31ea6
                    val |= cur[2] & 0x3f;
Packit Service a31ea6
                }
Packit Service a31ea6
                if (((val > 0xd7ff) && (val < 0xe000)) ||
Packit Service a31ea6
                    ((val > 0xfffd) && (val < 0x10000)) ||
Packit Service a31ea6
                    (val >= 0x110000)) {
Packit Service a31ea6
		xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
				  "Char 0x%X out of allowed range\n",
Packit Service a31ea6
				  val);
Packit Service a31ea6
                }
Packit Service a31ea6
            } else
Packit Service a31ea6
                /* 2-byte code */
Packit Service a31ea6
                ctxt->input->cur += 2;
Packit Service a31ea6
        } else
Packit Service a31ea6
            /* 1-byte code */
Packit Service a31ea6
            ctxt->input->cur++;
Packit Service a31ea6
Packit Service a31ea6
        ctxt->nbChars++;
Packit Service a31ea6
    } else {
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Assume it's a fixed length encoding (1) with
Packit Service a31ea6
         * a compatible encoding for the ASCII set, since
Packit Service a31ea6
         * XML constructs only use < 128 chars
Packit Service a31ea6
         */
Packit Service a31ea6
Packit Service a31ea6
        if (*(ctxt->input->cur) == '\n') {
Packit Service a31ea6
            ctxt->input->line++; ctxt->input->col = 1;
Packit Service a31ea6
        } else
Packit Service a31ea6
            ctxt->input->col++;
Packit Service a31ea6
        ctxt->input->cur++;
Packit Service a31ea6
        ctxt->nbChars++;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (*ctxt->input->cur == 0)
Packit Service a31ea6
        xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
    return;
Packit Service a31ea6
encoding_error:
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If we detect an UTF8 error that probably mean that the
Packit Service a31ea6
     * input encoding didn't get properly advertised in the
Packit Service a31ea6
     * declaration header. Report the error and switch the encoding
Packit Service a31ea6
     * to ISO-Latin-1 (if you don't like this policy, just declare the
Packit Service a31ea6
     * encoding !)
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->input == NULL) ||
Packit Service a31ea6
        (ctxt->input->end - ctxt->input->cur < 4)) {
Packit Service a31ea6
	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
		     "Input is not proper UTF-8, indicate encoding !\n",
Packit Service a31ea6
		     NULL, NULL);
Packit Service a31ea6
    } else {
Packit Service a31ea6
        char buffer[150];
Packit Service a31ea6
Packit Service a31ea6
	snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
Packit Service a31ea6
			ctxt->input->cur[0], ctxt->input->cur[1],
Packit Service a31ea6
			ctxt->input->cur[2], ctxt->input->cur[3]);
Packit Service a31ea6
	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
		     "Input is not proper UTF-8, indicate encoding !\n%s",
Packit Service a31ea6
		     BAD_CAST buffer, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->charset = XML_CHAR_ENCODING_8859_1;
Packit Service a31ea6
    ctxt->input->cur++;
Packit Service a31ea6
    return;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCurrentChar:
Packit Service a31ea6
 * @ctxt:  the XML parser context
Packit Service a31ea6
 * @len:  pointer to the length of the char read
Packit Service a31ea6
 *
Packit Service a31ea6
 * The current char value, if using UTF-8 this may actually span multiple
Packit Service a31ea6
 * bytes in the input buffer. Implement the end of line normalization:
Packit Service a31ea6
 * 2.11 End-of-Line Handling
Packit Service a31ea6
 * Wherever an external parsed entity or the literal entity value
Packit Service a31ea6
 * of an internal parsed entity contains either the literal two-character
Packit Service a31ea6
 * sequence "#xD#xA" or a standalone literal #xD, an XML processor
Packit Service a31ea6
 * must pass to the application the single character #xA.
Packit Service a31ea6
 * This behavior can conveniently be produced by normalizing all
Packit Service a31ea6
 * line breaks to #xA on input, before parsing.)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the current char value and its length
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
Packit Service a31ea6
    if ((ctxt == NULL) || (len == NULL) || (ctxt->input == NULL)) return(0);
Packit Service a31ea6
    if (ctxt->instate == XML_PARSER_EOF)
Packit Service a31ea6
	return(0);
Packit Service a31ea6
Packit Service a31ea6
    if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
Packit Service a31ea6
	    *len = 1;
Packit Service a31ea6
	    return((int) *ctxt->input->cur);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * We are supposed to handle UTF8, check it's valid
Packit Service a31ea6
	 * From rfc2044: encoding of the Unicode values on UTF-8:
Packit Service a31ea6
	 *
Packit Service a31ea6
	 * UCS-4 range (hex.)           UTF-8 octet sequence (binary)
Packit Service a31ea6
	 * 0000 0000-0000 007F   0xxxxxxx
Packit Service a31ea6
	 * 0000 0080-0000 07FF   110xxxxx 10xxxxxx
Packit Service a31ea6
	 * 0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
Packit Service a31ea6
	 *
Packit Service a31ea6
	 * Check for the 0x110000 limit too
Packit Service a31ea6
	 */
Packit Service a31ea6
	const unsigned char *cur = ctxt->input->cur;
Packit Service a31ea6
	unsigned char c;
Packit Service a31ea6
	unsigned int val;
Packit Service a31ea6
Packit Service a31ea6
	c = *cur;
Packit Service a31ea6
	if (c & 0x80) {
Packit Service a31ea6
	    if (((c & 0x40) == 0) || (c == 0xC0))
Packit Service a31ea6
		goto encoding_error;
Packit Service a31ea6
	    if (cur[1] == 0) {
Packit Service a31ea6
		xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                cur = ctxt->input->cur;
Packit Service a31ea6
            }
Packit Service a31ea6
	    if ((cur[1] & 0xc0) != 0x80)
Packit Service a31ea6
		goto encoding_error;
Packit Service a31ea6
	    if ((c & 0xe0) == 0xe0) {
Packit Service a31ea6
		if (cur[2] == 0) {
Packit Service a31ea6
		    xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                    cur = ctxt->input->cur;
Packit Service a31ea6
                }
Packit Service a31ea6
		if ((cur[2] & 0xc0) != 0x80)
Packit Service a31ea6
		    goto encoding_error;
Packit Service a31ea6
		if ((c & 0xf0) == 0xf0) {
Packit Service a31ea6
		    if (cur[3] == 0) {
Packit Service a31ea6
			xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
                        cur = ctxt->input->cur;
Packit Service a31ea6
                    }
Packit Service a31ea6
		    if (((c & 0xf8) != 0xf0) ||
Packit Service a31ea6
			((cur[3] & 0xc0) != 0x80))
Packit Service a31ea6
			goto encoding_error;
Packit Service a31ea6
		    /* 4-byte code */
Packit Service a31ea6
		    *len = 4;
Packit Service a31ea6
		    val = (cur[0] & 0x7) << 18;
Packit Service a31ea6
		    val |= (cur[1] & 0x3f) << 12;
Packit Service a31ea6
		    val |= (cur[2] & 0x3f) << 6;
Packit Service a31ea6
		    val |= cur[3] & 0x3f;
Packit Service a31ea6
		    if (val < 0x10000)
Packit Service a31ea6
			goto encoding_error;
Packit Service a31ea6
		} else {
Packit Service a31ea6
		  /* 3-byte code */
Packit Service a31ea6
		    *len = 3;
Packit Service a31ea6
		    val = (cur[0] & 0xf) << 12;
Packit Service a31ea6
		    val |= (cur[1] & 0x3f) << 6;
Packit Service a31ea6
		    val |= cur[2] & 0x3f;
Packit Service a31ea6
		    if (val < 0x800)
Packit Service a31ea6
			goto encoding_error;
Packit Service a31ea6
		}
Packit Service a31ea6
	    } else {
Packit Service a31ea6
	      /* 2-byte code */
Packit Service a31ea6
		*len = 2;
Packit Service a31ea6
		val = (cur[0] & 0x1f) << 6;
Packit Service a31ea6
		val |= cur[1] & 0x3f;
Packit Service a31ea6
		if (val < 0x80)
Packit Service a31ea6
		    goto encoding_error;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (!IS_CHAR(val)) {
Packit Service a31ea6
	        xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
				  "Char 0x%X out of allowed range\n", val);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    return(val);
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    /* 1-byte code */
Packit Service a31ea6
	    *len = 1;
Packit Service a31ea6
	    if (*ctxt->input->cur == 0)
Packit Service a31ea6
		xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
Packit Service a31ea6
	    if ((*ctxt->input->cur == 0) &&
Packit Service a31ea6
	        (ctxt->input->end > ctxt->input->cur)) {
Packit Service a31ea6
	        xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
				  "Char 0x0 out of allowed range\n", 0);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (*ctxt->input->cur == 0xD) {
Packit Service a31ea6
		if (ctxt->input->cur[1] == 0xA) {
Packit Service a31ea6
		    ctxt->nbChars++;
Packit Service a31ea6
		    ctxt->input->cur++;
Packit Service a31ea6
		}
Packit Service a31ea6
		return(0xA);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    return((int) *ctxt->input->cur);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Assume it's a fixed length encoding (1) with
Packit Service a31ea6
     * a compatible encoding for the ASCII set, since
Packit Service a31ea6
     * XML constructs only use < 128 chars
Packit Service a31ea6
     */
Packit Service a31ea6
    *len = 1;
Packit Service a31ea6
    if (*ctxt->input->cur == 0xD) {
Packit Service a31ea6
	if (ctxt->input->cur[1] == 0xA) {
Packit Service a31ea6
	    ctxt->nbChars++;
Packit Service a31ea6
	    ctxt->input->cur++;
Packit Service a31ea6
	}
Packit Service a31ea6
	return(0xA);
Packit Service a31ea6
    }
Packit Service a31ea6
    return((int) *ctxt->input->cur);
Packit Service a31ea6
encoding_error:
Packit Service a31ea6
    /*
Packit Service a31ea6
     * An encoding problem may arise from a truncated input buffer
Packit Service a31ea6
     * splitting a character in the middle. In that case do not raise
Packit Service a31ea6
     * an error but return 0 to endicate an end of stream problem
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->input->end - ctxt->input->cur < 4) {
Packit Service a31ea6
	*len = 0;
Packit Service a31ea6
	return(0);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If we detect an UTF8 error that probably mean that the
Packit Service a31ea6
     * input encoding didn't get properly advertised in the
Packit Service a31ea6
     * declaration header. Report the error and switch the encoding
Packit Service a31ea6
     * to ISO-Latin-1 (if you don't like this policy, just declare the
Packit Service a31ea6
     * encoding !)
Packit Service a31ea6
     */
Packit Service a31ea6
    {
Packit Service a31ea6
        char buffer[150];
Packit Service a31ea6
Packit Service a31ea6
	snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
Packit Service a31ea6
			ctxt->input->cur[0], ctxt->input->cur[1],
Packit Service a31ea6
			ctxt->input->cur[2], ctxt->input->cur[3]);
Packit Service a31ea6
	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
		     "Input is not proper UTF-8, indicate encoding !\n%s",
Packit Service a31ea6
		     BAD_CAST buffer, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->charset = XML_CHAR_ENCODING_8859_1;
Packit Service a31ea6
    *len = 1;
Packit Service a31ea6
    return((int) *ctxt->input->cur);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlStringCurrentChar:
Packit Service a31ea6
 * @ctxt:  the XML parser context
Packit Service a31ea6
 * @cur:  pointer to the beginning of the char
Packit Service a31ea6
 * @len:  pointer to the length of the char read
Packit Service a31ea6
 *
Packit Service a31ea6
 * The current char value, if using UTF-8 this may actually span multiple
Packit Service a31ea6
 * bytes in the input buffer.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the current char value and its length
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar * cur, int *len)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((len == NULL) || (cur == NULL)) return(0);
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->charset == XML_CHAR_ENCODING_UTF8)) {
Packit Service a31ea6
        /*
Packit Service a31ea6
         * We are supposed to handle UTF8, check it's valid
Packit Service a31ea6
         * From rfc2044: encoding of the Unicode values on UTF-8:
Packit Service a31ea6
         *
Packit Service a31ea6
         * UCS-4 range (hex.)           UTF-8 octet sequence (binary)
Packit Service a31ea6
         * 0000 0000-0000 007F   0xxxxxxx
Packit Service a31ea6
         * 0000 0080-0000 07FF   110xxxxx 10xxxxxx
Packit Service a31ea6
         * 0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
Packit Service a31ea6
         *
Packit Service a31ea6
         * Check for the 0x110000 limit too
Packit Service a31ea6
         */
Packit Service a31ea6
        unsigned char c;
Packit Service a31ea6
        unsigned int val;
Packit Service a31ea6
Packit Service a31ea6
        c = *cur;
Packit Service a31ea6
        if (c & 0x80) {
Packit Service a31ea6
            if ((cur[1] & 0xc0) != 0x80)
Packit Service a31ea6
                goto encoding_error;
Packit Service a31ea6
            if ((c & 0xe0) == 0xe0) {
Packit Service a31ea6
Packit Service a31ea6
                if ((cur[2] & 0xc0) != 0x80)
Packit Service a31ea6
                    goto encoding_error;
Packit Service a31ea6
                if ((c & 0xf0) == 0xf0) {
Packit Service a31ea6
                    if (((c & 0xf8) != 0xf0) || ((cur[3] & 0xc0) != 0x80))
Packit Service a31ea6
                        goto encoding_error;
Packit Service a31ea6
                    /* 4-byte code */
Packit Service a31ea6
                    *len = 4;
Packit Service a31ea6
                    val = (cur[0] & 0x7) << 18;
Packit Service a31ea6
                    val |= (cur[1] & 0x3f) << 12;
Packit Service a31ea6
                    val |= (cur[2] & 0x3f) << 6;
Packit Service a31ea6
                    val |= cur[3] & 0x3f;
Packit Service a31ea6
                } else {
Packit Service a31ea6
                    /* 3-byte code */
Packit Service a31ea6
                    *len = 3;
Packit Service a31ea6
                    val = (cur[0] & 0xf) << 12;
Packit Service a31ea6
                    val |= (cur[1] & 0x3f) << 6;
Packit Service a31ea6
                    val |= cur[2] & 0x3f;
Packit Service a31ea6
                }
Packit Service a31ea6
            } else {
Packit Service a31ea6
                /* 2-byte code */
Packit Service a31ea6
                *len = 2;
Packit Service a31ea6
                val = (cur[0] & 0x1f) << 6;
Packit Service a31ea6
                val |= cur[1] & 0x3f;
Packit Service a31ea6
            }
Packit Service a31ea6
            if (!IS_CHAR(val)) {
Packit Service a31ea6
	        xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
				  "Char 0x%X out of allowed range\n", val);
Packit Service a31ea6
            }
Packit Service a31ea6
            return (val);
Packit Service a31ea6
        } else {
Packit Service a31ea6
            /* 1-byte code */
Packit Service a31ea6
            *len = 1;
Packit Service a31ea6
            return ((int) *cur);
Packit Service a31ea6
        }
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Assume it's a fixed length encoding (1) with
Packit Service a31ea6
     * a compatible encoding for the ASCII set, since
Packit Service a31ea6
     * XML constructs only use < 128 chars
Packit Service a31ea6
     */
Packit Service a31ea6
    *len = 1;
Packit Service a31ea6
    return ((int) *cur);
Packit Service a31ea6
encoding_error:
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * An encoding problem may arise from a truncated input buffer
Packit Service a31ea6
     * splitting a character in the middle. In that case do not raise
Packit Service a31ea6
     * an error but return 0 to endicate an end of stream problem
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->input == NULL) ||
Packit Service a31ea6
        (ctxt->input->end - ctxt->input->cur < 4)) {
Packit Service a31ea6
	*len = 0;
Packit Service a31ea6
	return(0);
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If we detect an UTF8 error that probably mean that the
Packit Service a31ea6
     * input encoding didn't get properly advertised in the
Packit Service a31ea6
     * declaration header. Report the error and switch the encoding
Packit Service a31ea6
     * to ISO-Latin-1 (if you don't like this policy, just declare the
Packit Service a31ea6
     * encoding !)
Packit Service a31ea6
     */
Packit Service a31ea6
    {
Packit Service a31ea6
        char buffer[150];
Packit Service a31ea6
Packit Service a31ea6
	snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
Packit Service a31ea6
			ctxt->input->cur[0], ctxt->input->cur[1],
Packit Service a31ea6
			ctxt->input->cur[2], ctxt->input->cur[3]);
Packit Service a31ea6
	__xmlErrEncoding(ctxt, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
		     "Input is not proper UTF-8, indicate encoding !\n%s",
Packit Service a31ea6
		     BAD_CAST buffer, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    *len = 1;
Packit Service a31ea6
    return ((int) *cur);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCopyCharMultiByte:
Packit Service a31ea6
 * @out:  pointer to an array of xmlChar
Packit Service a31ea6
 * @val:  the char value
Packit Service a31ea6
 *
Packit Service a31ea6
 * append the char value in the array
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the number of xmlChar written
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlCopyCharMultiByte(xmlChar *out, int val) {
Packit Service a31ea6
    if (out == NULL) return(0);
Packit Service a31ea6
    /*
Packit Service a31ea6
     * We are supposed to handle UTF8, check it's valid
Packit Service a31ea6
     * From rfc2044: encoding of the Unicode values on UTF-8:
Packit Service a31ea6
     *
Packit Service a31ea6
     * UCS-4 range (hex.)           UTF-8 octet sequence (binary)
Packit Service a31ea6
     * 0000 0000-0000 007F   0xxxxxxx
Packit Service a31ea6
     * 0000 0080-0000 07FF   110xxxxx 10xxxxxx
Packit Service a31ea6
     * 0000 0800-0000 FFFF   1110xxxx 10xxxxxx 10xxxxxx
Packit Service a31ea6
     */
Packit Service a31ea6
    if  (val >= 0x80) {
Packit Service a31ea6
	xmlChar *savedout = out;
Packit Service a31ea6
	int bits;
Packit Service a31ea6
	if (val <   0x800) { *out++= (val >>  6) | 0xC0;  bits=  0; }
Packit Service a31ea6
	else if (val < 0x10000) { *out++= (val >> 12) | 0xE0;  bits=  6;}
Packit Service a31ea6
	else if (val < 0x110000)  { *out++= (val >> 18) | 0xF0;  bits=  12; }
Packit Service a31ea6
	else {
Packit Service a31ea6
	    xmlErrEncodingInt(NULL, XML_ERR_INVALID_CHAR,
Packit Service a31ea6
		    "Internal error, xmlCopyCharMultiByte 0x%X out of bound\n",
Packit Service a31ea6
			      val);
Packit Service a31ea6
	    return(0);
Packit Service a31ea6
	}
Packit Service a31ea6
	for ( ; bits >= 0; bits-= 6)
Packit Service a31ea6
	    *out++= ((val >> bits) & 0x3F) | 0x80 ;
Packit Service a31ea6
	return (out - savedout);
Packit Service a31ea6
    }
Packit Service a31ea6
    *out = (xmlChar) val;
Packit Service a31ea6
    return 1;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlCopyChar:
Packit Service a31ea6
 * @len:  Ignored, compatibility
Packit Service a31ea6
 * @out:  pointer to an array of xmlChar
Packit Service a31ea6
 * @val:  the char value
Packit Service a31ea6
 *
Packit Service a31ea6
 * append the char value in the array
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the number of xmlChar written
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlCopyChar(int len ATTRIBUTE_UNUSED, xmlChar *out, int val) {
Packit Service a31ea6
    if (out == NULL) return(0);
Packit Service a31ea6
    /* the len parameter is ignored */
Packit Service a31ea6
    if  (val >= 0x80) {
Packit Service a31ea6
	return(xmlCopyCharMultiByte (out, val));
Packit Service a31ea6
    }
Packit Service a31ea6
    *out = (xmlChar) val;
Packit Service a31ea6
    return 1;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Commodity functions to switch encodings			*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
static int
Packit Service a31ea6
xmlSwitchToEncodingInt(xmlParserCtxtPtr ctxt,
Packit Service a31ea6
                       xmlCharEncodingHandlerPtr handler, int len);
Packit Service a31ea6
static int
Packit Service a31ea6
xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
Packit Service a31ea6
                          xmlCharEncodingHandlerPtr handler, int len);
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSwitchEncoding:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @enc:  the encoding value (number)
Packit Service a31ea6
 *
Packit Service a31ea6
 * change the input functions when discovering the character encoding
Packit Service a31ea6
 * of a given entity.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success, -1 otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlCharEncodingHandlerPtr handler;
Packit Service a31ea6
    int len = -1;
Packit Service a31ea6
    int ret;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt == NULL) return(-1);
Packit Service a31ea6
    switch (enc) {
Packit Service a31ea6
	case XML_CHAR_ENCODING_ERROR:
Packit Service a31ea6
	    __xmlErrEncoding(ctxt, XML_ERR_UNKNOWN_ENCODING,
Packit Service a31ea6
	                   "encoding unknown\n", NULL, NULL);
Packit Service a31ea6
	    return(-1);
Packit Service a31ea6
	case XML_CHAR_ENCODING_NONE:
Packit Service a31ea6
	    /* let's assume it's UTF-8 without the XML decl */
Packit Service a31ea6
	    ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
	    return(0);
Packit Service a31ea6
	case XML_CHAR_ENCODING_UTF8:
Packit Service a31ea6
	    /* default encoding, no conversion should be needed */
Packit Service a31ea6
	    ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * Errata on XML-1.0 June 20 2001
Packit Service a31ea6
	     * Specific handling of the Byte Order Mark for
Packit Service a31ea6
	     * UTF-8
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if ((ctxt->input != NULL) &&
Packit Service a31ea6
		(ctxt->input->cur[0] == 0xEF) &&
Packit Service a31ea6
		(ctxt->input->cur[1] == 0xBB) &&
Packit Service a31ea6
		(ctxt->input->cur[2] == 0xBF)) {
Packit Service a31ea6
		ctxt->input->cur += 3;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    return(0);
Packit Service a31ea6
    case XML_CHAR_ENCODING_UTF16LE:
Packit Service a31ea6
    case XML_CHAR_ENCODING_UTF16BE:
Packit Service a31ea6
        /*The raw input characters are encoded
Packit Service a31ea6
         *in UTF-16. As we expect this function
Packit Service a31ea6
         *to be called after xmlCharEncInFunc, we expect
Packit Service a31ea6
         *ctxt->input->cur to contain UTF-8 encoded characters.
Packit Service a31ea6
         *So the raw UTF16 Byte Order Mark
Packit Service a31ea6
         *has also been converted into
Packit Service a31ea6
         *an UTF-8 BOM. Let's skip that BOM.
Packit Service a31ea6
         */
Packit Service a31ea6
        if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) &&
Packit Service a31ea6
            (ctxt->input->cur[0] == 0xEF) &&
Packit Service a31ea6
            (ctxt->input->cur[1] == 0xBB) &&
Packit Service a31ea6
            (ctxt->input->cur[2] == 0xBF)) {
Packit Service a31ea6
            ctxt->input->cur += 3;
Packit Service a31ea6
        }
Packit Service a31ea6
        len = 90;
Packit Service a31ea6
	break;
Packit Service a31ea6
    case XML_CHAR_ENCODING_UCS2:
Packit Service a31ea6
        len = 90;
Packit Service a31ea6
	break;
Packit Service a31ea6
    case XML_CHAR_ENCODING_UCS4BE:
Packit Service a31ea6
    case XML_CHAR_ENCODING_UCS4LE:
Packit Service a31ea6
    case XML_CHAR_ENCODING_UCS4_2143:
Packit Service a31ea6
    case XML_CHAR_ENCODING_UCS4_3412:
Packit Service a31ea6
        len = 180;
Packit Service a31ea6
	break;
Packit Service a31ea6
    case XML_CHAR_ENCODING_EBCDIC:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_1:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_2:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_3:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_4:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_5:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_6:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_7:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_8:
Packit Service a31ea6
    case XML_CHAR_ENCODING_8859_9:
Packit Service a31ea6
    case XML_CHAR_ENCODING_ASCII:
Packit Service a31ea6
    case XML_CHAR_ENCODING_2022_JP:
Packit Service a31ea6
    case XML_CHAR_ENCODING_SHIFT_JIS:
Packit Service a31ea6
    case XML_CHAR_ENCODING_EUC_JP:
Packit Service a31ea6
        len = 45;
Packit Service a31ea6
	break;
Packit Service a31ea6
    }
Packit Service a31ea6
    handler = xmlGetCharEncodingHandler(enc);
Packit Service a31ea6
    if (handler == NULL) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Default handlers.
Packit Service a31ea6
	 */
Packit Service a31ea6
	switch (enc) {
Packit Service a31ea6
	    case XML_CHAR_ENCODING_ASCII:
Packit Service a31ea6
		/* default encoding, no conversion should be needed */
Packit Service a31ea6
		ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
		return(0);
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UTF16LE:
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UTF16BE:
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UCS4LE:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "USC4 little endian", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UCS4BE:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "USC4 big endian", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_EBCDIC:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "EBCDIC", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UCS4_2143:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "UCS4 2143", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UCS4_3412:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "UCS4 3412", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_UCS2:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "UCS2", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_1:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_2:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_3:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_4:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_5:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_6:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_7:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_8:
Packit Service a31ea6
	    case XML_CHAR_ENCODING_8859_9:
Packit Service a31ea6
		/*
Packit Service a31ea6
		 * We used to keep the internal content in the
Packit Service a31ea6
		 * document encoding however this turns being unmaintainable
Packit Service a31ea6
		 * So xmlGetCharEncodingHandler() will return non-null
Packit Service a31ea6
		 * values for this now.
Packit Service a31ea6
		 */
Packit Service a31ea6
		if ((ctxt->inputNr == 1) &&
Packit Service a31ea6
		    (ctxt->encoding == NULL) &&
Packit Service a31ea6
		    (ctxt->input != NULL) &&
Packit Service a31ea6
		    (ctxt->input->encoding != NULL)) {
Packit Service a31ea6
		    ctxt->encoding = xmlStrdup(ctxt->input->encoding);
Packit Service a31ea6
		}
Packit Service a31ea6
		ctxt->charset = enc;
Packit Service a31ea6
		return(0);
Packit Service a31ea6
	    case XML_CHAR_ENCODING_2022_JP:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "ISO-2022-JP", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_SHIFT_JIS:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "Shift_JIS", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    case XML_CHAR_ENCODING_EUC_JP:
Packit Service a31ea6
		__xmlErrEncoding(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
Packit Service a31ea6
			       "encoding not supported %s\n",
Packit Service a31ea6
			       BAD_CAST "EUC-JP", NULL);
Packit Service a31ea6
		break;
Packit Service a31ea6
	    default:
Packit Service a31ea6
	        break;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * TODO: We could recover from errors in external entites if we
Packit Service a31ea6
     * didn't stop the parser. But most callers of this function don't
Packit Service a31ea6
     * check the return value.
Packit Service a31ea6
     */
Packit Service a31ea6
    if (handler == NULL) {
Packit Service a31ea6
        xmlStopParser(ctxt);
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
    ret = xmlSwitchToEncodingInt(ctxt, handler, len);
Packit Service a31ea6
    if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * on encoding conversion errors, stop the parser
Packit Service a31ea6
	 */
Packit Service a31ea6
        xmlStopParser(ctxt);
Packit Service a31ea6
	ctxt->errNo = XML_I18N_CONV_FAILED;
Packit Service a31ea6
    }
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSwitchInputEncoding:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @input:  the input stream
Packit Service a31ea6
 * @handler:  the encoding handler
Packit Service a31ea6
 * @len:  the number of bytes to convert for the first line or -1
Packit Service a31ea6
 *
Packit Service a31ea6
 * change the input functions when discovering the character encoding
Packit Service a31ea6
 * of a given entity.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success, -1 otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
Packit Service a31ea6
                          xmlCharEncodingHandlerPtr handler, int len)
Packit Service a31ea6
{
Packit Service a31ea6
    int nbchars;
Packit Service a31ea6
Packit Service a31ea6
    if (handler == NULL)
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    if (input == NULL)
Packit Service a31ea6
        return (-1);
Packit Service a31ea6
    if (input->buf != NULL) {
Packit Service a31ea6
        if (input->buf->encoder != NULL) {
Packit Service a31ea6
            /*
Packit Service a31ea6
             * Check in case the auto encoding detetection triggered
Packit Service a31ea6
             * in already.
Packit Service a31ea6
             */
Packit Service a31ea6
            if (input->buf->encoder == handler)
Packit Service a31ea6
                return (0);
Packit Service a31ea6
Packit Service a31ea6
            /*
Packit Service a31ea6
             * "UTF-16" can be used for both LE and BE
Packit Service a31ea6
             if ((!xmlStrncmp(BAD_CAST input->buf->encoder->name,
Packit Service a31ea6
             BAD_CAST "UTF-16", 6)) &&
Packit Service a31ea6
             (!xmlStrncmp(BAD_CAST handler->name,
Packit Service a31ea6
             BAD_CAST "UTF-16", 6))) {
Packit Service a31ea6
             return(0);
Packit Service a31ea6
             }
Packit Service a31ea6
             */
Packit Service a31ea6
Packit Service a31ea6
            /*
Packit Service a31ea6
             * Note: this is a bit dangerous, but that's what it
Packit Service a31ea6
             * takes to use nearly compatible signature for different
Packit Service a31ea6
             * encodings.
Packit Service a31ea6
             */
Packit Service a31ea6
            xmlCharEncCloseFunc(input->buf->encoder);
Packit Service a31ea6
            input->buf->encoder = handler;
Packit Service a31ea6
            return (0);
Packit Service a31ea6
        }
Packit Service a31ea6
        input->buf->encoder = handler;
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Is there already some content down the pipe to convert ?
Packit Service a31ea6
         */
Packit Service a31ea6
        if (xmlBufIsEmpty(input->buf->buffer) == 0) {
Packit Service a31ea6
            int processed;
Packit Service a31ea6
	    unsigned int use;
Packit Service a31ea6
Packit Service a31ea6
            /*
Packit Service a31ea6
             * Specific handling of the Byte Order Mark for
Packit Service a31ea6
             * UTF-16
Packit Service a31ea6
             */
Packit Service a31ea6
            if ((handler->name != NULL) &&
Packit Service a31ea6
                (!strcmp(handler->name, "UTF-16LE") ||
Packit Service a31ea6
                 !strcmp(handler->name, "UTF-16")) &&
Packit Service a31ea6
                (input->cur[0] == 0xFF) && (input->cur[1] == 0xFE)) {
Packit Service a31ea6
                input->cur += 2;
Packit Service a31ea6
            }
Packit Service a31ea6
            if ((handler->name != NULL) &&
Packit Service a31ea6
                (!strcmp(handler->name, "UTF-16BE")) &&
Packit Service a31ea6
                (input->cur[0] == 0xFE) && (input->cur[1] == 0xFF)) {
Packit Service a31ea6
                input->cur += 2;
Packit Service a31ea6
            }
Packit Service a31ea6
            /*
Packit Service a31ea6
             * Errata on XML-1.0 June 20 2001
Packit Service a31ea6
             * Specific handling of the Byte Order Mark for
Packit Service a31ea6
             * UTF-8
Packit Service a31ea6
             */
Packit Service a31ea6
            if ((handler->name != NULL) &&
Packit Service a31ea6
                (!strcmp(handler->name, "UTF-8")) &&
Packit Service a31ea6
                (input->cur[0] == 0xEF) &&
Packit Service a31ea6
                (input->cur[1] == 0xBB) && (input->cur[2] == 0xBF)) {
Packit Service a31ea6
                input->cur += 3;
Packit Service a31ea6
            }
Packit Service a31ea6
Packit Service a31ea6
            /*
Packit Service a31ea6
             * Shrink the current input buffer.
Packit Service a31ea6
             * Move it as the raw buffer and create a new input buffer
Packit Service a31ea6
             */
Packit Service a31ea6
            processed = input->cur - input->base;
Packit Service a31ea6
            xmlBufShrink(input->buf->buffer, processed);
Packit Service a31ea6
            input->buf->raw = input->buf->buffer;
Packit Service a31ea6
            input->buf->buffer = xmlBufCreate();
Packit Service a31ea6
	    input->buf->rawconsumed = processed;
Packit Service a31ea6
	    use = xmlBufUse(input->buf->raw);
Packit Service a31ea6
Packit Service a31ea6
            if (ctxt->html) {
Packit Service a31ea6
                /*
Packit Service a31ea6
                 * convert as much as possible of the buffer
Packit Service a31ea6
                 */
Packit Service a31ea6
                nbchars = xmlCharEncInput(input->buf, 1);
Packit Service a31ea6
            } else {
Packit Service a31ea6
                /*
Packit Service a31ea6
                 * convert just enough to get
Packit Service a31ea6
                 * ''
Packit Service a31ea6
                 * parsed with the autodetected encoding
Packit Service a31ea6
                 * into the parser reading buffer.
Packit Service a31ea6
                 */
Packit Service a31ea6
                nbchars = xmlCharEncFirstLineInput(input->buf, len);
Packit Service a31ea6
            }
Packit Service a31ea6
            xmlBufResetInput(input->buf->buffer, input);
Packit Service a31ea6
            if (nbchars < 0) {
Packit Service a31ea6
                xmlErrInternal(ctxt,
Packit Service a31ea6
                               "switching encoding: encoder error\n",
Packit Service a31ea6
                               NULL);
Packit Service a31ea6
                return (-1);
Packit Service a31ea6
            }
Packit Service a31ea6
	    input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
Packit Service a31ea6
        }
Packit Service a31ea6
        return (0);
Packit Service a31ea6
    } else if (input->length == 0) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * When parsing a static memory array one must know the
Packit Service a31ea6
	 * size to be able to convert the buffer.
Packit Service a31ea6
	 */
Packit Service a31ea6
	xmlErrInternal(ctxt, "switching encoding : no input\n", NULL);
Packit Service a31ea6
	return (-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    return (0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSwitchInputEncoding:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @input:  the input stream
Packit Service a31ea6
 * @handler:  the encoding handler
Packit Service a31ea6
 *
Packit Service a31ea6
 * change the input functions when discovering the character encoding
Packit Service a31ea6
 * of a given entity.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success, -1 otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
Packit Service a31ea6
                          xmlCharEncodingHandlerPtr handler) {
Packit Service a31ea6
    return(xmlSwitchInputEncodingInt(ctxt, input, handler, -1));
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSwitchToEncodingInt:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @handler:  the encoding handler
Packit Service a31ea6
 * @len: the length to convert or -1
Packit Service a31ea6
 *
Packit Service a31ea6
 * change the input functions when discovering the character encoding
Packit Service a31ea6
 * of a given entity, and convert only @len bytes of the output, this
Packit Service a31ea6
 * is needed on auto detect to allows any declared encoding later to
Packit Service a31ea6
 * convert the actual content after the xmlDecl
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success, -1 otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
static int
Packit Service a31ea6
xmlSwitchToEncodingInt(xmlParserCtxtPtr ctxt,
Packit Service a31ea6
                       xmlCharEncodingHandlerPtr handler, int len) {
Packit Service a31ea6
    int ret = 0;
Packit Service a31ea6
Packit Service a31ea6
    if (handler != NULL) {
Packit Service a31ea6
        if (ctxt->input != NULL) {
Packit Service a31ea6
	    ret = xmlSwitchInputEncodingInt(ctxt, ctxt->input, handler, len);
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlErrInternal(ctxt, "xmlSwitchToEncoding : no input\n",
Packit Service a31ea6
	                   NULL);
Packit Service a31ea6
	    return(-1);
Packit Service a31ea6
	}
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * The parsing is now done in UTF8 natively
Packit Service a31ea6
	 */
Packit Service a31ea6
	ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
    } else
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSwitchToEncoding:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @handler:  the encoding handler
Packit Service a31ea6
 *
Packit Service a31ea6
 * change the input functions when discovering the character encoding
Packit Service a31ea6
 * of a given entity.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success, -1 otherwise
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
Packit Service a31ea6
{
Packit Service a31ea6
    return (xmlSwitchToEncodingInt(ctxt, handler, -1));
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *	Commodity functions to handle entities processing		*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlFreeInputStream:
Packit Service a31ea6
 * @input:  an xmlParserInputPtr
Packit Service a31ea6
 *
Packit Service a31ea6
 * Free up an input stream.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlFreeInputStream(xmlParserInputPtr input) {
Packit Service a31ea6
    if (input == NULL) return;
Packit Service a31ea6
Packit Service a31ea6
    if (input->filename != NULL) xmlFree((char *) input->filename);
Packit Service a31ea6
    if (input->directory != NULL) xmlFree((char *) input->directory);
Packit Service a31ea6
    if (input->encoding != NULL) xmlFree((char *) input->encoding);
Packit Service a31ea6
    if (input->version != NULL) xmlFree((char *) input->version);
Packit Service a31ea6
    if ((input->free != NULL) && (input->base != NULL))
Packit Service a31ea6
        input->free((xmlChar *) input->base);
Packit Service a31ea6
    if (input->buf != NULL)
Packit Service a31ea6
        xmlFreeParserInputBuffer(input->buf);
Packit Service a31ea6
    xmlFree(input);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewInputStream:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Create a new input stream structure.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the new input stream or NULL
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlNewInputStream(xmlParserCtxtPtr ctxt) {
Packit Service a31ea6
    xmlParserInputPtr input;
Packit Service a31ea6
Packit Service a31ea6
    input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput));
Packit Service a31ea6
    if (input == NULL) {
Packit Service a31ea6
        xmlErrMemory(ctxt,  "couldn't allocate a new input stream\n");
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    memset(input, 0, sizeof(xmlParserInput));
Packit Service a31ea6
    input->line = 1;
Packit Service a31ea6
    input->col = 1;
Packit Service a31ea6
    input->standalone = -1;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If the context is NULL the id cannot be initialized, but that
Packit Service a31ea6
     * should not happen while parsing which is the situation where
Packit Service a31ea6
     * the id is actually needed.
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt != NULL)
Packit Service a31ea6
        input->id = ctxt->input_id++;
Packit Service a31ea6
Packit Service a31ea6
    return(input);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewIOInputStream:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @input:  an I/O Input
Packit Service a31ea6
 * @enc:  the charset encoding if known
Packit Service a31ea6
 *
Packit Service a31ea6
 * Create a new input stream structure encapsulating the @input into
Packit Service a31ea6
 * a stream suitable for the parser.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the new input stream or NULL
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input,
Packit Service a31ea6
	            xmlCharEncoding enc) {
Packit Service a31ea6
    xmlParserInputPtr inputStream;
Packit Service a31ea6
Packit Service a31ea6
    if (input == NULL) return(NULL);
Packit Service a31ea6
    if (xmlParserDebugEntities)
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext, "new input from I/O\n");
Packit Service a31ea6
    inputStream = xmlNewInputStream(ctxt);
Packit Service a31ea6
    if (inputStream == NULL) {
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    inputStream->filename = NULL;
Packit Service a31ea6
    inputStream->buf = input;
Packit Service a31ea6
    xmlBufResetInput(inputStream->buf->buffer, inputStream);
Packit Service a31ea6
Packit Service a31ea6
    if (enc != XML_CHAR_ENCODING_NONE) {
Packit Service a31ea6
        xmlSwitchEncoding(ctxt, enc);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    return(inputStream);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewEntityInputStream:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @entity:  an Entity pointer
Packit Service a31ea6
 *
Packit Service a31ea6
 * Create a new input stream based on an xmlEntityPtr
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the new input stream or NULL
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
Packit Service a31ea6
    xmlParserInputPtr input;
Packit Service a31ea6
Packit Service a31ea6
    if (entity == NULL) {
Packit Service a31ea6
        xmlErrInternal(ctxt, "xmlNewEntityInputStream entity = NULL\n",
Packit Service a31ea6
	               NULL);
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (xmlParserDebugEntities)
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"new input from entity: %s\n", entity->name);
Packit Service a31ea6
    if (entity->content == NULL) {
Packit Service a31ea6
	switch (entity->etype) {
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
Packit Service a31ea6
	        xmlErrInternal(ctxt, "Cannot parse entity %s\n",
Packit Service a31ea6
		               entity->name);
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
Packit Service a31ea6
            case XML_EXTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
		return(xmlLoadExternalEntity((char *) entity->URI,
Packit Service a31ea6
		       (char *) entity->ExternalID, ctxt));
Packit Service a31ea6
            case XML_INTERNAL_GENERAL_ENTITY:
Packit Service a31ea6
	        xmlErrInternal(ctxt,
Packit Service a31ea6
		      "Internal entity %s without content !\n",
Packit Service a31ea6
		               entity->name);
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PARAMETER_ENTITY:
Packit Service a31ea6
	        xmlErrInternal(ctxt,
Packit Service a31ea6
		      "Internal parameter entity %s without content !\n",
Packit Service a31ea6
		               entity->name);
Packit Service a31ea6
                break;
Packit Service a31ea6
            case XML_INTERNAL_PREDEFINED_ENTITY:
Packit Service a31ea6
	        xmlErrInternal(ctxt,
Packit Service a31ea6
		      "Predefined entity %s without content !\n",
Packit Service a31ea6
		               entity->name);
Packit Service a31ea6
                break;
Packit Service a31ea6
	}
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    input = xmlNewInputStream(ctxt);
Packit Service a31ea6
    if (input == NULL) {
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (entity->URI != NULL)
Packit Service a31ea6
	input->filename = (char *) xmlStrdup((xmlChar *) entity->URI);
Packit Service a31ea6
    input->base = entity->content;
Packit Service a31ea6
    if (entity->length == 0)
Packit Service a31ea6
        entity->length = xmlStrlen(entity->content);
Packit Service a31ea6
    input->cur = entity->content;
Packit Service a31ea6
    input->length = entity->length;
Packit Service a31ea6
    input->end = &entity->content[input->length];
Packit Service a31ea6
    return(input);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewStringInputStream:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @buffer:  an memory buffer
Packit Service a31ea6
 *
Packit Service a31ea6
 * Create a new input stream based on a memory buffer.
Packit Service a31ea6
 * Returns the new input stream
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
Packit Service a31ea6
    xmlParserInputPtr input;
Packit Service a31ea6
Packit Service a31ea6
    if (buffer == NULL) {
Packit Service a31ea6
        xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
Packit Service a31ea6
	               NULL);
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (xmlParserDebugEntities)
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"new fixed input: %.30s\n", buffer);
Packit Service a31ea6
    input = xmlNewInputStream(ctxt);
Packit Service a31ea6
    if (input == NULL) {
Packit Service a31ea6
        xmlErrMemory(ctxt,  "couldn't allocate a new input stream\n");
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    input->base = buffer;
Packit Service a31ea6
    input->cur = buffer;
Packit Service a31ea6
    input->length = xmlStrlen(buffer);
Packit Service a31ea6
    input->end = &buffer[input->length];
Packit Service a31ea6
    return(input);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewInputFromFile:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @filename:  the filename to use as entity
Packit Service a31ea6
 *
Packit Service a31ea6
 * Create a new input stream based on a file or an URL.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the new input stream or NULL in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
Packit Service a31ea6
    xmlParserInputBufferPtr buf;
Packit Service a31ea6
    xmlParserInputPtr inputStream;
Packit Service a31ea6
    char *directory = NULL;
Packit Service a31ea6
    xmlChar *URI = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (xmlParserDebugEntities)
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"new input from file: %s\n", filename);
Packit Service a31ea6
    if (ctxt == NULL) return(NULL);
Packit Service a31ea6
    buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
Packit Service a31ea6
    if (buf == NULL) {
Packit Service a31ea6
	if (filename == NULL)
Packit Service a31ea6
	    __xmlLoaderErr(ctxt,
Packit Service a31ea6
	                   "failed to load external entity: NULL filename \n",
Packit Service a31ea6
			   NULL);
Packit Service a31ea6
	else
Packit Service a31ea6
	    __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
Packit Service a31ea6
			   (const char *) filename);
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    inputStream = xmlNewInputStream(ctxt);
Packit Service a31ea6
    if (inputStream == NULL)
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
Packit Service a31ea6
    inputStream->buf = buf;
Packit Service a31ea6
    inputStream = xmlCheckHTTPInput(ctxt, inputStream);
Packit Service a31ea6
    if (inputStream == NULL)
Packit Service a31ea6
        return(NULL);
Packit Service a31ea6
Packit Service a31ea6
    if (inputStream->filename == NULL)
Packit Service a31ea6
	URI = xmlStrdup((xmlChar *) filename);
Packit Service a31ea6
    else
Packit Service a31ea6
	URI = xmlStrdup((xmlChar *) inputStream->filename);
Packit Service a31ea6
    directory = xmlParserGetDirectory((const char *) URI);
Packit Service a31ea6
    if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
Packit Service a31ea6
    inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
Packit Service a31ea6
    if (URI != NULL) xmlFree((char *) URI);
Packit Service a31ea6
    inputStream->directory = directory;
Packit Service a31ea6
Packit Service a31ea6
    xmlBufResetInput(inputStream->buf->buffer, inputStream);
Packit Service a31ea6
    if ((ctxt->directory == NULL) && (directory != NULL))
Packit Service a31ea6
        ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
Packit Service a31ea6
    return(inputStream);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Commodity functions to handle parser contexts		*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlInitParserCtxt:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize a parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success and -1 in case of error
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserInputPtr input;
Packit Service a31ea6
Packit Service a31ea6
    if(ctxt==NULL) {
Packit Service a31ea6
        xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
Packit Service a31ea6
        return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    xmlDefaultSAXHandlerInit();
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->dict == NULL)
Packit Service a31ea6
	ctxt->dict = xmlDictCreate();
Packit Service a31ea6
    if (ctxt->dict == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlDictSetLimit(ctxt->dict, XML_MAX_DICTIONARY_LIMIT);
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->sax == NULL)
Packit Service a31ea6
	ctxt->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
Packit Service a31ea6
    if (ctxt->sax == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    else
Packit Service a31ea6
        xmlSAXVersion(ctxt->sax, 2);
Packit Service a31ea6
Packit Service a31ea6
    ctxt->maxatts = 0;
Packit Service a31ea6
    ctxt->atts = NULL;
Packit Service a31ea6
    /* Allocate the Input stack */
Packit Service a31ea6
    if (ctxt->inputTab == NULL) {
Packit Service a31ea6
	ctxt->inputTab = (xmlParserInputPtr *)
Packit Service a31ea6
		    xmlMalloc(5 * sizeof(xmlParserInputPtr));
Packit Service a31ea6
	ctxt->inputMax = 5;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->inputTab == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	ctxt->inputNr = 0;
Packit Service a31ea6
	ctxt->inputMax = 0;
Packit Service a31ea6
	ctxt->input = NULL;
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
Packit Service a31ea6
        xmlFreeInputStream(input);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->inputNr = 0;
Packit Service a31ea6
    ctxt->input = NULL;
Packit Service a31ea6
Packit Service a31ea6
    ctxt->version = NULL;
Packit Service a31ea6
    ctxt->encoding = NULL;
Packit Service a31ea6
    ctxt->standalone = -1;
Packit Service a31ea6
    ctxt->hasExternalSubset = 0;
Packit Service a31ea6
    ctxt->hasPErefs = 0;
Packit Service a31ea6
    ctxt->html = 0;
Packit Service a31ea6
    ctxt->external = 0;
Packit Service a31ea6
    ctxt->instate = XML_PARSER_START;
Packit Service a31ea6
    ctxt->token = 0;
Packit Service a31ea6
    ctxt->directory = NULL;
Packit Service a31ea6
Packit Service a31ea6
    /* Allocate the Node stack */
Packit Service a31ea6
    if (ctxt->nodeTab == NULL) {
Packit Service a31ea6
	ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
Packit Service a31ea6
	ctxt->nodeMax = 10;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->nodeTab == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	ctxt->nodeNr = 0;
Packit Service a31ea6
	ctxt->nodeMax = 0;
Packit Service a31ea6
	ctxt->node = NULL;
Packit Service a31ea6
	ctxt->inputNr = 0;
Packit Service a31ea6
	ctxt->inputMax = 0;
Packit Service a31ea6
	ctxt->input = NULL;
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nodeNr = 0;
Packit Service a31ea6
    ctxt->node = NULL;
Packit Service a31ea6
Packit Service a31ea6
    /* Allocate the Name stack */
Packit Service a31ea6
    if (ctxt->nameTab == NULL) {
Packit Service a31ea6
	ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
Packit Service a31ea6
	ctxt->nameMax = 10;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->nameTab == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	ctxt->nodeNr = 0;
Packit Service a31ea6
	ctxt->nodeMax = 0;
Packit Service a31ea6
	ctxt->node = NULL;
Packit Service a31ea6
	ctxt->inputNr = 0;
Packit Service a31ea6
	ctxt->inputMax = 0;
Packit Service a31ea6
	ctxt->input = NULL;
Packit Service a31ea6
	ctxt->nameNr = 0;
Packit Service a31ea6
	ctxt->nameMax = 0;
Packit Service a31ea6
	ctxt->name = NULL;
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nameNr = 0;
Packit Service a31ea6
    ctxt->name = NULL;
Packit Service a31ea6
Packit Service a31ea6
    /* Allocate the space stack */
Packit Service a31ea6
    if (ctxt->spaceTab == NULL) {
Packit Service a31ea6
	ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
Packit Service a31ea6
	ctxt->spaceMax = 10;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->spaceTab == NULL) {
Packit Service a31ea6
        xmlErrMemory(NULL, "cannot initialize parser context\n");
Packit Service a31ea6
	ctxt->nodeNr = 0;
Packit Service a31ea6
	ctxt->nodeMax = 0;
Packit Service a31ea6
	ctxt->node = NULL;
Packit Service a31ea6
	ctxt->inputNr = 0;
Packit Service a31ea6
	ctxt->inputMax = 0;
Packit Service a31ea6
	ctxt->input = NULL;
Packit Service a31ea6
	ctxt->nameNr = 0;
Packit Service a31ea6
	ctxt->nameMax = 0;
Packit Service a31ea6
	ctxt->name = NULL;
Packit Service a31ea6
	ctxt->spaceNr = 0;
Packit Service a31ea6
	ctxt->spaceMax = 0;
Packit Service a31ea6
	ctxt->space = NULL;
Packit Service a31ea6
	return(-1);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->spaceNr = 1;
Packit Service a31ea6
    ctxt->spaceMax = 10;
Packit Service a31ea6
    ctxt->spaceTab[0] = -1;
Packit Service a31ea6
    ctxt->space = &ctxt->spaceTab[0];
Packit Service a31ea6
    ctxt->userData = ctxt;
Packit Service a31ea6
    ctxt->myDoc = NULL;
Packit Service a31ea6
    ctxt->wellFormed = 1;
Packit Service a31ea6
    ctxt->nsWellFormed = 1;
Packit Service a31ea6
    ctxt->valid = 1;
Packit Service a31ea6
    ctxt->loadsubset = xmlLoadExtDtdDefaultValue;
Packit Service a31ea6
    if (ctxt->loadsubset) {
Packit Service a31ea6
        ctxt->options |= XML_PARSE_DTDLOAD;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->validate = xmlDoValidityCheckingDefaultValue;
Packit Service a31ea6
    ctxt->pedantic = xmlPedanticParserDefaultValue;
Packit Service a31ea6
    if (ctxt->pedantic) {
Packit Service a31ea6
        ctxt->options |= XML_PARSE_PEDANTIC;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->linenumbers = xmlLineNumbersDefaultValue;
Packit Service a31ea6
    ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
Packit Service a31ea6
    if (ctxt->keepBlanks == 0) {
Packit Service a31ea6
	ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
Packit Service a31ea6
	ctxt->options |= XML_PARSE_NOBLANKS;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0;
Packit Service a31ea6
    ctxt->vctxt.userData = ctxt;
Packit Service a31ea6
    ctxt->vctxt.error = xmlParserValidityError;
Packit Service a31ea6
    ctxt->vctxt.warning = xmlParserValidityWarning;
Packit Service a31ea6
    if (ctxt->validate) {
Packit Service a31ea6
	if (xmlGetWarningsDefaultValue == 0)
Packit Service a31ea6
	    ctxt->vctxt.warning = NULL;
Packit Service a31ea6
	else
Packit Service a31ea6
	    ctxt->vctxt.warning = xmlParserValidityWarning;
Packit Service a31ea6
	ctxt->vctxt.nodeMax = 0;
Packit Service a31ea6
        ctxt->options |= XML_PARSE_DTDVALID;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
Packit Service a31ea6
    if (ctxt->replaceEntities) {
Packit Service a31ea6
        ctxt->options |= XML_PARSE_NOENT;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->record_info = 0;
Packit Service a31ea6
    ctxt->nbChars = 0;
Packit Service a31ea6
    ctxt->checkIndex = 0;
Packit Service a31ea6
    ctxt->inSubset = 0;
Packit Service a31ea6
    ctxt->errNo = XML_ERR_OK;
Packit Service a31ea6
    ctxt->depth = 0;
Packit Service a31ea6
    ctxt->charset = XML_CHAR_ENCODING_UTF8;
Packit Service a31ea6
    ctxt->catalogs = NULL;
Packit Service a31ea6
    ctxt->nbentities = 0;
Packit Service a31ea6
    ctxt->sizeentities = 0;
Packit Service a31ea6
    ctxt->sizeentcopy = 0;
Packit Service a31ea6
    ctxt->input_id = 1;
Packit Service a31ea6
    xmlInitNodeInfoSeq(&ctxt->node_seq);
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlFreeParserCtxt:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Free all the memory used by a parser context. However the parsed
Packit Service a31ea6
 * document in ctxt->myDoc is not freed.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
void
Packit Service a31ea6
xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserInputPtr input;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt == NULL) return;
Packit Service a31ea6
Packit Service a31ea6
    while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
Packit Service a31ea6
        xmlFreeInputStream(input);
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
Packit Service a31ea6
    if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
Packit Service a31ea6
    if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
Packit Service a31ea6
    if (ctxt->nodeInfoTab != NULL) xmlFree(ctxt->nodeInfoTab);
Packit Service a31ea6
    if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
Packit Service a31ea6
    if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
Packit Service a31ea6
    if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
Packit Service a31ea6
    if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
Packit Service a31ea6
    if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
Packit Service a31ea6
#ifdef LIBXML_SAX1_ENABLED
Packit Service a31ea6
    if ((ctxt->sax != NULL) &&
Packit Service a31ea6
        (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler))
Packit Service a31ea6
#else
Packit Service a31ea6
    if (ctxt->sax != NULL)
Packit Service a31ea6
#endif /* LIBXML_SAX1_ENABLED */
Packit Service a31ea6
        xmlFree(ctxt->sax);
Packit Service a31ea6
    if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
Packit Service a31ea6
    if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
Packit Service a31ea6
    if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
Packit Service a31ea6
    if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
Packit Service a31ea6
    if (ctxt->nsTab != NULL) xmlFree((char *) ctxt->nsTab);
Packit Service a31ea6
    if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);
Packit Service a31ea6
    if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);
Packit Service a31ea6
    if (ctxt->attsDefault != NULL)
Packit Service a31ea6
        xmlHashFree(ctxt->attsDefault, (xmlHashDeallocator) xmlFree);
Packit Service a31ea6
    if (ctxt->attsSpecial != NULL)
Packit Service a31ea6
        xmlHashFree(ctxt->attsSpecial, NULL);
Packit Service a31ea6
    if (ctxt->freeElems != NULL) {
Packit Service a31ea6
        xmlNodePtr cur, next;
Packit Service a31ea6
Packit Service a31ea6
	cur = ctxt->freeElems;
Packit Service a31ea6
	while (cur != NULL) {
Packit Service a31ea6
	    next = cur->next;
Packit Service a31ea6
	    xmlFree(cur);
Packit Service a31ea6
	    cur = next;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->freeAttrs != NULL) {
Packit Service a31ea6
        xmlAttrPtr cur, next;
Packit Service a31ea6
Packit Service a31ea6
	cur = ctxt->freeAttrs;
Packit Service a31ea6
	while (cur != NULL) {
Packit Service a31ea6
	    next = cur->next;
Packit Service a31ea6
	    xmlFree(cur);
Packit Service a31ea6
	    cur = next;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * cleanup the error strings
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->lastError.message != NULL)
Packit Service a31ea6
        xmlFree(ctxt->lastError.message);
Packit Service a31ea6
    if (ctxt->lastError.file != NULL)
Packit Service a31ea6
        xmlFree(ctxt->lastError.file);
Packit Service a31ea6
    if (ctxt->lastError.str1 != NULL)
Packit Service a31ea6
        xmlFree(ctxt->lastError.str1);
Packit Service a31ea6
    if (ctxt->lastError.str2 != NULL)
Packit Service a31ea6
        xmlFree(ctxt->lastError.str2);
Packit Service a31ea6
    if (ctxt->lastError.str3 != NULL)
Packit Service a31ea6
        xmlFree(ctxt->lastError.str3);
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_CATALOG_ENABLED
Packit Service a31ea6
    if (ctxt->catalogs != NULL)
Packit Service a31ea6
	xmlCatalogFreeLocal(ctxt->catalogs);
Packit Service a31ea6
#endif
Packit Service a31ea6
    xmlFree(ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNewParserCtxt:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Allocate and initialize a new parser context.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the xmlParserCtxtPtr or NULL
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
xmlParserCtxtPtr
Packit Service a31ea6
xmlNewParserCtxt(void)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt;
Packit Service a31ea6
Packit Service a31ea6
    ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
Packit Service a31ea6
    if (ctxt == NULL) {
Packit Service a31ea6
	xmlErrMemory(NULL, "cannot allocate parser context\n");
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    memset(ctxt, 0, sizeof(xmlParserCtxt));
Packit Service a31ea6
    if (xmlInitParserCtxt(ctxt) < 0) {
Packit Service a31ea6
        xmlFreeParserCtxt(ctxt);
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    return(ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Handling of node informations				*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlClearParserCtxt:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 *
Packit Service a31ea6
 * Clear (release owned resources) and reinitialize a parser context
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
void
Packit Service a31ea6
xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
Packit Service a31ea6
{
Packit Service a31ea6
  if (ctxt==NULL)
Packit Service a31ea6
    return;
Packit Service a31ea6
  xmlClearNodeInfoSeq(&ctxt->node_seq);
Packit Service a31ea6
  xmlCtxtReset(ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserFindNodeInfo:
Packit Service a31ea6
 * @ctx:  an XML parser context
Packit Service a31ea6
 * @node:  an XML node within the tree
Packit Service a31ea6
 *
Packit Service a31ea6
 * Find the parser node info struct for a given node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns an xmlParserNodeInfo block pointer or NULL
Packit Service a31ea6
 */
Packit Service a31ea6
const xmlParserNodeInfo *
Packit Service a31ea6
xmlParserFindNodeInfo(const xmlParserCtxtPtr ctx, const xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    unsigned long pos;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctx == NULL) || (node == NULL))
Packit Service a31ea6
        return (NULL);
Packit Service a31ea6
    /* Find position where node should be at */
Packit Service a31ea6
    pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node);
Packit Service a31ea6
    if (pos < ctx->node_seq.length
Packit Service a31ea6
        && ctx->node_seq.buffer[pos].node == node)
Packit Service a31ea6
        return &ctx->node_seq.buffer[pos];
Packit Service a31ea6
    else
Packit Service a31ea6
        return NULL;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlInitNodeInfoSeq:
Packit Service a31ea6
 * @seq:  a node info sequence pointer
Packit Service a31ea6
 *
Packit Service a31ea6
 * -- Initialize (set to initial state) node info sequence
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
Packit Service a31ea6
{
Packit Service a31ea6
    if (seq == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    seq->length = 0;
Packit Service a31ea6
    seq->maximum = 0;
Packit Service a31ea6
    seq->buffer = NULL;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlClearNodeInfoSeq:
Packit Service a31ea6
 * @seq:  a node info sequence pointer
Packit Service a31ea6
 *
Packit Service a31ea6
 * -- Clear (release memory and reinitialize) node
Packit Service a31ea6
 *   info sequence
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
Packit Service a31ea6
{
Packit Service a31ea6
    if (seq == NULL)
Packit Service a31ea6
        return;
Packit Service a31ea6
    if (seq->buffer != NULL)
Packit Service a31ea6
        xmlFree(seq->buffer);
Packit Service a31ea6
    xmlInitNodeInfoSeq(seq);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserFindNodeInfoIndex:
Packit Service a31ea6
 * @seq:  a node info sequence pointer
Packit Service a31ea6
 * @node:  an XML node pointer
Packit Service a31ea6
 *
Packit Service a31ea6
 *
Packit Service a31ea6
 * xmlParserFindNodeInfoIndex : Find the index that the info record for
Packit Service a31ea6
 *   the given node is or should be at in a sorted sequence
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns a long indicating the position of the record
Packit Service a31ea6
 */
Packit Service a31ea6
unsigned long
Packit Service a31ea6
xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
Packit Service a31ea6
                           const xmlNodePtr node)
Packit Service a31ea6
{
Packit Service a31ea6
    unsigned long upper, lower, middle;
Packit Service a31ea6
    int found = 0;
Packit Service a31ea6
Packit Service a31ea6
    if ((seq == NULL) || (node == NULL))
Packit Service a31ea6
        return ((unsigned long) -1);
Packit Service a31ea6
Packit Service a31ea6
    /* Do a binary search for the key */
Packit Service a31ea6
    lower = 1;
Packit Service a31ea6
    upper = seq->length;
Packit Service a31ea6
    middle = 0;
Packit Service a31ea6
    while (lower <= upper && !found) {
Packit Service a31ea6
        middle = lower + (upper - lower) / 2;
Packit Service a31ea6
        if (node == seq->buffer[middle - 1].node)
Packit Service a31ea6
            found = 1;
Packit Service a31ea6
        else if (node < seq->buffer[middle - 1].node)
Packit Service a31ea6
            upper = middle - 1;
Packit Service a31ea6
        else
Packit Service a31ea6
            lower = middle + 1;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /* Return position */
Packit Service a31ea6
    if (middle == 0 || seq->buffer[middle - 1].node < node)
Packit Service a31ea6
        return middle;
Packit Service a31ea6
    else
Packit Service a31ea6
        return middle - 1;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlParserAddNodeInfo:
Packit Service a31ea6
 * @ctxt:  an XML parser context
Packit Service a31ea6
 * @info:  a node info sequence pointer
Packit Service a31ea6
 *
Packit Service a31ea6
 * Insert node info record into the sorted sequence
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
Packit Service a31ea6
                     const xmlParserNodeInfoPtr info)
Packit Service a31ea6
{
Packit Service a31ea6
    unsigned long pos;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (info == NULL)) return;
Packit Service a31ea6
Packit Service a31ea6
    /* Find pos and check to see if node is already in the sequence */
Packit Service a31ea6
    pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (xmlNodePtr)
Packit Service a31ea6
                                     info->node);
Packit Service a31ea6
Packit Service a31ea6
    if ((pos < ctxt->node_seq.length) &&
Packit Service a31ea6
        (ctxt->node_seq.buffer != NULL) &&
Packit Service a31ea6
        (ctxt->node_seq.buffer[pos].node == info->node)) {
Packit Service a31ea6
        ctxt->node_seq.buffer[pos] = *info;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /* Otherwise, we need to add new node to buffer */
Packit Service a31ea6
    else {
Packit Service a31ea6
        if ((ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) ||
Packit Service a31ea6
	    (ctxt->node_seq.buffer == NULL)) {
Packit Service a31ea6
            xmlParserNodeInfo *tmp_buffer;
Packit Service a31ea6
            unsigned int byte_size;
Packit Service a31ea6
Packit Service a31ea6
            if (ctxt->node_seq.maximum == 0)
Packit Service a31ea6
                ctxt->node_seq.maximum = 2;
Packit Service a31ea6
            byte_size = (sizeof(*ctxt->node_seq.buffer) *
Packit Service a31ea6
			(2 * ctxt->node_seq.maximum));
Packit Service a31ea6
Packit Service a31ea6
            if (ctxt->node_seq.buffer == NULL)
Packit Service a31ea6
                tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
Packit Service a31ea6
            else
Packit Service a31ea6
                tmp_buffer =
Packit Service a31ea6
                    (xmlParserNodeInfo *) xmlRealloc(ctxt->node_seq.buffer,
Packit Service a31ea6
                                                     byte_size);
Packit Service a31ea6
Packit Service a31ea6
            if (tmp_buffer == NULL) {
Packit Service a31ea6
		xmlErrMemory(ctxt, "failed to allocate buffer\n");
Packit Service a31ea6
                return;
Packit Service a31ea6
            }
Packit Service a31ea6
            ctxt->node_seq.buffer = tmp_buffer;
Packit Service a31ea6
            ctxt->node_seq.maximum *= 2;
Packit Service a31ea6
        }
Packit Service a31ea6
Packit Service a31ea6
        /* If position is not at end, move elements out of the way */
Packit Service a31ea6
        if (pos != ctxt->node_seq.length) {
Packit Service a31ea6
            unsigned long i;
Packit Service a31ea6
Packit Service a31ea6
            for (i = ctxt->node_seq.length; i > pos; i--)
Packit Service a31ea6
                ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
Packit Service a31ea6
        }
Packit Service a31ea6
Packit Service a31ea6
        /* Copy element and increase length */
Packit Service a31ea6
        ctxt->node_seq.buffer[pos] = *info;
Packit Service a31ea6
        ctxt->node_seq.length++;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/************************************************************************
Packit Service a31ea6
 *									*
Packit Service a31ea6
 *		Defaults settings					*
Packit Service a31ea6
 *									*
Packit Service a31ea6
 ************************************************************************/
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlPedanticParserDefault:
Packit Service a31ea6
 * @val:  int 0 or 1
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set and return the previous value for enabling pedantic warnings.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the last value for 0 for no substitution, 1 for substitution.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlPedanticParserDefault(int val) {
Packit Service a31ea6
    int old = xmlPedanticParserDefaultValue;
Packit Service a31ea6
Packit Service a31ea6
    xmlPedanticParserDefaultValue = val;
Packit Service a31ea6
    return(old);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlLineNumbersDefault:
Packit Service a31ea6
 * @val:  int 0 or 1
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set and return the previous value for enabling line numbers in elements
Packit Service a31ea6
 * contents. This may break on old application and is turned off by default.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the last value for 0 for no substitution, 1 for substitution.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlLineNumbersDefault(int val) {
Packit Service a31ea6
    int old = xmlLineNumbersDefaultValue;
Packit Service a31ea6
Packit Service a31ea6
    xmlLineNumbersDefaultValue = val;
Packit Service a31ea6
    return(old);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSubstituteEntitiesDefault:
Packit Service a31ea6
 * @val:  int 0 or 1
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set and return the previous value for default entity support.
Packit Service a31ea6
 * Initially the parser always keep entity references instead of substituting
Packit Service a31ea6
 * entity values in the output. This function has to be used to change the
Packit Service a31ea6
 * default parser behavior
Packit Service a31ea6
 * SAX::substituteEntities() has to be used for changing that on a file by
Packit Service a31ea6
 * file basis.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the last value for 0 for no substitution, 1 for substitution.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlSubstituteEntitiesDefault(int val) {
Packit Service a31ea6
    int old = xmlSubstituteEntitiesDefaultValue;
Packit Service a31ea6
Packit Service a31ea6
    xmlSubstituteEntitiesDefaultValue = val;
Packit Service a31ea6
    return(old);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlKeepBlanksDefault:
Packit Service a31ea6
 * @val:  int 0 or 1
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set and return the previous value for default blanks text nodes support.
Packit Service a31ea6
 * The 1.x version of the parser used an heuristic to try to detect
Packit Service a31ea6
 * ignorable white spaces. As a result the SAX callback was generating
Packit Service a31ea6
 * xmlSAX2IgnorableWhitespace() callbacks instead of characters() one, and when
Packit Service a31ea6
 * using the DOM output text nodes containing those blanks were not generated.
Packit Service a31ea6
 * The 2.x and later version will switch to the XML standard way and
Packit Service a31ea6
 * ignorableWhitespace() are only generated when running the parser in
Packit Service a31ea6
 * validating mode and when the current element doesn't allow CDATA or
Packit Service a31ea6
 * mixed content.
Packit Service a31ea6
 * This function is provided as a way to force the standard behavior
Packit Service a31ea6
 * on 1.X libs and to switch back to the old mode for compatibility when
Packit Service a31ea6
 * running 1.X client code on 2.X . Upgrade of 1.X code should be done
Packit Service a31ea6
 * by using xmlIsBlankNode() commodity function to detect the "empty"
Packit Service a31ea6
 * nodes generated.
Packit Service a31ea6
 * This value also affect autogeneration of indentation when saving code
Packit Service a31ea6
 * if blanks sections are kept, indentation is not generated.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the last value for 0 for no substitution, 1 for substitution.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
int
Packit Service a31ea6
xmlKeepBlanksDefault(int val) {
Packit Service a31ea6
    int old = xmlKeepBlanksDefaultValue;
Packit Service a31ea6
Packit Service a31ea6
    xmlKeepBlanksDefaultValue = val;
Packit Service a31ea6
    if (!val) xmlIndentTreeOutput = 1;
Packit Service a31ea6
    return(old);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#define bottom_parserInternals
Packit Service a31ea6
#include "elfgcchack.h"