1 /* Dummy handler functions for the Expat test suite
2 __ __ _
3 ___\ \/ /_ __ __ _| |_
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
7 |_| XML parser
8
9 Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
10 Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
11 Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
12 Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
13 Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
14 Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
15 Copyright (c) 2017 Joe Orton <jorton@redhat.com>
16 Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
17 Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
18 Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
19 Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
20 Copyright (c) 2021 Donghee Na <donghee.na@python.org>
21 Licensed under the MIT license:
22
23 Permission is hereby granted, free of charge, to any person obtaining
24 a copy of this software and associated documentation files (the
25 "Software"), to deal in the Software without restriction, including
26 without limitation the rights to use, copy, modify, merge, publish,
27 distribute, sublicense, and/or sell copies of the Software, and to permit
28 persons to whom the Software is furnished to do so, subject to the
29 following conditions:
30
31 The above copyright notice and this permission notice shall be included
32 in all copies or substantial portions of the Software.
33
34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
37 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
38 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
39 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
40 USE OR OTHER DEALINGS IN THE SOFTWARE.
41 */
42
43 #include "expat.h"
44 #include "internal.h"
45 #include "common.h"
46 #include "dummy.h"
47
48 /* Dummy handlers for when we need to set a handler to tickle a bug,
49 but it doesn't need to do anything.
50 */
51 static unsigned long dummy_handler_flags = 0;
52
53 void
init_dummy_handlers(void)54 init_dummy_handlers(void) {
55 dummy_handler_flags = 0;
56 }
57
58 unsigned long
get_dummy_handler_flags(void)59 get_dummy_handler_flags(void) {
60 return dummy_handler_flags;
61 }
62
63 void XMLCALL
dummy_xdecl_handler(void * userData,const XML_Char * version,const XML_Char * encoding,int standalone)64 dummy_xdecl_handler(void *userData, const XML_Char *version,
65 const XML_Char *encoding, int standalone) {
66 UNUSED_P(userData);
67 UNUSED_P(version);
68 UNUSED_P(encoding);
69 UNUSED_P(standalone);
70 }
71
72 void XMLCALL
dummy_start_doctype_handler(void * userData,const XML_Char * doctypeName,const XML_Char * sysid,const XML_Char * pubid,int has_internal_subset)73 dummy_start_doctype_handler(void *userData, const XML_Char *doctypeName,
74 const XML_Char *sysid, const XML_Char *pubid,
75 int has_internal_subset) {
76 UNUSED_P(userData);
77 UNUSED_P(doctypeName);
78 UNUSED_P(sysid);
79 UNUSED_P(pubid);
80 UNUSED_P(has_internal_subset);
81 dummy_handler_flags |= DUMMY_START_DOCTYPE_HANDLER_FLAG;
82 }
83
84 void XMLCALL
dummy_end_doctype_handler(void * userData)85 dummy_end_doctype_handler(void *userData) {
86 UNUSED_P(userData);
87 dummy_handler_flags |= DUMMY_END_DOCTYPE_HANDLER_FLAG;
88 }
89
90 void XMLCALL
dummy_entity_decl_handler(void * userData,const XML_Char * entityName,int is_parameter_entity,const XML_Char * value,int value_length,const XML_Char * base,const XML_Char * systemId,const XML_Char * publicId,const XML_Char * notationName)91 dummy_entity_decl_handler(void *userData, const XML_Char *entityName,
92 int is_parameter_entity, const XML_Char *value,
93 int value_length, const XML_Char *base,
94 const XML_Char *systemId, const XML_Char *publicId,
95 const XML_Char *notationName) {
96 UNUSED_P(userData);
97 UNUSED_P(entityName);
98 UNUSED_P(is_parameter_entity);
99 UNUSED_P(value);
100 UNUSED_P(value_length);
101 UNUSED_P(base);
102 UNUSED_P(systemId);
103 UNUSED_P(publicId);
104 UNUSED_P(notationName);
105 dummy_handler_flags |= DUMMY_ENTITY_DECL_HANDLER_FLAG;
106 }
107
108 void XMLCALL
dummy_notation_decl_handler(void * userData,const XML_Char * notationName,const XML_Char * base,const XML_Char * systemId,const XML_Char * publicId)109 dummy_notation_decl_handler(void *userData, const XML_Char *notationName,
110 const XML_Char *base, const XML_Char *systemId,
111 const XML_Char *publicId) {
112 UNUSED_P(userData);
113 UNUSED_P(notationName);
114 UNUSED_P(base);
115 UNUSED_P(systemId);
116 UNUSED_P(publicId);
117 dummy_handler_flags |= DUMMY_NOTATION_DECL_HANDLER_FLAG;
118 }
119
120 void XMLCALL
dummy_element_decl_handler(void * userData,const XML_Char * name,XML_Content * model)121 dummy_element_decl_handler(void *userData, const XML_Char *name,
122 XML_Content *model) {
123 UNUSED_P(userData);
124 UNUSED_P(name);
125 /* The content model must be freed by the handler. Unfortunately
126 * we cannot pass the parser as the userData because this is used
127 * with other handlers that require other userData.
128 */
129 XML_FreeContentModel(g_parser, model);
130 dummy_handler_flags |= DUMMY_ELEMENT_DECL_HANDLER_FLAG;
131 }
132
133 void XMLCALL
dummy_attlist_decl_handler(void * userData,const XML_Char * elname,const XML_Char * attname,const XML_Char * att_type,const XML_Char * dflt,int isrequired)134 dummy_attlist_decl_handler(void *userData, const XML_Char *elname,
135 const XML_Char *attname, const XML_Char *att_type,
136 const XML_Char *dflt, int isrequired) {
137 UNUSED_P(userData);
138 UNUSED_P(elname);
139 UNUSED_P(attname);
140 UNUSED_P(att_type);
141 UNUSED_P(dflt);
142 UNUSED_P(isrequired);
143 dummy_handler_flags |= DUMMY_ATTLIST_DECL_HANDLER_FLAG;
144 }
145
146 void XMLCALL
dummy_comment_handler(void * userData,const XML_Char * data)147 dummy_comment_handler(void *userData, const XML_Char *data) {
148 UNUSED_P(userData);
149 UNUSED_P(data);
150 dummy_handler_flags |= DUMMY_COMMENT_HANDLER_FLAG;
151 }
152
153 void XMLCALL
dummy_pi_handler(void * userData,const XML_Char * target,const XML_Char * data)154 dummy_pi_handler(void *userData, const XML_Char *target, const XML_Char *data) {
155 UNUSED_P(userData);
156 UNUSED_P(target);
157 UNUSED_P(data);
158 dummy_handler_flags |= DUMMY_PI_HANDLER_FLAG;
159 }
160
161 void XMLCALL
dummy_start_element(void * userData,const XML_Char * name,const XML_Char ** atts)162 dummy_start_element(void *userData, const XML_Char *name,
163 const XML_Char **atts) {
164 UNUSED_P(userData);
165 UNUSED_P(name);
166 UNUSED_P(atts);
167 dummy_handler_flags |= DUMMY_START_ELEMENT_HANDLER_FLAG;
168 }
169
170 void XMLCALL
dummy_end_element(void * userData,const XML_Char * name)171 dummy_end_element(void *userData, const XML_Char *name) {
172 UNUSED_P(userData);
173 UNUSED_P(name);
174 }
175
176 void XMLCALL
dummy_start_cdata_handler(void * userData)177 dummy_start_cdata_handler(void *userData) {
178 UNUSED_P(userData);
179 dummy_handler_flags |= DUMMY_START_CDATA_HANDLER_FLAG;
180 }
181
182 void XMLCALL
dummy_end_cdata_handler(void * userData)183 dummy_end_cdata_handler(void *userData) {
184 UNUSED_P(userData);
185 dummy_handler_flags |= DUMMY_END_CDATA_HANDLER_FLAG;
186 }
187
188 void XMLCALL
dummy_cdata_handler(void * userData,const XML_Char * s,int len)189 dummy_cdata_handler(void *userData, const XML_Char *s, int len) {
190 UNUSED_P(userData);
191 UNUSED_P(s);
192 UNUSED_P(len);
193 }
194
195 void XMLCALL
dummy_start_namespace_decl_handler(void * userData,const XML_Char * prefix,const XML_Char * uri)196 dummy_start_namespace_decl_handler(void *userData, const XML_Char *prefix,
197 const XML_Char *uri) {
198 UNUSED_P(userData);
199 UNUSED_P(prefix);
200 UNUSED_P(uri);
201 dummy_handler_flags |= DUMMY_START_NS_DECL_HANDLER_FLAG;
202 }
203
204 void XMLCALL
dummy_end_namespace_decl_handler(void * userData,const XML_Char * prefix)205 dummy_end_namespace_decl_handler(void *userData, const XML_Char *prefix) {
206 UNUSED_P(userData);
207 UNUSED_P(prefix);
208 dummy_handler_flags |= DUMMY_END_NS_DECL_HANDLER_FLAG;
209 }
210
211 /* This handler is obsolete, but while the code exists we should
212 * ensure that dealing with the handler is covered by tests.
213 */
214 void XMLCALL
dummy_unparsed_entity_decl_handler(void * userData,const XML_Char * entityName,const XML_Char * base,const XML_Char * systemId,const XML_Char * publicId,const XML_Char * notationName)215 dummy_unparsed_entity_decl_handler(void *userData, const XML_Char *entityName,
216 const XML_Char *base,
217 const XML_Char *systemId,
218 const XML_Char *publicId,
219 const XML_Char *notationName) {
220 UNUSED_P(userData);
221 UNUSED_P(entityName);
222 UNUSED_P(base);
223 UNUSED_P(systemId);
224 UNUSED_P(publicId);
225 UNUSED_P(notationName);
226 dummy_handler_flags |= DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG;
227 }
228
229 void XMLCALL
dummy_default_handler(void * userData,const XML_Char * s,int len)230 dummy_default_handler(void *userData, const XML_Char *s, int len) {
231 UNUSED_P(userData);
232 UNUSED_P(s);
233 UNUSED_P(len);
234 }
235
236 void XMLCALL
dummy_start_doctype_decl_handler(void * userData,const XML_Char * doctypeName,const XML_Char * sysid,const XML_Char * pubid,int has_internal_subset)237 dummy_start_doctype_decl_handler(void *userData, const XML_Char *doctypeName,
238 const XML_Char *sysid, const XML_Char *pubid,
239 int has_internal_subset) {
240 UNUSED_P(userData);
241 UNUSED_P(doctypeName);
242 UNUSED_P(sysid);
243 UNUSED_P(pubid);
244 UNUSED_P(has_internal_subset);
245 dummy_handler_flags |= DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG;
246 }
247
248 void XMLCALL
dummy_end_doctype_decl_handler(void * userData)249 dummy_end_doctype_decl_handler(void *userData) {
250 UNUSED_P(userData);
251 dummy_handler_flags |= DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG;
252 }
253
254 void XMLCALL
dummy_skip_handler(void * userData,const XML_Char * entityName,int is_parameter_entity)255 dummy_skip_handler(void *userData, const XML_Char *entityName,
256 int is_parameter_entity) {
257 UNUSED_P(userData);
258 UNUSED_P(entityName);
259 UNUSED_P(is_parameter_entity);
260 dummy_handler_flags |= DUMMY_SKIP_HANDLER_FLAG;
261 }
262