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