summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Stocker <chregu@php.net>2003-04-09 07:29:39 +0000
committerChristian Stocker <chregu@php.net>2003-04-09 07:29:39 +0000
commit6f9d53e02d49dc2d19c62cfd012af26f4989e7d1 (patch)
tree063addd461ac0241a7421a6286d17764dbb9069f
parent7029ef01b39338397b76a4adcd59dccbb7afbace (diff)
downloadphp-git-6f9d53e02d49dc2d19c62cfd012af26f4989e7d1.tar.gz
- Fixed some memleaks when using attributes
- Added attrnode->set_value() (by Rob Richards)
-rw-r--r--ext/domxml/php_domxml.c44
-rw-r--r--ext/domxml/php_domxml.h3
2 files changed, 44 insertions, 3 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c
index 41c25746f8..fc3b68b839 100644
--- a/ext/domxml/php_domxml.c
+++ b/ext/domxml/php_domxml.c
@@ -513,6 +513,7 @@ static zend_function_entry php_domxmlattr_class_functions[] = {
PHP_FALIAS(name, domxml_attr_name, NULL)
PHP_FALIAS(value, domxml_attr_value, NULL)
PHP_FALIAS(specified, domxml_attr_specified, NULL)
+ PHP_FALIAS(set_value, domxml_attr_set_value, NULL)
/*
PHP_FALIAS(owner_element, domxml_attr_owner_element, NULL)
*/
@@ -757,6 +758,8 @@ static void php_free_xml_attr(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
xmlNodePtr node = (xmlNodePtr) rsrc->ptr;
if (node->parent == NULL) {
+ /* Attribute Nodes contain accessible children */
+ node_list_wrapper_dtor(node->children, 0);
node_wrapper_dtor(node);
xmlFreeProp((xmlAttrPtr) node);
} else {
@@ -1818,12 +1821,42 @@ PHP_FUNCTION(domxml_attr_value)
{
zval *id;
xmlAttrPtr attrp;
+ xmlChar *content;
DOMXML_GET_THIS_OBJ(attrp, id, le_domxmlattrp);
DOMXML_NO_ARGS();
- RETURN_STRING((char *) xmlNodeGetContent((xmlNodePtr) attrp), 1);
+ /* RETURN_STRING((char *) xmlNodeGetContent((xmlNodePtr) attrp), 1); */
+ if (content = xmlNodeGetContent((xmlNodePtr) attrp)) {
+ RETVAL_STRING(content,1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ xmlFree(content);
+}
+/* }}} */
+
+/* {{{ proto bool domxml_attr_set_value(string content)
+ Set value of attribute */
+PHP_FUNCTION(domxml_attr_set_value)
+{
+ zval *id;
+ xmlAttrPtr attrp;
+ int content_len;
+ char *content;
+
+ DOMXML_PARAM_TWO(attrp, id, le_domxmlattrp, "s", &content, &content_len);
+
+ /* If attribute has children unlink referenced nodes
+ Spec indicates that content is to be overwritten and not appended
+ xmlNodeSetContentLen will take care of removing and freeing the rest */
+ if (attrp->children) {
+ node_list_unlink(((xmlNodePtr) attrp) ->children);
+ }
+ xmlNodeSetContentLen((xmlNodePtr) attrp, content, content_len);
+ RETURN_TRUE;
+
}
/* }}} */
@@ -1869,12 +1902,19 @@ PHP_FUNCTION(domxml_pi_data)
{
zval *id;
xmlNodePtr nodep;
+ xmlChar *content;
DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlpip);
DOMXML_NO_ARGS();
- RETURN_STRING(xmlNodeGetContent(nodep), 1);
+ /* RETURN_STRING(xmlNodeGetContent(nodep), 1); */
+ if (content = xmlNodeGetContent(nodep)) {
+ RETVAL_STRING(content,1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ xmlFree(content);
}
/* }}} */
diff --git a/ext/domxml/php_domxml.h b/ext/domxml/php_domxml.h
index e7c6c86323..b1b0cdb541 100644
--- a/ext/domxml/php_domxml.h
+++ b/ext/domxml/php_domxml.h
@@ -1,4 +1,4 @@
-/*
+/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
@@ -165,6 +165,7 @@ PHP_FUNCTION(domxml_is_blank_node);
PHP_FUNCTION(domxml_attr_name);
PHP_FUNCTION(domxml_attr_value);
PHP_FUNCTION(domxml_attr_specified);
+PHP_FUNCTION(domxml_attr_set_value);
/* Class Element methods */
PHP_FUNCTION(domxml_elem_tagname);