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-23 Instrumented lines: 781
Code covered: 90.7 % Executed lines: 708
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:29 +0000 (34 hours ago)

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