Hello, This patch does two things.
Allows for php new/constructors to all of the dom nodes.. ex - new $var = new DomDocument("some.file", true); - old $var = xmldoc("some.file", true); // small example how you would use it $var = new DomDocument("some.file", true); $var = new DomElement("name"); $var->set_content("some_content"); $doc->append_child($var); $var = new DomElement("name"); $var = new DomText("name"); $var = new DomComment("comment"); $var = new DomAttribute("name", "value"); $var = new DomCData("data"); $var = new DomEnitityRefrence("data"); $var = new DomProcessingInstruction("data", "data"); and for all you c-programmers out there.... this patch also exports php_domobject_new() this will alow developers to create php_domobjects from there libxml2 node and pass it into userspace. If noone objects..... Ill commit it. - Brad __________________________________________________ Do You Yahoo!? Yahoo! Shopping - Mother's Day is May 12th! http://shopping.yahoo.com
--- php_domxml.cvs.c Sun May 5 18:26:09 2002 +++ out.c Thu May 9 22:01:12 2002 @@ -22,6 +22,7 @@ * - Support Notation Nodes * */ +#define PHP_EXPORTS #ifdef HAVE_CONFIG_H #include "config.h" @@ -36,7 +37,10 @@ #define PHP_XPTR 2 /* General macros used by domxml */ -#define DOMXML_DOMOBJ_NEW(zval, obj, ret) if (NULL == (zval = php_domobject_new(obj, ret TSRMLS_CC))) { \ + +#define DOMXML_IS_TYPE(zval, ce) (zval && +Z_TYPE_P(zval) == IS_OBJECT && Z_OBJCE_P(zval)->refcount == ce->refcount) + +#define DOMXML_DOMOBJ_NEW(zval, obj, ret) if (NULL == (zval = +php_domobject_new(obj, ret, zval TSRMLS_CC))) { \ php_error(E_WARNING, "%s(): cannot create required DOM object", \ get_active_function_name(TSRMLS_C)); \ RETURN_FALSE; \ @@ -261,6 +265,7 @@ static function_entry php_domxmldoc_class_functions[] = { + PHP_FALIAS(domdocument, xmldoc, + NULL) PHP_FALIAS(doctype, domxml_doc_doctype, NULL) PHP_FALIAS(implementation, domxml_doc_implementation, NULL) PHP_FALIAS(document_element, domxml_doc_document_element, NULL) @@ -360,7 +365,7 @@ }; static zend_function_entry php_domxmlelement_class_functions[] = { - PHP_FALIAS(domelement, domxml_element, NULL) + PHP_FALIAS(domelement, domxml_doc_create_element, + NULL) PHP_FALIAS(name, domxml_elem_tagname, NULL) PHP_FALIAS(tagname, domxml_elem_tagname, NULL) PHP_FALIAS(get_attribute, domxml_elem_get_attribute, NULL) @@ -374,15 +379,18 @@ }; static zend_function_entry php_domxmlcdata_class_functions[] = { + PHP_FALIAS(domcdata, +domxml_doc_create_cdata_section,NULL) PHP_FALIAS(length, domxml_cdata_length, NULL) {NULL, NULL, NULL} }; static zend_function_entry php_domxmltext_class_functions[] = { + PHP_FALIAS(domtext, +domxml_doc_create_text_node, NULL) {NULL, NULL, NULL} }; static zend_function_entry php_domxmlcomment_class_functions[] = { + PHP_FALIAS(domcomment, domxml_doc_create_comment, + NULL) {NULL, NULL, NULL} }; @@ -393,6 +401,7 @@ }; static zend_function_entry php_domxmlentityref_class_functions[] = { + PHP_FALIAS(domentityreference, domxml_doc_create_entity_reference, + NULL) {NULL, NULL, NULL} }; @@ -406,6 +415,7 @@ }; static zend_function_entry php_domxmlpi_class_functions[] = { + PHP_FALIAS(domprocessinginstruction, domxml_doc_create_processing_instruction, +NULL) PHP_FALIAS(target, domxml_pi_target, NULL) PHP_FALIAS(data, domxml_pi_data, NULL) {NULL, NULL, NULL} @@ -425,6 +435,7 @@ #endif static zend_function_entry php_domxmlattr_class_functions[] = { + PHP_FALIAS(domattribute, domxml_doc_create_attribute, + NULL) PHP_FALIAS(name, domxml_attr_name, NULL) PHP_FALIAS(value, domxml_attr_value, NULL) PHP_FALIAS(specified, domxml_attr_specified, NULL) @@ -613,7 +624,7 @@ if (parser) { zval *wrapper = dom_object_get_data(parser); - zval_ptr_dtor(&wrapper); + zval_ptr_dtor(&wrapper); xmlFreeParserCtxt(parser); } } @@ -1014,7 +1025,7 @@ } -static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC) +PHPAPI zval *php_domobject_new(xmlNodePtr obj, int *found, zval *wrapper_in +TSRMLS_DC) { zval *wrapper; char *content; @@ -1023,7 +1034,12 @@ *found = 0; if (!obj) { + if(!wrapper_in) + { MAKE_STD_ZVAL(wrapper); + } + else + wrapper = wrapper_in; ZVAL_NULL(wrapper); return wrapper; } @@ -1034,7 +1050,12 @@ return wrapper; } + if(!wrapper_in) + { MAKE_STD_ZVAL(wrapper); + } + else + wrapper = wrapper_in; switch (Z_TYPE_P(obj)) { @@ -1270,49 +1291,49 @@ le_domxsltstylesheetp = zend_register_list_destructors_ex(php_free_xslt_stylesheet, NULL, "xsltstylesheet", module_number); #endif - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomNode", php_domxmlnode_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domnode", php_domxmlnode_class_functions, +NULL, NULL, NULL); domxmlnode_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomDocument", php_domxmldoc_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domdocument", php_domxmldoc_class_functions, +NULL, NULL, NULL); domxmldoc_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomParser", php_domxmlparser_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domparser", php_domxmlparser_class_functions, +NULL, NULL, NULL); domxmlparser_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomDocumentType", php_domxmldoctype_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domdocumenttype", +php_domxmldoctype_class_functions, NULL, NULL, NULL); domxmldoctype_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "Dtd", php_domxmldtd_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "dtd", php_domxmldtd_class_functions, NULL, +NULL, NULL); domxmldtd_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomElement", php_domxmlelement_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domelement", +php_domxmlelement_class_functions, NULL, NULL, NULL); domxmlelement_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomAttribute", php_domxmlattr_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domattribute", +php_domxmlattr_class_functions, NULL, NULL, NULL); domxmlattr_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomCData", php_domxmlcdata_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domcdata", php_domxmlcdata_class_functions, +NULL, NULL, NULL); domxmlcdata_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomText", php_domxmltext_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domtext", php_domxmltext_class_functions, +NULL, NULL, NULL); domxmltext_class_entry = zend_register_internal_class_ex(&ce, domxmlcdata_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomComment", php_domxmlcomment_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domcomment", +php_domxmlcomment_class_functions, NULL, NULL, NULL); domxmlcomment_class_entry = zend_register_internal_class_ex(&ce, domxmlcdata_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomProcessingInstruction", php_domxmlpi_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domprocessinginstruction", +php_domxmlpi_class_functions, NULL, NULL, NULL); domxmlpi_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomNotation", php_domxmlnotation_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domnotation", +php_domxmlnotation_class_functions, NULL, NULL, NULL); domxmlnotation_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomEntity", php_domxmlentity_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domentity", php_domxmlentity_class_functions, +NULL, NULL, NULL); domxmlentity_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomEntityReference", php_domxmlentityref_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domentityreference", +php_domxmlentityref_class_functions, NULL, NULL, NULL); domxmlentityref_class_entry = zend_register_internal_class_ex(&ce, domxmlnode_class_entry, NULL TSRMLS_CC); - INIT_OVERLOADED_CLASS_ENTRY(ce, "DomNamespace", php_domxmlns_class_functions, NULL, NULL, NULL); + INIT_OVERLOADED_CLASS_ENTRY(ce, "domnamespace", php_domxmlns_class_functions, +NULL, NULL, NULL); domxmlns_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC); #if defined(LIBXML_XPATH_ENABLED) @@ -1436,8 +1457,8 @@ /* {{{ Methods of Class DomAttribute */ /* {{{ proto array domxml_attr_name(void) - Returns list of attribute names - Notice: domxml_node_name() does exactly the same for attribute-nodes, + Returns list of attribute names + Notice: domxml_node_name() does exactly the same for attribute-nodes, is this function here still needed, or would an alias be enough? */ PHP_FUNCTION(domxml_attr_name) @@ -1549,7 +1570,7 @@ Creates node */ PHP_FUNCTION(domxml_node) { - zval *rv; + zval *rv = NULL; xmlNode *node; int ret, name_len; char *name; @@ -1563,7 +1584,11 @@ RETURN_FALSE; } - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlnode_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -1702,7 +1727,7 @@ Clones a node */ PHP_FUNCTION(domxml_clone_node) { - zval *rv; + zval *rv = NULL; zval *id; xmlNode *n, *node; int ret, recursive = 0;; @@ -1726,7 +1751,7 @@ Returns first child from list of children */ PHP_FUNCTION(domxml_node_first_child) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep, *first; int ret; @@ -1747,7 +1772,7 @@ Returns last child from list of children */ PHP_FUNCTION(domxml_node_last_child) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep, *last; int ret; @@ -1768,7 +1793,7 @@ Returns next child from list of children */ PHP_FUNCTION(domxml_node_next_sibling) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep, *first; int ret; @@ -1789,7 +1814,7 @@ Returns previous child from list of children */ PHP_FUNCTION(domxml_node_previous_sibling) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep, *first; int ret; @@ -1810,7 +1835,7 @@ Returns document this node belongs to */ PHP_FUNCTION(domxml_node_owner_document) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep; xmlDocPtr docp; int ret; @@ -1898,7 +1923,7 @@ Returns parent of node */ PHP_FUNCTION(domxml_node_parent) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep, *last; int ret; @@ -1942,7 +1967,7 @@ while (last) { zval *child; - child = php_domobject_new(last, &ret TSRMLS_CC); + child = php_domobject_new(last, &ret, NULL TSRMLS_CC); add_next_index_zval(return_value, child); last = last->next; } @@ -1959,7 +1984,7 @@ DOMXML_PARAM_NONE(nodep, id, le_domxmlnodep); xmlUnlinkNode(nodep); - /* This causes a Segmentation Fault for some reason. Removing + /* This causes a Segmentation Fault for some reason. Removing it allows the user to re-add the node at some other time, in addition to fixing the segfault. Node will be freed at shutdown. */ @@ -1972,7 +1997,7 @@ Replaces one node with another node */ PHP_FUNCTION(domxml_node_replace_node) { - zval *id, *rv, *node; + zval *id, *rv = NULL, *node; xmlNodePtr repnode, nodep, new_repnode; int ret; @@ -2008,7 +2033,7 @@ Adds node to list of children */ PHP_FUNCTION(domxml_node_append_child) { - zval *id, *rv, *node; + zval *id, *rv = NULL, *node; xmlNodePtr child, nodep, new_child; int ret; @@ -2050,7 +2075,7 @@ Adds node to list of siblings */ PHP_FUNCTION(domxml_node_append_sibling) { - zval *id, *rv, *node; + zval *id, *rv = NULL, *node; xmlNodePtr child, nodep, new_child; int ret; @@ -2088,7 +2113,7 @@ Adds node in list of nodes before given node */ PHP_FUNCTION(domxml_node_insert_before) { - zval *id, *rv, *node, *ref; + zval *id, *rv = NULL, *node, *ref; xmlNodePtr child, new_child, nodep, refp; int ret; @@ -2140,7 +2165,7 @@ while (children) { if (children == child) { - zval *rv; + zval *rv = NULL; xmlUnlinkNode(child); DOMXML_RET_OBJ(rv, child, &ret); return; @@ -2188,7 +2213,7 @@ * a child, then do the replacement */ if(foundoldchild && !foundnewchild) { - zval *rv; + zval *rv = NULL; xmlNodePtr node; node = xmlReplaceNode(oldchild, newchild); DOMXML_RET_OBJ(rv, oldchild, &ret); @@ -2199,7 +2224,7 @@ * the new node are identical. */ if(foundnewchild) { - zval *rv; + zval *rv = NULL; DOMXML_RET_OBJ(rv, newchild, &ret); return; } else { @@ -2269,7 +2294,7 @@ Adds child node to parent node */ PHP_FUNCTION(domxml_node_new_child) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNodePtr child, nodep; int ret, name_len, content_len; char *name, *content = NULL; @@ -2310,14 +2335,14 @@ /* FIXME: Actually the property 'content' of the node has to be updated as well. Since 'content' should disappear sooner or later and being replaces by a function 'content()' I skip this for now - */ + */ RETURN_TRUE; } /* }}} */ /* {{{ proto string domxml_node_get_content() Gets content of a node. - + "Read the value of a node, this can be either the text carried directly by this node if it's a TEXT node or the aggregate string of the values carried by this node child's (TEXT and ENTITY_REF). Entity references are substituted." @@ -2333,7 +2358,7 @@ if (!mem) { RETURN_FALSE; } - + RETVAL_STRING(mem,1); xmlFree(mem); } @@ -2392,7 +2417,7 @@ Constructor of DomElement */ PHP_FUNCTION(domxml_element) { - zval *rv; + zval *rv = NULL; xmlNode *node; int ret, name_len; char *name; @@ -2453,7 +2478,7 @@ Sets value of given attribute */ PHP_FUNCTION(domxml_elem_set_attribute) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep; xmlAttr *attr; int ret, name_len, value_len; @@ -2480,7 +2505,7 @@ xmlAttr *attrp; int name_len; char *name; - + DOMXML_PARAM_TWO(nodep, id, le_domxmlelementp, "s", &name, &name_len); attrp = xmlHasProp(nodep,name); if (attrp == NULL) { @@ -2495,7 +2520,7 @@ Returns value of given attribute */ PHP_FUNCTION(domxml_elem_get_attribute_node) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *nodep; xmlAttr *attrp; int name_len, ret; @@ -2514,7 +2539,7 @@ Sets value of given attribute */ PHP_FUNCTION(domxml_elem_set_attribute_node) { - zval *id, *arg1, *rv; + zval *id, *arg1, *rv = NULL; xmlNode *nodep; xmlAttr *attrp, *newattrp; int ret; @@ -2577,7 +2602,7 @@ contextnodep = NULL; DOMXML_PARAM_FOUR(docp, id, le_domxmldocp, "s|oo", &name, &name_len,&ctxpin,&contextnodep); - + /* if no xpath_context was submitted, create a new one */ if (ctxpin == NULL) { ctxp = xmlXPathNewContext(docp); @@ -2627,7 +2652,7 @@ int retnode; /* construct a node object */ - child = php_domobject_new(node, &retnode TSRMLS_CC); + child = php_domobject_new(node, &retnode, NULL +TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(rv), &child, sizeof(zval *), NULL); } @@ -2670,10 +2695,10 @@ ids = (xmlHashTable *) docp->ids; if(ids) { - iter.elementId = (xmlChar *) + iter.elementId = (xmlChar *) iter.element = NULL; - xmlHashScan(ids, idsHashScanner, &iter); - rv = php_domobject_new(iter.element, &retnode TSRMLS_CC); + xmlHashScan(ids, (void *)idsHashScanner, &iter); + rv = php_domobject_new(iter.element, &retnode, NULL TSRMLS_CC); SEPARATE_ZVAL(&rv); *return_value = *rv; FREE_ZVAL(rv); @@ -2697,7 +2722,7 @@ DOMXML_PARAM_TWO(nodep, id, le_domxmlelementp, "s", &name, &name_len); MAKE_STD_ZVAL(rv); - + if(array_init(rv) != SUCCESS) { php_error(E_WARNING, "%s(): cannot create required array", get_active_function_name(TSRMLS_C)); RETURN_FALSE; @@ -2711,7 +2736,7 @@ zval *child; int retnode; - child = php_domobject_new(node, &retnode TSRMLS_CC); + child = php_domobject_new(node, &retnode, NULL TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(rv), &child, sizeof(zval *), NULL); } } @@ -2803,7 +2828,7 @@ while (last) { zval *child; - child = php_domobject_new(last, &ret TSRMLS_CC); + child = php_domobject_new(last, &ret, NULL TSRMLS_CC); add_next_index_zval(return_value, child); last = last->next; } @@ -2834,7 +2859,7 @@ while (last) { zval *child; - child = php_domobject_new(last, &ret TSRMLS_CC); + child = php_domobject_new(last, &ret, NULL TSRMLS_CC); add_next_index_zval(return_value, child); last = last->next; } @@ -2850,7 +2875,7 @@ Returns DomDocumentType */ PHP_FUNCTION(domxml_doc_doctype) { - zval *id, *rv; + zval *id, *rv = NULL; xmlDtdPtr dtd; xmlDocPtr docp; int ret; @@ -2913,7 +2938,7 @@ while (node) { if (Z_TYPE_P(node) == XML_ELEMENT_NODE) { - zval *rv; + zval *rv = NULL; DOMXML_RET_OBJ(rv, node, &ret); return; } @@ -2926,13 +2951,15 @@ Creates new element node */ PHP_FUNCTION(domxml_doc_create_element) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, name_len; char *name; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlelement_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; @@ -2944,7 +2971,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlelement_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -2952,13 +2983,15 @@ Creates new text node */ PHP_FUNCTION(domxml_doc_create_text_node) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, content_len; char *content; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmltext_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &content, &content_len) == FAILURE) { return; @@ -2970,7 +3003,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmltext_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -2978,13 +3015,15 @@ Creates new comment node */ PHP_FUNCTION(domxml_doc_create_comment) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, content_len; char *content; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlcomment_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &content, &content_len) == FAILURE) { return; @@ -2996,7 +3035,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlcomment_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -3004,13 +3047,15 @@ Creates new attribute node */ PHP_FUNCTION(domxml_doc_create_attribute) { - zval *id, *rv; + zval *id, *rv = NULL; xmlAttrPtr node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, name_len, value_len; char *name, *value; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlattr_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) { return; @@ -3022,7 +3067,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, (xmlNodePtr) node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlattr_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), (xmlNodePtr) node, &ret); + } else { + DOMXML_RET_OBJ(rv, (xmlNodePtr) node, &ret); + } } /* }}} */ @@ -3030,13 +3079,15 @@ Creates new cdata node */ PHP_FUNCTION(domxml_doc_create_cdata_section) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, content_len; char *content; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlcdata_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &content, &content_len) == FAILURE) { return; @@ -3048,7 +3099,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlcdata_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -3056,13 +3111,15 @@ Creates new cdata node */ PHP_FUNCTION(domxml_doc_create_entity_reference) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, name_len; char *name; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlentityref_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; @@ -3073,7 +3130,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlentityref_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -3081,13 +3142,15 @@ Creates new processing_instruction node */ PHP_FUNCTION(domxml_doc_create_processing_instruction) { - zval *id, *rv; + zval *id, *rv = NULL; xmlNode *node; - xmlDocPtr docp; + xmlDocPtr docp = NULL; int ret, name_len, content_len; char *name, *content; - DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + if(!DOMXML_IS_TYPE(getThis(), domxmlpi_class_entry)) { + DOMXML_GET_THIS_OBJ(docp, id, le_domxmldocp); + } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &content, &content_len) == FAILURE) { return; @@ -3099,7 +3162,11 @@ } node->doc = docp; - DOMXML_RET_OBJ(rv, node, &ret); + if(DOMXML_IS_TYPE(getThis(), domxmlpi_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), node, &ret); + } else { + DOMXML_RET_OBJ(rv, node, &ret); + } } /* }}} */ @@ -3107,7 +3174,7 @@ Creates new element node */ PHP_FUNCTION(domxml_doc_imported_node) { - zval *arg1, *id, *rv; + zval *arg1, *id, *rv = NULL; xmlNodePtr node, srcnode; xmlDocPtr docp; int ret, recursive = 0; @@ -3135,7 +3202,7 @@ Returns DTD of document */ PHP_FUNCTION(domxml_intdtd) { - zval *id, *rv; + zval *id, *rv = NULL; xmlDoc *docp; xmlDtd *dtd; int ret; @@ -3162,7 +3229,7 @@ int size; int encoding_len = 0; char *encoding; - + DOMXML_PARAM_THREE(docp, id, le_domxmldocp, "|ls", &format, &encoding, &encoding_len); if (format) { @@ -3171,7 +3238,7 @@ xmlDocDumpFormatMemoryEnc(docp, &mem, &size, encoding, format); } else { xmlDocDumpFormatMemory(docp, &mem, &size, format); - } + } } else { if (encoding_len) { xmlDocDumpMemoryEnc(docp, &mem, &size, encoding); @@ -3227,22 +3294,22 @@ xmlBufferPtr buf; int level = 0; int format = 0; - + DOMXML_PARAM_THREE(docp, id, le_domxmldocp, "o|ll", &nodep, &format, &level); - + DOMXML_GET_OBJ(elementp, nodep, le_domxmlnodep); if (Z_TYPE_P(elementp) == XML_DOCUMENT_NODE || Z_TYPE_P(elementp) == XML_HTML_DOCUMENT_NODE ) { php_error(E_WARNING, "%s(): cannot dump element with a document node", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } - + buf = xmlBufferCreate(); if (!buf) { php_error(E_WARNING, "%s(): could fetch buffer", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } - + xmlNodeDump(buf, docp, elementp, level, format); mem = (xmlChar*) xmlBufferContent(buf); @@ -3252,7 +3319,7 @@ RETURN_FALSE; } RETVAL_STRING(mem, 1); - + xmlBufferFree(buf); } @@ -3266,9 +3333,9 @@ xmlNode *nodep; TSRMLS_FETCH(); - + nodep = ((xmlNode *)((xmlID *)payload)->attr)->parent; - child = php_domobject_new(nodep, &ret TSRMLS_CC); + child = php_domobject_new(nodep, &ret, NULL TSRMLS_CC); add_next_index_zval(return_value, child); } @@ -3289,7 +3356,7 @@ RETURN_FALSE; } - xmlHashScan(ids, idsHashScanner2, return_value); + xmlHashScan(ids, (void *)idsHashScanner2, return_value); } else { RETURN_FALSE; } @@ -3300,7 +3367,7 @@ Creates DOM object of XML document */ PHP_FUNCTION(xmldoc) { - zval *rv; + zval *rv = NULL; xmlDoc *docp; int ret; char *buffer; @@ -3349,7 +3416,12 @@ xmlParseDTD(dtd->ExternalID, dtd->SystemID); } */ - DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); + + if(DOMXML_IS_TYPE(getThis(), domxmldoc_class_entry)) { + DOMXML_DOMOBJ_NEW(getThis(), (xmlNodePtr) docp, &ret); + } else { + DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); + } } /* }}} */ @@ -3357,7 +3429,7 @@ Creates DOM object of XML document in file */ PHP_FUNCTION(xmldocfile) { - zval *rv; + zval *rv = NULL; xmlDoc *docp; int ret, file_len; char *file; @@ -3373,7 +3445,7 @@ DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret); - add_property_resource(return_value, "doc", ret); +/* add_property_resource(return_value, "doc", ret); if (docp->name) add_property_stringl(return_value, "name", (char *) docp->name, strlen(docp->name), 1); if (docp->URL) @@ -3385,7 +3457,7 @@ add_property_long(return_value, "type", Z_TYPE_P(docp)); add_property_long(return_value, "compression", docp->compression); add_property_long(return_value, "charset", docp->charset); - zend_list_addref(ret); + zend_list_addref(ret);*/ } /* }}} */ @@ -3416,7 +3488,7 @@ Creates DOM object of HTML document */ PHP_FUNCTION(html_doc) { - zval *rv; + zval *rv = NULL; xmlDoc *docp; int ret; char *buffer; @@ -3443,7 +3515,7 @@ Creates DOM object of HTML document in file */ PHP_FUNCTION(html_doc_file) { - zval *rv; + zval *rv = NULL; xmlDoc *docp; int ret, file_len; char *file; @@ -3518,7 +3590,7 @@ Adds root node to document */ PHP_FUNCTION(domxml_add_root) { - zval *id, *rv; + zval *id, *rv = NULL; xmlDoc *docp; xmlNode *nodep; int ret, name_len; @@ -3541,7 +3613,7 @@ Creates new xmldoc */ PHP_FUNCTION(domxml_new_xmldoc) { - zval *rv; + zval *rv = NULL; xmlDoc *docp; int ret, buf_len; char *buf; @@ -3580,7 +3652,7 @@ } /* parserp->loadsubset = XML_DETECT_IDS; */ - rv = php_xmlparser_new(parserp, &ret TSRMLS_CC); + rv = php_xmlparser_new(parserp, &ret TSRMLS_CC); DOMXML_RET_ZVAL(rv); } /* }}} */ @@ -3608,7 +3680,7 @@ Ends parsing and returns DomDocument*/ PHP_FUNCTION(domxml_parser_end) { - zval *id,*rv; + zval *id,*rv = NULL; xmlParserCtxtPtr parserp; char *chunk = NULL; int chunk_len = 0, error; @@ -3618,7 +3690,7 @@ DOMXML_PARAM_TWO(parserp, id, le_domxmlparserp,"|s", &chunk, &chunk_len); error = xmlParseChunk(parserp, chunk, chunk_len, 1); if (error != 0) { - php_error(E_ERROR,"error: %d",error); + php_error(E_ERROR,"error: %d",error); RETURN_FALSE; } if (parserp->myDoc != NULL) { @@ -3668,7 +3740,7 @@ zval *pattr; int ret; - pattr = php_domobject_new((xmlNodePtr) ns, &ret TSRMLS_CC); + pattr = php_domobject_new((xmlNodePtr) ns, &ret, NULL TSRMLS_CC); SEPARATE_ZVAL(&pattr); /* if(!ret) { */ @@ -3711,7 +3783,7 @@ zval *pattr; int ret; - pattr = php_domobject_new((xmlNodePtr) attr, &ret TSRMLS_CC); + pattr = php_domobject_new((xmlNodePtr) attr, &ret, NULL TSRMLS_CC); /** XXX FIXME XXX */ /* if(0 <= (n = node_children(&children, attr->children TSRMLS_CC))) { zend_hash_update(Z_OBJPROP_P(value), "children", sizeof("children"), (void *) &children, sizeof(zval *), NULL); @@ -3749,7 +3821,7 @@ zval *child; int ret; - if (NULL != (child = php_domobject_new(last, &ret TSRMLS_CC))) { + if (NULL != (child = php_domobject_new(last, &ret, NULL TSRMLS_CC))) { zend_hash_next_index_insert(Z_ARRVAL_PP(children), &child, sizeof(zval *), NULL); /* Get the namespace of the current node and add it as a property */ @@ -3779,7 +3851,7 @@ Creates a tree of PHP objects from an XML document */ PHP_FUNCTION(domxml_xmltree) { - zval *children, *rv; + zval *children, *rv = NULL; xmlDoc *docp; xmlNode *root; int ret, buf_len; @@ -3961,7 +4033,7 @@ int retnode; /* construct a node object */ - child = php_domobject_new(node, &retnode TSRMLS_CC); + child = php_domobject_new(node, &retnode, NULL +TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(arr), &child, sizeof(zval *), NULL); } zend_hash_update(Z_OBJPROP_P(rv), "nodeset", sizeof("nodeset"), (void *) &arr, sizeof(zval *), NULL);
--- php_domxml.cvs.h Sun May 5 19:17:50 2002 +++ out.h Thu May 9 22:00:33 2002 @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ @@ -50,6 +50,8 @@ extern zend_module_entry domxml_module_entry; #define domxml_module_ptr &domxml_module_entry +PHPAPI zval *php_domobject_new(xmlNodePtr obj, int *found, zval* in TSRMLS_DC); + /* directory functions */ PHP_MINIT_FUNCTION(domxml); PHP_RINIT_FUNCTION(domxml); @@ -137,7 +139,6 @@ PHP_FUNCTION(domxml_attr_specified); /* Class Element methods */ -PHP_FUNCTION(domxml_element); PHP_FUNCTION(domxml_elem_tagname); PHP_FUNCTION(domxml_elem_get_attribute); PHP_FUNCTION(domxml_elem_set_attribute);
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php