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: 171 278 61.5 %
Date: 2014-08-23 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 23 Aug 2014 22:39:31 +0000 (7 days ago)

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