--- embedaddon/libxml2/SAX2.c 2013/07/22 01:22:18 1.1.1.2 +++ embedaddon/libxml2/SAX2.c 2014/06/15 19:53:28 1.1.1.3 @@ -45,7 +45,7 @@ *> values "system" and "public". I have made the default be "system" to *> match yours. */ -#define TODO \ +#define TODO \ xmlGenericError(xmlGenericErrorContext, \ "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__); @@ -57,12 +57,29 @@ */ static void xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt, const char *msg) { + xmlStructuredErrorFunc schannel = NULL; + const char *str1 = "out of memory\n"; + 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; + 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_PARSER, XML_ERR_NO_MEMORY, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + NULL, NULL, 0, 0, + msg, (const char *) str1, NULL); + ctxt->errNo = XML_ERR_NO_MEMORY; ctxt->instate = XML_PARSER_EOF; ctxt->disableSAX = 1; + } else { + __xmlRaiseError(schannel, + NULL, NULL, + ctxt, NULL, XML_FROM_PARSER, XML_ERR_NO_MEMORY, + XML_ERR_ERROR, NULL, 0, (const char *) str1, + NULL, NULL, 0, 0, + msg, (const char *) str1, NULL); } } @@ -126,7 +143,7 @@ xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors if (ctxt != NULL) ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, - XML_ERR_FATAL, NULL, 0, + XML_ERR_FATAL, NULL, 0, (const char *) str1, (const char *) str2, NULL, 0, 0, msg, str1, str2); if (ctxt != NULL) { @@ -157,7 +174,7 @@ xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors erro if (ctxt != NULL) ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error, - XML_ERR_WARNING, NULL, 0, + XML_ERR_WARNING, NULL, 0, (const char *) str1, NULL, NULL, 0, 0, msg, str1); } @@ -182,7 +199,7 @@ xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors err if (ctxt != NULL) ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, - XML_ERR_ERROR, NULL, 0, + XML_ERR_ERROR, NULL, 0, (const char *) str1, (const char *) str2, NULL, 0, 0, msg, str1, str2); } @@ -206,7 +223,7 @@ xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors er if (ctxt != NULL) ctxt->errNo = error; __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_NAMESPACE, error, - XML_ERR_WARNING, NULL, 0, + XML_ERR_WARNING, NULL, 0, (const char *) str1, (const char *) str2, NULL, 0, 0, msg, str1, str2); } @@ -240,7 +257,7 @@ xmlSAX2GetSystemId(void *ctx) { xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL); - return((const xmlChar *) ctxt->input->filename); + return((const xmlChar *) ctxt->input->filename); } /** @@ -355,7 +372,7 @@ xmlSAX2InternalSubset(void *ctx, const xmlChar *name, xmlFreeDtd(dtd); ctxt->myDoc->intSubset = NULL; } - ctxt->myDoc->intSubset = + ctxt->myDoc->intSubset = xmlCreateIntSubset(ctxt->myDoc, name, ExternalID, SystemID); if (ctxt->myDoc->intSubset == NULL) xmlSAX2ErrMemory(ctxt, "xmlSAX2InternalSubset"); @@ -394,6 +411,7 @@ xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, xmlParserInputPtr input = NULL; xmlCharEncoding enc; int oldcharset; + const xmlChar *oldencoding; /* * Ask the Entity resolver to load the damn thing @@ -415,6 +433,8 @@ xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, oldinputMax = ctxt->inputMax; oldinputTab = ctxt->inputTab; oldcharset = ctxt->charset; + oldencoding = ctxt->encoding; + ctxt->encoding = NULL; ctxt->inputTab = (xmlParserInputPtr *) xmlMalloc(5 * sizeof(xmlParserInputPtr)); @@ -425,6 +445,7 @@ xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, ctxt->inputMax = oldinputMax; ctxt->inputTab = oldinputTab; ctxt->charset = oldcharset; + ctxt->encoding = oldencoding; return; } ctxt->inputNr = 0; @@ -470,6 +491,11 @@ xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, ctxt->inputMax = oldinputMax; ctxt->inputTab = oldinputTab; ctxt->charset = oldcharset; + if ((ctxt->encoding != NULL) && + ((ctxt->dict == NULL) || + (!xmlDictOwns(ctxt->dict, ctxt->encoding)))) + xmlFree((xmlChar *) ctxt->encoding); + ctxt->encoding = oldencoding; /* ctxt->wellFormed = oldwellFormed; */ } } @@ -574,6 +600,7 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name) * parse the external entity */ xmlNodePtr children; + unsigned long oldnbent = ctxt->nbentities; val = xmlParseCtxtExternalEntity(ctxt, ret->URI, ret->ExternalID, &children); @@ -586,8 +613,11 @@ xmlSAX2GetEntity(void *ctx, const xmlChar *name) return(NULL); } ret->owner = 1; - if (ret->checked == 0) - ret->checked = 1; + if (ret->checked == 0) { + ret->checked = (ctxt->nbentities - oldnbent + 1) * 2; + if ((ret->content != NULL) && (xmlStrchr(ret->content, '<'))) + ret->checked |= 1; + } } return(ret); } @@ -621,8 +651,8 @@ xmlSAX2GetParameterEntity(void *ctx, const xmlChar *na /** * xmlSAX2EntityDecl: * @ctx: the user data (XML parser context) - * @name: the entity name - * @type: the entity type + * @name: the entity name + * @type: the entity type * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @content: the entity value (without processing). @@ -657,7 +687,7 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int base = ctxt->input->filename; if (base == NULL) base = ctxt->directory; - + URI = xmlBuildURI(systemId, (const xmlChar *) base); ent->URI = URI; } @@ -666,7 +696,7 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int systemId, content); if ((ent == NULL) && (ctxt->pedantic) && (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + 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; @@ -676,7 +706,7 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int base = ctxt->input->filename; if (base == NULL) base = ctxt->directory; - + URI = xmlBuildURI(systemId, (const xmlChar *) base); ent->URI = URI; } @@ -691,8 +721,8 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int * xmlSAX2AttributeDecl: * @ctx: the user data (XML parser context) * @elem: the name of the element - * @fullname: the attribute name - * @type: the attribute type + * @fullname: the attribute name + * @type: the attribute type * @def: the type of default value * @defaultValue: the attribute default value * @tree: the tree of enumerated value set @@ -735,7 +765,7 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, c (xmlAttributeDefault) def, defaultValue, tree); else if (ctxt->inSubset == 2) attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem, - name, prefix, (xmlAttributeType) type, + name, prefix, (xmlAttributeType) type, (xmlAttributeDefault) def, defaultValue, tree); else { xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR, @@ -761,8 +791,8 @@ xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, c /** * xmlSAX2ElementDecl: * @ctx: the user data (XML parser context) - * @name: the element name - * @type: the element type + * @name: the element name + * @type: the element type * @content: the element value tree * * An element definition has been parsed @@ -883,7 +913,7 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *na publicId, systemId, notationName); if ((ent == NULL) && (ctxt->pedantic) && (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + 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; @@ -893,7 +923,7 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *na base = ctxt->input->filename; if (base == NULL) base = ctxt->directory; - + URI = xmlBuildURI(systemId, (const xmlChar *) base); ent->URI = URI; } @@ -903,7 +933,7 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *na publicId, systemId, notationName); if ((ent == NULL) && (ctxt->pedantic) && (ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + 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; @@ -913,7 +943,7 @@ xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *na base = ctxt->input->filename; if (base == NULL) base = ctxt->directory; - + URI = xmlBuildURI(systemId, (const xmlChar *) base); ent->URI = URI; } @@ -1157,12 +1187,12 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful uri = xmlParseURI((const char *)val); if (uri == NULL) { if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL)) - ctxt->sax->warning(ctxt->userData, + 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, + ctxt->sax->warning(ctxt->userData, "xmlns: URI %s is not absolute\n", val); } xmlFreeURI(uri); @@ -1182,7 +1212,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, ctxt->node, prefix, nsret, val); #endif /* LIBXML_VALID_ENABLED */ - if (name != NULL) + if (name != NULL) xmlFree(name); if (nval != NULL) xmlFree(nval); @@ -1204,7 +1234,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful if (val == NULL) { xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); xmlFree(ns); - if (name != NULL) + if (name != NULL) xmlFree(name); return; } @@ -1245,7 +1275,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc, ctxt->node, prefix, nsret, value); #endif /* LIBXML_VALID_ENABLED */ - if (name != NULL) + if (name != NULL) xmlFree(name); if (nval != NULL) xmlFree(nval); @@ -1311,7 +1341,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful #ifdef LIBXML_VALID_ENABLED if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed && ctxt->myDoc && ctxt->myDoc->intSubset) { - + /* * If we don't substitute entities, the validation should be * done on a value with replaced entities anyway. @@ -1323,7 +1353,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful 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); @@ -1380,7 +1410,7 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *ful error: if (nval != NULL) xmlFree(nval); - if (ns != NULL) + if (ns != NULL) xmlFree(ns); } @@ -1479,7 +1509,7 @@ process_external_subset: * - this is a namespace prefix * - the user required for completion in the tree * like XSLT - * - there isn't already an attribute definition + * - there isn't already an attribute definition * in the internal subset overriding it. */ if (((attr->prefix != NULL) && @@ -1568,18 +1598,18 @@ xmlSAX2StartElement(void *ctx, const xmlChar *fullname /* * First check on validity: */ - if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && + if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && ((ctxt->myDoc->intSubset == NULL) || - ((ctxt->myDoc->intSubset->notations == NULL) && + ((ctxt->myDoc->intSubset->notations == NULL) && (ctxt->myDoc->intSubset->elements == NULL) && - (ctxt->myDoc->intSubset->attributes == 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; } - + /* * Split the full name into a namespace prefix and the tag name */ @@ -1766,7 +1796,7 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRI else xmlGenericError(xmlGenericErrorContext, "SAX.xmlSAX2EndElement(%s)\n", name); #endif - + /* Capture end position and add node */ if (cur != NULL && ctxt->record_info) { ctxt->nodeInfo->end_pos = ctxt->input->cur - ctxt->input->base; @@ -1783,7 +1813,7 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRI cur); #endif /* LIBXML_VALID_ENABLED */ - + /* * end of parsing of this node. */ @@ -1799,9 +1829,9 @@ xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRI * @ctxt: the parser context * @str: the input string * @len: the string length - * - * Remove the entities from an attribute value * + * Callback for a text node + * * Returns the newly allocated string or NULL if not needed or error */ static xmlNodePtr @@ -1833,7 +1863,7 @@ xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar * if ((len < (int) (2 * sizeof(void *))) && (ctxt->options & XML_PARSE_COMPACT)) { - /* store the string in the node overrithing properties and nsDef */ + /* store the string in the node overriding properties and nsDef */ xmlChar *tmp = (xmlChar *) &(ret->properties); memcpy(tmp, str, len); tmp[len] = 0; @@ -1865,8 +1895,17 @@ skip: } else ret->content = (xmlChar *) intern; - if (ctxt->input != NULL) - ret->line = ctxt->input->line; + if (ctxt->linenumbers) { + if (ctxt->input != NULL) { + if (ctxt->input->line < 65535) + ret->line = (short) ctxt->input->line; + else { + ret->line = 65535; + if (ctxt->options & XML_PARSE_BIG_LINES) + ret->psvi = (void *) (long) ctxt->input->line; + } + } + } if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) xmlRegisterNodeDefaultValue(ret); @@ -1879,7 +1918,7 @@ skip: * @ctxt: the parser context * @str: the input string * @len: the string length - * + * * Remove the entities from an attribute value * * Returns the newly allocated string or NULL if not needed or error @@ -1945,7 +1984,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, memset(ret, 0, sizeof(xmlAttr)); ret->type = XML_ATTRIBUTE_NODE; - ret->parent = ctxt->node; + ret->parent = ctxt->node; ret->doc = ctxt->myDoc; ret->ns = namespace; @@ -1969,7 +2008,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, xmlRegisterNodeDefaultValue((xmlNodePtr)ret); } else { if (ctxt->dictNames) - ret = xmlNewNsPropEatName(ctxt->node, namespace, + ret = xmlNewNsPropEatName(ctxt->node, namespace, (xmlChar *) localname, NULL); else ret = xmlNewNsProp(ctxt->node, namespace, localname, NULL); @@ -2055,7 +2094,7 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt, xmlChar *nvalnorm; xmlChar fn[50]; xmlChar *fullname; - + fullname = xmlBuildQName(localname, prefix, fn, 50); if (fullname != NULL) { ctxt->vctxt.valid = 1; @@ -2170,13 +2209,13 @@ xmlSAX2StartElementNs(void *ctx, /* * First check on validity: */ - if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && + if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) && ((ctxt->myDoc->intSubset == NULL) || - ((ctxt->myDoc->intSubset->notations == NULL) && + ((ctxt->myDoc->intSubset->notations == NULL) && (ctxt->myDoc->intSubset->elements == NULL) && - (ctxt->myDoc->intSubset->attributes == NULL) && + (ctxt->myDoc->intSubset->attributes == NULL) && (ctxt->myDoc->intSubset->entities == NULL)))) { - xmlErrValid(ctxt, XML_ERR_NO_DTD, + xmlErrValid(ctxt, XML_DTD_NO_DTD, "Validation failed: no DTD found !", NULL, NULL); ctxt->validate = 0; } @@ -2221,12 +2260,12 @@ xmlSAX2StartElementNs(void *ctx, xmlRegisterNodeDefaultValue(ret); } else { if (ctxt->dictNames) - ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, + ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, (xmlChar *) localname, NULL); else if (lname == NULL) ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL); else - ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, + ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, (xmlChar *) lname, NULL); if (ret == NULL) { xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs"); @@ -2431,7 +2470,7 @@ xmlSAX2EndElementNs(void *ctx, * @ctx: the user data (XML parser context) * @name: The entity name * - * called when an entity xmlSAX2Reference is detected. + * called when an entity xmlSAX2Reference is detected. */ void xmlSAX2Reference(void *ctx, const xmlChar *name) @@ -2536,7 +2575,7 @@ xmlSAX2Characters(void *ctx, const xmlChar *ch, int le xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node"); return; } - if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len || + 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;