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: 152 246 61.8 %
Date: 2016-08-28 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       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             : 
      20             : /* $Id$ */
      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, 1)
      52             :         ZEND_ARG_INFO(0, registerNodeNS)
      53             : ZEND_END_ARG_INFO();
      54             : 
      55             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_evaluate, 0, 0, 1)
      56             :         ZEND_ARG_INFO(0, expr)
      57             :         ZEND_ARG_OBJ_INFO(0, context, DOMNode, 1)
      58             :         ZEND_ARG_INFO(0, registerNodeNS)
      59             : ZEND_END_ARG_INFO();
      60             : 
      61             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_xpath_register_php_functions, 0, 0, 0)
      62             : ZEND_END_ARG_INFO();
      63             : /* }}} */
      64             : 
      65             : const zend_function_entry php_dom_xpath_class_functions[] = {
      66             :         PHP_ME(domxpath, __construct, arginfo_dom_xpath_construct, ZEND_ACC_PUBLIC)
      67             :         PHP_FALIAS(registerNamespace, dom_xpath_register_ns, arginfo_dom_xpath_register_ns)
      68             :         PHP_FALIAS(query, dom_xpath_query, arginfo_dom_xpath_query)
      69             :         PHP_FALIAS(evaluate, dom_xpath_evaluate, arginfo_dom_xpath_evaluate)
      70             :         PHP_FALIAS(registerPhpFunctions, dom_xpath_register_php_functions, arginfo_dom_xpath_register_php_functions)
      71             :         PHP_FE_END
      72             : };
      73             : 
      74             : 
      75           1 : static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int type) /* {{{ */
      76             : {
      77             :         zval retval;
      78             :         int result, i;
      79           1 :         int error = 0;
      80             :         zend_fcall_info fci;
      81             :         xmlXPathObjectPtr obj;
      82             :         char *str;
      83           1 :         zend_string *callable = NULL;
      84             :         dom_xpath_object *intern;
      85             : 
      86             : 
      87           1 :         if (! zend_is_executing()) {
      88           0 :                 xmlGenericError(xmlGenericErrorContext,
      89             :                 "xmlExtFunctionTest: Function called from outside of PHP\n");
      90           0 :                 error = 1;
      91             :         } else {
      92           1 :                 intern = (dom_xpath_object *) ctxt->context->userData;
      93           1 :                 if (intern == NULL) {
      94           0 :                         xmlGenericError(xmlGenericErrorContext,
      95             :                         "xmlExtFunctionTest: failed to get the internal object\n");
      96           0 :                         error = 1;
      97             :                 }
      98           1 :                 else if (intern->registerPhpFunctions == 0) {
      99           0 :                         xmlGenericError(xmlGenericErrorContext,
     100             :                         "xmlExtFunctionTest: PHP Object did not register PHP functions\n");
     101           0 :                         error = 1;
     102             :                 }
     103             :         }
     104             : 
     105           1 :         if (error == 1) {
     106           0 :                 for (i = nargs - 1; i >= 0; i--) {
     107           0 :                         obj = valuePop(ctxt);
     108           0 :                         xmlXPathFreeObject(obj);
     109             :                 }
     110           0 :                 return;
     111             :         }
     112             : 
     113           1 :         fci.param_count = nargs - 1;
     114           1 :         if (fci.param_count > 0) {
     115           1 :                 fci.params = safe_emalloc(fci.param_count, sizeof(zval), 0);
     116             :         }
     117             :         /* Reverse order to pop values off ctxt stack */
     118           2 :         for (i = nargs - 2; i >= 0; i--) {
     119           1 :                 obj = valuePop(ctxt);
     120           1 :                 switch (obj->type) {
     121             :                         case XPATH_STRING:
     122           0 :                                 ZVAL_STRING(&fci.params[i],  (char *)obj->stringval);
     123           0 :                                 break;
     124             :                         case XPATH_BOOLEAN:
     125           0 :                                 ZVAL_BOOL(&fci.params[i],  obj->boolval);
     126           0 :                                 break;
     127             :                         case XPATH_NUMBER:
     128           0 :                                 ZVAL_DOUBLE(&fci.params[i], obj->floatval);
     129           0 :                                 break;
     130             :                         case XPATH_NODESET:
     131           1 :                                 if (type == 1) {
     132           0 :                                         str = (char *)xmlXPathCastToString(obj);
     133           0 :                                         ZVAL_STRING(&fci.params[i], str);
     134           0 :                                         xmlFree(str);
     135           1 :                                 } else if (type == 2) {
     136             :                                         int j;
     137           1 :                                         array_init(&fci.params[i]);
     138           1 :                                         if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
     139           5 :                                                 for (j = 0; j < obj->nodesetval->nodeNr; j++) {
     140           4 :                                                         xmlNodePtr node = obj->nodesetval->nodeTab[j];
     141             :                                                         zval child;
     142             :                                                         /* not sure, if we need this... it's copied from xpath.c */
     143           4 :                                                         if (node->type == XML_NAMESPACE_DECL) {
     144             :                                                                 xmlNsPtr curns;
     145             :                                                                 xmlNodePtr nsparent;
     146             : 
     147           0 :                                                                 nsparent = node->_private;
     148           0 :                                                                 curns = xmlNewNs(NULL, node->name, NULL);
     149           0 :                                                                 if (node->children) {
     150           0 :                                                                         curns->prefix = xmlStrdup((xmlChar *) node->children);
     151             :                                                                 }
     152           0 :                                                                 if (node->children) {
     153           0 :                                                                         node = xmlNewDocNode(node->doc, NULL, (xmlChar *) node->children, node->name);
     154             :                                                                 } else {
     155           0 :                                                                         node = xmlNewDocNode(node->doc, NULL, (xmlChar *) "xmlns", node->name);
     156             :                                                                 }
     157           0 :                                                                 node->type = XML_NAMESPACE_DECL;
     158           0 :                                                                 node->parent = nsparent;
     159           0 :                                                                 node->ns = curns;
     160             :                                                         }
     161           4 :                                                         php_dom_create_object(node, &child, &intern->dom);
     162           4 :                                                         add_next_index_zval(&fci.params[i], &child);
     163             :                                                 }
     164             :                                         }
     165             :                                 }
     166           1 :                                 break;
     167             :                         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           1 :         } 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 :                                         ALLOC_HASHTABLE(intern->node_list);
     208           0 :                                         zend_hash_init(intern->node_list, 0, NULL, ZVAL_PTR_DTOR, 0);
     209             :                                 }
     210             :                                 Z_ADDREF(retval);
     211           0 :                                 zend_hash_next_index_insert(intern->node_list, &retval);
     212           0 :                                 obj = Z_DOMOBJ_P(&retval);
     213           0 :                                 nodep = dom_object_get_node(obj);
     214           0 :                                 valuePush(ctxt, xmlXPathNewNodeSet(nodep));
     215           2 :                         } else if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) {
     216           0 :                                 valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(retval) == IS_TRUE));
     217           1 :                         } else if (Z_TYPE(retval) == IS_OBJECT) {
     218           0 :                                 php_error_docref(NULL, E_WARNING, "A PHP Object cannot be converted to a XPath-string");
     219           0 :                                 valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
     220             :                         } else {
     221           1 :                                 zend_string *str = zval_get_string(&retval);
     222           1 :                                 valuePush(ctxt, xmlXPathNewString((xmlChar *) ZSTR_VAL(str)));
     223             :                                 zend_string_release(str);
     224             :                         }
     225           1 :                         zval_ptr_dtor(&retval);
     226             :                 }
     227             :         }
     228           1 :         zend_string_release(callable);
     229             :         zval_dtor(&fci.function_name);
     230           1 :         if (fci.param_count > 0) {
     231           2 :                 for (i = 0; i < nargs - 1; i++) {
     232           1 :                         zval_ptr_dtor(&fci.params[i]);
     233             :                 }
     234           1 :                 efree(fci.params);
     235             :         }
     236             : }
     237             : /* }}} */
     238             : 
     239           0 : static void dom_xpath_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs) /* {{{ */
     240             : {
     241           0 :         dom_xpath_ext_function_php(ctxt, nargs, 1);
     242           0 : }
     243             : /* }}} */
     244             : 
     245           1 : static void dom_xpath_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs) /* {{{ */
     246             : {
     247           1 :         dom_xpath_ext_function_php(ctxt, nargs, 2);
     248           1 : }
     249             : /* }}} */
     250             : 
     251             : /* {{{ proto void DOMXPath::__construct(DOMDocument doc) U */
     252          10 : PHP_METHOD(domxpath, __construct)
     253             : {
     254          20 :         zval *id = getThis(), *doc;
     255          10 :         xmlDocPtr docp = NULL;
     256             :         dom_object *docobj;
     257             :         dom_xpath_object *intern;
     258             :         xmlXPathContextPtr ctx, oldctx;
     259             : 
     260          10 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &doc, dom_document_class_entry) == FAILURE) {
     261           0 :                 return;
     262             :         }
     263             : 
     264          10 :         DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);
     265             : 
     266          10 :         ctx = xmlXPathNewContext(docp);
     267          10 :         if (ctx == NULL) {
     268           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 1);
     269           0 :                 RETURN_FALSE;
     270             :         }
     271             : 
     272          10 :         intern = Z_XPATHOBJ_P(id);
     273          10 :         if (intern != NULL) {
     274          10 :                 oldctx = (xmlXPathContextPtr)intern->dom.ptr;
     275          10 :                 if (oldctx != NULL) {
     276           0 :                         php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
     277           0 :                         xmlXPathFreeContext(oldctx);
     278             :                 }
     279             : 
     280          10 :                 xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
     281             :                                            (const xmlChar *) "http://php.net/xpath",
     282             :                                            dom_xpath_ext_function_string_php);
     283          10 :                 xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
     284             :                                            (const xmlChar *) "http://php.net/xpath",
     285             :                                            dom_xpath_ext_function_object_php);
     286             : 
     287          10 :                 intern->dom.ptr = ctx;
     288          10 :                 ctx->userData = (void *)intern;
     289          10 :                 intern->dom.document = docobj->document;
     290          10 :                 php_libxml_increment_doc_ref((php_libxml_node_object *) &intern->dom, docp);
     291             :         }
     292             : }
     293             : /* }}} end DOMXPath::__construct */
     294             : 
     295             : /* {{{ document DOMDocument*/
     296           1 : int dom_xpath_document_read(dom_object *obj, zval *retval)
     297             : {
     298           1 :         xmlDoc *docp = NULL;
     299           1 :         xmlXPathContextPtr ctx = (xmlXPathContextPtr) obj->ptr;
     300             : 
     301           1 :         if (ctx) {
     302           1 :                 docp = (xmlDocPtr) ctx->doc;
     303             :         }
     304             : 
     305           1 :         php_dom_create_object((xmlNodePtr) docp, retval, obj);
     306           1 :         return SUCCESS;
     307             : }
     308             : /* }}} */
     309             : 
     310             : /* {{{ proto boolean dom_xpath_register_ns(string prefix, string uri) */
     311           3 : PHP_FUNCTION(dom_xpath_register_ns)
     312             : {
     313             :         zval *id;
     314             :         xmlXPathContextPtr ctxp;
     315             :         size_t prefix_len, ns_uri_len;
     316             :         dom_xpath_object *intern;
     317             :         unsigned char *prefix, *ns_uri;
     318             : 
     319           6 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oss", &id, dom_xpath_class_entry, &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          10 : static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */
     339             : {
     340          10 :         dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr;
     341             : 
     342          10 :         ZVAL_COPY_VALUE(&mapptr->baseobj_zv, baseobj);
     343          10 :         mapptr->nodetype = DOM_NODESET;
     344          10 : }
     345             : /* }}} */
     346             : 
     347          12 : static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
     348             : {
     349          12 :         zval *id, retval, *context = NULL;
     350             :         xmlXPathContextPtr ctxp;
     351          12 :         xmlNodePtr nodep = NULL;
     352             :         xmlXPathObjectPtr xpathobjp;
     353          12 :         size_t expr_len, nsnbr = 0, xpath_type;
     354             :         dom_xpath_object *intern;
     355             :         dom_object *nodeobj;
     356             :         char *expr;
     357          12 :         xmlDoc *docp = NULL;
     358          12 :         xmlNsPtr *ns = NULL;
     359          12 :         zend_bool register_node_ns = 1;
     360             : 
     361          24 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|O!b", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry, &register_node_ns) == FAILURE) {
     362           0 :                 return;
     363             :         }
     364             : 
     365          12 :         intern = Z_XPATHOBJ_P(id);
     366             : 
     367          12 :         ctxp = (xmlXPathContextPtr) intern->dom.ptr;
     368          12 :         if (ctxp == NULL) {
     369           0 :                 php_error_docref(NULL, E_WARNING, "Invalid XPath Context");
     370           0 :                 RETURN_FALSE;
     371             :         }
     372             : 
     373          12 :         docp = (xmlDocPtr) ctxp->doc;
     374          12 :         if (docp == NULL) {
     375           0 :                 php_error_docref(NULL, E_WARNING, "Invalid XPath Document Pointer");
     376           0 :                 RETURN_FALSE;
     377             :         }
     378             : 
     379          12 :         if (context != NULL) {
     380           1 :                 DOM_GET_OBJ(nodep, context, xmlNodePtr, nodeobj);
     381             :         }
     382             : 
     383          12 :         if (!nodep) {
     384          11 :                 nodep = xmlDocGetRootElement(docp);
     385             :         }
     386             : 
     387          12 :         if (nodep && docp != nodep->doc) {
     388           0 :                 php_error_docref(NULL, E_WARNING, "Node From Wrong Document");
     389           0 :                 RETURN_FALSE;
     390             :         }
     391             : 
     392          12 :         ctxp->node = nodep;
     393             : 
     394          12 :         if (register_node_ns) {
     395             :                 /* Register namespaces in the node */
     396          11 :                 ns = xmlGetNsList(docp, nodep);
     397             : 
     398          11 :                 if (ns != NULL) {
     399          18 :                         while (ns[nsnbr] != NULL)
     400           6 :                         nsnbr++;
     401             :                 }
     402             :         }
     403             : 
     404             : 
     405          12 :     ctxp->namespaces = ns;
     406          12 :     ctxp->nsNr = nsnbr;
     407             : 
     408          12 :         xpathobjp = xmlXPathEvalExpression((xmlChar *) expr, ctxp);
     409          12 :         ctxp->node = NULL;
     410             : 
     411          12 :         if (ns != NULL) {
     412           6 :                 xmlFree(ns);
     413           6 :                 ctxp->namespaces = NULL;
     414           6 :                 ctxp->nsNr = 0;
     415             :         }
     416             : 
     417          12 :         if (! xpathobjp) {
     418           0 :                 RETURN_FALSE;
     419             :         }
     420             : 
     421          12 :         if (type == PHP_DOM_XPATH_QUERY) {
     422          10 :                 xpath_type = XPATH_NODESET;
     423             :         } else {
     424           2 :                 xpath_type = xpathobjp->type;
     425             :         }
     426             : 
     427          12 :         switch (xpath_type) {
     428             : 
     429             :                 case  XPATH_NODESET:
     430             :                 {
     431             :                         int i;
     432             :                         xmlNodeSetPtr nodesetp;
     433             : 
     434          10 :                         array_init(&retval);
     435             : 
     436          10 :                         if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) {
     437             : 
     438          19 :                                 for (i = 0; i < nodesetp->nodeNr; i++) {
     439           9 :                                         xmlNodePtr node = nodesetp->nodeTab[i];
     440             :                                         zval child;
     441             : 
     442           9 :                                         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           9 :                                         php_dom_create_object(node, &child, &intern->dom);
     461           9 :                                         add_next_index_zval(&retval, &child);
     462             :                                 }
     463             :                         }
     464          10 :                         php_dom_create_interator(return_value, DOM_NODELIST);
     465          10 :                         nodeobj = Z_DOMOBJ_P(return_value);
     466          10 :                         dom_xpath_iter(&retval, nodeobj);
     467          10 :                         break;
     468             :                 }
     469             : 
     470             :                 case XPATH_BOOLEAN:
     471           0 :                         RETVAL_BOOL(xpathobjp->boolval);
     472           0 :                         break;
     473             : 
     474             :                 case XPATH_NUMBER:
     475           2 :                         RETVAL_DOUBLE(xpathobjp->floatval);
     476           2 :                         break;
     477             : 
     478             :                 case XPATH_STRING:
     479           0 :                         RETVAL_STRING((char *) xpathobjp->stringval);
     480           0 :                         break;
     481             : 
     482             :                 default:
     483           0 :                         RETVAL_NULL();
     484             :                         break;
     485             :         }
     486             : 
     487          12 :         xmlXPathFreeObject(xpathobjp);
     488             : }
     489             : /* }}} */
     490             : 
     491             : /* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context [, boolean registerNodeNS]]) */
     492          10 : PHP_FUNCTION(dom_xpath_query)
     493             : {
     494          10 :         php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_QUERY);
     495          10 : }
     496             : /* }}} end dom_xpath_query */
     497             : 
     498             : /* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context [, boolean registerNodeNS]]) */
     499           2 : PHP_FUNCTION(dom_xpath_evaluate)
     500             : {
     501           2 :         php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_EVALUATE);
     502           2 : }
     503             : /* }}} end dom_xpath_evaluate */
     504             : 
     505             : /* {{{ proto void dom_xpath_register_php_functions() */
     506           1 : PHP_FUNCTION(dom_xpath_register_php_functions)
     507             : {
     508             :         zval *id;
     509             :         dom_xpath_object *intern;
     510             :         zval *array_value, *entry, new_string;
     511             :         zend_string *name;
     512             : 
     513           2 :         DOM_GET_THIS(id);
     514             : 
     515           1 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a",  &array_value) == SUCCESS) {
     516           0 :                 intern = Z_XPATHOBJ_P(id);
     517           0 :                 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) {
     518           0 :                         zend_string *str = zval_get_string(entry);
     519           0 :                         ZVAL_LONG(&new_string,1);
     520           0 :                         zend_hash_update(intern->registered_phpfunctions, str, &new_string);
     521             :                         zend_string_release(str);
     522             :                 } ZEND_HASH_FOREACH_END();
     523           0 :                 intern->registerPhpFunctions = 2;
     524           0 :                 RETURN_TRUE;
     525             : 
     526           1 :         } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S",  &name) == SUCCESS) {
     527           1 :                 intern = Z_XPATHOBJ_P(id);
     528             : 
     529           1 :                 ZVAL_LONG(&new_string, 1);
     530           1 :                 zend_hash_update(intern->registered_phpfunctions, name, &new_string);
     531           1 :                 intern->registerPhpFunctions = 2;
     532             :         } else {
     533           0 :                 intern = Z_XPATHOBJ_P(id);
     534           0 :                 intern->registerPhpFunctions = 1;
     535             :         }
     536             : 
     537             : }
     538             : /* }}} end dom_xpath_register_php_functions */
     539             : 
     540             : #endif /* LIBXML_XPATH_ENABLED */
     541             : 
     542             : #endif
     543             : 
     544             : /*
     545             :  * Local variables:
     546             :  * tab-width: 4
     547             :  * c-basic-offset: 4
     548             :  * End:
     549             :  * vim600: noet sw=4 ts=4 fdm=marker
     550             :  * vim<600: noet sw=4 ts=4
     551             :  */

Generated by: LCOV version 1.10

Generated at Sun, 28 Aug 2016 17:10:00 +0000 (34 hours ago)

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