xpath.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Christian Stocker <chregu@php.net> |
  16. | Rob Richards <rrichards@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "php.h"
  24. #if HAVE_LIBXML && HAVE_DOM
  25. #include "php_dom.h"
  26. #define PHP_DOM_XPATH_QUERY 0
  27. #define PHP_DOM_XPATH_EVALUATE 1
  28. /*
  29. * class DOMXPath
  30. */
  31. #if defined(LIBXML_XPATH_ENABLED)
  32. /* {{{ arginfo */
  33. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_construct, 0, 0, 1)
  34. ZEND_ARG_OBJ_INFO(0, doc, DOMDocument, 0)
  35. ZEND_END_ARG_INFO();
  36. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_register_ns, 0, 0, 2)
  37. ZEND_ARG_INFO(0, prefix)
  38. ZEND_ARG_INFO(0, uri)
  39. ZEND_END_ARG_INFO();
  40. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_query, 0, 0, 1)
  41. ZEND_ARG_INFO(0, expr)
  42. ZEND_ARG_OBJ_INFO(0, context, DOMNode, 1)
  43. ZEND_ARG_INFO(0, registerNodeNS)
  44. ZEND_END_ARG_INFO();
  45. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_evaluate, 0, 0, 1)
  46. ZEND_ARG_INFO(0, expr)
  47. ZEND_ARG_OBJ_INFO(0, context, DOMNode, 1)
  48. ZEND_ARG_INFO(0, registerNodeNS)
  49. ZEND_END_ARG_INFO();
  50. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_register_php_functions, 0, 0, 0)
  51. ZEND_END_ARG_INFO();
  52. /* }}} */
  53. const zend_function_entry php_dom_xpath_class_functions[] = {
  54. PHP_ME(domxpath, __construct, arginfo_dom_xpath_construct, ZEND_ACC_PUBLIC)
  55. PHP_FALIAS(registerNamespace, dom_xpath_register_ns, arginfo_dom_xpath_register_ns)
  56. PHP_FALIAS(query, dom_xpath_query, arginfo_dom_xpath_query)
  57. PHP_FALIAS(evaluate, dom_xpath_evaluate, arginfo_dom_xpath_evaluate)
  58. PHP_FALIAS(registerPhpFunctions, dom_xpath_register_php_functions, arginfo_dom_xpath_register_php_functions)
  59. PHP_FE_END
  60. };
  61. static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
  62. {
  63. zval **args = NULL;
  64. zval *retval;
  65. int result, i, ret;
  66. int error = 0;
  67. zend_fcall_info fci;
  68. zval handler;
  69. xmlXPathObjectPtr obj;
  70. char *str;
  71. char *callable = NULL;
  72. dom_xpath_object *intern;
  73. TSRMLS_FETCH();
  74. if (! zend_is_executing(TSRMLS_C)) {
  75. xmlGenericError(xmlGenericErrorContext,
  76. "xmlExtFunctionTest: Function called from outside of PHP\n");
  77. error = 1;
  78. } else {
  79. intern = (dom_xpath_object *) ctxt->context->userData;
  80. if (intern == NULL) {
  81. xmlGenericError(xmlGenericErrorContext,
  82. "xmlExtFunctionTest: failed to get the internal object\n");
  83. error = 1;
  84. }
  85. else if (intern->registerPhpFunctions == 0) {
  86. xmlGenericError(xmlGenericErrorContext,
  87. "xmlExtFunctionTest: PHP Object did not register PHP functions\n");
  88. error = 1;
  89. }
  90. }
  91. if (error == 1) {
  92. for (i = nargs - 1; i >= 0; i--) {
  93. obj = valuePop(ctxt);
  94. xmlXPathFreeObject(obj);
  95. }
  96. return;
  97. }
  98. fci.param_count = nargs - 1;
  99. if (fci.param_count > 0) {
  100. fci.params = safe_emalloc(fci.param_count, sizeof(zval**), 0);
  101. args = safe_emalloc(fci.param_count, sizeof(zval *), 0);
  102. }
  103. /* Reverse order to pop values off ctxt stack */
  104. for (i = nargs - 2; i >= 0; i--) {
  105. obj = valuePop(ctxt);
  106. MAKE_STD_ZVAL(args[i]);
  107. switch (obj->type) {
  108. case XPATH_STRING:
  109. ZVAL_STRING(args[i], (char *)obj->stringval, 1);
  110. break;
  111. case XPATH_BOOLEAN:
  112. ZVAL_BOOL(args[i], obj->boolval);
  113. break;
  114. case XPATH_NUMBER:
  115. ZVAL_DOUBLE(args[i], obj->floatval);
  116. break;
  117. case XPATH_NODESET:
  118. if (type == 1) {
  119. str = (char *)xmlXPathCastToString(obj);
  120. ZVAL_STRING(args[i], str, 1);
  121. xmlFree(str);
  122. } else if (type == 2) {
  123. int j;
  124. array_init(args[i]);
  125. if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
  126. for (j = 0; j < obj->nodesetval->nodeNr; j++) {
  127. xmlNodePtr node = obj->nodesetval->nodeTab[j];
  128. zval *child;
  129. MAKE_STD_ZVAL(child);
  130. /* not sure, if we need this... it's copied from xpath.c */
  131. if (node->type == XML_NAMESPACE_DECL) {
  132. xmlNsPtr curns;
  133. xmlNodePtr nsparent;
  134. nsparent = node->_private;
  135. curns = xmlNewNs(NULL, node->name, NULL);
  136. if (node->children) {
  137. curns->prefix = xmlStrdup((xmlChar *) node->children);
  138. }
  139. if (node->children) {
  140. node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
  141. } else {
  142. node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
  143. }
  144. node->type = XML_NAMESPACE_DECL;
  145. node->parent = nsparent;
  146. node->ns = curns;
  147. }
  148. child = php_dom_create_object(node, &ret, child, (dom_object *)intern TSRMLS_CC);
  149. add_next_index_zval(args[i], child);
  150. }
  151. }
  152. }
  153. break;
  154. default:
  155. ZVAL_STRING(args[i], (char *)xmlXPathCastToString(obj), 1);
  156. }
  157. xmlXPathFreeObject(obj);
  158. fci.params[i] = &args[i];
  159. }
  160. fci.size = sizeof(fci);
  161. fci.function_table = EG(function_table);
  162. obj = valuePop(ctxt);
  163. if (obj->stringval == NULL) {
  164. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Handler name must be a string");
  165. xmlXPathFreeObject(obj);
  166. if (fci.param_count > 0) {
  167. for (i = 0; i < nargs - 1; i++) {
  168. zval_ptr_dtor(&args[i]);
  169. }
  170. efree(args);
  171. efree(fci.params);
  172. }
  173. return;
  174. }
  175. INIT_PZVAL(&handler);
  176. ZVAL_STRING(&handler, obj->stringval, 1);
  177. xmlXPathFreeObject(obj);
  178. fci.function_name = &handler;
  179. fci.symbol_table = NULL;
  180. fci.object_ptr = NULL;
  181. fci.retval_ptr_ptr = &retval;
  182. fci.no_separation = 0;
  183. if (!zend_make_callable(&handler, &callable TSRMLS_CC)) {
  184. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", callable);
  185. } else if ( intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable, strlen(callable) + 1) == 0) {
  186. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not allowed to call handler '%s()'.", callable);
  187. /* Push an empty string, so that we at least have an xslt result... */
  188. valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
  189. } else {
  190. result = zend_call_function(&fci, NULL TSRMLS_CC);
  191. if (result == FAILURE) {
  192. if (Z_TYPE(handler) == IS_STRING) {
  193. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call handler %s()", Z_STRVAL_P(&handler));
  194. }
  195. /* retval is == NULL, when an exception occurred, don't report anything, because PHP itself will handle that */
  196. } else if (retval == NULL) {
  197. } else {
  198. if (retval->type == IS_OBJECT && instanceof_function( Z_OBJCE_P(retval), dom_node_class_entry TSRMLS_CC)) {
  199. xmlNode *nodep;
  200. dom_object *obj;
  201. if (intern->node_list == NULL) {
  202. ALLOC_HASHTABLE(intern->node_list);
  203. zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0);
  204. }
  205. zval_add_ref(&retval);
  206. zend_hash_next_index_insert(intern->node_list, &retval, sizeof(zval *), NULL);
  207. obj = (dom_object *)zend_object_store_get_object(retval TSRMLS_CC);
  208. nodep = dom_object_get_node(obj);
  209. valuePush(ctxt, xmlXPathNewNodeSet(nodep));
  210. } else if (retval->type == IS_BOOL) {
  211. valuePush(ctxt, xmlXPathNewBoolean(retval->value.lval));
  212. } else if (retval->type == IS_OBJECT) {
  213. php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object cannot be converted to a XPath-string");
  214. valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
  215. } else {
  216. convert_to_string_ex(&retval);
  217. valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
  218. }
  219. zval_ptr_dtor(&retval);
  220. }
  221. }
  222. efree(callable);
  223. zval_dtor(&handler);
  224. if (fci.param_count > 0) {
  225. for (i = 0; i < nargs - 1; i++) {
  226. zval_ptr_dtor(&args[i]);
  227. }
  228. efree(args);
  229. efree(fci.params);
  230. }
  231. }
  232. /* }}} */
  233. static void dom_xpath_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs) /* {{{ */
  234. {
  235. dom_xpath_ext_function_php(ctxt, nargs, 1);
  236. }
  237. /* }}} */
  238. static void dom_xpath_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs) /* {{{ */
  239. {
  240. dom_xpath_ext_function_php(ctxt, nargs, 2);
  241. }
  242. /* }}} */
  243. /* {{{ proto void DOMXPath::__construct(DOMDocument doc) U */
  244. PHP_METHOD(domxpath, __construct)
  245. {
  246. zval *id, *doc;
  247. xmlDocPtr docp = NULL;
  248. dom_object *docobj;
  249. dom_xpath_object *intern;
  250. xmlXPathContextPtr ctx, oldctx;
  251. zend_error_handling error_handling;
  252. zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
  253. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_xpath_class_entry, &doc, dom_document_class_entry) == FAILURE) {
  254. zend_restore_error_handling(&error_handling TSRMLS_CC);
  255. return;
  256. }
  257. zend_restore_error_handling(&error_handling TSRMLS_CC);
  258. DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);
  259. ctx = xmlXPathNewContext(docp);
  260. if (ctx == NULL) {
  261. php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
  262. RETURN_FALSE;
  263. }
  264. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  265. if (intern != NULL) {
  266. oldctx = (xmlXPathContextPtr)intern->ptr;
  267. if (oldctx != NULL) {
  268. php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
  269. xmlXPathFreeContext(oldctx);
  270. }
  271. xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
  272. (const xmlChar *) "http://php.net/xpath",
  273. dom_xpath_ext_function_string_php);
  274. xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
  275. (const xmlChar *) "http://php.net/xpath",
  276. dom_xpath_ext_function_object_php);
  277. intern->ptr = ctx;
  278. ctx->userData = (void *)intern;
  279. intern->document = docobj->document;
  280. php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp TSRMLS_CC);
  281. }
  282. }
  283. /* }}} end DOMXPath::__construct */
  284. /* {{{ document DOMDocument*/
  285. int dom_xpath_document_read(dom_object *obj, zval **retval TSRMLS_DC)
  286. {
  287. xmlDoc *docp = NULL;
  288. xmlXPathContextPtr ctx;
  289. int ret;
  290. zval *tmp;
  291. ctx = (xmlXPathContextPtr) obj->ptr;
  292. if (ctx) {
  293. docp = (xmlDocPtr) ctx->doc;
  294. }
  295. ALLOC_ZVAL(*retval);
  296. tmp = *retval;
  297. if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, *retval, obj TSRMLS_CC))) {
  298. FREE_ZVAL(tmp);
  299. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
  300. return FAILURE;
  301. }
  302. if (tmp != *retval) {
  303. FREE_ZVAL(tmp);
  304. }
  305. return SUCCESS;
  306. }
  307. /* }}} */
  308. /* {{{ proto boolean dom_xpath_register_ns(string prefix, string uri); */
  309. PHP_FUNCTION(dom_xpath_register_ns)
  310. {
  311. zval *id;
  312. xmlXPathContextPtr ctxp;
  313. int prefix_len, ns_uri_len;
  314. dom_xpath_object *intern;
  315. unsigned char *prefix, *ns_uri;
  316. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_xpath_class_entry, &prefix, &prefix_len, &ns_uri, &ns_uri_len) == FAILURE) {
  317. return;
  318. }
  319. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  320. ctxp = (xmlXPathContextPtr) intern->ptr;
  321. if (ctxp == NULL) {
  322. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
  323. RETURN_FALSE;
  324. }
  325. if (xmlXPathRegisterNs(ctxp, prefix, ns_uri) != 0) {
  326. RETURN_FALSE
  327. }
  328. RETURN_TRUE;
  329. }
  330. /* }}} */
  331. static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */
  332. {
  333. dom_nnodemap_object *mapptr;
  334. mapptr = (dom_nnodemap_object *)intern->ptr;
  335. mapptr->baseobjptr = baseobj;
  336. mapptr->nodetype = DOM_NODESET;
  337. }
  338. /* }}} */
  339. static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
  340. {
  341. zval *id, *retval, *context = NULL;
  342. xmlXPathContextPtr ctxp;
  343. xmlNodePtr nodep = NULL;
  344. xmlXPathObjectPtr xpathobjp;
  345. int expr_len, ret, nsnbr = 0, xpath_type;
  346. dom_xpath_object *intern;
  347. dom_object *nodeobj;
  348. char *expr;
  349. xmlDoc *docp = NULL;
  350. xmlNsPtr *ns = NULL;
  351. zend_bool register_node_ns = 1;
  352. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|O!b", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry, &register_node_ns) == FAILURE) {
  353. return;
  354. }
  355. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  356. ctxp = (xmlXPathContextPtr) intern->ptr;
  357. if (ctxp == NULL) {
  358. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
  359. RETURN_FALSE;
  360. }
  361. docp = (xmlDocPtr) ctxp->doc;
  362. if (docp == NULL) {
  363. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Document Pointer");
  364. RETURN_FALSE;
  365. }
  366. if (context != NULL) {
  367. DOM_GET_OBJ(nodep, context, xmlNodePtr, nodeobj);
  368. }
  369. if (!nodep) {
  370. nodep = xmlDocGetRootElement(docp);
  371. }
  372. if (nodep && docp != nodep->doc) {
  373. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Node From Wrong Document");
  374. RETURN_FALSE;
  375. }
  376. ctxp->node = nodep;
  377. if (register_node_ns) {
  378. /* Register namespaces in the node */
  379. ns = xmlGetNsList(docp, nodep);
  380. if (ns != NULL) {
  381. while (ns[nsnbr] != NULL)
  382. nsnbr++;
  383. }
  384. }
  385. ctxp->namespaces = ns;
  386. ctxp->nsNr = nsnbr;
  387. xpathobjp = xmlXPathEvalExpression(expr, ctxp);
  388. ctxp->node = NULL;
  389. if (ns != NULL) {
  390. xmlFree(ns);
  391. ctxp->namespaces = NULL;
  392. ctxp->nsNr = 0;
  393. }
  394. if (! xpathobjp) {
  395. RETURN_FALSE;
  396. }
  397. if (type == PHP_DOM_XPATH_QUERY) {
  398. xpath_type = XPATH_NODESET;
  399. } else {
  400. xpath_type = xpathobjp->type;
  401. }
  402. switch (xpath_type) {
  403. case XPATH_NODESET:
  404. {
  405. int i;
  406. xmlNodeSetPtr nodesetp;
  407. MAKE_STD_ZVAL(retval);
  408. array_init(retval);
  409. if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) {
  410. for (i = 0; i < nodesetp->nodeNr; i++) {
  411. xmlNodePtr node = nodesetp->nodeTab[i];
  412. zval *child;
  413. MAKE_STD_ZVAL(child);
  414. if (node->type == XML_NAMESPACE_DECL) {
  415. xmlNsPtr curns;
  416. xmlNodePtr nsparent;
  417. nsparent = node->_private;
  418. curns = xmlNewNs(NULL, node->name, NULL);
  419. if (node->children) {
  420. curns->prefix = xmlStrdup((char *) node->children);
  421. }
  422. if (node->children) {
  423. node = xmlNewDocNode(docp, NULL, (char *) node->children, node->name);
  424. } else {
  425. node = xmlNewDocNode(docp, NULL, "xmlns", node->name);
  426. }
  427. node->type = XML_NAMESPACE_DECL;
  428. node->parent = nsparent;
  429. node->ns = curns;
  430. }
  431. child = php_dom_create_object(node, &ret, child, (dom_object *)intern TSRMLS_CC);
  432. add_next_index_zval(retval, child);
  433. }
  434. }
  435. php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
  436. nodeobj = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
  437. dom_xpath_iter(retval, nodeobj);
  438. break;
  439. }
  440. case XPATH_BOOLEAN:
  441. RETVAL_BOOL(xpathobjp->boolval);
  442. break;
  443. case XPATH_NUMBER:
  444. RETVAL_DOUBLE(xpathobjp->floatval)
  445. break;
  446. case XPATH_STRING:
  447. RETVAL_STRING(xpathobjp->stringval, 1);
  448. break;
  449. default:
  450. RETVAL_NULL();
  451. break;
  452. }
  453. xmlXPathFreeObject(xpathobjp);
  454. }
  455. /* }}} */
  456. /* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context [, boolean registerNodeNS]]); */
  457. PHP_FUNCTION(dom_xpath_query)
  458. {
  459. php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_QUERY);
  460. }
  461. /* }}} end dom_xpath_query */
  462. /* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context [, boolean registerNodeNS]]); */
  463. PHP_FUNCTION(dom_xpath_evaluate)
  464. {
  465. php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_EVALUATE);
  466. }
  467. /* }}} end dom_xpath_evaluate */
  468. /* {{{ proto void dom_xpath_register_php_functions() */
  469. PHP_FUNCTION(dom_xpath_register_php_functions)
  470. {
  471. zval *id;
  472. dom_xpath_object *intern;
  473. zval *array_value, **entry, *new_string;
  474. int name_len = 0;
  475. char *name;
  476. DOM_GET_THIS(id);
  477. if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "a", &array_value) == SUCCESS) {
  478. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  479. zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
  480. while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
  481. SEPARATE_ZVAL(entry);
  482. convert_to_string_ex(entry);
  483. MAKE_STD_ZVAL(new_string);
  484. ZVAL_LONG(new_string,1);
  485. zend_hash_update(intern->registered_phpfunctions, Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &new_string, sizeof(zval*), NULL);
  486. zend_hash_move_forward(Z_ARRVAL_P(array_value));
  487. }
  488. intern->registerPhpFunctions = 2;
  489. RETURN_TRUE;
  490. } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == SUCCESS) {
  491. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  492. MAKE_STD_ZVAL(new_string);
  493. ZVAL_LONG(new_string,1);
  494. zend_hash_update(intern->registered_phpfunctions, name, name_len + 1, &new_string, sizeof(zval*), NULL);
  495. intern->registerPhpFunctions = 2;
  496. } else {
  497. intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
  498. intern->registerPhpFunctions = 1;
  499. }
  500. }
  501. /* }}} end dom_xpath_register_php_functions */
  502. #endif /* LIBXML_XPATH_ENABLED */
  503. #endif
  504. /*
  505. * Local variables:
  506. * tab-width: 4
  507. * c-basic-offset: 4
  508. * End:
  509. * vim600: noet sw=4 ts=4 fdm=marker
  510. * vim<600: noet sw=4 ts=4
  511. */