~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/dom/php_dom.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | PHP Version 5                                                        |
 
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
   +----------------------------------------------------------------------+
 
19
*/
 
20
 
 
21
/* $Id: php_dom.c,v 1.60.2.8 2005/06/22 19:58:33 rrichards Exp $ */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "php.h"
 
28
#if HAVE_LIBXML && HAVE_DOM
 
29
#include "ext/standard/php_rand.h"
 
30
#include "php_dom.h"
 
31
#include "dom_properties.h"
 
32
 
 
33
#include "ext/standard/info.h"
 
34
#define PHP_XPATH 1
 
35
#define PHP_XPTR 2
 
36
 
 
37
zend_class_entry *dom_node_class_entry;
 
38
zend_class_entry *dom_domexception_class_entry;
 
39
zend_class_entry *dom_domstringlist_class_entry;
 
40
zend_class_entry *dom_namelist_class_entry;
 
41
zend_class_entry *dom_domimplementationlist_class_entry;
 
42
zend_class_entry *dom_domimplementationsource_class_entry;
 
43
zend_class_entry *dom_domimplementation_class_entry;
 
44
zend_class_entry *dom_documentfragment_class_entry;
 
45
zend_class_entry *dom_document_class_entry;
 
46
zend_class_entry *dom_nodelist_class_entry;
 
47
zend_class_entry *dom_namednodemap_class_entry;
 
48
zend_class_entry *dom_characterdata_class_entry;
 
49
zend_class_entry *dom_attr_class_entry;
 
50
zend_class_entry *dom_element_class_entry;
 
51
zend_class_entry *dom_text_class_entry;
 
52
zend_class_entry *dom_comment_class_entry;
 
53
zend_class_entry *dom_typeinfo_class_entry;
 
54
zend_class_entry *dom_userdatahandler_class_entry;
 
55
zend_class_entry *dom_domerror_class_entry;
 
56
zend_class_entry *dom_domerrorhandler_class_entry;
 
57
zend_class_entry *dom_domlocator_class_entry;
 
58
zend_class_entry *dom_domconfiguration_class_entry;
 
59
zend_class_entry *dom_cdatasection_class_entry;
 
60
zend_class_entry *dom_documenttype_class_entry;
 
61
zend_class_entry *dom_notation_class_entry;
 
62
zend_class_entry *dom_entity_class_entry;
 
63
zend_class_entry *dom_entityreference_class_entry;
 
64
zend_class_entry *dom_processinginstruction_class_entry;
 
65
zend_class_entry *dom_string_extend_class_entry;
 
66
#if defined(LIBXML_XPATH_ENABLED)
 
67
zend_class_entry *dom_xpath_class_entry;
 
68
#endif
 
69
zend_class_entry *dom_namespace_node_class_entry;
 
70
 
 
71
zend_object_handlers dom_object_handlers;
 
72
zend_object_handlers dom_ze1_object_handlers;
 
73
 
 
74
static HashTable classes;
 
75
 
 
76
static HashTable dom_domstringlist_prop_handlers;
 
77
static HashTable dom_namelist_prop_handlers;
 
78
static HashTable dom_domimplementationlist_prop_handlers;
 
79
static HashTable dom_document_prop_handlers;
 
80
static HashTable dom_node_prop_handlers;
 
81
static HashTable dom_nodelist_prop_handlers;
 
82
static HashTable dom_namednodemap_prop_handlers;
 
83
static HashTable dom_characterdata_prop_handlers;
 
84
static HashTable dom_attr_prop_handlers;
 
85
static HashTable dom_element_prop_handlers;
 
86
static HashTable dom_text_prop_handlers;
 
87
static HashTable dom_typeinfo_prop_handlers;
 
88
static HashTable dom_domerror_prop_handlers;
 
89
static HashTable dom_domlocator_prop_handlers;
 
90
static HashTable dom_documenttype_prop_handlers;
 
91
static HashTable dom_notation_prop_handlers;
 
92
static HashTable dom_entity_prop_handlers;
 
93
static HashTable dom_processinginstruction_prop_handlers;
 
94
static HashTable dom_namespace_node_prop_handlers;
 
95
#if defined(LIBXML_XPATH_ENABLED)
 
96
static HashTable dom_xpath_prop_handlers;
 
97
#endif
 
98
 
 
99
typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC);
 
100
typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC);
 
101
 
 
102
typedef struct _dom_prop_handler {
 
103
        dom_read_t read_func;
 
104
        dom_write_t write_func;
 
105
} dom_prop_handler;
 
106
 
 
107
/* {{{ int dom_node_is_read_only(xmlNodePtr node) */
 
108
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:
 
114
                case XML_DTD_NODE:
 
115
                case XML_ELEMENT_DECL:
 
116
                case XML_ATTRIBUTE_DECL:
 
