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: 754 816 92.4 %
Date: 2014-07-21 Functions: 45 47 95.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:08 +0000 (6 days ago)

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