rrichards Mon Nov 24 06:24:41 2003 EDT
Modified files:
/php-src/ext/simplexml simplexml.c
Log:
Fix bug #26159 - SimpleXML XPath support (patch by Adam Trachtenberg)
a few fixes to memory corruption
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.86 php-src/ext/simplexml/simplexml.c:1.87
--- php-src/ext/simplexml/simplexml.c:1.86 Sun Nov 23 11:20:57 2003
+++ php-src/ext/simplexml/simplexml.c Mon Nov 24 06:24:40 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simplexml.c,v 1.86 2003/11/23 16:20:57 helly Exp $ */
+/* $Id: simplexml.c,v 1.87 2003/11/24 11:24:40 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -190,6 +190,7 @@
}
if (match_ns(sxe, node, name)) {
+ APPEND_PREV_ELEMENT(counter, value);
MAKE_STD_ZVAL(value);
_node_as_zval(sxe, node->parent, value
TSRMLS_CC);
APPEND_CUR_ELEMENT(counter, value);
@@ -647,6 +648,16 @@
}
/* }}} */
+/* {{{ simplexml_ce_xpath_register_ns()
+ */
+static void
+simplexml_ce_xpath_register_ns(char *prefix, xmlXPathContext *xpath, char *href)
+{
+ xmlXPathRegisterNs(xpath, prefix, href);
+}
+/* }}} */
+
+
/* {{{ xsearch()
*/
SXE_METHOD(xsearch)
@@ -656,6 +667,8 @@
char *query;
int query_len;
int i;
+ int nsnbr = 0;
+ xmlNsPtr *ns = NULL;
xmlXPathObjectPtr retval;
xmlNodeSetPtr result;
@@ -673,14 +686,38 @@
sxe->xpath->node = sxe->node->node;
+ ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, (xmlNodePtr)
sxe->node->node);
+
+ if (ns != NULL) {
+ while (ns[nsnbr] != NULL) {
+ nsnbr++;
+ }
+ }
+
+ sxe->xpath->namespaces = ns;
+ sxe->xpath->nsNr = nsnbr;
+
+ /* Register namespaces added in simplexml_cs_register_ns() */
+ xmlHashScan((xmlHashTablePtr) sxe->nsmapptr->nsmap, (xmlHashScanner)
simplexml_ce_xpath_register_ns, sxe->xpath);
+
retval = xmlXPathEval(query, sxe->xpath);
+
+ /* Cleanup registered namespaces added in simplexml_cs_register_ns() */
+ xmlXPathRegisteredNsCleanup(sxe->xpath);
+
+ if (ns != NULL) {
+ xmlFree(ns);
+ sxe->xpath->namespaces = NULL;
+ sxe->xpath->nsNr = 0;
+ }
+
if (!retval) {
RETURN_FALSE;
}
-
result = retval->nodesetval;
if (!result) {
+ xmlXPathFreeObject(retval);
RETURN_FALSE;
}
@@ -699,7 +736,9 @@
_node_as_zval(sxe, result->nodeTab[i], value TSRMLS_CC);
}
add_next_index_zval(return_value, value);
- }
+ }
+
+ xmlXPathFreeObject(retval);
}
/* }}} */
@@ -812,7 +851,7 @@
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
- xmlHashAddEntry(sxe->nsmapptr->nsmap, nsvalue, nsname);
+ xmlHashAddEntry(sxe->nsmapptr->nsmap, nsvalue, xmlStrdup(nsname));
}
/* }}} */
@@ -1522,7 +1561,7 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "Simplexml support", "enabled");
- php_info_print_table_row(2, "Revision", "$Revision: 1.86 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.87 $");
php_info_print_table_row(2, "Schema support",
#ifdef LIBXML_SCHEMAS_ENABLED
"enabled");
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php