PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/dom - xpath.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 157 259 60.6 %
Date: 2019-05-06 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Mon, 06 May 2019 17:58:13 +0000 (998 days ago)

Copyright © 2005-2022 The PHP Group
All rights reserved.