namednodemap.c 9.6 KB

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