summaryrefslogtreecommitdiff
path: root/entities.c
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2005-03-27 13:13:58 +0000
committerMike Hommey <glandium@debian.org>2005-03-27 13:13:58 +0000
commit50e5b428562964b1eb2f876370058b34b47c5e90 (patch)
treec66bcae6dbbce07128ee881353ff60090524462c /entities.c
parenta7457388701e6ccba9091ba3ec09505dc903b758 (diff)
downloadlibxml2-50e5b428562964b1eb2f876370058b34b47c5e90.tar.gz
Load /tmp/tmp.XJZ6qc/libxml2-2.6.18 intoupstream/2.6.18
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'entities.c')
-rw-r--r--entities.c96
1 files changed, 72 insertions, 24 deletions
diff --git a/entities.c b/entities.c
index 913a4e6..619a4d6 100644
--- a/entities.c
+++ b/entities.c
@@ -20,6 +20,7 @@
#include <libxml/parserInternals.h>
#include <libxml/xmlerror.h>
#include <libxml/globals.h>
+#include <libxml/dict.h>
/*
* The XML predefined entities.
@@ -89,24 +90,51 @@ xmlEntitiesErr(xmlParserErrors code, const char *msg)
/*
* xmlFreeEntity : clean-up an entity record.
*/
-static void xmlFreeEntity(xmlEntityPtr entity) {
- if (entity == NULL) return;
+static void
+xmlFreeEntity(xmlEntityPtr entity)
+{
+ xmlDictPtr dict = NULL;
+
+ if (entity == NULL)
+ return;
+
+ if (entity->doc != NULL)
+ dict = entity->doc->dict;
+
if ((entity->children) && (entity->owner == 1) &&
- (entity == (xmlEntityPtr) entity->children->parent))
- xmlFreeNodeList(entity->children);
- if (entity->name != NULL)
- xmlFree((char *) entity->name);
- if (entity->ExternalID != NULL)
- xmlFree((char *) entity->ExternalID);
- if (entity->SystemID != NULL)
- xmlFree((char *) entity->SystemID);
- if (entity->URI != NULL)
- xmlFree((char *) entity->URI);
- if (entity->content != NULL)
- xmlFree((char *) entity->content);
- if (entity->orig != NULL)
- xmlFree((char *) entity->orig);
+ (entity == (xmlEntityPtr) entity->children->parent))
+ xmlFreeNodeList(entity->children);
+ if (dict != NULL) {
+ if ((entity->name != NULL) && (!xmlDictOwns(dict, entity->name)))
+ xmlFree((char *) entity->name);
+ if ((entity->ExternalID != NULL) &&
+ (!xmlDictOwns(dict, entity->ExternalID)))
+ xmlFree((char *) entity->ExternalID);
+ if ((entity->SystemID != NULL) &&
+ (!xmlDictOwns(dict, entity->SystemID)))
+ xmlFree((char *) entity->SystemID);
+ if ((entity->URI != NULL) && (!xmlDictOwns(dict, entity->URI)))
+ xmlFree((char *) entity->URI);
+ if ((entity->content != NULL)
+ && (!xmlDictOwns(dict, entity->content)))
+ xmlFree((char *) entity->content);
+ if ((entity->orig != NULL) && (!xmlDictOwns(dict, entity->orig)))
+ xmlFree((char *) entity->orig);
+ } else {
+ if (entity->name != NULL)
+ xmlFree((char *) entity->name);
+ if (entity->ExternalID != NULL)
+ xmlFree((char *) entity->ExternalID);
+ if (entity->SystemID != NULL)
+ xmlFree((char *) entity->SystemID);
+ if (entity->URI != NULL)
+ xmlFree((char *) entity->URI);
+ if (entity->content != NULL)
+ xmlFree((char *) entity->content);
+ if (entity->orig != NULL)
+ xmlFree((char *) entity->orig);
+ }
xmlFree(entity);
}
@@ -117,23 +145,29 @@ static xmlEntityPtr
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
const xmlChar *ExternalID, const xmlChar *SystemID,
const xmlChar *content) {
+ xmlDictPtr dict = NULL;
xmlEntitiesTablePtr table = NULL;
xmlEntityPtr ret;
if (name == NULL)
return(NULL);
+ if (dtd == NULL)
+ return(NULL);
+ if (dtd->doc != NULL)
+ dict = dtd->doc->dict;
+
switch (type) {
case XML_INTERNAL_GENERAL_ENTITY:
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
if (dtd->entities == NULL)
- dtd->entities = xmlHashCreate(0);
+ dtd->entities = xmlHashCreateDict(0, dict);
table = dtd->entities;
break;
case XML_INTERNAL_PARAMETER_ENTITY:
case XML_EXTERNAL_PARAMETER_ENTITY:
if (dtd->pentities == NULL)
- dtd->pentities = xmlHashCreate(0);
+ dtd->pentities = xmlHashCreateDict(0, dict);
table = dtd->pentities;
break;
case XML_INTERNAL_PREDEFINED_ENTITY:
@@ -152,15 +186,27 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
/*
* fill the structure.
*/
- ret->name = xmlStrdup(name);
ret->etype = (xmlEntityType) type;
- if (ExternalID != NULL)
- ret->ExternalID = xmlStrdup(ExternalID);
- if (SystemID != NULL)
- ret->SystemID = xmlStrdup(SystemID);
+ if (dict == NULL) {
+ ret->name = xmlStrdup(name);
+ if (ExternalID != NULL)
+ ret->ExternalID = xmlStrdup(ExternalID);
+ if (SystemID != NULL)
+ ret->SystemID = xmlStrdup(SystemID);
+ } else {
+ ret->name = xmlDictLookup(dict, name, -1);
+ if (ExternalID != NULL)
+ ret->ExternalID = xmlDictLookup(dict, ExternalID, -1);
+ if (SystemID != NULL)
+ ret->SystemID = xmlDictLookup(dict, SystemID, -1);
+ }
if (content != NULL) {
ret->length = xmlStrlen(content);
- ret->content = xmlStrndup(content, ret->length);
+ if ((dict != NULL) && (ret->length < 5))
+ ret->content = (xmlChar *)
+ xmlDictLookup(dict, content, ret->length);
+ else
+ ret->content = xmlStrndup(content, ret->length);
} else {
ret->length = 0;
ret->content = NULL;
@@ -169,6 +215,7 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
the defining entity */
ret->orig = NULL;
ret->owner = 0;
+ ret->doc = dtd->doc;
if (xmlHashAddEntry(table, name, ret)) {
/*
@@ -679,6 +726,7 @@ xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) {
* xmlCreateEntitiesTable:
*
* create and initialize an empty entities hash table.
+ * This really doesn't make sense and should be deprecated
*
* Returns the xmlEntitiesTablePtr just created or NULL in case of error.
*/