1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2017 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 +----------------------------------------------------------------------+
18 */
19
20 /* $Id$ */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "php.h"
27 #if HAVE_LIBXML && HAVE_DOM
28 #include "php_dom.h"
29
30 /* {{{ arginfo */
31 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item, 0, 0, 1)
32 ZEND_ARG_INFO(0, name)
33 ZEND_END_ARG_INFO();
34
35 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item, 0, 0, 1)
36 ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
37 ZEND_END_ARG_INFO();
38
39 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item, 0, 0, 0)
40 ZEND_ARG_INFO(0, name)
41 ZEND_END_ARG_INFO();
42
43 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_item, 0, 0, 0)
44 ZEND_ARG_INFO(0, index)
45 ZEND_END_ARG_INFO();
46
47 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item_ns, 0, 0, 0)
48 ZEND_ARG_INFO(0, namespaceURI)
49 ZEND_ARG_INFO(0, localName)
50 ZEND_END_ARG_INFO();
51
52 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item_ns, 0, 0, 0)
53 ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
54 ZEND_END_ARG_INFO();
55
56 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item_ns, 0, 0, 0)
57 ZEND_ARG_INFO(0, namespaceURI)
58 ZEND_ARG_INFO(0, localName)
59 ZEND_END_ARG_INFO();
60 /* }}} */
61
62 /*
63 * class DOMNamedNodeMap
64 *
65 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1780488922
66 * Since:
67 */
68
69 const zend_function_entry php_dom_namednodemap_class_functions[] = { /* {{{ */
70 PHP_FALIAS(getNamedItem, dom_namednodemap_get_named_item, arginfo_dom_namednodemap_get_named_item)
71 PHP_FALIAS(setNamedItem, dom_namednodemap_set_named_item, arginfo_dom_namednodemap_set_named_item)
72 PHP_FALIAS(removeNamedItem, dom_namednodemap_remove_named_item, arginfo_dom_namednodemap_remove_named_item)
73 PHP_FALIAS(item, dom_namednodemap_item, arginfo_dom_namednodemap_item)
74 PHP_FALIAS(getNamedItemNS, dom_namednodemap_get_named_item_ns, arginfo_dom_namednodemap_get_named_item_ns)
75 PHP_FALIAS(setNamedItemNS, dom_namednodemap_set_named_item_ns, arginfo_dom_namednodemap_set_named_item_ns)
76 PHP_FALIAS(removeNamedItemNS, dom_namednodemap_remove_named_item_ns, arginfo_dom_namednodemap_remove_named_item_ns)
77 PHP_FE_END
78 };
79 /* }}} */
80
81 /* {{{ length int
82 readonly=yes
83 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D0FB19E
84 Since:
85 */
dom_namednodemap_length_read(dom_object * obj,zval * retval)86 int dom_namednodemap_length_read(dom_object *obj, zval *retval)
87 {
88 dom_nnodemap_object *objmap;
89 xmlAttrPtr curnode;
90 xmlNodePtr nodep;
91 int count = 0;
92
93 objmap = (dom_nnodemap_object *)obj->ptr;
94
95 if (objmap != NULL) {
96 if ((objmap->nodetype == XML_NOTATION_NODE) ||
97 objmap->nodetype == XML_ENTITY_NODE) {
98 if (objmap->ht) {
99 count = xmlHashSize(objmap->ht);
100 }
101 } else {
102 nodep = dom_object_get_node(objmap->baseobj);
103 if (nodep) {
104 curnode = nodep->properties;
105 if (curnode) {
106 count++;
107 while (curnode->next != NULL) {
108 count++;
109 curnode = curnode->next;
110 }
111 }
112 }
113 }
114 }
115
116 ZVAL_LONG(retval, count);
117 return SUCCESS;
118 }
119
120 /* }}} */
121
122 /* {{{ proto DOMNode dom_namednodemap_get_named_item(string name);
123 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
124 Since:
125 */
PHP_FUNCTION(dom_namednodemap_get_named_item)126 PHP_FUNCTION(dom_namednodemap_get_named_item)
127 {
128 zval *id;
129 int ret;
130 size_t namedlen=0;
131 dom_object *intern;
132 xmlNodePtr itemnode = NULL;
133 char *named;
134
135 dom_nnodemap_object *objmap;
136 xmlNodePtr nodep;
137 xmlNotation *notep = NULL;
138
139 if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_namednodemap_class_entry, &named, &namedlen) == FAILURE) {
140 return;
141 }
142
143 intern = Z_DOMOBJ_P(id);
144
145 objmap = (dom_nnodemap_object *)intern->ptr;
146
147 if (objmap != NULL) {
148 if ((objmap->nodetype == XML_NOTATION_NODE) ||
149 objmap->nodetype == XML_ENTITY_NODE) {
150 if (objmap->ht) {
151 if (objmap->nodetype == XML_ENTITY_NODE) {
152 itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, (xmlChar *) named);
153 } else {
154 notep = (xmlNotation *)xmlHashLookup(objmap->ht, (xmlChar *) named);
155 if (notep) {
156 itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
157 }
158 }
159 }
160 } else {
161 nodep = dom_object_get_node(objmap->baseobj);
162 if (nodep) {
163 itemnode = (xmlNodePtr)xmlHasProp(nodep, (xmlChar *) named);
164 }
165 }
166 }
167
168 if (itemnode) {
169 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
170 return;
171 } else {
172 RETVAL_NULL();
173 }
174 }
175 /* }}} end dom_namednodemap_get_named_item */
176
177 /* {{{ proto DOMNode dom_namednodemap_set_named_item(DOMNode arg);
178 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1025163788
179 Since:
180 */
PHP_FUNCTION(dom_namednodemap_set_named_item)181 PHP_FUNCTION(dom_namednodemap_set_named_item)
182 {
183 DOM_NOT_IMPLEMENTED();
184 }
185 /* }}} end dom_namednodemap_set_named_item */
186
187 /* {{{ proto DOMNode dom_namednodemap_remove_named_item(string name);
188 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D58B193
189 Since:
190 */
PHP_FUNCTION(dom_namednodemap_remove_named_item)191 PHP_FUNCTION(dom_namednodemap_remove_named_item)
192 {
193 DOM_NOT_IMPLEMENTED();
194 }
195 /* }}} end dom_namednodemap_remove_named_item */
196
197 /* {{{ proto DOMNode dom_namednodemap_item(int index);
198 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-349467F9
199 Since:
200 */
PHP_FUNCTION(dom_namednodemap_item)201 PHP_FUNCTION(dom_namednodemap_item)
202 {
203 zval *id;
204 zend_long index;
205 int ret;
206 dom_object *intern;
207 xmlNodePtr itemnode = NULL;
208
209 dom_nnodemap_object *objmap;
210 xmlNodePtr nodep, curnode;
211 int count;
212
213 if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &id, dom_namednodemap_class_entry, &index) == FAILURE) {
214 return;
215 }
216 if (index >= 0) {
217 if (ZEND_LONG_INT_OVFL(index)) {
218 php_error_docref(NULL, E_WARNING, "Invalid index");
219 RETURN_NULL();
220 }
221
222 intern = Z_DOMOBJ_P(id);
223
224 objmap = (dom_nnodemap_object *)intern->ptr;
225
226 if (objmap != NULL) {
227 if ((objmap->nodetype == XML_NOTATION_NODE) ||
228 objmap->nodetype == XML_ENTITY_NODE) {
229 if (objmap->ht) {
230 if (objmap->nodetype == XML_ENTITY_NODE) {
231 itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
232 } else {
233 itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
234 }
235 }
236 } else {
237 nodep = dom_object_get_node(objmap->baseobj);
238 if (nodep) {
239 curnode = (xmlNodePtr)nodep->properties;
240 count = 0;
241 while (count < index && curnode != NULL) {
242 count++;
243 curnode = (xmlNodePtr)curnode->next;
244 }
245 itemnode = curnode;
246 }
247 }
248 }
249
250 if (itemnode) {
251 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
252 return;
253 }
254 }
255
256 RETVAL_NULL();
257 }
258 /* }}} end dom_namednodemap_item */
259
260 /* {{{ proto DOMNode dom_namednodemap_get_named_item_ns(string namespaceURI, string localName);
261 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
262 Since: DOM Level 2
263 */
PHP_FUNCTION(dom_namednodemap_get_named_item_ns)264 PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
265 {
266 zval *id;
267 int ret;
268 size_t namedlen=0, urilen=0;
269 dom_object *intern;
270 xmlNodePtr itemnode = NULL;
271 char *uri, *named;
272
273 dom_nnodemap_object *objmap;
274 xmlNodePtr nodep;
275 xmlNotation *notep = NULL;
276
277 if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!s", &id, dom_namednodemap_class_entry, &uri, &urilen, &named, &namedlen) == FAILURE) {
278 return;
279 }
280
281 intern = Z_DOMOBJ_P(id);
282
283 objmap = (dom_nnodemap_object *)intern->ptr;
284
285 if (objmap != NULL) {
286 if ((objmap->nodetype == XML_NOTATION_NODE) ||
287 objmap->nodetype == XML_ENTITY_NODE) {
288 if (objmap->ht) {
289 if (objmap->nodetype == XML_ENTITY_NODE) {
290 itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, (xmlChar *) named);
291 } else {
292 notep = (xmlNotation *)xmlHashLookup(objmap->ht, (xmlChar *) named);
293 if (notep) {
294 itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
295 }
296 }
297 }
298 } else {
299 nodep = dom_object_get_node(objmap->baseobj);
300 if (nodep) {
301 itemnode = (xmlNodePtr)xmlHasNsProp(nodep, (xmlChar *) named, (xmlChar *) uri);
302 }
303 }
304 }
305
306 if (itemnode) {
307 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
308 return;
309 } else {
310 RETVAL_NULL();
311 }
312 }
313 /* }}} end dom_namednodemap_get_named_item_ns */
314
315 /* {{{ proto DOMNode dom_namednodemap_set_named_item_ns(DOMNode arg);
316 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
317 Since: DOM Level 2
318 */
PHP_FUNCTION(dom_namednodemap_set_named_item_ns)319 PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
320 {
321 DOM_NOT_IMPLEMENTED();
322 }
323 /* }}} end dom_namednodemap_set_named_item_ns */
324
325 /* {{{ proto DOMNode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
326 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
327 Since: DOM Level 2
328 */
PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)329 PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
330 {
331 DOM_NOT_IMPLEMENTED();
332 }
333 /* }}} end dom_namednodemap_remove_named_item_ns */
334
335 #endif
336
337 /*
338 * Local variables:
339 * tab-width: 4
340 * c-basic-offset: 4
341 * End:
342 * vim600: noet sw=4 ts=4 fdm=marker
343 * vim<600: noet sw=4 ts=4
344 */
345