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 - namednodemap.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 51 103 49.5 %
Date: 2016-05-22 Functions: 3 8 37.5 %
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             : /* {{{ arginfo */
      31             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item, 0, 0, 1)
      32             :         ZEND_ARG_INFO(0, name)
      33             : ZEND_END_ARG_INFO();
      34             : 
      35             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item, 0, 0, 1)
      36             :         ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
      37             : ZEND_END_ARG_INFO();
      38             : 
      39             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item, 0, 0, 0)
      40             :         ZEND_ARG_INFO(0, name)
      41             : ZEND_END_ARG_INFO();
      42             : 
      43             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_item, 0, 0, 0)
      44             :         ZEND_ARG_INFO(0, index)
      45             : ZEND_END_ARG_INFO();
      46             : 
      47             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item_ns, 0, 0, 0)
      48             :         ZEND_ARG_INFO(0, namespaceURI)
      49             :         ZEND_ARG_INFO(0, localName)
      50             : ZEND_END_ARG_INFO();
      51             : 
      52             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item_ns, 0, 0, 0)
      53             :         ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
      54             : ZEND_END_ARG_INFO();
      55             : 
      56             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item_ns, 0, 0, 0)
      57             :         ZEND_ARG_INFO(0, namespaceURI)
      58             :         ZEND_ARG_INFO(0, localName)
      59             : ZEND_END_ARG_INFO();
      60             : /* }}} */
      61             : 
      62             : /*
      63             : * class DOMNamedNodeMap
      64             : *
      65             : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1780488922
      66             : * Since:
      67             : */
      68             : 
      69             : const zend_function_entry php_dom_namednodemap_class_functions[] = { /* {{{ */
      70             :         PHP_FALIAS(getNamedItem, dom_namednodemap_get_named_item, arginfo_dom_namednodemap_get_named_item)
      71             :         PHP_FALIAS(setNamedItem, dom_namednodemap_set_named_item, arginfo_dom_namednodemap_set_named_item)
      72             :         PHP_FALIAS(removeNamedItem, dom_namednodemap_remove_named_item, arginfo_dom_namednodemap_remove_named_item)
      73             :         PHP_FALIAS(item, dom_namednodemap_item, arginfo_dom_namednodemap_item)
      74             :         PHP_FALIAS(getNamedItemNS, dom_namednodemap_get_named_item_ns, arginfo_dom_namednodemap_get_named_item_ns)
      75             :         PHP_FALIAS(setNamedItemNS, dom_namednodemap_set_named_item_ns, arginfo_dom_namednodemap_set_named_item_ns)
      76             :         PHP_FALIAS(removeNamedItemNS, dom_namednodemap_remove_named_item_ns, arginfo_dom_namednodemap_remove_named_item_ns)
      77             :         PHP_FE_END
      78             : };
      79             : /* }}} */
      80             : 
      81             : /* {{{ length   int
      82             : readonly=yes
      83             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D0FB19E
      84             : Since:
      85             : */
      86           2 : int dom_namednodemap_length_read(dom_object *obj, zval *retval)
      87             : {
      88             :         dom_nnodemap_object *objmap;
      89             :         xmlAttrPtr curnode;
      90             :         xmlNodePtr nodep;
      91           2 :         int count = 0;
      92             : 
      93           2 :         objmap = (dom_nnodemap_object *)obj->ptr;
      94             : 
      95           2 :         if (objmap != NULL) {
      96           5 :                 if ((objmap->nodetype == XML_NOTATION_NODE) ||
      97           1 :                         objmap->nodetype == XML_ENTITY_NODE) {
      98           2 :                         if (objmap->ht) {
      99           2 :                                 count = xmlHashSize(objmap->ht);
     100             :                         }
     101             :                 } else {
     102           0 :                         nodep = dom_object_get_node(objmap->baseobj);
     103           0 :                         if (nodep) {
     104           0 :                                 curnode = nodep->properties;
     105           0 :                                 if (curnode) {
     106           0 :                                         count++;
     107           0 :                                         while (curnode->next != NULL) {
     108           0 :                                                 count++;
     109           0 :                                                 curnode = curnode->next;
     110             :                                         }
     111             :                                 }
     112             :                         }
     113             :                 }
     114             :         }
     115             : 
     116           2 :         ZVAL_LONG(retval, count);
     117           2 :         return SUCCESS;
     118             : }
     119             : 
     120             : /* }}} */
     121             : 
     122             : /* {{{ proto DOMNode dom_namednodemap_get_named_item(string name);
     123             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
     124             : Since:
     125             : */
     126           2 : PHP_FUNCTION(dom_namednodemap_get_named_item)
     127             : {
     128             :         zval *id;
     129             :         int ret;
     130           2 :         size_t namedlen=0;
     131             :         dom_object *intern;
     132           2 :         xmlNodePtr itemnode = NULL;
     133             :         char *named;
     134             : 
     135             :         dom_nnodemap_object *objmap;
     136             :         xmlNodePtr nodep;
     137           2 :         xmlNotation *notep = NULL;
     138             : 
     139           2 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_namednodemap_class_entry, &named, &namedlen) == FAILURE) {
     140           0 :                 return;
     141             :         }
     142             : 
     143           2 :         intern = Z_DOMOBJ_P(id);
     144             : 
     145           2 :         objmap = (dom_nnodemap_object *)intern->ptr;
     146             : 
     147           2 :         if (objmap != NULL) {
     148           5 :                 if ((objmap->nodetype == XML_NOTATION_NODE) ||
     149           1 :                         objmap->nodetype == XML_ENTITY_NODE) {
     150           2 :                         if (objmap->ht) {
     151           2 :                                 if (objmap->nodetype == XML_ENTITY_NODE) {
     152           1 :                                         itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, (xmlChar *) named);
     153             :                                 } else {
     154           1 :                                         notep = (xmlNotation *)xmlHashLookup(objmap->ht, (xmlChar *) named);
     155           1 :                                         if (notep) {
     156           0 :                                                 itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
     157             :                                         }
     158             :                                 }
     159             :                         }
     160             :                 } else {
     161           0 :                         nodep = dom_object_get_node(objmap->baseobj);
     162           0 :                         if (nodep) {
     163           0 :                                 itemnode = (xmlNodePtr)xmlHasProp(nodep, (xmlChar *) named);
     164             :                         }
     165             :                 }
     166             :         }
     167             : 
     168           2 :         if (itemnode) {
     169           0 :                 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
     170           0 :                 return;
     171             :         } else {
     172           2 :                 RETVAL_NULL();
     173             :         }
     174             : }
     175             : /* }}} end dom_namednodemap_get_named_item */
     176             : 
     177             : /* {{{ proto DOMNode dom_namednodemap_set_named_item(DOMNode arg);
     178             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1025163788
     179             : Since:
     180             : */
     181           0 : PHP_FUNCTION(dom_namednodemap_set_named_item)
     182             : {
     183           0 :  DOM_NOT_IMPLEMENTED();
     184             : }
     185             : /* }}} end dom_namednodemap_set_named_item */
     186             : 
     187             : /* {{{ proto DOMNode dom_namednodemap_remove_named_item(string name);
     188             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D58B193
     189             : Since:
     190             : */
     191           0 : PHP_FUNCTION(dom_namednodemap_remove_named_item)
     192             : {
     193           0 :  DOM_NOT_IMPLEMENTED();
     194             : }
     195             : /* }}} end dom_namednodemap_remove_named_item */
     196             : 
     197             : /* {{{ proto DOMNode dom_namednodemap_item(int index);
     198             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-349467F9
     199             : Since:
     200             : */
     201          12 : PHP_FUNCTION(dom_namednodemap_item)
     202             : {
     203             :         zval *id;
     204             :         zend_long index;
     205             :         int ret;
     206             :         dom_object *intern;
     207          12 :         xmlNodePtr itemnode = NULL;
     208             : 
     209             :         dom_nnodemap_object *objmap;
     210             :         xmlNodePtr nodep, curnode;
     211             :         int count;
     212             : 
     213          12 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &id, dom_namednodemap_class_entry, &index) == FAILURE) {
     214           0 :                 return;
     215             :         }
     216          12 :         if (index >= 0) {
     217          12 :                 if (ZEND_LONG_INT_OVFL(index)) {
     218           0 :                         php_error_docref(NULL, E_WARNING, "Invalid index");
     219           0 :                         RETURN_NULL();
     220             :                 }
     221             : 
     222          12 :                 intern = Z_DOMOBJ_P(id);
     223             : 
     224          12 :                 objmap = (dom_nnodemap_object *)intern->ptr;
     225             : 
     226          12 :                 if (objmap != NULL) {
     227          29 :                         if ((objmap->nodetype == XML_NOTATION_NODE) ||
     228           8 :                                 objmap->nodetype == XML_ENTITY_NODE) {
     229           9 :                                 if (objmap->ht) {
     230           9 :                                         if (objmap->nodetype == XML_ENTITY_NODE) {
     231           5 :                                                 itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
     232             :                                         } else {
     233           4 :                                                 itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
     234             :                                         }
     235             :                                 }
     236             :                         } else {
     237           3 :                                 nodep = dom_object_get_node(objmap->baseobj);
     238           3 :                                 if (nodep) {
     239           3 :                                         curnode = (xmlNodePtr)nodep->properties;
     240           3 :                                         count = 0;
     241           6 :                                         while (count < index && curnode != NULL) {
     242           0 :                                                 count++;
     243           0 :                                                 curnode = (xmlNodePtr)curnode->next;
     244             :                                         }
     245           3 :                                         itemnode = curnode;
     246             :                                 }
     247             :                         }
     248             :                 }
     249             : 
     250          12 :                 if (itemnode) {
     251          11 :                         DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
     252          11 :                         return;
     253             :                 }
     254             :         }
     255             : 
     256           1 :         RETVAL_NULL();
     257             : }
     258             : /* }}} end dom_namednodemap_item */
     259             : 
     260             : /* {{{ proto DOMNode dom_namednodemap_get_named_item_ns(string namespaceURI, string localName);
     261             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
     262             : Since: DOM Level 2
     263             : */
     264           0 : PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
     265             : {
     266             :         zval *id;
     267             :         int ret;
     268           0 :         size_t namedlen=0, urilen=0;
     269             :         dom_object *intern;
     270           0 :         xmlNodePtr itemnode = NULL;
     271             :         char *uri, *named;
     272             : 
     273             :         dom_nnodemap_object *objmap;
     274             :         xmlNodePtr nodep;
     275           0 :         xmlNotation *notep = NULL;
     276             : 
     277           0 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!s", &id, dom_namednodemap_class_entry, &uri, &urilen, &named, &namedlen) == FAILURE) {
     278           0 :                 return;
     279             :         }
     280             : 
     281           0 :         intern = Z_DOMOBJ_P(id);
     282             : 
     283           0 :         objmap = (dom_nnodemap_object *)intern->ptr;
     284             : 
     285           0 :         if (objmap != NULL) {
     286           0 :                 if ((objmap->nodetype == XML_NOTATION_NODE) ||
     287           0 :                         objmap->nodetype == XML_ENTITY_NODE) {
     288           0 :                         if (objmap->ht) {
     289           0 :                                 if (objmap->nodetype == XML_ENTITY_NODE) {
     290           0 :                                         itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, (xmlChar *) named);
     291             :                                 } else {
     292           0 :                                         notep = (xmlNotation *)xmlHashLookup(objmap->ht, (xmlChar *) named);
     293           0 :                                         if (notep) {
     294           0 :                                                 itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
     295             :                                         }
     296             :                                 }
     297             :                         }
     298             :                 } else {
     299           0 :                         nodep = dom_object_get_node(objmap->baseobj);
     300           0 :                         if (nodep) {
     301           0 :                                 itemnode = (xmlNodePtr)xmlHasNsProp(nodep, (xmlChar *) named, (xmlChar *) uri);
     302             :                         }
     303             :                 }
     304             :         }
     305             : 
     306           0 :         if (itemnode) {
     307           0 :                 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
     308           0 :                 return;
     309             :         } else {
     310           0 :                 RETVAL_NULL();
     311             :         }
     312             : }
     313             : /* }}} end dom_namednodemap_get_named_item_ns */
     314             : 
     315             : /* {{{ proto DOMNode dom_namednodemap_set_named_item_ns(DOMNode arg);
     316             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
     317             : Since: DOM Level 2
     318             : */
     319           0 : PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
     320             : {
     321           0 :  DOM_NOT_IMPLEMENTED();
     322             : }
     323             : /* }}} end dom_namednodemap_set_named_item_ns */
     324             : 
     325             : /* {{{ proto DOMNode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
     326             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
     327             : Since: DOM Level 2
     328             : */
     329           0 : PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
     330             : {
     331           0 :  DOM_NOT_IMPLEMENTED();
     332             : }
     333             : /* }}} end dom_namednodemap_remove_named_item_ns */
     334             : 
     335             : #endif
     336             : 
     337             : /*
     338             :  * Local variables:
     339             :  * tab-width: 4
     340             :  * c-basic-offset: 4
     341             :  * End:
     342             :  * vim600: noet sw=4 ts=4 fdm=marker
     343             :  * vim<600: noet sw=4 ts=4
     344             :  */

Generated by: LCOV version 1.10

Generated at Sun, 22 May 2016 10:52:53 +0000 (2 days ago)

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