117
                case XML_ENTITY_DECL:
 
118
                case XML_NAMESPACE_DECL:
 
119
                        return SUCCESS;
 
120
                        break;
 
121
                default:
 
122
                        if (node->doc == NULL) {
 
123
                                return SUCCESS;
 
124
                        } else {
 
125
                                return FAILURE;
 
126
                        }
 
127
        }
 
128
}
 
129
/* }}} end dom_node_is_read_only */
 
130
 
 
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:
 
135
                case XML_DTD_NODE:
 
136
                case XML_PI_NODE:
 
137
                case XML_COMMENT_NODE:
 
138
                case XML_TEXT_NODE:
 
139
                case XML_CDATA_SECTION_NODE:
 
140
                case XML_NOTATION_NODE:
 
141
                        return FAILURE;
 
142
                        break;
 
143
                default:
 
144
                        return SUCCESS;
 
145
        }
 
146
}
 
147
/* }}} end dom_node_children_valid */
 
148
 
 
149
/* {{{ dom_get_doc_props() */
 
150
dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
 
151
{
 
152
        dom_doc_props *doc_props;
 
153
 
 
154
        if (document && document->doc_props) {
 
155
                return document->doc_props;
 
156
        } else {
 
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;
 
164
                if (document) {
 
165
                        document->doc_props = doc_props;
 
166
                }
 
167
                return doc_props;
 
168
        }
 
169
}
 
170
/* }}} */
 
171
 
 
172
/* {{{ dom_get_strict_error() */
 
173
int dom_get_strict_error(php_libxml_ref_obj *document) {
 
174
        int stricterror;
 
175
        dom_doc_props *doc_props;
 
176
 
 
177
        doc_props = dom_get_doc_props(document);
 
178
        stricterror = doc_props->stricterror;
 
179
        if (document == NULL) {
 
180
                efree(doc_props);
 
181
        }
 
182
 
 
183
        return stricterror;
 
184
}
 
185
/* }}} */
 
186
 
 
187
/* {{{ xmlNodePtr dom_object_get_node(dom_object *obj) */
 
188
xmlNodePtr dom_object_get_node(dom_object *obj)
 
189
{
 
190
        if (obj->ptr != NULL) {
 
191
                return ((php_libxml_node_ptr *)obj->ptr)->node;
 
192
        } else {
 
193
                return NULL;
 
194
        }
 
195
}
 
196
/* }}} end dom_object_get_node */
 
197
 
 
198
/* {{{ dom_object *php_dom_object_get_data(xmlNodePtr obj) */
 
199
dom_object *php_dom_object_get_data(xmlNodePtr obj)
 
200
{
 
201
        if (obj->_private != NULL) {
 
202
                return (dom_object *) ((php_libxml_node_ptr *) obj->_private)->_private;
 
203
        } else {
 
204
                return NULL;
 
205
        }
 
206
}
 
207
/* }}} end php_dom_object_get_data */
 
208
 
 
209
/* {{{ dom_read_na */
 
210
static int dom_read_na(dom_object *obj, zval **retval TSRMLS_DC)
 
211
{
 
212
        *retval = NULL;
 
213
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
 
214
        return FAILURE;
 
215
}
 
216
/* }}} */
 
217
 
 
218
/* {{{ dom_write_na */
 
219
static int dom_write_na(dom_object *obj, zval *newval TSRMLS_DC)
 
220
{
 
221
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
 
222
        return FAILURE;
 
223
}
 
224
/* }}} */
 
225
 
 
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)
 
228
{
 
229
        dom_prop_handler hnd;
 
230
        
 
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);
 
234
}
 
235
/* }}} */
 
236
 
 
237
static zval **dom_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC)
 
238
{
 
239
        dom_object *obj;
 
240
        zval tmp_member;
 
241
        zval **retval = NULL;
 
242
        dom_prop_handler *hnd;
 
243
        zend_object_handlers *std_hnd;
 
244
        int ret = FAILURE;
 
245
 
 
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;
 
251
        }
 
252
 
 
253
        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
 
254
 
 
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);
 
257
        }
 
258
        if (ret == FAILURE) {
 
259
                std_hnd = zend_get_std_object_handlers();
 
260
                retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC);
 
261
        }
 
262
 
 
263
        if (member == &tmp_member) {
 
264
                zval_dtor(member);
 
265
        }
 
266
        return retval;
 
267
}
 
268
 
 
269
/* {{{ dom_read_property */
 
270
zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC)
 
271
{
 
272
        dom_object *obj;
 
273
        zval tmp_member;
 
274
        zval *retval;
 
275
        dom_prop_handler *hnd;
 
276
        zend_object_handlers *std_hnd;
 
277
        int ret;
 
278
 
 
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;
 
284
        }
 
285
 
 
286
        ret = FAILURE;
 
