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