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 - php_dom.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 737 784 94.0 %
Date: 2019-05-06 Functions: 48 50 96.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) The PHP Group                                          |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Christian Stocker <chregu@php.net>                          |
      16             :    |          Rob Richards <rrichards@php.net>                            |
      17             :    |          Marcus Borger <helly@php.net>                               |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : #if HAVE_LIBXML && HAVE_DOM
      27             : #include "ext/standard/php_rand.h"
      28             : #include "php_dom.h"
      29             : #include "dom_properties.h"
      30             : #include "zend_interfaces.h"
      31             : 
      32             : #include "ext/standard/info.h"
      33             : #define PHP_XPATH 1
      34             : #define PHP_XPTR 2
      35             : 
      36             : /* {{{ class entries */
      37             : PHP_DOM_EXPORT zend_class_entry *dom_node_class_entry;
      38             : PHP_DOM_EXPORT zend_class_entry *dom_domexception_class_entry;
      39             : PHP_DOM_EXPORT zend_class_entry *dom_domstringlist_class_entry;
      40             : PHP_DOM_EXPORT zend_class_entry *dom_namelist_class_entry;
      41             : PHP_DOM_EXPORT zend_class_entry *dom_domimplementationlist_class_entry;
      42             : PHP_DOM_EXPORT zend_class_entry *dom_domimplementationsource_class_entry;
      43             : PHP_DOM_EXPORT zend_class_entry *dom_domimplementation_class_entry;
      44             : PHP_DOM_EXPORT zend_class_entry *dom_documentfragment_class_entry;
      45             : PHP_DOM_EXPORT zend_class_entry *dom_document_class_entry;
      46             : PHP_DOM_EXPORT zend_class_entry *dom_nodelist_class_entry;
      47             : PHP_DOM_EXPORT zend_class_entry *dom_namednodemap_class_entry;
      48             : PHP_DOM_EXPORT zend_class_entry *dom_characterdata_class_entry;
      49             : PHP_DOM_EXPORT zend_class_entry *dom_attr_class_entry;
      50             : PHP_DOM_EXPORT zend_class_entry *dom_element_class_entry;
      51             : PHP_DOM_EXPORT zend_class_entry *dom_text_class_entry;
      52             : PHP_DOM_EXPORT zend_class_entry *dom_comment_class_entry;
      53             : PHP_DOM_EXPORT zend_class_entry *dom_typeinfo_class_entry;
      54             : PHP_DOM_EXPORT zend_class_entry *dom_userdatahandler_class_entry;
      55             : PHP_DOM_EXPORT zend_class_entry *dom_domerror_class_entry;
      56             : PHP_DOM_EXPORT zend_class_entry *dom_domerrorhandler_class_entry;
      57             : PHP_DOM_EXPORT zend_class_entry *dom_domlocator_class_entry;
      58             : PHP_DOM_EXPORT zend_class_entry *dom_domconfiguration_class_entry;
      59             : PHP_DOM_EXPORT zend_class_entry *dom_cdatasection_class_entry;
      60             : PHP_DOM_EXPORT zend_class_entry *dom_documenttype_class_entry;
      61             : PHP_DOM_EXPORT zend_class_entry *dom_notation_class_entry;
      62             : PHP_DOM_EXPORT zend_class_entry *dom_entity_class_entry;
      63             : PHP_DOM_EXPORT zend_class_entry *dom_entityreference_class_entry;
      64             : PHP_DOM_EXPORT zend_class_entry *dom_processinginstruction_class_entry;
      65             : PHP_DOM_EXPORT zend_class_entry *dom_string_extend_class_entry;
      66             : #if defined(LIBXML_XPATH_ENABLED)
      67             : PHP_DOM_EXPORT zend_class_entry *dom_xpath_class_entry;
      68             : #endif
      69             : PHP_DOM_EXPORT zend_class_entry *dom_namespace_node_class_entry;
      70             : /* }}} */
      71             : 
      72             : zend_object_handlers dom_object_handlers;
      73             : zend_object_handlers dom_nnodemap_object_handlers;
      74             : #if defined(LIBXML_XPATH_ENABLED)
      75             : zend_object_handlers dom_xpath_object_handlers;
      76             : #endif
      77             : 
      78             : static HashTable classes;
      79             : /* {{{ prop handler tables */
      80             : static HashTable dom_domstringlist_prop_handlers;
      81             : static HashTable dom_namelist_prop_handlers;
      82             : static HashTable dom_domimplementationlist_prop_handlers;
      83             : static HashTable dom_document_prop_handlers;
      84             : static HashTable dom_node_prop_handlers;
      85             : static HashTable dom_nodelist_prop_handlers;
      86             : static HashTable dom_namednodemap_prop_handlers;
      87             : static HashTable dom_characterdata_prop_handlers;
      88             : static HashTable dom_attr_prop_handlers;
      89             : static HashTable dom_element_prop_handlers;
      90             : static HashTable dom_text_prop_handlers;
      91             : static HashTable dom_typeinfo_prop_handlers;
      92             : static HashTable dom_domerror_prop_handlers;
      93             : static HashTable dom_domlocator_prop_handlers;
      94             : static HashTable dom_documenttype_prop_handlers;
      95             : static HashTable dom_notation_prop_handlers;
      96             : static HashTable dom_entity_prop_handlers;
      97             : static HashTable dom_processinginstruction_prop_handlers;
      98             : static HashTable dom_namespace_node_prop_handlers;
      99             : #if defined(LIBXML_XPATH_ENABLED)
     100             : static HashTable dom_xpath_prop_handlers;
     101             : #endif
     102             : /* }}} */
     103             : 
     104             : typedef int (*dom_read_t)(dom_object *obj, zval *retval);
     105             : typedef int (*dom_write_t)(dom_object *obj, zval *newval);
     106             : 
     107             : typedef struct _dom_prop_handler {
     108             :         dom_read_t read_func;
     109             :         dom_write_t write_func;
     110             : } dom_prop_handler;
     111             : 
     112        1074 : static zend_object_handlers* dom_get_obj_handlers(void) {
     113        1074 :         return &dom_object_handlers;
     114             : }
     115             : 
     116             : /* {{{ int dom_node_is_read_only(xmlNodePtr node) */
     117         283 : int dom_node_is_read_only(xmlNodePtr node) {
     118         283 :         switch (node->type) {
     119           0 :                 case XML_ENTITY_REF_NODE:
     120             :                 case XML_ENTITY_NODE:
     121             :                 case XML_DOCUMENT_TYPE_NODE:
     122             :                 case XML_NOTATION_NODE:
     123             :                 case XML_DTD_NODE:
     124             :                 case XML_ELEMENT_DECL:
     125             :                 case XML_ATTRIBUTE_DECL:
     126             :                 case XML_ENTITY_DECL:
     127             :                 case XML_NAMESPACE_DECL:
     128           0 :                         return SUCCESS;
     129             :                         break;
     130         283 :                 default:
     131         283 :                         if (node->doc == NULL) {
     132           1 :                                 return SUCCESS;
     133             :                         } else {
     134         282 :                                 return FAILURE;
     135             :                         }
     136             :         }
     137             : }
     138             : /* }}} end dom_node_is_read_only */
     139             : 
     140             : /* {{{ int dom_node_children_valid(xmlNodePtr node) */
     141         490 : int dom_node_children_valid(xmlNodePtr node) {
     142         490 :         switch (node->type) {
     143          48 :                 case XML_DOCUMENT_TYPE_NODE:
     144             :                 case XML_DTD_NODE:
     145             :                 case XML_PI_NODE:
     146             :                 case XML_COMMENT_NODE:
     147             :                 case XML_TEXT_NODE:
     148             :                 case XML_CDATA_SECTION_NODE:
     149             :                 case XML_NOTATION_NODE:
     150          48 :                         return FAILURE;
     151             :                         break;
     152         442 :                 default:
     153         442 :                         return SUCCESS;
     154             :         }
     155             : }
     156             : /* }}} end dom_node_children_valid */
     157             : 
     158             : /* {{{ dom_get_doc_props() */
     159        1288 : dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
     160             : {
     161             :         dom_doc_propsptr doc_props;
     162             : 
     163        1288 :         if (document && document->doc_props) {
     164         959 :                 return document->doc_props;
     165             :         } else {
     166         329 :                 doc_props = emalloc(sizeof(libxml_doc_props));
     167         329 :                 doc_props->formatoutput = 0;
     168         329 :                 doc_props->validateonparse = 0;
     169         329 :                 doc_props->resolveexternals = 0;
     170         329 :                 doc_props->preservewhitespace = 1;
     171         329 :                 doc_props->substituteentities = 0;
     172         329 :                 doc_props->stricterror = 1;
     173         329 :                 doc_props->recover = 0;
     174         329 :                 doc_props->classmap = NULL;
     175         329 :                 if (document) {
     176         328 :                         document->doc_props = doc_props;
     177             :                 }
     178         329 :                 return doc_props;
     179             :         }
     180             : }
     181             : 
     182           2 : static void dom_copy_doc_props(php_libxml_ref_obj *source_doc, php_libxml_ref_obj *dest_doc)
     183             : {
     184             :         dom_doc_propsptr source, dest;
     185             : 
     186           2 :         if (source_doc && dest_doc) {
     187             : 
     188           2 :                 source = dom_get_doc_props(source_doc);
     189           2 :                 dest = dom_get_doc_props(dest_doc);
     190             : 
     191           2 :                 dest->formatoutput = source->formatoutput;
     192           2 :                 dest->validateonparse = source->validateonparse;
     193           2 :                 dest->resolveexternals = source->resolveexternals;
     194           2 :                 dest->preservewhitespace = source->preservewhitespace;
     195           2 :                 dest->substituteentities = source->substituteentities;
     196           2 :                 dest->stricterror = source->stricterror;
     197           2 :                 dest->recover = source->recover;
     198           2 :                 if (source->classmap) {
     199           0 :                         ALLOC_HASHTABLE(dest->classmap);
     200           0 :                         zend_hash_init(dest->classmap, 0, NULL, NULL, 0);
     201           0 :                         zend_hash_copy(dest->classmap, source->classmap, NULL);
     202             :                 }
     203             : 
     204             :         }
     205           2 : }
     206             : 
     207           4 : void dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *ce)
     208             : {
     209             :         dom_doc_propsptr doc_props;
     210             : 
     211           4 :         if (document) {
     212           4 :                 doc_props = dom_get_doc_props(document);
     213           4 :                 if (doc_props->classmap == NULL) {
     214           2 :                         if (ce == NULL) {
     215           0 :                                 return;
     216             :                         }
     217           2 :                         ALLOC_HASHTABLE(doc_props->classmap);
     218           2 :                         zend_hash_init(doc_props->classmap, 0, NULL, NULL, 0);
     219             :                 }
     220           4 :                 if (ce) {
     221           3 :                         zend_hash_update_ptr(doc_props->classmap, basece->name, ce);
     222             :                 } else {
     223           1 :                         zend_hash_del(doc_props->classmap, basece->name);
     224             :                 }
     225             :         }
     226             : }
     227             : 
     228         650 : zend_class_entry *dom_get_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece)
     229             : {
     230             :         dom_doc_propsptr doc_props;
     231             : 
     232         650 :         if (document) {
     233         650 :                 doc_props = dom_get_doc_props(document);
     234         650 :                 if (doc_props->classmap) {
     235           8 :                         zend_class_entry *ce = zend_hash_find_ptr(doc_props->classmap, basece->name);
     236           4 :                         if (ce) {
     237           3 :                                 return ce;
     238             :                         }
     239             :                 }
     240             :         }
     241             : 
     242         647 :         return basece;
     243             : }
     244             : /* }}} */
     245             : 
     246             : /* {{{ dom_get_strict_error() */
     247         233 : int dom_get_strict_error(php_libxml_ref_obj *document) {
     248             :         int stricterror;
     249             :         dom_doc_propsptr doc_props;
     250             : 
     251         233 :         doc_props = dom_get_doc_props(document);
     252         233 :         stricterror = doc_props->stricterror;
     253         233 :         if (document == NULL) {
     254           1 :                 efree(doc_props);
     255             :         }
     256             : 
     257         233 :         return stricterror;
     258             : }
     259             : /* }}} */
     260             : 
     261             : /* {{{ xmlNodePtr dom_object_get_node(dom_object *obj) */
     262        2352 : PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj)
     263             : {
     264        2352 :         if (obj && obj->ptr != NULL) {
     265        1972 :                 return ((php_libxml_node_ptr *)obj->ptr)->node;
     266             :         } else {
     267         380 :                 return NULL;
     268             :         }
     269             : }
     270             : /* }}} end dom_object_get_node */
     271             : 
     272             : /* {{{ dom_object *php_dom_object_get_data(xmlNodePtr obj) */
     273        1204 : PHP_DOM_EXPORT dom_object *php_dom_object_get_data(xmlNodePtr obj)
     274             : {
     275        1204 :         if (obj && obj->_private != NULL) {
     276         514 :                 return (dom_object *) ((php_libxml_node_ptr *) obj->_private)->_private;
     277             :         } else {
     278         690 :                 return NULL;
     279             :         }
     280             : }
     281             : /* }}} end php_dom_object_get_data */
     282             : 
     283             : /* {{{ dom_read_na */
     284           0 : static int dom_read_na(dom_object *obj, zval *retval)
     285             : {
     286           0 :         zend_throw_error(NULL, "Cannot read property");
     287           0 :         return FAILURE;
     288             : }
     289             : /* }}} */
     290             : 
     291             : /* {{{ dom_write_na */
     292           0 : static int dom_write_na(dom_object *obj, zval *newval)
     293             : {
     294           0 :         zend_throw_error(NULL, "Cannot write property");
     295           0 :         return FAILURE;
     296             : }
     297             : /* }}} */
     298             : 
     299             : /* {{{ dom_register_prop_handler */
     300     2027784 : static void dom_register_prop_handler(HashTable *prop_handler, char *name, size_t name_len, dom_read_t read_func, dom_write_t write_func)
     301             : {
     302             :         dom_prop_handler hnd;
     303             :         zend_string *str;
     304             : 
     305     2027784 :         hnd.read_func = read_func ? read_func : dom_read_na;
     306     2027784 :         hnd.write_func = write_func ? write_func : dom_write_na;
     307     2027784 :         str = zend_string_init_interned(name, name_len, 1);
     308             :         zend_hash_add_mem(prop_handler, str, &hnd, sizeof(dom_prop_handler));
     309             :         zend_string_release_ex(str, 1);
     310     2027784 : }
     311             : /* }}} */
     312             : 
     313          26 : static zval *dom_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot) /* {{{ */
     314             : {
     315          26 :         dom_object *obj = php_dom_obj_from_obj(object);
     316          26 :         zval *retval = NULL;
     317             : 
     318          52 :         if (!obj->prop_handler || !zend_hash_exists(obj->prop_handler, name)) {
     319           4 :                 retval = zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
     320             :         }
     321          26 :         return retval;
     322             : }
     323             : /* }}} */
     324             : 
     325             : /* {{{ dom_read_property */
     326        1332 : zval *dom_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
     327             : {
     328        1332 :         dom_object *obj = php_dom_obj_from_obj(object);
     329             :         zval *retval;
     330        1332 :         dom_prop_handler *hnd = NULL;
     331             : 
     332        1332 :         if (obj->prop_handler != NULL) {
     333        2660 :                 hnd = zend_hash_find_ptr(obj->prop_handler, name);
     334           2 :         } else if (instanceof_function(obj->std.ce, dom_node_class_entry)) {
     335           2 :                 php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", ZSTR_VAL(obj->std.ce->name));
     336             :         }
     337             : 
     338        1332 :         if (hnd) {
     339        1328 :                 int ret = hnd->read_func(obj, rv);
     340        1328 :                 if (ret == SUCCESS) {
     341        1320 :                         retval = rv;
     342             :                 } else {
     343           8 :                         retval = &EG(uninitialized_zval);
     344             :                 }
     345             :         } else {
     346           4 :                 retval = zend_std_read_property(object, name, type, cache_slot, rv);
     347             :         }
     348             : 
     349        1332 :         return retval;
     350             : }
     351             : /* }}} */
     352             : 
     353             : /* {{{ dom_write_property */
     354          77 : zval *dom_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
     355             : {
     356          77 :         dom_object *obj = php_dom_obj_from_obj(object);
     357          77 :         dom_prop_handler *hnd = NULL;
     358             : 
     359          77 :         if (obj->prop_handler != NULL) {
     360         154 :                 hnd = zend_hash_find_ptr(obj->prop_handler, name);
     361             :         }
     362          77 :         if (hnd) {
     363          75 :                 hnd->write_func(obj, value);
     364             :         } else {
     365           2 :                 value = zend_std_write_property(object, name, value, cache_slot);
     366             :         }
     367             : 
     368          77 :         return value;
     369             : }
     370             : /* }}} */
     371             : 
     372             : /* {{{ dom_property_exists */
     373           9 : static int dom_property_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot)
     374             : {
     375           9 :         dom_object *obj = php_dom_obj_from_obj(object);
     376           9 :         dom_prop_handler *hnd = NULL;
     377           9 :         int retval = 0;
     378             : 
     379           9 :         if (obj->prop_handler != NULL) {
     380          18 :                 hnd = zend_hash_find_ptr(obj->prop_handler, name);
     381             :         }
     382           9 :         if (hnd) {
     383             :                 zval tmp;
     384             : 
     385           7 :                 if (check_empty == 2) {
     386           0 :                         retval = 1;
     387           7 :                 } else if (hnd->read_func(obj, &tmp) == SUCCESS) {
     388           7 :                         if (check_empty == 1) {
     389           5 :                                 retval = zend_is_true(&tmp);
     390           2 :                         } else if (check_empty == 0) {
     391           2 :                                 retval = (Z_TYPE(tmp) != IS_NULL);
     392             :                         }
     393           7 :                         zval_ptr_dtor(&tmp);
     394             :                 }
     395             :         } else {
     396           2 :                 retval = zend_std_has_property(object, name, check_empty, cache_slot);
     397             :         }
     398             : 
     399           9 :         return retval;
     400             : }
     401             : /* }}} */
     402             : 
     403          11 : static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */
     404             : {
     405          11 :         dom_object                      *obj = php_dom_obj_from_obj(object);
     406             :         HashTable                       *debug_info,
     407          11 :                                                 *prop_handlers = obj->prop_handler,
     408             :                                                 *std_props;
     409             :         zend_string                     *string_key;
     410             :         dom_prop_handler        *entry;
     411             :         zend_string         *object_str;
     412             : 
     413          11 :         *is_temp = 1;
     414             : 
     415          11 :         std_props = zend_std_get_properties(object);
     416          11 :         debug_info = zend_array_dup(std_props);
     417             : 
     418          11 :         if (!prop_handlers) {
     419           2 :                 return debug_info;
     420             :         }
     421             : 
     422           9 :         object_str = zend_string_init("(object value omitted)", sizeof("(object value omitted)")-1, 0);
     423             : 
     424         389 :         ZEND_HASH_FOREACH_STR_KEY_PTR(prop_handlers, string_key, entry) {
     425             :                 zval value;
     426             : 
     427         190 :                 if (entry->read_func(obj, &value) == FAILURE || !string_key) {
     428           0 :                         continue;
     429             :                 }
     430             : 
     431         190 :                 if (Z_TYPE(value) == IS_OBJECT) {
     432          42 :                         zval_ptr_dtor(&value);
     433          42 :                         ZVAL_NEW_STR(&value, object_str);
     434             :                         zend_string_addref(object_str);
     435             :                 }
     436             : 
     437         190 :                 zend_hash_add(debug_info, string_key, &value);
     438             :         } ZEND_HASH_FOREACH_END();
     439             : 
     440             :         zend_string_release_ex(object_str, 0);
     441             : 
     442           9 :         return debug_info;
     443             : }
     444             : /* }}} */
     445             : 
     446          11 : static HashTable* dom_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
     447             : {
     448          11 :        return dom_get_debug_info_helper(object, is_temp);
     449             : }
     450             : /* }}} */
     451             : 
     452         100 : void *php_dom_export_node(zval *object) /* {{{ */
     453             : {
     454             :         php_libxml_node_object *intern;
     455         100 :         xmlNodePtr nodep = NULL;
     456             : 
     457         100 :         intern = (php_libxml_node_object *) Z_DOMOBJ_P(object);
     458         100 :         if (intern->node) {
     459         100 :                 nodep = intern->node->node;
     460             :         }
     461             : 
     462         100 :         return nodep;
     463             : }
     464             : /* }}} */
     465             : 
     466             : /* {{{ proto somNode dom_import_simplexml(sxeobject node)
     467             :    Get a simplexml_element object from dom to allow for processing */
     468           1 : PHP_FUNCTION(dom_import_simplexml)
     469             : {
     470             :         zval *node;
     471           1 :         xmlNodePtr nodep = NULL;
     472             :         php_libxml_node_object *nodeobj;
     473             :         int ret;
     474             : 
     475           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &node) == FAILURE) {
     476           0 :                 return;
     477             :         }
     478             : 
     479           1 :         nodeobj = (php_libxml_node_object *) ((char *) Z_OBJ_P(node) - Z_OBJ_HT_P(node)->offset);
     480           1 :         nodep = php_libxml_import_node(node);
     481             : 
     482           1 :         if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
     483           1 :                 DOM_RET_OBJ((xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
     484             :         } else {
     485           0 :                 php_error_docref(NULL, E_WARNING, "Invalid Nodetype to import");
     486           0 :                 RETURN_NULL();
     487             :         }
     488             : }
     489             : /* }}} */
     490             : 
     491             : static dom_object* dom_objects_set_class(zend_class_entry *class_type);
     492             : 
     493           3 : static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */
     494             : {
     495           3 :         dom_object *intern = php_dom_obj_from_obj(zobject);
     496           3 :         dom_object *clone = dom_objects_set_class(intern->std.ce);
     497             : 
     498           3 :         clone->std.handlers = dom_get_obj_handlers();
     499             : 
     500           3 :         if (instanceof_function(intern->std.ce, dom_node_class_entry)) {
     501           3 :                 xmlNodePtr node = (xmlNodePtr)dom_object_get_node(intern);
     502           3 :                 if (node != NULL) {
     503           3 :                         xmlNodePtr cloned_node = xmlDocCopyNode(node, node->doc, 1);
     504           3 :                         if (cloned_node != NULL) {
     505             :                                 /* If we cloned a document then we must create new doc proxy */
     506           3 :                                 if (cloned_node->doc == node->doc) {
     507           1 :                                         clone->document = intern->document;
     508             :                                 }
     509           3 :                                 php_libxml_increment_doc_ref((php_libxml_node_object *)clone, cloned_node->doc);
     510           3 :                                 php_libxml_increment_node_ptr((php_libxml_node_object *)clone, cloned_node, (void *)clone);
     511           3 :                                 if (intern->document != clone->document) {
     512           2 :                                         dom_copy_doc_props(intern->document, clone->document);
     513             :                                 }
     514             :                         }
     515             : 
     516             :                 }
     517             :         }
     518             : 
     519           3 :         zend_objects_clone_members(&clone->std, &intern->std);
     520             : 
     521           3 :         return &clone->std;
     522             : }
     523             : /* }}} */
     524             : 
     525     3364278 : static void dom_copy_prop_handler(zval *zv) /* {{{ */
     526             : {
     527     3364278 :         dom_prop_handler *hnd = Z_PTR_P(zv);
     528     3364278 :         Z_PTR_P(zv) = malloc(sizeof(dom_prop_handler));
     529     3364278 :         memcpy(Z_PTR_P(zv), hnd, sizeof(dom_prop_handler));
     530     3364278 : }
     531             : /* }}} */
     532             : 
     533     5406570 : static void dom_dtor_prop_handler(zval *zv) /* {{{ */
     534             : {
     535     5406570 :         free(Z_PTR_P(zv));
     536     5406570 : }
     537             : 
     538             : /* {{{ arginfo */
     539             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_import_simplexml, 0, 0, 1)
     540             :         ZEND_ARG_INFO(0, node)
     541             : ZEND_END_ARG_INFO()
     542             : /* }}} */
     543             : 
     544             : static const zend_function_entry dom_functions[] = {
     545             :         PHP_FE(dom_import_simplexml, arginfo_dom_import_simplexml)
     546             :         PHP_FE_END
     547             : };
     548             : 
     549             : static const zend_module_dep dom_deps[] = {
     550             :         ZEND_MOD_REQUIRED("libxml")
     551             :         ZEND_MOD_CONFLICTS("domxml")
     552             :         ZEND_MOD_END
     553             : };
     554             : 
     555             : zend_module_entry dom_module_entry = { /* {{{ */
     556             :         STANDARD_MODULE_HEADER_EX, NULL,
     557             :         dom_deps,
     558             :         "dom",
     559             :         dom_functions,
     560             :         PHP_MINIT(dom),
     561             :         PHP_MSHUTDOWN(dom),
     562             :         NULL,
     563             :         NULL,
     564             :         PHP_MINFO(dom),
     565             :         DOM_API_VERSION, /* Extension versionnumber */
     566             :         STANDARD_MODULE_PROPERTIES
     567             : };
     568             : /* }}} */
     569             : 
     570             : #ifdef COMPILE_DL_DOM
     571             : ZEND_GET_MODULE(dom)
     572             : #endif
     573             : 
     574             : void dom_objects_free_storage(zend_object *object);
     575             : void dom_nnodemap_objects_free_storage(zend_object *object);
     576             : static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int type, zval *rv);
     577             : static int dom_nodelist_has_dimension(zend_object *object, zval *member, int check_empty);
     578             : static zend_object *dom_objects_store_clone_obj(zend_object *zobject);
     579             : static void dom_nnodemap_object_dtor(zend_object *object);
     580             : #if defined(LIBXML_XPATH_ENABLED)
     581             : void dom_xpath_objects_free_storage(zend_object *object);
     582             : #endif
     583             : 
     584             : /* {{{ PHP_MINIT_FUNCTION(dom) */
     585       23043 : PHP_MINIT_FUNCTION(dom)
     586             : {
     587             :         zend_class_entry ce;
     588             : 
     589       23043 :         memcpy(&dom_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
     590       23043 :         dom_object_handlers.offset = XtOffsetOf(dom_object, std);
     591       23043 :         dom_object_handlers.free_obj = dom_objects_free_storage;
     592       23043 :         dom_object_handlers.read_property = dom_read_property;
     593       23043 :         dom_object_handlers.write_property = dom_write_property;
     594       23043 :         dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
     595       23043 :         dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
     596       23043 :         dom_object_handlers.has_property = dom_property_exists;
     597       23043 :         dom_object_handlers.get_debug_info = dom_get_debug_info;
     598             : 
     599       23043 :         memcpy(&dom_nnodemap_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
     600       23043 :         dom_nnodemap_object_handlers.free_obj = dom_nnodemap_objects_free_storage;
     601       23043 :         dom_nnodemap_object_handlers.dtor_obj = dom_nnodemap_object_dtor;
     602       23043 :         dom_nnodemap_object_handlers.read_dimension = dom_nodelist_read_dimension;
     603       23043 :         dom_nnodemap_object_handlers.has_dimension = dom_nodelist_has_dimension;
     604             : 
     605       23043 :         zend_hash_init(&classes, 0, NULL, NULL, 1);
     606             : 
     607       23043 :         INIT_CLASS_ENTRY(ce, "DOMException", php_dom_domexception_class_functions);
     608       23043 :         dom_domexception_class_entry = zend_register_internal_class_ex(&ce, zend_ce_exception);
     609       23043 :         dom_domexception_class_entry->ce_flags |= ZEND_ACC_FINAL;
     610       23043 :         zend_declare_property_long(dom_domexception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC);
     611             : 
     612       23043 :         REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
     613             : 
     614       23043 :         zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     615       23043 :         dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", sizeof("length")-1, dom_domstringlist_length_read, NULL);
     616       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_domstringlist_prop_handlers);
     617             : 
     618       23043 :         REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
     619             : 
     620       23043 :         zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     621       23043 :         dom_register_prop_handler(&dom_namelist_prop_handlers, "length", sizeof("length")-1, dom_namelist_length_read, NULL);
     622       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_namelist_prop_handlers);
     623             : 
     624       23043 :         REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
     625             : 
     626       23043 :         zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     627       23043 :         dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", sizeof("length")-1, dom_domimplementationlist_length_read, NULL);
     628       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_domimplementationlist_prop_handlers);
     629             : 
     630       23043 :         REGISTER_DOM_CLASS(ce, "DOMImplementationSource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry);
     631       23043 :         REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry);
     632             : 
     633       23043 :         REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry);
     634             : 
     635       23043 :         zend_hash_init(&dom_node_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     636       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "nodeName", sizeof("nodeName")-1, dom_node_node_name_read, NULL);
     637       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "nodeValue", sizeof("nodeValue")-1, dom_node_node_value_read, dom_node_node_value_write);
     638       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "nodeType", sizeof("nodeType")-1, dom_node_node_type_read, NULL);
     639       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "parentNode", sizeof("parentNode")-1, dom_node_parent_node_read, NULL);
     640       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "childNodes", sizeof("childNodes")-1, dom_node_child_nodes_read, NULL);
     641       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "firstChild", sizeof("firstChild")-1, dom_node_first_child_read, NULL);
     642       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "lastChild", sizeof("lastChild")-1, dom_node_last_child_read, NULL);
     643       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "previousSibling", sizeof("previousSibling")-1, dom_node_previous_sibling_read, NULL);
     644       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "nextSibling", sizeof("nextSibling")-1, dom_node_next_sibling_read, NULL);
     645       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "attributes", sizeof("attributes")-1, dom_node_attributes_read, NULL);
     646       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "ownerDocument", sizeof("ownerDocument")-1, dom_node_owner_document_read, NULL);
     647       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "namespaceURI", sizeof("namespaceURI")-1, dom_node_namespace_uri_read, NULL);
     648       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "prefix", sizeof("prefix")-1, dom_node_prefix_read, dom_node_prefix_write);
     649       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "localName", sizeof("localName")-1, dom_node_local_name_read, NULL);
     650       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "baseURI", sizeof("baseURI")-1, dom_node_base_uri_read, NULL);
     651       23043 :         dom_register_prop_handler(&dom_node_prop_handlers, "textContent", sizeof("textContent")-1, dom_node_text_content_read, dom_node_text_content_write);
     652       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_node_prop_handlers);
     653             : 
     654       23043 :         REGISTER_DOM_CLASS(ce, "DOMNameSpaceNode", NULL, NULL, dom_namespace_node_class_entry);
     655             : 
     656       23043 :         zend_hash_init(&dom_namespace_node_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     657       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeName", sizeof("nodeName")-1, dom_node_node_name_read, NULL);
     658       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeValue", sizeof("nodeValue")-1, dom_node_node_value_read, NULL);
     659       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeType", sizeof("nodeType")-1, dom_node_node_type_read, NULL);
     660       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "prefix", sizeof("prefix")-1, dom_node_prefix_read, NULL);
     661       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "localName", sizeof("localName")-1, dom_node_local_name_read, NULL);
     662       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "namespaceURI", sizeof("namespaceURI")-1, dom_node_namespace_uri_read, NULL);
     663       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "ownerDocument", sizeof("ownerDocument")-1, dom_node_owner_document_read, NULL);
     664       23043 :         dom_register_prop_handler(&dom_namespace_node_prop_handlers, "parentNode", sizeof("parentNode")-1, dom_node_parent_node_read, NULL);
     665       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_namespace_node_prop_handlers);
     666             : 
     667       23043 :         REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry);
     668       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_node_prop_handlers);
     669             : 
     670       23043 :         REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry);
     671       23043 :         zend_hash_init(&dom_document_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     672       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "doctype", sizeof("doctype")-1, dom_document_doctype_read, NULL);
     673       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "implementation", sizeof("implementation")-1, dom_document_implementation_read, NULL);
     674       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "documentElement", sizeof("documentElement")-1, dom_document_document_element_read, NULL);
     675       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_document_encoding_read, NULL);
     676       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "encoding", sizeof("encoding")-1, dom_document_encoding_read, dom_document_encoding_write);
     677       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "xmlEncoding", sizeof("xmlEncoding")-1, dom_document_encoding_read, NULL);
     678       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "standalone", sizeof("standalone")-1, dom_document_standalone_read, dom_document_standalone_write);
     679       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "xmlStandalone", sizeof("xmlStandalone")-1, dom_document_standalone_read, dom_document_standalone_write);
     680       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "version", sizeof("version")-1, dom_document_version_read, dom_document_version_write);
     681       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "xmlVersion", sizeof("xmlVersion")-1, dom_document_version_read, dom_document_version_write);
     682       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "strictErrorChecking", sizeof("strictErrorChecking")-1, dom_document_strict_error_checking_read, dom_document_strict_error_checking_write);
     683       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "documentURI", sizeof("documentURI")-1, dom_document_document_uri_read, dom_document_document_uri_write);
     684       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "config", sizeof("config")-1, dom_document_config_read, NULL);
     685       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "formatOutput", sizeof("formatOutput")-1, dom_document_format_output_read, dom_document_format_output_write);
     686       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "validateOnParse", sizeof("validateOnParse")-1, dom_document_validate_on_parse_read, dom_document_validate_on_parse_write);
     687       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "resolveExternals", sizeof("resolveExternals")-1, dom_document_resolve_externals_read, dom_document_resolve_externals_write);
     688       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "preserveWhiteSpace", sizeof("preserveWhitespace")-1, dom_document_preserve_whitespace_read, dom_document_preserve_whitespace_write);
     689       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "recover", sizeof("recover")-1, dom_document_recover_read, dom_document_recover_write);
     690       23043 :         dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", sizeof("substituteEntities")-1, dom_document_substitue_entities_read, dom_document_substitue_entities_write);
     691             : 
     692       23043 :         zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     693       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_document_prop_handlers);
     694             : 
     695       23043 :         INIT_CLASS_ENTRY(ce, "DOMNodeList", php_dom_nodelist_class_functions);
     696       23043 :         ce.create_object = dom_nnodemap_objects_new;
     697       23043 :         dom_nodelist_class_entry = zend_register_internal_class_ex(&ce, NULL);
     698       23043 :         dom_nodelist_class_entry->get_iterator = php_dom_get_iterator;
     699       23043 :         zend_class_implements(dom_nodelist_class_entry, 2, zend_ce_traversable, zend_ce_countable);
     700             : 
     701       23043 :         zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     702       23043 :         dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", sizeof("length")-1, dom_nodelist_length_read, NULL);
     703       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_nodelist_prop_handlers);
     704             : 
     705       23043 :         INIT_CLASS_ENTRY(ce, "DOMNamedNodeMap", php_dom_namednodemap_class_functions);
     706       23043 :         ce.create_object = dom_nnodemap_objects_new;
     707       23043 :         dom_namednodemap_class_entry = zend_register_internal_class_ex(&ce, NULL);
     708       23043 :         dom_namednodemap_class_entry->get_iterator = php_dom_get_iterator;
     709       23043 :         zend_class_implements(dom_namednodemap_class_entry, 2, zend_ce_traversable, zend_ce_countable);
     710             : 
     711       23043 :         zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     712       23043 :         dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", sizeof("length")-1, dom_namednodemap_length_read, NULL);
     713       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_namednodemap_prop_handlers);
     714             : 
     715       23043 :         REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry);
     716             : 
     717       23043 :         zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     718       23043 :         dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", sizeof("data")-1, dom_characterdata_data_read, dom_characterdata_data_write);
     719       23043 :         dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", sizeof("length")-1, dom_characterdata_length_read, NULL);
     720       23043 :         zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     721       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_characterdata_prop_handlers);
     722             : 
     723       23043 :         REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
     724             : 
     725       23043 :         zend_hash_init(&dom_attr_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     726       23043 :         dom_register_prop_handler(&dom_attr_prop_handlers, "name", sizeof("name")-1, dom_attr_name_read, NULL);
     727       23043 :         dom_register_prop_handler(&dom_attr_prop_handlers, "specified", sizeof("specified")-1, dom_attr_specified_read, NULL);
     728       23043 :         dom_register_prop_handler(&dom_attr_prop_handlers, "value", sizeof("value")-1, dom_attr_value_read, dom_attr_value_write);
     729       23043 :         dom_register_prop_handler(&dom_attr_prop_handlers, "ownerElement", sizeof("ownerElement")-1, dom_attr_owner_element_read, NULL);
     730       23043 :         dom_register_prop_handler(&dom_attr_prop_handlers, "schemaTypeInfo", sizeof("schemaTypeInfo")-1, dom_attr_schema_type_info_read, NULL);
     731       23043 :         zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     732       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_attr_prop_handlers);
     733             : 
     734       23043 :         REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry);
     735             : 
     736       23043 :         zend_hash_init(&dom_element_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     737       23043 :         dom_register_prop_handler(&dom_element_prop_handlers, "tagName", sizeof("tagName")-1, dom_element_tag_name_read, NULL);
     738       23043 :         dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", sizeof("schemaTypeInfo")-1, dom_element_schema_type_info_read, NULL);
     739       23043 :         zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     740       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_element_prop_handlers);
     741             : 
     742       23043 :         REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
     743             : 
     744       23043 :         zend_hash_init(&dom_text_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     745       23043 :         dom_register_prop_handler(&dom_text_prop_handlers, "wholeText", sizeof("wholeText")-1, dom_text_whole_text_read, NULL);
     746       23043 :         zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, dom_copy_prop_handler, 0);
     747       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_text_prop_handlers);
     748             : 
     749       23043 :         REGISTER_DOM_CLASS(ce, "DOMComment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry);
     750       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_characterdata_prop_handlers);
     751             : 
     752       23043 :         REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
     753             : 
     754       23043 :         zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     755       23043 :         dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", sizeof("typeName")-1, dom_typeinfo_type_name_read, NULL);
     756       23043 :         dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", sizeof("typeNamespace")-1, dom_typeinfo_type_namespace_read, NULL);
     757       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_typeinfo_prop_handlers);
     758             : 
     759       23043 :         REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry);
     760       23043 :         REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry);
     761             : 
     762       23043 :         zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     763       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", sizeof("severity")-1, dom_domerror_severity_read, NULL);
     764       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "message", sizeof("message")-1, dom_domerror_message_read, NULL);
     765       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "type", sizeof("type")-1, dom_domerror_type_read, NULL);
     766       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", sizeof("relatedException")-1, dom_domerror_related_exception_read, NULL);
     767       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", sizeof("related_data")-1, dom_domerror_related_data_read, NULL);
     768       23043 :         dom_register_prop_handler(&dom_domerror_prop_handlers, "location", sizeof("location")-1, dom_domerror_location_read, NULL);
     769       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_domerror_prop_handlers);
     770             : 
     771       23043 :         REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry);
     772       23043 :         REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry);
     773             : 
     774       23043 :         zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     775       23043 :         dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", sizeof("lineNumber")-1, dom_domlocator_line_number_read, NULL);
     776       23043 :         dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", sizeof("columnNumber")-1, dom_domlocator_column_number_read, NULL);
     777       23043 :         dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", sizeof("offset")-1, dom_domlocator_offset_read, NULL);
     778       23043 :         dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", sizeof("relatedNode")-1, dom_domlocator_related_node_read, NULL);
     779       23043 :         dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", sizeof("uri")-1, dom_domlocator_uri_read, NULL);
     780       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_domlocator_prop_handlers);
     781             : 
     782       23043 :         REGISTER_DOM_CLASS(ce, "DOMConfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry);
     783       23043 :         REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
     784       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_text_prop_handlers);
     785             : 
     786       23043 :         REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
     787             : 
     788       23043 :         zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     789       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", sizeof("name")-1, dom_documenttype_name_read, NULL);
     790       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "entities", sizeof("entities")-1, dom_documenttype_entities_read, NULL);
     791       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "notations", sizeof("notations")-1, dom_documenttype_notations_read, NULL);
     792       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "publicId", sizeof("publicId")-1, dom_documenttype_public_id_read, NULL);
     793       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "systemId", sizeof("systemId")-1, dom_documenttype_system_id_read, NULL);
     794       23043 :         dom_register_prop_handler(&dom_documenttype_prop_handlers, "internalSubset", sizeof("internalSubset")-1, dom_documenttype_internal_subset_read, NULL);
     795       23043 :         zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     796       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_documenttype_prop_handlers);
     797             : 
     798       23043 :         REGISTER_DOM_CLASS(ce, "DOMNotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry);
     799             : 
     800       23043 :         zend_hash_init(&dom_notation_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     801       23043 :         dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", sizeof("publicId")-1, dom_notation_public_id_read, NULL);
     802       23043 :         dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", sizeof("systemId")-1, dom_notation_system_id_read, NULL);
     803       23043 :         zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     804       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_notation_prop_handlers);
     805             : 
     806       23043 :         REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry);
     807             : 
     808       23043 :         zend_hash_init(&dom_entity_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     809       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", sizeof("publicId")-1, dom_entity_public_id_read, NULL);
     810       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", sizeof("systemId")-1, dom_entity_system_id_read, NULL);
     811       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", sizeof("notationName")-1, dom_entity_notation_name_read, NULL);
     812       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_entity_actual_encoding_read, dom_entity_actual_encoding_write);
     813       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", sizeof("encoding")-1, dom_entity_encoding_read, dom_entity_encoding_write);
     814       23043 :         dom_register_prop_handler(&dom_entity_prop_handlers, "version", sizeof("version")-1, dom_entity_version_read, dom_entity_version_write);
     815       23043 :         zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     816       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_entity_prop_handlers);
     817             : 
     818       23043 :         REGISTER_DOM_CLASS(ce, "DOMEntityReference", dom_node_class_entry, php_dom_entityreference_class_functions, dom_entityreference_class_entry);
     819       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_node_prop_handlers);
     820             : 
     821       23043 :         REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
     822             : 
     823       23043 :         zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     824       23043 :         dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", sizeof("target")-1, dom_processinginstruction_target_read, NULL);
     825       23043 :         dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", sizeof("data")-1, dom_processinginstruction_data_read, dom_processinginstruction_data_write);
     826       23043 :         zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
     827       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_processinginstruction_prop_handlers);
     828             : 
     829       23043 :         REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
     830             : 
     831             : #if defined(LIBXML_XPATH_ENABLED)
     832       23043 :         memcpy(&dom_xpath_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
     833       23043 :         dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, dom) + XtOffsetOf(dom_object, std);
     834       23043 :         dom_xpath_object_handlers.free_obj = dom_xpath_objects_free_storage;
     835             : 
     836       23043 :         INIT_CLASS_ENTRY(ce, "DOMXPath", php_dom_xpath_class_functions);
     837       23043 :         ce.create_object = dom_xpath_objects_new;
     838       23043 :         dom_xpath_class_entry = zend_register_internal_class_ex(&ce, NULL);
     839             : 
     840       23043 :         zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
     841       23043 :         dom_register_prop_handler(&dom_xpath_prop_handlers, "document", sizeof("document")-1, dom_xpath_document_read, NULL);
     842       23043 :         zend_hash_add_ptr(&classes, ce.name, &dom_xpath_prop_handlers);
     843             : #endif
     844             : 
     845       23043 :         REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE",                    XML_ELEMENT_NODE,                       CONST_CS | CONST_PERSISTENT);
     846       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE",          XML_ATTRIBUTE_NODE,                     CONST_CS | CONST_PERSISTENT);
     847       23043 :         REGISTER_LONG_CONSTANT("XML_TEXT_NODE",                               XML_TEXT_NODE,                          CONST_CS | CONST_PERSISTENT);
     848       23043 :         REGISTER_LONG_CONSTANT("XML_CDATA_SECTION_NODE",      XML_CDATA_SECTION_NODE,         CONST_CS | CONST_PERSISTENT);
     849       23043 :         REGISTER_LONG_CONSTANT("XML_ENTITY_REF_NODE",         XML_ENTITY_REF_NODE,            CONST_CS | CONST_PERSISTENT);
     850       23043 :         REGISTER_LONG_CONSTANT("XML_ENTITY_NODE",                     XML_ENTITY_NODE,                        CONST_CS | CONST_PERSISTENT);
     851       23043 :         REGISTER_LONG_CONSTANT("XML_PI_NODE",                         XML_PI_NODE,                            CONST_CS | CONST_PERSISTENT);
     852       23043 :         REGISTER_LONG_CONSTANT("XML_COMMENT_NODE",                    XML_COMMENT_NODE,                       CONST_CS | CONST_PERSISTENT);
     853       23043 :         REGISTER_LONG_CONSTANT("XML_DOCUMENT_NODE",                   XML_DOCUMENT_NODE,                      CONST_CS | CONST_PERSISTENT);
     854       23043 :         REGISTER_LONG_CONSTANT("XML_DOCUMENT_TYPE_NODE",      XML_DOCUMENT_TYPE_NODE,         CONST_CS | CONST_PERSISTENT);
     855       23043 :         REGISTER_LONG_CONSTANT("XML_DOCUMENT_FRAG_NODE",      XML_DOCUMENT_FRAG_NODE,         CONST_CS | CONST_PERSISTENT);
     856       23043 :         REGISTER_LONG_CONSTANT("XML_NOTATION_NODE",                   XML_NOTATION_NODE,                      CONST_CS | CONST_PERSISTENT);
     857       23043 :         REGISTER_LONG_CONSTANT("XML_HTML_DOCUMENT_NODE",      XML_HTML_DOCUMENT_NODE,         CONST_CS | CONST_PERSISTENT);
     858       23043 :         REGISTER_LONG_CONSTANT("XML_DTD_NODE",                                XML_DTD_NODE,                           CONST_CS | CONST_PERSISTENT);
     859       23043 :         REGISTER_LONG_CONSTANT("XML_ELEMENT_DECL_NODE",       XML_ELEMENT_DECL,                       CONST_CS | CONST_PERSISTENT);
     860       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_DECL_NODE",     XML_ATTRIBUTE_DECL,                     CONST_CS | CONST_PERSISTENT);
     861       23043 :         REGISTER_LONG_CONSTANT("XML_ENTITY_DECL_NODE",                XML_ENTITY_DECL,                        CONST_CS | CONST_PERSISTENT);
     862       23043 :         REGISTER_LONG_CONSTANT("XML_NAMESPACE_DECL_NODE",     XML_NAMESPACE_DECL,                     CONST_CS | CONST_PERSISTENT);
     863             : #ifdef XML_GLOBAL_NAMESPACE
     864             :         REGISTER_LONG_CONSTANT("XML_GLOBAL_NAMESPACE",                XML_GLOBAL_NAMESPACE,           CONST_CS | CONST_PERSISTENT);
     865             : #endif
     866       23043 :         REGISTER_LONG_CONSTANT("XML_LOCAL_NAMESPACE",         XML_LOCAL_NAMESPACE,            CONST_CS | CONST_PERSISTENT);
     867       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_CDATA",         XML_ATTRIBUTE_CDATA,            CONST_CS | CONST_PERSISTENT);
     868       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ID",                    XML_ATTRIBUTE_ID,                       CONST_CS | CONST_PERSISTENT);
     869       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREF",         XML_ATTRIBUTE_IDREF,            CONST_CS | CONST_PERSISTENT);
     870       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREFS",                XML_ATTRIBUTE_IDREFS,           CONST_CS | CONST_PERSISTENT);
     871       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENTITY",                XML_ATTRIBUTE_ENTITIES,         CONST_CS | CONST_PERSISTENT);
     872       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKEN",               XML_ATTRIBUTE_NMTOKEN,          CONST_CS | CONST_PERSISTENT);
     873       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKENS",      XML_ATTRIBUTE_NMTOKENS,         CONST_CS | CONST_PERSISTENT);
     874       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENUMERATION",   XML_ATTRIBUTE_ENUMERATION,      CONST_CS | CONST_PERSISTENT);
     875       23043 :         REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NOTATION",      XML_ATTRIBUTE_NOTATION,         CONST_CS | CONST_PERSISTENT);
     876             : 
     877             :         /* DOMException Codes */
     878       23043 :         REGISTER_LONG_CONSTANT("DOM_PHP_ERR",                         PHP_ERR,                                CONST_CS | CONST_PERSISTENT);
     879       23043 :         REGISTER_LONG_CONSTANT("DOM_INDEX_SIZE_ERR",          INDEX_SIZE_ERR,                 CONST_CS | CONST_PERSISTENT);
     880       23043 :         REGISTER_LONG_CONSTANT("DOMSTRING_SIZE_ERR",          DOMSTRING_SIZE_ERR,             CONST_CS | CONST_PERSISTENT);
     881       23043 :         REGISTER_LONG_CONSTANT("DOM_HIERARCHY_REQUEST_ERR",   HIERARCHY_REQUEST_ERR,  CONST_CS | CONST_PERSISTENT);
     882       23043 :         REGISTER_LONG_CONSTANT("DOM_WRONG_DOCUMENT_ERR",      WRONG_DOCUMENT_ERR,             CONST_CS | CONST_PERSISTENT);
     883       23043 :         REGISTER_LONG_CONSTANT("DOM_INVALID_CHARACTER_ERR",   INVALID_CHARACTER_ERR,  CONST_CS | CONST_PERSISTENT);
     884       23043 :         REGISTER_LONG_CONSTANT("DOM_NO_DATA_ALLOWED_ERR",     NO_DATA_ALLOWED_ERR,    CONST_CS | CONST_PERSISTENT);
     885       23043 :         REGISTER_LONG_CONSTANT("DOM_NO_MODIFICATION_ALLOWED_ERR", NO_MODIFICATION_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
     886       23043 :         REGISTER_LONG_CONSTANT("DOM_NOT_FOUND_ERR",                   NOT_FOUND_ERR,                  CONST_CS | CONST_PERSISTENT);
     887       23043 :         REGISTER_LONG_CONSTANT("DOM_NOT_SUPPORTED_ERR",               NOT_SUPPORTED_ERR,              CONST_CS | CONST_PERSISTENT);
     888       23043 :         REGISTER_LONG_CONSTANT("DOM_INUSE_ATTRIBUTE_ERR",     INUSE_ATTRIBUTE_ERR,    CONST_CS | CONST_PERSISTENT);
     889       23043 :         REGISTER_LONG_CONSTANT("DOM_INVALID_STATE_ERR",               INVALID_STATE_ERR,              CONST_CS | CONST_PERSISTENT);
     890       23043 :         REGISTER_LONG_CONSTANT("DOM_SYNTAX_ERR",                      SYNTAX_ERR,                             CONST_CS | CONST_PERSISTENT);
     891       23043 :         REGISTER_LONG_CONSTANT("DOM_INVALID_MODIFICATION_ERR",        INVALID_MODIFICATION_ERR, CONST_CS | CONST_PERSISTENT);
     892       23043 :         REGISTER_LONG_CONSTANT("DOM_NAMESPACE_ERR",                   NAMESPACE_ERR,                  CONST_CS | CONST_PERSISTENT);
     893       23043 :         REGISTER_LONG_CONSTANT("DOM_INVALID_ACCESS_ERR",      INVALID_ACCESS_ERR,             CONST_CS | CONST_PERSISTENT);
     894       23043 :         REGISTER_LONG_CONSTANT("DOM_VALIDATION_ERR",          VALIDATION_ERR,                 CONST_CS | CONST_PERSISTENT);
     895             : 
     896       23043 :         php_libxml_register_export(dom_node_class_entry, php_dom_export_node);
     897             : 
     898       23043 :         return SUCCESS;
     899             : }
     900             : /* }}} */
     901             : 
     902             : /* {{{ */
     903         146 : PHP_MINFO_FUNCTION(dom)
     904             : {
     905         146 :         php_info_print_table_start();
     906         146 :         php_info_print_table_row(2, "DOM/XML", "enabled");
     907         146 :         php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
     908         146 :         php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION);
     909             : #if defined(LIBXML_HTML_ENABLED)
     910         146 :         php_info_print_table_row(2, "HTML Support", "enabled");
     911             : #endif
     912             : #if defined(LIBXML_XPATH_ENABLED)
     913         146 :         php_info_print_table_row(2, "XPath Support", "enabled");
     914             : #endif
     915             : #if defined(LIBXML_XPTR_ENABLED)
     916         146 :         php_info_print_table_row(2, "XPointer Support", "enabled");
     917             : #endif
     918             : #ifdef LIBXML_SCHEMAS_ENABLED
     919         146 :         php_info_print_table_row(2, "Schema Support", "enabled");
     920         146 :         php_info_print_table_row(2, "RelaxNG Support", "enabled");
     921             : #endif
     922         146 :         php_info_print_table_end();
     923         146 : }
     924             : /* }}} */
     925             : 
     926       23105 : PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */
     927             : {
     928       23105 :         zend_hash_destroy(&dom_domstringlist_prop_handlers);
     929       23105 :         zend_hash_destroy(&dom_namelist_prop_handlers);
     930       23105 :         zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
     931       23105 :         zend_hash_destroy(&dom_document_prop_handlers);
     932       23105 :         zend_hash_destroy(&dom_node_prop_handlers);
     933       23105 :         zend_hash_destroy(&dom_namespace_node_prop_handlers);
     934       23105 :         zend_hash_destroy(&dom_nodelist_prop_handlers);
     935       23105 :         zend_hash_destroy(&dom_namednodemap_prop_handlers);
     936       23105 :         zend_hash_destroy(&dom_characterdata_prop_handlers);
     937       23105 :         zend_hash_destroy(&dom_attr_prop_handlers);
     938       23105 :         zend_hash_destroy(&dom_element_prop_handlers);
     939       23105 :         zend_hash_destroy(&dom_text_prop_handlers);
     940       23105 :         zend_hash_destroy(&dom_typeinfo_prop_handlers);
     941       23105 :         zend_hash_destroy(&dom_domerror_prop_handlers);
     942       23105 :         zend_hash_destroy(&dom_domlocator_prop_handlers);
     943       23105 :         zend_hash_destroy(&dom_documenttype_prop_handlers);
     944       23105 :         zend_hash_destroy(&dom_notation_prop_handlers);
     945       23105 :         zend_hash_destroy(&dom_entity_prop_handlers);
     946       23105 :         zend_hash_destroy(&dom_processinginstruction_prop_handlers);
     947             : #if defined(LIBXML_XPATH_ENABLED)
     948       23105 :         zend_hash_destroy(&dom_xpath_prop_handlers);
     949             : #endif
     950       23105 :         zend_hash_destroy(&classes);
     951             : 
     952             : /*      If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and
     953             :         uncomment the following line, this will tell you the amount of not freed memory
     954             :         and the total used memory into apaches error_log  */
     955             : /*  xmlMemoryDump();*/
     956             : 
     957       23105 :         return SUCCESS;
     958             : }
     959             : /* }}} */
     960             : 
     961             : /* {{{ node_list_unlink */
     962          58 : void node_list_unlink(xmlNodePtr node)
     963             : {
     964             :         dom_object *wrapper;
     965             : 
     966         155 :         while (node != NULL) {
     967             : 
     968          39 :                 wrapper = php_dom_object_get_data(node);
     969             : 
     970          39 :                 if (wrapper != NULL ) {
     971          20 :                         xmlUnlinkNode(node);
     972             :                 } else {
     973          19 :                         if (node->type == XML_ENTITY_REF_NODE)
     974           0 :                                 break;
     975          19 :                         node_list_unlink(node->children);
     976             : 
     977          19 :                         switch (node->type) {
     978          19 :                                 case XML_ATTRIBUTE_DECL:
     979             :                                 case XML_DTD_NODE:
     980             :                                 case XML_DOCUMENT_TYPE_NODE:
     981             :                                 case XML_ENTITY_DECL:
     982             :                                 case XML_ATTRIBUTE_NODE:
     983             :                                 case XML_TEXT_NODE:
     984          19 :                                         break;
     985           0 :                                 default:
     986           0 :                                         node_list_unlink((xmlNodePtr) node->properties);
     987             :                         }
     988             : 
     989             :                 }
     990             : 
     991          39 :                 node = node->next;
     992             :         }
     993          58 : }
     994             : /* }}} end node_list_unlink */
     995             : 
     996             : #if defined(LIBXML_XPATH_ENABLED)
     997             : /* {{{ dom_xpath_objects_free_storage */
     998          31 : void dom_xpath_objects_free_storage(zend_object *object)
     999             : {
    1000          31 :         dom_xpath_object *intern = php_xpath_obj_from_obj(object);
    1001             : 
    1002          31 :         zend_object_std_dtor(&intern->dom.std);
    1003             : 
    1004          31 :         if (intern->dom.ptr != NULL) {
    1005          31 :                 xmlXPathFreeContext((xmlXPathContextPtr) intern->dom.ptr);
    1006          31 :                 php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
    1007             :         }
    1008             : 
    1009          31 :         if (intern->registered_phpfunctions) {
    1010          31 :                 zend_hash_destroy(intern->registered_phpfunctions);
    1011          31 :                 FREE_HASHTABLE(intern->registered_phpfunctions);
    1012             :         }
    1013             : 
    1014          31 :         if (intern->node_list) {
    1015           0 :                 zend_hash_destroy(intern->node_list);
    1016           0 :                 FREE_HASHTABLE(intern->node_list);
    1017             :         }
    1018          31 : }
    1019             : /* }}} */
    1020             : #endif
    1021             : 
    1022             : /* {{{ dom_objects_free_storage */
    1023        1074 : void dom_objects_free_storage(zend_object *object)
    1024             : {
    1025        1074 :         dom_object *intern = php_dom_obj_from_obj(object);
    1026             : #if defined(__GNUC__) && __GNUC__ >= 3
    1027             :         int retcount __attribute__((unused)); /* keep compiler quiet */
    1028             : #else
    1029             :         int retcount;
    1030             : #endif
    1031             : 
    1032        1074 :         zend_object_std_dtor(&intern->std);
    1033             : 
    1034        1074 :         if (intern->ptr != NULL && ((php_libxml_node_ptr *)intern->ptr)->node != NULL) {
    1035        1018 :                 if (((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_DOCUMENT_NODE && ((xmlNodePtr) ((php_libxml_node_ptr *)intern->ptr)->node)->type != XML_HTML_DOCUMENT_NODE) {
    1036         669 :                         php_libxml_node_decrement_resource((php_libxml_node_object *) intern);
    1037             :                 } else {
    1038         349 :                         php_libxml_decrement_node_ptr((php_libxml_node_object *) intern);
    1039         349 :                         retcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
    1040             :                 }
    1041        1018 :                 intern->ptr = NULL;
    1042             :         }
    1043        1074 : }
    1044             : /* }}} */
    1045             : 
    1046         171 : void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns) /* {{{ */
    1047             : {
    1048         171 :         dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr;
    1049             : 
    1050         171 :         ZEND_ASSERT(basenode != NULL);
    1051             : 
    1052         171 :         ZVAL_OBJ(&mapptr->baseobj_zv, &basenode->std);
    1053         171 :         Z_ADDREF(mapptr->baseobj_zv);
    1054             : 
    1055         171 :         mapptr->baseobj = basenode;
    1056         171 :         mapptr->nodetype = ntype;
    1057         171 :         mapptr->ht = ht;
    1058         171 :         mapptr->local = local;
    1059         171 :         mapptr->ns = ns;
    1060         171 : }
    1061             : /* }}} */
    1062             : 
    1063        1277 : static dom_object* dom_objects_set_class(zend_class_entry *class_type) /* {{{ */
    1064             : {
    1065        1277 :         dom_object *intern = zend_object_alloc(sizeof(dom_object), class_type);
    1066             : 
    1067        1277 :         zend_class_entry *base_class = class_type;
    1068        2561 :         while ((base_class->type != ZEND_INTERNAL_CLASS || base_class->info.internal.module->module_number != dom_module_entry.module_number) && base_class->parent != NULL) {
    1069           7 :                 base_class = base_class->parent;
    1070             :         }
    1071             : 
    1072        2554 :         intern->prop_handler = zend_hash_find_ptr(&classes, base_class->name);
    1073             : 
    1074        1277 :         zend_object_std_init(&intern->std, class_type);
    1075        1277 :         object_properties_init(&intern->std, class_type);
    1076             : 
    1077        1277 :         return intern;
    1078             : }
    1079             : /* }}} */
    1080             : 
    1081             : /* {{{ dom_objects_new */
    1082        1071 : zend_object *dom_objects_new(zend_class_entry *class_type)
    1083             : {
    1084        1071 :         dom_object *intern = dom_objects_set_class(class_type);
    1085        1071 :         intern->std.handlers = dom_get_obj_handlers();
    1086        1071 :         return &intern->std;
    1087             : }
    1088             : /* }}} */
    1089             : 
    1090             : #if defined(LIBXML_XPATH_ENABLED)
    1091             : /* {{{ zend_object dom_xpath_objects_new(zend_class_entry *class_type) */
    1092          31 : zend_object *dom_xpath_objects_new(zend_class_entry *class_type)
    1093             : {
    1094          31 :         dom_xpath_object *intern = zend_object_alloc(sizeof(dom_xpath_object), class_type);
    1095             : 
    1096          31 :         intern->registered_phpfunctions = zend_new_array(0);
    1097             : 
    1098          31 :         intern->dom.prop_handler = &dom_xpath_prop_handlers;
    1099          31 :         intern->dom.std.handlers = &dom_xpath_object_handlers;
    1100             : 
    1101          31 :         zend_object_std_init(&intern->dom.std, class_type);
    1102          31 :         object_properties_init(&intern->dom.std, class_type);
    1103             : 
    1104          31 :         return &intern->dom.std;
    1105             : }
    1106             : /* }}} */
    1107             : #endif
    1108             : 
    1109         203 : static void dom_nnodemap_object_dtor(zend_object *object) /* {{{ */
    1110             : {
    1111             :         dom_object *intern;
    1112             :         dom_nnodemap_object *objmap;
    1113             : 
    1114         203 :         intern = php_dom_obj_from_obj(object);
    1115         203 :         objmap = (dom_nnodemap_object *)intern->ptr;
    1116             : 
    1117         203 :         if (objmap) {
    1118         203 :                 if (objmap->local) {
    1119          43 :                         xmlFree(objmap->local);
    1120             :                 }
    1121         203 :                 if (objmap->ns) {
    1122           6 :                         xmlFree(objmap->ns);
    1123             :                 }
    1124         406 :                 if (!Z_ISUNDEF(objmap->baseobj_zv)) {
    1125         202 :                         zval_ptr_dtor(&objmap->baseobj_zv);
    1126             :                 }
    1127         203 :                 efree(objmap);
    1128         203 :                 intern->ptr = NULL;
    1129             :         }
    1130         203 : }
    1131             : /* }}} */
    1132             : 
    1133         203 : void dom_nnodemap_objects_free_storage(zend_object *object) /* {{{ */
    1134             : {
    1135         203 :         dom_object *intern = php_dom_obj_from_obj(object);
    1136             : 
    1137         203 :         php_libxml_decrement_doc_ref((php_libxml_node_object *)intern);
    1138             : 
    1139         203 :         zend_object_std_dtor(&intern->std);
    1140         203 : }
    1141             : /* }}} */
    1142             : 
    1143         203 : zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type) /* {{{ */
    1144             : {
    1145             :         dom_object *intern;
    1146             :         dom_nnodemap_object *objmap;
    1147             : 
    1148         203 :         intern = dom_objects_set_class(class_type);
    1149         203 :         intern->ptr = emalloc(sizeof(dom_nnodemap_object));
    1150         203 :         objmap = (dom_nnodemap_object *)intern->ptr;
    1151         203 :         ZVAL_UNDEF(&objmap->baseobj_zv);
    1152         203 :         objmap->baseobj = NULL;
    1153         203 :         objmap->nodetype = 0;
    1154         203 :         objmap->ht = NULL;
    1155         203 :         objmap->local = NULL;
    1156         203 :         objmap->ns = NULL;
    1157             : 
    1158         203 :         intern->std.handlers = &dom_nnodemap_object_handlers;
    1159             : 
    1160         203 :         return &intern->std;
    1161             : }
    1162             : /* }}} */
    1163             : 
    1164         202 : void php_dom_create_interator(zval *return_value, int ce_type) /* {{{ */
    1165             : {
    1166             :         zend_class_entry *ce;
    1167             : 
    1168         202 :         if (ce_type == DOM_NAMEDNODEMAP) {
    1169          14 :                 ce = dom_namednodemap_class_entry;
    1170             :         } else {
    1171         188 :                 ce = dom_nodelist_class_entry;
    1172             :         }
    1173             : 
    1174         202 :         object_init_ex(return_value, ce);
    1175         202 : }
    1176             : /* }}} */
    1177             : 
    1178             : /* {{{ php_dom_create_object */
    1179        1159 : PHP_DOM_EXPORT zend_bool php_dom_create_object(xmlNodePtr obj, zval *return_value, dom_object *domobj)
    1180             : {
    1181             :         zend_class_entry *ce;
    1182             :         dom_object *intern;
    1183             : 
    1184        1159 :         if (!obj) {
    1185           0 :                 ZVAL_NULL(return_value);
    1186           0 :                 return 0;
    1187             :         }
    1188             : 
    1189        1159 :         if ((intern = (dom_object *) php_dom_object_get_data((void *) obj))) {
    1190         491 :                 GC_ADDREF(&intern->std);
    1191         491 :                 ZVAL_OBJ(return_value, &intern->std);
    1192         491 :                 return 1;
    1193             :         }
    1194             : 
    1195         668 :         switch (obj->type) {
    1196          15 :                 case XML_DOCUMENT_NODE:
    1197             :                 case XML_HTML_DOCUMENT_NODE:
    1198             :                 {
    1199          15 :                         ce = dom_document_class_entry;
    1200          15 :                         break;
    1201             :                 }
    1202          11 :                 case XML_DTD_NODE:
    1203             :                 case XML_DOCUMENT_TYPE_NODE:
    1204             :                 {
    1205          11 :                         ce = dom_documenttype_class_entry;
    1206          11 :                         break;
    1207             :                 }
    1208         408 :                 case XML_ELEMENT_NODE:
    1209             :                 {
    1210         408 :                         ce = dom_element_class_entry;
    1211         408 :                         break;
    1212             :                 }
    1213          50 :                 case XML_ATTRIBUTE_NODE:
    1214             :                 {
    1215          50 :                         ce = dom_attr_class_entry;
    1216          50 :                         break;
    1217             :                 }
    1218         142 :                 case XML_TEXT_NODE:
    1219             :                 {
    1220         142 :                         ce = dom_text_class_entry;
    1221         142 :                         break;
    1222             :                 }
    1223          11 :                 case XML_COMMENT_NODE:
    1224             :                 {
    1225          11 :                         ce = dom_comment_class_entry;
    1226          11 :                         break;
    1227             :                 }
    1228           2 :                 case XML_PI_NODE:
    1229             :                 {
    1230           2 :                         ce = dom_processinginstruction_class_entry;
    1231           2 :                         break;
    1232             :                 }
    1233           2 :                 case XML_ENTITY_REF_NODE:
    1234             :                 {
    1235           2 :                         ce = dom_entityreference_class_entry;
    1236           2 :                         break;
    1237             :                 }
    1238           7 :                 case XML_ENTITY_DECL:
    1239             :                 case XML_ELEMENT_DECL:
    1240             :                 {
    1241           7 :                         ce = dom_entity_class_entry;
    1242           7 :                         break;
    1243             :                 }
    1244           5 :                 case XML_CDATA_SECTION_NODE:
    1245             :                 {
    1246           5 :                         ce = dom_cdatasection_class_entry;
    1247           5 :                         break;
    1248             :                 }
    1249           9 :                 case XML_DOCUMENT_FRAG_NODE:
    1250             :                 {
    1251           9 :                         ce = dom_documentfragment_class_entry;
    1252           9 :                         break;
    1253             :                 }
    1254           5 :                 case XML_NOTATION_NODE:
    1255             :                 {
    1256           5 :                         ce = dom_notation_class_entry;
    1257           5 :                         break;
    1258             :                 }
    1259           1 :                 case XML_NAMESPACE_DECL:
    1260             :                 {
    1261           1 :                         ce = dom_namespace_node_class_entry;
    1262           1 :                         break;
    1263             :                 }
    1264           0 :                 default:
    1265           0 :                         php_error_docref(NULL, E_WARNING, "Unsupported node type: %d", obj->type);
    1266           0 :                         ZVAL_NULL(return_value);
    1267           0 :                         return 0;
    1268             :         }
    1269             : 
    1270         668 :         if (domobj && domobj->document) {
    1271         650 :                 ce = dom_get_doc_classmap(domobj->document, ce);
    1272             :         }
    1273         668 :         object_init_ex(return_value, ce);
    1274             : 
    1275         668 :         intern = Z_DOMOBJ_P(return_value);
    1276         668 :         if (obj->doc != NULL) {
    1277         659 :                 if (domobj != NULL) {
    1278         645 :                         intern->document = domobj->document;
    1279             :                 }
    1280         659 :                 php_libxml_increment_doc_ref((php_libxml_node_object *)intern, obj->doc);
    1281             :         }
    1282             : 
    1283         668 :         php_libxml_increment_node_ptr((php_libxml_node_object *)intern, obj, (void *)intern);
    1284         668 :         return 0;
    1285             : }
    1286             : /* }}} end php_domobject_new */
    1287             : 
    1288           2 : void php_dom_create_implementation(zval *retval) {
    1289           2 :         object_init_ex(retval, dom_domimplementation_class_entry);
    1290           2 : }
    1291             : 
    1292             : /* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */
    1293         183 : int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
    1294             : {
    1295             :         xmlNodePtr nodep;
    1296             : 
    1297         183 :     if (parent == NULL || child == NULL || child->doc != parent->doc) {
    1298          25 :         return SUCCESS;
    1299             :     }
    1300             : 
    1301         158 :         nodep = parent;
    1302             : 
    1303         604 :         while (nodep) {
    1304         290 :                 if (nodep == child) {
    1305           2 :                         return FAILURE;
    1306             :                 }
    1307         288 :                 nodep = nodep->parent;
    1308             :         }
    1309             : 
    1310         156 :     return SUCCESS;
    1311             : }
    1312             : /* }}} end dom_hierarchy */
    1313             : 
    1314             : /* {{{ dom_has_feature(char *feature, char *version) */
    1315           2 : int dom_has_feature(char *feature, char *version)
    1316             : {
    1317           2 :         int retval = 0;
    1318             : 
    1319           2 :         if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, ""))) {
    1320           2 :                 if ((!strcasecmp(feature, "Core") && !strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
    1321           2 :                         retval = 1;
    1322             :         }
    1323             : 
    1324           2 :         return retval;
    1325             : }
    1326             : /* }}} end dom_has_feature */
    1327             : 
    1328       66088 : xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index) /* {{{ */
    1329             : {
    1330       66088 :         xmlNodePtr ret = NULL;
    1331             : 
    1332      264200 :         while (nodep != NULL && (*cur <= index || index == -1)) {
    1333      132149 :                 if (nodep->type == XML_ELEMENT_NODE) {
    1334       66061 :                         if (xmlStrEqual(nodep->name, (xmlChar *)local) || xmlStrEqual((xmlChar *)"*", (xmlChar *)local)) {
    1335         147 :                                 if (ns == NULL || (!strcmp(ns, "") && nodep->ns == NULL) || (nodep->ns != NULL && (xmlStrEqual(nodep->ns->href, (xmlChar *)ns) || xmlStrEqual((xmlChar *)"*", (xmlChar *)ns)))) {
    1336         133 :                                         if (*cur == index) {
    1337          61 :                                                 ret = nodep;
    1338          61 :                                                 break;
    1339             :                                         }
    1340          72 :                                         (*cur)++;
    1341             :                                 }
    1342             :                         }
    1343       66000 :                         ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
    1344       66000 :                         if (ret != NULL) {
    1345          64 :                                 break;
    1346             :                         }
    1347             :                 }
    1348      132024 :                 nodep = nodep->next;
    1349             :         }
    1350       66088 :         return ret;
    1351             : }
    1352             : /* }}} */
    1353             : /* }}} end dom_element_get_elements_by_tag_name_ns_raw */
    1354             : 
    1355             : /* {{{ void dom_normalize (xmlNodePtr nodep) */
    1356           2 : void dom_normalize (xmlNodePtr nodep)
    1357             : {
    1358             :         xmlNodePtr child, nextp, newnextp;
    1359             :         xmlAttrPtr attr;
    1360             :         xmlChar *strContent;
    1361             : 
    1362           2 :         child = nodep->children;
    1363           5 :         while(child != NULL) {
    1364           1 :                 switch (child->type) {
    1365           1 :                         case XML_TEXT_NODE:
    1366           1 :                                 nextp = child->next;
    1367           3 :                                 while (nextp != NULL) {
    1368           1 :                                         if (nextp->type == XML_TEXT_NODE) {
    1369           1 :                                                 newnextp = nextp->next;
    1370           1 :                                                 strContent = xmlNodeGetContent(nextp);
    1371           1 :                                                 xmlNodeAddContent(child, strContent);
    1372           1 :                                                 xmlFree(strContent);
    1373           1 :                                                 xmlUnlinkNode(nextp);
    1374           1 :                                                 php_libxml_node_free_resource(nextp);
    1375           1 :                                                 nextp = newnextp;
    1376             :                                         } else {
    1377           0 :                                                 break;
    1378             :                                         }
    1379             :                                 }
    1380           1 :                                 break;
    1381           0 :                         case XML_ELEMENT_NODE:
    1382           0 :                                 dom_normalize (child);
    1383           0 :                                 attr = child->properties;
    1384           0 :                                 while (attr != NULL) {
    1385           0 :                                         dom_normalize((xmlNodePtr) attr);
    1386           0 :                                         attr = attr->next;
    1387             :                                 }
    1388           0 :                                 break;
    1389           0 :                         case XML_ATTRIBUTE_NODE:
    1390           0 :                                 dom_normalize (child);
    1391           0 :                                 break;
    1392           0 :                         default:
    1393           0 :                                 break;
    1394             :                 }
    1395           1 :                 child = child->next;
    1396             :         }
    1397           2 : }
    1398             : /* }}} end dom_normalize */
    1399             : 
    1400             : 
    1401             : /* {{{ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) */
    1402           5 : void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
    1403             :         xmlNs *cur;
    1404             : 
    1405           5 :         if (doc == NULL)
    1406           0 :                 return;
    1407             : 
    1408           5 :         if (doc->oldNs == NULL) {
    1409           2 :                 doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
    1410           2 :                 if (doc->oldNs == NULL) {
    1411           0 :                         return;
    1412             :                 }
    1413           2 :                 memset(doc->oldNs, 0, sizeof(xmlNs));
    1414           2 :                 doc->oldNs->type = XML_LOCAL_NAMESPACE;
    1415           2 :                 doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
    1416           2 :                 doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml");
    1417             :         }
    1418             : 
    1419           5 :         cur = doc->oldNs;
    1420          16 :         while (cur->next != NULL) {
    1421           6 :                 cur = cur->next;
    1422             :         }
    1423           5 :         cur->next = ns;
    1424             : }
    1425             : /* }}} end dom_set_old_ns */
    1426             : 
    1427             : /*
    1428             : http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
    1429             : 
    1430             : NAMESPACE_ERR: Raised if
    1431             : 
    1432             : 1. the qualifiedName is a malformed qualified name
    1433             : 2. the qualifiedName has a prefix and the  namespaceURI is null
    1434             : */
    1435             : 
    1436             : /* {{{ int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) */
    1437          45 : int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) {
    1438          45 :         if (name_len == 0) {
    1439           0 :                 return NAMESPACE_ERR;
    1440             :         }
    1441             : 
    1442          45 :         *localname = (char *)xmlSplitQName2((xmlChar *)qname, (xmlChar **) prefix);
    1443          45 :         if (*localname == NULL) {
    1444          14 :                 *localname = (char *)xmlStrdup((xmlChar *)qname);
    1445          14 :                 if (*prefix == NULL && uri_len == 0) {
    1446           1 :                         return 0;
    1447             :                 }
    1448             :         }
    1449             : 
    1450             :         /* 1 */
    1451          44 :         if (xmlValidateQName((xmlChar *) qname, 0) != 0) {
    1452           7 :                 return NAMESPACE_ERR;
    1453             :         }
    1454             : 
    1455             :         /* 2 */
    1456          37 :         if (*prefix != NULL && uri_len == 0) {
    1457           2 :                 return NAMESPACE_ERR;
    1458             :         }
    1459             : 
    1460          35 :         return 0;
    1461             : }
    1462             : /* }}} */
    1463             : 
    1464             : /*
    1465             : http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
    1466             : 
    1467             : NAMESPACE_ERR: Raised if
    1468             : 
    1469             : 3. the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace" [XML Namespaces]
    1470             : 4. the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from  "http://www.w3.org/2000/xmlns/"
    1471             : 5. the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the        qualifiedName nor its prefix is "xmlns".
    1472             : */
    1473             : 
    1474             : /* {{{ xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) */
    1475          25 : xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) {
    1476          25 :         xmlNsPtr nsptr = NULL;
    1477             : 
    1478          25 :         *errorcode = 0;
    1479             : 
    1480          46 :         if (! ((prefix && !strcmp (prefix, "xml") && strcmp(uri, (char *)XML_XML_NAMESPACE)) ||
    1481          17 :                    (prefix && !strcmp (prefix, "xmlns") && strcmp(uri, (char *)DOM_XMLNS_NAMESPACE)) ||
    1482          15 :                    (prefix && !strcmp(uri, (char *)DOM_XMLNS_NAMESPACE) && strcmp (prefix, "xmlns")))) {
    1483          19 :                 nsptr = xmlNewNs(nodep, (xmlChar *)uri, (xmlChar *)prefix);
    1484             :         }
    1485             : 
    1486          25 :         if (nsptr == NULL) {
    1487           7 :                 *errorcode = NAMESPACE_ERR;
    1488             :         }
    1489             : 
    1490          25 :         return nsptr;
    1491             : 
    1492             : }
    1493             : /* }}} end dom_get_ns */
    1494             : 
    1495             : /* {{{ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) */
    1496           3 : xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
    1497             :         xmlNsPtr cur;
    1498           3 :         xmlNs *ret = NULL;
    1499           3 :         if (node == NULL)
    1500           0 :                 return NULL;
    1501             : 
    1502           4 :         if (localName == NULL || xmlStrEqual(localName, (xmlChar *)"")) {
    1503           1 :                 cur = node->nsDef;
    1504           3 :                 while (cur != NULL) {
    1505           1 :                         if (cur->prefix == NULL  && cur->href != NULL) {
    1506           0 :                                 ret = cur;
    1507           0 :                                 break;
    1508             :                         }
    1509           1 :                         cur = cur->next;
    1510             :                 }
    1511             :         } else {
    1512           2 :                 cur = node->nsDef;
    1513           5 :                 while (cur != NULL) {
    1514           2 :                         if (cur->prefix != NULL && xmlStrEqual(localName, cur->prefix)) {
    1515           1 :                                 ret = cur;
    1516           1 :                                 break;
    1517             :                         }
    1518           1 :                         cur = cur->next;
    1519             :                 }
    1520             :         }
    1521           3 :         return ret;
    1522             : }
    1523             : /* }}} end dom_get_nsdecl */
    1524             : 
    1525           8 : static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int type, zval *rv) /* {{{ */
    1526             : {
    1527             :         zval offset_copy;
    1528             : 
    1529           8 :         if (!offset) {
    1530           1 :                 return NULL;
    1531             :         }
    1532             : 
    1533          14 :         ZVAL_LONG(&offset_copy, zval_get_long(offset));
    1534             : 
    1535           7 :         zend_call_method_with_1_params(object, object->ce, NULL, "item", rv, &offset_copy);
    1536             : 
    1537           7 :         return rv;
    1538             : } /* }}} end dom_nodelist_read_dimension */
    1539             : 
    1540           6 : static int dom_nodelist_has_dimension(zend_object *object, zval *member, int check_empty)
    1541             : {
    1542           6 :         zend_long offset = zval_get_long(member);
    1543             :         zval rv;
    1544             : 
    1545           6 :         if (offset < 0) {
    1546           1 :                 return 0;
    1547             :         } else {
    1548             :                 zval obj;
    1549             :                 zval *length;
    1550             : 
    1551           5 :                 ZVAL_OBJ(&obj, object);
    1552           5 :                 length = zend_read_property(object->ce, &obj, "length", sizeof("length") - 1, 0, &rv);
    1553           5 :                 return length && offset < Z_LVAL_P(length);
    1554             :         }
    1555             : } /* }}} end dom_nodelist_has_dimension */
    1556             : 
    1557             : #endif /* HAVE_DOM */

Generated by: LCOV version 1.10

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

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