287
        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
 
288
 
 
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);
 
291
        }
 
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;
 
297
                } else {
 
298
                        retval = EG(uninitialized_zval_ptr);
 
299
                }
 
300
        } else {
 
301
                std_hnd = zend_get_std_object_handlers();
 
302
                retval = std_hnd->read_property(object, member, type TSRMLS_CC);
 
303
        }
 
304
 
 
305
        if (member == &tmp_member) {
 
306
                zval_dtor(member);
 
307
        }
 
308
        return retval;
 
309
}
 
310
/* }}} */
 
311
 
 
312
/* {{{ dom_write_property */
 
313
void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
 
314
{
 
315
        dom_object *obj;
 
316
        zval tmp_member;
 
317
        dom_prop_handler *hnd;
 
318
        zend_object_handlers *std_hnd;
 
319
        int ret;
 
320
 
 
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;
 
326
        }
 
327
 
 
328
        ret = FAILURE;
 
329
        obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC);
 
330
 
 
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);
 
333
        }
 
334
        if (ret == SUCCESS) {
 
335
                hnd->write_func(obj, value TSRMLS_CC);
 
336
        } else {
 
337
                std_hnd = zend_get_std_object_handlers();
 
338
                std_hnd->write_property(object, member, value TSRMLS_CC);
 
339
        }
 
340
 
 
341
        if (member == &tmp_member) {
 
342
                zval_dtor(member);
 
343
        }
 
344
}
 
345
/* }}} */
 
346
 
 
347
 
 
348
void *php_dom_export_node(zval *object TSRMLS_DC)
 
349
{
 
350
        php_libxml_node_object *intern;
 
351
        xmlNodePtr nodep = NULL;
 
352
 
 
353
        intern = (php_libxml_node_object *)zend_object_store_get_object(object TSRMLS_CC);
 
354
        if (intern && intern->node) {
 
355
                nodep = intern->node->node;
 
356
        }
 
357
 
 
358
        return nodep;   
 
359
}
 
360
 
 
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)
 
364
{
 
365
#ifdef HAVE_SIMPLEXML
 
366
        zval *rv = NULL;
 
367
        zval *node;
 
368
        xmlNodePtr nodep = NULL;
 
369
        php_libxml_node_object *nodeobj;
 
370
        int ret;
 
371
 
 
372
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &node) == FAILURE) {
 
373
                return;
 
374
        }
 
375
 
 
376
        nodeobj = (php_libxml_node_object *)zend_object_store_get_object(node TSRMLS_CC);
 
377
        nodep = php_libxml_import_node(node TSRMLS_CC);
 
378
 
 
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);
 
381
        } else {
 
382
                php_error(E_WARNING, "Invalid Nodetype to import");
 
383
                RETURN_NULL();
 
384
        }
 
385
#else
 
386
        php_error(E_WARNING, "SimpleXML support is not enabled");
 
387
        return;
 
388
#endif
 
389
}
 
390
/* }}} */
 
391
 
 
392
zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC)
 
393
{
 
394
        zend_object_value retval;
 
395
        void *new_object;
 
396
        dom_object *intern;
 
397
        dom_object *old_object;
 
398
        struct _store_object *obj;
 
399
        zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
 
400
 
 
401
        obj = &EG(objects_store).object_buckets[handle].bucket.obj;
 
402
        
 
403
        if (obj->clone == NULL) {
 
404
                php_error(E_ERROR, "Trying to clone an uncloneable object of class %s", Z_OBJCE_P(zobject)->name);
 
405
        }               
 
406
 
 
407
        obj->clone(obj->object, &new_object TSRMLS_CC);
 
408
 
 
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);
 
413
        
 
414
        old_object = (dom_object *) obj->object;
 
415
        zend_objects_clone_members(&intern->std, retval, &old_object->std, intern->handle TSRMLS_CC);
 
416
 
 
417
        return retval;
 
418
}
 
419
 
 
420
zend_object_value dom_objects_ze1_clone_obj(zval *zobject TSRMLS_DC)
 
421
{
 
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;
 
425
}
 
426
 
 
427
static zend_function_entry dom_functions[] = {
 
428
        PHP_FE(dom_import_simplexml, NULL)
 
429
        {NULL, NULL, NULL}
 
430
};
 
431
 
 
432
static zend_object_handlers* dom_get_obj_handlers(TSRMLS_D) {
 
433
        if (EG(ze1_compatibility_mode)) {
 
434
                return &dom_ze1_object_handlers;
 
435
        } else {
 
436
                return &dom_object_handlers;
 
437
        }
 
438
}
 
