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