Back to index

php5  5.3.10
php_dom.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Christian Stocker <chregu@php.net>                          |
00016    |          Rob Richards <rrichards@php.net>                            |
00017    |          Marcus Borger <helly@php.net>                               |
00018    +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: php_dom.c 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 #include "php.h"
00028 #if HAVE_LIBXML && HAVE_DOM
00029 #include "ext/standard/php_rand.h"
00030 #include "php_dom.h"
00031 #include "dom_properties.h"
00032 #include "zend_interfaces.h"
00033 
00034 #include "ext/standard/info.h"
00035 #define PHP_XPATH 1
00036 #define PHP_XPTR 2
00037 
00038 /* {{{ class entries */
00039 zend_class_entry *dom_node_class_entry;
00040 zend_class_entry *dom_domexception_class_entry;
00041 zend_class_entry *dom_domstringlist_class_entry;
00042 zend_class_entry *dom_namelist_class_entry;
00043 zend_class_entry *dom_domimplementationlist_class_entry;
00044 zend_class_entry *dom_domimplementationsource_class_entry;
00045 zend_class_entry *dom_domimplementation_class_entry;
00046 zend_class_entry *dom_documentfragment_class_entry;
00047 zend_class_entry *dom_document_class_entry;
00048 zend_class_entry *dom_nodelist_class_entry;
00049 zend_class_entry *dom_namednodemap_class_entry;
00050 zend_class_entry *dom_characterdata_class_entry;
00051 zend_class_entry *dom_attr_class_entry;
00052 zend_class_entry *dom_element_class_entry;
00053 zend_class_entry *dom_text_class_entry;
00054 zend_class_entry *dom_comment_class_entry;
00055 zend_class_entry *dom_typeinfo_class_entry;
00056 zend_class_entry *dom_userdatahandler_class_entry;
00057 zend_class_entry *dom_domerror_class_entry;
00058 zend_class_entry *dom_domerrorhandler_class_entry;
00059 zend_class_entry *dom_domlocator_class_entry;
00060 zend_class_entry *dom_domconfiguration_class_entry;
00061 zend_class_entry *dom_cdatasection_class_entry;
00062 zend_class_entry *dom_documenttype_class_entry;
00063 zend_class_entry *dom_notation_class_entry;
00064 zend_class_entry *dom_entity_class_entry;
00065 zend_class_entry *dom_entityreference_class_entry;
00066 zend_class_entry *dom_processinginstruction_class_entry;
00067 zend_class_entry *dom_string_extend_class_entry;
00068 #if defined(LIBXML_XPATH_ENABLED)
00069 zend_class_entry *dom_xpath_class_entry;
00070 #endif
00071 zend_class_entry *dom_namespace_node_class_entry;
00072 /* }}} */
00073 
00074 zend_object_handlers dom_object_handlers;
00075 
00076 static HashTable classes;
00077 /* {{{ prop handler tables */
00078 static HashTable dom_domstringlist_prop_handlers;
00079 static HashTable dom_namelist_prop_handlers;
00080 static HashTable dom_domimplementationlist_prop_handlers;
00081 static HashTable dom_document_prop_handlers;
00082 static HashTable dom_node_prop_handlers;
00083 static HashTable dom_nodelist_prop_handlers;
00084 static HashTable dom_namednodemap_prop_handlers;
00085 static HashTable dom_characterdata_prop_handlers;
00086 static HashTable dom_attr_prop_handlers;
00087 static HashTable dom_element_prop_handlers;
00088 static HashTable dom_text_prop_handlers;
00089 static HashTable dom_typeinfo_prop_handlers;
00090 static HashTable dom_domerror_prop_handlers;
00091 static HashTable dom_domlocator_prop_handlers;
00092 static HashTable dom_documenttype_prop_handlers;
00093 static HashTable dom_notation_prop_handlers;
00094 static HashTable dom_entity_prop_handlers;
00095 static HashTable dom_processinginstruction_prop_handlers;
00096 static HashTable dom_namespace_node_prop_handlers;
00097 #if defined(LIBXML_XPATH_ENABLED)
00098 static HashTable dom_xpath_prop_handlers;
00099 #endif
00100 /* }}} */
00101 
00102 typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC);
00103 typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC);
00104 
00105 typedef struct _dom_prop_handler {
00106        dom_read_t read_func;
00107        dom_write_t write_func;
00108 } dom_prop_handler;
00109 
00110 /* {{{ int dom_node_is_read_only(xmlNodePtr node) */
00111 int dom_node_is_read_only(xmlNodePtr node) {
00112        switch (node->type) {
00113               case XML_ENTITY_REF_NODE:
00114               case XML_ENTITY_NODE:
00115               case XML_DOCUMENT_TYPE_NODE:
00116               case XML_NOTATION_NODE:
00117               case XML_DTD_NODE:
00118               case XML_ELEMENT_DECL:
00119               case XML_ATTRIBUTE_DECL:
00120               case XML_ENTITY_DECL:
00121               case XML_NAMESPACE_DECL:
00122                      return SUCCESS;
00123                      break;
00124               default:
00125                      if (node->doc == NULL) {
00126                             return SUCCESS;
00127                      } else {
00128                             return FAILURE;
00129                      }
00130        }
00131 }
00132 /* }}} end dom_node_is_read_only */
00133 
00134 /* {{{ int dom_node_children_valid(xmlNodePtr node) */
00135 int dom_node_children_valid(xmlNodePtr node) {
00136        switch (node->type) {
00137               case XML_DOCUMENT_TYPE_NODE:
00138               case XML_DTD_NODE:
00139               case XML_PI_NODE:
00140               case XML_COMMENT_NODE:
00141               case XML_TEXT_NODE:
00142               case XML_CDATA_SECTION_NODE:
00143               case XML_NOTATION_NODE:
00144                      return FAILURE;
00145                      break;
00146               default:
00147                      return SUCCESS;
00148        }
00149 }
00150 /* }}} end dom_node_children_valid */
00151 
00152 /* {{{ dom_get_doc_props() */
00153 dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
00154 {
00155        dom_doc_propsptr doc_props;
00156 
00157        if (document && document->doc_props) {
00158               return document->doc_props;
00159        } else {
00160               doc_props = emalloc(sizeof(libxml_doc_props));
00161               doc_props->formatoutput = 0;
00162               doc_props->validateonparse = 0;
00163               doc_props->resolveexternals = 0;
00164               doc_props->preservewhitespace = 1;
00165               doc_props->substituteentities = 0;
00166               doc_props->stricterror = 1;
00167               doc_props->recover = 0;
00168               doc_props->classmap = NULL;
00169               if (document) {
00170                      document->doc_props = doc_props;
00171               }
00172               return doc_props;
00173        }
00174 }
00175 
00176 static void dom_copy_doc_props(php_libxml_ref_obj *source_doc, php_libxml_ref_obj *dest_doc)
00177 {
00178        dom_doc_propsptr source, dest;
00179        
00180        if (source_doc && dest_doc) {
00181               
00182               source = dom_get_doc_props(source_doc);
00183               dest = dom_get_doc_props(dest_doc);
00184 
00185               dest->formatoutput = source->formatoutput;
00186               dest->validateonparse = source->validateonparse;
00187               dest->resolveexternals = source->resolveexternals;
00188               dest->preservewhitespace = source->preservewhitespace;
00189               dest->substituteentities = source->substituteentities;
00190               dest->stricterror = source->stricterror;
00191               dest->recover = source->recover;
00192               if (source->classmap) {
00193                      ALLOC_HASHTABLE(dest->classmap);
00194                      zend_hash_init(dest->classmap, 0, NULL, NULL, 0);
00195                      zend_hash_copy(dest->classmap, source->classmap, NULL, NULL, sizeof(zend_class_entry *));
00196               }
00197 
00198        }
00199 }
00200 
00201 int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *ce TSRMLS_DC)
00202 {
00203        dom_doc_propsptr doc_props;
00204 
00205        if (document) {
00206               doc_props = dom_get_doc_props(document);
00207               if (doc_props->classmap == NULL) {
00208                      if (ce == NULL) {
00209                             return SUCCESS;
00210                      }
00211                      ALLOC_HASHTABLE(doc_props->classmap);
00212                      zend_hash_init(doc_props->classmap, 0, NULL, NULL, 0);
00213               }
00214               if (ce) {
00215                      return zend_hash_update(doc_props->classmap, basece->name, basece->name_length + 1, &ce, sizeof(zend_class_entry *), NULL);
00216               } else {
00217                      zend_hash_del(doc_props->classmap, basece->name, basece->name_length + 1);
00218               }
00219        }
00220        return SUCCESS;
00221 }
00222 
00223 zend_class_entry *dom_get_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece TSRMLS_DC)
00224 {
00225        dom_doc_propsptr doc_props;
00226        zend_class_entry **ce = NULL;
00227        
00228        if (document) {
00229               doc_props = dom_get_doc_props(document);
00230               if (doc_props->classmap) {
00231                      if (zend_hash_find(doc_props->classmap, basece->name, basece->name_length + 1,  (void**) &ce) == SUCCESS) {
00232                             return *ce;
00233                      }
00234               }
00235        }
00236 
00237        return basece;
00238 }
00239 /* }}} */
00240 
00241 /* {{{ dom_get_strict_error() */
00242 int dom_get_strict_error(php_libxml_ref_obj *document) {
00243        int stricterror;
00244        dom_doc_propsptr doc_props;
00245 
00246        doc_props = dom_get_doc_props(document);
00247        stricterror = doc_props->stricterror;
00248        if (document == NULL) {
00249               efree(doc_props);
00250        }
00251 
00252        return stricterror;
00253 }
00254 /* }}} */
00255 
00256 /* {{{ xmlNodePtr dom_object_get_node(dom_object *obj) */
00257 PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj)
00258 {
00259        if (obj && obj->ptr != NULL) {
00260               return ((php_libxml_node_ptr *)obj->ptr)->node;
00261        } else {
00262               return NULL;
00263        }
00264 }
00265 /* }}} end dom_object_get_node */
00266 
00267 /* {{{ dom_object *php_dom_object_get_data(xmlNodePtr obj) */
00268 PHP_DOM_EXPORT dom_object *php_dom_object_get_data(xmlNodePtr obj)
00269 {
00270        if (obj && obj->_private != NULL) {
00271               return (dom_object *) ((php_libxml_node_ptr *) obj->_private)->_private;
00272        } else {
00273               return NULL;
00274        }
00275 }
00276 /* }}} end php_dom_object_get_data */
00277 
00278 /* {{{ dom_read_na */
00279 static int dom_read_na(dom_object *obj, zval **retval TSRMLS_DC)
00280 {
00281        *retval = NULL;
00282        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
00283        return FAILURE;
00284 }
00285 /* }}} */
00286 
00287 /* {{{ dom_write_na */
00288 static int dom_write_na(dom_object *obj, zval *newval TSRMLS_DC)
00289 {
00290        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
00291        return FAILURE;
00292 }
00293 /* }}} */
00294 
00295 /* {{{ dom_register_prop_handler */
00296 static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_read_t read_func, dom_write_t write_func TSRMLS_DC)
00297 {
00298        dom_prop_handler hnd;
00299        
00300        hnd.read_func = read_func ? read_func : dom_read_na;
00301        hnd.write_func = write_func ? write_func : dom_write_na;
00302        zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(dom_prop_handler), NULL);
00303 }
00304 /* }}} */
00305 
00306 static zval **dom_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */
00307 {
00308        dom_object *obj;
00309        zval tmp_member;
00310        zval **retval = NULL;
00311        dom_prop_handler *hnd;
00312        zend_object_handlers *std_hnd;
00313        int ret = FAILURE;
00314 
00315        if (member->type != IS_STRING) {
00316               tmp_member = *member;
00317               zval_copy_ctor(&tmp_member);
00318               convert_to_string(&tmp_member);
00319               member = &tmp_member;
00320        }
00321 
00322        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
00323 
00324        if (obj->prop_handler != NULL) {
00325               ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00326        }
00327        if (ret == FAILURE) {
00328               std_hnd = zend_get_std_object_handlers();
00329               retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC);
00330        }
00331 
00332        if (member == &tmp_member) {
00333               zval_dtor(member);
00334        }
00335        return retval;
00336 }
00337 /* }}} */
00338 
00339 /* {{{ dom_read_property */
00340 zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC)
00341 {
00342        dom_object *obj;
00343        zval tmp_member;
00344        zval *retval;
00345        dom_prop_handler *hnd;
00346        zend_object_handlers *std_hnd;
00347        int ret;
00348 
00349        if (member->type != IS_STRING) {
00350               tmp_member = *member;
00351               zval_copy_ctor(&tmp_member);
00352               convert_to_string(&tmp_member);
00353               member = &tmp_member;
00354        }
00355 
00356        ret = FAILURE;
00357        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
00358 
00359        if (obj->prop_handler != NULL) {
00360               ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00361        } else if (instanceof_function(obj->std.ce, dom_node_class_entry TSRMLS_CC)) {
00362               php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", obj->std.ce->name);
00363        }
00364        if (ret == SUCCESS) {
00365               ret = hnd->read_func(obj, &retval TSRMLS_CC);
00366               if (ret == SUCCESS) {
00367                      /* ensure we're creating a temporary variable */
00368                      Z_SET_REFCOUNT_P(retval, 0);
00369                      Z_UNSET_ISREF_P(retval);
00370               } else {
00371                      retval = EG(uninitialized_zval_ptr);
00372               }
00373        } else {
00374               std_hnd = zend_get_std_object_handlers();
00375               retval = std_hnd->read_property(object, member, type TSRMLS_CC);
00376        }
00377 
00378        if (member == &tmp_member) {
00379               zval_dtor(member);
00380        }
00381        return retval;
00382 }
00383 /* }}} */
00384 
00385 /* {{{ dom_write_property */
00386 void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
00387 {
00388        dom_object *obj;
00389        zval tmp_member;
00390        dom_prop_handler *hnd;
00391        zend_object_handlers *std_hnd;
00392        int ret;
00393 
00394        if (member->type != IS_STRING) {
00395               tmp_member = *member;
00396               zval_copy_ctor(&tmp_member);
00397               convert_to_string(&tmp_member);
00398               member = &tmp_member;
00399        }
00400 
00401        ret = FAILURE;
00402        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
00403 
00404        if (obj->prop_handler != NULL) {
00405               ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00406        }
00407        if (ret == SUCCESS) {
00408               hnd->write_func(obj, value TSRMLS_CC);
00409        } else {
00410               std_hnd = zend_get_std_object_handlers();
00411               std_hnd->write_property(object, member, value TSRMLS_CC);
00412        }
00413 
00414        if (member == &tmp_member) {
00415               zval_dtor(member);
00416        }
00417 }
00418 /* }}} */
00419 
00420 /* {{{ dom_property_exists */
00421 static int dom_property_exists(zval *object, zval *member, int check_empty TSRMLS_DC)
00422 {
00423        dom_object *obj;
00424        zval tmp_member;
00425        dom_prop_handler *hnd;
00426        zend_object_handlers *std_hnd;
00427        int ret, retval=0;
00428 
00429        if (member->type != IS_STRING) {
00430               tmp_member = *member;
00431               zval_copy_ctor(&tmp_member);
00432               convert_to_string(&tmp_member);
00433               member = &tmp_member;
00434        }
00435 
00436        ret = FAILURE;
00437        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
00438 
00439        if (obj->prop_handler != NULL) {
00440               ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
00441        }
00442        if (ret == SUCCESS) {
00443               zval *tmp;
00444 
00445               if (check_empty == 2) {
00446                      retval = 1;
00447               } else if (hnd->read_func(obj, &tmp TSRMLS_CC) == SUCCESS) {
00448                      Z_SET_REFCOUNT_P(tmp, 1);
00449                      Z_UNSET_ISREF_P(tmp);
00450                      if (check_empty == 1) {
00451                             retval = zend_is_true(tmp);
00452                      } else if (check_empty == 0) {
00453                             retval = (Z_TYPE_P(tmp) != IS_NULL);
00454                      }
00455                      zval_ptr_dtor(&tmp);
00456               }
00457        } else {
00458               std_hnd = zend_get_std_object_handlers();
00459               retval = std_hnd->has_property(object, member, check_empty TSRMLS_CC);
00460        }
00461 
00462        if (member == &tmp_member) {
00463               zval_dtor(member);
00464        }
00465        return retval;
00466 }
00467 /* }}} */
00468 
00469 void *php_dom_export_node(zval *object TSRMLS_DC) /* {{{ */
00470 {
00471        php_libxml_node_object *intern;
00472        xmlNodePtr nodep = NULL;
00473 
00474        intern = (php_libxml_node_object *)zend_object_store_get_object(object TSRMLS_CC);
00475        if (intern && intern->node) {
00476               nodep = intern->node->node;
00477        }
00478 
00479        return nodep; 
00480 }
00481 /* }}} */
00482 
00483 /* {{{ proto somNode dom_import_simplexml(sxeobject node)
00484    Get a simplexml_element object from dom to allow for processing */
00485 PHP_FUNCTION(dom_import_simplexml)
00486 {
00487        zval *rv = NULL;
00488        zval *node;
00489        xmlNodePtr nodep = NULL;
00490        php_libxml_node_object *nodeobj;
00491        int ret;
00492 
00493        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
00494               return;
00495        }
00496 
00497        nodeobj = (php_libxml_node_object *)zend_object_store_get_object(node TSRMLS_CC);
00498        nodep = php_libxml_import_node(node TSRMLS_CC);
00499 
00500        if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
00501               DOM_RET_OBJ(rv, (xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
00502        } else {
00503               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Nodetype to import");
00504               RETURN_NULL();
00505        }
00506 }
00507 /* }}} */
00508 
00509 zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */
00510 {
00511        zend_object_value retval;
00512        void *new_object;
00513        dom_object *intern;
00514        dom_object *old_object;
00515        struct _store_object *obj;
00516        zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
00517 
00518        obj = &EG(objects_store).object_buckets[handle].bucket.obj;
00519        
00520        if (obj->clone == NULL) {
00521               php_error(E_ERROR, "Trying to clone an uncloneable object of class %s", Z_OBJCE_P(zobject)->name);
00522        }             
00523 
00524        obj->clone(obj->object, &new_object TSRMLS_CC);
00525 
00526        retval.handle = zend_objects_store_put(new_object, obj->dtor, obj->free_storage, obj->clone TSRMLS_CC);
00527        intern = (dom_object *) new_object;
00528        intern->handle = retval.handle;
00529        retval.handlers = Z_OBJ_HT_P(zobject);
00530        
00531        old_object = (dom_object *) obj->object;
00532        zend_objects_clone_members(&intern->std, retval, &old_object->std, intern->handle TSRMLS_CC);
00533 
00534        return retval;
00535 }
00536 /* }}} */
00537 
00538 /* {{{ arginfo */
00539 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_import_simplexml, 0, 0, 1)
00540        ZEND_ARG_INFO(0, node)
00541 ZEND_END_ARG_INFO()
00542 /* }}} */
00543 
00544 static const zend_function_entry dom_functions[] = {
00545        PHP_FE(dom_import_simplexml, arginfo_dom_import_simplexml)
00546        PHP_FE_END
00547 };
00548 
00549 static zend_object_handlers* dom_get_obj_handlers(TSRMLS_D) {
00550        return &dom_object_handlers;
00551 }
00552 
00553 static const zend_module_dep dom_deps[] = {
00554        ZEND_MOD_REQUIRED("libxml")
00555        ZEND_MOD_CONFLICTS("domxml")
00556        ZEND_MOD_END
00557 };
00558 
00559 zend_module_entry dom_module_entry = { /* {{{ */
00560        STANDARD_MODULE_HEADER_EX, NULL,
00561        dom_deps,
00562        "dom",
00563        dom_functions,
00564        PHP_MINIT(dom),
00565        PHP_MSHUTDOWN(dom),
00566        NULL,
00567        NULL,
00568        PHP_MINFO(dom),
00569        DOM_API_VERSION, /* Extension versionnumber */
00570        STANDARD_MODULE_PROPERTIES
00571 };
00572 /* }}} */
00573 
00574 #ifdef COMPILE_DL_DOM
00575 ZEND_GET_MODULE(dom)
00576 #endif
00577 
00578 /* {{{ PHP_MINIT_FUNCTION(dom) */
00579 PHP_MINIT_FUNCTION(dom)
00580 {
00581        zend_class_entry ce;
00582 
00583        memcpy(&dom_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
00584        dom_object_handlers.read_property = dom_read_property;
00585        dom_object_handlers.write_property = dom_write_property;
00586        dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
00587        dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
00588        dom_object_handlers.has_property = dom_property_exists;
00589 
00590        zend_hash_init(&classes, 0, NULL, NULL, 1);
00591 
00592        INIT_CLASS_ENTRY(ce, "DOMException", php_dom_domexception_class_functions);
00593        dom_domexception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
00594        dom_domexception_class_entry->ce_flags |= ZEND_ACC_FINAL;
00595        zend_declare_property_long(dom_domexception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
00596 
00597        REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
00598        
00599        zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, NULL, 1);
00600        dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", dom_domstringlist_length_read, NULL TSRMLS_CC);
00601        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers), NULL);
00602 
00603        REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
00604        
00605        zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, NULL, 1);
00606        dom_register_prop_handler(&dom_namelist_prop_handlers, "length", dom_namelist_length_read, NULL TSRMLS_CC);
00607        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers), NULL);
00608 
00609        REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
00610        
00611        zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, NULL, 1);
00612        dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", dom_domimplementationlist_length_read, NULL TSRMLS_CC);
00613        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers), NULL);
00614 
00615        REGISTER_DOM_CLASS(ce, "DOMImplementationSource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry);
00616        REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry);
00617 
00618        REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry);
00619        
00620        zend_hash_init(&dom_node_prop_handlers, 0, NULL, NULL, 1);
00621        dom_register_prop_handler(&dom_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
00622        dom_register_prop_handler(&dom_node_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC);
00623        dom_register_prop_handler(&dom_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL TSRMLS_CC);
00624        dom_register_prop_handler(&dom_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC);
00625        dom_register_prop_handler(&dom_node_prop_handlers, "childNodes", dom_node_child_nodes_read, NULL TSRMLS_CC);
00626        dom_register_prop_handler(&dom_node_prop_handlers, "firstChild", dom_node_first_child_read, NULL TSRMLS_CC);
00627        dom_register_prop_handler(&dom_node_prop_handlers, "lastChild", dom_node_last_child_read, NULL TSRMLS_CC);
00628        dom_register_prop_handler(&dom_node_prop_handlers, "previousSibling", dom_node_previous_sibling_read, NULL TSRMLS_CC);
00629        dom_register_prop_handler(&dom_node_prop_handlers, "nextSibling", dom_node_next_sibling_read, NULL TSRMLS_CC);
00630        dom_register_prop_handler(&dom_node_prop_handlers, "attributes", dom_node_attributes_read, NULL TSRMLS_CC);
00631        dom_register_prop_handler(&dom_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC);
00632        dom_register_prop_handler(&dom_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC);
00633        dom_register_prop_handler(&dom_node_prop_handlers, "prefix", dom_node_prefix_read, dom_node_prefix_write TSRMLS_CC);
00634        dom_register_prop_handler(&dom_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC);
00635        dom_register_prop_handler(&dom_node_prop_handlers, "baseURI", dom_node_base_uri_read, NULL TSRMLS_CC);
00636        dom_register_prop_handler(&dom_node_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write TSRMLS_CC);
00637        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
00638 
00639        REGISTER_DOM_CLASS(ce, "DOMNameSpaceNode", NULL, NULL, dom_namespace_node_class_entry);
00640 
00641        zend_hash_init(&dom_namespace_node_prop_handlers, 0, NULL, NULL, 1);
00642        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
00643        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeValue", dom_node_node_value_read, NULL TSRMLS_CC);
00644        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL TSRMLS_CC);
00645        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "prefix", dom_node_prefix_read, NULL TSRMLS_CC);
00646        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC);
00647        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC);
00648        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC);
00649        dom_register_prop_handler(&dom_namespace_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC);
00650        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namespace_node_prop_handlers, sizeof(dom_namespace_node_prop_handlers), NULL);
00651 
00652        REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry);
00653        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
00654        
00655        REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry);
00656        zend_hash_init(&dom_document_prop_handlers, 0, NULL, NULL, 1);
00657        dom_register_prop_handler(&dom_document_prop_handlers, "doctype", dom_document_doctype_read, NULL TSRMLS_CC);
00658        dom_register_prop_handler(&dom_document_prop_handlers, "implementation", dom_document_implementation_read, NULL TSRMLS_CC);
00659        dom_register_prop_handler(&dom_document_prop_handlers, "documentElement", dom_document_document_element_read, NULL TSRMLS_CC);
00660        dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", dom_document_encoding_read, NULL TSRMLS_CC);
00661        dom_register_prop_handler(&dom_document_prop_handlers, "encoding", dom_document_encoding_read, dom_document_encoding_write TSRMLS_CC);
00662        dom_register_prop_handler(&dom_document_prop_handlers, "xmlEncoding", dom_document_encoding_read, NULL TSRMLS_CC);
00663        dom_register_prop_handler(&dom_document_prop_handlers, "standalone", dom_document_standalone_read, dom_document_standalone_write TSRMLS_CC);
00664        dom_register_prop_handler(&dom_document_prop_handlers, "xmlStandalone", dom_document_standalone_read, dom_document_standalone_write TSRMLS_CC);
00665        dom_register_prop_handler(&dom_document_prop_handlers, "version", dom_document_version_read, dom_document_version_write TSRMLS_CC);
00666        dom_register_prop_handler(&dom_document_prop_handlers, "xmlVersion", dom_document_version_read, dom_document_version_write TSRMLS_CC);
00667        dom_register_prop_handler(&dom_document_prop_handlers, "strictErrorChecking", dom_document_strict_error_checking_read, dom_document_strict_error_checking_write TSRMLS_CC);
00668        dom_register_prop_handler(&dom_document_prop_handlers, "documentURI", dom_document_document_uri_read, dom_document_document_uri_write TSRMLS_CC);
00669        dom_register_prop_handler(&dom_document_prop_handlers, "config", dom_document_config_read, NULL TSRMLS_CC);
00670        dom_register_prop_handler(&dom_document_prop_handlers, "formatOutput", dom_document_format_output_read, dom_document_format_output_write TSRMLS_CC);
00671        dom_register_prop_handler(&dom_document_prop_handlers, "validateOnParse", dom_document_validate_on_parse_read, dom_document_validate_on_parse_write TSRMLS_CC);
00672        dom_register_prop_handler(&dom_document_prop_handlers, "resolveExternals", dom_document_resolve_externals_read, dom_document_resolve_externals_write TSRMLS_CC);
00673        dom_register_prop_handler(&dom_document_prop_handlers, "preserveWhiteSpace", dom_document_preserve_whitespace_read, dom_document_preserve_whitespace_write TSRMLS_CC);
00674        dom_register_prop_handler(&dom_document_prop_handlers, "recover", dom_document_recover_read, dom_document_recover_write TSRMLS_CC);
00675        dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", dom_document_substitue_entities_read, dom_document_substitue_entities_write TSRMLS_CC);
00676 
00677        zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00678        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_document_prop_handlers, sizeof(dom_document_prop_handlers), NULL);
00679 
00680        INIT_CLASS_ENTRY(ce, "DOMNodeList", php_dom_nodelist_class_functions);
00681        ce.create_object = dom_nnodemap_objects_new;
00682        dom_nodelist_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
00683        dom_nodelist_class_entry->get_iterator = php_dom_get_iterator;
00684        zend_class_implements(dom_nodelist_class_entry TSRMLS_CC, 1, zend_ce_traversable);
00685 
00686        zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, NULL, 1);
00687        dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", dom_nodelist_length_read, NULL TSRMLS_CC);
00688        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_nodelist_prop_handlers, sizeof(dom_nodelist_prop_handlers), NULL);
00689 
00690        INIT_CLASS_ENTRY(ce, "DOMNamedNodeMap", php_dom_namednodemap_class_functions);
00691        ce.create_object = dom_nnodemap_objects_new;
00692        dom_namednodemap_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
00693        dom_namednodemap_class_entry->get_iterator = php_dom_get_iterator;
00694        zend_class_implements(dom_namednodemap_class_entry TSRMLS_CC, 1, zend_ce_traversable);
00695 
00696        zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, NULL, 1);
00697        dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", dom_namednodemap_length_read, NULL TSRMLS_CC);
00698        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers), NULL);
00699 
00700        REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry);
00701        
00702        zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, NULL, 1);
00703        dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", dom_characterdata_data_read, dom_characterdata_data_write TSRMLS_CC);
00704        dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", dom_characterdata_length_read, NULL TSRMLS_CC);
00705        zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00706        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers), NULL);
00707 
00708        REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
00709        
00710        zend_hash_init(&dom_attr_prop_handlers, 0, NULL, NULL, 1);
00711        dom_register_prop_handler(&dom_attr_prop_handlers, "name", dom_attr_name_read, NULL TSRMLS_CC);
00712        dom_register_prop_handler(&dom_attr_prop_handlers, "specified", dom_attr_specified_read, NULL TSRMLS_CC);
00713        dom_register_prop_handler(&dom_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write TSRMLS_CC);
00714        dom_register_prop_handler(&dom_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL TSRMLS_CC);
00715        dom_register_prop_handler(&dom_attr_prop_handlers, "schemaTypeInfo", dom_attr_schema_type_info_read, NULL TSRMLS_CC);
00716        zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00717        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers), NULL);
00718 
00719        REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry);
00720        
00721        zend_hash_init(&dom_element_prop_handlers, 0, NULL, NULL, 1);
00722        dom_register_prop_handler(&dom_element_prop_handlers, "tagName", dom_element_tag_name_read, NULL TSRMLS_CC);
00723        dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", dom_element_schema_type_info_read, NULL TSRMLS_CC);
00724        zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00725        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers), NULL);
00726 
00727        REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
00728        
00729        zend_hash_init(&dom_text_prop_handlers, 0, NULL, NULL, 1);
00730        dom_register_prop_handler(&dom_text_prop_handlers, "wholeText", dom_text_whole_text_read, NULL TSRMLS_CC);
00731        zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00732        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers), NULL);
00733 
00734        REGISTER_DOM_CLASS(ce, "DOMComment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry);
00735        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
00736 
00737        REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
00738        
00739        zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, NULL, 1);
00740        dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", dom_typeinfo_type_name_read, NULL TSRMLS_CC);
00741        dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", dom_typeinfo_type_namespace_read, NULL TSRMLS_CC);
00742        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_typeinfo_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
00743 
00744        REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry);
00745        REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry);
00746        
00747        zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, NULL, 1);
00748        dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", dom_domerror_severity_read, NULL TSRMLS_CC);
00749        dom_register_prop_handler(&dom_domerror_prop_handlers, "message", dom_domerror_message_read, NULL TSRMLS_CC);
00750        dom_register_prop_handler(&dom_domerror_prop_handlers, "type", dom_domerror_type_read, NULL TSRMLS_CC);
00751        dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", dom_domerror_related_exception_read, NULL TSRMLS_CC);
00752        dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", dom_domerror_related_data_read, NULL TSRMLS_CC);
00753        dom_register_prop_handler(&dom_domerror_prop_handlers, "location", dom_domerror_location_read, NULL TSRMLS_CC);
00754        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domerror_prop_handlers, sizeof(dom_domerror_prop_handlers), NULL);
00755 
00756        REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry);
00757        REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry);
00758        
00759        zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, NULL, 1);
00760        dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", dom_domlocator_line_number_read, NULL TSRMLS_CC);
00761        dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", dom_domlocator_column_number_read, NULL TSRMLS_CC);
00762        dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", dom_domlocator_offset_read, NULL TSRMLS_CC);
00763        dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", dom_domlocator_related_node_read, NULL TSRMLS_CC);
00764        dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", dom_domlocator_uri_read, NULL TSRMLS_CC);
00765        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domlocator_prop_handlers, sizeof(dom_domlocator_prop_handlers), NULL);
00766 
00767        REGISTER_DOM_CLASS(ce, "DOMConfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry);
00768        REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
00769        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
00770 
00771        REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
00772        
00773        zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, NULL, 1);
00774        dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", dom_documenttype_name_read, NULL TSRMLS_CC);
00775        dom_register_prop_handler(&dom_documenttype_prop_handlers, "entities", dom_documenttype_entities_read, NULL TSRMLS_CC);
00776        dom_register_prop_handler(&dom_documenttype_prop_handlers, "notations", dom_documenttype_notations_read, NULL TSRMLS_CC);
00777        dom_register_prop_handler(&dom_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL TSRMLS_CC);
00778        dom_register_prop_handler(&dom_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL TSRMLS_CC);
00779        dom_register_prop_handler(&dom_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL TSRMLS_CC);
00780        zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00781        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
00782 
00783        REGISTER_DOM_CLASS(ce, "DOMNotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry);
00784        
00785        zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1);
00786        dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC);
00787        dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC);
00788        zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00789        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL);
00790 
00791        REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry);
00792        
00793        zend_hash_init(&dom_entity_prop_handlers, 0, NULL, NULL, 1);
00794        dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", dom_entity_public_id_read, NULL TSRMLS_CC);
00795        dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", dom_entity_system_id_read, NULL TSRMLS_CC);
00796        dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", dom_entity_notation_name_read, NULL TSRMLS_CC);
00797        dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", dom_entity_actual_encoding_read, dom_entity_actual_encoding_write TSRMLS_CC);
00798        dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", dom_entity_encoding_read, dom_entity_encoding_write TSRMLS_CC);
00799        dom_register_prop_handler(&dom_entity_prop_handlers, "version", dom_entity_version_read, dom_entity_version_write TSRMLS_CC);
00800        zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00801 
00802        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
00803 
00804        REGISTER_DOM_CLASS(ce, "DOMEntityReference", dom_node_class_entry, php_dom_entityreference_class_functions, dom_entityreference_class_entry);
00805        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
00806 
00807        REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
00808        
00809        zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, NULL, 1);
00810        dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", dom_processinginstruction_target_read, NULL TSRMLS_CC);
00811        dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", dom_processinginstruction_data_read, dom_processinginstruction_data_write TSRMLS_CC);
00812        zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
00813        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_processinginstruction_prop_handlers, sizeof(dom_processinginstruction_prop_handlers), NULL);
00814 
00815        REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
00816 
00817 #if defined(LIBXML_XPATH_ENABLED)
00818        INIT_CLASS_ENTRY(ce, "DOMXPath", php_dom_xpath_class_functions);
00819        ce.create_object = dom_xpath_objects_new;
00820        dom_xpath_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
00821 
00822        zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, NULL, 1);
00823        dom_register_prop_handler(&dom_xpath_prop_handlers, "document", dom_xpath_document_read, NULL TSRMLS_CC);
00824        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_xpath_prop_handlers, sizeof(dom_xpath_prop_handlers), NULL);
00825 #endif
00826 
00827        REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE",                     XML_ELEMENT_NODE,                  CONST_CS | CONST_PERSISTENT);
00828        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE",            XML_ATTRIBUTE_NODE,                CONST_CS | CONST_PERSISTENT);
00829        REGISTER_LONG_CONSTANT("XML_TEXT_NODE",                        XML_TEXT_NODE,                            CONST_CS | CONST_PERSISTENT);
00830        REGISTER_LONG_CONSTANT("XML_CDATA_SECTION_NODE", XML_CDATA_SECTION_NODE,            CONST_CS | CONST_PERSISTENT);
00831        REGISTER_LONG_CONSTANT("XML_ENTITY_REF_NODE",           XML_ENTITY_REF_NODE,        CONST_CS | CONST_PERSISTENT);
00832        REGISTER_LONG_CONSTANT("XML_ENTITY_NODE",               XML_ENTITY_NODE,                   CONST_CS | CONST_PERSISTENT);
00833        REGISTER_LONG_CONSTANT("XML_PI_NODE",                          XML_PI_NODE,                       CONST_CS | CONST_PERSISTENT);
00834        REGISTER_LONG_CONSTANT("XML_COMMENT_NODE",                     XML_COMMENT_NODE,                  CONST_CS | CONST_PERSISTENT);
00835        REGISTER_LONG_CONSTANT("XML_DOCUMENT_NODE",                    XML_DOCUMENT_NODE,                 CONST_CS | CONST_PERSISTENT);
00836        REGISTER_LONG_CONSTANT("XML_DOCUMENT_TYPE_NODE", XML_DOCUMENT_TYPE_NODE,            CONST_CS | CONST_PERSISTENT);
00837        REGISTER_LONG_CONSTANT("XML_DOCUMENT_FRAG_NODE", XML_DOCUMENT_FRAG_NODE,            CONST_CS | CONST_PERSISTENT);
00838        REGISTER_LONG_CONSTANT("XML_NOTATION_NODE",                    XML_NOTATION_NODE,                 CONST_CS | CONST_PERSISTENT);
00839        REGISTER_LONG_CONSTANT("XML_HTML_DOCUMENT_NODE", XML_HTML_DOCUMENT_NODE,            CONST_CS | CONST_PERSISTENT);
00840        REGISTER_LONG_CONSTANT("XML_DTD_NODE",                         XML_DTD_NODE,                      CONST_CS | CONST_PERSISTENT);
00841        REGISTER_LONG_CONSTANT("XML_ELEMENT_DECL_NODE",  XML_ELEMENT_DECL,                  CONST_CS | CONST_PERSISTENT);
00842        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_DECL_NODE",       XML_ATTRIBUTE_DECL,                CONST_CS | CONST_PERSISTENT);
00843        REGISTER_LONG_CONSTANT("XML_ENTITY_DECL_NODE",          XML_ENTITY_DECL,                   CONST_CS | CONST_PERSISTENT);
00844        REGISTER_LONG_CONSTANT("XML_NAMESPACE_DECL_NODE",       XML_NAMESPACE_DECL,                CONST_CS | CONST_PERSISTENT);
00845 #ifdef XML_GLOBAL_NAMESPACE
00846        REGISTER_LONG_CONSTANT("XML_GLOBAL_NAMESPACE",          XML_GLOBAL_NAMESPACE,              CONST_CS | CONST_PERSISTENT);
00847 #endif
00848        REGISTER_LONG_CONSTANT("XML_LOCAL_NAMESPACE",           XML_LOCAL_NAMESPACE,        CONST_CS | CONST_PERSISTENT);
00849        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_CDATA",           XML_ATTRIBUTE_CDATA,        CONST_CS | CONST_PERSISTENT);
00850        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ID",                     XML_ATTRIBUTE_ID,                  CONST_CS | CONST_PERSISTENT);
00851        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREF",           XML_ATTRIBUTE_IDREF,        CONST_CS | CONST_PERSISTENT);
00852        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREFS",          XML_ATTRIBUTE_IDREFS,              CONST_CS | CONST_PERSISTENT);
00853        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENTITY",          XML_ATTRIBUTE_ENTITIES,            CONST_CS | CONST_PERSISTENT);
00854        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKEN",         XML_ATTRIBUTE_NMTOKEN,             CONST_CS | CONST_PERSISTENT);
00855        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKENS", XML_ATTRIBUTE_NMTOKENS,            CONST_CS | CONST_PERSISTENT);
00856        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENUMERATION",     XML_ATTRIBUTE_ENUMERATION,  CONST_CS | CONST_PERSISTENT);
00857        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NOTATION", XML_ATTRIBUTE_NOTATION,            CONST_CS | CONST_PERSISTENT);
00858 
00859        /* DOMException Codes */
00860        REGISTER_LONG_CONSTANT("DOM_PHP_ERR",                          PHP_ERR,                           CONST_CS | CONST_PERSISTENT);
00861        REGISTER_LONG_CONSTANT("DOM_INDEX_SIZE_ERR",            INDEX_SIZE_ERR,                    CONST_CS | CONST_PERSISTENT);
00862        REGISTER_LONG_CONSTANT("DOMSTRING_SIZE_ERR",            DOMSTRING_SIZE_ERR,         CONST_CS | CONST_PERSISTENT);
00863        REGISTER_LONG_CONSTANT("DOM_HIERARCHY_REQUEST_ERR",     HIERARCHY_REQUEST_ERR,      CONST_CS | CONST_PERSISTENT);
00864        REGISTER_LONG_CONSTANT("DOM_WRONG_DOCUMENT_ERR", WRONG_DOCUMENT_ERR,         CONST_CS | CONST_PERSISTENT);
00865        REGISTER_LONG_CONSTANT("DOM_INVALID_CHARACTER_ERR",     INVALID_CHARACTER_ERR,      CONST_CS | CONST_PERSISTENT);
00866        REGISTER_LONG_CONSTANT("DOM_NO_DATA_ALLOWED_ERR",       NO_DATA_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
00867        REGISTER_LONG_CONSTANT("DOM_NO_MODIFICATION_ALLOWED_ERR", NO_MODIFICATION_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
00868        REGISTER_LONG_CONSTANT("DOM_NOT_FOUND_ERR",                    NOT_FOUND_ERR,                     CONST_CS | CONST_PERSISTENT);
00869        REGISTER_LONG_CONSTANT("DOM_NOT_SUPPORTED_ERR",         NOT_SUPPORTED_ERR,          CONST_CS | CONST_PERSISTENT);
00870        REGISTER_LONG_CONSTANT("DOM_INUSE_ATTRIBUTE_ERR",       INUSE_ATTRIBUTE_ERR, CONST_CS | CONST_PERSISTENT);
00871        REGISTER_LONG_CONSTANT("DOM_INVALID_STATE_ERR",         INVALID_STATE_ERR,          CONST_CS | CONST_PERSISTENT);
00872        REGISTER_LONG_CONSTANT("DOM_SYNTAX_ERR",                SYNTAX_ERR,                        CONST_CS | CONST_PERSISTENT);
00873        REGISTER_LONG_CONSTANT("DOM_INVALID_MODIFICATION_ERR",  INVALID_MODIFICATION_ERR, CONST_CS | CONST_PERSISTENT);
00874        REGISTER_LONG_CONSTANT("DOM_NAMESPACE_ERR",                    NAMESPACE_ERR,                     CONST_CS | CONST_PERSISTENT);
00875        REGISTER_LONG_CONSTANT("DOM_INVALID_ACCESS_ERR", INVALID_ACCESS_ERR,         CONST_CS | CONST_PERSISTENT);
00876        REGISTER_LONG_CONSTANT("DOM_VALIDATION_ERR",            VALIDATION_ERR,                    CONST_CS | CONST_PERSISTENT);
00877 
00878        php_libxml_register_export(dom_node_class_entry, php_dom_export_node);
00879 
00880        return SUCCESS;
00881 }
00882 /* }}} */
00883 
00884 /* {{{ */
00885 PHP_MINFO_FUNCTION(dom)
00886 {
00887        php_info_print_table_start();
00888        php_info_print_table_row(2, "DOM/XML", "enabled");
00889        php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
00890        php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION);
00891 #if defined(LIBXML_HTML_ENABLED)
00892        php_info_print_table_row(2, "HTML Support", "enabled");
00893 #endif
00894 #if defined(LIBXML_XPATH_ENABLED)
00895        php_info_print_table_row(2, "XPath Support", "enabled");
00896 #endif
00897 #if defined(LIBXML_XPTR_ENABLED)
00898        php_info_print_table_row(2, "XPointer Support", "enabled");
00899 #endif
00900 #ifdef LIBXML_SCHEMAS_ENABLED
00901        php_info_print_table_row(2, "Schema Support", "enabled");
00902        php_info_print_table_row(2, "RelaxNG Support", "enabled");
00903 #endif
00904        php_info_print_table_end();
00905 }
00906 /* }}} */
00907 
00908 PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */
00909 {
00910        zend_hash_destroy(&dom_domstringlist_prop_handlers);
00911        zend_hash_destroy(&dom_namelist_prop_handlers);
00912        zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
00913        zend_hash_destroy(&dom_document_prop_handlers);
00914        zend_hash_destroy(&dom_node_prop_handlers);
00915        zend_hash_destroy(&dom_namespace_node_prop_handlers);
00916        zend_hash_destroy(&dom_nodelist_prop_handlers);
00917        zend_hash_destroy(&dom_namednodemap_prop_handlers);
00918        zend_hash_destroy(&dom_characterdata_prop_handlers);
00919        zend_hash_destroy(&dom_attr_prop_handlers);
00920        zend_hash_destroy(&dom_element_prop_handlers);
00921        zend_hash_destroy(&dom_text_prop_handlers);
00922        zend_hash_destroy(&dom_typeinfo_prop_handlers);
00923        zend_hash_destroy(&dom_domerror_prop_handlers);
00924        zend_hash_destroy(&dom_domlocator_prop_handlers);
00925        zend_hash_destroy(&dom_documenttype_prop_handlers);
00926        zend_hash_destroy(&dom_notation_prop_handlers);
00927        zend_hash_destroy(&dom_entity_prop_handlers);
00928        zend_hash_destroy(&dom_processinginstruction_prop_handlers);
00929 #if defined(LIBXML_XPATH_ENABLED)
00930        zend_hash_destroy(&dom_xpath_prop_handlers);
00931 #endif
00932        zend_hash_destroy(&classes);
00933        
00934 /*     If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and
00935        uncomment the following line, this will tell you the amount of not freed memory
00936        and the total used memory into apaches error_log  */
00937 /*  xmlMemoryDump();*/
00938 
00939        return SUCCESS;
00940 }
00941 /* }}} */
00942 
00943 /* {{{ node_list_unlink */
00944 void node_list_unlink(xmlNodePtr node TSRMLS_DC)
00945 {
00946        dom_object *wrapper;
00947 
00948        while (node != NULL) {
00949 
00950               wrapper = php_dom_object_get_data(node);
00951 
00952               if (wrapper != NULL ) {
00953                      xmlUnlinkNode(node);
00954               } else {
00955                      if (node->type == XML_ENTITY_REF_NODE)
00956                             break;
00957                      node_list_unlink(node->children TSRMLS_CC);
00958 
00959                      switch (node->type) {
00960                             case XML_ATTRIBUTE_DECL:
00961                             case XML_DTD_NODE:
00962                             case XML_DOCUMENT_TYPE_NODE:
00963                             case XML_ENTITY_DECL:
00964                             case XML_ATTRIBUTE_NODE:
00965                             case XML_TEXT_NODE:
00966                                    break;
00967                             default:
00968                                    node_list_unlink((xmlNodePtr) node->properties TSRMLS_CC);
00969                      }
00970 
00971               }
00972 
00973               node = node->next;
00974        }
00975 }
00976 /* }}} end node_list_unlink */
00977 
00978 #if defined(LIBXML_XPATH_ENABLED)
00979 /* {{{ dom_xpath_objects_free_storage */
00980 void dom_xpath_objects_free_storage(void *object TSRMLS_DC)
00981 {
00982        dom_xpath_object *intern = (dom_xpath_object *)object;
00983 
00984        zend_object_std_dtor(&intern->std TSRMLS_CC);
00985 
00986        if (intern->ptr != NULL) {
00987               xmlXPathFreeContext((xmlXPathContextPtr) intern->ptr);
00988               php_libxml_decrement_doc_ref((php_libxml_node_object *) intern TSRMLS_CC);
00989               intern->ptr = NULL;
00990        }
00991 
00992        if (intern->registered_phpfunctions) {
00993               zend_hash_destroy(intern->registered_phpfunctions);
00994               FREE_HASHTABLE(intern->registered_phpfunctions);
00995        }
00996        
00997        if (intern->node_list) {
00998               zend_hash_destroy(intern->node_list);
00999               FREE_HASHTABLE(intern->node_list);
01000        }
01001 
01002        efree(object);
01003 }
01004 /* }}} */
01005 #endif
01006 
01007 /* {{{ dom_objects_free_storage */
01008 void dom_objects_free_storage(void *object TSRMLS_DC)
01009 {
01010        dom_object *intern = (dom_object *)object;
01011        int retcount;
01012 
01013        zend_object_std_dtor(&intern->std TSRMLS_CC);
01014 
01015        if (intern->ptr != NULL && ((php_libxml_node_ptr *)intern->ptr)->node != NULL) {
01016               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) {
01017                      php_libxml_node_decrement_resource((php_libxml_node_object *) intern TSRMLS_CC);
01018               } else {
01019                      php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
01020                      retcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
01021               }
01022               intern->ptr = NULL;
01023        }
01024 
01025        efree(object);
01026 }
01027 /* }}} */
01028 
01029 void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns TSRMLS_DC) /* {{{ */
01030 {
01031        dom_nnodemap_object *mapptr;
01032        zval *baseobj = NULL;
01033 
01034        mapptr = (dom_nnodemap_object *)intern->ptr;
01035        if (basenode) {
01036               MAKE_STD_ZVAL(baseobj);
01037               baseobj->type = IS_OBJECT;
01038               Z_SET_ISREF_P(baseobj);
01039               baseobj->value.obj.handle = basenode->handle;
01040               baseobj->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C);
01041               zval_copy_ctor(baseobj);
01042        }
01043        mapptr->baseobjptr = baseobj;
01044        mapptr->baseobj = basenode;
01045        mapptr->nodetype = ntype;
01046        mapptr->ht = ht;
01047        mapptr->local = local;
01048        mapptr->ns = ns;
01049 
01050 }
01051 /* }}} */
01052 
01053 static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy TSRMLS_DC) /* {{{ */
01054 {
01055        zend_class_entry *base_class;
01056        zval *tmp;
01057        dom_object *intern;
01058 
01059        if (instanceof_function(class_type, dom_xpath_class_entry TSRMLS_CC)) {
01060               intern = emalloc(sizeof(dom_xpath_object));
01061               memset(intern, 0, sizeof(dom_xpath_object));
01062        } else {
01063               intern = emalloc(sizeof(dom_object));
01064        }
01065        intern->ptr = NULL;
01066        intern->prop_handler = NULL;
01067        intern->document = NULL;
01068 
01069        base_class = class_type;
01070        while(base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) {
01071               base_class = base_class->parent;
01072        }
01073 
01074        zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler);
01075 
01076        zend_object_std_init(&intern->std, class_type TSRMLS_CC);
01077        if (hash_copy) {
01078               zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
01079        }
01080 
01081        return intern;
01082 }
01083 /* }}} */
01084 
01085 /* {{{ dom_objects_clone */
01086 void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
01087 {
01088        dom_object *intern = (dom_object *) object;
01089        dom_object *clone;
01090        xmlNodePtr node;
01091        xmlNodePtr cloned_node;
01092 
01093        clone = dom_objects_set_class(intern->std.ce, 0 TSRMLS_CC);
01094 
01095        if (instanceof_function(intern->std.ce, dom_node_class_entry TSRMLS_CC)) {
01096               node = (xmlNodePtr)dom_object_get_node((dom_object *) object);
01097               if (node != NULL) {
01098                      cloned_node = xmlDocCopyNode(node, node->doc, 1);
01099                      if (cloned_node != NULL) {
01100                             /* If we cloned a document then we must create new doc proxy */
01101                             if (cloned_node->doc == node->doc) {
01102                                    clone->document = intern->document;
01103                             }
01104                             php_libxml_increment_doc_ref((php_libxml_node_object *)clone, cloned_node->doc TSRMLS_CC);
01105                             php_libxml_increment_node_ptr((php_libxml_node_object *)clone, cloned_node, (void *)clone TSRMLS_CC);
01106                             if (intern->document != clone->document) {
01107                                    dom_copy_doc_props(intern->document, clone->document);
01108                             }
01109                      }
01110 
01111               }
01112        }
01113 
01114        *object_clone = (void *) clone;
01115 }
01116 /* }}} */
01117 
01118 /* {{{ dom_objects_new */
01119 zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
01120 {
01121        zend_object_value retval;
01122        dom_object *intern;
01123        
01124        intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
01125 
01126        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);
01127        intern->handle = retval.handle;
01128        retval.handlers = dom_get_obj_handlers(TSRMLS_C);
01129 
01130        return retval;
01131 }
01132 /* }}} */
01133 
01134 #if defined(LIBXML_XPATH_ENABLED)
01135 /* {{{ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC) */
01136 zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC)
01137 {
01138        zend_object_value retval;
01139        dom_xpath_object *intern;
01140 
01141        intern = (dom_xpath_object *)dom_objects_set_class(class_type, 1 TSRMLS_CC);
01142        intern->registerPhpFunctions = 0;
01143        intern->registered_phpfunctions = NULL;
01144        intern->node_list = NULL;
01145 
01146        ALLOC_HASHTABLE(intern->registered_phpfunctions);
01147        zend_hash_init(intern->registered_phpfunctions, 0, NULL, ZVAL_PTR_DTOR, 0);
01148 
01149        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);
01150        intern->handle = retval.handle;
01151        retval.handlers = dom_get_obj_handlers(TSRMLS_C);
01152 
01153        return retval;
01154 }
01155 /* }}} */
01156 #endif
01157 
01158 static void dom_nnodemap_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */
01159 {
01160        zval *baseobj;
01161        dom_object *intern;
01162        dom_nnodemap_object *objmap;
01163 
01164        intern = (dom_object *)object;
01165        objmap = (dom_nnodemap_object *)intern->ptr;
01166 
01167        if (objmap) {
01168               if (objmap->local) {
01169                      xmlFree(objmap->local);
01170               }
01171               if (objmap->ns) {
01172                      xmlFree(objmap->ns);
01173               }
01174               if (objmap->baseobjptr) {
01175                      baseobj = objmap->baseobjptr;
01176                      zval_ptr_dtor((zval **)&baseobj);
01177               }
01178               efree(objmap);
01179               intern->ptr = NULL;
01180        }
01181 
01182 
01183 }
01184 /* }}} */
01185 
01186 void dom_nnodemap_objects_free_storage(void *object TSRMLS_DC) /* {{{ */
01187 {
01188        dom_object *intern = (dom_object *)object;
01189 
01190        php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
01191 
01192        zend_object_std_dtor(&intern->std TSRMLS_CC);
01193 
01194        efree(object);
01195 }
01196 /* }}} */
01197 
01198 zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
01199 {
01200        zend_object_value retval;
01201        dom_object *intern;
01202        dom_nnodemap_object *objmap;
01203        
01204        intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
01205        intern->ptr = emalloc(sizeof(dom_nnodemap_object));
01206        objmap = (dom_nnodemap_object *)intern->ptr;
01207        objmap->baseobj = NULL;
01208        objmap->baseobjptr = NULL;
01209        objmap->nodetype = 0;
01210        objmap->ht = NULL;
01211        objmap->local = NULL;
01212        objmap->ns = NULL;
01213 
01214        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);
01215        intern->handle = retval.handle;
01216        retval.handlers = dom_get_obj_handlers(TSRMLS_C);
01217 
01218        return retval;
01219 }
01220 /* }}} */
01221 
01222 void php_dom_create_interator(zval *return_value, int ce_type TSRMLS_DC) /* {{{ */
01223 {
01224        zend_class_entry *ce;
01225 
01226        if (ce_type == DOM_NAMEDNODEMAP) {
01227               ce = dom_namednodemap_class_entry;
01228        } else {
01229               ce = dom_nodelist_class_entry;
01230        }
01231 
01232        object_init_ex(return_value, ce);
01233 }
01234 /* }}} */
01235 
01236 /* {{{ php_dom_create_object */
01237 PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval *return_value, dom_object *domobj TSRMLS_DC)
01238 {
01239        zval *wrapper;
01240        zend_class_entry *ce;
01241        dom_object *intern;
01242 
01243        *found = 0;
01244 
01245        if (!obj) {
01246               ALLOC_ZVAL(wrapper);
01247               ZVAL_NULL(wrapper);
01248               return wrapper;
01249        }
01250 
01251        if ((intern = (dom_object *) php_dom_object_get_data((void *) obj))) {
01252               return_value->type = IS_OBJECT;
01253               Z_SET_ISREF_P(return_value);
01254               return_value->value.obj.handle = intern->handle;
01255               return_value->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C);
01256               zval_copy_ctor(return_value);
01257               *found = 1;
01258               return return_value;
01259        }
01260 
01261        wrapper = return_value;
01262 
01263        switch (obj->type) {
01264               case XML_DOCUMENT_NODE:
01265               case XML_HTML_DOCUMENT_NODE:
01266               {
01267                      ce = dom_document_class_entry;
01268                      break;
01269               }
01270               case XML_DTD_NODE:
01271               case XML_DOCUMENT_TYPE_NODE:
01272               {
01273                      ce = dom_documenttype_class_entry;
01274                      break;
01275               }
01276               case XML_ELEMENT_NODE:
01277               {
01278                      ce = dom_element_class_entry;
01279                      break;
01280               }
01281               case XML_ATTRIBUTE_NODE:
01282               {
01283                      ce = dom_attr_class_entry;
01284                      break;
01285               }
01286               case XML_TEXT_NODE:
01287               {
01288                      ce = dom_text_class_entry;
01289                      break;
01290               }
01291               case XML_COMMENT_NODE:
01292               {
01293                      ce = dom_comment_class_entry;
01294                      break;
01295               }
01296               case XML_PI_NODE:
01297               {
01298                      ce = dom_processinginstruction_class_entry;
01299                      break;
01300               }
01301               case XML_ENTITY_REF_NODE:
01302               {
01303                      ce = dom_entityreference_class_entry;
01304                      break;
01305               }
01306               case XML_ENTITY_DECL:
01307               case XML_ELEMENT_DECL:
01308               {
01309                      ce = dom_entity_class_entry;
01310                      break;
01311               }
01312               case XML_CDATA_SECTION_NODE:
01313               {
01314                      ce = dom_cdatasection_class_entry;
01315                      break;
01316               }
01317               case XML_DOCUMENT_FRAG_NODE:
01318               {
01319                      ce = dom_documentfragment_class_entry;
01320                      break;
01321               }
01322               case XML_NOTATION_NODE:
01323               {
01324                      ce = dom_notation_class_entry;
01325                      break;
01326               }
01327               case XML_NAMESPACE_DECL:
01328               {
01329                      ce = dom_namespace_node_class_entry;
01330                      break;
01331               }
01332               default:
01333                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d", Z_TYPE_P(obj));
01334                      ZVAL_NULL(wrapper);
01335                      return wrapper;
01336        }
01337 
01338        if (domobj && domobj->document) {
01339               ce = dom_get_doc_classmap(domobj->document, ce TSRMLS_CC);
01340        }
01341        object_init_ex(wrapper, ce);
01342 
01343        intern = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
01344        if (obj->doc != NULL) {
01345               if (domobj != NULL) {
01346                      intern->document = domobj->document;
01347               }
01348               php_libxml_increment_doc_ref((php_libxml_node_object *)intern, obj->doc TSRMLS_CC);
01349        }
01350 
01351        php_libxml_increment_node_ptr((php_libxml_node_object *)intern, obj, (void *)intern TSRMLS_CC);
01352        return (wrapper);
01353 }
01354 /* }}} end php_domobject_new */
01355 
01356 void php_dom_create_implementation(zval **retval  TSRMLS_DC) {
01357        object_init_ex(*retval, dom_domimplementation_class_entry);
01358 }
01359 
01360 /* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */
01361 int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) 
01362 {
01363        xmlNodePtr nodep;
01364 
01365     if (parent == NULL || child == NULL || child->doc != parent->doc) {
01366         return SUCCESS;
01367     }
01368 
01369        nodep = parent;
01370 
01371        while (nodep) {
01372               if (nodep == child) {
01373                      return FAILURE;
01374               }
01375               nodep = nodep->parent;
01376        }
01377 
01378     return SUCCESS;
01379 }
01380 /* }}} end dom_hierarchy */
01381 
01382 /* {{{ dom_has_feature(char *feature, char *version) */
01383 int dom_has_feature(char *feature, char *version)
01384 {
01385        int retval = 0;
01386 
01387        if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, ""))) {
01388               if ((!strcasecmp(feature, "Core") && !strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
01389                      retval = 1;
01390        }
01391 
01392        return retval;
01393 }
01394 /* }}} end dom_has_feature */
01395 
01396 xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index) /* {{{ */
01397 {
01398        xmlNodePtr ret = NULL;
01399 
01400        while (nodep != NULL && (*cur <= index || index == -1)) {
01401               if (nodep->type == XML_ELEMENT_NODE) {
01402                      if (xmlStrEqual(nodep->name, (xmlChar *)local) || xmlStrEqual((xmlChar *)"*", (xmlChar *)local)) {
01403                             if (ns == NULL || (nodep->ns != NULL && (xmlStrEqual(nodep->ns->href, (xmlChar *)ns) || xmlStrEqual((xmlChar *)"*", (xmlChar *)ns)))) {
01404                                    if (*cur == index) {
01405                                           ret = nodep;
01406                                           break;
01407                                    }
01408                                    (*cur)++;
01409                             }
01410                      }
01411                      ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
01412                      if (ret != NULL) {
01413                             break;
01414                      }
01415               }
01416               nodep = nodep->next;
01417        }
01418        return ret;
01419 }
01420 /* }}} */
01421 /* }}} end dom_element_get_elements_by_tag_name_ns_raw */
01422 
01423 /* {{{ void dom_normalize (xmlNodePtr nodep TSRMLS_DC) */
01424 void dom_normalize (xmlNodePtr nodep TSRMLS_DC)
01425 {
01426        xmlNodePtr child, nextp, newnextp;
01427        xmlAttrPtr attr;
01428        xmlChar       *strContent; 
01429 
01430        child = nodep->children;
01431        while(child != NULL) {
01432               switch (child->type) {
01433                      case XML_TEXT_NODE:
01434                             nextp = child->next;
01435                             while (nextp != NULL) {
01436                                    if (nextp->type == XML_TEXT_NODE) {
01437                                           newnextp = nextp->next;
01438                                           strContent = xmlNodeGetContent(nextp);
01439                                           xmlNodeAddContent(child, strContent);
01440                                           xmlFree(strContent);
01441                                           xmlUnlinkNode(nextp);
01442                                           php_libxml_node_free_resource(nextp TSRMLS_CC);
01443                                           nextp = newnextp;
01444                                    } else {
01445                                           break;
01446                                    }
01447                             }
01448                             break;
01449                      case XML_ELEMENT_NODE:
01450                             dom_normalize (child TSRMLS_CC);
01451                             attr = child->properties;
01452                             while (attr != NULL) {
01453                                    dom_normalize((xmlNodePtr) attr TSRMLS_CC);
01454                                    attr = attr->next;
01455                             }
01456                             break;
01457                      case XML_ATTRIBUTE_NODE:
01458                             dom_normalize (child TSRMLS_CC);
01459                             break;
01460                      default:
01461                             break;
01462               }
01463               child = child->next;
01464        }
01465 }
01466 /* }}} end dom_normalize */
01467 
01468 
01469 /* {{{ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) */
01470 void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
01471        xmlNs *cur;
01472 
01473        if (doc == NULL)
01474               return;
01475 
01476        if (doc->oldNs == NULL) {
01477               doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
01478               if (doc->oldNs == NULL) {
01479                      return;
01480               }
01481               memset(doc->oldNs, 0, sizeof(xmlNs));
01482               doc->oldNs->type = XML_LOCAL_NAMESPACE;
01483               doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE); 
01484               doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml"); 
01485        }
01486 
01487        cur = doc->oldNs;
01488        while (cur->next != NULL) {
01489               cur = cur->next;
01490        }
01491        cur->next = ns;
01492 }
01493 /* }}} end dom_set_old_ns */
01494 
01495 /*
01496 http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
01497 
01498 NAMESPACE_ERR: Raised if
01499 
01500 1. the qualifiedName is a malformed qualified name
01501 2. the qualifiedName has a prefix and the  namespaceURI is null
01502 */
01503 
01504 /* {{{ int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) */
01505 int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) {
01506        if (name_len == 0) {
01507               return NAMESPACE_ERR;
01508        }
01509        
01510        *localname = (char *)xmlSplitQName2((xmlChar *)qname, (xmlChar **) prefix);
01511        if (*localname == NULL) {
01512               *localname = (char *)xmlStrdup((xmlChar *)qname);
01513               if (*prefix == NULL && uri_len == 0) {
01514                      return 0;
01515               }
01516        }
01517 
01518        /* 1 */
01519        if (xmlValidateQName((xmlChar *) qname, 0) != 0) {
01520               return NAMESPACE_ERR;
01521        }
01522 
01523        /* 2 */
01524        if (*prefix != NULL && uri_len == 0) {
01525               return NAMESPACE_ERR;
01526        }
01527 
01528        return 0;
01529 }
01530 /* }}} */
01531 
01532 /*
01533 http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
01534 
01535 NAMESPACE_ERR: Raised if
01536 
01537 3. the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace" [XML Namespaces]
01538 4. the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from  "http://www.w3.org/2000/xmlns/"
01539 5. the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the       qualifiedName nor its prefix is "xmlns".
01540 */
01541 
01542 /* {{{ xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) */
01543 xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) {
01544        xmlNsPtr nsptr = NULL;
01545 
01546        *errorcode = 0;
01547 
01548        if (! ((prefix && !strcmp (prefix, "xml") && strcmp(uri, (char *)XML_XML_NAMESPACE)) ||
01549                  (prefix && !strcmp (prefix, "xmlns") && strcmp(uri, (char *)DOM_XMLNS_NAMESPACE)) ||
01550                  (prefix && !strcmp(uri, (char *)DOM_XMLNS_NAMESPACE) && strcmp (prefix, "xmlns")))) {
01551               nsptr = xmlNewNs(nodep, (xmlChar *)uri, (xmlChar *)prefix);
01552        }
01553 
01554        if (nsptr == NULL) {
01555               *errorcode = NAMESPACE_ERR;
01556        }
01557 
01558        return nsptr;
01559 
01560 }
01561 /* }}} end dom_get_ns */
01562 
01563 /* {{{ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) */
01564 xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
01565        xmlNsPtr cur;
01566        xmlNs *ret = NULL;
01567        if (node == NULL)
01568               return NULL;
01569 
01570        if (localName == NULL || xmlStrEqual(localName, (xmlChar *)"")) {
01571               cur = node->nsDef;
01572               while (cur != NULL) {
01573                      if (cur->prefix == NULL  && cur->href != NULL) {
01574                             ret = cur;
01575                             break;
01576                      }
01577                      cur = cur->next;
01578               }
01579        } else {
01580               cur = node->nsDef;
01581               while (cur != NULL) {
01582                      if (cur->prefix != NULL && xmlStrEqual(localName, cur->prefix)) {
01583                             ret = cur;
01584                             break;
01585                      }
01586                      cur = cur->next;
01587               }
01588        }
01589        return ret;
01590 }
01591 /* }}} end dom_get_nsdecl */
01592 
01593 #endif /* HAVE_DOM */
01594 
01595 /*
01596  * Local variables:
01597  * tab-width: 4
01598  * c-basic-offset: 4
01599  * End:
01600  * vim600: noet sw=4 ts=4 fdm=marker
01601  * vim<600: noet sw=4 ts=4
01602  */