439
 
 
440
zend_module_entry dom_module_entry = {
 
441
        STANDARD_MODULE_HEADER,
 
442
        "dom",
 
443
        dom_functions,
 
444
        PHP_MINIT(dom),
 
445
        PHP_MSHUTDOWN(dom),
 
446
        NULL,
 
447
        NULL,
 
448
        PHP_MINFO(dom),
 
449
        DOM_API_VERSION, /* Extension versionnumber */
 
450
        STANDARD_MODULE_PROPERTIES
 
451
};
 
452
 
 
453
#ifdef COMPILE_DL_DOM
 
454
ZEND_GET_MODULE(dom)
 
455
#endif
 
456
 
 
457
/* {{{ PHP_MINIT_FUNCTION(dom) */
 
458
PHP_MINIT_FUNCTION(dom)
 
459
{
 
460
        zend_class_entry ce;
 
461
 
 
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;
 
467
 
 
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;
 
473
 
 
474
        zend_hash_init(&classes, 0, NULL, NULL, 1);
 
475
 
 
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);
 
480
 
 
481
        REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
 
482
        
 
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);
 
486
 
 
487
        REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
 
488
        
 
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);
 
492
 
 
493
        REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
 
494
        
 
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);
 
498
 
 
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);
 
501
 
 
502
        REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry);
 
503
        
 
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);
 
522
 
 
523
        REGISTER_DOM_CLASS(ce, "DOMNameSpaceNode", NULL, NULL, dom_namespace_node_class_entry);
 
524
 
 
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);
 
535
 
 
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);
 
538
        
 
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);
 
558
 
 
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);
 
561
 
 
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;
 
566
 
 
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);
 
570
 
 
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;
 
575
 
 
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);
 
579
 
 
580
        REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry);
 
581
        
 
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);
 
587
 
 
588
        REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
 
589
        
 
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);
 
598
 
 
599
        REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry);
 
600
        
 
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);
 
606
 
 
607
        REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
 
608
        
 
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);
 
613
 
 
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);
 
616
 
 
617
        REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
 
618
        
 
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);
 
623
 
 
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);
 
626
        
 
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);
 
635
 
 
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);
 
638
        
 
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);
 
646
 
 
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);
 
650
 
 
651
        REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
 
652
        
 
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);
 
662
 
 
663
        REGISTER_DOM_CLASS(ce, "DOMNotation", NULL, php_dom_notation_class_functions, dom_notation_class_entry);
 
664
        
 
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);
 
673
 
 
674
        REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry);
 
675
        
 
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);
 
684
 
 
685
        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
 
686
 
 
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);
 
689
 
 
690
        REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
 
691
        
 
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);
 
697
 
 
698
        REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
 
699
 
 
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);
 
704
 
 
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);
 
708
#endif
 
709
 
 
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);
 
730
#endif
 
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);
 
741
 
 
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);
 
760
 
 
761
        php_libxml_register_export(dom_node_class_entry, php_dom_export_node);
 
762
 
 
763
        return SUCCESS;
 
764
}
 
765
/* }}} */
 
766
 
 
767
/* {{{ */
 
768
PHP_MINFO_FUNCTION(dom)
 
769
{
 
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");
 
776
#endif
 
777
#if defined(LIBXML_XPATH_ENABLED)
 
778
        php_info_print_table_row(2, "XPath Support", "enabled");
 
779
#endif
 
780
#if defined(LIBXML_XPTR_ENABLED)
 
781
        php_info_print_table_row(2, "XPointer Support", "enabled");
 
782
#endif
 
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");
 
786
#endif
 
787
        php_info_print_table_end();
 
788
}
 
789
/* }}} */
 
790
 
 
791
PHP_MSHUTDOWN_FUNCTION(dom)
 
792
{
 
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);
 
814
#endif
 
815
        zend_hash_destroy(&classes);
 
816
        
 
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();*/
 
821
 
 
822
        return SUCCESS;
 
823
}
 
824
 
 
825
/* {{{ node_list_unlink */
 
826
void node_list_unlink(xmlNodePtr node TSRMLS_DC)
 
827
{
 
828
        dom_object *wrapper;
 
829
 
 
830
        while (node != NULL) {
 
831
 
 
832
                wrapper = php_dom_object_get_data(node);
 
833
 
 
834
                if (wrapper != NULL ) {
 
835
                        xmlUnlinkNode(node);
 
836
                } else {
 
837
                        node_list_unlink(node->children TSRMLS_CC);
 
838
 
 
839
                        switch (node->type) {
 
840
                                case XML_ATTRIBUTE_DECL:
 
841
                                case XML_DTD_NODE:
 
842
                                case XML_DOCUMENT_TYPE_NODE:
 
843
                                case XML_ENTITY_DECL:
 
844
                                case XML_ATTRIBUTE_NODE:
 
845
                                        break;
 
846
                                default:
 
847
                                        node_list_unlink((xmlNodePtr) node->properties TSRMLS_CC);
 
848
                        }
 
849
 
 
850
                }
 
851
 
 
852
                node = node->next;
 
853
        }
 
854
}
 
