Back to index

php5  5.3.10
processinginstruction.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: processinginstruction.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 
00031 /* {{{ arginfo */
00032 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_processinginstruction_construct, 0, 0, 1)
00033        ZEND_ARG_INFO(0, name)
00034        ZEND_ARG_INFO(0, value)
00035 ZEND_END_ARG_INFO();
00036 /* }}} */
00037 
00038 /*
00039 * class DOMProcessingInstruction extends DOMNode 
00040 *
00041 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
00042 * Since: 
00043 */
00044 
00045 const zend_function_entry php_dom_processinginstruction_class_functions[] = {
00046        PHP_ME(domprocessinginstruction, __construct, arginfo_dom_processinginstruction_construct, ZEND_ACC_PUBLIC)
00047        PHP_FE_END
00048 };
00049 
00050 /* {{{ proto void DOMProcessingInstruction::__construct(string name, [string value]); */
00051 PHP_METHOD(domprocessinginstruction, __construct)
00052 {
00053 
00054        zval *id;
00055        xmlNodePtr nodep = NULL, oldnode = NULL;
00056        dom_object *intern;
00057        char *name, *value = NULL;
00058        int name_len, value_len, name_valid;
00059        zend_error_handling error_handling;
00060 
00061        zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
00062        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_processinginstruction_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
00063               zend_restore_error_handling(&error_handling TSRMLS_CC);
00064               return;
00065        }
00066 
00067        zend_restore_error_handling(&error_handling TSRMLS_CC);
00068 
00069        name_valid = xmlValidateName((xmlChar *) name, 0);
00070        if (name_valid != 0) {
00071               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
00072               RETURN_FALSE;
00073        }
00074 
00075        nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
00076 
00077        if (!nodep) {
00078               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
00079               RETURN_FALSE;
00080        }
00081 
00082        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
00083        if (intern != NULL) {
00084               oldnode = dom_object_get_node(intern);
00085               if (oldnode != NULL) {
00086                      php_libxml_node_free_resource(oldnode  TSRMLS_CC);
00087               }
00088               php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
00089        }
00090 }
00091 /* }}} end DOMProcessingInstruction::__construct */
00092 
00093 /* {{{ target string 
00094 readonly=yes 
00095 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
00096 Since: 
00097 */
00098 int dom_processinginstruction_target_read(dom_object *obj, zval **retval TSRMLS_DC)
00099 {
00100        xmlNodePtr nodep;
00101 
00102        nodep = dom_object_get_node(obj);
00103 
00104        if (nodep == NULL) {
00105               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00106               return FAILURE;
00107        }
00108 
00109        ALLOC_ZVAL(*retval);
00110        ZVAL_STRING(*retval, (char *) (nodep->name), 1);
00111 
00112        return SUCCESS;
00113 }
00114 
00115 /* }}} */
00116 
00117 /* {{{ data   string 
00118 readonly=no 
00119 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
00120 Since: 
00121 */
00122 int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC)
00123 {
00124        xmlNodePtr nodep;
00125        xmlChar *content;
00126 
00127        nodep = dom_object_get_node(obj);
00128 
00129        if (nodep == NULL) {
00130               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00131               return FAILURE;
00132        }
00133 
00134        ALLOC_ZVAL(*retval);
00135 
00136        
00137        if ((content = xmlNodeGetContent(nodep)) != NULL) {
00138               ZVAL_STRING(*retval, content, 1);
00139               xmlFree(content);
00140        } else {
00141               ZVAL_EMPTY_STRING(*retval);
00142        }
00143 
00144        return SUCCESS;
00145 }
00146 
00147 int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC)
00148 {
00149        zval value_copy;
00150        xmlNode *nodep;
00151 
00152        nodep = dom_object_get_node(obj);
00153 
00154        if (nodep == NULL) {
00155               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00156               return FAILURE;
00157        }
00158 
00159        if (newval->type != IS_STRING) {
00160               if(Z_REFCOUNT_P(newval) > 1) {
00161                      value_copy = *newval;
00162                      zval_copy_ctor(&value_copy);
00163                      newval = &value_copy;
00164               }
00165               convert_to_string(newval);
00166        }
00167 
00168        xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
00169 
00170        if (newval == &value_copy) {
00171               zval_dtor(newval);
00172        }
00173 
00174        return SUCCESS;
00175 }
00176 
00177 /* }}} */
00178 
00179 #endif
00180 
00181 /*
00182  * Local variables:
00183  * tab-width: 4
00184  * c-basic-offset: 4
00185  * End:
00186  * vim600: noet sw=4 ts=4 fdm=marker
00187  * vim<600: noet sw=4 ts=4
00188  */