1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2017 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
31 /* {{{ arginfo */
32 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_processinginstruction_construct, 0, 0, 1)
33 ZEND_ARG_INFO(0, name)
34 ZEND_ARG_INFO(0, value)
35 ZEND_END_ARG_INFO();
36 /* }}} */
37
38 /*
39 * class DOMProcessingInstruction extends DOMNode
40 *
41 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
42 * Since:
43 */
44
45 const zend_function_entry php_dom_processinginstruction_class_functions[] = {
46 PHP_ME(domprocessinginstruction, __construct, arginfo_dom_processinginstruction_construct, ZEND_ACC_PUBLIC)
47 PHP_FE_END
48 };
49
50 /* {{{ proto void DOMProcessingInstruction::__construct(string name, [string value]); */
PHP_METHOD(domprocessinginstruction,__construct)51 PHP_METHOD(domprocessinginstruction, __construct)
52 {
53 zval *id = getThis();
54 xmlNodePtr nodep = NULL, oldnode = NULL;
55 dom_object *intern;
56 char *name, *value = NULL;
57 size_t name_len, value_len;
58 int name_valid;
59
60 if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
61 return;
62 }
63
64 name_valid = xmlValidateName((xmlChar *) name, 0);
65 if (name_valid != 0) {
66 php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
67 RETURN_FALSE;
68 }
69
70 nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
71
72 if (!nodep) {
73 php_dom_throw_error(INVALID_STATE_ERR, 1);
74 RETURN_FALSE;
75 }
76
77 intern = Z_DOMOBJ_P(id);
78 oldnode = dom_object_get_node(intern);
79 if (oldnode != NULL) {
80 php_libxml_node_free_resource(oldnode );
81 }
82 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
83 }
84 /* }}} end DOMProcessingInstruction::__construct */
85
86 /* {{{ target string
87 readonly=yes
88 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
89 Since:
90 */
dom_processinginstruction_target_read(dom_object * obj,zval * retval)91 int dom_processinginstruction_target_read(dom_object *obj, zval *retval)
92 {
93 xmlNodePtr nodep = dom_object_get_node(obj);
94
95 if (nodep == NULL) {
96 php_dom_throw_error(INVALID_STATE_ERR, 0);
97 return FAILURE;
98 }
99
100 ZVAL_STRING(retval, (char *) (nodep->name));
101
102 return SUCCESS;
103 }
104
105 /* }}} */
106
107 /* {{{ data string
108 readonly=no
109 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
110 Since:
111 */
dom_processinginstruction_data_read(dom_object * obj,zval * retval)112 int dom_processinginstruction_data_read(dom_object *obj, zval *retval)
113 {
114 xmlNodePtr nodep;
115 xmlChar *content;
116
117 nodep = dom_object_get_node(obj);
118
119 if (nodep == NULL) {
120 php_dom_throw_error(INVALID_STATE_ERR, 0);
121 return FAILURE;
122 }
123
124 if ((content = xmlNodeGetContent(nodep)) != NULL) {
125 ZVAL_STRING(retval, (char *) content);
126 xmlFree(content);
127 } else {
128 ZVAL_EMPTY_STRING(retval);
129 }
130
131 return SUCCESS;
132 }
133
dom_processinginstruction_data_write(dom_object * obj,zval * newval)134 int dom_processinginstruction_data_write(dom_object *obj, zval *newval)
135 {
136 xmlNode *nodep = dom_object_get_node(obj);
137 zend_string *str;
138
139 if (nodep == NULL) {
140 php_dom_throw_error(INVALID_STATE_ERR, 0);
141 return FAILURE;
142 }
143
144 str = zval_get_string(newval);
145
146 xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
147
148 zend_string_release(str);
149 return SUCCESS;
150 }
151
152 /* }}} */
153
154 #endif
155
156 /*
157 * Local variables:
158 * tab-width: 4
159 * c-basic-offset: 4
160 * End:
161 * vim600: noet sw=4 ts=4 fdm=marker
162 * vim<600: noet sw=4 ts=4
163 */
164