855
/* }}} end node_list_unlink */
 
856
 
 
857
#if defined(LIBXML_XPATH_ENABLED)
 
858
/* {{{ dom_xpath_objects_free_storage */
 
859
void dom_xpath_objects_free_storage(void *object TSRMLS_DC)
 
860
{
 
861
        dom_object *intern = (dom_object *)object;
 
862
 
 
863
        zend_hash_destroy(intern->std.properties);
 
864
        FREE_HASHTABLE(intern->std.properties);
 
865
 
 
866
        if (intern->ptr != NULL) {
 
867
                xmlXPathFreeContext((xmlXPathContextPtr) intern->ptr);
 
868
                php_libxml_decrement_doc_ref((php_libxml_node_object *) intern TSRMLS_CC);
 
869
                intern->ptr = NULL;
 
870
        }
 
871
 
 
872
        efree(object);
 
873
}
 
874
/* }}} */
 
875
#endif
 
876
 
 
877
/* {{{ dom_objects_free_storage */
 
878
void dom_objects_free_storage(void *object TSRMLS_DC)
 
879
{
 
880
        dom_object *intern = (dom_object *)object;
 
881
        int retcount;
 
882
 
 
883
        zend_hash_destroy(intern->std.properties);
 
884
        FREE_HASHTABLE(intern->std.properties);
 
885
 
 
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);
 
889
                } else {
 
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);
 
892
                }
 
893
                intern->ptr = NULL;
 
894
        }
 
895
 
 
896
        efree(object);
 
897
}
 
898
/* }}} */
 
899
 
 
900
void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns TSRMLS_DC)
 
901
{
 
902
        dom_nnodemap_object *mapptr;
 
903
        zval *baseobj = NULL;
 
904
 
 
905
        mapptr = (dom_nnodemap_object *)intern->ptr;
 
906
        if (basenode) {
 
907
                MAKE_STD_ZVAL(baseobj);
 
908
                baseobj->type = IS_OBJECT;
 
909
                baseobj->is_ref = 1;
 
910
                baseobj->value.obj.handle = basenode->handle;
 
911
                baseobj->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C);
 
912
                zval_copy_ctor(baseobj);
 
913
        }
 
914
        mapptr->baseobjptr = baseobj;
 
915
        mapptr->baseobj = basenode;
 
916
        mapptr->nodetype = ntype;
 
917
        mapptr->ht = ht;
 
918
        mapptr->local = local;
 
919
        mapptr->ns = ns;
 
920
 
 
921
}
 
922
 
 
923
static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy TSRMLS_DC)
 
924
{
 
925
        zend_class_entry *base_class;
 
926
        zval *tmp;
 
927
        dom_object *intern;
 
928
 
 
929
        intern = emalloc(sizeof(dom_object));
 
930
        intern->std.ce = class_type;
 
931
        intern->std.in_get = 0;
 
932
        intern->std.in_set = 0;
 
933
        intern->ptr = NULL;
 
934
        intern->prop_handler = NULL;
 
935
        intern->document = NULL;
 
936
 
 
937
        base_class = class_type;
 
938
        while(base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) {
 
939
                base_class = base_class->parent;
 
940
        }
 
941
 
 
942
        zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler);
 
943
 
 
944
        ALLOC_HASHTABLE(intern->std.properties);
 
945
        zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
 
946
        if (hash_copy) {
 
947
                zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
 
948
        }
 
949
 
 
950
        return intern;
 
951
}
 
952
 
 
953
/* {{{ dom_objects_clone */
 
954
void dom_objects_clone(void *object, void **object_clone TSRMLS_DC)
 
955
{
 
956
        dom_object *intern = (dom_object *) object;
 
957
        dom_object *clone;
 
958
        xmlNodePtr node;
 
959
        xmlNodePtr cloned_node;
 
960
 
 
961
        clone = dom_objects_set_class(intern->std.ce, 0 TSRMLS_CC);
 
962
 
 
963
        if (instanceof_function(intern->std.ce, dom_node_class_entry TSRMLS_CC)) {
 
964
                node = (xmlNodePtr)dom_object_get_node((dom_object *) object);
 
965
                if (node != NULL) {
 
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;
 
971
                                }
 
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);
 
974
                        }
 
975
 
 
976
                }
 
977
        }
 
978
 
 
979
        *object_clone = (void *) clone;
 
980
}
 
981
/* }}} */
 
982
 
 
983
/* {{{ dom_objects_new */
 
984
zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC)
 
985
{
 
986
        zend_object_value retval;
 
987
        dom_object *intern;
 
988
        
 
989
        intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
 
990
 
 
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);
 
994
 
 
995
        return retval;
 
996
}
 
