This source file includes following definitions.
- xmlSAX2ErrMemory
- xmlErrValid
- xmlFatalErrMsg
- xmlWarnMsg
- xmlNsErrMsg
- xmlNsWarnMsg
- xmlSAX2GetPublicId
- xmlSAX2GetSystemId
- xmlSAX2GetLineNumber
- xmlSAX2GetColumnNumber
- xmlSAX2IsStandalone
- xmlSAX2HasInternalSubset
- xmlSAX2HasExternalSubset
- xmlSAX2InternalSubset
- xmlSAX2ExternalSubset
- xmlSAX2ResolveEntity
- xmlSAX2GetEntity
- xmlSAX2GetParameterEntity
- xmlSAX2EntityDecl
- xmlSAX2AttributeDecl
- xmlSAX2ElementDecl
- xmlSAX2NotationDecl
- xmlSAX2UnparsedEntityDecl
- xmlSAX2SetDocumentLocator
- xmlSAX2StartDocument
- xmlSAX2EndDocument
- xmlSAX2AttributeInternal
- xmlCheckDefaultedAttributes
- xmlSAX2StartElement
- xmlSAX2EndElement
- xmlSAX2TextNode
- xmlSAX2DecodeAttrEntities
- xmlSAX2AttributeNs
- xmlSAX2StartElementNs
- xmlSAX2EndElementNs
- xmlSAX2Reference
- xmlSAX2Characters
- xmlSAX2IgnorableWhitespace
- xmlSAX2ProcessingInstruction
- xmlSAX2Comment
- xmlSAX2CDataBlock
- xmlSAXDefaultVersion
- xmlSAXVersion
- xmlSAX2InitDefaultSAXHandler
- xmlDefaultSAXHandlerInit
- xmlSAX2InitHtmlDefaultSAXHandler
- htmlDefaultSAXHandlerInit
- xmlSAX2InitDocbDefaultSAXHandler
- docbDefaultSAXHandlerInit
#define IN_LIBXML
#include "libxml.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/valid.h>
#include <libxml/entities.h>
#include <libxml/xmlerror.h>
#include <libxml/debugXML.h>
#include <libxml/xmlIO.h>
#include <libxml/SAX.h>
#include <libxml/uri.h>
#include <libxml/valid.h>
#include <libxml/HTMLtree.h>
#include <libxml/globals.h>
#ifndef SIZE_T_MAX
# define SIZE_T_MAX ((size_t)-1)
#endif
#define TODO \
xmlGenericError(xmlGenericErrorContext, \
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
static void
xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt, const char *msg) {
if (ctxt != NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData, "%s: out of memory\n", msg);
ctxt->errNo = XML_ERR_NO_MEMORY;
ctxt->instate = XML_PARSER_EOF;
ctxt->disableSAX = 1;
}
}
static void
xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const char *str1, const char *str2)
{
xmlStructuredErrorFunc schannel = NULL;
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
if (ctxt != NULL) {
ctxt->errNo = error;
if ((ctxt->sax != NULL) && (ctxt->sax->initialized == XML_SAX2_MAGIC))
schannel = ctxt->sax->serror;
__xmlRaiseError(schannel,
ctxt->vctxt.error, ctxt->vctxt.userData,
ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1,
(const char *) str2, NULL, 0, 0,
msg, (const char *) str1, (const char *) str2);
ctxt->valid = 0;
} else {
__xmlRaiseError(schannel,
NULL, NULL,
ctxt, NULL, XML_FROM_DTD, error,
XML_ERR_ERROR, NULL, 0, (const char *) str1,
(const char *) str2, NULL, 0, 0,
msg, (const char *) str1, (const char *) str2);
}
}
static void
xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1, const xmlChar *str2)
{
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_FATAL, NULL, 0,
(const char *) str1, (const char *) str2,
NULL, 0, 0, msg, str1, str2);
if (ctxt != NULL) {
ctxt->wellFormed = 0;
ctxt->valid = 0;
if (ctxt->recovery == 0)
ctxt->disableSAX = 1;
}
}
static void
xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1)
{
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
XML_ERR_WARNING, NULL, 0,
(const char *) str1, NULL,
NULL, 0, 0, msg, str1);
}
static void
xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1, const xmlChar *str2)
{
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str2,
NULL, 0, 0, msg, str1, str2);
}
static void
xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
const char *msg, const xmlChar *str1, const xmlChar *str2)
{
if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
(ctxt->instate == XML_PARSER_EOF))
return;
if (ctxt != NULL)
ctxt->errNo = error;
__xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error,
XML_ERR_WARNING, NULL, 0,
(const char *) str1, (const char *) str2,
NULL, 0, 0, msg, str1, str2);
}
const xmlChar *
xmlSAX2GetPublicId(void *ctx ATTRIBUTE_UNUSED)
{
return(NULL);
}
const xmlChar *
xmlSAX2GetSystemId(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL);
return((const xmlChar *) ctxt->input->filename);
}
int
xmlSAX2GetLineNumber(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
return(ctxt->input->line);
}
int
xmlSAX2GetColumnNumber(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
return(ctxt->input->col);
}
int
xmlSAX2IsStandalone(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctx == NULL) || (ctxt->myDoc == NULL)) return(0);
return(ctxt->myDoc->standalone == 1);
}
int
xmlSAX2HasInternalSubset(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
return(ctxt->myDoc->intSubset != NULL);
}
int
xmlSAX2HasExternalSubset(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
return(ctxt->myDoc->extSubset != NULL);
}
void
xmlSAX2InternalSubset(void *ctx, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlDtdPtr dtd;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2InternalSubset(%s, %s, %s)\n",
name, ExternalID, SystemID);
#endif
if (ctxt->myDoc == NULL)
return;
dtd = xmlGetIntSubset(ctxt->myDoc);
if (dtd != NULL) {
if (ctxt->html)
return;
xmlUnlinkNode((xmlNodePtr) dtd);
xmlFreeDtd(dtd);
ctxt->myDoc->intSubset = NULL;
}
ctxt->myDoc->intSubset =
xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID);
if (ctxt->myDoc->intSubset == NULL)
xmlSAX2ErrMemory(ctxt, "xmlSAX2InternalSubset");
}
void
xmlSAX2ExternalSubset(void *ctx, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2ExternalSubset(%s, %s, %s)\n",
name, ExternalID, SystemID);
#endif
if (((ExternalID != NULL) || (SystemID != NULL)) &&
(((ctxt->validate) || (ctxt->loadsubset != 0)) &&
(ctxt->wellFormed && ctxt->myDoc))) {
xmlParserInputPtr oldinput;
int oldinputNr;
int oldinputMax;
xmlParserInputPtr *oldinputTab;
xmlParserInputPtr input = NULL;
xmlCharEncoding enc;
int oldcharset;
if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID,
SystemID);
if (input == NULL) {
return;
}
xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID);
oldinput = ctxt->input;
oldinputNr = ctxt->inputNr;
oldinputMax = ctxt->inputMax;
oldinputTab = ctxt->inputTab;
oldcharset = ctxt->charset;
ctxt->inputTab = (xmlParserInputPtr *)
xmlMalloc(5 * sizeof(xmlParserInputPtr));
if (ctxt->inputTab == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2ExternalSubset");
ctxt->input = oldinput;
ctxt->inputNr = oldinputNr;
ctxt->inputMax = oldinputMax;
ctxt->inputTab = oldinputTab;
ctxt->charset = oldcharset;
return;
}
ctxt->inputNr = 0;
ctxt->inputMax = 5;
ctxt->input = NULL;
xmlPushInput(ctxt, input);
if (ctxt->input->length >= 4) {
enc = xmlDetectCharEncoding(ctxt->input->cur, 4);
xmlSwitchEncoding(ctxt, enc);
}
if (input->filename == NULL)
input->filename = (char *) xmlCanonicPath(SystemID);
input->line = 1;
input->col = 1;
input->base = ctxt->input->cur;
input->cur = ctxt->input->cur;
input->free = NULL;
xmlParseExternalSubset(ctxt, ExternalID, SystemID);
while (ctxt->inputNr > 1)
xmlPopInput(ctxt);
xmlFreeInputStream(ctxt->input);
xmlFree(ctxt->inputTab);
ctxt->input = oldinput;
ctxt->inputNr = oldinputNr;
ctxt->inputMax = oldinputMax;
ctxt->inputTab = oldinputTab;
ctxt->charset = oldcharset;
}
}
xmlParserInputPtr
xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr ret;
xmlChar *URI;
const char *base = NULL;
if (ctx == NULL) return(NULL);
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, (const xmlChar *) base);
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2ResolveEntity(%s, %s)\n", publicId, systemId);
#endif
ret = xmlLoadExternalEntity((const char *) URI,
(const char *) publicId, ctxt);
if (URI != NULL)
xmlFree(URI);
return(ret);
}
xmlEntityPtr
xmlSAX2GetEntity(void *ctx, const xmlChar *name)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlEntityPtr ret = NULL;
if (ctx == NULL) return(NULL);
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2GetEntity(%s)\n", name);
#endif
if (ctxt->inSubset == 0) {
ret = xmlGetPredefinedEntity(name);
if (ret != NULL)
return(ret);
}
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) {
if (ctxt->inSubset == 2) {
ctxt->myDoc->standalone = 0;
ret = xmlGetDocEntity(ctxt->myDoc, name);
ctxt->myDoc->standalone = 1;
} else {
ret = xmlGetDocEntity(ctxt->myDoc, name);
if (ret == NULL) {
ctxt->myDoc->standalone = 0;
ret = xmlGetDocEntity(ctxt->myDoc, name);
if (ret != NULL) {
xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE,
"Entity(%s) document marked standalone but requires external subset\n",
name, NULL);
}
ctxt->myDoc->standalone = 1;
}
}
} else {
ret = xmlGetDocEntity(ctxt->myDoc, name);
}
if ((ret != NULL) &&
((ctxt->validate) || (ctxt->replaceEntities)) &&
(ret->children == NULL) &&
(ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
int val;
xmlNodePtr children;
val = xmlParseCtxtExternalEntity(ctxt, ret->URI,
ret->ExternalID, &children);
if (val == 0) {
xmlAddChildList((xmlNodePtr) ret, children);
} else {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
"Failure to process entity %s\n", name, NULL);
ctxt->validate = 0;
return(NULL);
}
ret->owner = 1;
if (ret->checked == 0)
ret->checked = 1;
}
return(ret);
}
xmlEntityPtr
xmlSAX2GetParameterEntity(void *ctx, const xmlChar *name)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlEntityPtr ret;
if (ctx == NULL) return(NULL);
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2GetParameterEntity(%s)\n", name);
#endif
ret = xmlGetParameterEntity(ctxt->myDoc, name);
return(ret);
}
void
xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
{
xmlEntityPtr ent;
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2EntityDecl(%s, %d, %s, %s, %s)\n",
name, type, publicId, systemId, content);
#endif
if (ctxt->inSubset == 1) {
ent = xmlAddDocEntity(ctxt->myDoc, name, type, publicId,
systemId, content);
if ((ent == NULL) && (ctxt->pedantic))
xmlWarnMsg(ctxt, XML_WAR_ENTITY_REDEFINED,
"Entity(%s) already defined in the internal subset\n",
name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
xmlChar *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, (const xmlChar *) base);
ent->URI = URI;
}
} else if (ctxt->inSubset == 2) {
ent = xmlAddDtdEntity(ctxt->myDoc, name, type, publicId,
systemId, content);
if ((ent == NULL) && (ctxt->pedantic) &&
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"Entity(%s) already defined in the external subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
xmlChar *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, (const xmlChar *) base);
ent->URI = URI;
}
} else {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
"SAX.xmlSAX2EntityDecl(%s) called while not in subset\n",
name, NULL);
}
}
void
xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
int type, int def, const xmlChar *defaultValue,
xmlEnumerationPtr tree)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlAttributePtr attr;
xmlChar *name = NULL, *prefix = NULL;
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2AttributeDecl(%s, %s, %d, %d, %s, ...)\n",
elem, fullname, type, def, defaultValue);
#endif
if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) &&
(type != XML_ATTRIBUTE_ID)) {
int tmp = ctxt->valid;
xmlErrValid(ctxt, XML_DTD_XMLID_TYPE,
"xml:id : attribute type should be ID\n", NULL, NULL);
ctxt->valid = tmp;
}
name = xmlSplitQName(ctxt, fullname, &prefix);
ctxt->vctxt.valid = 1;
if (ctxt->inSubset == 1)
attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
name, prefix, (xmlAttributeType) type,
(xmlAttributeDefault) def, defaultValue, tree);
else if (ctxt->inSubset == 2)
attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
name, prefix, (xmlAttributeType) type,
(xmlAttributeDefault) def, defaultValue, tree);
else {
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
"SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n",
name, NULL);
xmlFreeEnumeration(tree);
return;
}
#ifdef LIBXML_VALID_ENABLED
if (ctxt->vctxt.valid == 0)
ctxt->valid = 0;
if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&
(ctxt->myDoc->intSubset != NULL))
ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
attr);
#endif
if (prefix != NULL)
xmlFree(prefix);
if (name != NULL)
xmlFree(name);
}
void
xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,
xmlElementContentPtr content)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlElementPtr elem = NULL;
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2ElementDecl(%s, %d, ...)\n", name, type);
#endif
if (ctxt->inSubset == 1)
elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
name, (xmlElementTypeVal) type, content);
else if (ctxt->inSubset == 2)
elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
name, (xmlElementTypeVal) type, content);
else {
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
"SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
name, NULL);
return;
}
#ifdef LIBXML_VALID_ENABLED
if (elem == NULL)
ctxt->valid = 0;
if (ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &=
xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
#endif
}
void
xmlSAX2NotationDecl(void *ctx, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNotationPtr nota = NULL;
if ((ctxt == NULL) || (ctxt->myDoc == NULL))
return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2NotationDecl(%s, %s, %s)\n", name, publicId, systemId);
#endif
if ((publicId == NULL) && (systemId == NULL)) {
xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
"SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
name, NULL);
return;
} else if (ctxt->inSubset == 1)
nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
publicId, systemId);
else if (ctxt->inSubset == 2)
nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
publicId, systemId);
else {
xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
"SAX.xmlSAX2NotationDecl(%s) called while not in subset\n",
name, NULL);
return;
}
#ifdef LIBXML_VALID_ENABLED
if (nota == NULL) ctxt->valid = 0;
if ((ctxt->validate) && (ctxt->wellFormed) &&
(ctxt->myDoc->intSubset != NULL))
ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
nota);
#endif
}
void
xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId,
const xmlChar *notationName)
{
xmlEntityPtr ent;
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2UnparsedEntityDecl(%s, %s, %s, %s)\n",
name, publicId, systemId, notationName);
#endif
if (ctxt->inSubset == 1) {
ent = xmlAddDocEntity(ctxt->myDoc, name,
XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
publicId, systemId, notationName);
if ((ent == NULL) && (ctxt->pedantic) &&
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"Entity(%s) already defined in the internal subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
xmlChar *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, (const xmlChar *) base);
ent->URI = URI;
}
} else if (ctxt->inSubset == 2) {
ent = xmlAddDtdEntity(ctxt->myDoc, name,
XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
publicId, systemId, notationName);
if ((ent == NULL) && (ctxt->pedantic) &&
(ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"Entity(%s) already defined in the external subset\n", name);
if ((ent != NULL) && (ent->URI == NULL) && (systemId != NULL)) {
xmlChar *URI;
const char *base = NULL;
if (ctxt->input != NULL)
base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
URI = xmlBuildURI(systemId, (const xmlChar *) base);
ent->URI = URI;
}
} else {
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
"SAX.xmlSAX2UnparsedEntityDecl(%s) called while not in subset\n",
name, NULL);
}
}
void
xmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED)
{
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2SetDocumentLocator()\n");
#endif
}
void
xmlSAX2StartDocument(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlDocPtr doc;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2StartDocument()\n");
#endif
if (ctxt->html) {
#ifdef LIBXML_HTML_ENABLED
if (ctxt->myDoc == NULL)
ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
ctxt->myDoc->properties = XML_DOC_HTML;
ctxt->myDoc->parseFlags = ctxt->options;
if (ctxt->myDoc == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
return;
}
#else
xmlGenericError(xmlGenericErrorContext,
"libxml2 built without HTML support\n");
ctxt->errNo = XML_ERR_INTERNAL_ERROR;
ctxt->instate = XML_PARSER_EOF;
ctxt->disableSAX = 1;
return;
#endif
} else {
doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
if (doc != NULL) {
doc->properties = 0;
if (ctxt->options & XML_PARSE_OLD10)
doc->properties |= XML_DOC_OLD10;
doc->parseFlags = ctxt->options;
if (ctxt->encoding != NULL)
doc->encoding = xmlStrdup(ctxt->encoding);
else
doc->encoding = NULL;
doc->standalone = ctxt->standalone;
} else {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
return;
}
if ((ctxt->dictNames) && (doc != NULL)) {
doc->dict = ctxt->dict;
xmlDictReference(doc->dict);
}
}
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename);
if (ctxt->myDoc->URL == NULL)
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
}
}
void
xmlSAX2EndDocument(void *ctx)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2EndDocument()\n");
#endif
if (ctx == NULL) return;
#ifdef LIBXML_VALID_ENABLED
if (ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
#endif
if ((ctxt->encoding != NULL) && (ctxt->myDoc != NULL) &&
(ctxt->myDoc->encoding == NULL)) {
ctxt->myDoc->encoding = ctxt->encoding;
ctxt->encoding = NULL;
}
if ((ctxt->inputTab != NULL) &&
(ctxt->inputNr > 0) && (ctxt->inputTab[0] != NULL) &&
(ctxt->inputTab[0]->encoding != NULL) && (ctxt->myDoc != NULL) &&
(ctxt->myDoc->encoding == NULL)) {
ctxt->myDoc->encoding = xmlStrdup(ctxt->inputTab[0]->encoding);
}
if ((ctxt->charset != XML_CHAR_ENCODING_NONE) && (ctxt->myDoc != NULL) &&
(ctxt->myDoc->charset == XML_CHAR_ENCODING_NONE)) {
ctxt->myDoc->charset = ctxt->charset;
}
}
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED)
static void
xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
const xmlChar *value, const xmlChar *prefix ATTRIBUTE_UNUSED)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlAttrPtr ret;
xmlChar *name;
xmlChar *ns;
xmlChar *nval;
xmlNsPtr namespace;
if (ctxt->html) {
name = xmlStrdup(fullname);
ns = NULL;
namespace = NULL;
} else {
name = xmlSplitQName(ctxt, fullname, &ns);
if ((name != NULL) && (name[0] == 0)) {
if (xmlStrEqual(ns, BAD_CAST "xmlns")) {
xmlNsErrMsg(ctxt, XML_ERR_NS_DECL_ERROR,
"invalid namespace declaration '%s'\n",
fullname, NULL);
} else {
xmlNsWarnMsg(ctxt, XML_WAR_NS_COLUMN,
"Avoid attribute ending with ':' like '%s'\n",
fullname, NULL);
}
if (ns != NULL)
xmlFree(ns);
ns = NULL;
xmlFree(name);
name = xmlStrdup(fullname);
}
}
if (name == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
if (ns != NULL)
xmlFree(ns);
return;
}
#ifdef LIBXML_HTML_ENABLED
if ((ctxt->html) &&
(value == NULL) && (htmlIsBooleanAttr(fullname))) {
nval = xmlStrdup(fullname);
value = (const xmlChar *) nval;
} else
#endif
{
#ifdef LIBXML_VALID_ENABLED
ctxt->vctxt.valid = 1;
nval = xmlValidCtxtNormalizeAttributeValue(&ctxt->vctxt,
ctxt->myDoc, ctxt->node,
fullname, value);
if (ctxt->vctxt.valid != 1) {
ctxt->valid = 0;
}
if (nval != NULL)
value = nval;
#else
nval = NULL;
#endif
}
if ((!ctxt->html) && (ns == NULL) &&
(name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
(name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
xmlNsPtr nsret;
xmlChar *val;
if (!ctxt->replaceEntities) {
ctxt->depth++;
val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
0,0,0);
ctxt->depth--;
} else {
val = (xmlChar *) value;
}
if (val[0] != 0) {
xmlURIPtr uri;
uri = xmlParseURI((const char *)val);
if (uri == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"xmlns: %s not a valid URI\n", val);
} else {
if (uri->scheme == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
ctxt->sax->warning(ctxt->userData,
"xmlns: URI %s is not absolute\n", val);
}
xmlFreeURI(uri);
}
}
nsret = xmlNewNs(ctxt->node, val, NULL);
#ifdef LIBXML_VALID_ENABLED
if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
ctxt->node, prefix, nsret, val);
#endif
if (name != NULL)
xmlFree(name);
if (nval != NULL)
xmlFree(nval);
if (val != value)
xmlFree(val);
return;
}
if ((!ctxt->html) &&
(ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
(ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
xmlNsPtr nsret;
xmlChar *val;
if (!ctxt->replaceEntities) {
ctxt->depth++;
val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
0,0,0);
ctxt->depth--;
if (val == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
xmlFree(ns);
if (name != NULL)
xmlFree(name);
return;
}
} else {
val = (xmlChar *) value;
}
if (val[0] == 0) {
xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY,
"Empty namespace name for prefix %s\n", name, NULL);
}
if ((ctxt->pedantic != 0) && (val[0] != 0)) {
xmlURIPtr uri;
uri = xmlParseURI((const char *)val);
if (uri == NULL) {
xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
"xmlns:%s: %s not a valid URI\n", name, value);
} else {
if (uri->scheme == NULL) {
xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
"xmlns:%s: URI %s is not absolute\n", name, value);
}
xmlFreeURI(uri);
}
}
nsret = xmlNewNs(ctxt->node, val, name);
xmlFree(ns);
#ifdef LIBXML_VALID_ENABLED
if (nsret != NULL && ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
ctxt->node, prefix, nsret, value);
#endif
if (name != NULL)
xmlFree(name);
if (nval != NULL)
xmlFree(nval);
if (val != value)
xmlFree(val);
return;
}
if (ns != NULL) {
namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, ns);
if (namespace == NULL) {
xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace prefix %s of attribute %s is not defined\n",
ns, name);
} else {
xmlAttrPtr prop;
prop = ctxt->node->properties;
while (prop != NULL) {
if (prop->ns != NULL) {
if ((xmlStrEqual(name, prop->name)) &&
((namespace == prop->ns) ||
(xmlStrEqual(namespace->href, prop->ns->href)))) {
xmlNsErrMsg(ctxt, XML_ERR_ATTRIBUTE_REDEFINED,
"Attribute %s in %s redefined\n",
name, namespace->href);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
goto error;
}
}
prop = prop->next;
}
}
} else {
namespace = NULL;
}
ret = xmlNewNsPropEatName(ctxt->node, namespace, name, NULL);
if (ret != NULL) {
if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
xmlNodePtr tmp;
ret->children = xmlStringGetNodeList(ctxt->myDoc, value);
tmp = ret->children;
while (tmp != NULL) {
tmp->parent = (xmlNodePtr) ret;
if (tmp->next == NULL)
ret->last = tmp;
tmp = tmp->next;
}
} else if (value != NULL) {
ret->children = xmlNewDocText(ctxt->myDoc, value);
ret->last = ret->children;
if (ret->children != NULL)
ret->children->parent = (xmlNodePtr) ret;
}
}
#ifdef LIBXML_VALID_ENABLED
if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset) {
if (!ctxt->replaceEntities) {
xmlChar *val;
ctxt->depth++;
val = xmlStringDecodeEntities(ctxt, value, XML_SUBSTITUTE_REF,
0,0,0);
ctxt->depth--;
if (val == NULL)
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, value);
else {
xmlChar *nvalnorm;
nvalnorm = xmlValidNormalizeAttributeValue(ctxt->myDoc,
ctxt->node, fullname, val);
if (nvalnorm != NULL) {
xmlFree(val);
val = nvalnorm;
}
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, val);
xmlFree(val);
}
} else {
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
ctxt->node, ret, value);
}
} else
#endif
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
(((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) {
if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
if (xmlValidateNCName(value, 1) != 0) {
xmlErrValid(ctxt, XML_DTD_XMLID_VALUE,
"xml:id : attribute value %s is not an NCName\n",
(const char *) value, NULL);
}
xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret))
xmlAddID(&ctxt->vctxt, ctxt->myDoc, value, ret);
else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, value, ret);
}
error:
if (nval != NULL)
xmlFree(nval);
if (ns != NULL)
xmlFree(ns);
}
static void
xmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt, const xmlChar *name,
const xmlChar *prefix, const xmlChar **atts) {
xmlElementPtr elemDecl;
const xmlChar *att;
int internal = 1;
int i;
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix);
if (elemDecl == NULL) {
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix);
internal = 0;
}
process_external_subset:
if (elemDecl != NULL) {
xmlAttributePtr attr = elemDecl->attributes;
if ((ctxt->myDoc->standalone == 1) &&
(ctxt->myDoc->extSubset != NULL) &&
(ctxt->validate)) {
while (attr != NULL) {
if ((attr->defaultValue != NULL) &&
(xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
attr->elem, attr->name,
attr->prefix) == attr) &&
(xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
attr->elem, attr->name,
attr->prefix) == NULL)) {
xmlChar *fulln;
if (attr->prefix != NULL) {
fulln = xmlStrdup(attr->prefix);
fulln = xmlStrcat(fulln, BAD_CAST ":");
fulln = xmlStrcat(fulln, attr->name);
} else {
fulln = xmlStrdup(attr->name);
}
if (fulln == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
break;
}
att = NULL;
if (atts != NULL) {
i = 0;
att = atts[i];
while (att != NULL) {
if (xmlStrEqual(att, fulln))
break;
i += 2;
att = atts[i];
}
}
if (att == NULL) {
xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED,
"standalone: attribute %s on %s defaulted from external subset\n",
(const char *)fulln,
(const char *)attr->elem);
}
xmlFree(fulln);
}
attr = attr->nexth;
}
}
attr = elemDecl->attributes;
while (attr != NULL) {
if (attr->defaultValue != NULL) {
if (((attr->prefix != NULL) &&
(xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
((attr->prefix == NULL) &&
(xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
(ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
xmlAttributePtr tst;
tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
attr->elem, attr->name,
attr->prefix);
if ((tst == attr) || (tst == NULL)) {
xmlChar fn[50];
xmlChar *fulln;
fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);
if (fulln == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
return;
}
att = NULL;
if (atts != NULL) {
i = 0;
att = atts[i];
while (att != NULL) {
if (xmlStrEqual(att, fulln))
break;
i += 2;
att = atts[i];
}
}
if (att == NULL) {
xmlSAX2AttributeInternal(ctxt, fulln,
attr->defaultValue, prefix);
}
if ((fulln != fn) && (fulln != attr->name))
xmlFree(fulln);
}
}
}
attr = attr->nexth;
}
if (internal == 1) {
elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
name, prefix);
internal = 0;
goto process_external_subset;
}
}
}
void
xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret;
xmlNodePtr parent;
xmlNsPtr ns;
xmlChar *name;
xmlChar *prefix;
const xmlChar *att;
const xmlChar *value;
int i;
if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
parent = ctxt->node;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2StartElement(%s)\n", fullname);
#endif
if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
((ctxt->myDoc->intSubset == NULL) ||
((ctxt->myDoc->intSubset->notations == NULL) &&
(ctxt->myDoc->intSubset->elements == NULL) &&
(ctxt->myDoc->intSubset->attributes == NULL) &&
(ctxt->myDoc->intSubset->entities == NULL)))) {
xmlErrValid(ctxt, XML_ERR_NO_DTD,
"Validation failed: no DTD found !", NULL, NULL);
ctxt->validate = 0;
}
name = xmlSplitQName(ctxt, fullname, &prefix);
ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, name, NULL);
if (ret == NULL) {
if (prefix != NULL)
xmlFree(prefix);
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
return;
}
if (ctxt->myDoc->children == NULL) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext, "Setting %s as root\n", name);
#endif
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
} else if (parent == NULL) {
parent = ctxt->myDoc->children;
}
ctxt->nodemem = -1;
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
else
ret->line = 65535;
}
}
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext, "pushing(%s)\n", name);
#endif
nodePush(ctxt, ret);
if (parent != NULL) {
if (parent->type == XML_ELEMENT_NODE) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding child %s to %s\n", name, parent->name);
#endif
xmlAddChild(parent, ret);
} else {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding sibling %s to ", name);
xmlDebugDumpOneNode(stderr, parent, 0);
#endif
xmlAddSibling(parent, ret);
}
}
if ((!ctxt->html) &&
((ctxt->myDoc->intSubset != NULL) ||
(ctxt->myDoc->extSubset != NULL))) {
xmlCheckDefaultedAttributes(ctxt, name, prefix, atts);
}
if (atts != NULL) {
i = 0;
att = atts[i++];
value = atts[i++];
if (!ctxt->html) {
while ((att != NULL) && (value != NULL)) {
if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') &&
(att[3] == 'n') && (att[4] == 's'))
xmlSAX2AttributeInternal(ctxt, att, value, prefix);
att = atts[i++];
value = atts[i++];
}
}
}
ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
if ((ns == NULL) && (parent != NULL))
ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
if ((prefix != NULL) && (ns == NULL)) {
ns = xmlNewNs(ret, NULL, prefix);
xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace prefix %s is not defined\n",
prefix, NULL);
}
if ((ns != NULL) && (ns->href != NULL) &&
((ns->href[0] != 0) || (ns->prefix != NULL)))
xmlSetNs(ret, ns);
if (atts != NULL) {
i = 0;
att = atts[i++];
value = atts[i++];
if (ctxt->html) {
while (att != NULL) {
xmlSAX2AttributeInternal(ctxt, att, value, NULL);
att = atts[i++];
value = atts[i++];
}
} else {
while ((att != NULL) && (value != NULL)) {
if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l') ||
(att[3] != 'n') || (att[4] != 's'))
xmlSAX2AttributeInternal(ctxt, att, value, NULL);
att = atts[i++];
value = atts[i++];
}
}
}
#ifdef LIBXML_VALID_ENABLED
if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) {
int chk;
chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
if (chk <= 0)
ctxt->valid = 0;
if (chk < 0)
ctxt->wellFormed = 0;
ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1;
}
#endif
if (prefix != NULL)
xmlFree(prefix);
}
void
xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserNodeInfo node_info;
xmlNodePtr cur;
if (ctx == NULL) return;
cur = ctxt->node;
#ifdef DEBUG_SAX
if (name == NULL)
xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(NULL)\n");
else
xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(%s)\n", name);
#endif
if (cur != NULL && ctxt->record_info) {
node_info.end_pos = ctxt->input->cur - ctxt->input->base;
node_info.end_line = ctxt->input->line;
node_info.node = cur;
xmlParserAddNodeInfo(ctxt, &node_info);
}
ctxt->nodemem = -1;
#ifdef LIBXML_VALID_ENABLED
if (ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
cur);
#endif
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext, "popping(%s)\n", cur->name);
#endif
nodePop(ctxt);
}
#endif
static xmlNodePtr
xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
xmlNodePtr ret;
const xmlChar *intern = NULL;
if (ctxt->freeElems != NULL) {
ret = ctxt->freeElems;
ctxt->freeElems = ret->next;
ctxt->freeElemsNr--;
} else {
ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
}
if (ret == NULL) {
xmlErrMemory(ctxt, "xmlSAX2Characters");
return(NULL);
}
memset(ret, 0, sizeof(xmlNode));
if (ctxt->dictNames) {
xmlChar cur = str[len];
if ((len < (int) (2 * sizeof(void *))) &&
(ctxt->options & XML_PARSE_COMPACT)) {
xmlChar *tmp = (xmlChar *) &(ret->properties);
memcpy(tmp, str, len);
tmp[len] = 0;
intern = tmp;
} else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
((cur == '<') && (str[len + 1] != '!')))) {
intern = xmlDictLookup(ctxt->dict, str, len);
} else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
(str[len + 1] != '!')) {
int i;
for (i = 1;i < len;i++) {
if (!IS_BLANK_CH(str[i])) goto skip;
}
intern = xmlDictLookup(ctxt->dict, str, len);
}
}
skip:
ret->type = XML_TEXT_NODE;
ret->name = xmlStringText;
if (intern == NULL) {
ret->content = xmlStrndup(str, len);
if (ret->content == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2TextNode");
xmlFree(ret);
return(NULL);
}
} else
ret->content = (xmlChar *) intern;
if (ctxt->input != NULL)
ret->line = ctxt->input->line;
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
xmlRegisterNodeDefaultValue(ret);
return(ret);
}
#ifdef LIBXML_VALID_ENABLED
static xmlChar *
xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt, const xmlChar *str,
const xmlChar *end) {
const xmlChar *in;
xmlChar *ret;
in = str;
while (in < end)
if (*in++ == '&')
goto decode;
return(NULL);
decode:
ctxt->depth++;
ret = xmlStringLenDecodeEntities(ctxt, str, end - str,
XML_SUBSTITUTE_REF, 0,0,0);
ctxt->depth--;
return(ret);
}
#endif
static void
xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
const xmlChar * localname,
const xmlChar * prefix,
const xmlChar * value,
const xmlChar * valueend)
{
xmlAttrPtr ret;
xmlNsPtr namespace = NULL;
xmlChar *dup = NULL;
if (prefix != NULL)
namespace = xmlSearchNs(ctxt->myDoc, ctxt->node, prefix);
if (ctxt->freeAttrs != NULL) {
ret = ctxt->freeAttrs;
ctxt->freeAttrs = ret->next;
ctxt->freeAttrsNr--;
memset(ret, 0, sizeof(xmlAttr));
ret->type = XML_ATTRIBUTE_NODE;
ret->parent = ctxt->node;
ret->doc = ctxt->myDoc;
ret->ns = namespace;
if (ctxt->dictNames)
ret->name = localname;
else
ret->name = xmlStrdup(localname);
if (ctxt->node->properties == NULL) {
ctxt->node->properties = ret;
} else {
xmlAttrPtr prev = ctxt->node->properties;
while (prev->next != NULL) prev = prev->next;
prev->next = ret;
ret->prev = prev;
}
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
xmlRegisterNodeDefaultValue((xmlNodePtr)ret);
} else {
if (ctxt->dictNames)
ret = xmlNewNsPropEatName(ctxt->node, namespace,
(xmlChar *) localname, NULL);
else
ret = xmlNewNsProp(ctxt->node, namespace, localname, NULL);
if (ret == NULL) {
xmlErrMemory(ctxt, "xmlSAX2AttributeNs");
return;
}
}
if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
xmlNodePtr tmp;
if (*valueend != 0) {
tmp = xmlSAX2TextNode(ctxt, value, valueend - value);
ret->children = tmp;
ret->last = tmp;
if (tmp != NULL) {
tmp->doc = ret->doc;
tmp->parent = (xmlNodePtr) ret;
}
} else {
ret->children = xmlStringLenGetNodeList(ctxt->myDoc, value,
valueend - value);
tmp = ret->children;
while (tmp != NULL) {
tmp->doc = ret->doc;
tmp->parent = (xmlNodePtr) ret;
if (tmp->next == NULL)
ret->last = tmp;
tmp = tmp->next;
}
}
} else if (value != NULL) {
xmlNodePtr tmp;
tmp = xmlSAX2TextNode(ctxt, value, valueend - value);
ret->children = tmp;
ret->last = tmp;
if (tmp != NULL) {
tmp->doc = ret->doc;
tmp->parent = (xmlNodePtr) ret;
}
}
#ifdef LIBXML_VALID_ENABLED
if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset) {
if (!ctxt->replaceEntities) {
dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend);
if (dup == NULL) {
if (*valueend == 0) {
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, value);
} else {
dup = xmlStrndup(value, valueend - value);
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, dup);
}
} else {
if (ctxt->attsSpecial != NULL) {
xmlChar *nvalnorm;
xmlChar fn[50];
xmlChar *fullname;
fullname = xmlBuildQName(localname, prefix, fn, 50);
if (fullname != NULL) {
ctxt->vctxt.valid = 1;
nvalnorm = xmlValidCtxtNormalizeAttributeValue(
&ctxt->vctxt, ctxt->myDoc,
ctxt->node, fullname, dup);
if (ctxt->vctxt.valid != 1)
ctxt->valid = 0;
if ((fullname != fn) && (fullname != localname))
xmlFree(fullname);
if (nvalnorm != NULL) {
xmlFree(dup);
dup = nvalnorm;
}
}
}
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, dup);
}
} else {
dup = xmlStrndup(value, valueend - value);
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, dup);
}
} else
#endif
if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
(((ctxt->replaceEntities == 0) && (ctxt->external != 2)) ||
((ctxt->replaceEntities != 0) && (ctxt->inSubset == 0)))) {
if ((prefix == ctxt->str_xml) &&
(localname[0] == 'i') && (localname[1] == 'd') &&
(localname[2] == 0)) {
if (dup == NULL)
dup = xmlStrndup(value, valueend - value);
#ifdef LIBXML_VALID_ENABLED
if (xmlValidateNCName(dup, 1) != 0) {
xmlErrValid(ctxt, XML_DTD_XMLID_VALUE,
"xml:id : attribute value %s is not an NCName\n",
(const char *) dup, NULL);
}
#endif
xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
} else if (xmlIsID(ctxt->myDoc, ctxt->node, ret)) {
if (dup == NULL)
dup = xmlStrndup(value, valueend - value);
xmlAddID(&ctxt->vctxt, ctxt->myDoc, dup, ret);
} else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret)) {
if (dup == NULL)
dup = xmlStrndup(value, valueend - value);
xmlAddRef(&ctxt->vctxt, ctxt->myDoc, dup, ret);
}
}
if (dup != NULL)
xmlFree(dup);
}
void
xmlSAX2StartElementNs(void *ctx,
const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI,
int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar **attributes)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret;
xmlNodePtr parent;
xmlNsPtr last = NULL, ns;
const xmlChar *uri, *pref;
int i, j;
if (ctx == NULL) return;
parent = ctxt->node;
if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
((ctxt->myDoc->intSubset == NULL) ||
((ctxt->myDoc->intSubset->notations == NULL) &&
(ctxt->myDoc->intSubset->elements == NULL) &&
(ctxt->myDoc->intSubset->attributes == NULL) &&
(ctxt->myDoc->intSubset->entities == NULL)))) {
xmlErrValid(ctxt, XML_ERR_NO_DTD,
"Validation failed: no DTD found !", NULL, NULL);
ctxt->validate = 0;
}
if (ctxt->freeElems != NULL) {
ret = ctxt->freeElems;
ctxt->freeElems = ret->next;
ctxt->freeElemsNr--;
memset(ret, 0, sizeof(xmlNode));
ret->type = XML_ELEMENT_NODE;
if (ctxt->dictNames)
ret->name = localname;
else {
ret->name = xmlStrdup(localname);
if (ret->name == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
}
if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
xmlRegisterNodeDefaultValue(ret);
} else {
if (ctxt->dictNames)
ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
(xmlChar *) localname, NULL);
else
ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
if (ret == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
}
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
else
ret->line = 65535;
}
}
if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
}
for (i = 0,j = 0;j < nb_namespaces;j++) {
pref = namespaces[i++];
uri = namespaces[i++];
ns = xmlNewNs(NULL, uri, pref);
if (ns != NULL) {
if (last == NULL) {
ret->nsDef = last = ns;
} else {
last->next = ns;
last = ns;
}
if ((URI != NULL) && (prefix == pref))
ret->ns = ns;
} else {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
#ifdef LIBXML_VALID_ENABLED
if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset) {
ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
ret, prefix, ns, uri);
}
#endif
}
ctxt->nodemem = -1;
nodePush(ctxt, ret);
if (parent != NULL) {
if (parent->type == XML_ELEMENT_NODE) {
xmlAddChild(parent, ret);
} else {
xmlAddSibling(parent, ret);
}
}
if ((nb_defaulted != 0) &&
((ctxt->loadsubset & XML_COMPLETE_ATTRS) == 0))
nb_attributes -= nb_defaulted;
if ((URI != NULL) && (ret->ns == NULL)) {
ret->ns = xmlSearchNs(ctxt->myDoc, parent, prefix);
if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
ret->ns = xmlSearchNs(ctxt->myDoc, ret, prefix);
}
if (ret->ns == NULL) {
ns = xmlNewNs(ret, NULL, prefix);
if (ns == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
}
if (prefix != NULL)
xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace prefix %s was not found\n",
prefix, NULL);
else
xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
"Namespace default prefix was not found\n",
NULL, NULL);
}
}
if (nb_attributes > 0) {
for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {
xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],
attributes[j+3], attributes[j+4]);
}
}
#ifdef LIBXML_VALID_ENABLED
if ((ctxt->validate) && (ctxt->vctxt.finishDtd == XML_CTXT_FINISH_DTD_0)) {
int chk;
chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
if (chk <= 0)
ctxt->valid = 0;
if (chk < 0)
ctxt->wellFormed = 0;
ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_1;
}
#endif
}
void
xmlSAX2EndElementNs(void *ctx,
const xmlChar * localname ATTRIBUTE_UNUSED,
const xmlChar * prefix ATTRIBUTE_UNUSED,
const xmlChar * URI ATTRIBUTE_UNUSED)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserNodeInfo node_info;
xmlNodePtr cur;
if (ctx == NULL) return;
cur = ctxt->node;
if ((ctxt->record_info) && (cur != NULL)) {
node_info.end_pos = ctxt->input->cur - ctxt->input->base;
node_info.end_line = ctxt->input->line;
node_info.node = cur;
xmlParserAddNodeInfo(ctxt, &node_info);
}
ctxt->nodemem = -1;
#ifdef LIBXML_VALID_ENABLED
if (ctxt->validate && ctxt->wellFormed &&
ctxt->myDoc && ctxt->myDoc->intSubset)
ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc, cur);
#endif
nodePop(ctxt);
}
void
xmlSAX2Reference(void *ctx, const xmlChar *name)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2Reference(%s)\n", name);
#endif
if (name[0] == '#')
ret = xmlNewCharRef(ctxt->myDoc, name);
else
ret = xmlNewReference(ctxt->myDoc, name);
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"add xmlSAX2Reference %s to %s \n", name, ctxt->node->name);
#endif
if (xmlAddChild(ctxt->node, ret) == NULL) {
xmlFreeNode(ret);
}
}
void
xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr lastChild;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2Characters(%.30s, %d)\n", ch, len);
#endif
if (ctxt->node == NULL) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"add chars: ctxt->node == NULL !\n");
#endif
return;
}
lastChild = ctxt->node->last;
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"add chars to %s \n", ctxt->node->name);
#endif
if (lastChild == NULL) {
lastChild = xmlSAX2TextNode(ctxt, ch, len);
if (lastChild != NULL) {
ctxt->node->children = lastChild;
ctxt->node->last = lastChild;
lastChild->parent = ctxt->node;
lastChild->doc = ctxt->node->doc;
ctxt->nodelen = len;
ctxt->nodemem = len + 1;
} else {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
return;
}
} else {
int coalesceText = (lastChild != NULL) &&
(lastChild->type == XML_TEXT_NODE) &&
(lastChild->name == xmlStringText);
if ((coalesceText) && (ctxt->nodemem != 0)) {
if (lastChild->content == (xmlChar *)&(lastChild->properties)) {
lastChild->content = xmlStrdup(lastChild->content);
lastChild->properties = NULL;
} else if ((ctxt->nodemem == ctxt->nodelen + 1) &&
(xmlDictOwns(ctxt->dict, lastChild->content))) {
lastChild->content = xmlStrdup(lastChild->content);
}
if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGTH) &&
((ctxt->options & XML_PARSE_HUGE) == 0)) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node");
return;
}
if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len ||
(size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
return;
}
if (ctxt->nodelen + len >= ctxt->nodemem) {
xmlChar *newbuf;
size_t size;
size = ctxt->nodemem + len;
size *= 2;
newbuf = (xmlChar *) xmlRealloc(lastChild->content,size);
if (newbuf == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
return;
}
ctxt->nodemem = size;
lastChild->content = newbuf;
}
memcpy(&lastChild->content[ctxt->nodelen], ch, len);
ctxt->nodelen += len;
lastChild->content[ctxt->nodelen] = 0;
} else if (coalesceText) {
if (xmlTextConcat(lastChild, ch, len)) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters");
}
if (ctxt->node->children != NULL) {
ctxt->nodelen = xmlStrlen(lastChild->content);
ctxt->nodemem = ctxt->nodelen + 1;
}
} else {
lastChild = xmlSAX2TextNode(ctxt, ch, len);
if (lastChild != NULL) {
xmlAddChild(ctxt->node, lastChild);
if (ctxt->node->children != NULL) {
ctxt->nodelen = len;
ctxt->nodemem = len + 1;
}
}
}
}
}
void
xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
{
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2IgnorableWhitespace(%.30s, %d)\n", ch, len);
#endif
}
void
xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
const xmlChar *data)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret;
xmlNodePtr parent;
if (ctx == NULL) return;
parent = ctxt->node;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.xmlSAX2ProcessingInstruction(%s, %s)\n", target, data);
#endif
ret = xmlNewDocPI(ctxt->myDoc, target, data);
if (ret == NULL) return;
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
else
ret->line = 65535;
}
}
if (ctxt->inSubset == 1) {
xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
return;
} else if (ctxt->inSubset == 2) {
xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
return;
}
if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"Setting PI %s as root\n", target);
#endif
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
return;
}
if (parent->type == XML_ELEMENT_NODE) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding PI %s child to %s\n", target, parent->name);
#endif
xmlAddChild(parent, ret);
} else {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding PI %s sibling to ", target);
xmlDebugDumpOneNode(stderr, parent, 0);
#endif
xmlAddSibling(parent, ret);
}
}
void
xmlSAX2Comment(void *ctx, const xmlChar *value)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret;
xmlNodePtr parent;
if (ctx == NULL) return;
parent = ctxt->node;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2Comment(%s)\n", value);
#endif
ret = xmlNewDocComment(ctxt->myDoc, value);
if (ret == NULL) return;
if (ctxt->linenumbers) {
if (ctxt->input != NULL) {
if (ctxt->input->line < 65535)
ret->line = (short) ctxt->input->line;
else
ret->line = 65535;
}
}
if (ctxt->inSubset == 1) {
xmlAddChild((xmlNodePtr) ctxt->myDoc->intSubset, ret);
return;
} else if (ctxt->inSubset == 2) {
xmlAddChild((xmlNodePtr) ctxt->myDoc->extSubset, ret);
return;
}
if ((ctxt->myDoc->children == NULL) || (parent == NULL)) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"Setting xmlSAX2Comment as root\n");
#endif
xmlAddChild((xmlNodePtr) ctxt->myDoc, (xmlNodePtr) ret);
return;
}
if (parent->type == XML_ELEMENT_NODE) {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding xmlSAX2Comment child to %s\n", parent->name);
#endif
xmlAddChild(parent, ret);
} else {
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"adding xmlSAX2Comment sibling to ");
xmlDebugDumpOneNode(stderr, parent, 0);
#endif
xmlAddSibling(parent, ret);
}
}
void
xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlNodePtr ret, lastChild;
if (ctx == NULL) return;
#ifdef DEBUG_SAX
xmlGenericError(xmlGenericErrorContext,
"SAX.pcdata(%.10s, %d)\n", value, len);
#endif
lastChild = xmlGetLastChild(ctxt->node);
#ifdef DEBUG_SAX_TREE
xmlGenericError(xmlGenericErrorContext,
"add chars to %s \n", ctxt->node->name);
#endif
if ((lastChild != NULL) &&
(lastChild->type == XML_CDATA_SECTION_NODE)) {
xmlTextConcat(lastChild, value, len);
} else {
ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
xmlAddChild(ctxt->node, ret);
}
}
static int xmlSAX2DefaultVersionValue = 2;
#ifdef LIBXML_SAX1_ENABLED
int
xmlSAXDefaultVersion(int version)
{
int ret = xmlSAX2DefaultVersionValue;
if ((version != 1) && (version != 2))
return(-1);
xmlSAX2DefaultVersionValue = version;
return(ret);
}
#endif
int
xmlSAXVersion(xmlSAXHandler *hdlr, int version)
{
if (hdlr == NULL) return(-1);
if (version == 2) {
hdlr->startElement = NULL;
hdlr->endElement = NULL;
hdlr->startElementNs = xmlSAX2StartElementNs;
hdlr->endElementNs = xmlSAX2EndElementNs;
hdlr->serror = NULL;
hdlr->initialized = XML_SAX2_MAGIC;
#ifdef LIBXML_SAX1_ENABLED
} else if (version == 1) {
hdlr->startElement = xmlSAX2StartElement;
hdlr->endElement = xmlSAX2EndElement;
hdlr->initialized = 1;
#endif
} else
return(-1);
hdlr->internalSubset = xmlSAX2InternalSubset;
hdlr->externalSubset = xmlSAX2ExternalSubset;
hdlr->isStandalone = xmlSAX2IsStandalone;
hdlr->hasInternalSubset = xmlSAX2HasInternalSubset;
hdlr->hasExternalSubset = xmlSAX2HasExternalSubset;
hdlr->resolveEntity = xmlSAX2ResolveEntity;
hdlr->getEntity = xmlSAX2GetEntity;
hdlr->getParameterEntity = xmlSAX2GetParameterEntity;
hdlr->entityDecl = xmlSAX2EntityDecl;
hdlr->attributeDecl = xmlSAX2AttributeDecl;
hdlr->elementDecl = xmlSAX2ElementDecl;
hdlr->notationDecl = xmlSAX2NotationDecl;
hdlr->unparsedEntityDecl = xmlSAX2UnparsedEntityDecl;
hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
hdlr->startDocument = xmlSAX2StartDocument;
hdlr->endDocument = xmlSAX2EndDocument;
hdlr->reference = xmlSAX2Reference;
hdlr->characters = xmlSAX2Characters;
hdlr->cdataBlock = xmlSAX2CDataBlock;
hdlr->ignorableWhitespace = xmlSAX2Characters;
hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
hdlr->comment = xmlSAX2Comment;
hdlr->warning = xmlParserWarning;
hdlr->error = xmlParserError;
hdlr->fatalError = xmlParserError;
return(0);
}
void
xmlSAX2InitDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
{
if ((hdlr == NULL) || (hdlr->initialized != 0))
return;
xmlSAXVersion(hdlr, xmlSAX2DefaultVersionValue);
if (warning == 0)
hdlr->warning = NULL;
else
hdlr->warning = xmlParserWarning;
}
void
xmlDefaultSAXHandlerInit(void)
{
#ifdef LIBXML_SAX1_ENABLED
xmlSAXVersion((xmlSAXHandlerPtr) &xmlDefaultSAXHandler, 1);
#endif
}
#ifdef LIBXML_HTML_ENABLED
void
xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
{
if ((hdlr == NULL) || (hdlr->initialized != 0))
return;
hdlr->internalSubset = xmlSAX2InternalSubset;
hdlr->externalSubset = NULL;
hdlr->isStandalone = NULL;
hdlr->hasInternalSubset = NULL;
hdlr->hasExternalSubset = NULL;
hdlr->resolveEntity = NULL;
hdlr->getEntity = xmlSAX2GetEntity;
hdlr->getParameterEntity = NULL;
hdlr->entityDecl = NULL;
hdlr->attributeDecl = NULL;
hdlr->elementDecl = NULL;
hdlr->notationDecl = NULL;
hdlr->unparsedEntityDecl = NULL;
hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
hdlr->startDocument = xmlSAX2StartDocument;
hdlr->endDocument = xmlSAX2EndDocument;
hdlr->startElement = xmlSAX2StartElement;
hdlr->endElement = xmlSAX2EndElement;
hdlr->reference = NULL;
hdlr->characters = xmlSAX2Characters;
hdlr->cdataBlock = xmlSAX2CDataBlock;
hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
hdlr->comment = xmlSAX2Comment;
hdlr->warning = xmlParserWarning;
hdlr->error = xmlParserError;
hdlr->fatalError = xmlParserError;
hdlr->initialized = 1;
}
void
htmlDefaultSAXHandlerInit(void)
{
xmlSAX2InitHtmlDefaultSAXHandler((xmlSAXHandlerPtr) &htmlDefaultSAXHandler);
}
#endif
#ifdef LIBXML_DOCB_ENABLED
void
xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr)
{
if ((hdlr == NULL) || (hdlr->initialized != 0))
return;
hdlr->internalSubset = xmlSAX2InternalSubset;
hdlr->externalSubset = NULL;
hdlr->isStandalone = xmlSAX2IsStandalone;
hdlr->hasInternalSubset = xmlSAX2HasInternalSubset;
hdlr->hasExternalSubset = xmlSAX2HasExternalSubset;
hdlr->resolveEntity = xmlSAX2ResolveEntity;
hdlr->getEntity = xmlSAX2GetEntity;
hdlr->getParameterEntity = NULL;
hdlr->entityDecl = xmlSAX2EntityDecl;
hdlr->attributeDecl = NULL;
hdlr->elementDecl = NULL;
hdlr->notationDecl = NULL;
hdlr->unparsedEntityDecl = NULL;
hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
hdlr->startDocument = xmlSAX2StartDocument;
hdlr->endDocument = xmlSAX2EndDocument;
hdlr->startElement = xmlSAX2StartElement;
hdlr->endElement = xmlSAX2EndElement;
hdlr->reference = xmlSAX2Reference;
hdlr->characters = xmlSAX2Characters;
hdlr->cdataBlock = NULL;
hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
hdlr->processingInstruction = NULL;
hdlr->comment = xmlSAX2Comment;
hdlr->warning = xmlParserWarning;
hdlr->error = xmlParserError;
hdlr->fatalError = xmlParserError;
hdlr->initialized = 1;
}
void
docbDefaultSAXHandlerInit(void)
{
xmlSAX2InitDocbDefaultSAXHandler((xmlSAXHandlerPtr) &docbDefaultSAXHandler);
}
#endif
#define bottom_SAX2
#include "elfgcchack.h"