1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
/* XML handler functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_HANDLERS_H
# define XML_HANDLERS_H
# include "expat_config.h"
# include "expat.h"
/* Variable holding the expected handler userData */
extern const void *g_handler_data;
/* Count of the number of times the comment handler has been invoked */
extern int g_comment_count;
/* Count of the number of skipped entities */
extern int g_skip_count;
/* Count of the number of times the XML declaration handler is invoked */
extern int g_xdecl_count;
/* Start/End Element Handlers */
extern void XMLCALL start_element_event_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL end_element_event_handler(void *userData,
const XML_Char *name);
# define STRUCT_START_TAG 0
# define STRUCT_END_TAG 1
extern void XMLCALL start_element_event_handler2(void *userData,
const XML_Char *name,
const XML_Char **attr);
extern void XMLCALL end_element_event_handler2(void *userData,
const XML_Char *name);
typedef struct attrInfo {
const XML_Char *name;
const XML_Char *value;
} AttrInfo;
typedef struct elementInfo {
const XML_Char *name;
int attr_count;
const XML_Char *id_name;
AttrInfo *attributes;
} ElementInfo;
typedef struct StructParserAndElementInfo {
XML_Parser parser;
ElementInfo *info;
} ParserAndElementInfo;
extern void XMLCALL counting_start_element_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL suspending_end_handler(void *userData, const XML_Char *s);
extern void XMLCALL start_element_suspender(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern int g_triplet_start_flag;
extern int g_triplet_end_flag;
extern void XMLCALL triplet_start_checker(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL triplet_end_checker(void *userData, const XML_Char *name);
extern void XMLCALL overwrite_start_checker(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL overwrite_end_checker(void *userData, const XML_Char *name);
extern void XMLCALL start_element_fail(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL start_ns_clearing_start_element(void *userData,
const XML_Char *prefix,
const XML_Char *uri);
typedef struct {
XML_Parser parser;
int deep;
} DataIssue240;
extern void XMLCALL start_element_issue_240(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL end_element_issue_240(void *userData, const XML_Char *name);
/* Text encoding handlers */
extern int XMLCALL UnknownEncodingHandler(void *data, const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL UnrecognisedEncodingHandler(void *data,
const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL unknown_released_encoding_handler(void *data,
const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL MiscEncodingHandler(void *data, const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL long_encoding_handler(void *userData,
const XML_Char *encoding,
XML_Encoding *info);
/* External Entity Handlers */
typedef struct ExtOption {
const XML_Char *system_id;
const char *parse_text;
} ExtOption;
extern int XMLCALL external_entity_optioner(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ext_faults {
const char *parse_text;
const char *fail_text;
const XML_Char *encoding;
enum XML_Error error;
} ExtFaults;
extern int XMLCALL external_entity_faulter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_failer__if_not_xml_ge(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
extern int XMLCALL external_entity_null_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_resetter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspender(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspend_xmldecl(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspending_faulter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_cr_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_bad_cr_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_rsqb_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_good_cdata_ascii(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* Entity declaration handlers */
extern void XMLCALL entity_suspending_decl_handler(void *userData,
const XML_Char *name,
XML_Content *model);
extern void XMLCALL entity_suspending_xdecl_handler(void *userData,
const XML_Char *version,
const XML_Char *encoding,
int standalone);
extern int XMLCALL external_entity_param_checker(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_ref_param_checker(XML_Parser parameter,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_param(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore_utf16(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore_utf16_be(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
extern int XMLCALL external_entity_valuer(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_not_standalone(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_value_aborter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_public(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_devaluer(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ext_hdlr_data {
const char *parse_text;
XML_ExternalEntityRefHandler handler;
} ExtHdlrData;
extern int XMLCALL external_entity_oneshot_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ExtTest2 {
const char *parse_text;
int parse_len;
const XML_Char *encoding;
CharData *storage;
} ExtTest2;
extern int XMLCALL external_entity_loader2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ExtFaults2 {
const char *parse_text;
int parse_len;
const char *fail_text;
const XML_Char *encoding;
enum XML_Error error;
} ExtFaults2;
extern int XMLCALL external_entity_faulter2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_unfinished_attlist(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_duff_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_dbl_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_dbl_handler_2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_alloc_set_encoding(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_reallocator(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_alloc(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_parser_create_alloc_fail_handler(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
struct AccountingTestCase {
const char *primaryText;
const char *firstExternalText; /* often NULL */
const char *secondExternalText; /* often NULL */
const unsigned long long expectedCountBytesIndirectExtra;
};
extern int accounting_external_entity_ref_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* NotStandalone handlers */
extern int XMLCALL reject_not_standalone_handler(void *userData);
extern int XMLCALL accept_not_standalone_handler(void *userData);
/* Attribute List handlers */
typedef struct AttTest {
const char *definition;
const XML_Char *element_name;
const XML_Char *attr_name;
const XML_Char *attr_type;
const XML_Char *default_value;
int is_required;
} AttTest;
extern void XMLCALL verify_attlist_decl_handler(
void *userData, const XML_Char *element_name, const XML_Char *attr_name,
const XML_Char *attr_type, const XML_Char *default_value, int is_required);
/* Character data handlers */
extern void XMLCALL clearing_aborting_character_handler(void *userData,
const XML_Char *s,
int len);
extern void XMLCALL parser_stop_character_handler(void *userData,
const XML_Char *s, int len);
extern void XMLCALL cr_cdata_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL rsqb_handler(void *userData, const XML_Char *s, int len);
typedef struct ByteTestData {
int start_element_len;
int cdata_len;
int total_string_len;
} ByteTestData;
extern void XMLCALL byte_character_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL ext2_accumulate_characters(void *userData,
const XML_Char *s, int len);
/* Handlers that record their `len` arg and a single identifying character */
struct handler_record_entry {
const char *name;
int arg;
};
struct handler_record_list {
int count;
struct handler_record_entry entries[50]; // arbitrary big-enough max count
};
extern void XMLCALL record_default_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL record_cdata_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL record_cdata_nodefault_handler(void *userData,
const XML_Char *s, int len);
extern void XMLCALL record_skip_handler(void *userData,
const XML_Char *entityName,
int is_parameter_entity);
extern void XMLCALL record_element_start_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL record_element_end_handler(void *userData,
const XML_Char *name);
extern const struct handler_record_entry *
_handler_record_get(const struct handler_record_list *storage, int index,
const char *file, int line);
# define handler_record_get(storage, index) \
_handler_record_get((storage), (index), __FILE__, __LINE__)
# define assert_record_handler_called(storage, index, expected_name, \
expected_arg) \
do { \
const struct handler_record_entry *e \
= handler_record_get(storage, index); \
assert_true(strcmp(e->name, expected_name) == 0); \
assert_true(e->arg == (expected_arg)); \
} while (0)
/* Entity Declaration Handlers */
# define ENTITY_MATCH_FAIL (-1)
# define ENTITY_MATCH_NOT_FOUND (0)
# define ENTITY_MATCH_SUCCESS (1)
extern void XMLCALL param_entity_match_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);
extern void param_entity_match_init(const XML_Char *name,
const XML_Char *value);
extern int get_param_entity_match_flag(void);
/* Misc handlers */
extern void XMLCALL xml_decl_handler(void *userData, const XML_Char *version,
const XML_Char *encoding, int standalone);
extern void XMLCALL param_check_skip_handler(void *userData,
const XML_Char *entityName,
int is_parameter_entity);
extern void XMLCALL data_check_comment_handler(void *userData,
const XML_Char *data);
extern void XMLCALL selective_aborting_default_handler(void *userData,
const XML_Char *s,
int len);
extern void XMLCALL suspending_comment_handler(void *userData,
const XML_Char *data);
extern void XMLCALL element_decl_suspender(void *userData, const XML_Char *name,
XML_Content *model);
extern void XMLCALL accumulate_pi_characters(void *userData,
const XML_Char *target,
const XML_Char *data);
extern void XMLCALL accumulate_comment(void *userData, const XML_Char *data);
extern void XMLCALL accumulate_entity_decl(
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);
extern void XMLCALL accumulate_start_element(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void XMLCALL accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL ext_accumulate_characters(void *userData, const XML_Char *s,
int len);
typedef struct default_check {
const XML_Char *expected;
const int expectedLen;
XML_Bool seen;
} DefaultCheck;
void XMLCALL checking_default_handler(void *userData, const XML_Char *s,
int len);
typedef struct {
XML_Parser parser;
CharData *storage;
} ParserPlusStorage;
extern void XMLCALL
accumulate_and_suspend_comment_handler(void *userData, const XML_Char *data);
#endif /* XML_HANDLERS_H */
#ifdef __cplusplus
}
#endif
|