997
/* }}} */
 
998
 
 
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)
 
1002
{
 
1003
        zend_object_value retval;
 
1004
        dom_object *intern;
 
1005
        
 
1006
        intern = dom_objects_set_class(class_type, 1 TSRMLS_CC);
 
1007
 
 
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);
 
1011
 
 
1012
        return retval;
 
1013
}
 
1014
/* }}} */
 
1015
#endif
 
1016
 
 
1017
static void dom_nnodemap_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
 
1018
{
 
1019
        zval *baseobj;
 
1020
        dom_object *intern;
 
1021
        dom_nnodemap_object *objmap;
 
1022
 
 
1023
        intern = (dom_object *)object;
 
1024
        objmap = (dom_nnodemap_object *)intern->ptr;
 
1025
 
 
1026
        if (objmap) {
 
1027
                if (objmap->local) {
 
1028
                        xmlFree(objmap->local);
 
1029
                }
 
1030
                if (objmap->ns) {
 
1031
                        xmlFree(objmap->ns);
 
1032
                }
 
1033
                if (objmap->baseobjptr) {
 
1034
                        baseobj = objmap->baseobjptr;
 
1035
                        zval_ptr_dtor((zval **)&baseobj);
 
1036
                }
 
1037
                efree(objmap);
 
1038
                intern->ptr = NULL;
 
1039
        }
 
1040
 
 
1041
 
 
1042
}
 
1043
 
 
1044
void dom_nnodemap_objects_free_storage(void *object TSRMLS_DC)
 
1045
{
 
1046
        dom_object *intern = (dom_object *)object;
 
1047
 
 
1048
        php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
 
1049
 
 
1050
        zend_hash_destroy(intern->std.properties);
 
1051
        FREE_HASHTABLE(intern->std.properties);
 
1052
 
 
1053
        efree(object);
 
1054
}
 
1055
 
 
1056
zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_DC)
 
1057
{
 
1058
        zend_object_value retval;
 
1059
        dom_object *intern;
 
1060
        dom_nnodemap_object *objmap;
 
1061
        
 
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;
 
1068
        objmap->ht = NULL;
 
1069
        objmap->local = NULL;
 
1070
        objmap->ns = NULL;
 
1071
 
 
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);
 
1075
 
 
1076
        return retval;
 
1077
}
 
1078
 
 
1079
void php_dom_create_interator(zval *return_value, int ce_type TSRMLS_DC)
 
1080
{
 
1081
        zend_class_entry *ce;
 
1082
 
 
1083
        if (ce_type == DOM_NAMEDNODEMAP) {
 
1084
                ce = dom_namednodemap_class_entry;
 
1085
        } else {
 
1086
                ce = dom_nodelist_class_entry;
 
1087
        }
 
1088
 
 
1089
        object_init_ex(return_value, ce);
 
1090
}
 
1091
 
 
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)
 
1094
{
 
1095
        zval *wrapper;
 
1096
        zend_class_entry *ce;
 
1097
        dom_object *intern;
 
1098
 
 
1099
        *found = 0;
 
1100
 
 
1101
        if (!obj) {
 
1102
                ALLOC_ZVAL(wrapper);
 
1103
                ZVAL_NULL(wrapper);
 
1104
                return wrapper;
 
1105
        }
 
1106
 
 
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);
 
1113
                *found = 1;
 
1114
                return return_value;
 
1115
        }
 
1116
 
 
1117
        wrapper = return_value;
 
