xref: /PHP-8.1/ext/dom/entity.c (revision d439ee18)
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 /*
28 * class DOMEntity extends DOMNode
29 *
30 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-527DCFF2
31 * Since:
32 */
33 
34 /* {{{ publicId	string
35 readonly=yes
36 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7303025
37 Since:
38 */
dom_entity_public_id_read(dom_object * obj,zval * retval)39 int dom_entity_public_id_read(dom_object *obj, zval *retval)
40 {
41 	xmlEntity *nodep = (xmlEntity *) dom_object_get_node(obj);
42 
43 	if (nodep == NULL) {
44 		php_dom_throw_error(INVALID_STATE_ERR, 1);
45 		return FAILURE;
46 	}
47 
48 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY || !nodep->ExternalID) {
49 		ZVAL_NULL(retval);
50 	} else {
51 		ZVAL_STRING(retval, (char *) (nodep->ExternalID));
52 	}
53 
54 	return SUCCESS;
55 }
56 
57 /* }}} */
58 
59 /* {{{ systemId	string
60 readonly=yes
61 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7C29F3E
62 Since:
63 */
dom_entity_system_id_read(dom_object * obj,zval * retval)64 int dom_entity_system_id_read(dom_object *obj, zval *retval)
65 {
66 	xmlEntity *nodep = (xmlEntity *) dom_object_get_node(obj);
67 
68 	if (nodep == NULL) {
69 		php_dom_throw_error(INVALID_STATE_ERR, 1);
70 		return FAILURE;
71 	}
72 
73 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
74 		ZVAL_NULL(retval);
75 	} else {
76 		ZVAL_STRING(retval, (char *) (nodep->SystemID));
77 	}
78 
79 	return SUCCESS;
80 }
81 
82 /* }}} */
83 
84 /* {{{ notationName	string
85 readonly=yes
86 URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6ABAEB38
87 Since:
88 */
dom_entity_notation_name_read(dom_object * obj,zval * retval)89 int dom_entity_notation_name_read(dom_object *obj, zval *retval)
90 {
91 	xmlEntity *nodep = (xmlEntity *) dom_object_get_node(obj);
92 
93 	if (nodep == NULL) {
94 		php_dom_throw_error(INVALID_STATE_ERR, 1);
95 		return FAILURE;
96 	}
97 
98 	if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
99 		ZVAL_NULL(retval);
100 	} else {
101 		/* According to spec, NULL is only allowed for unparsed entities, if it's not set we should use the empty string. */
102 		if (!nodep->content) {
103 			ZVAL_EMPTY_STRING(retval);
104 		} else {
105 			ZVAL_STRING(retval, (const char *) nodep->content);
106 		}
107 	}
108 
109 	return SUCCESS;
110 }
111 
112 /* }}} */
113 
114 /* {{{ actualEncoding	string
115 readonly=yes
116 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-actualEncoding
117 Since: DOM Level 3
118 */
dom_entity_actual_encoding_read(dom_object * obj,zval * retval)119 int dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
120 {
121 	ZVAL_NULL(retval);
122 	return SUCCESS;
123 }
124 
125 /* }}} */
126 
127 /* {{{ encoding	string
128 readonly=yes
129 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-encoding
130 Since: DOM Level 3
131 */
dom_entity_encoding_read(dom_object * obj,zval * retval)132 int dom_entity_encoding_read(dom_object *obj, zval *retval)
133 {
134 	ZVAL_NULL(retval);
135 	return SUCCESS;
136 }
137 
138 /* }}} */
139 
140 /* {{{ version	string
141 readonly=yes
142 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Entity3-version
143 Since: DOM Level 3
144 */
dom_entity_version_read(dom_object * obj,zval * retval)145 int dom_entity_version_read(dom_object *obj, zval *retval)
146 {
147 	ZVAL_NULL(retval);
148 	return SUCCESS;
149 }
150 
151 /* }}} */
152 
153 #endif
154