1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 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: processinginstruction.c 272374 2008-12-31 11:17:49Z sebastian $ */
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 :
31 : /* {{{ arginfo */
32 : static
33 : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_processinginstruction_construct, 0, 0, 1)
34 : ZEND_ARG_INFO(0, name)
35 : ZEND_ARG_INFO(0, value)
36 : ZEND_END_ARG_INFO();
37 : /* }}} */
38 :
39 : /*
40 : * class DOMProcessingInstruction extends DOMNode
41 : *
42 : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
43 : * Since:
44 : */
45 :
46 : zend_function_entry php_dom_processinginstruction_class_functions[] = {
47 : PHP_ME(domprocessinginstruction, __construct, arginfo_dom_processinginstruction_construct, ZEND_ACC_PUBLIC)
48 : {NULL, NULL, NULL}
49 : };
50 :
51 : /* {{{ proto void DOMProcessingInstruction::__construct(string name, [string value]); */
52 : PHP_METHOD(domprocessinginstruction, __construct)
53 0 : {
54 :
55 : zval *id;
56 0 : xmlNodePtr nodep = NULL, oldnode = NULL;
57 : dom_object *intern;
58 0 : char *name, *value = NULL;
59 : int name_len, value_len, name_valid;
60 :
61 0 : php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
62 0 : 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) {
63 0 : php_std_error_handling();
64 0 : return;
65 : }
66 :
67 0 : php_std_error_handling();
68 :
69 0 : name_valid = xmlValidateName((xmlChar *) name, 0);
70 0 : if (name_valid != 0) {
71 0 : php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
72 0 : RETURN_FALSE;
73 : }
74 :
75 0 : nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
76 :
77 0 : if (!nodep) {
78 0 : php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
79 0 : RETURN_FALSE;
80 : }
81 :
82 0 : intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
83 0 : if (intern != NULL) {
84 0 : oldnode = dom_object_get_node(intern);
85 0 : if (oldnode != NULL) {
86 0 : php_libxml_node_free_resource(oldnode TSRMLS_CC);
87 : }
88 0 : php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
89 : }
90 : }
91 : /* }}} end DOMProcessingInstruction::__construct */
92 :
93 : /* {{{ target string
94 : readonly=yes
95 : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
96 : Since:
97 : */
98 : int dom_processinginstruction_target_read(dom_object *obj, zval **retval TSRMLS_DC)
99 0 : {
100 : xmlNodePtr nodep;
101 :
102 0 : nodep = dom_object_get_node(obj);
103 :
104 0 : if (nodep == NULL) {
105 0 : php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
106 0 : return FAILURE;
107 : }
108 :
109 0 : ALLOC_ZVAL(*retval);
110 0 : ZVAL_STRING(*retval, (char *) (nodep->name), 1);
111 :
112 0 : return SUCCESS;
113 : }
114 :
115 : /* }}} */
116 :
117 :
118 :
119 : /* {{{ data string
120 : readonly=no
121 : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
122 : Since:
123 : */
124 : int dom_processinginstruction_data_read(dom_object *obj, zval **retval TSRMLS_DC)
125 0 : {
126 : xmlNodePtr nodep;
127 : xmlChar *content;
128 :
129 0 : nodep = dom_object_get_node(obj);
130 :
131 0 : if (nodep == NULL) {
132 0 : php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
133 0 : return FAILURE;
134 : }
135 :
136 0 : ALLOC_ZVAL(*retval);
137 :
138 :
139 0 : if ((content = xmlNodeGetContent(nodep)) != NULL) {
140 0 : ZVAL_STRING(*retval, content, 1);
141 0 : xmlFree(content);
142 : } else {
143 0 : ZVAL_EMPTY_STRING(*retval);
144 : }
145 :
146 0 : return SUCCESS;
147 : }
148 :
149 : int dom_processinginstruction_data_write(dom_object *obj, zval *newval TSRMLS_DC)
150 0 : {
151 : zval value_copy;
152 : xmlNode *nodep;
153 :
154 0 : nodep = dom_object_get_node(obj);
155 :
156 0 : if (nodep == NULL) {
157 0 : php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
158 0 : return FAILURE;
159 : }
160 :
161 0 : if (newval->type != IS_STRING) {
162 0 : if(newval->refcount > 1) {
163 0 : value_copy = *newval;
164 0 : zval_copy_ctor(&value_copy);
165 0 : newval = &value_copy;
166 : }
167 0 : convert_to_string(newval);
168 : }
169 :
170 0 : xmlNodeSetContentLen(nodep, Z_STRVAL_P(newval), Z_STRLEN_P(newval) + 1);
171 :
172 0 : if (newval == &value_copy) {
173 0 : zval_dtor(newval);
174 : }
175 :
176 0 : return SUCCESS;
177 : }
178 :
179 : /* }}} */
180 :
181 : #endif
|