Blame SAX2.c

Packit Service a31ea6
/*
Packit Service a31ea6
 * SAX2.c : Default SAX2 handler to build a tree.
Packit Service a31ea6
 *
Packit Service a31ea6
 * See Copyright for the status of this software.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Daniel Veillard <daniel@veillard.com>
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
#define IN_LIBXML
Packit Service a31ea6
#include "libxml.h"
Packit Service a31ea6
#include <stdlib.h>
Packit Service a31ea6
#include <string.h>
Packit Service a31ea6
#include <limits.h>
Packit Service a31ea6
#include <stddef.h>
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/debugXML.h>
Packit Service a31ea6
#include <libxml/xmlIO.h>
Packit Service a31ea6
#include <libxml/SAX.h>
Packit Service a31ea6
#include <libxml/uri.h>
Packit Service a31ea6
#include <libxml/valid.h>
Packit Service a31ea6
#include <libxml/HTMLtree.h>
Packit Service a31ea6
#include <libxml/globals.h>
Packit Service a31ea6
Packit Service a31ea6
/* Define SIZE_T_MAX unless defined through <limits.h>. */
Packit Service a31ea6
#ifndef SIZE_T_MAX
Packit Service a31ea6
# define SIZE_T_MAX     ((size_t)-1)
Packit Service a31ea6
#endif /* !SIZE_T_MAX */
Packit Service a31ea6
Packit Service a31ea6
/* #define DEBUG_SAX2 */
Packit Service a31ea6
/* #define DEBUG_SAX2_TREE */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * TODO:
Packit Service a31ea6
 *
Packit Service a31ea6
 * macro to flag unimplemented blocks
Packit Service a31ea6
 * XML_CATALOG_PREFER user env to select between system/public prefered
Packit Service a31ea6
 * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk>
Packit Service a31ea6
 *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with
Packit Service a31ea6
 *> values "system" and "public".  I have made the default be "system" to
Packit Service a31ea6
 *> match yours.
Packit Service a31ea6
 */
Packit Service a31ea6
#define TODO								\
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,				\
Packit Service a31ea6
	    "Unimplemented block at %s:%d\n",				\
Packit Service a31ea6
            __FILE__, __LINE__);
Packit Service a31ea6
Packit Service a31ea6
/*
Packit Service a31ea6
 * xmlSAX2ErrMemory:
Packit Service a31ea6
 * @ctxt:  an XML validation parser context
Packit Service a31ea6
 * @msg:   a string to accompany the error message
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(2,0)
Packit Service a31ea6
xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt, const char *msg) {
Packit Service a31ea6
    xmlStructuredErrorFunc schannel = NULL;
Packit Service a31ea6
    const char *str1 = "out of memory\n";
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt != NULL) {
Packit Service a31ea6
	ctxt->errNo = XML_ERR_NO_MEMORY;
Packit Service a31ea6
	if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
Packit Service a31ea6
	    schannel = ctxt->sax->serror;
Packit Service a31ea6
	__xmlRaiseError(schannel,
Packit Service a31ea6
			ctxt->vctxt.error, ctxt->vctxt.userData,
Packit Service a31ea6
			ctxt, NULL, XML_FROM_PARSER, XML_ERR_NO_MEMORY,
Packit Service a31ea6
			XML_ERR_ERROR, NULL, 0, (const char *) str1,
Packit Service a31ea6
			NULL, NULL, 0, 0,
Packit Service a31ea6
			msg, (const char *) str1, 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
    } else {
Packit Service a31ea6
	__xmlRaiseError(schannel,
Packit Service a31ea6
			NULL, NULL,
Packit Service a31ea6
			ctxt, NULL, XML_FROM_PARSER, XML_ERR_NO_MEMORY,
Packit Service a31ea6
			XML_ERR_ERROR, NULL, 0, (const char *) str1,
Packit Service a31ea6
			NULL, NULL, 0, 0,
Packit Service a31ea6
			msg, (const char *) str1, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlValidError:
Packit Service a31ea6
 * @ctxt:  an XML validation parser context
Packit Service a31ea6
 * @error:  the error number
Packit Service a31ea6
 * @msg:  the error message
Packit Service a31ea6
 * @str1:  extra data
Packit Service a31ea6
 * @str2:  extra data
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a validation error
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error,
Packit Service a31ea6
            const char *msg, const char *str1, const char *str2)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlStructuredErrorFunc schannel = NULL;
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
	if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
Packit Service a31ea6
	    schannel = ctxt->sax->serror;
Packit Service a31ea6
	__xmlRaiseError(schannel,
Packit Service a31ea6
			ctxt->vctxt.error, ctxt->vctxt.userData,
Packit Service a31ea6
			ctxt, NULL, XML_FROM_DTD, error,
Packit Service a31ea6
			XML_ERR_ERROR, NULL, 0, (const char *) str1,
Packit Service a31ea6
			(const char *) str2, NULL, 0, 0,
Packit Service a31ea6
			msg, (const char *) str1, (const char *) str2);
Packit Service a31ea6
	ctxt->valid = 0;
Packit Service a31ea6
    } else {
Packit Service a31ea6
	__xmlRaiseError(schannel,
Packit Service a31ea6
			NULL, NULL,
Packit Service a31ea6
			ctxt, NULL, XML_FROM_DTD, error,
Packit Service a31ea6
			XML_ERR_ERROR, NULL, 0, (const char *) str1,
Packit Service a31ea6
			(const char *) str2, NULL, 0, 0,
Packit Service a31ea6
			msg, (const char *) str1, (const char *) str2);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlFatalErrMsg:
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
 * @str1:  an error string
Packit Service a31ea6
 * @str2:  an error string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a fatal parser error, i.e. violating Well-Formedness constraints
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
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 = error;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
Packit Service a31ea6
                    XML_ERR_FATAL, NULL, 0,
Packit Service a31ea6
		    (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
	ctxt->valid = 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
 * xmlWarnMsg:
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
 * @str1:  an error string
Packit Service a31ea6
 * @str2:  an error string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a parser warning
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
Packit Service a31ea6
               const char *msg, const xmlChar *str1)
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, ctxt, NULL, XML_FROM_PARSER, error,
Packit Service a31ea6
                    XML_ERR_WARNING, NULL, 0,
Packit Service a31ea6
		    (const char *) str1, NULL,
Packit Service a31ea6
		    NULL, 0, 0, msg, str1);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNsErrMsg:
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
 * @str1:  an error string
Packit Service a31ea6
 * @str2:  an error string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a namespace error
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
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 = error;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
Packit Service a31ea6
                    XML_ERR_ERROR, NULL, 0,
Packit Service a31ea6
		    (const char *) str1, (const char *) str2,
Packit Service a31ea6
		    NULL, 0, 0, msg, str1, str2);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlNsWarnMsg:
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
 * @str1:  an error string
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle a namespace warning
Packit Service a31ea6
 */
Packit Service a31ea6
static void LIBXML_ATTR_FORMAT(3,0)
Packit Service a31ea6
xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
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 = error;
Packit Service a31ea6
    __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
Packit Service a31ea6
                    XML_ERR_WARNING, NULL, 0,
Packit Service a31ea6
		    (const char *) str1, (const char *) str2,
Packit Service a31ea6
		    NULL, 0, 0, msg, str1, str2);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetPublicId:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Provides the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns a xmlChar *
Packit Service a31ea6
 */
Packit Service a31ea6
const xmlChar *
Packit Service a31ea6
xmlSAX2GetPublicId(void *ctx ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Packit Service a31ea6
    return(NULL);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetSystemId:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Provides the system ID, basically URL or filename e.g.
Packit Service a31ea6
 * http://www.sgmlsource.com/dtds/memo.dtd
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns a xmlChar *
Packit Service a31ea6
 */
Packit Service a31ea6
const xmlChar *
Packit Service a31ea6
xmlSAX2GetSystemId(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL);
Packit Service a31ea6
    return((const xmlChar *) ctxt->input->filename);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetLineNumber:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Provide the line number of the current parsing point.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns an int
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAX2GetLineNumber(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
Packit Service a31ea6
    return(ctxt->input->line);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetColumnNumber:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Provide the column number of the current parsing point.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns an int
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAX2GetColumnNumber(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
Packit Service a31ea6
    return(ctxt->input->col);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2IsStandalone:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Is this document tagged standalone ?
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 1 if true
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAX2IsStandalone(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctx == NULL) || (ctxt->myDoc == NULL)) return(0);
Packit Service a31ea6
    return(ctxt->myDoc->standalone == 1);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2HasInternalSubset:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Does this document has an internal subset
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 1 if true
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAX2HasInternalSubset(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
Packit Service a31ea6
    return(ctxt->myDoc->intSubset != NULL);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2HasExternalSubset:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Does this document has an external subset
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 1 if true
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAX2HasExternalSubset(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
Packit Service a31ea6
    return(ctxt->myDoc->extSubset != NULL);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2InternalSubset:
Packit Service a31ea6
 * @ctx:  the user data (XML parser context)
Packit Service a31ea6
 * @name:  the root element name
Packit Service a31ea6
 * @ExternalID:  the external ID
Packit Service a31ea6
 * @SystemID:  the SYSTEM ID (e.g. filename or URL)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Callback on internal subset declaration.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2InternalSubset(void *ctx, const xmlChar *name,
Packit Service a31ea6
	       const xmlChar *ExternalID, const xmlChar *SystemID)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlDtdPtr dtd;
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2InternalSubset(%s, %s, %s)\n",
Packit Service a31ea6
            name, ExternalID, SystemID);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->myDoc == NULL)
Packit Service a31ea6
	return;
Packit Service a31ea6
    dtd = xmlGetIntSubset(ctxt->myDoc);
Packit Service a31ea6
    if (dtd != NULL) {
Packit Service a31ea6
	if (ctxt->html)
Packit Service a31ea6
	    return;
Packit Service a31ea6
	xmlUnlinkNode((xmlNodePtr) dtd);
Packit Service a31ea6
	xmlFreeDtd(dtd);
Packit Service a31ea6
	ctxt->myDoc->intSubset = NULL;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->myDoc->intSubset =
Packit Service a31ea6
	xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID);
Packit Service a31ea6
    if (ctxt->myDoc->intSubset == NULL)
Packit Service a31ea6
        xmlSAX2ErrMemory(ctxt, "xmlSAX2InternalSubset");
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2ExternalSubset:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name:  the root element name
Packit Service a31ea6
 * @ExternalID:  the external ID
Packit Service a31ea6
 * @SystemID:  the SYSTEM ID (e.g. filename or URL)
Packit Service a31ea6
 *
Packit Service a31ea6
 * Callback on external subset declaration.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2ExternalSubset(void *ctx, const xmlChar *name,
Packit Service a31ea6
	       const xmlChar *ExternalID, const xmlChar *SystemID)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2ExternalSubset(%s, %s, %s)\n",
Packit Service a31ea6
            name, ExternalID, SystemID);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (((ExternalID != NULL) || (SystemID != NULL)) &&
Packit Service a31ea6
        (((ctxt->validate) || (ctxt->loadsubset != 0)) &&
Packit Service a31ea6
	 (ctxt->wellFormed && ctxt->myDoc))) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Try to fetch and parse the external subset.
Packit Service a31ea6
	 */
Packit Service a31ea6
	xmlParserInputPtr oldinput;
Packit Service a31ea6
	int oldinputNr;
Packit Service a31ea6
	int oldinputMax;
Packit Service a31ea6
	xmlParserInputPtr *oldinputTab;
Packit Service a31ea6
	xmlParserInputPtr input = NULL;
Packit Service a31ea6
	xmlCharEncoding enc;
Packit Service a31ea6
	int oldcharset;
Packit Service a31ea6
	const xmlChar *oldencoding;
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Ask the Entity resolver to load the damn thing
Packit Service a31ea6
	 */
Packit Service a31ea6
	if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
Packit Service a31ea6
	    input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID,
Packit Service a31ea6
	                                        SystemID);
Packit Service a31ea6
	if (input == NULL) {
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID);
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * make sure we won't destroy the main document context
Packit Service a31ea6
	 */
Packit Service a31ea6
	oldinput = ctxt->input;
Packit Service a31ea6
	oldinputNr = ctxt->inputNr;
Packit Service a31ea6
	oldinputMax = ctxt->inputMax;
Packit Service a31ea6
	oldinputTab = ctxt->inputTab;
Packit Service a31ea6
	oldcharset = ctxt->charset;
Packit Service a31ea6
	oldencoding = ctxt->encoding;
Packit Service a31ea6
	ctxt->encoding = NULL;
Packit Service a31ea6
Packit Service a31ea6
	ctxt->inputTab = (xmlParserInputPtr *)
Packit Service a31ea6
	                 xmlMalloc(5 * sizeof(xmlParserInputPtr));
