diff options
author | Mike Hommey <glandium@debian.org> | 2006-01-06 18:28:17 +0100 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2006-01-06 18:28:17 +0100 |
commit | 0fd83af441e251fc23fc1af7959fd6ecfa105fe1 (patch) | |
tree | a2b35749a66abce02e6f07983ef50618d93bef58 /tree.c | |
parent | 17049f05f9ef09b3dc2a9c5d1de3f21de7c03193 (diff) | |
download | libxml2-0fd83af441e251fc23fc1af7959fd6ecfa105fe1.tar.gz |
Load /tmp/tmp.U9vXwU/libxml2-2.6.23 intoupstream/2.6.23
local/libxml2/branches/upstream/current.
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 95 |
1 files changed, 69 insertions, 26 deletions
@@ -2012,6 +2012,8 @@ xmlRemoveProp(xmlAttrPtr cur) { tmp = cur->parent->properties; if (tmp == cur) { cur->parent->properties = cur->next; + if (cur->next != NULL) + cur->next->prev = NULL; xmlFreeProp(cur); return(0); } @@ -2831,6 +2833,14 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { return(NULL); } + if (cur == elem) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddNextSibling : cur == elem\n"); +#endif + return(NULL); + } + xmlUnlinkNode(elem); if (elem->type == XML_TEXT_NODE) { @@ -2854,12 +2864,16 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { /* check if an attribute with the same name exists */ xmlAttrPtr attr; + if (cur->type != XML_ATTRIBUTE_NODE) + return(NULL); if (elem->ns == NULL) - attr = xmlHasProp(cur->parent, elem->name); + attr = xmlHasNsProp(cur->parent, elem->name, NULL); else attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); - if ((attr != NULL) && (attr != (xmlAttrPtr) elem)) { + /* elem has already been unlinked so can never be attr */ + if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { /* different instance, destroy it (attributes must be unique) */ + xmlUnlinkNode((xmlNodePtr) attr); xmlFreeProp(attr); } } @@ -2911,6 +2925,14 @@ xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { return(NULL); } + if (cur == elem) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddPrevSibling : cur == elem\n"); +#endif + return(NULL); + } + xmlUnlinkNode(elem); if (elem->type == XML_TEXT_NODE) { @@ -2934,12 +2956,16 @@ xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { /* check if an attribute with the same name exists */ xmlAttrPtr attr; + if (cur->type != XML_ATTRIBUTE_NODE) + return(NULL); if (elem->ns == NULL) - attr = xmlHasProp(cur->parent, elem->name); + attr = xmlHasNsProp(cur->parent, elem->name, NULL); else attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); - if ((attr != NULL) && (attr != (xmlAttrPtr) elem)) { + /* elem has already been unlinked so can never be attr */ + if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { /* different instance, destroy it (attributes must be unique) */ + xmlUnlinkNode((xmlNodePtr) attr); xmlFreeProp(attr); } } @@ -3149,6 +3175,13 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { return(NULL); } + if (parent == cur) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlAddChild : parent == cur\n"); +#endif + return(NULL); + } /* * If cur is a TEXT node, merge its content with adjacent TEXT nodes * cur is then freed. @@ -3156,8 +3189,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { if (cur->type == XML_TEXT_NODE) { if ((parent->type == XML_TEXT_NODE) && (parent->content != NULL) && - (parent->name == cur->name) && - (parent != cur)) { + (parent->name == cur->name)) { xmlNodeAddContent(parent, cur->content); xmlFreeNode(cur); return(parent); @@ -3196,6 +3228,8 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { return(parent); } if (cur->type == XML_ATTRIBUTE_NODE) { + if (parent->type != XML_ELEMENT_NODE) + return(NULL); if (parent->properties == NULL) { parent->properties = (xmlAttrPtr) cur; } else { @@ -3203,13 +3237,16 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { xmlAttrPtr lastattr; if (cur->ns == NULL) - lastattr = xmlHasProp(parent, cur->name); + lastattr = xmlHasNsProp(parent, cur->name, NULL); else lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href); - if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur)) { + if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur) && (lastattr->type != XML_ATTRIBUTE_DECL)) { /* different instance, destroy it (attributes must be unique) */ + xmlUnlinkNode((xmlNodePtr) lastattr); xmlFreeProp(lastattr); } + if (lastattr == (xmlAttrPtr) cur) + return(cur); /* find the end */ lastattr = parent->properties; while (lastattr->next != NULL) { @@ -3575,22 +3612,16 @@ xmlCopyNamespaceList(xmlNsPtr cur) { static xmlNodePtr xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); -/** - * xmlCopyProp: - * @target: the element where the attribute will be grafted - * @cur: the attribute - * - * Do a copy of the attribute. - * - * Returns: a new #xmlAttrPtr, or NULL in case of error. - */ -xmlAttrPtr -xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { + +static xmlAttrPtr +xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { xmlAttrPtr ret; if (cur == NULL) return(NULL); if (target != NULL) ret = xmlNewDocProp(target->doc, cur->name, NULL); + else if (doc != NULL) + ret = xmlNewDocProp(doc, cur->name, NULL); else if (cur->parent != NULL) ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); else if (cur->children != NULL) @@ -3679,6 +3710,20 @@ xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { } /** + * xmlCopyProp: + * @target: the element where the attribute will be grafted + * @cur: the attribute + * + * Do a copy of the attribute. + * + * Returns: a new #xmlAttrPtr, or NULL in case of error. + */ +xmlAttrPtr +xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { + return xmlCopyPropInternal(NULL, target, cur); +} + +/** * xmlCopyPropList: * @target: the element where the attributes will be grafted * @cur: the first attribute @@ -3746,7 +3791,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, case XML_XINCLUDE_END: break; case XML_ATTRIBUTE_NODE: - return((xmlNodePtr) xmlCopyProp(parent, (xmlAttrPtr) node)); + return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr) node)); case XML_NAMESPACE_DECL: return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node)); @@ -4861,8 +4906,8 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) xmlBufferCat(buffer, tmp->content); break; case XML_ENTITY_REF_NODE: - xmlNodeBufGetContent(buffer, tmp->children); - break; + xmlNodeBufGetContent(buffer, tmp); + break; default: break; } @@ -6258,7 +6303,7 @@ xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { */ int xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { - xmlAttrPtr prop, prev = NULL;; + xmlAttrPtr prop; if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) return(-1); @@ -6270,7 +6315,6 @@ xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { xmlFreeProp(prop); return(0); } - prev = prop; prop = prop->next; } return(-1); @@ -6287,7 +6331,7 @@ xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { */ int xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { - xmlAttrPtr prop, prev = NULL;; + xmlAttrPtr prop; if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) return(-1); @@ -6303,7 +6347,6 @@ xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { xmlFreeProp(prop); return(0); } - prev = prop; prop = prop->next; } return(-1); |