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-07-27 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-2013 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 **args;
      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, NULL, 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 occured, 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           1 :         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           1 :         if (NULL == (*retval = php_dom_create_object((xmlNodePtr) docp, &ret, NULL, *retval, obj TSRMLS_CC))) {
     335           0 :                 FREE_ZVAL(tmp);
     336           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
     337           0 :                 return FAILURE;
     338             :         }
     339           1 :         if (tmp != *retval) {
     340           0 :                 FREE_ZVAL(tmp);
     341             :         }
     342           1 :         return SUCCESS;
     343             : }
     344             : /* }}} */
     345             : 
     346             : /* {{{ proto boolean dom_xpath_register_ns(string prefix, string uri); */
     347           3 : PHP_FUNCTION(dom_xpath_register_ns)
     348             : {
     349             :         zval *id;
     350             :         xmlXPathContextPtr ctxp;
     351             :         int prefix_len, ns_uri_len;
     352             :         dom_xpath_object *intern;
     353             :         unsigned char *prefix, *ns_uri;
     354             : 
     355           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) {
     356           0 :                 return;
     357             :         }
     358             : 
     359           3 :         intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
     360             : 
     361           3 :         ctxp = (xmlXPathContextPtr) intern->ptr;
     362           3 :         if (ctxp == NULL) {
     363           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
     364           0 :                 RETURN_FALSE;
     365             :         }
     366             : 
     367           3 :         if (xmlXPathRegisterNs(ctxp, prefix, ns_uri) != 0) {
     368           0 :                 RETURN_FALSE
     369             :         }
     370           3 :         RETURN_TRUE;
     371             : }
     372             : /* }}} */
     373             : 
     374          10 : static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */
     375             : {
     376             :         dom_nnodemap_object *mapptr;
     377             : 
     378          10 :         mapptr = (dom_nnodemap_object *)intern->ptr;
     379          10 :         mapptr->baseobjptr = baseobj;
     380          10 :         mapptr->nodetype = DOM_NODESET;
     381             : 
     382          10 : }
     383             : /* }}} */
     384             : 
     385          12 : static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
     386             : {
     387          12 :         zval *id, *retval, *context = NULL;
     388             :         xmlXPathContextPtr ctxp;
     389          12 :         xmlNodePtr nodep = NULL;
     390             :         xmlXPathObjectPtr xpathobjp;
     391          12 :         int expr_len, ret, nsnbr = 0, xpath_type;
     392             :         dom_xpath_object *intern;
     393             :         dom_object *nodeobj;
     394             :         char *expr;
     395          12 :         xmlDoc *docp = NULL;
     396          12 :         xmlNsPtr *ns = NULL;
     397          12 :         zend_bool register_node_ns = 1;
     398             : 
     399          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) {
     400           0 :                 return;
     401             :         }
     402             : 
     403          12 :         intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
     404             : 
     405          12 :         ctxp = (xmlXPathContextPtr) intern->ptr;
     406          12 :         if (ctxp == NULL) {
     407           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
     408           0 :                 RETURN_FALSE;
     409             :         }
     410             : 
     411          12 :         docp = (xmlDocPtr) ctxp->doc;
     412          12 :         if (docp == NULL) {
     413           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Document Pointer");
     414           0 :                 RETURN_FALSE;
     415             :         }
     416             : 
     417          12 :         if (context != NULL) {
     418           1 :                 DOM_GET_OBJ(nodep, context, xmlNodePtr, nodeobj);
     419             :         }
     420             : 
     421          12 :         if (!nodep) {
     422          11 :                 nodep = xmlDocGetRootElement(docp);
     423             :         }
     424             : 
     425          12 :         if (nodep && docp != nodep->doc) {
     426           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Node From Wrong Document");
     427           0 :                 RETURN_FALSE;
     428             :         }
     429             : 
     430          12 :         ctxp->node = nodep;
     431             : 
     432          12 :         if (register_node_ns) {
     433             :                 /* Register namespaces in the node */
     434          11 :                 ns = xmlGetNsList(docp, nodep);
     435             : 
     436          11 :                 if (ns != NULL) {
     437          18 :                         while (ns[nsnbr] != NULL)
     438           6 :                         nsnbr++;
     439             :                 }
     440             :         }
     441             : 
     442             : 
     443          12 :     ctxp->namespaces = ns;
     444          12 :     ctxp->nsNr = nsnbr;
     445             : 
     446          12 :         xpathobjp = xmlXPathEvalExpression(expr, ctxp);
     447          12 :         ctxp->node = NULL;
     448             : 
     449          12 :         if (ns != NULL) {
     450           6 :                 xmlFree(ns);
     451           6 :                 ctxp->namespaces = NULL;
     452           6 :                 ctxp->nsNr = 0;
     453             :         }
     454             : 
     455          12 :         if (! xpathobjp) {
     456           0 :                 RETURN_FALSE;
     457             :         }
     458             : 
     459          12 :         if (type == PHP_DOM_XPATH_QUERY) {
     460          10 :                 xpath_type = XPATH_NODESET;
     461             :         } else {
     462           2 :                 xpath_type = xpathobjp->type;
     463             :         }
     464             : 
     465          12 :         switch (xpath_type) {
     466             : 
     467             :                 case  XPATH_NODESET:
     468             :                 {
     469             :                         int i;
     470             :                         xmlNodeSetPtr nodesetp;
     471             : 
     472          10 :                         MAKE_STD_ZVAL(retval);
     473          10 :                         array_init(retval);
     474             : 
     475          10 :                         if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) {
     476             : 
     477          19 :                                 for (i = 0; i < nodesetp->nodeNr; i++) {
     478           9 :                                         xmlNodePtr node = nodesetp->nodeTab[i];
     479             :                                         zval *child;
     480             : 
     481           9 :                                         MAKE_STD_ZVAL(child);
     482             :                                         
     483           9 :                                         if (node->type == XML_NAMESPACE_DECL) {
     484             :                                                 xmlNsPtr curns;
     485             :                                                 xmlNodePtr nsparent;
     486             : 
     487           0 :                                                 nsparent = node->_private;
     488           0 :                                                 curns = xmlNewNs(NULL, node->name, NULL);
     489           0 :                                                 if (node->children) {
     490           0 :                                                         curns->prefix = xmlStrdup((char *) node->children);
     491             :                                                 }
     492           0 :                                                 if (node->children) {
     493           0 :                                                         node = xmlNewDocNode(docp, NULL, (char *) node->children, node->name);
     494             :                                                 } else {
     495           0 :                                                         node = xmlNewDocNode(docp, NULL, "xmlns", node->name);
     496             :                                                 }
     497           0 :                                                 node->type = XML_NAMESPACE_DECL;
     498           0 :                                                 node->parent = nsparent;
     499           0 :                                                 node->ns = curns;
     500             :                                         }
     501           9 :                                         child = php_dom_create_object(node, &ret, NULL, child, (dom_object *)intern TSRMLS_CC);
     502           9 :                                         add_next_index_zval(retval, child);
     503             :                                 }
     504             :                         }
     505          10 :                         php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
     506          10 :                         nodeobj = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
     507          10 :                         dom_xpath_iter(retval, nodeobj);
     508          10 :                         break;
     509             :                 }
     510             : 
     511             :                 case XPATH_BOOLEAN:
     512           0 :                         RETVAL_BOOL(xpathobjp->boolval);
     513           0 :                         break;
     514             : 
     515             :                 case XPATH_NUMBER:
     516           2 :                         RETVAL_DOUBLE(xpathobjp->floatval)
     517           2 :                         break;
     518             : 
     519             :                 case XPATH_STRING:
     520           0 :                         RETVAL_STRING(xpathobjp->stringval, 1);
     521           0 :                         break;
     522             : 
     523             :                 default:
     524           0 :                         RETVAL_NULL();
     525             :                         break;
     526             :         }
     527             : 
     528          12 :         xmlXPathFreeObject(xpathobjp);
     529             : }
     530             : /* }}} */
     531             : 
     532             : /* {{{ proto DOMNodeList dom_xpath_query(string expr [,DOMNode context [, boolean registerNodeNS]]); */
     533          10 : PHP_FUNCTION(dom_xpath_query)
     534             : {
     535          10 :         php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_QUERY);
     536          10 : }
     537             : /* }}} end dom_xpath_query */
     538             : 
     539             : /* {{{ proto mixed dom_xpath_evaluate(string expr [,DOMNode context [, boolean registerNodeNS]]); */
     540           2 : PHP_FUNCTION(dom_xpath_evaluate)
     541             : {
     542           2 :         php_xpath_eval(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_DOM_XPATH_EVALUATE);
     543           2 : }
     544             : /* }}} end dom_xpath_evaluate */
     545             : 
     546             : /* {{{ proto void dom_xpath_register_php_functions() */
     547           1 : PHP_FUNCTION(dom_xpath_register_php_functions)
     548             : {
     549             :         zval *id;
     550             :         dom_xpath_object *intern;
     551             :         zval *array_value, **entry, *new_string;
     552           1 :         int  name_len = 0;
     553             :         char *name;
     554             : 
     555           1 :         DOM_GET_THIS(id);
     556             :         
     557           1 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "a",  &array_value) == SUCCESS) {
     558           0 :                 intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
     559           0 :                 zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
     560             : 
     561           0 :                 while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
     562           0 :                         SEPARATE_ZVAL(entry);
     563           0 :                         convert_to_string_ex(entry);
     564             : 
     565           0 :                         MAKE_STD_ZVAL(new_string);
     566           0 :                         ZVAL_LONG(new_string,1);
     567             :                 
     568           0 :                         zend_hash_update(intern->registered_phpfunctions, Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &new_string, sizeof(zval*), NULL);
     569           0 :                         zend_hash_move_forward(Z_ARRVAL_P(array_value));
     570             :                 }
     571           0 :                 intern->registerPhpFunctions = 2;
     572           0 :                 RETURN_TRUE;
     573             : 
     574           1 :         } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s",  &name, &name_len) == SUCCESS) {
     575           1 :                 intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
     576             :                 
     577           1 :                 MAKE_STD_ZVAL(new_string);
     578           1 :                 ZVAL_LONG(new_string,1);
     579           1 :                 zend_hash_update(intern->registered_phpfunctions, name, name_len + 1, &new_string, sizeof(zval*), NULL);
     580           1 :                 intern->registerPhpFunctions = 2;
     581             :                 
     582             :         } else {
     583           0 :                 intern = (dom_xpath_object *)zend_object_store_get_object(id TSRMLS_CC);
     584           0 :                 intern->registerPhpFunctions = 1;
     585             :         }
     586             :         
     587             : }
     588             : /* }}} end dom_xpath_register_php_functions */
     589             : 
     590             : #endif /* LIBXML_XPATH_ENABLED */
     591             : 
     592             : #endif
     593             : 
     594             : /*
     595             :  * Local variables:
     596             :  * tab-width: 4
     597             :  * c-basic-offset: 4
     598             :  * End:
     599             :  * vim600: noet sw=4 ts=4 fdm=marker
     600             :  * vim<600: noet sw=4 ts=4
     601             :  */

Generated by: LCOV version 1.10

Generated at Sun, 27 Jul 2014 12:58:27 +0000 (4 days ago)

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