2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 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_0.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
+----------------------------------------------------------------------+
21
/* $Id: php_dom.c,v 1.60.2.8 2005/06/22 19:58:33 rrichards Exp $ */
28
#if HAVE_LIBXML && HAVE_DOM
29
#include "ext/standard/php_rand.h"
31
#include "dom_properties.h"
33
#include "ext/standard/info.h"
37
zend_class_entry *dom_node_class_entry;
38
zend_class_entry *dom_domexception_class_entry;
39
zend_class_entry *dom_domstringlist_class_entry;
40
zend_class_entry *dom_namelist_class_entry;
41
zend_class_entry *dom_domimplementationlist_class_entry;
42
zend_class_entry *dom_domimplementationsource_class_entry;
43
zend_class_entry *dom_domimplementation_class_entry;
44
zend_class_entry *dom_documentfragment_class_entry;
45
zend_class_entry *dom_document_class_entry;
46
zend_class_entry *dom_nodelist_class_entry;
47
zend_class_entry *dom_namednodemap_class_entry;
48
zend_class_entry *dom_characterdata_class_entry;
49
zend_class_entry *dom_attr_class_entry;
50
zend_class_entry *dom_element_class_entry;
51
zend_class_entry *dom_text_class_entry;
52
zend_class_entry *dom_comment_class_entry;
53
zend_class_entry *dom_typeinfo_class_entry;
54
zend_class_entry *dom_userdatahandler_class_entry;
55
zend_class_entry *dom_domerror_class_entry;
56
zend_class_entry *dom_domerrorhandler_class_entry;
57
zend_class_entry *dom_domlocator_class_entry;
58
zend_class_entry *dom_domconfiguration_class_entry;
59
zend_class_entry *dom_cdatasection_class_entry;
60
zend_class_entry *dom_documenttype_class_entry;
61
zend_class_entry *dom_notation_class_entry;
62
zend_class_entry *dom_entity_class_entry;
63
zend_class_entry *dom_entityreference_class_entry;
64
zend_class_entry *dom_processinginstruction_class_entry;
65
zend_class_entry *dom_string_extend_class_entry;
66
#if defined(LIBXML_XPATH_ENABLED)
67
zend_class_entry *dom_xpath_class_entry;
69
zend_class_entry *dom_namespace_node_class_entry;
71
zend_object_handlers dom_object_handlers;
72
zend_object_handlers dom_ze1_object_handlers;
74
static HashTable classes;
76
static HashTable dom_domstringlist_prop_handlers;
77
static HashTable dom_namelist_prop_handlers;
78
static HashTable dom_domimplementationlist_prop_handlers;
79
static HashTable dom_document_prop_handlers;
80
static HashTable dom_node_prop_handlers;
81
static HashTable dom_nodelist_prop_handlers;
82
static HashTable dom_namednodemap_prop_handlers;
83
static HashTable dom_characterdata_prop_handlers;
84
static HashTable dom_attr_prop_handlers;
85
static HashTable dom_element_prop_handlers;
86
static HashTable dom_text_prop_handlers;
87
static HashTable dom_typeinfo_prop_handlers;
88
static HashTable dom_domerror_prop_handlers;
89
static HashTable dom_domlocator_prop_handlers;
90
static HashTable dom_documenttype_prop_handlers;
91
static HashTable dom_notation_prop_handlers;
92
static HashTable dom_entity_prop_handlers;
93
static HashTable dom_processinginstruction_prop_handlers;
94
static HashTable dom_namespace_node_prop_handlers;
95
#if defined(LIBXML_XPATH_ENABLED)
96
static HashTable dom_xpath_prop_handlers;
99
typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC);
100
typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC);
102
typedef struct _dom_prop_handler {
103
dom_read_t read_func;
104
dom_write_t write_func;
107
/* {{{ int dom_node_is_read_only(xmlNodePtr node) */
108
int dom_node_is_read_only(xmlNodePtr node) {
109
switch (node->type) {
110
case XML_ENTITY_REF_NODE:
111
case XML_ENTITY_NODE:
112
case XML_DOCUMENT_TYPE_NODE:
113
case XML_NOTATION_NODE:
115
case XML_ELEMENT_DECL:
116
case XML_ATTRIBUTE_DECL:
117
case XML_ENTITY_DECL:
118
case XML_NAMESPACE_DECL:
122
if (node->doc == NULL) {
129
/* }}} end dom_node_is_read_only */
131
/* {{{ int dom_node_children_valid(xmlNodePtr node) */
132
int dom_node_children_valid(xmlNodePtr node) {
133
switch (node->type) {
134
case XML_DOCUMENT_TYPE_NODE:
137
case XML_COMMENT_NODE:
139
case XML_CDATA_SECTION_NODE:
140
case XML_NOTATION_NODE:
147
/* }}} end dom_node_children_valid */
149
/* {{{ dom_get_doc_props() */
150
dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
152
dom_doc_props *doc_props;
154
if (document && document->doc_props) {
155
return document->doc_props;
157
doc_props = emalloc(sizeof(dom_doc_props));
158
doc_props->formatoutput = 0;
159
doc_props->validateonparse = 0;
160
doc_props->resolveexternals = 0;
161
doc_props->preservewhitespace = 1;
162
doc_props->substituteentities = 0;
163
doc_props->stricterror = 1;
165
document->doc_props = doc_props;
172
/* {{{ dom_get_strict_error() */
173
int dom_get_strict_error(php_libxml_ref_obj *document) {
175
dom_doc_props *doc_props;
177
doc_props = dom_get_doc_props(document);
178
stricterror = doc_props->stricterror;
179
if (document == NULL) {
187
/* {{{ xmlNodePtr dom_object_get_node(dom_object *obj) */
188
xmlNodePtr dom_object_get_node(dom_object *obj)
190
if (obj->ptr != NULL) {
191
return ((php_libxml_node_ptr *)obj->ptr)->node;
196
/* }}} end dom_object_get_node */
198
/* {{{ dom_object *php_dom_object_get_data(xmlNodePtr obj) */
199
dom_object *php_dom_object_get_data(xmlNodePtr obj)
201
if (obj->_private != NULL) {
202
return (dom_object *) ((php_libxml_node_ptr *) obj->_private)->_private;
207
/* }}} end php_dom_object_get_data */
209
/* {{{ dom_read_na */
210
static int dom_read_na(dom_object *obj, zval **retval TSRMLS_DC)
213
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
218
/* {{{ dom_write_na */
219
static int dom_write_na(dom_object *obj, zval *newval TSRMLS_DC)
221
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
226
/* {{{ dom_register_prop_handler */
227
static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_read_t read_func, dom_write_t write_func TSRMLS_DC)
229
dom_prop_handler hnd;
231
hnd.read_func = read_func ? read_func : dom_read_na;
232
hnd.write_func = write_func ? write_func : dom_write_na;
233
zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(dom_prop_handler), NULL);
237
static zval **dom_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC)
241
zval **retval = NULL;
242
dom_prop_handler *hnd;
243
zend_object_handlers *std_hnd;
246
if (member->type != IS_STRING) {
247
tmp_member = *member;
248
zval_copy_ctor(&tmp_member);
249
convert_to_string(&tmp_member);
250
member = &tmp_member;
253
obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
255
if (obj->prop_handler != NULL) {
256
ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
258
if (ret == FAILURE) {
259
std_hnd = zend_get_std_object_handlers();
260
retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC);
263
if (member == &tmp_member) {
269
/* {{{ dom_read_property */
270
zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC)
275
dom_prop_handler *hnd;
276
zend_object_handlers *std_hnd;
279
if (member->type != IS_STRING) {
280
tmp_member = *member;
281
zval_copy_ctor(&tmp_member);
282
convert_to_string(&tmp_member);
283
member = &tmp_member;
287
obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
289
if (obj->prop_handler != NULL) {
290
ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
292
if (ret == SUCCESS) {
293
ret = hnd->read_func(obj, &retval TSRMLS_CC);
294
if (ret == SUCCESS) {
295
/* ensure we're creating a temporary variable */
296
retval->refcount = 0;
298
retval = EG(uninitialized_zval_ptr);
301
std_hnd = zend_get_std_object_handlers();
302
retval = std_hnd->read_property(object, member, type TSRMLS_CC);
305
if (member == &tmp_member) {
312
/* {{{ dom_write_property */
313
void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
317
dom_prop_handler *hnd;
318
zend_object_handlers *std_hnd;
321
if (member->type != IS_STRING) {
322
tmp_member = *member;
323
zval_copy_ctor(&tmp_member);
324
convert_to_string(&tmp_member);
325
member = &tmp_member;
329
obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
331
if (obj->prop_handler != NULL) {
332
ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
334
if (ret == SUCCESS) {
335
hnd->write_func(obj, value TSRMLS_CC);
337
std_hnd = zend_get_std_object_handlers();
338
std_hnd->write_property(object, member, value TSRMLS_CC);
341
if (member == &tmp_member) {
348
void *php_dom_export_node(zval *object TSRMLS_DC)
350
php_libxml_node_object *intern;
351
xmlNodePtr nodep = NULL;
353
intern = (php_libxml_node_object *)zend_object_store_get_object(object TSRMLS_CC);
354
if (intern && intern->node) {
355
nodep = intern->node->node;
361
/* {{{ proto somNode dom_import_simplexml(sxeobject node)
362
Get a simplexml_element object from dom to allow for processing */
363
PHP_FUNCTION(dom_import_simplexml)
365
#ifdef HAVE_SIMPLEXML
368
xmlNodePtr nodep = NULL;
369
php_libxml_node_object *nodeobj;
372
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
376
nodeobj = (php_libxml_node_object *)zend_object_store_get_object(node TSRMLS_CC);
377
nodep = php_libxml_import_node(node TSRMLS_CC);
379
if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
380
DOM_RET_OBJ(rv, (xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
382
php_error(E_WARNING, "Invalid Nodetype to import");
386
php_error(E_WARNING, "SimpleXML support is not enabled");
392
zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC)
394
zend_object_value retval;
397
dom_object *old_object;
398
struct _store_object *obj;
399
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
401
obj = &EG(objects_store).object_buckets[handle].bucket.obj;
403
if (obj->clone == NULL) {
404
php_error(E_ERROR, "Trying to clone an uncloneable object of class %s", Z_OBJCE_P(zobject)->name);
407
obj->clone(obj->object, &new_object TSRMLS_CC);
409
retval.handle = zend_objects_store_put(new_object, obj->dtor, obj->free_storage, obj->clone TSRMLS_CC);
410
intern = (dom_object *) new_object;
411
intern->handle = retval.handle;
412
retval.handlers = Z_OBJ_HT_P(zobject);
414
old_object = (dom_object *) obj->object;
415
zend_objects_clone_members(&intern->std, retval, &old_object->std, intern->handle TSRMLS_CC);
420
zend_object_value dom_objects_ze1_clone_obj(zval *zobject TSRMLS_DC)
422
php_error(E_ERROR, "Cannot clone object of class %s due to 'zend.ze1_compatibility_mode'", Z_OBJCE_P(zobject)->name);
423
/* Return zobject->value.obj just to satisfy compiler */
424
return zobject->value.obj;
427
static zend_function_entry dom_functions[] = {
428
PHP_FE(dom_import_simplexml, NULL)
432
static zend_object_handlers* dom_get_obj_handlers(TSRMLS_D) {
433
if (EG(ze1_compatibility_mode)) {
434
return &dom_ze1_object_handlers;
436
return &dom_object_handlers;
440
zend_module_entry dom_module_entry = {
441
STANDARD_MODULE_HEADER,
449
DOM_API_VERSION, /* Extension versionnumber */
450
STANDARD_MODULE_PROPERTIES
453
#ifdef COMPILE_DL_DOM
457
/* {{{ PHP_MINIT_FUNCTION(dom) */
458
PHP_MINIT_FUNCTION(dom)
462
memcpy(&dom_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
463
dom_object_handlers.read_property = dom_read_property;
464
dom_object_handlers.write_property = dom_write_property;
465
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
466
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
468
memcpy(&dom_ze1_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
469
dom_ze1_object_handlers.read_property = dom_read_property;
470
dom_ze1_object_handlers.write_property = dom_write_property;
471
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
472
dom_ze1_object_handlers.clone_obj = dom_objects_ze1_clone_obj;
474
zend_hash_init(&classes, 0, NULL, NULL, 1);
476
INIT_CLASS_ENTRY(ce, "DOMException", php_dom_domexception_class_functions);
477
dom_domexception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(), NULL TSRMLS_CC);
478
dom_domexception_class_entry->ce_flags |= ZEND_ACC_FINAL;
479
zend_declare_property_long(dom_domexception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
481
REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
483
zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, NULL, 1);
484
dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", dom_domstringlist_length_read, NULL TSRMLS_CC);
485
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers), NULL);
487
REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
489
zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, NULL, 1);
490
dom_register_prop_handler(&dom_namelist_prop_handlers, "length", dom_namelist_length_read, NULL TSRMLS_CC);
491
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers), NULL);
493
REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
495
zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, NULL, 1);
496
dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", dom_domimplementationlist_length_read, NULL TSRMLS_CC);
497
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers), NULL);
499
REGISTER_DOM_CLASS(ce, "DOMImplementationSource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry);
500
REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry);
502
REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry);
504
zend_hash_init(&dom_node_prop_handlers, 0, NULL, NULL, 1);
505
dom_register_prop_handler(&dom_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
506
dom_register_prop_handler(&dom_node_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC);
507
dom_register_prop_handler(&dom_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL TSRMLS_CC);
508
dom_register_prop_handler(&dom_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC);
509
dom_register_prop_handler(&dom_node_prop_handlers, "childNodes", dom_node_child_nodes_read, NULL TSRMLS_CC);
510
dom_register_prop_handler(&dom_node_prop_handlers, "firstChild", dom_node_first_child_read, NULL TSRMLS_CC);
511
dom_register_prop_handler(&dom_node_prop_handlers, "lastChild", dom_node_last_child_read, NULL TSRMLS_CC);
512
dom_register_prop_handler(&dom_node_prop_handlers, "previousSibling", dom_node_previous_sibling_read, NULL TSRMLS_CC);
513
dom_register_prop_handler(&dom_node_prop_handlers, "nextSibling", dom_node_next_sibling_read, NULL TSRMLS_CC);
514
dom_register_prop_handler(&dom_node_prop_handlers, "attributes", dom_node_attributes_read, NULL TSRMLS_CC);
515
dom_register_prop_handler(&dom_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC);
516
dom_register_prop_handler(&dom_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC);
517
dom_register_prop_handler(&dom_node_prop_handlers, "prefix", dom_node_prefix_read, dom_node_prefix_write TSRMLS_CC);
518
dom_register_prop_handler(&dom_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC);
519
dom_register_prop_handler(&dom_node_prop_handlers, "baseURI", dom_node_base_uri_read, NULL TSRMLS_CC);
520
dom_register_prop_handler(&dom_node_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write TSRMLS_CC);
521
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
523
REGISTER_DOM_CLASS(ce, "DOMNameSpaceNode", NULL, NULL, dom_namespace_node_class_entry);
525
zend_hash_init(&dom_namespace_node_prop_handlers, 0, NULL, NULL, 1);
526
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
527
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeValue", dom_node_node_value_read, NULL TSRMLS_CC);
528
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL TSRMLS_CC);
529
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "prefix", dom_node_prefix_read, NULL TSRMLS_CC);
530
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC);
531
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC);
532
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC);
533
dom_register_prop_handler(&dom_namespace_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC);
534
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namespace_node_prop_handlers, sizeof(dom_namespace_node_prop_handlers), NULL);
536
REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry);
537
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
539
REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry);
540
zend_hash_init(&dom_document_prop_handlers, 0, NULL, NULL, 1);
541
dom_register_prop_handler(&dom_document_prop_handlers, "doctype", dom_document_doctype_read, NULL TSRMLS_CC);
542
dom_register_prop_handler(&dom_document_prop_handlers, "implementation", dom_document_implementation_read, NULL TSRMLS_CC);
543
dom_register_prop_handler(&dom_document_prop_handlers, "documentElement", dom_document_document_element_read, NULL TSRMLS_CC);
544
/* actualEncoding currently set as read only alias to encoding
545
dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", dom_document_actual_encoding_read, dom_document_actual_encoding_write TSRMLS_CC); */
546
dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", dom_document_encoding_read, NULL TSRMLS_CC);
547
dom_register_prop_handler(&dom_document_prop_handlers, "encoding", dom_document_encoding_read, dom_document_encoding_write TSRMLS_CC);
548
dom_register_prop_handler(&dom_document_prop_handlers, "standalone", dom_document_standalone_read, dom_document_standalone_write TSRMLS_CC);
549
dom_register_prop_handler(&dom_document_prop_handlers, "version", dom_document_version_read, dom_document_version_write TSRMLS_CC);
550
dom_register_prop_handler(&dom_document_prop_handlers, "strictErrorChecking", dom_document_strict_error_checking_read, dom_document_strict_error_checking_write TSRMLS_CC);
551
dom_register_prop_handler(&dom_document_prop_handlers, "documentURI", dom_document_document_uri_read, dom_document_document_uri_write TSRMLS_CC);
552
dom_register_prop_handler(&dom_document_prop_handlers, "config", dom_document_config_read, NULL TSRMLS_CC);
553
dom_register_prop_handler(&dom_document_prop_handlers, "formatOutput", dom_document_format_output_read, dom_document_format_output_write TSRMLS_CC);
554
dom_register_prop_handler(&dom_document_prop_handlers, "validateOnParse", dom_document_validate_on_parse_read, dom_document_validate_on_parse_write TSRMLS_CC);
555
dom_register_prop_handler(&dom_document_prop_handlers, "resolveExternals", dom_document_resolve_externals_read, dom_document_resolve_externals_write TSRMLS_CC);
556
dom_register_prop_handler(&dom_document_prop_handlers, "preserveWhiteSpace", dom_document_preserve_whitespace_read, dom_document_preserve_whitespace_write TSRMLS_CC);
557
dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", dom_document_substitue_entities_read, dom_document_substitue_entities_write TSRMLS_CC);
559
zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
560
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_document_prop_handlers, sizeof(dom_document_prop_handlers), NULL);
562
INIT_CLASS_ENTRY(ce, "DOMNodeList", php_dom_nodelist_class_functions);
563
ce.create_object = dom_nnodemap_objects_new;
564
dom_nodelist_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
565
dom_nodelist_class_entry->get_iterator = php_dom_get_iterator;
567
zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, NULL, 1);
568
dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", dom_nodelist_length_read, NULL TSRMLS_CC);
569
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_nodelist_prop_handlers, sizeof(dom_nodelist_prop_handlers), NULL);
571
INIT_CLASS_ENTRY(ce, "DOMNamedNodeMap", php_dom_namednodemap_class_functions);
572
ce.create_object = dom_nnodemap_objects_new;
573
dom_namednodemap_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
574
dom_namednodemap_class_entry->get_iterator = php_dom_get_iterator;
576
zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, NULL, 1);
577
dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", dom_namednodemap_length_read, NULL TSRMLS_CC);
578
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers), NULL);
580
REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry);
582
zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, NULL, 1);
583
dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", dom_characterdata_data_read, dom_characterdata_data_write TSRMLS_CC);
584
dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", dom_characterdata_length_read, NULL TSRMLS_CC);
585
zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
586
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers), NULL);
588
REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
590
zend_hash_init(&dom_attr_prop_handlers, 0, NULL, NULL, 1);
591
dom_register_prop_handler(&dom_attr_prop_handlers, "name", dom_attr_name_read, NULL TSRMLS_CC);
592
dom_register_prop_handler(&dom_attr_prop_handlers, "specified", dom_attr_specified_read, NULL TSRMLS_CC);
593
dom_register_prop_handler(&dom_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write TSRMLS_CC);
594
dom_register_prop_handler(&dom_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL TSRMLS_CC);
595
dom_register_prop_handler(&dom_attr_prop_handlers, "schemaTypeInfo", dom_attr_schema_type_info_read, NULL TSRMLS_CC);
596
zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
597
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers), NULL);
599
REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry);
601
zend_hash_init(&dom_element_prop_handlers, 0, NULL, NULL, 1);
602
dom_register_prop_handler(&dom_element_prop_handlers, "tagName", dom_element_tag_name_read, NULL TSRMLS_CC);
603
dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", dom_element_schema_type_info_read, NULL TSRMLS_CC);
604
zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
605
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers), NULL);
607
REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
609
zend_hash_init(&dom_text_prop_handlers, 0, NULL, NULL, 1);
610
dom_register_prop_handler(&dom_text_prop_handlers, "wholeText", dom_text_whole_text_read, NULL TSRMLS_CC);
611
zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
612
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers), NULL);
614
REGISTER_DOM_CLASS(ce, "DOMComment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry);
615
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
617
REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
619
zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, NULL, 1);
620
dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", dom_typeinfo_type_name_read, NULL TSRMLS_CC);
621
dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", dom_typeinfo_type_namespace_read, NULL TSRMLS_CC);
622
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_typeinfo_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
624
REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry);
625
REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry);
627
zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, NULL, 1);
628
dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", dom_domerror_severity_read, NULL TSRMLS_CC);
629
dom_register_prop_handler(&dom_domerror_prop_handlers, "message", dom_domerror_message_read, NULL TSRMLS_CC);
630
dom_register_prop_handler(&dom_domerror_prop_handlers, "type", dom_domerror_type_read, NULL TSRMLS_CC);
631
dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", dom_domerror_related_exception_read, NULL TSRMLS_CC);
632
dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", dom_domerror_related_data_read, NULL TSRMLS_CC);
633
dom_register_prop_handler(&dom_domerror_prop_handlers, "location", dom_domerror_location_read, NULL TSRMLS_CC);
634
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domerror_prop_handlers, sizeof(dom_domerror_prop_handlers), NULL);
636
REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry);
637
REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry);
639
zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, NULL, 1);
640
dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", dom_domlocator_line_number_read, NULL TSRMLS_CC);
641
dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", dom_domlocator_column_number_read, NULL TSRMLS_CC);
642
dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", dom_domlocator_offset_read, NULL TSRMLS_CC);
643
dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", dom_domlocator_related_node_read, NULL TSRMLS_CC);
644
dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", dom_domlocator_uri_read, NULL TSRMLS_CC);
645
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domlocator_prop_handlers, sizeof(dom_domlocator_prop_handlers), NULL);
647
REGISTER_DOM_CLASS(ce, "DOMConfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry);
648
REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
649
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
651
REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
653
zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, NULL, 1);
654
dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", dom_documenttype_name_read, NULL TSRMLS_CC);
655
dom_register_prop_handler(&dom_documenttype_prop_handlers, "entities", dom_documenttype_entities_read, NULL TSRMLS_CC);
656
dom_register_prop_handler(&dom_documenttype_prop_handlers, "notations", dom_documenttype_notations_read, NULL TSRMLS_CC);
657
dom_register_prop_handler(&dom_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL TSRMLS_CC);
658
dom_register_prop_handler(&dom_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL TSRMLS_CC);
659
dom_register_prop_handler(&dom_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL TSRMLS_CC);
660
zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
661
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
663
REGISTER_DOM_CLASS(ce, "DOMNotation", NULL, php_dom_notation_class_functions, dom_notation_class_entry);
665
zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1);
666
dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC);
667
dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC);
668
/* Notation nodes are special */
669
dom_register_prop_handler(&dom_notation_prop_handlers, "nodeName", dom_node_node_name_read, NULL TSRMLS_CC);
670
dom_register_prop_handler(&dom_notation_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write TSRMLS_CC);
671
dom_register_prop_handler(&dom_notation_prop_handlers, "attributes", dom_node_attributes_read, NULL TSRMLS_CC);
672
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL);
674
REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry);
676
zend_hash_init(&dom_entity_prop_handlers, 0, NULL, NULL, 1);
677
dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", dom_entity_public_id_read, NULL TSRMLS_CC);
678
dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", dom_entity_system_id_read, NULL TSRMLS_CC);
679
dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", dom_entity_notation_name_read, NULL TSRMLS_CC);
680
dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", dom_entity_actual_encoding_read, dom_entity_actual_encoding_write TSRMLS_CC);
681
dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", dom_entity_encoding_read, dom_entity_encoding_write TSRMLS_CC);
682
dom_register_prop_handler(&dom_entity_prop_handlers, "version", dom_entity_version_read, dom_entity_version_write TSRMLS_CC);
683
zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
685
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
687
REGISTER_DOM_CLASS(ce, "DOMEntityReference", dom_node_class_entry, php_dom_entityreference_class_functions, dom_entityreference_class_entry);
688
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
690
REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
692
zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, NULL, 1);
693
dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", dom_processinginstruction_target_read, NULL TSRMLS_CC);
694
dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", dom_processinginstruction_data_read, dom_processinginstruction_data_write TSRMLS_CC);
695
zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0);
696
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_processinginstruction_prop_handlers, sizeof(dom_processinginstruction_prop_handlers), NULL);
698
REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
700
#if defined(LIBXML_XPATH_ENABLED)
701
INIT_CLASS_ENTRY(ce, "DOMXPath", php_dom_xpath_class_functions);
702
ce.create_object = dom_xpath_objects_new;
703
dom_xpath_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
705
zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, NULL, 1);
706
dom_register_prop_handler(&dom_xpath_prop_handlers, "document", dom_xpath_document_read, NULL TSRMLS_CC);
707
zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_xpath_prop_handlers, sizeof(dom_xpath_prop_handlers), NULL);
710
REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE", XML_ELEMENT_NODE, CONST_CS | CONST_PERSISTENT);
711
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NODE", XML_ATTRIBUTE_NODE, CONST_CS | CONST_PERSISTENT);
712
REGISTER_LONG_CONSTANT("XML_TEXT_NODE", XML_TEXT_NODE, CONST_CS | CONST_PERSISTENT);
713
REGISTER_LONG_CONSTANT("XML_CDATA_SECTION_NODE", XML_CDATA_SECTION_NODE, CONST_CS | CONST_PERSISTENT);
714
REGISTER_LONG_CONSTANT("XML_ENTITY_REF_NODE", XML_ENTITY_REF_NODE, CONST_CS | CONST_PERSISTENT);
715
REGISTER_LONG_CONSTANT("XML_ENTITY_NODE", XML_ENTITY_NODE, CONST_CS | CONST_PERSISTENT);
716
REGISTER_LONG_CONSTANT("XML_PI_NODE", XML_PI_NODE, CONST_CS | CONST_PERSISTENT);
717
REGISTER_LONG_CONSTANT("XML_COMMENT_NODE", XML_COMMENT_NODE, CONST_CS | CONST_PERSISTENT);
718
REGISTER_LONG_CONSTANT("XML_DOCUMENT_NODE", XML_DOCUMENT_NODE, CONST_CS | CONST_PERSISTENT);
719
REGISTER_LONG_CONSTANT("XML_DOCUMENT_TYPE_NODE", XML_DOCUMENT_TYPE_NODE, CONST_CS | CONST_PERSISTENT);
720
REGISTER_LONG_CONSTANT("XML_DOCUMENT_FRAG_NODE", XML_DOCUMENT_FRAG_NODE, CONST_CS | CONST_PERSISTENT);
721
REGISTER_LONG_CONSTANT("XML_NOTATION_NODE", XML_NOTATION_NODE, CONST_CS | CONST_PERSISTENT);
722
REGISTER_LONG_CONSTANT("XML_HTML_DOCUMENT_NODE", XML_HTML_DOCUMENT_NODE, CONST_CS | CONST_PERSISTENT);
723
REGISTER_LONG_CONSTANT("XML_DTD_NODE", XML_DTD_NODE, CONST_CS | CONST_PERSISTENT);
724
REGISTER_LONG_CONSTANT("XML_ELEMENT_DECL_NODE", XML_ELEMENT_DECL, CONST_CS | CONST_PERSISTENT);
725
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_DECL_NODE", XML_ATTRIBUTE_DECL, CONST_CS | CONST_PERSISTENT);
726
REGISTER_LONG_CONSTANT("XML_ENTITY_DECL_NODE", XML_ENTITY_DECL, CONST_CS | CONST_PERSISTENT);
727
REGISTER_LONG_CONSTANT("XML_NAMESPACE_DECL_NODE", XML_NAMESPACE_DECL, CONST_CS | CONST_PERSISTENT);
728
#ifdef XML_GLOBAL_NAMESPACE
729
REGISTER_LONG_CONSTANT("XML_GLOBAL_NAMESPACE", XML_GLOBAL_NAMESPACE, CONST_CS | CONST_PERSISTENT);
731
REGISTER_LONG_CONSTANT("XML_LOCAL_NAMESPACE", XML_LOCAL_NAMESPACE, CONST_CS | CONST_PERSISTENT);
732
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_CDATA", XML_ATTRIBUTE_CDATA, CONST_CS | CONST_PERSISTENT);
733
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ID", XML_ATTRIBUTE_ID, CONST_CS | CONST_PERSISTENT);
734
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREF", XML_ATTRIBUTE_IDREF, CONST_CS | CONST_PERSISTENT);
735
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_IDREFS", XML_ATTRIBUTE_IDREFS, CONST_CS | CONST_PERSISTENT);
736
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENTITY", XML_ATTRIBUTE_ENTITIES, CONST_CS | CONST_PERSISTENT);
737
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKEN", XML_ATTRIBUTE_NMTOKEN, CONST_CS | CONST_PERSISTENT);
738
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NMTOKENS", XML_ATTRIBUTE_NMTOKENS, CONST_CS | CONST_PERSISTENT);
739
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENUMERATION", XML_ATTRIBUTE_ENUMERATION, CONST_CS | CONST_PERSISTENT);
740
REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NOTATION", XML_ATTRIBUTE_NOTATION, CONST_CS | CONST_PERSISTENT);
742
/* DOMException Codes */
743
REGISTER_LONG_CONSTANT("DOM_PHP_ERR", PHP_ERR, CONST_CS | CONST_PERSISTENT);
744
REGISTER_LONG_CONSTANT("DOM_INDEX_SIZE_ERR", INDEX_SIZE_ERR, CONST_CS | CONST_PERSISTENT);
745
REGISTER_LONG_CONSTANT("DOMSTRING_SIZE_ERR", DOMSTRING_SIZE_ERR, CONST_CS | CONST_PERSISTENT);
746
REGISTER_LONG_CONSTANT("DOM_HIERARCHY_REQUEST_ERR", HIERARCHY_REQUEST_ERR, CONST_CS | CONST_PERSISTENT);
747
REGISTER_LONG_CONSTANT("DOM_WRONG_DOCUMENT_ERR", WRONG_DOCUMENT_ERR, CONST_CS | CONST_PERSISTENT);
748
REGISTER_LONG_CONSTANT("DOM_INVALID_CHARACTER_ERR", INVALID_CHARACTER_ERR, CONST_CS | CONST_PERSISTENT);
749
REGISTER_LONG_CONSTANT("DOM_NO_DATA_ALLOWED_ERR", NO_DATA_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
750
REGISTER_LONG_CONSTANT("DOM_NO_MODIFICATION_ALLOWED_ERR", NO_MODIFICATION_ALLOWED_ERR, CONST_CS | CONST_PERSISTENT);
751
REGISTER_LONG_CONSTANT("DOM_NOT_FOUND_ERR", NOT_FOUND_ERR, CONST_CS | CONST_PERSISTENT);
752
REGISTER_LONG_CONSTANT("DOM_NOT_SUPPORTED_ERR", NOT_SUPPORTED_ERR, CONST_CS | CONST_PERSISTENT);
753
REGISTER_LONG_CONSTANT("DOM_INUSE_ATTRIBUTE_ERR", INUSE_ATTRIBUTE_ERR, CONST_CS | CONST_PERSISTENT);
754
REGISTER_LONG_CONSTANT("DOM_INVALID_STATE_ERR", INVALID_STATE_ERR, CONST_CS | CONST_PERSISTENT);
755
REGISTER_LONG_CONSTANT("DOM_SYNTAX_ERR", SYNTAX_ERR, CONST_CS | CONST_PERSISTENT);
756
REGISTER_LONG_CONSTANT("DOM_INVALID_MODIFICATION_ERR", INVALID_MODIFICATION_ERR, CONST_CS | CONST_PERSISTENT);
757
REGISTER_LONG_CONSTANT("DOM_NAMESPACE_ERR", NAMESPACE_ERR, CONST_CS | CONST_PERSISTENT);
758
REGISTER_LONG_CONSTANT("DOM_INVALID_ACCESS_ERR", INVALID_ACCESS_ERR, CONST_CS | CONST_PERSISTENT);
759
REGISTER_LONG_CONSTANT("DOM_VALIDATION_ERR", VALIDATION_ERR, CONST_CS | CONST_PERSISTENT);
761
php_libxml_register_export(dom_node_class_entry, php_dom_export_node);
768
PHP_MINFO_FUNCTION(dom)
770
php_info_print_table_start();
771
php_info_print_table_row(2, "DOM/XML", "enabled");
772
php_info_print_table_row(2, "DOM/XML API Version", DOM_API_VERSION);
773
php_info_print_table_row(2, "libxml Version", LIBXML_DOTTED_VERSION);
774
#if defined(LIBXML_HTML_ENABLED)
775
php_info_print_table_row(2, "HTML Support", "enabled");
777
#if defined(LIBXML_XPATH_ENABLED)
778
php_info_print_table_row(2, "XPath Support", "enabled");
780
#if defined(LIBXML_XPTR_ENABLED)
781
php_info_print_table_row(2, "XPointer Support", "enabled");
783
#ifdef LIBXML_SCHEMAS_ENABLED
784
php_info_print_table_row(2, "Schema Support", "enabled");
785
php_info_print_table_row(2, "RelaxNG Support", "enabled");
787
php_info_print_table_end();
791
PHP_MSHUTDOWN_FUNCTION(dom)
793
zend_hash_destroy(&dom_domstringlist_prop_handlers);
794
zend_hash_destroy(&dom_namelist_prop_handlers);
795
zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
796
zend_hash_destroy(&dom_document_prop_handlers);
797
zend_hash_destroy(&dom_node_prop_handlers);
798
zend_hash_destroy(&dom_namespace_node_prop_handlers);
799
zend_hash_destroy(&dom_nodelist_prop_handlers);
800
zend_hash_destroy(&dom_namednodemap_prop_handlers);
801
zend_hash_destroy(&dom_characterdata_prop_handlers);
802
zend_hash_destroy(&dom_attr_prop_handlers);
803
zend_hash_destroy(&dom_element_prop_handlers);
804
zend_hash_destroy(&dom_text_prop_handlers);
805
zend_hash_destroy(&dom_typeinfo_prop_handlers);
806
zend_hash_destroy(&dom_domerror_prop_handlers);
807
zend_hash_destroy(&dom_domlocator_prop_handlers);
808
zend_hash_destroy(&dom_documenttype_prop_handlers);
809
zend_hash_destroy(&dom_notation_prop_handlers);
810
zend_hash_destroy(&dom_entity_prop_handlers);
811
zend_hash_destroy(&dom_processinginstruction_prop_handlers);
812
#if defined(LIBXML_XPATH_ENABLED)
813
zend_hash_destroy(&dom_xpath_prop_handlers);
815
zend_hash_destroy(&classes);
817
/* If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and
818
uncomment the following line, this will tell you the amount of not freed memory
819
and the total used memory into apaches error_log */
820
/* xmlMemoryDump();*/
825
/* {{{ node_list_unlink */
826
void node_list_unlink(xmlNodePtr node TSRMLS_DC)
830
while (node != NULL) {
832
wrapper = php_dom_object_get_data(node);
834
if (wrapper != NULL ) {
837
node_list_unlink(node->children TSRMLS_CC);
839
switch (node->type) {
840
case XML_ATTRIBUTE_DECL:
842
case XML_DOCUMENT_TYPE_NODE:
843
case XML_ENTITY_DECL:
844
case XML_ATTRIBUTE_NODE:
847
node_list_unlink((xmlNodePtr) node->properties TSRMLS_CC);
855
/* }}} end node_list_unlink */
857
#if defined(LIBXML_XPATH_ENABLED)
858
/* {{{ dom_xpath_objects_free_storage */
859
void dom_xpath_objects_free_storage(void *object TSRMLS_DC)
861
dom_object *intern = (dom_object *)object;
863
zend_hash_destroy(intern->std.properties);
864
FREE_HASHTABLE(intern->std.properties);
866
if (intern->ptr != NULL) {
867
xmlXPathFreeContext((xmlXPathContextPtr) intern->ptr);
868
php_libxml_decrement_doc_ref((php_libxml_node_object *) intern TSRMLS_CC);
877
/* {{{ dom_objects_free_storage */
878
void dom_objects_free_storage(void *object TSRMLS_DC)
880
dom_object *intern = (dom_object *)object;
883
zend_hash_destroy(intern->std.properties);
884
FREE_HASHTABLE(intern->std.properties);
886
if (intern->ptr != NULL && ((php_libxml_node_ptr *)intern->ptr)->node != NULL) {
887
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) {
888
php_libxml_node_decrement_resource((php_libxml_node_object *) intern TSRMLS_CC);
890
php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
891
retcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
900
void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns TSRMLS_DC)
902
dom_nnodemap_object *mapptr;
903
zval *baseobj = NULL;
905
mapptr = (dom_nnodemap_object *)intern->ptr;
907
MAKE_STD_ZVAL(baseobj);
908
baseobj->type = IS_OBJECT;
910
baseobj->value.obj.handle = basenode->handle;
911
baseobj->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C);
912
zval_copy_ctor(baseobj);
914
mapptr->baseobjptr = baseobj;
915
mapptr->baseobj = basenode;
916
mapptr->nodetype = ntype;
918
mapptr->local = local;
923
static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy TSRMLS_DC)
925
zend_class_entry *base_class;
929
intern = emalloc(sizeof(dom_object));
930
intern->std.ce = class_type;
931
intern->std.in_get = 0;
932
intern->std.in_set = 0;
934
intern->prop_handler = NULL;
935
intern->document = NULL;
937
base_class = class_type;
938
while(base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) {
939
base_class = base_class->parent;
942
zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler);
944
ALLOC_HASHTABLE(intern->std.properties);
945
zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
947
zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
953
/* {{{ dom_objects_clone */
954
void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
956
dom_object *intern = (dom_object *) object;
959
xmlNodePtr cloned_node;
961
clone = dom_objects_set_class(intern->std.ce, 0 TSRMLS_CC);
963
if (instanceof_function(intern->std.ce, dom_node_class_entry TSRMLS_CC)) {
964
node = (xmlNodePtr)dom_object_get_node((dom_object *) object);
966
cloned_node = xmlDocCopyNode(node, node->doc, 1);
967
if (cloned_node != NULL) {
968
/* If we cloned a document then we must create new doc proxy */
969
if (cloned_node->doc == node->doc) {
970
clone->document = intern->document;
972
php_libxml_increment_doc_ref((php_libxml_node_object *)clone, cloned_node->doc TSRMLS_CC);
973
php_libxml_increment_node_ptr((php_libxml_node_object *)clone, cloned_node, (void *)clone TSRMLS_CC);
979
*object_clone = (void *) clone;
983
/* {{{ dom_objects_new */
984
zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
986
zend_object_value retval;
989
intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
991
retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t)dom_objects_free_storage, dom_objects_clone TSRMLS_CC);
992
intern->handle = retval.handle;
993
retval.handlers = dom_get_obj_handlers(TSRMLS_C);
999
#if defined(LIBXML_XPATH_ENABLED)
1000
/* {{{ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC) */
1001
zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC)
1003
zend_object_value retval;
1006
intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
1008
retval.handle = zend_objects_store_put(intern, NULL, (zend_objects_free_object_storage_t)dom_xpath_objects_free_storage, dom_objects_clone TSRMLS_CC);
1009
intern->handle = retval.handle;
1010
retval.handlers = dom_get_obj_handlers(TSRMLS_C);
1017
static void dom_nnodemap_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
1021
dom_nnodemap_object *objmap;
1023
intern = (dom_object *)object;
1024
objmap = (dom_nnodemap_object *)intern->ptr;
1027
if (objmap->local) {
1028
xmlFree(objmap->local);
1031
xmlFree(objmap->ns);
1033
if (objmap->baseobjptr) {
1034
baseobj = objmap->baseobjptr;
1035
zval_ptr_dtor((zval **)&baseobj);
1044
void dom_nnodemap_objects_free_storage(void *object TSRMLS_DC)
1046
dom_object *intern = (dom_object *)object;
1048
php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
1050
zend_hash_destroy(intern->std.properties);
1051
FREE_HASHTABLE(intern->std.properties);
1056
zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_DC)
1058
zend_object_value retval;
1060
dom_nnodemap_object *objmap;
1062
intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
1063
intern->ptr = emalloc(sizeof(dom_nnodemap_object));
1064
objmap = (dom_nnodemap_object *)intern->ptr;
1065
objmap->baseobj = NULL;
1066
objmap->baseobjptr = NULL;
1067
objmap->nodetype = 0;
1069
objmap->local = NULL;
1072
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);
1073
intern->handle = retval.handle;
1074
retval.handlers = dom_get_obj_handlers(TSRMLS_C);
1079
void php_dom_create_interator(zval *return_value, int ce_type TSRMLS_DC)
1081
zend_class_entry *ce;
1083
if (ce_type == DOM_NAMEDNODEMAP) {
1084
ce = dom_namednodemap_class_entry;
1086
ce = dom_nodelist_class_entry;
1089
object_init_ex(return_value, ce);
1092
/* {{{ php_dom_create_object */
1093
zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval *return_value, dom_object *domobj TSRMLS_DC)
1096
zend_class_entry *ce;
1102
ALLOC_ZVAL(wrapper);
1107
if ((intern = (dom_object *) php_dom_object_get_data((void *) obj))) {
1108
return_value->type = IS_OBJECT;
1109
return_value->is_ref = 1;
1110
return_value->value.obj.handle = intern->handle;
1111
return_value->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C);
1112
zval_copy_ctor(return_value);
1114
return return_value;
1117
wrapper = return_value;
1119
switch (obj->type) {
1120
case XML_DOCUMENT_NODE:
1121
case XML_HTML_DOCUMENT_NODE:
1123
ce = dom_document_class_entry;
1127
case XML_DOCUMENT_TYPE_NODE:
1129
ce = dom_documenttype_class_entry;
1132
case XML_ELEMENT_NODE:
1134
ce = dom_element_class_entry;
1137
case XML_ATTRIBUTE_NODE:
1139
ce = dom_attr_class_entry;
1144
ce = dom_text_class_entry;
1147
case XML_COMMENT_NODE:
1149
ce = dom_comment_class_entry;
1154
ce = dom_processinginstruction_class_entry;
1157
case XML_ENTITY_REF_NODE:
1159
ce = dom_entityreference_class_entry;
1162
case XML_ENTITY_DECL:
1163
case XML_ELEMENT_DECL:
1165
ce = dom_entity_class_entry;
1168
case XML_CDATA_SECTION_NODE:
1170
ce = dom_cdatasection_class_entry;
1173
case XML_DOCUMENT_FRAG_NODE:
1175
ce = dom_documentfragment_class_entry;
1178
case XML_NOTATION_NODE:
1180
ce = dom_notation_class_entry;
1183
case XML_NAMESPACE_DECL:
1185
ce = dom_namespace_node_class_entry;
1189
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d\n", Z_TYPE_P(obj));
1194
object_init_ex(wrapper, ce);
1196
intern = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
1197
if (obj->doc != NULL) {
1198
if (domobj != NULL) {
1199
intern->document = domobj->document;
1201
php_libxml_increment_doc_ref((php_libxml_node_object *)intern, obj->doc TSRMLS_CC);
1204
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, obj, (void *)intern TSRMLS_CC);
1207
/* }}} end php_domobject_new */
1210
void php_dom_create_implementation(zval **retval TSRMLS_DC) {
1211
object_init_ex(*retval, dom_domimplementation_class_entry);
1214
/* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */
1215
int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child)
1219
if (parent == NULL || child == NULL || child->doc != parent->doc) {
1226
if (nodep == child) {
1229
nodep = nodep->parent;
1234
/* }}} end dom_hierarchy */
1236
/* {{{ dom_has_feature(char *feature, char *version) */
1237
int dom_has_feature(char *feature, char *version)
1241
if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, ""))) {
1242
if ((!strcasecmp(feature, "Core") && !strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
1248
/* }}} end dom_has_feature */
1250
xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index)
1252
xmlNodePtr ret = NULL;
1254
while (nodep != NULL && (*cur <= index || index == -1)) {
1255
if (nodep->type == XML_ELEMENT_NODE) {
1256
if (xmlStrEqual(nodep->name, local) || xmlStrEqual("*", local)) {
1257
if (ns == NULL || (nodep->ns != NULL && (xmlStrEqual(nodep->ns->href, ns) || xmlStrEqual("*", ns)))) {
1258
if (*cur == index) {
1265
ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
1270
nodep = nodep->next;
1274
/* }}} end dom_element_get_elements_by_tag_name_ns_raw */
1277
/* {{{ void dom_normalize (xmlNodePtr nodep TSRMLS_DC) */
1278
void dom_normalize (xmlNodePtr nodep TSRMLS_DC)
1280
xmlNodePtr child, nextp, newnextp;
1282
xmlChar *strContent;
1284
child = nodep->children;
1285
while(child != NULL) {
1286
switch (child->type) {
1288
nextp = child->next;
1289
while (nextp != NULL) {
1290
if (nextp->type == XML_TEXT_NODE) {
1291
newnextp = nextp->next;
1292
strContent = xmlNodeGetContent(nextp);
1293
xmlNodeAddContent(child, strContent);
1294
xmlFree(strContent);
1295
xmlUnlinkNode(nextp);
1296
php_libxml_node_free_resource(nextp TSRMLS_CC);
1303
case XML_ELEMENT_NODE:
1304
dom_normalize (child TSRMLS_CC);
1305
attr = child->properties;
1306
while (attr != NULL) {
1307
dom_normalize((xmlNodePtr) attr TSRMLS_CC);
1311
case XML_ATTRIBUTE_NODE:
1312
dom_normalize (child TSRMLS_CC);
1317
child = child->next;
1320
/* }}} end dom_normalize */
1323
/* {{{ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) */
1324
void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
1330
if (doc->oldNs == NULL) {
1331
doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
1332
if (doc->oldNs == NULL) {
1335
memset(doc->oldNs, 0, sizeof(xmlNs));
1336
doc->oldNs->type = XML_LOCAL_NAMESPACE;
1337
doc->oldNs->href = xmlStrdup(XML_XML_NAMESPACE);
1338
doc->oldNs->prefix = xmlStrdup((const xmlChar *)"xml");
1342
while (cur->next != NULL) {
1347
/* }}} end dom_set_old_ns */
1350
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
1352
NAMESPACE_ERR: Raised if
1354
1. the qualifiedName is a malformed qualified name
1355
2. the qualifiedName has a prefix and the namespaceURI is null
1358
/* {{{ int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) */
1359
int dom_check_qname(char *qname, char **localname, char **prefix, int uri_len, int name_len) {
1360
if (name_len == 0) {
1361
return NAMESPACE_ERR;
1364
*localname = xmlSplitQName2(qname, (xmlChar **) prefix);
1365
if (*localname == NULL) {
1366
*localname = xmlStrdup(qname);
1367
if (*prefix == NULL && uri_len == 0) {
1373
if (xmlValidateQName((xmlChar *) qname, 0) != 0) {
1374
return NAMESPACE_ERR;
1378
if (*prefix != NULL && uri_len == 0) {
1379
return NAMESPACE_ERR;
1387
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
1389
NAMESPACE_ERR: Raised if
1391
3. the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace" [XML Namespaces]
1392
4. the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/"
1393
5. the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
1396
/* {{{ xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) */
1397
xmlNsPtr dom_get_ns(xmlNodePtr nodep, char *uri, int *errorcode, char *prefix) {
1398
xmlNsPtr nsptr = NULL;
1402
if (! ((prefix && !strcmp (prefix, "xml" ) && strcmp(uri, XML_XML_NAMESPACE)) ||
1403
(prefix && !strcmp (prefix, "xmlns") && strcmp(uri, DOM_XMLNS_NAMESPACE)) ||
1404
(prefix && !strcmp(uri, DOM_XMLNS_NAMESPACE) && strcmp (prefix, "xmlns")))) {
1405
nsptr = xmlNewNs(nodep, uri, prefix);
1408
if (nsptr == NULL) {
1409
*errorcode = NAMESPACE_ERR;
1415
/* }}} end dom_get_ns */
1417
/* {{{ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) */
1418
xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
1424
if (localName == NULL || xmlStrEqual(localName, "")) {
1426
while (cur != NULL) {
1427
if (cur->prefix == NULL && cur->href != NULL) {
1435
while (cur != NULL) {
1436
if (cur->prefix != NULL && xmlStrEqual(localName, cur->prefix)) {
1445
/* }}} end dom_get_nsdecl */
1447
#endif /* HAVE_DOM */
1454
* vim600: noet sw=4 ts=4 fdm=marker
1455
* vim<600: noet sw=4 ts=4