1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2016 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 TSRMLS_DC)86 int dom_namednodemap_length_read(dom_object *obj, zval **retval TSRMLS_DC)
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 MAKE_STD_ZVAL(*retval);
117 ZVAL_LONG(*retval, count);
118 return SUCCESS;
119 }
120
121 /* }}} */
122
123 /* {{{ proto DOMNode dom_namednodemap_get_named_item(string name);
124 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
125 Since:
126 */
PHP_FUNCTION(dom_namednodemap_get_named_item)127 PHP_FUNCTION(dom_namednodemap_get_named_item)
128 {
129 zval *id;
130 int ret, 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() TSRMLS_CC, getThis(), "Os", &id, dom_namednodemap_class_entry, &named, &namedlen) == FAILURE) {
140 return;
141 }
142
143 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
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, named);
153 } else {
154 notep = (xmlNotation *)xmlHashLookup(objmap->ht, 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, 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 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() TSRMLS_CC, getThis(), "Ol", &id, dom_namednodemap_class_entry, &index) == FAILURE) {
214 return;
215 }
216 if (index >= 0) {
217 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
218
219 objmap = (dom_nnodemap_object *)intern->ptr;
220
221 if (objmap != NULL) {
222 if ((objmap->nodetype == XML_NOTATION_NODE) ||
223 objmap->nodetype == XML_ENTITY_NODE) {
224 if (objmap->ht) {
225 if (objmap->nodetype == XML_ENTITY_NODE) {
226 itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
227 } else {
228 itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
229 }
230 }
231 } else {
232 nodep = dom_object_get_node(objmap->baseobj);
233 if (nodep) {
234 curnode = (xmlNodePtr)nodep->properties;
235 count = 0;
236 while (count < index && curnode != NULL) {
237 count++;
238 curnode = (xmlNodePtr)curnode->next;
239 }
240 itemnode = curnode;
241 }
242 }
243 }
244
245 if (itemnode) {
246 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
247 return;
248 }
249 }
250
251 RETVAL_NULL();
252 }
253 /* }}} end dom_namednodemap_item */
254
255 /* {{{ proto DOMNode dom_namednodemap_get_named_item_ns(string namespaceURI, string localName);
256 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
257 Since: DOM Level 2
258 */
PHP_FUNCTION(dom_namednodemap_get_named_item_ns)259 PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
260 {
261 zval *id;
262 int ret, namedlen=0, urilen=0;
263 dom_object *intern;
264 xmlNodePtr itemnode = NULL;
265 char *uri, *named;
266
267 dom_nnodemap_object *objmap;
268 xmlNodePtr nodep;
269 xmlNotation *notep = NULL;
270
271 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_namednodemap_class_entry, &uri, &urilen, &named, &namedlen) == FAILURE) {
272 return;
273 }
274
275 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
276
277 objmap = (dom_nnodemap_object *)intern->ptr;
278
279 if (objmap != NULL) {
280 if ((objmap->nodetype == XML_NOTATION_NODE) ||
281 objmap->nodetype == XML_ENTITY_NODE) {
282 if (objmap->ht) {
283 if (objmap->nodetype == XML_ENTITY_NODE) {
284 itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named);
285 } else {
286 notep = (xmlNotation *)xmlHashLookup(objmap->ht, named);
287 if (notep) {
288 itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
289 }
290 }
291 }
292 } else {
293 nodep = dom_object_get_node(objmap->baseobj);
294 if (nodep) {
295 itemnode = (xmlNodePtr)xmlHasNsProp(nodep, named, uri);
296 }
297 }
298 }
299
300 if (itemnode) {
301 DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
302 return;
303 } else {
304 RETVAL_NULL();
305 }
306 }
307 /* }}} end dom_namednodemap_get_named_item_ns */
308
309 /* {{{ proto DOMNode dom_namednodemap_set_named_item_ns(DOMNode arg);
310 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
311 Since: DOM Level 2
312 */
PHP_FUNCTION(dom_namednodemap_set_named_item_ns)313 PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
314 {
315 DOM_NOT_IMPLEMENTED();
316 }
317 /* }}} end dom_namednodemap_set_named_item_ns */
318
319 /* {{{ proto DOMNode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
320 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
321 Since: DOM Level 2
322 */
PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)323 PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
324 {
325 DOM_NOT_IMPLEMENTED();
326 }
327 /* }}} end dom_namednodemap_remove_named_item_ns */
328
329 #endif
330
331 /*
332 * Local variables:
333 * tab-width: 4
334 * c-basic-offset: 4
335 * End:
336 * vim600: noet sw=4 ts=4 fdm=marker
337 * vim<600: noet sw=4 ts=4
338 */
339