Packit Service a31ea6
	if (ctxt->inputTab == NULL) {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2ExternalSubset");
Packit Service a31ea6
	    ctxt->input = oldinput;
Packit Service a31ea6
	    ctxt->inputNr = oldinputNr;
Packit Service a31ea6
	    ctxt->inputMax = oldinputMax;
Packit Service a31ea6
	    ctxt->inputTab = oldinputTab;
Packit Service a31ea6
	    ctxt->charset = oldcharset;
Packit Service a31ea6
	    ctxt->encoding = oldencoding;
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
	ctxt->inputNr = 0;
Packit Service a31ea6
	ctxt->inputMax = 5;
Packit Service a31ea6
	ctxt->input = NULL;
Packit Service a31ea6
	xmlPushInput(ctxt, input);
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * On the fly encoding conversion if needed
Packit Service a31ea6
	 */
Packit Service a31ea6
	if (ctxt->input->length >= 4) {
Packit Service a31ea6
	    enc = xmlDetectCharEncoding(ctxt->input->cur, 4);
Packit Service a31ea6
	    xmlSwitchEncoding(ctxt, enc);
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	if (input->filename == NULL)
Packit Service a31ea6
	    input->filename = (char *) xmlCanonicPath(SystemID);
Packit Service a31ea6
	input->line = 1;
Packit Service a31ea6
	input->col = 1;
Packit Service a31ea6
	input->base = ctxt->input->cur;
Packit Service a31ea6
	input->cur = ctxt->input->cur;
Packit Service a31ea6
	input->free = NULL;
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * let's parse that entity knowing it's an external subset.
Packit Service a31ea6
	 */
Packit Service a31ea6
	xmlParseExternalSubset(ctxt, ExternalID, SystemID);
Packit Service a31ea6
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * Free up the external entities
Packit Service a31ea6
	 */
Packit Service a31ea6
Packit Service a31ea6
	while (ctxt->inputNr > 1)
Packit Service a31ea6
	    xmlPopInput(ctxt);
Packit Service a31ea6
	xmlFreeInputStream(ctxt->input);
Packit Service a31ea6
        xmlFree(ctxt->inputTab);
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Restore the parsing context of the main entity
Packit Service a31ea6
	 */
Packit Service a31ea6
	ctxt->input = oldinput;
Packit Service a31ea6
	ctxt->inputNr = oldinputNr;
Packit Service a31ea6
	ctxt->inputMax = oldinputMax;
Packit Service a31ea6
	ctxt->inputTab = oldinputTab;
Packit Service a31ea6
	ctxt->charset = oldcharset;
Packit Service a31ea6
	if ((ctxt->encoding != NULL) &&
Packit Service a31ea6
	    ((ctxt->dict == NULL) ||
Packit Service a31ea6
	     (!xmlDictOwns(ctxt->dict, ctxt->encoding))))
Packit Service a31ea6
	    xmlFree((xmlChar *) ctxt->encoding);
Packit Service a31ea6
	ctxt->encoding = oldencoding;
Packit Service a31ea6
	/* ctxt->wellFormed = oldwellFormed; */
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2ResolveEntity:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @publicId: The public ID of the entity
Packit Service a31ea6
 * @systemId: The system ID of the entity
Packit Service a31ea6
 *
Packit Service a31ea6
 * The entity loader, to control the loading of external entities,
Packit Service a31ea6
 * the application can either:
Packit Service a31ea6
 *    - override this xmlSAX2ResolveEntity() callback in the SAX block
Packit Service a31ea6
 *    - or better use the xmlSetExternalEntityLoader() function to
Packit Service a31ea6
 *      set up it's own entity resolution routine
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
Packit Service a31ea6
 */
Packit Service a31ea6
xmlParserInputPtr
Packit Service a31ea6
xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserInputPtr ret;
Packit Service a31ea6
    xmlChar *URI;
Packit Service a31ea6
    const char *base = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return(NULL);
Packit Service a31ea6
    if (ctxt->input != NULL)
Packit Service a31ea6
	base = ctxt->input->filename;
Packit Service a31ea6
    if (base == NULL)
Packit Service a31ea6
	base = ctxt->directory;
Packit Service a31ea6
Packit Service a31ea6
    URI = xmlBuildURI(systemId, (const xmlChar *) base);
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2ResolveEntity(%s, %s)\n", publicId, systemId);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    ret = xmlLoadExternalEntity((const char *) URI,
Packit Service a31ea6
				(const char *) publicId, ctxt);
Packit Service a31ea6
    if (URI != NULL)
Packit Service a31ea6
	xmlFree(URI);
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetEntity:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name: The entity name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Get an entity by name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the xmlEntityPtr if found.
Packit Service a31ea6
 */
Packit Service a31ea6
xmlEntityPtr
Packit Service a31ea6
xmlSAX2GetEntity(void *ctx, const xmlChar *name)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlEntityPtr ret = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return(NULL);
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2GetEntity(%s)\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->inSubset == 0) {
Packit Service a31ea6
	ret = xmlGetPredefinedEntity(name);
Packit Service a31ea6
	if (ret != NULL)
Packit Service a31ea6
	    return(ret);
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) {
Packit Service a31ea6
	if (ctxt->inSubset == 2) {
Packit Service a31ea6
	    ctxt->myDoc->standalone = 0;
Packit Service a31ea6
	    ret = xmlGetDocEntity(ctxt->myDoc, name);
Packit Service a31ea6
	    ctxt->myDoc->standalone = 1;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    ret = xmlGetDocEntity(ctxt->myDoc, name);
Packit Service a31ea6
	    if (ret == NULL) {
Packit Service a31ea6
		ctxt->myDoc->standalone = 0;
Packit Service a31ea6
		ret = xmlGetDocEntity(ctxt->myDoc, name);
Packit Service a31ea6
		if (ret != NULL) {
Packit Service a31ea6
		    xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE,
Packit Service a31ea6
	 "Entity(%s) document marked standalone but requires external subset\n",
Packit Service a31ea6
				   name, NULL);
Packit Service a31ea6
		}
Packit Service a31ea6
		ctxt->myDoc->standalone = 1;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    } else {
Packit Service a31ea6
	ret = xmlGetDocEntity(ctxt->myDoc, name);
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((ret != NULL) &&
Packit Service a31ea6
	((ctxt->validate) || (ctxt->replaceEntities)) &&
Packit Service a31ea6
	(ret->children == NULL) &&
Packit Service a31ea6
	(ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
Packit Service a31ea6
	int val;
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * for validation purposes we really need to fetch and
Packit Service a31ea6
	 * parse the external entity
Packit Service a31ea6
	 */
Packit Service a31ea6
	xmlNodePtr children;
Packit Service a31ea6
	unsigned long oldnbent = ctxt->nbentities;
Packit Service a31ea6
Packit Service a31ea6
        val = xmlParseCtxtExternalEntity(ctxt, ret->URI,
Packit Service a31ea6
		                         ret->ExternalID, &children);
Packit Service a31ea6
	if (val == 0) {
Packit Service a31ea6
	    xmlAddChildList((xmlNodePtr) ret, children);
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
Packit Service a31ea6
		           "Failure to process entity %s\n", name, NULL);
Packit Service a31ea6
	    ctxt->validate = 0;
Packit Service a31ea6
	    return(NULL);
Packit Service a31ea6
	}
Packit Service a31ea6
	ret->owner = 1;
Packit Service a31ea6
	if (ret->checked == 0) {
Packit Service a31ea6
	    ret->checked = (ctxt->nbentities - oldnbent + 1) * 2;
Packit Service a31ea6
	    if ((ret->content != NULL) && (xmlStrchr(ret->content, '<')))
Packit Service a31ea6
	        ret->checked |= 1;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2GetParameterEntity:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name: The entity name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Get a parameter entity by name
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the xmlEntityPtr if found.
Packit Service a31ea6
 */
Packit Service a31ea6
xmlEntityPtr
Packit Service a31ea6
xmlSAX2GetParameterEntity(void *ctx, const xmlChar *name)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlEntityPtr ret;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return(NULL);
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2GetParameterEntity(%s)\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    ret = xmlGetParameterEntity(ctxt->myDoc, name);
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2EntityDecl:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name:  the entity name
Packit Service a31ea6
 * @type:  the entity type
Packit Service a31ea6
 * @publicId: The public ID of the entity
Packit Service a31ea6
 * @systemId: The system ID of the entity
Packit Service a31ea6
 * @content: the entity value (without processing).
Packit Service a31ea6
 *
Packit Service a31ea6
 * An entity definition has been parsed
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
Packit Service a31ea6
          const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlEntityPtr ent;
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2EntityDecl(%s, %d, %s, %s, %s)\n",
Packit Service a31ea6
            name, type, publicId, systemId, content);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (ctxt->inSubset == 1) {
Packit Service a31ea6
	ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,
Packit Service a31ea6
		              systemId, content);
Packit Service a31ea6
	if ((ent == NULL) && (ctxt->pedantic))
Packit Service a31ea6
	    xmlWarnMsg(ctxt, XML_WAR_ENTITY_REDEFINED,
Packit Service a31ea6
	     "Entity(%s) already defined in the internal subset\n",
Packit Service a31ea6
	               name);
Packit Service a31ea6
	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
Packit Service a31ea6
	    xmlChar *URI;
Packit Service a31ea6
	    const char *base = NULL;
Packit Service a31ea6
Packit Service a31ea6
	    if (ctxt->input != NULL)
Packit Service a31ea6
		base = ctxt->input->filename;
Packit Service a31ea6
	    if (base == NULL)
Packit Service a31ea6
		base = ctxt->directory;
Packit Service a31ea6
Packit Service a31ea6
	    URI = xmlBuildURI(systemId, (const xmlChar *) base);
Packit Service a31ea6
	    ent->URI = URI;
Packit Service a31ea6
	}
Packit Service a31ea6
    } else if (ctxt->inSubset == 2) {
Packit Service a31ea6
	ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
Packit Service a31ea6
		              systemId, content);
Packit Service a31ea6
	if ((ent == NULL) && (ctxt->pedantic) &&
Packit Service a31ea6
	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
Packit Service a31ea6
	    ctxt->sax->warning(ctxt->userData,
Packit Service a31ea6
	     "Entity(%s) already defined in the external subset\n", name);
Packit Service a31ea6
	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
Packit Service a31ea6
	    xmlChar *URI;
Packit Service a31ea6
	    const char *base = NULL;
Packit Service a31ea6
Packit Service a31ea6
	    if (ctxt->input != NULL)
Packit Service a31ea6
		base = ctxt->input->filename;
Packit Service a31ea6
	    if (base == NULL)
Packit Service a31ea6
		base = ctxt->directory;
Packit Service a31ea6
Packit Service a31ea6
	    URI = xmlBuildURI(systemId, (const xmlChar *) base);
Packit Service a31ea6
	    ent->URI = URI;
Packit Service a31ea6
	}
Packit Service a31ea6
    } else {
Packit Service a31ea6
	xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
Packit Service a31ea6
	               "SAX.xmlSAX2EntityDecl(%s) called while not in subset\n",
Packit Service a31ea6
		       name, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2AttributeDecl:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @elem:  the name of the element
Packit Service a31ea6
 * @fullname:  the attribute name
Packit Service a31ea6
 * @type:  the attribute type
Packit Service a31ea6
 * @def:  the type of default value
Packit Service a31ea6
 * @defaultValue: the attribute default value
Packit Service a31ea6
 * @tree:  the tree of enumerated value set
Packit Service a31ea6
 *
Packit Service a31ea6
 * An attribute definition has been parsed
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
Packit Service a31ea6
              int type, int def, const xmlChar *defaultValue,
Packit Service a31ea6
	      xmlEnumerationPtr tree)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlAttributePtr attr;
Packit Service a31ea6
    xmlChar *name = NULL, *prefix = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n",
Packit Service a31ea6
            elem, fullname, type, def, defaultValue);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) &&
Packit Service a31ea6
        (type != XML_ATTRIBUTE_ID)) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Raise the error but keep the validity flag
Packit Service a31ea6
	 */
Packit Service a31ea6
	int tmp = ctxt->valid;
Packit Service a31ea6
	xmlErrValid(ctxt, XML_DTD_XMLID_TYPE,
Packit Service a31ea6
	      "xml:id : attribute type should be ID\n", NULL, NULL);
Packit Service a31ea6
	ctxt->valid = tmp;
Packit Service a31ea6
    }
Packit Service a31ea6
    /* TODO: optimize name/prefix allocation */
Packit Service a31ea6
    name = xmlSplitQName(ctxt, fullname, &prefix);
Packit Service a31ea6
    ctxt->vctxt.valid = 1;
Packit Service a31ea6
    if (ctxt->inSubset == 1)
Packit Service a31ea6
	attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
Packit Service a31ea6
	       name, prefix, (xmlAttributeType) type,
Packit Service a31ea6
	       (xmlAttributeDefault) def, defaultValue, tree);
Packit Service a31ea6
    else if (ctxt->inSubset == 2)
Packit Service a31ea6
	attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
Packit Service a31ea6
	   name, prefix, (xmlAttributeType) type,
Packit Service a31ea6
	   (xmlAttributeDefault) def, defaultValue, tree);
Packit Service a31ea6
    else {
Packit Service a31ea6
        xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
Packit Service a31ea6
	     "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n",
Packit Service a31ea6
	               name, NULL);
Packit Service a31ea6
	xmlFreeEnumeration(tree);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (ctxt->vctxt.valid == 0)
Packit Service a31ea6
	ctxt->valid = 0;
Packit Service a31ea6
    if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&
Packit Service a31ea6
        (ctxt->myDoc->intSubset != NULL))
Packit Service a31ea6
	ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
	                                        attr);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
    if (prefix != NULL)
Packit Service a31ea6
	xmlFree(prefix);
Packit Service a31ea6
    if (name != NULL)
Packit Service a31ea6
	xmlFree(name);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2ElementDecl:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name:  the element name
Packit Service a31ea6
 * @type:  the element type
Packit Service a31ea6
 * @content: the element value tree
Packit Service a31ea6
 *
Packit Service a31ea6
 * An element definition has been parsed
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,
Packit Service a31ea6
            xmlElementContentPtr content)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlElementPtr elem = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
                    "SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->inSubset == 1)
Packit Service a31ea6
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
Packit Service a31ea6
                                 name, (xmlElementTypeVal) type, content);
Packit Service a31ea6
    else if (ctxt->inSubset == 2)
Packit Service a31ea6
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
Packit Service a31ea6
                                 name, (xmlElementTypeVal) type, content);
Packit Service a31ea6
    else {
Packit Service a31ea6
        xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
Packit Service a31ea6
	     "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
Packit Service a31ea6
	               name, NULL);
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (elem == NULL)
Packit Service a31ea6
        ctxt->valid = 0;
Packit Service a31ea6
    if (ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
        ctxt->valid &=
Packit Service a31ea6
            xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2NotationDecl:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name: The name of the notation
Packit Service a31ea6
 * @publicId: The public ID of the entity
Packit Service a31ea6
 * @systemId: The system ID of the entity
Packit Service a31ea6
 *
Packit Service a31ea6
 * What to do when a notation declaration has been parsed.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2NotationDecl(void *ctx, const xmlChar *name,
Packit Service a31ea6
	     const xmlChar *publicId, const xmlChar *systemId)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNotationPtr nota = NULL;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
Packit Service a31ea6
        return;
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    if ((publicId == NULL) && (systemId == NULL)) {
Packit Service a31ea6
	xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
Packit Service a31ea6
	     "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
Packit Service a31ea6
	               name, NULL);
Packit Service a31ea6
	return;
Packit Service a31ea6
    } else if (ctxt->inSubset == 1)
Packit Service a31ea6
	nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
Packit Service a31ea6
                              publicId, systemId);
Packit Service a31ea6
    else if (ctxt->inSubset == 2)
Packit Service a31ea6
	nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
Packit Service a31ea6
                              publicId, systemId);
Packit Service a31ea6
    else {
Packit Service a31ea6
	xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
Packit Service a31ea6
	     "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n",
Packit Service a31ea6
	               name, NULL);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (nota == NULL) ctxt->valid = 0;
Packit Service a31ea6
    if ((ctxt->validate) && (ctxt->wellFormed) &&
Packit Service a31ea6
        (ctxt->myDoc->intSubset != NULL))
