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: 722 768 94.0 %
Date: 2014-11-22 Functions: 48 50 96.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:14 +0000 (9 hours ago)

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