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 * class DOMDocumentType extends DOMNode
32 *
33 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-412266927
34 * Since:
35 */
36
37 const zend_function_entry php_dom_documenttype_class_functions[] = {
38 PHP_FE_END
39 };
40
41 /* {{{ name string
42 readonly=yes
43 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1844763134
44 Since:
45 */
dom_documenttype_name_read(dom_object * obj,zval ** retval TSRMLS_DC)46 int dom_documenttype_name_read(dom_object *obj, zval **retval TSRMLS_DC)
47 {
48 xmlDtdPtr dtdptr;
49
50 dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
51
52 if (dtdptr == NULL) {
53 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
54 return FAILURE;
55 }
56
57 ALLOC_ZVAL(*retval);
58 ZVAL_STRING(*retval, (char *) (dtdptr->name), 1);
59
60 return SUCCESS;
61 }
62
63 /* }}} */
64
65 /* {{{ entities DOMNamedNodeMap
66 readonly=yes
67 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1788794630
68 Since:
69 */
dom_documenttype_entities_read(dom_object * obj,zval ** retval TSRMLS_DC)70 int dom_documenttype_entities_read(dom_object *obj, zval **retval TSRMLS_DC)
71 {
72 xmlDtdPtr doctypep;
73 xmlHashTable *entityht;
74 dom_object *intern;
75
76 doctypep = (xmlDtdPtr) dom_object_get_node(obj);
77
78 if (doctypep == NULL) {
79 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
80 return FAILURE;
81 }
82
83 MAKE_STD_ZVAL(*retval);
84 php_dom_create_interator(*retval, DOM_NAMEDNODEMAP TSRMLS_CC);
85
86 entityht = (xmlHashTable *) doctypep->entities;
87
88 intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
89 dom_namednode_iter(obj, XML_ENTITY_NODE, intern, entityht, NULL, NULL TSRMLS_CC);
90
91 return SUCCESS;
92 }
93
94 /* }}} */
95
96 /* {{{ notations DOMNamedNodeMap
97 readonly=yes
98 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D46829EF
99 Since:
100 */
dom_documenttype_notations_read(dom_object * obj,zval ** retval TSRMLS_DC)101 int dom_documenttype_notations_read(dom_object *obj, zval **retval TSRMLS_DC)
102 {
103 xmlDtdPtr doctypep;
104 xmlHashTable *notationht;
105 dom_object *intern;
106
107 doctypep = (xmlDtdPtr) dom_object_get_node(obj);
108
109 if (doctypep == NULL) {
110 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
111 return FAILURE;
112 }
113
114 MAKE_STD_ZVAL(*retval);
115 php_dom_create_interator(*retval, DOM_NAMEDNODEMAP TSRMLS_CC);
116
117 notationht = (xmlHashTable *) doctypep->notations;
118
119 intern = (dom_object *)zend_objects_get_address(*retval TSRMLS_CC);
120 dom_namednode_iter(obj, XML_NOTATION_NODE, intern, notationht, NULL, NULL TSRMLS_CC);
121
122 return SUCCESS;
123 }
124
125 /* }}} */
126
127 /* {{{ publicId string
128 readonly=yes
129 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-publicId
130 Since: DOM Level 2
131 */
dom_documenttype_public_id_read(dom_object * obj,zval ** retval TSRMLS_DC)132 int dom_documenttype_public_id_read(dom_object *obj, zval **retval TSRMLS_DC)
133 {
134 xmlDtdPtr dtdptr;
135
136 dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
137
138 if (dtdptr == NULL) {
139 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
140 return FAILURE;
141 }
142
143 ALLOC_ZVAL(*retval);
144 if (dtdptr->ExternalID) {
145 ZVAL_STRING(*retval, (char *) (dtdptr->ExternalID), 1);
146 } else {
147 ZVAL_EMPTY_STRING(*retval);
148 }
149 return SUCCESS;
150
151 }
152
153 /* }}} */
154
155 /* {{{ systemId string
156 readonly=yes
157 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-systemId
158 Since: DOM Level 2
159 */
dom_documenttype_system_id_read(dom_object * obj,zval ** retval TSRMLS_DC)160 int dom_documenttype_system_id_read(dom_object *obj, zval **retval TSRMLS_DC)
161 {
162 xmlDtdPtr dtdptr;
163
164 dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
165
166 if (dtdptr == NULL) {
167 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
168 return FAILURE;
169 }
170
171 ALLOC_ZVAL(*retval);
172 if (dtdptr->SystemID) {
173 ZVAL_STRING(*retval, (char *) (dtdptr->SystemID), 1);
174 } else {
175 ZVAL_EMPTY_STRING(*retval);
176 }
177 return SUCCESS;
178 }
179
180 /* }}} */
181
182 /* {{{ internalSubset string
183 readonly=yes
184 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-Core-DocType-internalSubset
185 Since: DOM Level 2
186 */
dom_documenttype_internal_subset_read(dom_object * obj,zval ** retval TSRMLS_DC)187 int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_DC)
188 {
189
190 xmlDtdPtr dtdptr;
191 xmlDtdPtr intsubset;
192
193 dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
194
195 if (dtdptr == NULL) {
196 php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
197 return FAILURE;
198 }
199
200 ALLOC_ZVAL(*retval);
201
202 if (dtdptr->doc != NULL && ((intsubset = xmlGetIntSubset(dtdptr->doc)) != NULL) && intsubset->children != NULL) {
203 smart_str ret_buf = {0};
204 xmlNodePtr cur = intsubset->children;
205
206 while (cur != NULL) {
207 xmlOutputBuffer *buff = xmlAllocOutputBuffer(NULL);
208
209 if (buff != NULL) {
210 xmlNodeDumpOutput (buff, NULL, cur, 0, 0, NULL);
211 xmlOutputBufferFlush(buff);
212
213 #ifdef LIBXML2_NEW_BUFFER
214 smart_str_appendl(&ret_buf, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff));
215 #else
216 smart_str_appendl(&ret_buf, buff->buffer->content, buff->buffer->use);
217 #endif
218
219 (void)xmlOutputBufferClose(buff);
220 }
221
222 cur = cur->next;
223 }
224
225 if (ret_buf.len) {
226 ZVAL_STRINGL(*retval, ret_buf.c, ret_buf.len, 1);
227 smart_str_free(&ret_buf);
228 return SUCCESS;
229 }
230 }
231
232 ZVAL_NULL(*retval);
233
234 return SUCCESS;
235
236 }
237
238 /* }}} */
239
240 #endif
241
242 /*
243 * Local variables:
244 * tab-width: 4
245 * c-basic-offset: 4
246 * End:
247 * vim600: noet sw=4 ts=4 fdm=marker
248 * vim<600: noet sw=4 ts=4
249 */
250