1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Christian Stocker <chregu@php.net> |
14 | Rob Richards <rrichards@php.net> |
15 +----------------------------------------------------------------------+
16 */
17
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include "php.h"
23 #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
24 #include "php_dom.h"
25
26 /*
27 * class DOMProcessingInstruction extends DOMNode
28 *
29 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
30 * Since:
31 */
32
33 /* {{{ */
PHP_METHOD(DOMProcessingInstruction,__construct)34 PHP_METHOD(DOMProcessingInstruction, __construct)
35 {
36 xmlNodePtr nodep = NULL, oldnode = NULL;
37 dom_object *intern;
38 char *name, *value = NULL;
39 size_t name_len, value_len;
40 int name_valid;
41
42 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
43 RETURN_THROWS();
44 }
45
46 name_valid = xmlValidateName((xmlChar *) name, 0);
47 if (name_valid != 0) {
48 php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
49 RETURN_THROWS();
50 }
51
52 nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
53
54 if (!nodep) {
55 php_dom_throw_error(INVALID_STATE_ERR, 1);
56 RETURN_THROWS();
57 }
58
59 intern = Z_DOMOBJ_P(ZEND_THIS);
60 oldnode = dom_object_get_node(intern);
61 if (oldnode != NULL) {
62 php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
63 }
64 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
65 }
66 /* }}} end DOMProcessingInstruction::__construct */
67
68 /* {{{ target string
69 readonly=yes
70 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
71 Since:
72 */
dom_processinginstruction_target_read(dom_object * obj,zval * retval)73 int dom_processinginstruction_target_read(dom_object *obj, zval *retval)
74 {
75 xmlNodePtr nodep = dom_object_get_node(obj);
76
77 if (nodep == NULL) {
78 php_dom_throw_error(INVALID_STATE_ERR, 1);
79 return FAILURE;
80 }
81
82 ZVAL_STRING(retval, (char *) (nodep->name));
83
84 return SUCCESS;
85 }
86
87 /* }}} */
88
89 /* {{{ data string
90 readonly=no
91 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
92 Since:
93 */
dom_processinginstruction_data_read(dom_object * obj,zval * retval)94 int dom_processinginstruction_data_read(dom_object *obj, zval *retval)
95 {
96 xmlNodePtr nodep = dom_object_get_node(obj);
97
98 if (nodep == NULL) {
99 php_dom_throw_error(INVALID_STATE_ERR, 1);
100 return FAILURE;
101 }
102
103 php_dom_get_content_into_zval(nodep, retval, false);
104
105 return SUCCESS;
106 }
107
dom_processinginstruction_data_write(dom_object * obj,zval * newval)108 int dom_processinginstruction_data_write(dom_object *obj, zval *newval)
109 {
110 xmlNode *nodep = dom_object_get_node(obj);
111
112 if (nodep == NULL) {
113 php_dom_throw_error(INVALID_STATE_ERR, 1);
114 return FAILURE;
115 }
116
117 /* Typed property, this is already a string */
118 ZEND_ASSERT(Z_TYPE_P(newval) == IS_STRING);
119 zend_string *str = Z_STR_P(newval);
120
121 xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));
122
123 return SUCCESS;
124 }
125
126 /* }}} */
127
128 #endif
129