Packit Service a31ea6
	ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
	                                       nota);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2UnparsedEntityDecl:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name: The name of the entity
Packit Service a31ea6
 * @publicId: The public ID of the entity
Packit Service a31ea6
 * @systemId: The system ID of the entity
Packit Service a31ea6
 * @notationName: the name of the notation
Packit Service a31ea6
 *
Packit Service a31ea6
 * What to do when an unparsed entity declaration is parsed
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name,
Packit Service a31ea6
		   const xmlChar *publicId, const xmlChar *systemId,
Packit Service a31ea6
		   const xmlChar *notationName)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlEntityPtr ent;
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2UnparsedEntityDecl(%s, %s, %s, %s)\n",
Packit Service a31ea6
            name, publicId, systemId, notationName);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (ctxt->inSubset == 1) {
Packit Service a31ea6
	ent = xmlAddDocEntity(ctxt->myDoc, name,
Packit Service a31ea6
			XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
Packit Service a31ea6
			publicId, systemId, notationName);
Packit Service a31ea6
	if ((ent == NULL) && (ctxt->pedantic) &&
Packit Service a31ea6
	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
Packit Service a31ea6
	    ctxt->sax->warning(ctxt->userData,
Packit Service a31ea6
	     "Entity(%s) already defined in the internal subset\n", name);
Packit Service a31ea6
	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
Packit Service a31ea6
	    xmlChar *URI;
Packit Service a31ea6
	    const char *base = NULL;
Packit Service a31ea6
Packit Service a31ea6
	    if (ctxt->input != NULL)
Packit Service a31ea6
		base = ctxt->input->filename;
Packit Service a31ea6
	    if (base == NULL)
Packit Service a31ea6
		base = ctxt->directory;
Packit Service a31ea6
Packit Service a31ea6
	    URI = xmlBuildURI(systemId, (const xmlChar *) base);
Packit Service a31ea6
	    ent->URI = URI;
Packit Service a31ea6
	}
Packit Service a31ea6
    } else if (ctxt->inSubset == 2) {
Packit Service a31ea6
	ent = xmlAddDtdEntity(ctxt->myDoc, name,
Packit Service a31ea6
			XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
Packit Service a31ea6
			publicId, systemId, notationName);
Packit Service a31ea6
	if ((ent == NULL) && (ctxt->pedantic) &&
Packit Service a31ea6
	    (ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
Packit Service a31ea6
	    ctxt->sax->warning(ctxt->userData,
Packit Service a31ea6
	     "Entity(%s) already defined in the external subset\n", name);
Packit Service a31ea6
	if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
Packit Service a31ea6
	    xmlChar *URI;
Packit Service a31ea6
	    const char *base = NULL;
Packit Service a31ea6
Packit Service a31ea6
	    if (ctxt->input != NULL)
Packit Service a31ea6
		base = ctxt->input->filename;
Packit Service a31ea6
	    if (base == NULL)
Packit Service a31ea6
		base = ctxt->directory;
Packit Service a31ea6
Packit Service a31ea6
	    URI = xmlBuildURI(systemId, (const xmlChar *) base);
Packit Service a31ea6
	    ent->URI = URI;
Packit Service a31ea6
	}
Packit Service a31ea6
    } else {
Packit Service a31ea6
        xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
Packit Service a31ea6
	     "SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n",
Packit Service a31ea6
	               name, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2SetDocumentLocator:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @loc: A SAX Locator
Packit Service a31ea6
 *
Packit Service a31ea6
 * Receive the document locator at startup, actually xmlDefaultSAXLocator
Packit Service a31ea6
 * Everything is available on the context, so this is useless in our case.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2SetDocumentLocator()\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2StartDocument:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when the document start being processed.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2StartDocument(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlDocPtr doc;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2StartDocument()\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (ctxt->html) {
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
	if (ctxt->myDoc == NULL)
Packit Service a31ea6
	    ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
Packit Service a31ea6
	if (ctxt->myDoc == NULL) {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
	ctxt->myDoc->properties = XML_DOC_HTML;
Packit Service a31ea6
	ctxt->myDoc->parseFlags = ctxt->options;
Packit Service a31ea6
#else
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"libxml2 built without HTML support\n");
Packit Service a31ea6
	ctxt->errNo = XML_ERR_INTERNAL_ERROR;
Packit Service a31ea6
	ctxt->instate = XML_PARSER_EOF;
Packit Service a31ea6
	ctxt->disableSAX = 1;
Packit Service a31ea6
	return;
Packit Service a31ea6
#endif
Packit Service a31ea6
    } else {
Packit Service a31ea6
	doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
Packit Service a31ea6
	if (doc != NULL) {
Packit Service a31ea6
	    doc->properties = 0;
Packit Service a31ea6
	    if (ctxt->options & XML_PARSE_OLD10)
Packit Service a31ea6
	        doc->properties |= XML_DOC_OLD10;
Packit Service a31ea6
	    doc->parseFlags = ctxt->options;
Packit Service a31ea6
	    if (ctxt->encoding != NULL)
Packit Service a31ea6
		doc->encoding = xmlStrdup(ctxt->encoding);
Packit Service a31ea6
	    else
Packit Service a31ea6
		doc->encoding = NULL;
Packit Service a31ea6
	    doc->standalone = ctxt->standalone;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
	if ((ctxt->dictNames) && (doc != NULL)) {
Packit Service a31ea6
	    doc->dict = ctxt->dict;
Packit Service a31ea6
	    xmlDictReference(doc->dict);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
Packit Service a31ea6
	(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
Packit Service a31ea6
	ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename);
Packit Service a31ea6
	if (ctxt->myDoc->URL == NULL)
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2EndDocument:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when the document end has been detected.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2EndDocument(void *ctx)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2EndDocument()\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
	ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Grab the encoding if it was added on-the-fly
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&
Packit Service a31ea6
	(ctxt->myDoc->encoding == NULL)) {
Packit Service a31ea6
	ctxt->myDoc->encoding = ctxt->encoding;
Packit Service a31ea6
	ctxt->encoding = NULL;
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((ctxt->inputTab != NULL) &&
Packit Service a31ea6
        (ctxt->inputNr > 0) && (ctxt->inputTab[0] != NULL) &&
Packit Service a31ea6
        (ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&
Packit Service a31ea6
	(ctxt->myDoc->encoding == NULL)) {
Packit Service a31ea6
	ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&
Packit Service a31ea6
	(ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {
Packit Service a31ea6
	ctxt->myDoc->charset = ctxt->charset;
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED)
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2AttributeInternal:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @fullname:  The attribute name, including namespace prefix
Packit Service a31ea6
 * @value:  The attribute value
Packit Service a31ea6
 * @prefix: the prefix on the element node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle an attribute that has been read by the parser.
Packit Service a31ea6
 * The default handling is to convert the attribute into an
Packit Service a31ea6
 * DOM subtree and past it in a new xmlAttr element added to
Packit Service a31ea6
 * the element.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
Packit Service a31ea6
             const xmlChar *value, const xmlChar *prefix ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlAttrPtr ret;
Packit Service a31ea6
    xmlChar *name;
Packit Service a31ea6
    xmlChar *ns;
Packit Service a31ea6
    xmlChar *nval;
Packit Service a31ea6
    xmlNsPtr namespace;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->html) {
Packit Service a31ea6
	name = xmlStrdup(fullname);
Packit Service a31ea6
	ns = NULL;
Packit Service a31ea6
	namespace = NULL;
Packit Service a31ea6
    } else {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Split the full name into a namespace prefix and the tag name
Packit Service a31ea6
	 */
Packit Service a31ea6
	name = xmlSplitQName(ctxt, fullname, &ns);
Packit Service a31ea6
	if ((name != NULL) && (name[0] == 0)) {
Packit Service a31ea6
	    if (xmlStrEqual(ns, BAD_CAST "xmlns")) {
Packit Service a31ea6
		xmlNsErrMsg(ctxt, XML_ERR_NS_DECL_ERROR,
Packit Service a31ea6
			    "invalid namespace declaration '%s'\n",
Packit Service a31ea6
			    fullname, NULL);
Packit Service a31ea6
	    } else {
Packit Service a31ea6
		xmlNsWarnMsg(ctxt, XML_WAR_NS_COLUMN,
Packit Service a31ea6
			     "Avoid attribute ending with ':' like '%s'\n",
Packit Service a31ea6
			     fullname, NULL);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (ns != NULL)
Packit Service a31ea6
		xmlFree(ns);
Packit Service a31ea6
	    ns = NULL;
Packit Service a31ea6
	    xmlFree(name);
Packit Service a31ea6
	    name = xmlStrdup(fullname);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (name == NULL) {
Packit Service a31ea6
        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
	if (ns != NULL)
Packit Service a31ea6
	    xmlFree(ns);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
    if ((ctxt->html) &&
Packit Service a31ea6
        (value == NULL) && (htmlIsBooleanAttr(fullname))) {
Packit Service a31ea6
            nval = xmlStrdup(fullname);
Packit Service a31ea6
            value = (const xmlChar *) nval;
Packit Service a31ea6
    } else
Packit Service a31ea6
#endif
Packit Service a31ea6
    {
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
        /*
Packit Service a31ea6
         * Do the last stage of the attribute normalization
Packit Service a31ea6
         * Needed for HTML too:
Packit Service a31ea6
         *   http://www.w3.org/TR/html4/types.html#h-6.2
Packit Service a31ea6
         */
Packit Service a31ea6
        ctxt->vctxt.valid = 1;
Packit Service a31ea6
        nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt,
Packit Service a31ea6
                                               ctxt->myDoc, ctxt->node,
Packit Service a31ea6
                                               fullname, value);
Packit Service a31ea6
        if (ctxt->vctxt.valid != 1) {
Packit Service a31ea6
            ctxt->valid = 0;
Packit Service a31ea6
        }
Packit Service a31ea6
        if (nval != NULL)
Packit Service a31ea6
            value = nval;
Packit Service a31ea6
#else
Packit Service a31ea6
        nval = NULL;
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Check whether it's a namespace definition
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((!ctxt->html) && (ns == NULL) &&
Packit Service a31ea6
        (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
Packit Service a31ea6
        (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
Packit Service a31ea6
	xmlNsPtr nsret;
Packit Service a31ea6
	xmlChar *val;
Packit Service a31ea6
Packit Service a31ea6
        if (!ctxt->replaceEntities) {
Packit Service a31ea6
	    ctxt->depth++;
Packit Service a31ea6
	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
Packit Service a31ea6
		                          0,0,0);
Packit Service a31ea6
	    ctxt->depth--;
Packit Service a31ea6
	    if (val == NULL) {
Packit Service a31ea6
	        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
		if (name != NULL)
Packit Service a31ea6
		    xmlFree(name);
Packit Service a31ea6
                if (nval != NULL)
Packit Service a31ea6
                    xmlFree(nval);
Packit Service a31ea6
		return;
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    val = (xmlChar *) value;
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	if (val[0] != 0) {
Packit Service a31ea6
	    xmlURIPtr uri;
Packit Service a31ea6
Packit Service a31ea6
	    uri = xmlParseURI((const char *)val);
Packit Service a31ea6
	    if (uri == NULL) {
Packit Service a31ea6
		if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
Packit Service a31ea6
		    ctxt->sax->warning(ctxt->userData,
Packit Service a31ea6
			 "xmlns: %s not a valid URI\n", val);
Packit Service a31ea6
	    } else {
Packit Service a31ea6
		if (uri->scheme == NULL) {
Packit Service a31ea6
		    if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
Packit Service a31ea6
			ctxt->sax->warning(ctxt->userData,
Packit Service a31ea6
			     "xmlns: URI %s is not absolute\n", val);
Packit Service a31ea6
		}
Packit Service a31ea6
		xmlFreeURI(uri);
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	/* a default namespace definition */
Packit Service a31ea6
	nsret = xmlNewNs(ctxt->node, val, NULL);
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Validate also for namespace decls, they are attributes from
Packit Service a31ea6
	 * an XML-1.0 perspective
Packit Service a31ea6
	 */
Packit Service a31ea6
        if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
	    ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
	    ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
					   ctxt->node, prefix, nsret, val);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
	if (name != NULL)
Packit Service a31ea6
	    xmlFree(name);
Packit Service a31ea6
	if (nval != NULL)
Packit Service a31ea6
	    xmlFree(nval);
Packit Service a31ea6
	if (val != value)
Packit Service a31ea6
	    xmlFree(val);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if ((!ctxt->html) &&
Packit Service a31ea6
	(ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
Packit Service a31ea6
        (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
Packit Service a31ea6
	xmlNsPtr nsret;
Packit Service a31ea6
	xmlChar *val;
Packit Service a31ea6
Packit Service a31ea6
        if (!ctxt->replaceEntities) {
Packit Service a31ea6
	    ctxt->depth++;
Packit Service a31ea6
	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
Packit Service a31ea6
		                          0,0,0);
Packit Service a31ea6
	    ctxt->depth--;
Packit Service a31ea6
	    if (val == NULL) {
Packit Service a31ea6
	        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
	        xmlFree(ns);
Packit Service a31ea6
		if (name != NULL)
Packit Service a31ea6
		    xmlFree(name);
Packit Service a31ea6
                if (nval != NULL)
Packit Service a31ea6
                    xmlFree(nval);
Packit Service a31ea6
		return;
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    val = (xmlChar *) value;
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	if (val[0] == 0) {
Packit Service a31ea6
	    xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY,
Packit Service a31ea6
		        "Empty namespace name for prefix %s\n", name, NULL);
Packit Service a31ea6
	}
Packit Service a31ea6
	if ((ctxt->pedantic != 0) && (val[0] != 0)) {
Packit Service a31ea6
	    xmlURIPtr uri;
Packit Service a31ea6
Packit Service a31ea6
	    uri = xmlParseURI((const char *)val);
Packit Service a31ea6
	    if (uri == NULL) {
Packit Service a31ea6
	        xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
Packit Service a31ea6
			 "xmlns:%s: %s not a valid URI\n", name, value);
Packit Service a31ea6
	    } else {
Packit Service a31ea6
		if (uri->scheme == NULL) {
Packit Service a31ea6
		    xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
Packit Service a31ea6
			   "xmlns:%s: URI %s is not absolute\n", name, value);
Packit Service a31ea6
		}
Packit Service a31ea6
		xmlFreeURI(uri);
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	/* a standard namespace definition */
Packit Service a31ea6
	nsret = xmlNewNs(ctxt->node, val, name);
Packit Service a31ea6
	xmlFree(ns);
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Validate also for namespace decls, they are attributes from
Packit Service a31ea6
	 * an XML-1.0 perspective
Packit Service a31ea6
	 */
Packit Service a31ea6
        if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
	    ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
	    ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
					   ctxt->node, prefix, nsret, value);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
	if (name != NULL)
Packit Service a31ea6
	    xmlFree(name);
Packit Service a31ea6
	if (nval != NULL)
Packit Service a31ea6
	    xmlFree(nval);
Packit Service a31ea6
	if (val != value)
Packit Service a31ea6
	    xmlFree(val);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (ns != NULL) {
Packit Service a31ea6
	namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
Packit Service a31ea6
Packit Service a31ea6
	if (namespace == NULL) {
Packit Service a31ea6
	    xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
Packit Service a31ea6
		    "Namespace prefix %s of attribute %s is not defined\n",
Packit Service a31ea6
		             ns, name);
Packit Service a31ea6
	} else {
Packit Service a31ea6
            xmlAttrPtr prop;
Packit Service a31ea6
Packit Service a31ea6
            prop = ctxt->node->properties;
Packit Service a31ea6
            while (prop != NULL) {
Packit Service a31ea6
                if (prop->ns != NULL) {
Packit Service a31ea6
                    if ((xmlStrEqual(name, prop->name)) &&
Packit Service a31ea6
                        ((namespace == prop->ns) ||
Packit Service a31ea6
                         (xmlStrEqual(namespace->href, prop->ns->href)))) {
Packit Service a31ea6
                            xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED,
Packit Service a31ea6
                                    "Attribute %s in %s redefined\n",
Packit Service a31ea6
                                             name, namespace->href);
Packit Service a31ea6
                        ctxt->wellFormed = 0;
Packit Service a31ea6
                        if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Packit Service a31ea6
                        if (name != NULL)
Packit Service a31ea6
                            xmlFree(name);
Packit Service a31ea6
                        goto error;
Packit Service a31ea6
                    }
Packit Service a31ea6
                }
Packit Service a31ea6
                prop = prop->next;
Packit Service a31ea6
            }
Packit Service a31ea6
        }
Packit Service a31ea6
    } else {
Packit Service a31ea6
	namespace = NULL;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /* !!!!!!  */
Packit Service a31ea6
    ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL);
Packit Service a31ea6
Packit Service a31ea6
    if (ret != NULL) {
Packit Service a31ea6
        if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
Packit Service a31ea6
	    xmlNodePtr tmp;
Packit Service a31ea6
Packit Service a31ea6
	    ret->children = xmlStringGetNodeList(ctxt->myDoc, value);
Packit Service a31ea6
	    tmp = ret->children;
Packit Service a31ea6
	    while (tmp != NULL) {
Packit Service a31ea6
		tmp->parent = (xmlNodePtr) ret;
Packit Service a31ea6
		if (tmp->next == NULL)
Packit Service a31ea6
		    ret->last = tmp;
Packit Service a31ea6
		tmp = tmp->next;
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else if (value != NULL) {
Packit Service a31ea6
	    ret->children = xmlNewDocText(ctxt->myDoc, value);
Packit Service a31ea6
	    ret->last = ret->children;
Packit Service a31ea6
	    if (ret->children != NULL)
Packit Service a31ea6
		ret->children->parent = (xmlNodePtr) ret;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset) {
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * If we don't substitute entities, the validation should be
Packit Service a31ea6
	 * done on a value with replaced entities anyway.
Packit Service a31ea6
	 */
Packit Service a31ea6
        if (!ctxt->replaceEntities) {
Packit Service a31ea6
	    xmlChar *val;
Packit Service a31ea6
Packit Service a31ea6
	    ctxt->depth++;
Packit Service a31ea6
	    val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
Packit Service a31ea6
		                          0,0,0);
Packit Service a31ea6
	    ctxt->depth--;
Packit Service a31ea6
Packit Service a31ea6
	    if (val == NULL)
Packit Service a31ea6
		ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
				ctxt->myDoc, ctxt->node, ret, value);
Packit Service a31ea6
	    else {
Packit Service a31ea6
		xmlChar *nvalnorm;
Packit Service a31ea6
Packit Service a31ea6
		/*
Packit Service a31ea6
		 * Do the last stage of the attribute normalization
Packit Service a31ea6
		 * It need to be done twice ... it's an extra burden related
Packit Service a31ea6
		 * to the ability to keep xmlSAX2References in attributes
Packit Service a31ea6
		 */
Packit Service a31ea6
		nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,
Packit Service a31ea6
					    ctxt->node, fullname, val);
Packit Service a31ea6
		if (nvalnorm != NULL) {
Packit Service a31ea6
		    xmlFree(val);
Packit Service a31ea6
		    val = nvalnorm;
Packit Service a31ea6
		}
Packit Service a31ea6
Packit Service a31ea6
		ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
			        ctxt->myDoc, ctxt->node, ret, val);
Packit Service a31ea6
                xmlFree(val);
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
					       ctxt->node, ret, value);
Packit Service a31ea6
	}
Packit Service a31ea6
    } else
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
Packit Service a31ea6
	       (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
Packit Service a31ea6
	        ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) {
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * when validating, the ID registration is done at the attribute
Packit Service a31ea6
	 * validation level. Otherwise we have to do specific handling here.
Packit Service a31ea6
	 */
Packit Service a31ea6
	if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * Add the xml:id value
Packit Service a31ea6
	     *
Packit Service a31ea6
	     * Open issue: normalization of the value.
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if (xmlValidateNCName(value, 1) != 0) {
Packit Service a31ea6
	        xmlErrValid(ctxt, XML_DTD_XMLID_VALUE,
Packit Service a31ea6
		      "xml:id : attribute value %s is not an NCName\n",
Packit Service a31ea6
			    (const char *) value, NULL);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
Packit Service a31ea6
	} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
Packit Service a31ea6
	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
Packit Service a31ea6
	else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
Packit Service a31ea6
	    xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
error:
Packit Service a31ea6
    if (nval != NULL)
Packit Service a31ea6
	xmlFree(nval);
Packit Service a31ea6
    if (ns != NULL)
Packit Service a31ea6
	xmlFree(ns);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/*
Packit Service a31ea6
 * xmlCheckDefaultedAttributes:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Check defaulted attributes from the DTD
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt, const xmlChar *name,
Packit Service a31ea6
	const xmlChar *prefix, const xmlChar **atts) {
Packit Service a31ea6
    xmlElementPtr elemDecl;
Packit Service a31ea6
    const xmlChar *att;
Packit Service a31ea6
    int internal = 1;
Packit Service a31ea6
    int i;
Packit Service a31ea6
Packit Service a31ea6
    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix);
Packit Service a31ea6
    if (elemDecl == NULL) {
Packit Service a31ea6
	elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix);
Packit Service a31ea6
	internal = 0;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
process_external_subset:
Packit Service a31ea6
Packit Service a31ea6
    if (elemDecl != NULL) {
Packit Service a31ea6
	xmlAttributePtr attr = elemDecl->attributes;
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Check against defaulted attributes from the external subset
Packit Service a31ea6
	 * if the document is stamped as standalone
Packit Service a31ea6
	 */
Packit Service a31ea6
	if ((ctxt->myDoc->standalone == 1) &&
Packit Service a31ea6
	    (ctxt->myDoc->extSubset != NULL) &&
Packit Service a31ea6
	    (ctxt->validate)) {
Packit Service a31ea6
	    while (attr != NULL) {
Packit Service a31ea6
		if ((attr->defaultValue != NULL) &&
Packit Service a31ea6
		    (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
Packit Service a31ea6
					attr->elem, attr->name,
Packit Service a31ea6
					attr->prefix) == attr) &&
Packit Service a31ea6
		    (xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
Packit Service a31ea6
					attr->elem, attr->name,
Packit Service a31ea6
					attr->prefix) == NULL)) {
Packit Service a31ea6
		    xmlChar *fulln;
Packit Service a31ea6
Packit Service a31ea6
		    if (attr->prefix != NULL) {
Packit Service a31ea6
			fulln = xmlStrdup(attr->prefix);
Packit Service a31ea6
			fulln = xmlStrcat(fulln, BAD_CAST ":");
Packit Service a31ea6
			fulln = xmlStrcat(fulln, attr->name);
Packit Service a31ea6
		    } else {
Packit Service a31ea6
			fulln = xmlStrdup(attr->name);
Packit Service a31ea6
		    }
Packit Service a31ea6
                    if (fulln == NULL) {
Packit Service a31ea6
                        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
                        break;
Packit Service a31ea6
                    }
Packit Service a31ea6
Packit Service a31ea6
		    /*
Packit Service a31ea6
		     * Check that the attribute is not declared in the
Packit Service a31ea6
		     * serialization
Packit Service a31ea6
		     */
Packit Service a31ea6
		    att = NULL;
Packit Service a31ea6
		    if (atts != NULL) {
Packit Service a31ea6
			i = 0;
Packit Service a31ea6
			att = atts[i];
Packit Service a31ea6
			while (att != NULL) {
Packit Service a31ea6
			    if (xmlStrEqual(att, fulln))
Packit Service a31ea6
				break;
Packit Service a31ea6
			    i += 2;
Packit Service a31ea6
			    att = atts[i];
Packit Service a31ea6
			}
Packit Service a31ea6
		    }
Packit Service a31ea6
		    if (att == NULL) {
Packit Service a31ea6
		        xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED,
Packit Service a31ea6
      "standalone: attribute %s on %s defaulted from external subset\n",
Packit Service a31ea6
				    (const char *)fulln,
Packit Service a31ea6
				    (const char *)attr->elem);
Packit Service a31ea6
		    }
Packit Service a31ea6
                    xmlFree(fulln);
Packit Service a31ea6
		}
Packit Service a31ea6
		attr = attr->nexth;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * Actually insert defaulted values when needed
Packit Service a31ea6
	 */
Packit Service a31ea6
	attr = elemDecl->attributes;
Packit Service a31ea6
	while (attr != NULL) {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * Make sure that attributes redefinition occuring in the
Packit Service a31ea6
	     * internal subset are not overriden by definitions in the
Packit Service a31ea6
	     * external subset.
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if (attr->defaultValue != NULL) {
Packit Service a31ea6
		/*
Packit Service a31ea6
		 * the element should be instantiated in the tree if:
Packit Service a31ea6
		 *  - this is a namespace prefix
Packit Service a31ea6
		 *  - the user required for completion in the tree
Packit Service a31ea6
		 *    like XSLT
Packit Service a31ea6
		 *  - there isn't already an attribute definition
Packit Service a31ea6
		 *    in the internal subset overriding it.
Packit Service a31ea6
		 */
Packit Service a31ea6
		if (((attr->prefix != NULL) &&
Packit Service a31ea6
		     (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
Packit Service a31ea6
		    ((attr->prefix == NULL) &&
Packit Service a31ea6
		     (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
Packit Service a31ea6
		    (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
Packit Service a31ea6
		    xmlAttributePtr tst;
Packit Service a31ea6
Packit Service a31ea6
		    tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
Packit Service a31ea6
					     attr->elem, attr->name,
Packit Service a31ea6
					     attr->prefix);
Packit Service a31ea6
		    if ((tst == attr) || (tst == NULL)) {
Packit Service a31ea6
		        xmlChar fn[50];
Packit Service a31ea6
			xmlChar *fulln;
Packit Service a31ea6
Packit Service a31ea6
                        fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);
Packit Service a31ea6
			if (fulln == NULL) {
Packit Service a31ea6
			    xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
			    return;
Packit Service a31ea6
			}
Packit Service a31ea6
Packit Service a31ea6
			/*
Packit Service a31ea6
			 * Check that the attribute is not declared in the
Packit Service a31ea6
			 * serialization
Packit Service a31ea6
			 */
Packit Service a31ea6
			att = NULL;
Packit Service a31ea6
			if (atts != NULL) {
Packit Service a31ea6
			    i = 0;
Packit Service a31ea6
			    att = atts[i];
Packit Service a31ea6
			    while (att != NULL) {
Packit Service a31ea6
				if (xmlStrEqual(att, fulln))
Packit Service a31ea6
				    break;
Packit Service a31ea6
				i += 2;
Packit Service a31ea6
				att = atts[i];
Packit Service a31ea6
			    }
Packit Service a31ea6
			}
Packit Service a31ea6
			if (att == NULL) {
Packit Service a31ea6
			    xmlSAX2AttributeInternal(ctxt, fulln,
Packit Service a31ea6
						 attr->defaultValue, prefix);
Packit Service a31ea6
			}
Packit Service a31ea6
			if ((fulln != fn) && (fulln != attr->name))
Packit Service a31ea6
			    xmlFree(fulln);
Packit Service a31ea6
		    }
Packit Service a31ea6
		}
Packit Service a31ea6
	    }
Packit Service a31ea6
	    attr = attr->nexth;
Packit Service a31ea6
	}
Packit Service a31ea6
	if (internal == 1) {
Packit Service a31ea6
	    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
Packit Service a31ea6
		                             name, prefix);
Packit Service a31ea6
	    internal = 0;
Packit Service a31ea6
	    goto process_external_subset;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2StartElement:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @fullname:  The element name, including namespace prefix
Packit Service a31ea6
 * @atts:  An array of name/value attributes pairs, NULL terminated
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when an opening tag has been processed.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
    xmlNodePtr parent;
Packit Service a31ea6
    xmlNsPtr ns;
Packit Service a31ea6
    xmlChar *name;
Packit Service a31ea6
    xmlChar *prefix;
Packit Service a31ea6
    const xmlChar *att;
Packit Service a31ea6
    const xmlChar *value;
Packit Service a31ea6
    int i;
Packit Service a31ea6
Packit Service a31ea6
    if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
Packit Service a31ea6
    parent = ctxt->node;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2StartElement(%s)\n", fullname);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * First check on validity:
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
Packit Service a31ea6
        ((ctxt->myDoc->intSubset == NULL) ||
Packit Service a31ea6
	 ((ctxt->myDoc->intSubset->notations == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->elements == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->attributes == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->entities == NULL)))) {
Packit Service a31ea6
	xmlErrValid(ctxt, XML_ERR_NO_DTD,
Packit Service a31ea6
	  "Validation failed: no DTD found !", NULL, NULL);
Packit Service a31ea6
	ctxt->validate = 0;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Split the full name into a namespace prefix and the tag name
Packit Service a31ea6
     */
Packit Service a31ea6
    name = xmlSplitQName(ctxt, fullname, &prefix);
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Note : the namespace resolution is deferred until the end of the
Packit Service a31ea6
     *        attributes parsing, since local namespace can be defined as
Packit Service a31ea6
     *        an attribute at this level.
Packit Service a31ea6
     */
Packit Service a31ea6
    ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, name, NULL);
Packit Service a31ea6
    if (ret == NULL) {
Packit Service a31ea6
        if (prefix != NULL)
Packit Service a31ea6
	    xmlFree(prefix);
Packit Service a31ea6
	xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->myDoc->children == NULL) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
        xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
Packit Service a31ea6
    } else if (parent == NULL) {
Packit Service a31ea6
        parent = ctxt->myDoc->children;
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nodemem = -1;
Packit Service a31ea6
    if (ctxt->linenumbers) {
Packit Service a31ea6
	if (ctxt->input != NULL) {
Packit Service a31ea6
	    if (ctxt->input->line < 65535)
Packit Service a31ea6
		ret->line = (short) ctxt->input->line;
Packit Service a31ea6
	    else
Packit Service a31ea6
	        ret->line = 65535;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * We are parsing a new node.
Packit Service a31ea6
     */
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
    nodePush(ctxt, ret);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Link the child element
Packit Service a31ea6
     */
Packit Service a31ea6
    if (parent != NULL) {
Packit Service a31ea6
        if (parent->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "adding child %s to %s\n", name, parent->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
	    xmlAddChild(parent, ret);
Packit Service a31ea6
	} else {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "adding sibling %s to ", name);
Packit Service a31ea6
	    xmlDebugDumpOneNode(stderr, parent, 0);
Packit Service a31ea6
#endif
Packit Service a31ea6
	    xmlAddSibling(parent, ret);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Insert all the defaulted attributes from the DTD especially namespaces
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((!ctxt->html) &&
Packit Service a31ea6
	((ctxt->myDoc->intSubset != NULL) ||
Packit Service a31ea6
	 (ctxt->myDoc->extSubset != NULL))) {
Packit Service a31ea6
	xmlCheckDefaultedAttributes(ctxt, name, prefix, atts);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * process all the attributes whose name start with "xmlns"
Packit Service a31ea6
     */
Packit Service a31ea6
    if (atts != NULL) {
Packit Service a31ea6
        i = 0;
Packit Service a31ea6
	att = atts[i++];
Packit Service a31ea6
	value = atts[i++];
Packit Service a31ea6
	if (!ctxt->html) {
Packit Service a31ea6
	    while ((att != NULL) && (value != NULL)) {
Packit Service a31ea6
		if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') &&
Packit Service a31ea6
		    (att[3] == 'n') && (att[4] == 's'))
Packit Service a31ea6
		    xmlSAX2AttributeInternal(ctxt, att, value, prefix);
Packit Service a31ea6
Packit Service a31ea6
		att = atts[i++];
Packit Service a31ea6
		value = atts[i++];
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Search the namespace, note that since the attributes have been
Packit Service a31ea6
     * processed, the local namespaces are available.
Packit Service a31ea6
     */
Packit Service a31ea6
    ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
Packit Service a31ea6
    if ((ns == NULL) && (parent != NULL))
Packit Service a31ea6
	ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
Packit Service a31ea6
    if ((prefix != NULL) && (ns == NULL)) {
Packit Service a31ea6
	ns = xmlNewNs(ret, NULL, prefix);
Packit Service a31ea6
	xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
Packit Service a31ea6
		     "Namespace prefix %s is not defined\n",
Packit Service a31ea6
		     prefix, NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * set the namespace node, making sure that if the default namspace
Packit Service a31ea6
     * is unbound on a parent we simply kee it NULL
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ns != NULL) && (ns->href != NULL) &&
Packit Service a31ea6
	((ns->href[0] != 0) || (ns->prefix != NULL)))
Packit Service a31ea6
	xmlSetNs(ret, ns);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * process all the other attributes
Packit Service a31ea6
     */
Packit Service a31ea6
    if (atts != NULL) {
Packit Service a31ea6
        i = 0;
Packit Service a31ea6
	att = atts[i++];
Packit Service a31ea6
	value = atts[i++];
Packit Service a31ea6
	if (ctxt->html) {
Packit Service a31ea6
	    while (att != NULL) {
Packit Service a31ea6
		xmlSAX2AttributeInternal(ctxt, att, value, NULL);
Packit Service a31ea6
		att = atts[i++];
Packit Service a31ea6
		value = atts[i++];
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    while ((att != NULL) && (value != NULL)) {
Packit Service a31ea6
		if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l') ||
Packit Service a31ea6
		    (att[3] != 'n') || (att[4] != 's'))
Packit Service a31ea6
		    xmlSAX2AttributeInternal(ctxt, att, value, NULL);
Packit Service a31ea6
Packit Service a31ea6
		/*
Packit Service a31ea6
		 * Next ones
Packit Service a31ea6
		 */
Packit Service a31ea6
		att = atts[i++];
Packit Service a31ea6
		value = atts[i++];
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If it's the Document root, finish the DTD validation and
Packit Service a31ea6
     * check the document root element for validity
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) {
Packit Service a31ea6
	int chk;
Packit Service a31ea6
Packit Service a31ea6
	chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
Packit Service a31ea6
	if (chk <= 0)
Packit Service a31ea6
	    ctxt->valid = 0;
Packit Service a31ea6
	if (chk < 0)
Packit Service a31ea6
	    ctxt->wellFormed = 0;
Packit Service a31ea6
	ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
Packit Service a31ea6
	ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1;
Packit Service a31ea6
    }
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
    if (prefix != NULL)
Packit Service a31ea6
	xmlFree(prefix);
Packit Service a31ea6
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2EndElement:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name:  The element name
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when the end of an element has been detected.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr cur;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
    cur = ctxt->node;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    if (name == NULL)
Packit Service a31ea6
        xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(NULL)\n");
Packit Service a31ea6
    else
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(%s)\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    /* Capture end position and add node */
Packit Service a31ea6
    if (cur != NULL && ctxt->record_info) {
Packit Service a31ea6
      ctxt->nodeInfo->end_pos = ctxt->input->cur - ctxt->input->base;
Packit Service a31ea6
      ctxt->nodeInfo->end_line = ctxt->input->line;
Packit Service a31ea6
      ctxt->nodeInfo->node = cur;
Packit Service a31ea6
      xmlParserAddNodeInfo(ctxt, ctxt->nodeInfo);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nodemem = -1;
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
					     cur);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * end of parsing of this node.
Packit Service a31ea6
     */
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
    nodePop(ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_SAX1_ENABLED || LIBXML_HTML_ENABLED || LIBXML_LEGACY_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/*
Packit Service a31ea6
 * xmlSAX2TextNode:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @str:  the input string
Packit Service a31ea6
 * @len: the string length
Packit Service a31ea6
 *
Packit Service a31ea6
 * Callback for a text node
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the newly allocated string or NULL if not needed or error
Packit Service a31ea6
 */
Packit Service a31ea6
static xmlNodePtr
Packit Service a31ea6
xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
    const xmlChar *intern = NULL;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Allocate
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->freeElems != NULL) {
Packit Service a31ea6
	ret = ctxt->freeElems;
Packit Service a31ea6
	ctxt->freeElems = ret->next;
Packit Service a31ea6
	ctxt->freeElemsNr--;
Packit Service a31ea6
    } else {
Packit Service a31ea6
	ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ret == NULL) {
Packit Service a31ea6
        xmlErrMemory(ctxt, "xmlSAX2Characters");
Packit Service a31ea6
	return(NULL);
Packit Service a31ea6
    }
Packit Service a31ea6
    memset(ret, 0, sizeof(xmlNode));
Packit Service a31ea6
    /*
Packit Service a31ea6
     * intern the formatting blanks found between tags, or the
Packit Service a31ea6
     * very short strings
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->dictNames) {
Packit Service a31ea6
        xmlChar cur = str[len];
Packit Service a31ea6
Packit Service a31ea6
	if ((len < (int) (2 * sizeof(void *))) &&
Packit Service a31ea6
	    (ctxt->options & XML_PARSE_COMPACT)) {
Packit Service a31ea6
	    /* store the string in the node overriding properties and nsDef */
Packit Service a31ea6
	    xmlChar *tmp = (xmlChar *) &(ret->properties);
Packit Service a31ea6
	    memcpy(tmp, str, len);
Packit Service a31ea6
	    tmp[len] = 0;
Packit Service a31ea6
	    intern = tmp;
Packit Service a31ea6
	} else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
Packit Service a31ea6
	    ((cur == '<') && (str[len + 1] != '!')))) {
Packit Service a31ea6
	    intern = xmlDictLookup(ctxt->dict, str, len);
Packit Service a31ea6
	} else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
Packit Service a31ea6
	           (str[len + 1] != '!')) {
Packit Service a31ea6
	    int i;
Packit Service a31ea6
Packit Service a31ea6
	    for (i = 1;i < len;i++) {
Packit Service a31ea6
		if (!IS_BLANK_CH(str[i])) goto skip;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    intern = xmlDictLookup(ctxt->dict, str, len);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
skip:
Packit Service a31ea6
    ret->type = XML_TEXT_NODE;
Packit Service a31ea6
Packit Service a31ea6
    ret->name = xmlStringText;
Packit Service a31ea6
    if (intern == NULL) {
Packit Service a31ea6
	ret->content = xmlStrndup(str, len);
Packit Service a31ea6
	if (ret->content == NULL) {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode");
Packit Service a31ea6
	    xmlFree(ret);
Packit Service a31ea6
	    return(NULL);
Packit Service a31ea6
	}
Packit Service a31ea6
    } else
Packit Service a31ea6
	ret->content = (xmlChar *) intern;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->linenumbers) {
Packit Service a31ea6
	if (ctxt->input != NULL) {
Packit Service a31ea6
	    if (ctxt->input->line < 65535)
Packit Service a31ea6
		ret->line = (short) ctxt->input->line;
Packit Service a31ea6
	    else {
Packit Service a31ea6
	        ret->line = 65535;
Packit Service a31ea6
		if (ctxt->options & XML_PARSE_BIG_LINES)
Packit Service a31ea6
		    ret->psvi = (void *) (ptrdiff_t) ctxt->input->line;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
Packit Service a31ea6
	xmlRegisterNodeDefaultValue(ret);
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
/*
Packit Service a31ea6
 * xmlSAX2DecodeAttrEntities:
Packit Service a31ea6
 * @ctxt:  the parser context
Packit Service a31ea6
 * @str:  the input string
Packit Service a31ea6
 * @len: the string length
Packit Service a31ea6
 *
Packit Service a31ea6
 * Remove the entities from an attribute value
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the newly allocated string or NULL if not needed or error
Packit Service a31ea6
 */
Packit Service a31ea6
static xmlChar *
Packit Service a31ea6
xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt, const xmlChar *str,
Packit Service a31ea6
                          const xmlChar *end) {
Packit Service a31ea6
    const xmlChar *in;
Packit Service a31ea6
    xmlChar *ret;
Packit Service a31ea6
Packit Service a31ea6
    in = str;
Packit Service a31ea6
    while (in < end)
Packit Service a31ea6
        if (*in++ == '&')
Packit Service a31ea6
	    goto decode;
Packit Service a31ea6
    return(NULL);
Packit Service a31ea6
decode:
Packit Service a31ea6
    ctxt->depth++;
Packit Service a31ea6
    ret = xmlStringLenDecodeEntities(ctxt, str, end - str,
Packit Service a31ea6
				     XML_SUBSTITUTE_REF, 0,0,0);
Packit Service a31ea6
    ctxt->depth--;
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2AttributeNs:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @localname:  the local name of the attribute
Packit Service a31ea6
 * @prefix:  the attribute namespace prefix if available
Packit Service a31ea6
 * @URI:  the attribute namespace name if available
Packit Service a31ea6
 * @value:  Start of the attribute value
Packit Service a31ea6
 * @valueend: end of the attribute value
Packit Service a31ea6
 *
Packit Service a31ea6
 * Handle an attribute that has been read by the parser.
Packit Service a31ea6
 * The default handling is to convert the attribute into an
Packit Service a31ea6
 * DOM subtree and past it in a new xmlAttr element added to
Packit Service a31ea6
 * the element.
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
Packit Service a31ea6
                   const xmlChar * localname,
Packit Service a31ea6
                   const xmlChar * prefix,
Packit Service a31ea6
		   const xmlChar * value,
Packit Service a31ea6
		   const xmlChar * valueend)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlAttrPtr ret;
Packit Service a31ea6
    xmlNsPtr namespace = NULL;
Packit Service a31ea6
    xmlChar *dup = NULL;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Note: if prefix == NULL, the attribute is not in the default namespace
Packit Service a31ea6
     */
Packit Service a31ea6
    if (prefix != NULL)
Packit Service a31ea6
	namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, prefix);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * allocate the node
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->freeAttrs != NULL) {
Packit Service a31ea6
        ret = ctxt->freeAttrs;
Packit Service a31ea6
	ctxt->freeAttrs = ret->next;
Packit Service a31ea6
	ctxt->freeAttrsNr--;
Packit Service a31ea6
	memset(ret, 0, sizeof(xmlAttr));
Packit Service a31ea6
	ret->type = XML_ATTRIBUTE_NODE;
Packit Service a31ea6
Packit Service a31ea6
	ret->parent = ctxt->node;
Packit Service a31ea6
	ret->doc = ctxt->myDoc;
Packit Service a31ea6
	ret->ns = namespace;
Packit Service a31ea6
Packit Service a31ea6
	if (ctxt->dictNames)
Packit Service a31ea6
	    ret->name = localname;
Packit Service a31ea6
	else
Packit Service a31ea6
	    ret->name = xmlStrdup(localname);
Packit Service a31ea6
Packit Service a31ea6
        /* link at the end to preserv order, TODO speed up with a last */
Packit Service a31ea6
	if (ctxt->node->properties == NULL) {
Packit Service a31ea6
	    ctxt->node->properties = ret;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlAttrPtr prev = ctxt->node->properties;
Packit Service a31ea6
Packit Service a31ea6
	    while (prev->next != NULL) prev = prev->next;
Packit Service a31ea6
	    prev->next = ret;
Packit Service a31ea6
	    ret->prev = prev;
Packit Service a31ea6
	}
Packit Service a31ea6
Packit Service a31ea6
	if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
Packit Service a31ea6
	    xmlRegisterNodeDefaultValue((xmlNodePtr)ret);
Packit Service a31ea6
    } else {
Packit Service a31ea6
	if (ctxt->dictNames)
Packit Service a31ea6
	    ret = xmlNewNsPropEatName(ctxt->node, namespace,
Packit Service a31ea6
	                              (xmlChar *) localname, NULL);
Packit Service a31ea6
	else
Packit Service a31ea6
	    ret = xmlNewNsProp(ctxt->node, namespace, localname, NULL);
Packit Service a31ea6
	if (ret == NULL) {
Packit Service a31ea6
	    xmlErrMemory(ctxt, "xmlSAX2AttributeNs");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
Packit Service a31ea6
	xmlNodePtr tmp;
Packit Service a31ea6
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * We know that if there is an entity reference, then
Packit Service a31ea6
	 * the string has been dup'ed and terminates with 0
Packit Service a31ea6
	 * otherwise with ' or "
Packit Service a31ea6
	 */
Packit Service a31ea6
	if (*valueend != 0) {
Packit Service a31ea6
	    tmp = xmlSAX2TextNode(ctxt, value, valueend - value);
Packit Service a31ea6
	    ret->children = tmp;
Packit Service a31ea6
	    ret->last = tmp;
Packit Service a31ea6
	    if (tmp != NULL) {
Packit Service a31ea6
		tmp->doc = ret->doc;
Packit Service a31ea6
		tmp->parent = (xmlNodePtr) ret;
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    ret->children = xmlStringLenGetNodeList(ctxt->myDoc, value,
Packit Service a31ea6
						    valueend - value);
Packit Service a31ea6
	    tmp = ret->children;
Packit Service a31ea6
	    while (tmp != NULL) {
Packit Service a31ea6
	        tmp->doc = ret->doc;
Packit Service a31ea6
		tmp->parent = (xmlNodePtr) ret;
Packit Service a31ea6
		if (tmp->next == NULL)
Packit Service a31ea6
		    ret->last = tmp;
Packit Service a31ea6
		tmp = tmp->next;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    } else if (value != NULL) {
Packit Service a31ea6
	xmlNodePtr tmp;
Packit Service a31ea6
Packit Service a31ea6
	tmp = xmlSAX2TextNode(ctxt, value, valueend - value);
Packit Service a31ea6
	ret->children = tmp;
Packit Service a31ea6
	ret->last = tmp;
Packit Service a31ea6
	if (tmp != NULL) {
Packit Service a31ea6
	    tmp->doc = ret->doc;
Packit Service a31ea6
	    tmp->parent = (xmlNodePtr) ret;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset) {
Packit Service a31ea6
	/*
Packit Service a31ea6
	 * If we don't substitute entities, the validation should be
Packit Service a31ea6
	 * done on a value with replaced entities anyway.
Packit Service a31ea6
	 */
Packit Service a31ea6
        if (!ctxt->replaceEntities) {
Packit Service a31ea6
	    dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend);
Packit Service a31ea6
	    if (dup == NULL) {
Packit Service a31ea6
	        if (*valueend == 0) {
Packit Service a31ea6
		    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
				    ctxt->myDoc, ctxt->node, ret, value);
Packit Service a31ea6
		} else {
Packit Service a31ea6
		    /*
Packit Service a31ea6
		     * That should already be normalized.
Packit Service a31ea6
		     * cheaper to finally allocate here than duplicate
Packit Service a31ea6
		     * entry points in the full validation code
Packit Service a31ea6
		     */
Packit Service a31ea6
		    dup = xmlStrndup(value, valueend - value);
Packit Service a31ea6
Packit Service a31ea6
		    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
				    ctxt->myDoc, ctxt->node, ret, dup);
Packit Service a31ea6
		}
Packit Service a31ea6
	    } else {
Packit Service a31ea6
	        /*
Packit Service a31ea6
		 * dup now contains a string of the flattened attribute
Packit Service a31ea6
		 * content with entities substitued. Check if we need to
Packit Service a31ea6
		 * apply an extra layer of normalization.
Packit Service a31ea6
		 * It need to be done twice ... it's an extra burden related
Packit Service a31ea6
		 * to the ability to keep references in attributes
Packit Service a31ea6
		 */
Packit Service a31ea6
		if (ctxt->attsSpecial != NULL) {
Packit Service a31ea6
		    xmlChar *nvalnorm;
Packit Service a31ea6
		    xmlChar fn[50];
Packit Service a31ea6
		    xmlChar *fullname;
Packit Service a31ea6
Packit Service a31ea6
		    fullname = xmlBuildQName(localname, prefix, fn, 50);
Packit Service a31ea6
		    if (fullname != NULL) {
Packit Service a31ea6
			ctxt->vctxt.valid = 1;
Packit Service a31ea6
		        nvalnorm = xmlValidCtxtNormalizeAttributeValue(
Packit Service a31ea6
			                 &ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
					 ctxt->node, fullname, dup);
Packit Service a31ea6
			if (ctxt->vctxt.valid != 1)
Packit Service a31ea6
			    ctxt->valid = 0;
Packit Service a31ea6
Packit Service a31ea6
			if ((fullname != fn) && (fullname != localname))
Packit Service a31ea6
			    xmlFree(fullname);
Packit Service a31ea6
			if (nvalnorm != NULL) {
Packit Service a31ea6
			    xmlFree(dup);
Packit Service a31ea6
			    dup = nvalnorm;
Packit Service a31ea6
			}
Packit Service a31ea6
		    }
Packit Service a31ea6
		}
Packit Service a31ea6
Packit Service a31ea6
		ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
			        ctxt->myDoc, ctxt->node, ret, dup);
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * if entities already have been substitued, then
Packit Service a31ea6
	     * the attribute as passed is already normalized
Packit Service a31ea6
	     */
Packit Service a31ea6
	    dup = xmlStrndup(value, valueend - value);
Packit Service a31ea6
Packit Service a31ea6
	    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
Packit Service a31ea6
	                             ctxt->myDoc, ctxt->node, ret, dup);
Packit Service a31ea6
	}
Packit Service a31ea6
    } else
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
Packit Service a31ea6
	       (((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
Packit Service a31ea6
	        ((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) {
Packit Service a31ea6
        /*
Packit Service a31ea6
	 * when validating, the ID registration is done at the attribute
Packit Service a31ea6
	 * validation level. Otherwise we have to do specific handling here.
Packit Service a31ea6
	 */
Packit Service a31ea6
        if ((prefix == ctxt->str_xml) &&
Packit Service a31ea6
	           (localname[0] == 'i') && (localname[1] == 'd') &&
Packit Service a31ea6
		   (localname[2] == 0)) {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * Add the xml:id value
Packit Service a31ea6
	     *
Packit Service a31ea6
	     * Open issue: normalization of the value.
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if (dup == NULL)
Packit Service a31ea6
	        dup = xmlStrndup(value, valueend - value);
Packit Service a31ea6
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED)
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
	    if (xmlValidateNCName(dup, 1) != 0) {
Packit Service a31ea6
	        xmlErrValid(ctxt, XML_DTD_XMLID_VALUE,
Packit Service a31ea6
		      "xml:id : attribute value %s is not an NCName\n",
Packit Service a31ea6
			    (const char *) dup, NULL);
Packit Service a31ea6
	    }
Packit Service a31ea6
#endif
Packit Service a31ea6
#endif
Packit Service a31ea6
	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
Packit Service a31ea6
	} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) {
Packit Service a31ea6
	    /* might be worth duplicate entry points and not copy */
Packit Service a31ea6
	    if (dup == NULL)
Packit Service a31ea6
	        dup = xmlStrndup(value, valueend - value);
Packit Service a31ea6
	    xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
Packit Service a31ea6
	} else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) {
Packit Service a31ea6
	    if (dup == NULL)
Packit Service a31ea6
	        dup = xmlStrndup(value, valueend - value);
Packit Service a31ea6
	    xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (dup != NULL)
Packit Service a31ea6
	xmlFree(dup);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2StartElementNs:
Packit Service a31ea6
 * @ctx:  the user data (XML parser context)
Packit Service a31ea6
 * @localname:  the local name of the element
Packit Service a31ea6
 * @prefix:  the element namespace prefix if available
Packit Service a31ea6
 * @URI:  the element namespace name if available
Packit Service a31ea6
 * @nb_namespaces:  number of namespace definitions on that node
Packit Service a31ea6
 * @namespaces:  pointer to the array of prefix/URI pairs namespace definitions
Packit Service a31ea6
 * @nb_attributes:  the number of attributes on that node
Packit Service a31ea6
 * @nb_defaulted:  the number of defaulted attributes.
Packit Service a31ea6
 * @attributes:  pointer to the array of (localname/prefix/URI/value/end)
Packit Service a31ea6
 *               attribute values.
Packit Service a31ea6
 *
Packit Service a31ea6
 * SAX2 callback when an element start has been detected by the parser.
Packit Service a31ea6
 * It provides the namespace informations for the element, as well as
Packit Service a31ea6
 * the new namespace declarations on the element.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2StartElementNs(void *ctx,
Packit Service a31ea6
                      const xmlChar *localname,
Packit Service a31ea6
		      const xmlChar *prefix,
Packit Service a31ea6
		      const xmlChar *URI,
Packit Service a31ea6
		      int nb_namespaces,
Packit Service a31ea6
		      const xmlChar **namespaces,
Packit Service a31ea6
		      int nb_attributes,
Packit Service a31ea6
		      int nb_defaulted,
Packit Service a31ea6
		      const xmlChar **attributes)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
    xmlNodePtr parent;
Packit Service a31ea6
    xmlNsPtr last = NULL, ns;
Packit Service a31ea6
    const xmlChar *uri, *pref;
Packit Service a31ea6
    xmlChar *lname = NULL;
Packit Service a31ea6
    int i, j;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
    parent = ctxt->node;
Packit Service a31ea6
    /*
Packit Service a31ea6
     * First check on validity:
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
Packit Service a31ea6
        ((ctxt->myDoc->intSubset == NULL) ||
Packit Service a31ea6
	 ((ctxt->myDoc->intSubset->notations == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->elements == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->attributes == NULL) &&
Packit Service a31ea6
	  (ctxt->myDoc->intSubset->entities == NULL)))) {
Packit Service a31ea6
	xmlErrValid(ctxt, XML_DTD_NO_DTD,
Packit Service a31ea6
	  "Validation failed: no DTD found !", NULL, NULL);
Packit Service a31ea6
	ctxt->validate = 0;
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Take care of the rare case of an undefined namespace prefix
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((prefix != NULL) && (URI == NULL)) {
Packit Service a31ea6
        if (ctxt->dictNames) {
Packit Service a31ea6
	    const xmlChar *fullname;
Packit Service a31ea6
Packit Service a31ea6
	    fullname = xmlDictQLookup(ctxt->dict, prefix, localname);
Packit Service a31ea6
	    if (fullname != NULL)
Packit Service a31ea6
	        localname = fullname;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    lname = xmlBuildQName(localname, prefix, NULL, 0);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * allocate the node
Packit Service a31ea6
     */
Packit Service a31ea6
    if (ctxt->freeElems != NULL) {
Packit Service a31ea6
        ret = ctxt->freeElems;
Packit Service a31ea6
	ctxt->freeElems = ret->next;
Packit Service a31ea6
	ctxt->freeElemsNr--;
Packit Service a31ea6
	memset(ret, 0, sizeof(xmlNode));
Packit Service a31ea6
	ret->type = XML_ELEMENT_NODE;
Packit Service a31ea6
Packit Service a31ea6
	if (ctxt->dictNames)
Packit Service a31ea6
	    ret->name = localname;
Packit Service a31ea6
	else {
Packit Service a31ea6
	    if (lname == NULL)
Packit Service a31ea6
		ret->name = xmlStrdup(localname);
Packit Service a31ea6
	    else
Packit Service a31ea6
	        ret->name = lname;
Packit Service a31ea6
	    if (ret->name == NULL) {
Packit Service a31ea6
	        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
Packit Service a31ea6
		return;
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
	if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
Packit Service a31ea6
	    xmlRegisterNodeDefaultValue(ret);
Packit Service a31ea6
    } else {
Packit Service a31ea6
	if (ctxt->dictNames)
Packit Service a31ea6
	    ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
Packit Service a31ea6
	                               (xmlChar *) localname, NULL);
Packit Service a31ea6
	else if (lname == NULL)
Packit Service a31ea6
	    ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
Packit Service a31ea6
	else
Packit Service a31ea6
	    ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
Packit Service a31ea6
	                               (xmlChar *) lname, NULL);
Packit Service a31ea6
	if (ret == NULL) {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->linenumbers) {
Packit Service a31ea6
	if (ctxt->input != NULL) {
Packit Service a31ea6
	    if (ctxt->input->line < 65535)
Packit Service a31ea6
		ret->line = (short) ctxt->input->line;
Packit Service a31ea6
	    else
Packit Service a31ea6
	        ret->line = 65535;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (parent == NULL) {
Packit Service a31ea6
        xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
Packit Service a31ea6
    }
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Build the namespace list
Packit Service a31ea6
     */
Packit Service a31ea6
    for (i = 0,j = 0;j < nb_namespaces;j++) {
Packit Service a31ea6
        pref = namespaces[i++];
Packit Service a31ea6
	uri = namespaces[i++];
Packit Service a31ea6
	ns = xmlNewNs(NULL, uri, pref);
Packit Service a31ea6
	if (ns != NULL) {
Packit Service a31ea6
	    if (last == NULL) {
Packit Service a31ea6
	        ret->nsDef = last = ns;
Packit Service a31ea6
	    } else {
Packit Service a31ea6
	        last->next = ns;
Packit Service a31ea6
		last = ns;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if ((URI != NULL) && (prefix == pref))
Packit Service a31ea6
		ret->ns = ns;
Packit Service a31ea6
	} else {
Packit Service a31ea6
            /*
Packit Service a31ea6
             * any out of memory error would already have been raised
Packit Service a31ea6
             * but we can't be guaranteed it's the actual error due to the
Packit Service a31ea6
             * API, best is to skip in this case
Packit Service a31ea6
             */
Packit Service a31ea6
	    continue;
Packit Service a31ea6
	}
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
	if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
	    ctxt->myDoc && ctxt->myDoc->intSubset) {
Packit Service a31ea6
	    ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
Packit Service a31ea6
	                                           ret, prefix, ns, uri);
Packit Service a31ea6
	}
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nodemem = -1;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * We are parsing a new node.
Packit Service a31ea6
     */
Packit Service a31ea6
    nodePush(ctxt, ret);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Link the child element
Packit Service a31ea6
     */
Packit Service a31ea6
    if (parent != NULL) {
Packit Service a31ea6
        if (parent->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
	    xmlAddChild(parent, ret);
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlAddSibling(parent, ret);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Insert the defaulted attributes from the DTD only if requested:
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((nb_defaulted != 0) &&
Packit Service a31ea6
        ((ctxt->loadsubset & XML_COMPLETE_ATTRS) == 0))
Packit Service a31ea6
	nb_attributes -= nb_defaulted;
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Search the namespace if it wasn't already found
Packit Service a31ea6
     * Note that, if prefix is NULL, this searches for the default Ns
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((URI != NULL) && (ret->ns == NULL)) {
Packit Service a31ea6
        ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
Packit Service a31ea6
	if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
Packit Service a31ea6
	    ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
Packit Service a31ea6
	}
Packit Service a31ea6
	if (ret->ns == NULL) {
Packit Service a31ea6
	    ns = xmlNewNs(ret, NULL, prefix);
Packit Service a31ea6
	    if (ns == NULL) {
Packit Service a31ea6
Packit Service a31ea6
	        xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
Packit Service a31ea6
		return;
Packit Service a31ea6
	    }
Packit Service a31ea6
            if (prefix != NULL)
Packit Service a31ea6
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
Packit Service a31ea6
                             "Namespace prefix %s was not found\n",
Packit Service a31ea6
                             prefix, NULL);
Packit Service a31ea6
            else
Packit Service a31ea6
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
Packit Service a31ea6
                             "Namespace default prefix was not found\n",
Packit Service a31ea6
                             NULL, NULL);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * process all the other attributes
Packit Service a31ea6
     */
Packit Service a31ea6
    if (nb_attributes > 0) {
Packit Service a31ea6
        for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * Handle the rare case of an undefined atribute prefix
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {
Packit Service a31ea6
		if (ctxt->dictNames) {
Packit Service a31ea6
		    const xmlChar *fullname;
Packit Service a31ea6
Packit Service a31ea6
		    fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],
Packit Service a31ea6
		                              attributes[j]);
Packit Service a31ea6
		    if (fullname != NULL) {
Packit Service a31ea6
			xmlSAX2AttributeNs(ctxt, fullname, NULL,
Packit Service a31ea6
			                   attributes[j+3], attributes[j+4]);
Packit Service a31ea6
		        continue;
Packit Service a31ea6
		    }
Packit Service a31ea6
		} else {
Packit Service a31ea6
		    lname = xmlBuildQName(attributes[j], attributes[j+1],
Packit Service a31ea6
		                          NULL, 0);
Packit Service a31ea6
		    if (lname != NULL) {
Packit Service a31ea6
			xmlSAX2AttributeNs(ctxt, lname, NULL,
Packit Service a31ea6
			                   attributes[j+3], attributes[j+4]);
Packit Service a31ea6
			xmlFree(lname);
Packit Service a31ea6
		        continue;
Packit Service a31ea6
		    }
Packit Service a31ea6
		}
Packit Service a31ea6
	    }
Packit Service a31ea6
	    xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],
Packit Service a31ea6
			       attributes[j+3], attributes[j+4]);
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    /*
Packit Service a31ea6
     * If it's the Document root, finish the DTD validation and
Packit Service a31ea6
     * check the document root element for validity
Packit Service a31ea6
     */
Packit Service a31ea6
    if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) {
Packit Service a31ea6
	int chk;
Packit Service a31ea6
Packit Service a31ea6
	chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
Packit Service a31ea6
	if (chk <= 0)
Packit Service a31ea6
	    ctxt->valid = 0;
Packit Service a31ea6
	if (chk < 0)
Packit Service a31ea6
	    ctxt->wellFormed = 0;
Packit Service a31ea6
	ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
Packit Service a31ea6
	ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1;
Packit Service a31ea6
    }
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2EndElementNs:
Packit Service a31ea6
 * @ctx:  the user data (XML parser context)
Packit Service a31ea6
 * @localname:  the local name of the element
Packit Service a31ea6
 * @prefix:  the element namespace prefix if available
Packit Service a31ea6
 * @URI:  the element namespace name if available
Packit Service a31ea6
 *
Packit Service a31ea6
 * SAX2 callback when an element end has been detected by the parser.
Packit Service a31ea6
 * It provides the namespace informations for the element.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2EndElementNs(void *ctx,
Packit Service a31ea6
                    const xmlChar * localname ATTRIBUTE_UNUSED,
Packit Service a31ea6
                    const xmlChar * prefix ATTRIBUTE_UNUSED,
Packit Service a31ea6
		    const xmlChar * URI ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlParserNodeInfo node_info;
Packit Service a31ea6
    xmlNodePtr cur;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
    cur = ctxt->node;
Packit Service a31ea6
    /* Capture end position and add node */
Packit Service a31ea6
    if ((ctxt->record_info) && (cur != NULL)) {
Packit Service a31ea6
        node_info.end_pos = ctxt->input->cur - ctxt->input->base;
Packit Service a31ea6
        node_info.end_line = ctxt->input->line;
Packit Service a31ea6
        node_info.node = cur;
Packit Service a31ea6
        xmlParserAddNodeInfo(ctxt, &node_info);
Packit Service a31ea6
    }
Packit Service a31ea6
    ctxt->nodemem = -1;
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_VALID_ENABLED
Packit Service a31ea6
    if (ctxt->validate && ctxt->wellFormed &&
Packit Service a31ea6
        ctxt->myDoc && ctxt->myDoc->intSubset)
Packit Service a31ea6
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, cur);
Packit Service a31ea6
#endif /* LIBXML_VALID_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * end of parsing of this node.
Packit Service a31ea6
     */
Packit Service a31ea6
    nodePop(ctxt);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2Reference:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @name:  The entity name
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when an entity xmlSAX2Reference is detected.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2Reference(void *ctx, const xmlChar *name)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2Reference(%s)\n", name);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (name[0] == '#')
Packit Service a31ea6
	ret = xmlNewCharRef(ctxt->myDoc, name);
Packit Service a31ea6
    else
Packit Service a31ea6
	ret = xmlNewReference(ctxt->myDoc, name);
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "add xmlSAX2Reference %s to %s \n", name, ctxt->node->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if (xmlAddChild(ctxt->node, ret) == NULL) {
Packit Service a31ea6
        xmlFreeNode(ret);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2Characters:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @ch:  a xmlChar string
Packit Service a31ea6
 * @len: the number of xmlChar
Packit Service a31ea6
 *
Packit Service a31ea6
 * receiving some chars from the parser.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr lastChild;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2Characters(%.30s, %d)\n", ch, len);
Packit Service a31ea6
#endif
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Handle the data if any. If there is no child
Packit Service a31ea6
     * add it as content, otherwise if the last child is text,
Packit Service a31ea6
     * concatenate it, else create a new node of type text.
Packit Service a31ea6
     */
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->node == NULL) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"add chars: ctxt->node == NULL !\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
        return;
Packit Service a31ea6
    }
Packit Service a31ea6
    lastChild = ctxt->node->last;
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "add chars to %s \n", ctxt->node->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Here we needed an accelerator mechanism in case of very large
Packit Service a31ea6
     * elements. Use an attribute in the structure !!!
Packit Service a31ea6
     */
Packit Service a31ea6
    if (lastChild == NULL) {
Packit Service a31ea6
        lastChild = xmlSAX2TextNode(ctxt, ch, len);
Packit Service a31ea6
	if (lastChild != NULL) {
Packit Service a31ea6
	    ctxt->node->children = lastChild;
Packit Service a31ea6
	    ctxt->node->last = lastChild;
Packit Service a31ea6
	    lastChild->parent = ctxt->node;
Packit Service a31ea6
	    lastChild->doc = ctxt->node->doc;
Packit Service a31ea6
	    ctxt->nodelen = len;
Packit Service a31ea6
	    ctxt->nodemem = len + 1;
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
Packit Service a31ea6
	    return;
Packit Service a31ea6
	}
Packit Service a31ea6
    } else {
Packit Service a31ea6
	int coalesceText = (lastChild != NULL) &&
Packit Service a31ea6
	    (lastChild->type == XML_TEXT_NODE) &&
Packit Service a31ea6
	    (lastChild->name == xmlStringText);
Packit Service a31ea6
	if ((coalesceText) && (ctxt->nodemem != 0)) {
Packit Service a31ea6
	    /*
Packit Service a31ea6
	     * The whole point of maintaining nodelen and nodemem,
Packit Service a31ea6
	     * xmlTextConcat is too costly, i.e. compute length,
Packit Service a31ea6
	     * reallocate a new buffer, move data, append ch. Here
Packit Service a31ea6
	     * We try to minimaze realloc() uses and avoid copying
Packit Service a31ea6
	     * and recomputing length over and over.
Packit Service a31ea6
	     */
Packit Service a31ea6
	    if (lastChild->content == (xmlChar *)&(lastChild->properties)) {
Packit Service a31ea6
		lastChild->content = xmlStrdup(lastChild->content);
Packit Service a31ea6
		lastChild->properties = NULL;
Packit Service a31ea6
	    } else if ((ctxt->nodemem == ctxt->nodelen + 1) &&
Packit Service a31ea6
	               (xmlDictOwns(ctxt->dict, lastChild->content))) {
Packit Service a31ea6
		lastChild->content = xmlStrdup(lastChild->content);
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (lastChild->content == NULL) {
Packit Service a31ea6
		xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: xmlStrdup returned NULL");
Packit Service a31ea6
		return;
Packit Service a31ea6
 	    }
Packit Service a31ea6
            if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) &&
Packit Service a31ea6
                ((ctxt->options & XML_PARSE_HUGE) == 0)) {
Packit Service a31ea6
                xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node");
Packit Service a31ea6
                return;
Packit Service a31ea6
            }
Packit Service a31ea6
	    if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len ||
Packit Service a31ea6
	        (size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) {
Packit Service a31ea6
                xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
Packit Service a31ea6
                return;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (ctxt->nodelen + len >= ctxt->nodemem) {
Packit Service a31ea6
		xmlChar *newbuf;
Packit Service a31ea6
		size_t size;
Packit Service a31ea6
Packit Service a31ea6
		size = ctxt->nodemem + len;
Packit Service a31ea6
		size *= 2;
Packit Service a31ea6
                newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
Packit Service a31ea6
		if (newbuf == NULL) {
Packit Service a31ea6
		    xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
Packit Service a31ea6
		    return;
Packit Service a31ea6
		}
Packit Service a31ea6
		ctxt->nodemem = size;
Packit Service a31ea6
		lastChild->content = newbuf;
Packit Service a31ea6
	    }
Packit Service a31ea6
	    memcpy(&lastChild->content[ctxt->nodelen], ch, len);
Packit Service a31ea6
	    ctxt->nodelen += len;
Packit Service a31ea6
	    lastChild->content[ctxt->nodelen] = 0;
Packit Service a31ea6
	} else if (coalesceText) {
Packit Service a31ea6
	    if (xmlTextConcat(lastChild, ch, len)) {
Packit Service a31ea6
		xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
Packit Service a31ea6
	    }
Packit Service a31ea6
	    if (ctxt->node->children != NULL) {
Packit Service a31ea6
		ctxt->nodelen = xmlStrlen(lastChild->content);
Packit Service a31ea6
		ctxt->nodemem = ctxt->nodelen + 1;
Packit Service a31ea6
	    }
Packit Service a31ea6
	} else {
Packit Service a31ea6
	    /* Mixed content, first time */
Packit Service a31ea6
	    lastChild = xmlSAX2TextNode(ctxt, ch, len);
Packit Service a31ea6
	    if (lastChild != NULL) {
Packit Service a31ea6
		xmlAddChild(ctxt->node, lastChild);
Packit Service a31ea6
		if (ctxt->node->children != NULL) {
Packit Service a31ea6
		    ctxt->nodelen = len;
Packit Service a31ea6
		    ctxt->nodemem = len + 1;
Packit Service a31ea6
		}
Packit Service a31ea6
	    }
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2IgnorableWhitespace:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @ch:  a xmlChar string
Packit Service a31ea6
 * @len: the number of xmlChar
Packit Service a31ea6
 *
Packit Service a31ea6
 * receiving some ignorable whitespaces from the parser.
Packit Service a31ea6
 * UNUSED: by default the DOM building will use xmlSAX2Characters
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
Packit Service a31ea6
{
Packit Service a31ea6
    /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2IgnorableWhitespace(%.30s, %d)\n", ch, len);
Packit Service a31ea6
#endif
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2ProcessingInstruction:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @target:  the target name
Packit Service a31ea6
 * @data: the PI data's
Packit Service a31ea6
 *
Packit Service a31ea6
 * A processing instruction has been parsed.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
Packit Service a31ea6
                      const xmlChar *data)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
    xmlNodePtr parent;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
    parent = ctxt->node;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data);
Packit Service a31ea6
#endif
Packit Service a31ea6
Packit Service a31ea6
    ret = xmlNewDocPI(ctxt->myDoc, target, data);
Packit Service a31ea6
    if (ret == NULL) return;
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->linenumbers) {
Packit Service a31ea6
	if (ctxt->input != NULL) {
Packit Service a31ea6
	    if (ctxt->input->line < 65535)
Packit Service a31ea6
		ret->line = (short) ctxt->input->line;
Packit Service a31ea6
	    else
Packit Service a31ea6
	        ret->line = 65535;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
    if (ctxt->inSubset == 1) {
Packit Service a31ea6
	xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    } else if (ctxt->inSubset == 2) {
Packit Service a31ea6
	xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (parent == NULL) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "Setting PI %s as root\n", target);
Packit Service a31ea6
#endif
Packit Service a31ea6
        xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (parent->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"adding PI %s child to %s\n", target, parent->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
	xmlAddChild(parent, ret);
Packit Service a31ea6
    } else {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"adding PI %s sibling to ", target);
Packit Service a31ea6
	xmlDebugDumpOneNode(stderr, parent, 0);
Packit Service a31ea6
#endif
Packit Service a31ea6
	xmlAddSibling(parent, ret);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2Comment:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @value:  the xmlSAX2Comment content
Packit Service a31ea6
 *
Packit Service a31ea6
 * A xmlSAX2Comment has been parsed.
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2Comment(void *ctx, const xmlChar *value)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret;
Packit Service a31ea6
    xmlNodePtr parent;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
    parent = ctxt->node;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2Comment(%s)\n", value);
Packit Service a31ea6
#endif
Packit Service a31ea6
    ret = xmlNewDocComment(ctxt->myDoc, value);
Packit Service a31ea6
    if (ret == NULL) return;
Packit Service a31ea6
    if (ctxt->linenumbers) {
Packit Service a31ea6
	if (ctxt->input != NULL) {
Packit Service a31ea6
	    if (ctxt->input->line < 65535)
Packit Service a31ea6
		ret->line = (short) ctxt->input->line;
Packit Service a31ea6
	    else
Packit Service a31ea6
	        ret->line = 65535;
Packit Service a31ea6
	}
Packit Service a31ea6
    }
Packit Service a31ea6
Packit Service a31ea6
    if (ctxt->inSubset == 1) {
Packit Service a31ea6
	xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    } else if (ctxt->inSubset == 2) {
Packit Service a31ea6
	xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (parent == NULL) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		    "Setting xmlSAX2Comment as root\n");
Packit Service a31ea6
#endif
Packit Service a31ea6
        xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    if (parent->type == XML_ELEMENT_NODE) {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"adding xmlSAX2Comment child to %s\n", parent->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
	xmlAddChild(parent, ret);
Packit Service a31ea6
    } else {
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
	xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
		"adding xmlSAX2Comment sibling to ");
Packit Service a31ea6
	xmlDebugDumpOneNode(stderr, parent, 0);
Packit Service a31ea6
#endif
Packit Service a31ea6
	xmlAddSibling(parent, ret);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2CDataBlock:
Packit Service a31ea6
 * @ctx: the user data (XML parser context)
Packit Service a31ea6
 * @value:  The pcdata content
Packit Service a31ea6
 * @len:  the block length
Packit Service a31ea6
 *
Packit Service a31ea6
 * called when a pcdata block has been parsed
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
Packit Service a31ea6
    xmlNodePtr ret, lastChild;
Packit Service a31ea6
Packit Service a31ea6
    if (ctx == NULL) return;
Packit Service a31ea6
#ifdef DEBUG_SAX
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "SAX.pcdata(%.10s, %d)\n", value, len);
Packit Service a31ea6
#endif
Packit Service a31ea6
    lastChild = xmlGetLastChild(ctxt->node);
Packit Service a31ea6
#ifdef DEBUG_SAX_TREE
Packit Service a31ea6
    xmlGenericError(xmlGenericErrorContext,
Packit Service a31ea6
	    "add chars to %s \n", ctxt->node->name);
Packit Service a31ea6
#endif
Packit Service a31ea6
    if ((lastChild != NULL) &&
Packit Service a31ea6
        (lastChild->type == XML_CDATA_SECTION_NODE)) {
Packit Service a31ea6
	xmlTextConcat(lastChild, value, len);
Packit Service a31ea6
    } else {
Packit Service a31ea6
	ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
Packit Service a31ea6
	if (xmlAddChild(ctxt->node, ret) == NULL)
Packit Service a31ea6
		xmlFreeNode(ret);
Packit Service a31ea6
    }
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
static int xmlSAX2DefaultVersionValue = 2;
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_SAX1_ENABLED
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAXDefaultVersion:
Packit Service a31ea6
 * @version:  the version, 1 or 2
Packit Service a31ea6
 *
Packit Service a31ea6
 * Set the default version of SAX used globally by the library.
Packit Service a31ea6
 * By default, during initialization the default is set to 2.
Packit Service a31ea6
 * Note that it is generally a better coding style to use
Packit Service a31ea6
 * xmlSAXVersion() to set up the version explicitly for a given
Packit Service a31ea6
 * parsing context.
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns the previous value in case of success and -1 in case of error.
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAXDefaultVersion(int version)
Packit Service a31ea6
{
Packit Service a31ea6
    int ret = xmlSAX2DefaultVersionValue;
Packit Service a31ea6
Packit Service a31ea6
    if ((version != 1) && (version != 2))
Packit Service a31ea6
        return(-1);
Packit Service a31ea6
    xmlSAX2DefaultVersionValue = version;
Packit Service a31ea6
    return(ret);
Packit Service a31ea6
}
Packit Service a31ea6
#endif /* LIBXML_SAX1_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAXVersion:
Packit Service a31ea6
 * @hdlr:  the SAX handler
Packit Service a31ea6
 * @version:  the version, 1 or 2
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default XML SAX handler according to the version
Packit Service a31ea6
 *
Packit Service a31ea6
 * Returns 0 in case of success and -1 in case of error.
Packit Service a31ea6
 */
Packit Service a31ea6
int
Packit Service a31ea6
xmlSAXVersion(xmlSAXHandler *hdlr, int version)
Packit Service a31ea6
{
Packit Service a31ea6
    if (hdlr == NULL) return(-1);
Packit Service a31ea6
    if (version == 2) {
Packit Service a31ea6
	hdlr->startElement = NULL;
Packit Service a31ea6
	hdlr->endElement = NULL;
Packit Service a31ea6
	hdlr->startElementNs = xmlSAX2StartElementNs;
Packit Service a31ea6
	hdlr->endElementNs = xmlSAX2EndElementNs;
Packit Service a31ea6
	hdlr->serror = NULL;
Packit Service a31ea6
	hdlr->initialized = XML_SAX2_MAGIC;
Packit Service a31ea6
#ifdef LIBXML_SAX1_ENABLED
Packit Service a31ea6
    } else if (version == 1) {
Packit Service a31ea6
	hdlr->startElement = xmlSAX2StartElement;
Packit Service a31ea6
	hdlr->endElement = xmlSAX2EndElement;
Packit Service a31ea6
	hdlr->initialized = 1;
Packit Service a31ea6
#endif /* LIBXML_SAX1_ENABLED */
Packit Service a31ea6
    } else
Packit Service a31ea6
        return(-1);
Packit Service a31ea6
    hdlr->internalSubset = xmlSAX2InternalSubset;
Packit Service a31ea6
    hdlr->externalSubset = xmlSAX2ExternalSubset;
Packit Service a31ea6
    hdlr->isStandalone = xmlSAX2IsStandalone;
Packit Service a31ea6
    hdlr->hasInternalSubset = xmlSAX2HasInternalSubset;
Packit Service a31ea6
    hdlr->hasExternalSubset = xmlSAX2HasExternalSubset;
Packit Service a31ea6
    hdlr->resolveEntity = xmlSAX2ResolveEntity;
Packit Service a31ea6
    hdlr->getEntity = xmlSAX2GetEntity;
Packit Service a31ea6
    hdlr->getParameterEntity = xmlSAX2GetParameterEntity;
Packit Service a31ea6
    hdlr->entityDecl = xmlSAX2EntityDecl;
Packit Service a31ea6
    hdlr->attributeDecl = xmlSAX2AttributeDecl;
Packit Service a31ea6
    hdlr->elementDecl = xmlSAX2ElementDecl;
Packit Service a31ea6
    hdlr->notationDecl = xmlSAX2NotationDecl;
Packit Service a31ea6
    hdlr->unparsedEntityDecl = xmlSAX2UnparsedEntityDecl;
Packit Service a31ea6
    hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
Packit Service a31ea6
    hdlr->startDocument = xmlSAX2StartDocument;
Packit Service a31ea6
    hdlr->endDocument = xmlSAX2EndDocument;
Packit Service a31ea6
    hdlr->reference = xmlSAX2Reference;
Packit Service a31ea6
    hdlr->characters = xmlSAX2Characters;
Packit Service a31ea6
    hdlr->cdataBlock = xmlSAX2CDataBlock;
Packit Service a31ea6
    hdlr->ignorableWhitespace = xmlSAX2Characters;
Packit Service a31ea6
    hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
Packit Service a31ea6
    hdlr->comment = xmlSAX2Comment;
Packit Service a31ea6
    hdlr->warning = xmlParserWarning;
Packit Service a31ea6
    hdlr->error = xmlParserError;
Packit Service a31ea6
    hdlr->fatalError = xmlParserError;
Packit Service a31ea6
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2InitDefaultSAXHandler:
Packit Service a31ea6
 * @hdlr:  the SAX handler
Packit Service a31ea6
 * @warning:  flag if non-zero sets the handler warning procedure
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default XML SAX2 handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2InitDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((hdlr == NULL) || (hdlr->initialized != 0))
Packit Service a31ea6
	return;
Packit Service a31ea6
Packit Service a31ea6
    xmlSAXVersion(hdlr, xmlSAX2DefaultVersionValue);
Packit Service a31ea6
    if (warning == 0)
Packit Service a31ea6
	hdlr->warning = NULL;
Packit Service a31ea6
    else
Packit Service a31ea6
	hdlr->warning = xmlParserWarning;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlDefaultSAXHandlerInit:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default SAX2 handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlDefaultSAXHandlerInit(void)
Packit Service a31ea6
{
Packit Service a31ea6
#ifdef LIBXML_SAX1_ENABLED
Packit Service a31ea6
    xmlSAXVersion((xmlSAXHandlerPtr) &xmlDefaultSAXHandler, 1);
Packit Service a31ea6
#endif /* LIBXML_SAX1_ENABLED */
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_HTML_ENABLED
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2InitHtmlDefaultSAXHandler:
Packit Service a31ea6
 * @hdlr:  the SAX handler
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default HTML SAX2 handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((hdlr == NULL) || (hdlr->initialized != 0))
Packit Service a31ea6
	return;
Packit Service a31ea6
Packit Service a31ea6
    hdlr->internalSubset = xmlSAX2InternalSubset;
Packit Service a31ea6
    hdlr->externalSubset = NULL;
Packit Service a31ea6
    hdlr->isStandalone = NULL;
Packit Service a31ea6
    hdlr->hasInternalSubset = NULL;
Packit Service a31ea6
    hdlr->hasExternalSubset = NULL;
Packit Service a31ea6
    hdlr->resolveEntity = NULL;
Packit Service a31ea6
    hdlr->getEntity = xmlSAX2GetEntity;
Packit Service a31ea6
    hdlr->getParameterEntity = NULL;
Packit Service a31ea6
    hdlr->entityDecl = NULL;
Packit Service a31ea6
    hdlr->attributeDecl = NULL;
Packit Service a31ea6
    hdlr->elementDecl = NULL;
Packit Service a31ea6
    hdlr->notationDecl = NULL;
Packit Service a31ea6
    hdlr->unparsedEntityDecl = NULL;
Packit Service a31ea6
    hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
Packit Service a31ea6
    hdlr->startDocument = xmlSAX2StartDocument;
Packit Service a31ea6
    hdlr->endDocument = xmlSAX2EndDocument;
Packit Service a31ea6
    hdlr->startElement = xmlSAX2StartElement;
Packit Service a31ea6
    hdlr->endElement = xmlSAX2EndElement;
Packit Service a31ea6
    hdlr->reference = NULL;
Packit Service a31ea6
    hdlr->characters = xmlSAX2Characters;
Packit Service a31ea6
    hdlr->cdataBlock = xmlSAX2CDataBlock;
Packit Service a31ea6
    hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
Packit Service a31ea6
    hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
Packit Service a31ea6
    hdlr->comment = xmlSAX2Comment;
Packit Service a31ea6
    hdlr->warning = xmlParserWarning;
Packit Service a31ea6
    hdlr->error = xmlParserError;
Packit Service a31ea6
    hdlr->fatalError = xmlParserError;
Packit Service a31ea6
Packit Service a31ea6
    hdlr->initialized = 1;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * htmlDefaultSAXHandlerInit:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default SAX handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
htmlDefaultSAXHandlerInit(void)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlSAX2InitHtmlDefaultSAXHandler((xmlSAXHandlerPtr) &htmlDefaultSAXHandler);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#endif /* LIBXML_HTML_ENABLED */
Packit Service a31ea6
Packit Service a31ea6
#ifdef LIBXML_DOCB_ENABLED
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * xmlSAX2InitDocbDefaultSAXHandler:
Packit Service a31ea6
 * @hdlr:  the SAX handler
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default DocBook SAX2 handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr)
Packit Service a31ea6
{
Packit Service a31ea6
    if ((hdlr == NULL) || (hdlr->initialized != 0))
Packit Service a31ea6
	return;
Packit Service a31ea6
Packit Service a31ea6
    hdlr->internalSubset = xmlSAX2InternalSubset;
Packit Service a31ea6
    hdlr->externalSubset = NULL;
Packit Service a31ea6
    hdlr->isStandalone = xmlSAX2IsStandalone;
Packit Service a31ea6
    hdlr->hasInternalSubset = xmlSAX2HasInternalSubset;
Packit Service a31ea6
    hdlr->hasExternalSubset = xmlSAX2HasExternalSubset;
Packit Service a31ea6
    hdlr->resolveEntity = xmlSAX2ResolveEntity;
Packit Service a31ea6
    hdlr->getEntity = xmlSAX2GetEntity;
Packit Service a31ea6
    hdlr->getParameterEntity = NULL;
Packit Service a31ea6
    hdlr->entityDecl = xmlSAX2EntityDecl;
Packit Service a31ea6
    hdlr->attributeDecl = NULL;
Packit Service a31ea6
    hdlr->elementDecl = NULL;
Packit Service a31ea6
    hdlr->notationDecl = NULL;
Packit Service a31ea6
    hdlr->unparsedEntityDecl = NULL;
Packit Service a31ea6
    hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
Packit Service a31ea6
    hdlr->startDocument = xmlSAX2StartDocument;
Packit Service a31ea6
    hdlr->endDocument = xmlSAX2EndDocument;
Packit Service a31ea6
    hdlr->startElement = xmlSAX2StartElement;
Packit Service a31ea6
    hdlr->endElement = xmlSAX2EndElement;
Packit Service a31ea6
    hdlr->reference = xmlSAX2Reference;
Packit Service a31ea6
    hdlr->characters = xmlSAX2Characters;
Packit Service a31ea6
    hdlr->cdataBlock = NULL;
Packit Service a31ea6
    hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
Packit Service a31ea6
    hdlr->processingInstruction = NULL;
Packit Service a31ea6
    hdlr->comment = xmlSAX2Comment;
Packit Service a31ea6
    hdlr->warning = xmlParserWarning;
Packit Service a31ea6
    hdlr->error = xmlParserError;
Packit Service a31ea6
    hdlr->fatalError = xmlParserError;
Packit Service a31ea6
Packit Service a31ea6
    hdlr->initialized = 1;
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * docbDefaultSAXHandlerInit:
Packit Service a31ea6
 *
Packit Service a31ea6
 * Initialize the default SAX handler
Packit Service a31ea6
 */
Packit Service a31ea6
void
Packit Service a31ea6
docbDefaultSAXHandlerInit(void)
Packit Service a31ea6
{
Packit Service a31ea6
    xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
#endif /* LIBXML_DOCB_ENABLED */
Packit Service a31ea6
#define bottom_SAX2
Packit Service a31ea6
#include "elfgcchack.h"