added the ability to use new keywork with domxmls objects "new DomDocument()"

instead of xmldoc. This also allows you to create nodes without having
  a whole document "new DomElement("foo")".

moved DOMXML_API_VERSION to php_domxml.h
exposed php_domobject_new for other extensions to use
removed some un-needed code
This commit is contained in:
Brad LaFountain 2002-05-31 05:58:40 +00:00
parent 575e3682f5
commit e6fa086537
2 changed files with 225 additions and 144 deletions

View File

@ -34,14 +34,12 @@
#include "ext/standard/info.h"
#define PHP_XPATH 1
#define PHP_XPTR 2
/* DOMXML API_VERSION, please bump it up, if you change anything in the API
therefore it's easier for the script-programmers to check, what's working how
Can be checked with phpversion("domxml");
*/
#define DOMXML_API_VERSION "20020516"
/* 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; \
@ -270,6 +268,7 @@ static zend_function_entry domxml_functions[] = {
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)
@ -371,7 +370,7 @@ static zend_function_entry php_domxmlnode_class_functions[] = {
};
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)
@ -385,15 +384,18 @@ static zend_function_entry php_domxmlelement_class_functions[] = {
};
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}
};
@ -404,6 +406,7 @@ static zend_function_entry php_domxmlnotation_class_functions[] = {
};
static zend_function_entry php_domxmlentityref_class_functions[] = {
PHP_FALIAS(domentityreference, domxml_doc_create_entity_reference, NULL)
{NULL, NULL, NULL}
};
@ -417,6 +420,7 @@ static zend_function_entry php_domxmlentity_class_functions[] = {
};
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}
@ -436,6 +440,7 @@ static zend_function_entry php_xpathobject_class_functions[] = {
#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)
@ -1036,7 +1041,7 @@ static void php_dom_set_object(zval *wrapper, void *obj, int rsrc_type)
}
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;
@ -1045,7 +1050,12 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
*found = 0;
if (!obj) {
if(!wrapper_in)
{
MAKE_STD_ZVAL(wrapper);
}
else
wrapper = wrapper_in;
ZVAL_NULL(wrapper);
return wrapper;
}
@ -1056,13 +1066,19 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
return wrapper;
}
if(!wrapper_in)
{
MAKE_STD_ZVAL(wrapper);
}
else
wrapper = wrapper_in;
switch (Z_TYPE_P(obj)) {
case XML_ELEMENT_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlelement_class_entry);
rsrc_type = le_domxmlelementp;
add_property_long(wrapper, "type", Z_TYPE_P(nodep));
@ -1073,6 +1089,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_TEXT_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmltext_class_entry);
rsrc_type = le_domxmltextp;
content = xmlNodeGetContent(nodep);
@ -1087,6 +1104,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_COMMENT_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlcomment_class_entry);
rsrc_type = le_domxmlcommentp;
content = xmlNodeGetContent(nodep);
@ -1102,6 +1120,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_PI_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlpi_class_entry);
rsrc_type = le_domxmlpip;
content = xmlNodeGetContent(nodep);
@ -1116,6 +1135,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_ENTITY_REF_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlentityref_class_entry);
rsrc_type = le_domxmlentityrefp;
add_property_stringl(wrapper, "name", (char *) nodep->name, strlen(nodep->name), 1);
@ -1126,6 +1146,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_ELEMENT_DECL:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlnode_class_entry);
rsrc_type = le_domxmlnodep;
add_property_long(wrapper, "type", Z_TYPE_P(nodep));
@ -1143,6 +1164,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_ATTRIBUTE_NODE:
{
xmlAttrPtr attrp = (xmlAttrPtr) obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlattr_class_entry);
rsrc_type = le_domxmlattrp;
add_property_long(wrapper, "type", Z_TYPE_P(attrp));
@ -1160,6 +1182,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
{
xmlDocPtr docp = (xmlDocPtr) obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmldoc_class_entry);
rsrc_type = le_domxmldocp;
if (docp->name)
@ -1199,6 +1222,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_DOCUMENT_TYPE_NODE:
{
xmlDtdPtr dtd = (xmlDtdPtr) obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmldoctype_class_entry);
/* rsrc_type = le_domxmldtdp; */
rsrc_type = le_domxmldoctypep;
@ -1220,6 +1244,7 @@ static zval *php_domobject_new(xmlNodePtr obj, int *found TSRMLS_DC)
case XML_CDATA_SECTION_NODE:
{
xmlNodePtr nodep = obj;
if(!wrapper_in)
object_init_ex(wrapper, domxmlcdata_class_entry);
rsrc_type = le_domxmlcdatap;
content = xmlNodeGetContent(nodep);
@ -1292,49 +1317,49 @@ PHP_MINIT_FUNCTION(domxml)
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)
@ -1572,7 +1597,7 @@ PHP_FUNCTION(domxml_cdata_length)
Creates node */
PHP_FUNCTION(domxml_node)
{
zval *rv;
zval *rv = NULL;
xmlNode *node;
int ret, name_len;
char *name;
@ -1586,8 +1611,12 @@ PHP_FUNCTION(domxml_node)
RETURN_FALSE;
}
if(DOMXML_IS_TYPE(getThis(), domxmlnode_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_node_name(void)
@ -1725,7 +1754,7 @@ PHP_FUNCTION(domxml_node_type)
Clones a node */
PHP_FUNCTION(domxml_clone_node)
{
zval *rv;
zval *rv = NULL;
zval *id;
xmlNode *n, *node;
int ret, recursive = 0;;
@ -1749,7 +1778,7 @@ PHP_FUNCTION(domxml_clone_node)
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;
@ -1770,7 +1799,7 @@ PHP_FUNCTION(domxml_node_first_child)
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;
@ -1791,7 +1820,7 @@ PHP_FUNCTION(domxml_node_last_child)
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;
@ -1812,7 +1841,7 @@ PHP_FUNCTION(domxml_node_next_sibling)
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;
@ -1833,7 +1862,7 @@ PHP_FUNCTION(domxml_node_previous_sibling)
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;
@ -1921,7 +1950,7 @@ PHP_FUNCTION(domxml_node_prefix)
Returns parent of node */
PHP_FUNCTION(domxml_node_parent)
{
zval *id, *rv;
zval *id, *rv = NULL;
xmlNode *nodep, *last;
int ret;
@ -1965,7 +1994,7 @@ PHP_FUNCTION(domxml_node_children)
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;
}
@ -1991,12 +2020,11 @@ PHP_FUNCTION(domxml_node_unlink_node)
}
/* }}} */
/* {{{ proto object domxml_node_replace_node(object domnode)
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;
@ -2032,7 +2060,7 @@ PHP_FUNCTION(domxml_node_replace_node)
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;
@ -2074,7 +2102,7 @@ PHP_FUNCTION(domxml_node_append_child)
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;
@ -2112,7 +2140,7 @@ PHP_FUNCTION(domxml_node_append_sibling)
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;
@ -2164,7 +2192,7 @@ PHP_FUNCTION(domxml_node_remove_child)
while (children) {
if (children == child) {
zval *rv;
zval *rv = NULL;
xmlUnlinkNode(child);
DOMXML_RET_OBJ(rv, child, &ret);
return;
@ -2212,7 +2240,7 @@ PHP_FUNCTION(domxml_node_replace_child)
* 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);
@ -2223,7 +2251,7 @@ PHP_FUNCTION(domxml_node_replace_child)
* the new node are identical.
*/
if(foundnewchild) {
zval *rv;
zval *rv = NULL;
DOMXML_RET_OBJ(rv, newchild, &ret);
return;
} else {
@ -2293,7 +2321,7 @@ PHP_FUNCTION(domxml_node_attributes)
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;
@ -2416,7 +2444,7 @@ PHP_FUNCTION(domxml_notation_system_id)
Constructor of DomElement */
PHP_FUNCTION(domxml_element)
{
zval *rv;
zval *rv = NULL;
xmlNode *node;
int ret, name_len;
char *name;
@ -2477,7 +2505,7 @@ PHP_FUNCTION(domxml_elem_get_attribute)
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;
@ -2519,7 +2547,7 @@ PHP_FUNCTION(domxml_elem_remove_attribute)
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;
@ -2538,7 +2566,7 @@ PHP_FUNCTION(domxml_elem_get_attribute_node)
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;
@ -2651,7 +2679,7 @@ PHP_FUNCTION(domxml_doc_get_elements_by_tagname)
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);
}
@ -2696,8 +2724,8 @@ PHP_FUNCTION(domxml_doc_get_element_by_id)
if(ids) {
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);
@ -2735,7 +2763,7 @@ PHP_FUNCTION(domxml_elem_get_elements_by_tagname)
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);
}
}
@ -2827,7 +2855,7 @@ PHP_FUNCTION(domxml_doctype_entities)
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;
}
@ -2858,7 +2886,7 @@ PHP_FUNCTION(domxml_doctype_notations)
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;
}
@ -2874,7 +2902,7 @@ PHP_FUNCTION(domxml_doctype_notations)
Returns DomDocumentType */
PHP_FUNCTION(domxml_doc_doctype)
{
zval *id, *rv;
zval *id, *rv = NULL;
xmlDtdPtr dtd;
xmlDocPtr docp;
int ret;
@ -2935,13 +2963,15 @@ PHP_FUNCTION(domxml_doc_document_element)
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;
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;
@ -2953,21 +2983,27 @@ PHP_FUNCTION(domxml_doc_create_element)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlelement_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_text_node(string content)
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;
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;
@ -2979,21 +3015,27 @@ PHP_FUNCTION(domxml_doc_create_text_node)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmltext_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_comment(string content)
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;
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;
@ -3005,21 +3047,27 @@ PHP_FUNCTION(domxml_doc_create_comment)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlcomment_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_attribute(string name, string value)
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;
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;
@ -3031,21 +3079,27 @@ PHP_FUNCTION(domxml_doc_create_attribute)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlattr_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), (xmlNodePtr) node, &ret);
} else {
DOMXML_RET_OBJ(rv, (xmlNodePtr) node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_cdata_section(string content)
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;
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;
@ -3057,21 +3111,27 @@ PHP_FUNCTION(domxml_doc_create_cdata_section)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlcdata_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_entity_reference(string name)
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;
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;
@ -3082,21 +3142,27 @@ PHP_FUNCTION(domxml_doc_create_entity_reference)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlentityref_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_create_processing_instruction(string name)
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;
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;
@ -3108,15 +3174,19 @@ PHP_FUNCTION(domxml_doc_create_processing_instruction)
}
node->doc = docp;
if(DOMXML_IS_TYPE(getThis(), domxmlpi_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
}
/* }}} */
/* {{{ proto object domxml_doc_imported_node(object node, bool recursive)
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;
@ -3144,7 +3214,7 @@ PHP_FUNCTION(domxml_doc_imported_node)
Returns DTD of document */
PHP_FUNCTION(domxml_intdtd)
{
zval *id, *rv;
zval *id, *rv = NULL;
xmlDoc *docp;
xmlDtd *dtd;
int ret;
@ -3262,6 +3332,7 @@ PHP_FUNCTION(domxml_dump_node)
RETURN_FALSE;
}
RETVAL_STRING(mem, 1);
xmlBufferFree(buf);
}
@ -3277,7 +3348,7 @@ static void idsHashScanner2(void *payload, void *data, xmlChar *name)
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);
}
@ -3298,7 +3369,7 @@ PHP_FUNCTION(domxml_doc_ids)
RETURN_FALSE;
}
xmlHashScan(ids, idsHashScanner2, return_value);
xmlHashScan(ids, (void *)idsHashScanner2, return_value);
} else {
RETURN_FALSE;
}
@ -3309,7 +3380,7 @@ PHP_FUNCTION(domxml_doc_ids)
Creates DOM object of XML document */
PHP_FUNCTION(xmldoc)
{
zval *rv;
zval *rv = NULL;
xmlDoc *docp;
int ret;
char *buffer;
@ -3358,15 +3429,20 @@ PHP_FUNCTION(xmldoc)
xmlParseDTD(dtd->ExternalID, dtd->SystemID);
}
*/
if(DOMXML_IS_TYPE(getThis(), domxmldoc_class_entry)) {
DOMXML_DOMOBJ_NEW(getThis(), (xmlNodePtr) docp, &ret);
} else {
DOMXML_RET_OBJ(rv, (xmlNodePtr) docp, &ret);
}
}
/* }}} */
/* {{{ proto object xmldocfile(string filename)
Creates DOM object of XML document in file */
PHP_FUNCTION(xmldocfile)
{
zval *rv;
zval *rv = NULL;
xmlDoc *docp;
int ret, file_len;
char *file;
@ -3382,7 +3458,7 @@ PHP_FUNCTION(xmldocfile)
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)
@ -3394,7 +3470,7 @@ PHP_FUNCTION(xmldocfile)
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);*/
}
/* }}} */
@ -3425,7 +3501,7 @@ PHP_FUNCTION(domxml_html_dump_mem)
Creates DOM object of HTML document */
PHP_FUNCTION(html_doc)
{
zval *rv;
zval *rv = NULL;
xmlDoc *docp;
int ret;
char *buffer;
@ -3452,7 +3528,7 @@ PHP_FUNCTION(html_doc)
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;
@ -3523,11 +3599,11 @@ PHP_FUNCTION(domxml_node_text_concat)
}
/* }}} */
/* {{{ proto object domxml_doc_add_root(string name)
/* {{{ proto object domxml_add_root(string name)
Adds root node to document */
PHP_FUNCTION(domxml_doc_add_root)
{
zval *id, *rv;
zval *id, *rv = NULL;
xmlDoc *docp;
xmlNode *nodep;
int ret, name_len;
@ -3571,7 +3647,7 @@ PHP_FUNCTION(domxml_doc_set_root)
Creates new xmldoc */
PHP_FUNCTION(domxml_new_xmldoc)
{
zval *rv;
zval *rv = NULL;
xmlDoc *docp;
int ret, buf_len;
char *buf;
@ -3638,7 +3714,7 @@ PHP_FUNCTION(domxml_parser_add_chunk)
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;
@ -3698,7 +3774,7 @@ static int node_namespace(zval **attributes, xmlNode *nodep TSRMLS_DC)
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) { */
@ -3741,7 +3817,7 @@ static int node_attributes(zval **attributes, xmlNode *nodep TSRMLS_DC)
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);
@ -3779,7 +3855,7 @@ static int node_children(zval **children, xmlNode *nodep TSRMLS_DC)
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 */
@ -3809,7 +3885,7 @@ static int node_children(zval **children, xmlNode *nodep TSRMLS_DC)
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;
@ -3991,7 +4067,7 @@ static void php_xpathptr_eval(INTERNAL_FUNCTION_PARAMETERS, int mode, int expr)
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);
@ -4099,8 +4175,6 @@ PHP_FUNCTION(domxml_version)
}
/* }}} */
#if HAVE_DOMXSLT
static zval *php_xsltstylesheet_new(xsltStylesheetPtr obj, int *found TSRMLS_DC)
{

View File

@ -47,9 +47,17 @@
#endif
#endif
/* DOMXML API_VERSION, please bump it up, if you change anything in the API
therefore it's easier for the script-programmers to check, what's working how
Can be checked with phpversion("domxml");
*/
#define DOMXML_API_VERSION "20020530"
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);
@ -138,7 +146,6 @@ PHP_FUNCTION(domxml_attr_value);
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);