1/*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2014 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 */
31ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item, 0, 0, 1)
32    ZEND_ARG_INFO(0, name)
33ZEND_END_ARG_INFO();
34
35ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item, 0, 0, 1)
36    ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
37ZEND_END_ARG_INFO();
38
39ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item, 0, 0, 0)
40    ZEND_ARG_INFO(0, name)
41ZEND_END_ARG_INFO();
42
43ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_item, 0, 0, 0)
44    ZEND_ARG_INFO(0, index)
45ZEND_END_ARG_INFO();
46
47ZEND_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)
50ZEND_END_ARG_INFO();
51
52ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item_ns, 0, 0, 0)
53    ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
54ZEND_END_ARG_INFO();
55
56ZEND_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)
59ZEND_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
69const 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
82readonly=yes
83URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D0FB19E
84Since:
85*/
86int 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    ZVAL_LONG(retval, count);
117    return SUCCESS;
118}
119
120/* }}} */
121
122/* {{{ proto DOMNode dom_namednodemap_get_named_item(string name);
123URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
124Since:
125*/
126PHP_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() TSRMLS_CC, 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);
178URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1025163788
179Since:
180*/
181PHP_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);
188URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D58B193
189Since:
190*/
191PHP_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);
198URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-349467F9
199Since:
200*/
201PHP_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() TSRMLS_CC, getThis(), "Ol", &id, dom_namednodemap_class_entry, &index) == FAILURE) {
214        return;
215    }
216    if (index >= 0) {
217        intern = Z_DOMOBJ_P(id);
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);
256URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
257Since: DOM Level 2
258*/
259PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
260{
261    zval *id;
262    int ret;
263    size_t namedlen=0, urilen=0;
264    dom_object *intern;
265    xmlNodePtr itemnode = NULL;
266    char *uri, *named;
267
268    dom_nnodemap_object *objmap;
269    xmlNodePtr nodep;
270    xmlNotation *notep = NULL;
271
272    if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_namednodemap_class_entry, &uri, &urilen, &named, &namedlen) == FAILURE) {
273        return;
274    }
275
276    intern = Z_DOMOBJ_P(id);
277
278    objmap = (dom_nnodemap_object *)intern->ptr;
279
280    if (objmap != NULL) {
281        if ((objmap->nodetype == XML_NOTATION_NODE) ||
282            objmap->nodetype == XML_ENTITY_NODE) {
283            if (objmap->ht) {
284                if (objmap->nodetype == XML_ENTITY_NODE) {
285                    itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, (xmlChar *) named);
286                } else {
287                    notep = (xmlNotation *)xmlHashLookup(objmap->ht, (xmlChar *) named);
288                    if (notep) {
289                        itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
290                    }
291                }
292            }
293        } else {
294            nodep = dom_object_get_node(objmap->baseobj);
295            if (nodep) {
296                itemnode = (xmlNodePtr)xmlHasNsProp(nodep, (xmlChar *) named, (xmlChar *) uri);
297            }
298        }
299    }
300
301    if (itemnode) {
302        DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
303        return;
304    } else {
305        RETVAL_NULL();
306    }
307}
308/* }}} end dom_namednodemap_get_named_item_ns */
309
310/* {{{ proto DOMNode dom_namednodemap_set_named_item_ns(DOMNode arg);
311URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
312Since: DOM Level 2
313*/
314PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
315{
316 DOM_NOT_IMPLEMENTED();
317}
318/* }}} end dom_namednodemap_set_named_item_ns */
319
320/* {{{ proto DOMNode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
321URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
322Since: DOM Level 2
323*/
324PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
325{
326 DOM_NOT_IMPLEMENTED();
327}
328/* }}} end dom_namednodemap_remove_named_item_ns */
329
330#endif
331
332/*
333 * Local variables:
334 * tab-width: 4
335 * c-basic-offset: 4
336 * End:
337 * vim600: noet sw=4 ts=4 fdm=marker
338 * vim<600: noet sw=4 ts=4
339 */
340