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