1118
 
 
1119
        switch (obj->type) {
 
1120
                case XML_DOCUMENT_NODE:
 
1121
                case XML_HTML_DOCUMENT_NODE:
 
1122
                {
 
1123
                        ce = dom_document_class_entry;
 
1124
                        break;
 
1125
                }
 
1126
                case XML_DTD_NODE:
 
1127
                case XML_DOCUMENT_TYPE_NODE:
 
1128
                {
 
1129
                        ce = dom_documenttype_class_entry;
 
1130
                        break;
 
1131
                }
 
1132
                case XML_ELEMENT_NODE:
 
1133
                {
 
1134
                        ce = dom_element_class_entry;
 
1135
                        break;
 
1136
                }
 
1137
                case XML_ATTRIBUTE_NODE:
 
1138
                {
 
1139
                        ce = dom_attr_class_entry;
 
1140
                        break;
 
1141
                }
 
1142
                case XML_TEXT_NODE:
 
1143
                {
 
1144
                        ce = dom_text_class_entry;
 
1145
                        break;
 
1146
                }
 
1147
                case XML_COMMENT_NODE:
 
1148
                {
 
1149
                        ce = dom_comment_class_entry;
 
1150
                        break;
 
1151
                }
 
1152
                case XML_PI_NODE:
 
1153
                {
 
1154
                        ce = dom_processinginstruction_class_entry;
 
1155
                        break;
 
1156
                }
 
1157
                case XML_ENTITY_REF_NODE:
 
1158
                {
 
1159
                        ce = dom_entityreference_class_entry;
 
1160
                        break;
 
1161
                }
 
1162
                case XML_ENTITY_DECL:
 
1163
                case XML_ELEMENT_DECL:
 
1164
                {
 
1165
                        ce = dom_entity_class_entry;
 
1166
                        break;
 
1167
                }
 
1168
                case XML_CDATA_SECTION_NODE:
 
1169
                {
 
1170
                        ce = dom_cdatasection_class_entry;
 
1171
                        break;
 
1172
                }
 
1173
                case XML_DOCUMENT_FRAG_NODE:
 
1174
                {
 
1175
                        ce = dom_documentfragment_class_entry;
 
1176
                        break;
 
1177
                }
 
1178
                case XML_NOTATION_NODE:
 
1179
                {
 
1180
                        ce = dom_notation_class_entry;
 
1181
                        break;
 
1182
                }
 
1183
                case XML_NAMESPACE_DECL:
 
1184
                {
 
1185
                        ce = dom_namespace_node_class_entry;
 
1186
                        break;
 
1187
                }
 
1188
                default:
 
1189
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d\n", Z_TYPE_P(obj));
 
1190
                        ZVAL_NULL(wrapper);
 
1191
                        return wrapper;
 
1192
        }
 
1193
 
 
1194
        object_init_ex(wrapper, ce);
 
1195
 
 
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;
 
1200
                }
 
1201
                php_libxml_increment_doc_ref((php_libxml_node_object *)intern, obj->doc TSRMLS_CC);
 
1202
        }
 
1203
 
 
1204
        php_libxml_increment_node_ptr((php_libxml_node_object *)intern, obj, (void *)intern TSRMLS_CC);
 
1205
        return (wrapper);
 
1206
}
 
1207
/* }}} end php_domobject_new */
 
1208
 
 
1209
 
 
1210
void php_dom_create_implementation(zval **retval  TSRMLS_DC) {
 
1211
        object_init_ex(*retval, dom_domimplementation_class_entry);
 
1212
}
 
1213
 
 
1214
/* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */
 
1215
int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) 
 
1216
{
 
1217
        xmlNodePtr nodep;
 
1218
 
 
1219
    if (parent == NULL || child == NULL || child->doc != parent->doc) {
 
1220
        return SUCCESS;
 
1221
    }
 
1222
 
 
1223
        nodep = parent;
 
1224
 
 
1225
        while (nodep) {
 
1226
                if (nodep == child) {
 
1227
                        return FAILURE;
 
1228
                }
 
1229
                nodep = nodep->parent;
 
1230
        }
 
1231
 
 
1232
    return SUCCESS;
 
1233
}
 
1234
/* }}} end dom_hierarchy */
 
1235
 
 
1236
/* {{{ dom_has_feature(char *feature, char *version) */
 
1237
int dom_has_feature(char *feature, char *version)
 
1238
{
 
1239
        int retval = 0;
 
1240
 
 
1241
        if (!(strcmp (version, "1.0") && strcmp (version,"2.0") && strcmp(version, ""))) {
 
1242
                if ((!strcasecmp(feature, "Core") && !strcmp (version, "1.0")) || !strcasecmp(feature, "XML"))
 
1243
                        retval = 1;
 
1244
        }
 
1245
 
 
1246
        return retval;
 
1247
}
 
1248
/* }}} end dom_has_feature */
 
1249
 
 
1250
xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr nodep, char *ns, char *local, int *cur, int index)
 
1251
{
 
1252
        xmlNodePtr ret = NULL;
 
1253
 
 
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) {
 
1259
                                                ret = nodep;
 
1260
                                                break;
 
1261
                                        }
 
1262
                                        (*cur)++;
 
1263
                                }
 
1264
                        }
 
1265
                        ret = dom_get_elements_by_tag_name_ns_raw(nodep->children, ns, local, cur, index);
 
1266
                        if (ret != NULL) {
 
1267
                                break;
 
1268
                        }
 
1269
                }
 
1270
                nodep = nodep->next;
 
1271
        }
 
1272
        return ret;
 
1273
}
 
1274
/* }}} end dom_element_get_elements_by_tag_name_ns_raw */
 
1275
 
 
1276
 
 
1277
/* {{{ void dom_normalize (xmlNodePtr nodep TSRMLS_DC) */
 
1278
void dom_normalize (xmlNodePtr nodep TSRMLS_DC)
 
