PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - dom - php_dom.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 769
Code covered: 88.3 % Executed lines: 679
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:06 +0000 (5 days ago)

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