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