1279
{
 
1280
        xmlNodePtr child, nextp, newnextp;
 
1281
        xmlAttrPtr attr;
 
1282
        xmlChar *strContent; 
 
1283
 
 
1284
        child = nodep->children;
 
1285
        while(child != NULL) {
 
1286
                switch (child->type) {
 
1287
                        case XML_TEXT_NODE:
 
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);
 
1297
                                                nextp = newnextp;
 
1298
                                        } else {
 
1299
                                                break;
 
1300
                                        }
 
1301
                                }
 
1302
                                break;
 
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);
 
1308
                                        attr = attr->next;
 
1309
                                }
 
1310
                                break;
 
1311
                        case XML_ATTRIBUTE_NODE:
 
1312
                                dom_normalize (child TSRMLS_CC);
 
1313
                                break;
 
1314
                        default:
 
1315
                                break;
 
1316
                }
 
1317
                child = child->next;
 
1318
        }
 
1319
}
 
1320
/* }}} end dom_normalize */
 
1321
 
 
1322
 
 
1323
/* {{{ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) */
 
1324
void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
 
1325
        xmlNs *cur;
 
1326
 
 
1327
        if (doc == NULL)
 
1328
                return;
 
1329
 
 
1330
        if (doc->oldNs == NULL) {
 
1331
                doc->oldNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
 
1332
                if (doc->oldNs == NULL) {
 
1333
                        return;
 
1334
                }
 
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"); 
 
1339
        }
 
1340
 
 
1341
        cur = doc->oldNs;
 
1342
        while (cur->next != NULL) {
 
1343
                cur = cur->next;
 
1344
        }
 
1345
        cur->next = ns;
 
1346
}
 
1347
/* }}} end dom_set_old_ns */
 
1348
 
 
1349
/*
 
1350
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
 
1351
 
 
1352
NAMESPACE_ERR: Raised if
 
1353
 
 
1354
1. the qualifiedName is a malformed qualified name
 
1355
2. the qualifiedName has a prefix and the  namespaceURI is null
 
1356
*/
 
1357
 
 
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;
 
1362
        }
 
1363
        
 
1364
        *localname = xmlSplitQName2(qname, (xmlChar **) prefix);
 
1365
        if (*localname == NULL) {
 
1366
                *localname = xmlStrdup(qname);
 
1367
                if (*prefix == NULL && uri_len == 0) {
 
1368
                        return 0;
 
1369
                }
 
1370
        }
 
1371
 
 
1372
        /* 1 */
 
1373
        if (xmlValidateQName((xmlChar *) qname, 0) != 0) {
 
1374
                return NAMESPACE_ERR;
 
1375
        }
 
1376
 
 
1377
        /* 2 */
 
1378
        if (*prefix != NULL && uri_len == 0) {
 
1379
                return NAMESPACE_ERR;
 
1380
        }
 
1381
 
 
1382
        return 0;
 
1383
}
 
1384
 
 
1385
 
 
1386
/*
 
1387
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
 
1388
 
 
1389
NAMESPACE_ERR: Raised if
 
1390
 
 
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".
 
1394
*/
 
1395
 
 
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;
 
1399
 
 
1400
        *errorcode = 0;
 
1401
 
 
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);
 
1406
        }
 
1407
 
 
1408
        if (nsptr == NULL) {
 
1409
                *errorcode = NAMESPACE_ERR;
 
1410
        }
 
1411
 
 
1412
        return nsptr;
 
1413
 
 
1414
}
 
1415
/* }}} end dom_get_ns */
 
1416
 
 
1417
/* {{{ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) */
 
1418
xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
 
1419
        xmlNsPtr cur;
 
1420
        xmlNs *ret = NULL;
 
1421
        if (node == NULL)
 
1422
                return NULL;
 
1423
 
 
1424
        if (localName == NULL || xmlStrEqual(localName, "")) {
 
1425
                cur = node->nsDef;
 
1426
                while (cur != NULL) {
 
1427
                        if (cur->prefix == NULL  && cur->href != NULL) {
 
1428
                                ret = cur;
 
1429
                                break;
 
1430
                        }
 
1431
                        cur = cur->next;
 
1432
                }
 
1433
        } else {
 
1434
                cur = node->nsDef;
 
1435
                while (cur != NULL) {
 
1436
                        if (cur->prefix != NULL && xmlStrEqual(localName, cur->prefix)) {
 
1437
                                ret = cur;
 
1438
                                break;
 
1439
                        }
 
1440
                        cur = cur->next;
 
1441
                }
 
1442
        }
 
1443
        return ret;
 
1444
}
 
1445
/* }}} end dom_get_nsdecl */
 
1446
 
 
1447
#endif /* HAVE_DOM */
 
1448
 
 
1449
/*
 
1450
 * Local variables:
 
1451
 * tab-width: 4
 
1452
 * c-basic-offset: 4
 
1453
 * End:
 
1454
 * vim600: noet sw=4 ts=4 fdm=marker
 
1455
 * vim<600: noet sw=4 ts=4
 
1456
 */