|
|
|
@ -130,10 +130,10 @@ static inline int match_ns(php_sxe_object *sxe, xmlNodePtr node, xmlChar *name) |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node) /* {{{ */ |
|
|
|
static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xmlNodePtr node, long *cnt) /* {{{ */ |
|
|
|
{ |
|
|
|
long nodendx = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (sxe->iter.type == SXE_ITER_NONE) { |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
@ -151,12 +151,15 @@ static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xm |
|
|
|
next_iter: |
|
|
|
node = node->next; |
|
|
|
} |
|
|
|
|
|
|
|
if (cnt) { |
|
|
|
*cnt = nodendx; |
|
|
|
} |
|
|
|
|
|
|
|
return node; |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
#if SXE_ELEMENT_BY_NAME |
|
|
|
static xmlNodePtr sxe_find_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char *name TSRMLS_DC) /* {{{ */ |
|
|
|
{ |
|
|
|
while (node) { |
|
|
|
@ -172,7 +175,7 @@ next_iter: |
|
|
|
return NULL; |
|
|
|
} /* }}} */ |
|
|
|
|
|
|
|
static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char **name, int *type TSRMLS_DC) /* {{{ */ |
|
|
|
static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node, char **name, SXE_ITER *type TSRMLS_DC) /* {{{ */ |
|
|
|
{ |
|
|
|
int orgtype; |
|
|
|
xmlNodePtr orgnode = node; |
|
|
|
@ -219,7 +222,6 @@ next_iter: |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
#endif /* SXE_ELEMENT_BY_NAME */ |
|
|
|
|
|
|
|
/* {{{ sxe_prop_dim_read() |
|
|
|
*/ |
|
|
|
@ -231,7 +233,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, |
|
|
|
xmlNodePtr node; |
|
|
|
xmlAttrPtr attr = NULL; |
|
|
|
zval tmp_zv; |
|
|
|
int nodendx = 0; |
|
|
|
int nodendx = 0; |
|
|
|
int test = 0; |
|
|
|
|
|
|
|
sxe = php_sxe_fetch_object(object TSRMLS_CC); |
|
|
|
@ -303,7 +305,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, |
|
|
|
if (sxe->iter.type == SXE_ITER_CHILD) { |
|
|
|
node = php_sxe_get_first_node(sxe, node TSRMLS_CC); |
|
|
|
} |
|
|
|
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node); |
|
|
|
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL); |
|
|
|
if (node) { |
|
|
|
_node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix TSRMLS_CC); |
|
|
|
} |
|
|
|
@ -329,6 +331,10 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, |
|
|
|
if (member == &tmp_zv) { |
|
|
|
zval_dtor(&tmp_zv); |
|
|
|
} |
|
|
|
if (Z_TYPE_P(return_value) == IS_NULL) { |
|
|
|
zval_ptr_dtor(&return_value); |
|
|
|
return_value = &EG(uninitialized_zval); |
|
|
|
} |
|
|
|
|
|
|
|
return return_value; |
|
|
|
} |
|
|
|
@ -356,6 +362,11 @@ static void change_node_zval(xmlNodePtr node, zval *value TSRMLS_DC) |
|
|
|
{ |
|
|
|
zval value_copy; |
|
|
|
|
|
|
|
if (!value) |
|
|
|
{ |
|
|
|
xmlNodeSetContentLen(node, "", 0); |
|
|
|
return; |
|
|
|
} |
|
|
|
switch (Z_TYPE_P(value)) { |
|
|
|
case IS_LONG: |
|
|
|
case IS_BOOL: |
|
|
|
@ -383,18 +394,20 @@ static void change_node_zval(xmlNodePtr node, zval *value TSRMLS_DC) |
|
|
|
|
|
|
|
/* {{{ sxe_property_write() |
|
|
|
*/ |
|
|
|
static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool elements, zend_bool attribs TSRMLS_DC) |
|
|
|
static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC) |
|
|
|
{ |
|
|
|
php_sxe_object *sxe; |
|
|
|
char *name; |
|
|
|
xmlNodePtr node; |
|
|
|
xmlNodePtr newnode = NULL; |
|
|
|
xmlNodePtr mynode; |
|
|
|
xmlNodePtr tempnode; |
|
|
|
xmlAttrPtr attr = NULL; |
|
|
|
int counter = 0; |
|
|
|
int is_attr = 0; |
|
|
|
int nodendx = 0; |
|
|
|
int test = 0; |
|
|
|
long cnt; |
|
|
|
zval tmp_zv, trim_zv; |
|
|
|
|
|
|
|
if (!member) { |
|
|
|
@ -444,9 +457,31 @@ static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_boo |
|
|
|
attr = (xmlAttrPtr)node; |
|
|
|
test = sxe->iter.name != NULL; |
|
|
|
} else if (sxe->iter.type != SXE_ITER_CHILD) { |
|
|
|
mynode = node; |
|
|
|
node = php_sxe_get_first_node(sxe, node TSRMLS_CC); |
|
|
|
attr = node ? node->properties : NULL; |
|
|
|
test = 0; |
|
|
|
if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) { |
|
|
|
node = xmlNewChild(mynode, mynode->ns, sxe->iter.name, NULL); |
|
|
|
attr = node->properties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
mynode = node; |
|
|
|
|
|
|
|
if (value) { |
|
|
|
switch (Z_TYPE_P(value)) { |
|
|
|
case IS_LONG: |
|
|
|
case IS_BOOL: |
|
|
|
case IS_DOUBLE: |
|
|
|
case IS_NULL: |
|
|
|
convert_to_string(value); |
|
|
|
break; |
|
|
|
case IS_STRING: |
|
|
|
break; |
|
|
|
default: |
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "It is not yet possible to assign complex types to %s", attribs ? "attributes" : "properties"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (node) { |
|
|
|
@ -478,7 +513,7 @@ static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_boo |
|
|
|
|
|
|
|
if (elements) { |
|
|
|
if (Z_TYPE_P(member) == IS_LONG) { |
|
|
|
newnode = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node); |
|
|
|
newnode = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, &cnt); |
|
|
|
if (newnode) { |
|
|
|
++counter; |
|
|
|
} |
|
|
|
@ -502,34 +537,35 @@ next_iter: |
|
|
|
if (is_attr) { |
|
|
|
newnode = (xmlNodePtr) attr; |
|
|
|
} |
|
|
|
while ((tempnode = (xmlNodePtr) newnode->children)) { |
|
|
|
xmlUnlinkNode(tempnode); |
|
|
|
php_libxml_node_free_resource((xmlNodePtr) tempnode TSRMLS_CC); |
|
|
|
if (value) { |
|
|
|
while ((tempnode = (xmlNodePtr) newnode->children)) { |
|
|
|
xmlUnlinkNode(tempnode); |
|
|
|
php_libxml_node_free_resource((xmlNodePtr) tempnode TSRMLS_CC); |
|
|
|
} |
|
|
|
change_node_zval(newnode, value TSRMLS_CC); |
|
|
|
} |
|
|
|
change_node_zval(newnode, value TSRMLS_CC); |
|
|
|
} else if (counter > 1) { |
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot assign to an array of nodes (duplicate subnodes or attr detected)"); |
|
|
|
} else { |
|
|
|
if (attribs) { |
|
|
|
switch (Z_TYPE_P(value)) { |
|
|
|
case IS_LONG: |
|
|
|
case IS_BOOL: |
|
|
|
case IS_DOUBLE: |
|
|
|
case IS_NULL: |
|
|
|
convert_to_string(value); |
|
|
|
case IS_STRING: |
|
|
|
newnode = (xmlNodePtr)xmlNewProp(node, name, Z_STRVAL_P(value)); |
|
|
|
break; |
|
|
|
default: |
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "It is not yet possible to assign complex types to attributes"); |
|
|
|
} else if (elements) { |
|
|
|
if (!node) { |
|
|
|
newnode = xmlNewTextChild(mynode, mynode->ns, name, value ? Z_STRVAL_P(value) : NULL); |
|
|
|
} else if (Z_TYPE_P(member) == IS_LONG) { |
|
|
|
if (cnt < Z_LVAL_P(member)) { |
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only %ld such elements exist", mynode->name, Z_LVAL_P(member), cnt); |
|
|
|
} |
|
|
|
newnode = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? Z_STRVAL_P(value) : NULL); |
|
|
|
} |
|
|
|
} else if (attribs) { |
|
|
|
newnode = (xmlNodePtr)xmlNewProp(node, name, value ? Z_STRVAL_P(value) : NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (member == &tmp_zv) { |
|
|
|
zval_dtor(&tmp_zv); |
|
|
|
} |
|
|
|
if (pnewnode) { |
|
|
|
*pnewnode = newnode; |
|
|
|
} |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
@ -537,7 +573,7 @@ next_iter: |
|
|
|
*/ |
|
|
|
static void sxe_property_write(zval *object, zval *member, zval *value TSRMLS_DC) |
|
|
|
{ |
|
|
|
sxe_prop_dim_write(object, member, value, 1, 0 TSRMLS_CC); |
|
|
|
sxe_prop_dim_write(object, member, value, 1, 0, NULL TSRMLS_CC); |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
@ -545,7 +581,37 @@ static void sxe_property_write(zval *object, zval *member, zval *value TSRMLS_DC |
|
|
|
*/ |
|
|
|
static void sxe_dimension_write(zval *object, zval *offset, zval *value TSRMLS_DC) |
|
|
|
{ |
|
|
|
sxe_prop_dim_write(object, offset, value, 0, 1 TSRMLS_CC); |
|
|
|
sxe_prop_dim_write(object, offset, value, 0, 1, NULL TSRMLS_CC); |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
static zval** sxe_property_get_adr(zval *object, zval *member TSRMLS_DC) /* {{{ */ |
|
|
|
{ |
|
|
|
php_sxe_object *sxe; |
|
|
|
xmlNodePtr node; |
|
|
|
zval *return_value; |
|
|
|
char *name; |
|
|
|
SXE_ITER type; |
|
|
|
|
|
|
|
sxe = php_sxe_fetch_object(object TSRMLS_CC); |
|
|
|
|
|
|
|
GET_NODE(sxe, node); |
|
|
|
convert_to_string(member); |
|
|
|
name = Z_STRVAL_P(member); |
|
|
|
node = sxe_get_element_by_name(sxe, node, &name, &type TSRMLS_CC); |
|
|
|
if (!node) { |
|
|
|
sxe_prop_dim_write(object, member, NULL, 1, 0, &node TSRMLS_CC); |
|
|
|
type = SXE_ITER_NONE; |
|
|
|
name = NULL; |
|
|
|
} |
|
|
|
MAKE_STD_ZVAL(return_value); |
|
|
|
_node_as_zval(sxe, node, return_value, type, name, sxe->iter.nsprefix TSRMLS_CC); |
|
|
|
|
|
|
|
sxe = php_sxe_fetch_object(return_value TSRMLS_CC); |
|
|
|
sxe->tmp = return_value; |
|
|
|
return_value->is_ref = 1; |
|
|
|
|
|
|
|
return &sxe->tmp; |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
@ -554,7 +620,6 @@ static void sxe_dimension_write(zval *object, zval *offset, zval *value TSRMLS_D |
|
|
|
static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend_bool elements, zend_bool attribs TSRMLS_DC) |
|
|
|
{ |
|
|
|
php_sxe_object *sxe; |
|
|
|
char *name; |
|
|
|
xmlNodePtr node; |
|
|
|
xmlAttrPtr attr = NULL; |
|
|
|
int exists = 0; |
|
|
|
@ -562,8 +627,6 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend |
|
|
|
|
|
|
|
sxe = php_sxe_fetch_object(object TSRMLS_CC); |
|
|
|
|
|
|
|
name = Z_STRVAL_P(member); |
|
|
|
|
|
|
|
GET_NODE(sxe, node); |
|
|
|
|
|
|
|
if (Z_TYPE_P(member) == IS_LONG) { |
|
|
|
@ -591,7 +654,7 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend |
|
|
|
if (node) { |
|
|
|
if (attribs) { |
|
|
|
while (attr) { |
|
|
|
if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { |
|
|
|
if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { |
|
|
|
exists = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -605,7 +668,7 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend |
|
|
|
if (sxe->iter.type == SXE_ITER_CHILD) { |
|
|
|
node = php_sxe_get_first_node(sxe, node TSRMLS_CC); |
|
|
|
} |
|
|
|
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node); |
|
|
|
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL); |
|
|
|
} |
|
|
|
else { |
|
|
|
zval tmp_zv; |
|
|
|
@ -628,7 +691,7 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend |
|
|
|
if (member == &tmp_zv) { |
|
|
|
zval_dtor(&tmp_zv); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (node) { |
|
|
|
exists = 1; |
|
|
|
} |
|
|
|
@ -680,7 +743,7 @@ static void sxe_prop_dim_delete(zval *object, zval *member, zend_bool elements, |
|
|
|
if (sxe->iter.type == SXE_ITER_ATTRLIST) { |
|
|
|
attribs = 1; |
|
|
|
elements = 0; |
|
|
|
node = php_sxe_get_first_node(sxe, node TSRMLS_CC); |
|
|
|
node = php_sxe_get_first_node(sxe, node TSRMLS_CC); |
|
|
|
attr = (xmlAttrPtr)node; |
|
|
|
test = sxe->iter.name != NULL; |
|
|
|
} else { |
|
|
|
@ -1000,7 +1063,7 @@ SXE_METHOD(xpath) |
|
|
|
_node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_NONE, NULL, NULL TSRMLS_CC); |
|
|
|
} else if (nodeptr->type == XML_ATTRIBUTE_NODE) { |
|
|
|
_node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, NULL TSRMLS_CC); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_node_as_zval(sxe, nodeptr, value, SXE_ITER_NONE, NULL, NULL TSRMLS_CC); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1215,7 +1278,7 @@ SXE_METHOD(getDocNamespaces) |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* {{{ proto object SimpleXMLElement::children() |
|
|
|
/* {{{ proto object SimpleXMLElement::children([string ns]) |
|
|
|
Finds children of given node */ |
|
|
|
SXE_METHOD(children) |
|
|
|
{ |
|
|
|
@ -1242,6 +1305,23 @@ SXE_METHOD(children) |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* {{{ proto object SimpleXMLElement::getName() |
|
|
|
Finds children of given node */ |
|
|
|
SXE_METHOD(getName) |
|
|
|
{ |
|
|
|
php_sxe_object *sxe; |
|
|
|
xmlNodePtr node; |
|
|
|
int namelen; |
|
|
|
|
|
|
|
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); |
|
|
|
|
|
|
|
GET_NODE(sxe, node); |
|
|
|
|
|
|
|
namelen = xmlStrlen(node->name); |
|
|
|
RETURN_STRINGL((char*)node->name, namelen, 1); |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/* {{{ proto array SimpleXMLElement::attributes([string ns]) |
|
|
|
Identifies an element's attributes */ |
|
|
|
SXE_METHOD(attributes) |
|
|
|
@ -1396,7 +1476,7 @@ static zend_object_handlers sxe_object_handlers = { |
|
|
|
sxe_property_write, |
|
|
|
sxe_dimension_read, |
|
|
|
sxe_dimension_write, |
|
|
|
NULL, |
|
|
|
sxe_property_get_adr, |
|
|
|
sxe_get_value, /* get */ |
|
|
|
NULL, |
|
|
|
sxe_property_exists, |
|
|
|
@ -1420,7 +1500,7 @@ static zend_object_handlers sxe_ze1_object_handlers = { |
|
|
|
sxe_property_write, |
|
|
|
sxe_dimension_read, |
|
|
|
sxe_dimension_write, |
|
|
|
NULL, |
|
|
|
sxe_property_get_adr, |
|
|
|
sxe_get_value, /* get */ |
|
|
|
NULL, |
|
|
|
sxe_property_exists, |
|
|
|
@ -1495,6 +1575,10 @@ static void sxe_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) |
|
|
|
xmlFree(sxe->iter.nsprefix); |
|
|
|
sxe->iter.nsprefix = NULL; |
|
|
|
} |
|
|
|
if (sxe->tmp) { |
|
|
|
zval_ptr_dtor(&sxe->tmp); |
|
|
|
sxe->tmp = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
@ -1961,11 +2045,12 @@ static zend_function_entry sxe_functions[] = { |
|
|
|
SXE_ME(__construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* must be called */ |
|
|
|
SXE_ME(asXML, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(xpath, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(registerXPathNamespace, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(registerXPathNamespace, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(attributes, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(children, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(children, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(getNamespaces, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(getDocNamespaces, NULL, ZEND_ACC_PUBLIC) |
|
|
|
SXE_ME(getName, NULL, ZEND_ACC_PUBLIC) |
|
|
|
{NULL, NULL, NULL} |
|
|
|
}; |
|
|
|
|
|
|
|
|