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
|
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2007 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> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#if HAVE_LIBXML && HAVE_DOM
#include "php_dom.h"
/*
* class DOMImplementation
*
* URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-102161490
* Since:
*/
const zend_function_entry php_dom_domimplementation_class_functions[] = {
PHP_ME(domimplementation, getFeature, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, hasFeature, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, createDocumentType, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
PHP_ME(domimplementation, createDocument, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
{NULL, NULL, NULL}
};
/* {{{ proto boolean dom_domimplementation_has_feature(string feature, string version);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-5CED94D7
Since:
*/
PHP_METHOD(domimplementation, hasFeature)
{
int feature_len, version_len;
char *feature, *version;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &feature, &feature_len, &version, &version_len) == FAILURE) {
return;
}
if (dom_has_feature(feature, version)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} end dom_domimplementation_has_feature */
/* {{{ proto DOMDocumentType dom_domimplementation_create_document_type(string qualifiedName, string publicId, string systemId);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
Since: DOM Level 2
*/
PHP_METHOD(domimplementation, createDocumentType)
{
zval *rv = NULL;
xmlDtd *doctype;
int ret, name_len = 0, publicid_len = 0, systemid_len = 0;
char *name, *publicid, *systemid;
xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
xmlURIPtr uri;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
return;
}
if (name_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "qualifiedName is required");
RETURN_FALSE;
}
if (publicid_len > 0)
pch1 = publicid;
if (systemid_len > 0)
pch2 = systemid;
uri = xmlParseURI(name);
if (uri != NULL && uri->opaque != NULL) {
localname = xmlStrdup(uri->opaque);
if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
php_dom_throw_error(NAMESPACE_ERR, 1 TSRMLS_CC);
xmlFreeURI(uri);
xmlFree(localname);
RETURN_FALSE;
}
} else {
localname = xmlStrdup(name);
}
/* TODO: Test that localname has no invalid chars
php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC);
*/
if (uri) {
xmlFreeURI(uri);
}
doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
xmlFree(localname);
if (doctype == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create DocumentType");
RETURN_FALSE;
}
DOM_RET_OBJ(rv, (xmlNodePtr) doctype, &ret, NULL);
}
/* }}} end dom_domimplementation_create_document_type */
/* {{{ proto DOMDocument dom_domimplementation_create_document(string namespaceURI, string qualifiedName, DOMDocumentType doctype);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocument
Since: DOM Level 2
*/
PHP_METHOD(domimplementation, createDocument)
{
zval *node = NULL, *rv = NULL;
xmlDoc *docp;
xmlNode *nodep;
xmlDtdPtr doctype = NULL;
xmlNsPtr nsptr = NULL;
int ret, uri_len = 0, name_len = 0, errorcode = 0;
char *uri, *name;
char *prefix = NULL, *localname = NULL;
dom_object *doctobj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssO", &uri, &uri_len, &name, &name_len, &node, dom_documenttype_class_entry) == FAILURE) {
return;
}
if (node != NULL) {
DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object");
RETURN_FALSE;
}
if (doctype->doc != NULL) {
php_dom_throw_error(WRONG_DOCUMENT_ERR, 1 TSRMLS_CC);
RETURN_FALSE;
}
} else {
doctobj = NULL;
}
if (name_len > 0) {
errorcode = dom_check_qname(name, &localname, &prefix, 1, name_len);
if (errorcode == 0 && uri_len > 0 && ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL)) {
errorcode = NAMESPACE_ERR;
}
}
if (prefix != NULL) {
xmlFree(prefix);
}
if (errorcode != 0) {
if (localname != NULL) {
xmlFree(localname);
}
php_dom_throw_error(errorcode, 1 TSRMLS_CC);
RETURN_FALSE;
}
/* currently letting libxml2 set the version string */
docp = xmlNewDoc(NULL);
if (!docp) {
if (localname != NULL) {
xmlFree(localname);
}
RETURN_FALSE;
}
if (doctype != NULL) {
docp->intSubset = doctype;
doctype->parent = docp;
doctype->doc = docp;
docp->children = (xmlNodePtr) doctype;
docp->last = (xmlNodePtr) doctype;
}
if (localname != NULL) {
nodep = xmlNewDocNode (docp, nsptr, localname, NULL);
if (!nodep) {
if (doctype != NULL) {
docp->intSubset = NULL;
doctype->parent = NULL;
doctype->doc = NULL;
docp->children = NULL;
docp->last = NULL;
}
xmlFreeDoc(docp);
xmlFree(localname);
/* Need some type of error here */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error");
RETURN_FALSE;
}
nodep->nsDef = nsptr;
xmlDocSetRootElement(docp, nodep);
xmlFree(localname);
}
DOM_RET_OBJ(rv, (xmlNodePtr) docp, &ret, NULL);
if (doctobj != NULL) {
doctobj->document = ((dom_object *)((php_libxml_node_ptr *)docp->_private)->_private)->document;
php_libxml_increment_doc_ref((php_libxml_node_object *)doctobj, docp TSRMLS_CC);
}
}
/* }}} end dom_domimplementation_create_document */
/* {{{ proto DOMNode dom_domimplementation_get_feature(string feature, string version);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementation3-getFeature
Since: DOM Level 3
*/
PHP_METHOD(domimplementation, getFeature)
{
DOM_NOT_IMPLEMENTED();
}
/* }}} end dom_domimplementation_get_feature */
#endif
|