Back to index

php5  5.3.10
namednodemap.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Christian Stocker <chregu@php.net>                          |
00016    |          Rob Richards <rrichards@php.net>                            |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: namednodemap.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025 
00026 #include "php.h"
00027 #if HAVE_LIBXML && HAVE_DOM
00028 #include "php_dom.h"
00029 
00030 /* {{{ arginfo */
00031 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item, 0, 0, 1)
00032        ZEND_ARG_INFO(0, name)
00033 ZEND_END_ARG_INFO();
00034 
00035 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item, 0, 0, 1)
00036        ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
00037 ZEND_END_ARG_INFO();
00038 
00039 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item, 0, 0, 0)
00040        ZEND_ARG_INFO(0, name)
00041 ZEND_END_ARG_INFO();
00042 
00043 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_item, 0, 0, 0)
00044        ZEND_ARG_INFO(0, index)
00045 ZEND_END_ARG_INFO();
00046 
00047 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_get_named_item_ns, 0, 0, 0)
00048        ZEND_ARG_INFO(0, namespaceURI)
00049        ZEND_ARG_INFO(0, localName)
00050 ZEND_END_ARG_INFO();
00051 
00052 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_set_named_item_ns, 0, 0, 0)
00053        ZEND_ARG_OBJ_INFO(0, arg, DOMNode, 0)
00054 ZEND_END_ARG_INFO();
00055 
00056 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item_ns, 0, 0, 0)
00057        ZEND_ARG_INFO(0, namespaceURI)
00058        ZEND_ARG_INFO(0, localName)
00059 ZEND_END_ARG_INFO();
00060 /* }}} */
00061 
00062 /*
00063 * class DOMNamedNodeMap 
00064 *
00065 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1780488922
00066 * Since: 
00067 */
00068 
00069 const zend_function_entry php_dom_namednodemap_class_functions[] = { /* {{{ */
00070        PHP_FALIAS(getNamedItem, dom_namednodemap_get_named_item, arginfo_dom_namednodemap_get_named_item)
00071        PHP_FALIAS(setNamedItem, dom_namednodemap_set_named_item, arginfo_dom_namednodemap_set_named_item)
00072        PHP_FALIAS(removeNamedItem, dom_namednodemap_remove_named_item, arginfo_dom_namednodemap_remove_named_item)
00073        PHP_FALIAS(item, dom_namednodemap_item, arginfo_dom_namednodemap_item)
00074        PHP_FALIAS(getNamedItemNS, dom_namednodemap_get_named_item_ns, arginfo_dom_namednodemap_get_named_item_ns)
00075        PHP_FALIAS(setNamedItemNS, dom_namednodemap_set_named_item_ns, arginfo_dom_namednodemap_set_named_item_ns)
00076        PHP_FALIAS(removeNamedItemNS, dom_namednodemap_remove_named_item_ns, arginfo_dom_namednodemap_remove_named_item_ns)
00077        PHP_FE_END
00078 };
00079 /* }}} */
00080 
00081 /* {{{ length int    
00082 readonly=yes 
00083 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6D0FB19E
00084 Since: 
00085 */
00086 int dom_namednodemap_length_read(dom_object *obj, zval **retval TSRMLS_DC)
00087 {
00088        dom_nnodemap_object *objmap;
00089        xmlAttrPtr curnode;
00090        xmlNodePtr nodep;
00091        int count = 0;
00092 
00093        objmap = (dom_nnodemap_object *)obj->ptr;
00094 
00095        if (objmap != NULL) {
00096               if ((objmap->nodetype == XML_NOTATION_NODE) || 
00097                      objmap->nodetype == XML_ENTITY_NODE) {
00098                      if (objmap->ht) {
00099                             count = xmlHashSize(objmap->ht);
00100                      }
00101               } else {
00102                      nodep = dom_object_get_node(objmap->baseobj);
00103                      if (nodep) {
00104                             curnode = nodep->properties;
00105                             if (curnode) {
00106                                    count++;
00107                                    while (curnode->next != NULL) {
00108                                           count++;
00109                                           curnode = curnode->next;
00110                                    }
00111                             }
00112                      }
00113               }
00114        }
00115 
00116        MAKE_STD_ZVAL(*retval);
00117        ZVAL_LONG(*retval, count);
00118        return SUCCESS;
00119 }
00120 
00121 /* }}} */
00122 
00123 /* {{{ proto DOMNode dom_namednodemap_get_named_item(string name);
00124 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549
00125 Since: 
00126 */
00127 PHP_FUNCTION(dom_namednodemap_get_named_item)
00128 {
00129        zval *id, *rv = NULL;
00130        int ret, namedlen=0;
00131        dom_object *intern;
00132        xmlNodePtr itemnode = NULL;
00133        char *named;
00134 
00135        dom_nnodemap_object *objmap;
00136        xmlNodePtr nodep;
00137        xmlNotation *notep = NULL;
00138 
00139        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_namednodemap_class_entry, &named, &namedlen) == FAILURE) {
00140               return;
00141        }
00142 
00143        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
00144 
00145        objmap = (dom_nnodemap_object *)intern->ptr;
00146 
00147        if (objmap != NULL) {
00148               if ((objmap->nodetype == XML_NOTATION_NODE) || 
00149                      objmap->nodetype == XML_ENTITY_NODE) {
00150                      if (objmap->ht) {
00151                             if (objmap->nodetype == XML_ENTITY_NODE) {
00152                                    itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named);
00153                             } else {
00154                                    notep = (xmlNotation *)xmlHashLookup(objmap->ht, named);
00155                                    if (notep) {
00156                                           itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
00157                                    }
00158                             }
00159                      }
00160               } else {
00161                      nodep = dom_object_get_node(objmap->baseobj);
00162                      if (nodep) {
00163                             itemnode = (xmlNodePtr)xmlHasProp(nodep, named);
00164                      }
00165               }
00166        }
00167 
00168        if (itemnode) {
00169               DOM_RET_OBJ(rv, itemnode, &ret, objmap->baseobj);
00170               return;
00171        } else {
00172               RETVAL_NULL();
00173        }
00174 }
00175 /* }}} end dom_namednodemap_get_named_item */
00176 
00177 /* {{{ proto DOMNode dom_namednodemap_set_named_item(DOMNode arg);
00178 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1025163788
00179 Since: 
00180 */
00181 PHP_FUNCTION(dom_namednodemap_set_named_item)
00182 {
00183  DOM_NOT_IMPLEMENTED();
00184 }
00185 /* }}} end dom_namednodemap_set_named_item */
00186 
00187 /* {{{ proto DOMNode dom_namednodemap_remove_named_item(string name);
00188 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D58B193
00189 Since: 
00190 */
00191 PHP_FUNCTION(dom_namednodemap_remove_named_item)
00192 {
00193  DOM_NOT_IMPLEMENTED();
00194 }
00195 /* }}} end dom_namednodemap_remove_named_item */
00196 
00197 /* {{{ proto DOMNode dom_namednodemap_item(int index);
00198 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-349467F9
00199 Since: 
00200 */
00201 PHP_FUNCTION(dom_namednodemap_item)
00202 {
00203        zval *id, *rv = NULL;
00204        long index;
00205        int ret;
00206        dom_object *intern;
00207        xmlNodePtr itemnode = NULL;
00208 
00209        dom_nnodemap_object *objmap;
00210        xmlNodePtr nodep, curnode;
00211        int count;
00212 
00213        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &id, dom_namednodemap_class_entry, &index) == FAILURE) {
00214               return;
00215        }
00216        if (index >= 0) {
00217               intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
00218 
00219               objmap = (dom_nnodemap_object *)intern->ptr;
00220 
00221               if (objmap != NULL) {
00222                      if ((objmap->nodetype == XML_NOTATION_NODE) || 
00223                             objmap->nodetype == XML_ENTITY_NODE) {
00224                             if (objmap->ht) {
00225                                    if (objmap->nodetype == XML_ENTITY_NODE) {
00226                                           itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
00227                                    } else {
00228                                           itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
00229                                    }
00230                             }
00231                      } else {
00232                             nodep = dom_object_get_node(objmap->baseobj);
00233                             if (nodep) {
00234                                    curnode = (xmlNodePtr)nodep->properties;
00235                                    count = 0;
00236                                    while (count < index && curnode != NULL) {
00237                                           count++;
00238                                           curnode = (xmlNodePtr)curnode->next;
00239                                    }
00240                                    itemnode = curnode;
00241                             }
00242                      }
00243               }
00244 
00245               if (itemnode) {
00246                      DOM_RET_OBJ(rv, itemnode, &ret, objmap->baseobj);
00247                      return;
00248               }
00249        }
00250 
00251        RETVAL_NULL();
00252 }
00253 /* }}} end dom_namednodemap_item */
00254 
00255 /* {{{ proto DOMNode dom_namednodemap_get_named_item_ns(string namespaceURI, string localName);
00256 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getNamedItemNS
00257 Since: DOM Level 2
00258 */
00259 PHP_FUNCTION(dom_namednodemap_get_named_item_ns)
00260 {
00261        zval *id, *rv = NULL;
00262        int ret, namedlen=0, urilen=0;
00263        dom_object *intern;
00264        xmlNodePtr itemnode = NULL;
00265        char *uri, *named;
00266 
00267        dom_nnodemap_object *objmap;
00268        xmlNodePtr nodep;
00269        xmlNotation *notep = NULL;
00270 
00271        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_namednodemap_class_entry, &uri, &urilen, &named, &namedlen) == FAILURE) {
00272               return;
00273        }
00274 
00275        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
00276 
00277        objmap = (dom_nnodemap_object *)intern->ptr;
00278 
00279        if (objmap != NULL) {
00280               if ((objmap->nodetype == XML_NOTATION_NODE) || 
00281                      objmap->nodetype == XML_ENTITY_NODE) {
00282                      if (objmap->ht) {
00283                             if (objmap->nodetype == XML_ENTITY_NODE) {
00284                                    itemnode = (xmlNodePtr)xmlHashLookup(objmap->ht, named);
00285                             } else {
00286                                    notep = (xmlNotation *)xmlHashLookup(objmap->ht, named);
00287                                    if (notep) {
00288                                           itemnode = create_notation(notep->name, notep->PublicID, notep->SystemID);
00289                                    }
00290                             }
00291                      }
00292               } else {
00293                      nodep = dom_object_get_node(objmap->baseobj);
00294                      if (nodep) {
00295                             itemnode = (xmlNodePtr)xmlHasNsProp(nodep, named, uri);
00296                      }
00297               }
00298        }
00299 
00300        if (itemnode) {
00301               DOM_RET_OBJ(rv, itemnode, &ret, objmap->baseobj);
00302               return;
00303        } else {
00304               RETVAL_NULL();
00305        }
00306 }
00307 /* }}} end dom_namednodemap_get_named_item_ns */
00308 
00309 /* {{{ proto DOMNode dom_namednodemap_set_named_item_ns(DOMNode arg);
00310 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-setNamedItemNS
00311 Since: DOM Level 2
00312 */
00313 PHP_FUNCTION(dom_namednodemap_set_named_item_ns)
00314 {
00315  DOM_NOT_IMPLEMENTED();
00316 }
00317 /* }}} end dom_namednodemap_set_named_item_ns */
00318 
00319 /* {{{ proto DOMNode dom_namednodemap_remove_named_item_ns(string namespaceURI, string localName);
00320 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-removeNamedItemNS
00321 Since: DOM Level 2
00322 */
00323 PHP_FUNCTION(dom_namednodemap_remove_named_item_ns)
00324 {
00325  DOM_NOT_IMPLEMENTED();
00326 }
00327 /* }}} end dom_namednodemap_remove_named_item_ns */
00328 
00329 #endif
00330 
00331 /*
00332  * Local variables:
00333  * tab-width: 4
00334  * c-basic-offset: 4
00335  * End:
00336  * vim600: noet sw=4 ts=4 fdm=marker
00337  * vim<600: noet sw=4 ts=4
00338  */