Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * error.c: module displaying/handling XML parser errors |
3 | | * |
4 | | * See Copyright for the status of this software. |
5 | | * |
6 | | * Daniel Veillard <daniel@veillard.com> |
7 | | */ |
8 | | |
9 | | #define IN_LIBXML |
10 | | #include "libxml.h" |
11 | | |
12 | | #include <string.h> |
13 | | #include <stdarg.h> |
14 | | #include <stdlib.h> |
15 | | #include <libxml/parser.h> |
16 | | #include <libxml/xmlerror.h> |
17 | | #include <libxml/xmlmemory.h> |
18 | | |
19 | | #include "private/error.h" |
20 | | #include "private/globals.h" |
21 | | #include "private/string.h" |
22 | | |
23 | | /************************************************************************ |
24 | | * * |
25 | | * Error struct * |
26 | | * * |
27 | | ************************************************************************/ |
28 | | |
29 | | static int |
30 | | xmlVSetError(xmlError *err, |
31 | | void *ctxt, xmlNodePtr node, |
32 | | int domain, int code, xmlErrorLevel level, |
33 | | const char *file, int line, |
34 | | const char *str1, const char *str2, const char *str3, |
35 | | int int1, int col, |
36 | | const char *fmt, va_list ap) |
37 | 912k | { |
38 | 912k | char *message = NULL; |
39 | 912k | char *fileCopy = NULL; |
40 | 912k | char *str1Copy = NULL; |
41 | 912k | char *str2Copy = NULL; |
42 | 912k | char *str3Copy = NULL; |
43 | | |
44 | 912k | if (code == XML_ERR_OK) { |
45 | 0 | xmlResetError(err); |
46 | 0 | return(0); |
47 | 0 | } |
48 | | |
49 | | /* |
50 | | * Formatting the message |
51 | | */ |
52 | 912k | if (fmt == NULL) { |
53 | 0 | message = xmlMemStrdup("No error message provided"); |
54 | 912k | } else { |
55 | 912k | xmlChar *tmp; |
56 | 912k | int res; |
57 | | |
58 | 912k | res = xmlStrVASPrintf(&tmp, MAX_ERR_MSG_SIZE, fmt, ap); |
59 | 912k | if (res < 0) |
60 | 0 | goto err_memory; |
61 | 912k | message = (char *) tmp; |
62 | 912k | } |
63 | 912k | if (message == NULL) |
64 | 0 | goto err_memory; |
65 | | |
66 | 912k | if (file != NULL) { |
67 | 432k | fileCopy = (char *) xmlStrdup((const xmlChar *) file); |
68 | 432k | if (fileCopy == NULL) |
69 | 0 | goto err_memory; |
70 | 432k | } |
71 | 912k | if (str1 != NULL) { |
72 | 439k | str1Copy = (char *) xmlStrdup((const xmlChar *) str1); |
73 | 439k | if (str1Copy == NULL) |
74 | 0 | goto err_memory; |
75 | 439k | } |
76 | 912k | if (str2 != NULL) { |
77 | 143k | str2Copy = (char *) xmlStrdup((const xmlChar *) str2); |
78 | 143k | if (str2Copy == NULL) |
79 | 0 | goto err_memory; |
80 | 143k | } |
81 | 912k | if (str3 != NULL) { |
82 | 45.2k | str3Copy = (char *) xmlStrdup((const xmlChar *) str3); |
83 | 45.2k | if (str3Copy == NULL) |
84 | 0 | goto err_memory; |
85 | 45.2k | } |
86 | | |
87 | 912k | xmlResetError(err); |
88 | | |
89 | 912k | err->domain = domain; |
90 | 912k | err->code = code; |
91 | 912k | err->message = message; |
92 | 912k | err->level = level; |
93 | 912k | err->file = fileCopy; |
94 | 912k | err->line = line; |
95 | 912k | err->str1 = str1Copy; |
96 | 912k | err->str2 = str2Copy; |
97 | 912k | err->str3 = str3Copy; |
98 | 912k | err->int1 = int1; |
99 | 912k | err->int2 = col; |
100 | 912k | err->node = node; |
101 | 912k | err->ctxt = ctxt; |
102 | | |
103 | 912k | return(0); |
104 | | |
105 | 0 | err_memory: |
106 | 0 | xmlFree(message); |
107 | 0 | xmlFree(fileCopy); |
108 | 0 | xmlFree(str1Copy); |
109 | 0 | xmlFree(str2Copy); |
110 | 0 | xmlFree(str3Copy); |
111 | 0 | return(-1); |
112 | 912k | } |
113 | | |
114 | | static int LIBXML_ATTR_FORMAT(14,15) |
115 | | xmlSetError(xmlError *err, |
116 | | void *ctxt, xmlNodePtr node, |
117 | | int domain, int code, xmlErrorLevel level, |
118 | | const char *file, int line, |
119 | | const char *str1, const char *str2, const char *str3, |
120 | | int int1, int col, |
121 | | const char *fmt, ...) |
122 | 456k | { |
123 | 456k | va_list ap; |
124 | 456k | int res; |
125 | | |
126 | 456k | va_start(ap, fmt); |
127 | 456k | res = xmlVSetError(err, ctxt, node, domain, code, level, file, line, |
128 | 456k | str1, str2, str3, int1, col, fmt, ap); |
129 | 456k | va_end(ap); |
130 | | |
131 | 456k | return(res); |
132 | 456k | } |
133 | | |
134 | | static int |
135 | | xmlVUpdateError(xmlError *err, |
136 | | void *ctxt, xmlNodePtr node, |
137 | | int domain, int code, xmlErrorLevel level, |
138 | | const char *file, int line, |
139 | | const char *str1, const char *str2, const char *str3, |
140 | | int int1, int col, |
141 | | const char *fmt, va_list ap) |
142 | 456k | { |
143 | 456k | int res; |
144 | | |
145 | | /* |
146 | | * Find first element parent. |
147 | | */ |
148 | 456k | if (node != NULL) { |
149 | 56.8k | int i; |
150 | | |
151 | 87.8k | for (i = 0; i < 10; i++) { |
152 | 87.8k | if ((node->type == XML_ELEMENT_NODE) || |
153 | 87.8k | (node->parent == NULL)) |
154 | 56.8k | break; |
155 | 31.0k | node = node->parent; |
156 | 31.0k | } |
157 | 56.8k | } |
158 | | |
159 | | /* |
160 | | * Get file and line from node. |
161 | | */ |
162 | 456k | if (node != NULL) { |
163 | 56.8k | if ((file == NULL) && (node->doc != NULL)) |
164 | 24.8k | file = (const char *) node->doc->URL; |
165 | | |
166 | 56.8k | if (line == 0) { |
167 | 0 | if (node->type == XML_ELEMENT_NODE) |
168 | 0 | line = node->line; |
169 | 0 | if ((line == 0) || (line == 65535)) |
170 | 0 | line = xmlGetLineNo(node); |
171 | 0 | } |
172 | 56.8k | } |
173 | | |
174 | 456k | res = xmlVSetError(err, ctxt, node, domain, code, level, file, line, |
175 | 456k | str1, str2, str3, int1, col, fmt, ap); |
176 | | |
177 | 456k | return(res); |
178 | 456k | } |
179 | | |
180 | | /************************************************************************ |
181 | | * * |
182 | | * Handling of out of context errors * |
183 | | * * |
184 | | ************************************************************************/ |
185 | | |
186 | | /** |
187 | | * xmlGenericErrorDefaultFunc: |
188 | | * @ctx: an error context |
189 | | * @msg: the message to display/transmit |
190 | | * @...: extra parameters for the message display |
191 | | * |
192 | | * Default handler for out of context error messages. |
193 | | */ |
194 | | void |
195 | 2.81M | xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { |
196 | 2.81M | va_list args; |
197 | | |
198 | 2.81M | if (xmlGenericErrorContext == NULL) |
199 | 9.88k | xmlGenericErrorContext = (void *) stderr; |
200 | | |
201 | 2.81M | va_start(args, msg); |
202 | 2.81M | vfprintf((FILE *)xmlGenericErrorContext, msg, args); |
203 | 2.81M | va_end(args); |
204 | 2.81M | } |
205 | | |
206 | | /** |
207 | | * initGenericErrorDefaultFunc: |
208 | | * @handler: the handler |
209 | | * |
210 | | * DEPRECATED: Use xmlSetGenericErrorFunc. |
211 | | * |
212 | | * Set or reset (if NULL) the default handler for generic errors |
213 | | * to the builtin error function. |
214 | | */ |
215 | | void |
216 | | initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler) |
217 | 0 | { |
218 | 0 | if (handler == NULL) |
219 | 0 | xmlGenericError = xmlGenericErrorDefaultFunc; |
220 | 0 | else |
221 | 0 | xmlGenericError = (*handler); |
222 | 0 | } |
223 | | |
224 | | /** |
225 | | * xmlSetGenericErrorFunc: |
226 | | * @ctx: the new error handling context |
227 | | * @handler: the new handler function |
228 | | * |
229 | | * DEPRECATED: See xmlSetStructuredErrorFunc for alternatives. |
230 | | * |
231 | | * Set the global "generic" handler and context for error messages. |
232 | | * The generic error handler will only receive fragments of error |
233 | | * messages which should be concatenated or printed to a stream. |
234 | | * |
235 | | * If handler is NULL, use the built-in default handler which prints |
236 | | * to stderr. |
237 | | * |
238 | | * Since this is a global setting, it's a good idea to reset the |
239 | | * error handler to its default value after collecting the errors |
240 | | * you're interested in. |
241 | | * |
242 | | * For multi-threaded applications, this must be set separately for |
243 | | * each thread. |
244 | | */ |
245 | | void |
246 | 0 | xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { |
247 | 0 | xmlGenericErrorContext = ctx; |
248 | 0 | if (handler != NULL) |
249 | 0 | xmlGenericError = handler; |
250 | 0 | else |
251 | 0 | xmlGenericError = xmlGenericErrorDefaultFunc; |
252 | 0 | } |
253 | | |
254 | | /** |
255 | | * xmlSetStructuredErrorFunc: |
256 | | * @ctx: the new error handling context |
257 | | * @handler: the new handler function |
258 | | * |
259 | | * DEPRECATED: Use a per-context error handler. |
260 | | * |
261 | | * It's recommended to use the per-context error handlers instead: |
262 | | * |
263 | | * - xmlCtxtSetErrorHandler (since 2.13.0) |
264 | | * - xmlTextReaderSetStructuredErrorHandler |
265 | | * - xmlXPathSetErrorHandler (since 2.13.0) |
266 | | * - xmlXIncludeSetErrorHandler (since 2.13.0) |
267 | | * - xmlSchemaSetParserStructuredErrors |
268 | | * - xmlSchemaSetValidStructuredErrors |
269 | | * - xmlRelaxNGSetParserStructuredErrors |
270 | | * - xmlRelaxNGSetValidStructuredErrors |
271 | | * |
272 | | * Set the global "structured" handler and context for error messages. |
273 | | * If handler is NULL, the error handler is deactivated. |
274 | | * |
275 | | * The structured error handler takes precedence over "generic" |
276 | | * handlers, even per-context generic handlers. |
277 | | * |
278 | | * Since this is a global setting, it's a good idea to deactivate the |
279 | | * error handler after collecting the errors you're interested in. |
280 | | * |
281 | | * For multi-threaded applications, this must be set separately for |
282 | | * each thread. |
283 | | */ |
284 | | void |
285 | 0 | xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { |
286 | 0 | xmlStructuredErrorContext = ctx; |
287 | 0 | xmlStructuredError = handler; |
288 | 0 | } |
289 | | |
290 | | /************************************************************************ |
291 | | * * |
292 | | * Handling of parsing errors * |
293 | | * * |
294 | | ************************************************************************/ |
295 | | |
296 | | /** |
297 | | * xmlParserPrintFileInfo: |
298 | | * @input: an xmlParserInputPtr input |
299 | | * |
300 | | * DEPRECATED: Use xmlFormatError. |
301 | | * |
302 | | * Displays the associated file and line information for the current input |
303 | | */ |
304 | | |
305 | | void |
306 | 0 | xmlParserPrintFileInfo(xmlParserInputPtr input) { |
307 | 0 | if (input != NULL) { |
308 | 0 | if (input->filename) |
309 | 0 | xmlGenericError(xmlGenericErrorContext, |
310 | 0 | "%s:%d: ", input->filename, |
311 | 0 | input->line); |
312 | 0 | else |
313 | 0 | xmlGenericError(xmlGenericErrorContext, |
314 | 0 | "Entity: line %d: ", input->line); |
315 | 0 | } |
316 | 0 | } |
317 | | |
318 | | /** |
319 | | * xmlParserPrintFileContextInternal: |
320 | | * @input: an xmlParserInputPtr input |
321 | | * |
322 | | * Displays current context within the input content for error tracking |
323 | | */ |
324 | | |
325 | | static void |
326 | | xmlParserPrintFileContextInternal(xmlParserInputPtr input , |
327 | 492k | xmlGenericErrorFunc channel, void *data ) { |
328 | 492k | const xmlChar *cur, *base, *start; |
329 | 492k | unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */ |
330 | 492k | xmlChar content[81]; /* space for 80 chars + line terminator */ |
331 | 492k | xmlChar *ctnt; |
332 | | |
333 | 492k | if ((input == NULL) || (input->cur == NULL)) |
334 | 0 | return; |
335 | | |
336 | 492k | cur = input->cur; |
337 | 492k | base = input->base; |
338 | | /* skip backwards over any end-of-lines */ |
339 | 499k | while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { |
340 | 6.68k | cur--; |
341 | 6.68k | } |
342 | 492k | n = 0; |
343 | | /* search backwards for beginning-of-line (to max buff size) */ |
344 | 27.5M | while ((n < sizeof(content) - 1) && (cur > base) && |
345 | 27.5M | (*cur != '\n') && (*cur != '\r')) { |
346 | 27.0M | cur--; |
347 | 27.0M | n++; |
348 | 27.0M | } |
349 | 492k | if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) { |
350 | 161k | cur++; |
351 | 331k | } else { |
352 | | /* skip over continuation bytes */ |
353 | 551k | while ((cur < input->cur) && ((*cur & 0xC0) == 0x80)) |
354 | 219k | cur++; |
355 | 331k | } |
356 | | /* calculate the error position in terms of the current position */ |
357 | 492k | col = input->cur - cur; |
358 | | /* search forward for end-of-line (to max buff size) */ |
359 | 492k | n = 0; |
360 | 492k | start = cur; |
361 | | /* copy selected text to our buffer */ |
362 | 19.4M | while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) { |
363 | 19.3M | int len = input->end - cur; |
364 | 19.3M | int c = xmlGetUTF8Char(cur, &len); |
365 | | |
366 | 19.3M | if ((c < 0) || (n + len > sizeof(content)-1)) |
367 | 297k | break; |
368 | 19.0M | cur += len; |
369 | 19.0M | n += len; |
370 | 19.0M | } |
371 | 492k | memcpy(content, start, n); |
372 | 492k | content[n] = 0; |
373 | | /* print out the selected text */ |
374 | 492k | channel(data ,"%s\n", content); |
375 | | /* create blank line with problem pointer */ |
376 | 492k | n = 0; |
377 | 492k | ctnt = content; |
378 | | /* (leave buffer space for pointer + line terminator) */ |
379 | 18.9M | while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { |
380 | 18.4M | if (*(ctnt) != '\t') |
381 | 17.9M | *(ctnt) = ' '; |
382 | 18.4M | ctnt++; |
383 | 18.4M | } |
384 | 492k | *ctnt++ = '^'; |
385 | 492k | *ctnt = 0; |
386 | 492k | channel(data ,"%s\n", content); |
387 | 492k | } |
388 | | |
389 | | /** |
390 | | * xmlParserPrintFileContext: |
391 | | * @input: an xmlParserInputPtr input |
392 | | * |
393 | | * DEPRECATED: Use xmlFormatError. |
394 | | * |
395 | | * Displays current context within the input content for error tracking |
396 | | */ |
397 | | void |
398 | 0 | xmlParserPrintFileContext(xmlParserInputPtr input) { |
399 | 0 | xmlParserPrintFileContextInternal(input, xmlGenericError, |
400 | 0 | xmlGenericErrorContext); |
401 | 0 | } |
402 | | |
403 | | /** |
404 | | * xmlFormatError: |
405 | | * @err: the error |
406 | | * @channel: callback |
407 | | * @data: user data for callback |
408 | | * |
409 | | * Report a formatted error to a printf-like callback. |
410 | | * |
411 | | * This can result in a verbose multi-line report including additional |
412 | | * information from the parser context. |
413 | | * |
414 | | * Available since 2.13.0. |
415 | | */ |
416 | | void |
417 | | xmlFormatError(const xmlError *err, xmlGenericErrorFunc channel, void *data) |
418 | 456k | { |
419 | 456k | const char *message; |
420 | 456k | const char *file; |
421 | 456k | int line; |
422 | 456k | int code; |
423 | 456k | int domain; |
424 | 456k | const xmlChar *name = NULL; |
425 | 456k | xmlNodePtr node; |
426 | 456k | xmlErrorLevel level; |
427 | 456k | xmlParserCtxtPtr ctxt = NULL; |
428 | 456k | xmlParserInputPtr input = NULL; |
429 | 456k | xmlParserInputPtr cur = NULL; |
430 | | |
431 | 456k | if ((err == NULL) || (channel == NULL)) |
432 | 0 | return; |
433 | | |
434 | 456k | message = err->message; |
435 | 456k | file = err->file; |
436 | 456k | line = err->line; |
437 | 456k | code = err->code; |
438 | 456k | domain = err->domain; |
439 | 456k | level = err->level; |
440 | 456k | node = err->node; |
441 | | |
442 | 456k | if (code == XML_ERR_OK) |
443 | 0 | return; |
444 | | |
445 | 456k | if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
446 | 456k | (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
447 | 456k | (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
448 | 456k | ctxt = err->ctxt; |
449 | 456k | } |
450 | | |
451 | 456k | if ((node != NULL) && (node->type == XML_ELEMENT_NODE) && |
452 | 456k | (domain != XML_FROM_SCHEMASV)) |
453 | 3.98k | name = node->name; |
454 | | |
455 | | /* |
456 | | * Maintain the compatibility with the legacy error handling |
457 | | */ |
458 | 456k | if ((ctxt != NULL) && (ctxt->input != NULL)) { |
459 | 456k | input = ctxt->input; |
460 | 456k | if ((input->filename == NULL) && |
461 | 456k | (ctxt->inputNr > 1)) { |
462 | 36.6k | cur = input; |
463 | 36.6k | input = ctxt->inputTab[ctxt->inputNr - 2]; |
464 | 36.6k | } |
465 | 456k | if (input->filename) |
466 | 216k | channel(data, "%s:%d: ", input->filename, input->line); |
467 | 239k | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
468 | 187k | channel(data, "Entity: line %d: ", input->line); |
469 | 456k | } else { |
470 | 0 | if (file != NULL) |
471 | 0 | channel(data, "%s:%d: ", file, line); |
472 | 0 | else if ((line != 0) && |
473 | 0 | ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)|| |
474 | 0 | (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) || |
475 | 0 | (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV))) |
476 | 0 | channel(data, "Entity: line %d: ", line); |
477 | 0 | } |
478 | 456k | if (name != NULL) { |
479 | 3.98k | channel(data, "element %s: ", name); |
480 | 3.98k | } |
481 | 456k | switch (domain) { |
482 | 344k | case XML_FROM_PARSER: |
483 | 344k | channel(data, "parser "); |
484 | 344k | break; |
485 | 43.8k | case XML_FROM_NAMESPACE: |
486 | 43.8k | channel(data, "namespace "); |
487 | 43.8k | break; |
488 | 4.66k | case XML_FROM_DTD: |
489 | 62.6k | case XML_FROM_VALID: |
490 | 62.6k | channel(data, "validity "); |
491 | 62.6k | break; |
492 | 0 | case XML_FROM_HTML: |
493 | 0 | channel(data, "HTML parser "); |
494 | 0 | break; |
495 | 0 | case XML_FROM_MEMORY: |
496 | 0 | channel(data, "memory "); |
497 | 0 | break; |
498 | 0 | case XML_FROM_OUTPUT: |
499 | 0 | channel(data, "output "); |
500 | 0 | break; |
501 | 5.35k | case XML_FROM_IO: |
502 | 5.35k | channel(data, "I/O "); |
503 | 5.35k | break; |
504 | 0 | case XML_FROM_XINCLUDE: |
505 | 0 | channel(data, "XInclude "); |
506 | 0 | break; |
507 | 0 | case XML_FROM_XPATH: |
508 | 0 | channel(data, "XPath "); |
509 | 0 | break; |
510 | 0 | case XML_FROM_XPOINTER: |
511 | 0 | channel(data, "parser "); |
512 | 0 | break; |
513 | 0 | case XML_FROM_REGEXP: |
514 | 0 | channel(data, "regexp "); |
515 | 0 | break; |
516 | 0 | case XML_FROM_MODULE: |
517 | 0 | channel(data, "module "); |
518 | 0 | break; |
519 | 0 | case XML_FROM_SCHEMASV: |
520 | 0 | channel(data, "Schemas validity "); |
521 | 0 | break; |
522 | 0 | case XML_FROM_SCHEMASP: |
523 | 0 | channel(data, "Schemas parser "); |
524 | 0 | break; |
525 | 0 | case XML_FROM_RELAXNGP: |
526 | 0 | channel(data, "Relax-NG parser "); |
527 | 0 | break; |
528 | 0 | case XML_FROM_RELAXNGV: |
529 | 0 | channel(data, "Relax-NG validity "); |
530 | 0 | break; |
531 | 0 | case XML_FROM_CATALOG: |
532 | 0 | channel(data, "Catalog "); |
533 | 0 | break; |
534 | 0 | case XML_FROM_C14N: |
535 | 0 | channel(data, "C14N "); |
536 | 0 | break; |
537 | 0 | case XML_FROM_XSLT: |
538 | 0 | channel(data, "XSLT "); |
539 | 0 | break; |
540 | 0 | case XML_FROM_I18N: |
541 | 0 | channel(data, "encoding "); |
542 | 0 | break; |
543 | 0 | case XML_FROM_SCHEMATRONV: |
544 | 0 | channel(data, "schematron "); |
545 | 0 | break; |
546 | 0 | case XML_FROM_BUFFER: |
547 | 0 | channel(data, "internal buffer "); |
548 | 0 | break; |
549 | 0 | case XML_FROM_URI: |
550 | 0 | channel(data, "URI "); |
551 | 0 | break; |
552 | 0 | default: |
553 | 0 | break; |
554 | 456k | } |
555 | 456k | switch (level) { |
556 | 0 | case XML_ERR_NONE: |
557 | 0 | channel(data, ": "); |
558 | 0 | break; |
559 | 36.1k | case XML_ERR_WARNING: |
560 | 36.1k | channel(data, "warning : "); |
561 | 36.1k | break; |
562 | 88.9k | case XML_ERR_ERROR: |
563 | 88.9k | channel(data, "error : "); |
564 | 88.9k | break; |
565 | 331k | case XML_ERR_FATAL: |
566 | 331k | channel(data, "error : "); |
567 | 331k | break; |
568 | 456k | } |
569 | 456k | if (message != NULL) { |
570 | 456k | int len; |
571 | 456k | len = xmlStrlen((const xmlChar *) message); |
572 | 456k | if ((len > 0) && (message[len - 1] != '\n')) |
573 | 2.71k | channel(data, "%s\n", message); |
574 | 453k | else |
575 | 453k | channel(data, "%s", message); |
576 | 456k | } else { |
577 | 0 | channel(data, "%s\n", "No error message provided"); |
578 | 0 | } |
579 | | |
580 | 456k | if (ctxt != NULL) { |
581 | 456k | if ((input != NULL) && |
582 | 456k | ((input->buf == NULL) || (input->buf->encoder == NULL)) && |
583 | 456k | (code == XML_ERR_INVALID_ENCODING) && |
584 | 456k | (input->cur < input->end)) { |
585 | 5.17k | int i; |
586 | | |
587 | 5.17k | channel(data, "Bytes:"); |
588 | 25.1k | for (i = 0; i < 4; i++) { |
589 | 20.3k | if (input->cur + i >= input->end) |
590 | 378 | break; |
591 | 20.0k | channel(data, " 0x%02X", input->cur[i]); |
592 | 20.0k | } |
593 | 5.17k | channel(data, "\n"); |
594 | 5.17k | } |
595 | | |
596 | 456k | xmlParserPrintFileContextInternal(input, channel, data); |
597 | | |
598 | 456k | if (cur != NULL) { |
599 | 36.6k | if (cur->filename) |
600 | 0 | channel(data, "%s:%d: \n", cur->filename, cur->line); |
601 | 36.6k | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
602 | 23.3k | channel(data, "Entity: line %d: \n", cur->line); |
603 | 36.6k | xmlParserPrintFileContextInternal(cur, channel, data); |
604 | 36.6k | } |
605 | 456k | } |
606 | 456k | if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) && |
607 | 456k | (err->int1 < 100) && |
608 | 456k | (err->int1 < xmlStrlen((const xmlChar *)err->str1))) { |
609 | 0 | xmlChar buf[150]; |
610 | 0 | int i; |
611 | |
|
612 | 0 | channel(data, "%s\n", err->str1); |
613 | 0 | for (i=0;i < err->int1;i++) |
614 | 0 | buf[i] = ' '; |
615 | 0 | buf[i++] = '^'; |
616 | 0 | buf[i] = 0; |
617 | 0 | channel(data, "%s\n", buf); |
618 | 0 | } |
619 | 456k | } |
620 | | |
621 | | /** |
622 | | * xmlRaiseMemoryError: |
623 | | * @schannel: the structured callback channel |
624 | | * @channel: the old callback channel |
625 | | * @data: the callback data |
626 | | * @domain: the domain for the error |
627 | | * @error: optional error struct to be filled |
628 | | * |
629 | | * Update the global and optional error structure, then forward the |
630 | | * error to an error handler. |
631 | | * |
632 | | * This function doesn't make memory allocations which are likely |
633 | | * to fail after an OOM error. |
634 | | */ |
635 | | void |
636 | | xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, |
637 | | void *data, int domain, xmlError *error) |
638 | 0 | { |
639 | 0 | xmlError *lastError = xmlGetLastErrorInternal(); |
640 | |
|
641 | 0 | xmlResetLastError(); |
642 | 0 | lastError->domain = domain; |
643 | 0 | lastError->code = XML_ERR_NO_MEMORY; |
644 | 0 | lastError->level = XML_ERR_FATAL; |
645 | |
|
646 | 0 | if (error != NULL) { |
647 | 0 | xmlResetError(error); |
648 | 0 | error->domain = domain; |
649 | 0 | error->code = XML_ERR_NO_MEMORY; |
650 | 0 | error->level = XML_ERR_FATAL; |
651 | 0 | } |
652 | |
|
653 | 0 | if (schannel != NULL) { |
654 | 0 | schannel(data, lastError); |
655 | 0 | } else if (xmlStructuredError != NULL) { |
656 | 0 | xmlStructuredError(xmlStructuredErrorContext, lastError); |
657 | 0 | } else if (channel != NULL) { |
658 | 0 | channel(data, "libxml2: out of memory\n"); |
659 | 0 | } |
660 | 0 | } |
661 | | |
662 | | /** |
663 | | * xmlVRaiseError: |
664 | | * @schannel: the structured callback channel |
665 | | * @channel: the old callback channel |
666 | | * @data: the callback data |
667 | | * @ctx: the parser context or NULL |
668 | | * @node: the current node or NULL |
669 | | * @domain: the domain for the error |
670 | | * @code: the code for the error |
671 | | * @level: the xmlErrorLevel for the error |
672 | | * @file: the file source of the error (or NULL) |
673 | | * @line: the line of the error or 0 if N/A |
674 | | * @str1: extra string info |
675 | | * @str2: extra string info |
676 | | * @str3: extra string info |
677 | | * @int1: extra int info |
678 | | * @col: column number of the error or 0 if N/A |
679 | | * @msg: the message to display/transmit |
680 | | * @ap: extra parameters for the message display |
681 | | * |
682 | | * Update the appropriate global or contextual error structure, |
683 | | * then forward the error message down the parser or generic |
684 | | * error callback handler |
685 | | * |
686 | | * Returns 0 on success, -1 if a memory allocation failed. |
687 | | */ |
688 | | int |
689 | | xmlVRaiseError(xmlStructuredErrorFunc schannel, |
690 | | xmlGenericErrorFunc channel, void *data, void *ctx, |
691 | | xmlNode *node, int domain, int code, xmlErrorLevel level, |
692 | | const char *file, int line, const char *str1, |
693 | | const char *str2, const char *str3, int int1, int col, |
694 | | const char *msg, va_list ap) |
695 | 456k | { |
696 | 456k | xmlParserCtxtPtr ctxt = NULL; |
697 | | /* xmlLastError is a macro retrieving the per-thread global. */ |
698 | 456k | xmlErrorPtr lastError = xmlGetLastErrorInternal(); |
699 | 456k | xmlErrorPtr to = lastError; |
700 | | |
701 | 456k | if (code == XML_ERR_OK) |
702 | 0 | return(0); |
703 | 456k | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
704 | 456k | if (code == XML_ERR_INTERNAL_ERROR) |
705 | 0 | xmlAbort("Unexpected error: %d\n", code); |
706 | 456k | #endif |
707 | 456k | if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING)) |
708 | 0 | return(0); |
709 | | |
710 | 456k | if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
711 | 456k | (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
712 | 456k | (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
713 | 456k | ctxt = (xmlParserCtxtPtr) ctx; |
714 | | |
715 | 456k | if (ctxt != NULL) |
716 | 456k | to = &ctxt->lastError; |
717 | 456k | } |
718 | | |
719 | 456k | if (xmlVUpdateError(to, ctxt, node, domain, code, level, file, line, |
720 | 456k | str1, str2, str3, int1, col, msg, ap)) |
721 | 0 | return(-1); |
722 | | |
723 | 456k | if (to != lastError) { |
724 | 456k | if (xmlCopyError(to, lastError) < 0) |
725 | 0 | return(-1); |
726 | 456k | } |
727 | | |
728 | 456k | if (schannel != NULL) { |
729 | 0 | schannel(data, to); |
730 | 456k | } else if (xmlStructuredError != NULL) { |
731 | 0 | xmlStructuredError(xmlStructuredErrorContext, to); |
732 | 456k | } else if (channel != NULL) { |
733 | | /* Don't invoke legacy error handlers */ |
734 | 456k | if ((channel == xmlGenericErrorDefaultFunc) || |
735 | 456k | (channel == xmlParserError) || |
736 | 456k | (channel == xmlParserWarning) || |
737 | 456k | (channel == xmlParserValidityError) || |
738 | 456k | (channel == xmlParserValidityWarning)) |
739 | 456k | xmlFormatError(to, xmlGenericError, xmlGenericErrorContext); |
740 | 0 | else |
741 | 0 | channel(data, "%s", to->message); |
742 | 456k | } |
743 | | |
744 | 456k | return(0); |
745 | 456k | } |
746 | | |
747 | | /** |
748 | | * xmlRaiseError: |
749 | | * @schannel: the structured callback channel |
750 | | * @channel: the old callback channel |
751 | | * @data: the callback data |
752 | | * @ctx: the parser context or NULL |
753 | | * @nod: the node or NULL |
754 | | * @domain: the domain for the error |
755 | | * @code: the code for the error |
756 | | * @level: the xmlErrorLevel for the error |
757 | | * @file: the file source of the error (or NULL) |
758 | | * @line: the line of the error or 0 if N/A |
759 | | * @str1: extra string info |
760 | | * @str2: extra string info |
761 | | * @str3: extra string info |
762 | | * @int1: extra int info |
763 | | * @col: column number of the error or 0 if N/A |
764 | | * @msg: the message to display/transmit |
765 | | * @...: extra parameters for the message display |
766 | | * |
767 | | * Update the appropriate global or contextual error structure, |
768 | | * then forward the error message down the parser or generic |
769 | | * error callback handler |
770 | | * |
771 | | * Returns 0 on success, -1 if a memory allocation failed. |
772 | | */ |
773 | | int |
774 | | xmlRaiseError(xmlStructuredErrorFunc schannel, |
775 | | xmlGenericErrorFunc channel, void *data, void *ctx, |
776 | | xmlNode *node, int domain, int code, xmlErrorLevel level, |
777 | | const char *file, int line, const char *str1, |
778 | | const char *str2, const char *str3, int int1, int col, |
779 | | const char *msg, ...) |
780 | 0 | { |
781 | 0 | va_list ap; |
782 | 0 | int res; |
783 | |
|
784 | 0 | va_start(ap, msg); |
785 | 0 | res = xmlVRaiseError(schannel, channel, data, ctx, node, domain, code, |
786 | 0 | level, file, line, str1, str2, str3, int1, col, msg, |
787 | 0 | ap); |
788 | 0 | va_end(ap); |
789 | |
|
790 | 0 | return(res); |
791 | 0 | } |
792 | | |
793 | | static void |
794 | | xmlVFormatLegacyError(void *ctx, const char *level, |
795 | 0 | const char *fmt, va_list ap) { |
796 | 0 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
797 | 0 | xmlParserInputPtr input = NULL; |
798 | 0 | xmlParserInputPtr cur = NULL; |
799 | 0 | xmlChar *str = NULL; |
800 | |
|
801 | 0 | if (ctxt != NULL) { |
802 | 0 | input = ctxt->input; |
803 | 0 | if ((input != NULL) && (input->filename == NULL) && |
804 | 0 | (ctxt->inputNr > 1)) { |
805 | 0 | cur = input; |
806 | 0 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
807 | 0 | } |
808 | 0 | xmlParserPrintFileInfo(input); |
809 | 0 | } |
810 | |
|
811 | 0 | xmlGenericError(xmlGenericErrorContext, "%s: ", level); |
812 | |
|
813 | 0 | xmlStrVASPrintf(&str, MAX_ERR_MSG_SIZE, fmt, ap); |
814 | 0 | if (str != NULL) { |
815 | 0 | xmlGenericError(xmlGenericErrorContext, "%s", (char *) str); |
816 | 0 | xmlFree(str); |
817 | 0 | } |
818 | |
|
819 | 0 | if (ctxt != NULL) { |
820 | 0 | xmlParserPrintFileContext(input); |
821 | 0 | if (cur != NULL) { |
822 | 0 | xmlParserPrintFileInfo(cur); |
823 | 0 | xmlGenericError(xmlGenericErrorContext, "\n"); |
824 | 0 | xmlParserPrintFileContext(cur); |
825 | 0 | } |
826 | 0 | } |
827 | 0 | } |
828 | | |
829 | | /** |
830 | | * xmlParserError: |
831 | | * @ctx: an XML parser context |
832 | | * @msg: the message to display/transmit |
833 | | * @...: extra parameters for the message display |
834 | | * |
835 | | * Display and format an error messages, gives file, line, position and |
836 | | * extra parameters. |
837 | | */ |
838 | | void |
839 | | xmlParserError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) |
840 | 0 | { |
841 | 0 | va_list ap; |
842 | |
|
843 | 0 | va_start(ap, msg); |
844 | 0 | xmlVFormatLegacyError(ctx, "error", msg, ap); |
845 | 0 | va_end(ap); |
846 | 0 | } |
847 | | |
848 | | /** |
849 | | * xmlParserWarning: |
850 | | * @ctx: an XML parser context |
851 | | * @msg: the message to display/transmit |
852 | | * @...: extra parameters for the message display |
853 | | * |
854 | | * Display and format a warning messages, gives file, line, position and |
855 | | * extra parameters. |
856 | | */ |
857 | | void |
858 | | xmlParserWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) |
859 | 0 | { |
860 | 0 | va_list ap; |
861 | |
|
862 | 0 | va_start(ap, msg); |
863 | 0 | xmlVFormatLegacyError(ctx, "warning", msg, ap); |
864 | 0 | va_end(ap); |
865 | 0 | } |
866 | | |
867 | | /** |
868 | | * xmlParserValidityError: |
869 | | * @ctx: an XML parser context |
870 | | * @msg: the message to display/transmit |
871 | | * @...: extra parameters for the message display |
872 | | * |
873 | | * Display and format an validity error messages, gives file, |
874 | | * line, position and extra parameters. |
875 | | */ |
876 | | void |
877 | | xmlParserValidityError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) |
878 | 0 | { |
879 | 0 | va_list ap; |
880 | |
|
881 | 0 | va_start(ap, msg); |
882 | 0 | xmlVFormatLegacyError(ctx, "validity error", msg, ap); |
883 | 0 | va_end(ap); |
884 | 0 | } |
885 | | |
886 | | /** |
887 | | * xmlParserValidityWarning: |
888 | | * @ctx: an XML parser context |
889 | | * @msg: the message to display/transmit |
890 | | * @...: extra parameters for the message display |
891 | | * |
892 | | * Display and format a validity warning messages, gives file, line, |
893 | | * position and extra parameters. |
894 | | */ |
895 | | void |
896 | | xmlParserValidityWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) |
897 | 0 | { |
898 | 0 | va_list ap; |
899 | |
|
900 | 0 | va_start(ap, msg); |
901 | 0 | xmlVFormatLegacyError(ctx, "validity warning", msg, ap); |
902 | 0 | va_end(ap); |
903 | 0 | } |
904 | | |
905 | | |
906 | | /************************************************************************ |
907 | | * * |
908 | | * Extended Error Handling * |
909 | | * * |
910 | | ************************************************************************/ |
911 | | |
912 | | /** |
913 | | * xmlGetLastError: |
914 | | * |
915 | | * Get the last global error registered. This is per thread if compiled |
916 | | * with thread support. |
917 | | * |
918 | | * Returns a pointer to the error |
919 | | */ |
920 | | const xmlError * |
921 | | xmlGetLastError(void) |
922 | 0 | { |
923 | 0 | const xmlError *error = xmlGetLastErrorInternal(); |
924 | |
|
925 | 0 | if (error->code == XML_ERR_OK) |
926 | 0 | return(NULL); |
927 | 0 | return(error); |
928 | 0 | } |
929 | | |
930 | | /** |
931 | | * xmlResetError: |
932 | | * @err: pointer to the error. |
933 | | * |
934 | | * Cleanup the error. |
935 | | */ |
936 | | void |
937 | | xmlResetError(xmlErrorPtr err) |
938 | 922k | { |
939 | 922k | if (err == NULL) |
940 | 0 | return; |
941 | 922k | if (err->code == XML_ERR_OK) |
942 | 30.0k | return; |
943 | 891k | if (err->message != NULL) |
944 | 891k | xmlFree(err->message); |
945 | 891k | if (err->file != NULL) |
946 | 422k | xmlFree(err->file); |
947 | 891k | if (err->str1 != NULL) |
948 | 432k | xmlFree(err->str1); |
949 | 891k | if (err->str2 != NULL) |
950 | 142k | xmlFree(err->str2); |
951 | 891k | if (err->str3 != NULL) |
952 | 45.1k | xmlFree(err->str3); |
953 | 891k | memset(err, 0, sizeof(xmlError)); |
954 | 891k | err->code = XML_ERR_OK; |
955 | 891k | } |
956 | | |
957 | | /** |
958 | | * xmlResetLastError: |
959 | | * |
960 | | * Cleanup the last global error registered. For parsing error |
961 | | * this does not change the well-formedness result. |
962 | | */ |
963 | | void |
964 | | xmlResetLastError(void) |
965 | 0 | { |
966 | 0 | xmlError *error = xmlGetLastErrorInternal(); |
967 | |
|
968 | 0 | if (error->code != XML_ERR_OK) |
969 | 0 | xmlResetError(error); |
970 | 0 | } |
971 | | |
972 | | /** |
973 | | * xmlCopyError: |
974 | | * @from: a source error |
975 | | * @to: a target error |
976 | | * |
977 | | * Save the original error to the new place. |
978 | | * |
979 | | * Returns 0 in case of success and -1 in case of error. |
980 | | */ |
981 | | int |
982 | 456k | xmlCopyError(const xmlError *from, xmlErrorPtr to) { |
983 | 456k | const char *fmt = NULL; |
984 | | |
985 | 456k | if ((from == NULL) || (to == NULL)) |
986 | 0 | return(-1); |
987 | | |
988 | 456k | if (from->message != NULL) |
989 | 456k | fmt = "%s"; |
990 | | |
991 | 456k | return(xmlSetError(to, from->ctxt, from->node, |
992 | 456k | from->domain, from->code, from->level, |
993 | 456k | from->file, from->line, |
994 | 456k | from->str1, from->str2, from->str3, |
995 | 456k | from->int1, from->int2, |
996 | 456k | fmt, from->message)); |
997 | 456k | } |
998 | | |
999 | | /** |
1000 | | * xmlErrString: |
1001 | | * @code: an xmlParserErrors code |
1002 | | * |
1003 | | * Returns an error message for a code. |
1004 | | */ |
1005 | | const char * |
1006 | 6.61M | xmlErrString(xmlParserErrors code) { |
1007 | 6.61M | const char *errmsg; |
1008 | | |
1009 | 6.61M | switch (code) { |
1010 | 47.0k | case XML_ERR_INVALID_HEX_CHARREF: |
1011 | 47.0k | errmsg = "CharRef: invalid hexadecimal value"; |
1012 | 47.0k | break; |
1013 | 22.1k | case XML_ERR_INVALID_DEC_CHARREF: |
1014 | 22.1k | errmsg = "CharRef: invalid decimal value"; |
1015 | 22.1k | break; |
1016 | 0 | case XML_ERR_INVALID_CHARREF: |
1017 | 0 | errmsg = "CharRef: invalid value"; |
1018 | 0 | break; |
1019 | 0 | case XML_ERR_INTERNAL_ERROR: |
1020 | 0 | errmsg = "internal error"; |
1021 | 0 | break; |
1022 | 0 | case XML_ERR_PEREF_AT_EOF: |
1023 | 0 | errmsg = "PEReference at end of document"; |
1024 | 0 | break; |
1025 | 0 | case XML_ERR_PEREF_IN_PROLOG: |
1026 | 0 | errmsg = "PEReference in prolog"; |
1027 | 0 | break; |
1028 | 0 | case XML_ERR_PEREF_IN_EPILOG: |
1029 | 0 | errmsg = "PEReference in epilog"; |
1030 | 0 | break; |
1031 | 0 | case XML_ERR_PEREF_NO_NAME: |
1032 | 0 | errmsg = "PEReference: no name"; |
1033 | 0 | break; |
1034 | 1.93k | case XML_ERR_PEREF_SEMICOL_MISSING: |
1035 | 1.93k | errmsg = "PEReference: expecting ';'"; |
1036 | 1.93k | break; |
1037 | 58 | case XML_ERR_ENTITY_LOOP: |
1038 | 58 | errmsg = "Detected an entity reference loop"; |
1039 | 58 | break; |
1040 | 0 | case XML_ERR_ENTITY_NOT_STARTED: |
1041 | 0 | errmsg = "EntityValue: \" or ' expected"; |
1042 | 0 | break; |
1043 | 642 | case XML_ERR_ENTITY_PE_INTERNAL: |
1044 | 642 | errmsg = "PEReferences forbidden in internal subset"; |
1045 | 642 | break; |
1046 | 0 | case XML_ERR_ENTITY_NOT_FINISHED: |
1047 | 0 | errmsg = "EntityValue: \" or ' expected"; |
1048 | 0 | break; |
1049 | 10.5k | case XML_ERR_ATTRIBUTE_NOT_STARTED: |
1050 | 10.5k | errmsg = "AttValue: \" or ' expected"; |
1051 | 10.5k | break; |
1052 | 164k | case XML_ERR_LT_IN_ATTRIBUTE: |
1053 | 164k | errmsg = "Unescaped '<' not allowed in attributes values"; |
1054 | 164k | break; |
1055 | 1.24k | case XML_ERR_LITERAL_NOT_STARTED: |
1056 | 1.24k | errmsg = "SystemLiteral \" or ' expected"; |
1057 | 1.24k | break; |
1058 | 1.18k | case XML_ERR_LITERAL_NOT_FINISHED: |
1059 | 1.18k | errmsg = "Unfinished System or Public ID \" or ' expected"; |
1060 | 1.18k | break; |
1061 | 9.77k | case XML_ERR_MISPLACED_CDATA_END: |
1062 | 9.77k | errmsg = "Sequence ']]>' not allowed in content"; |
1063 | 9.77k | break; |
1064 | 882 | case XML_ERR_URI_REQUIRED: |
1065 | 882 | errmsg = "SYSTEM or PUBLIC, the URI is missing"; |
1066 | 882 | break; |
1067 | 372 | case XML_ERR_PUBID_REQUIRED: |
1068 | 372 | errmsg = "PUBLIC, the Public Identifier is missing"; |
1069 | 372 | break; |
1070 | 107k | case XML_ERR_HYPHEN_IN_COMMENT: |
1071 | 107k | errmsg = "Comment must not contain '--' (double-hyphen)"; |
1072 | 107k | break; |
1073 | 4.32k | case XML_ERR_PI_NOT_STARTED: |
1074 | 4.32k | errmsg = "xmlParsePI : no target name"; |
1075 | 4.32k | break; |
1076 | 1.58k | case XML_ERR_RESERVED_XML_NAME: |
1077 | 1.58k | errmsg = "Invalid PI name"; |
1078 | 1.58k | break; |
1079 | 145 | case XML_ERR_NOTATION_NOT_STARTED: |
1080 | 145 | errmsg = "NOTATION: Name expected here"; |
1081 | 145 | break; |
1082 | 1.05k | case XML_ERR_NOTATION_NOT_FINISHED: |
1083 | 1.05k | errmsg = "'>' required to close NOTATION declaration"; |
1084 | 1.05k | break; |
1085 | 682 | case XML_ERR_VALUE_REQUIRED: |
1086 | 682 | errmsg = "Entity value required"; |
1087 | 682 | break; |
1088 | 1.40k | case XML_ERR_URI_FRAGMENT: |
1089 | 1.40k | errmsg = "Fragment not allowed"; |
1090 | 1.40k | break; |
1091 | 507 | case XML_ERR_ATTLIST_NOT_STARTED: |
1092 | 507 | errmsg = "'(' required to start ATTLIST enumeration"; |
1093 | 507 | break; |
1094 | 89 | case XML_ERR_NMTOKEN_REQUIRED: |
1095 | 89 | errmsg = "NmToken expected in ATTLIST enumeration"; |
1096 | 89 | break; |
1097 | 338 | case XML_ERR_ATTLIST_NOT_FINISHED: |
1098 | 338 | errmsg = "')' required to finish ATTLIST enumeration"; |
1099 | 338 | break; |
1100 | 198 | case XML_ERR_MIXED_NOT_STARTED: |
1101 | 198 | errmsg = "MixedContentDecl : '|' or ')*' expected"; |
1102 | 198 | break; |
1103 | 0 | case XML_ERR_PCDATA_REQUIRED: |
1104 | 0 | errmsg = "MixedContentDecl : '#PCDATA' expected"; |
1105 | 0 | break; |
1106 | 446 | case XML_ERR_ELEMCONTENT_NOT_STARTED: |
1107 | 446 | errmsg = "ContentDecl : Name or '(' expected"; |
1108 | 446 | break; |
1109 | 1.44k | case XML_ERR_ELEMCONTENT_NOT_FINISHED: |
1110 | 1.44k | errmsg = "ContentDecl : ',' '|' or ')' expected"; |
1111 | 1.44k | break; |
1112 | 0 | case XML_ERR_PEREF_IN_INT_SUBSET: |
1113 | 0 | errmsg = |
1114 | 0 | "PEReference: forbidden within markup decl in internal subset"; |
1115 | 0 | break; |
1116 | 25.3k | case XML_ERR_GT_REQUIRED: |
1117 | 25.3k | errmsg = "expected '>'"; |
1118 | 25.3k | break; |
1119 | 0 | case XML_ERR_CONDSEC_INVALID: |
1120 | 0 | errmsg = "XML conditional section '[' expected"; |
1121 | 0 | break; |
1122 | 3.60k | case XML_ERR_INT_SUBSET_NOT_FINISHED: |
1123 | 3.60k | errmsg = "Content error in the internal subset"; |
1124 | 3.60k | break; |
1125 | 0 | case XML_ERR_EXT_SUBSET_NOT_FINISHED: |
1126 | 0 | errmsg = "Content error in the external subset"; |
1127 | 0 | break; |
1128 | 0 | case XML_ERR_CONDSEC_INVALID_KEYWORD: |
1129 | 0 | errmsg = |
1130 | 0 | "conditional section INCLUDE or IGNORE keyword expected"; |
1131 | 0 | break; |
1132 | 0 | case XML_ERR_CONDSEC_NOT_FINISHED: |
1133 | 0 | errmsg = "XML conditional section not closed"; |
1134 | 0 | break; |
1135 | 0 | case XML_ERR_XMLDECL_NOT_STARTED: |
1136 | 0 | errmsg = "Text declaration '<?xml' required"; |
1137 | 0 | break; |
1138 | 1.55k | case XML_ERR_XMLDECL_NOT_FINISHED: |
1139 | 1.55k | errmsg = "parsing XML declaration: '?>' expected"; |
1140 | 1.55k | break; |
1141 | 0 | case XML_ERR_EXT_ENTITY_STANDALONE: |
1142 | 0 | errmsg = "external parsed entities cannot be standalone"; |
1143 | 0 | break; |
1144 | 60.2k | case XML_ERR_ENTITYREF_SEMICOL_MISSING: |
1145 | 60.2k | errmsg = "EntityRef: expecting ';'"; |
1146 | 60.2k | break; |
1147 | 414 | case XML_ERR_DOCTYPE_NOT_FINISHED: |
1148 | 414 | errmsg = "DOCTYPE improperly terminated"; |
1149 | 414 | break; |
1150 | 131 | case XML_ERR_LTSLASH_REQUIRED: |
1151 | 131 | errmsg = "EndTag: '</' not found"; |
1152 | 131 | break; |
1153 | 93 | case XML_ERR_EQUAL_REQUIRED: |
1154 | 93 | errmsg = "expected '='"; |
1155 | 93 | break; |
1156 | 315 | case XML_ERR_STRING_NOT_CLOSED: |
1157 | 315 | errmsg = "String not closed expecting \" or '"; |
1158 | 315 | break; |
1159 | 123 | case XML_ERR_STRING_NOT_STARTED: |
1160 | 123 | errmsg = "String not started expecting ' or \""; |
1161 | 123 | break; |
1162 | 17 | case XML_ERR_ENCODING_NAME: |
1163 | 17 | errmsg = "Invalid XML encoding name"; |
1164 | 17 | break; |
1165 | 26 | case XML_ERR_STANDALONE_VALUE: |
1166 | 26 | errmsg = "standalone accepts only 'yes' or 'no'"; |
1167 | 26 | break; |
1168 | 3.25k | case XML_ERR_DOCUMENT_EMPTY: |
1169 | 3.25k | errmsg = "Document is empty"; |
1170 | 3.25k | break; |
1171 | 12 | case XML_ERR_DOCUMENT_END: |
1172 | 12 | errmsg = "Extra content at the end of the document"; |
1173 | 12 | break; |
1174 | 101 | case XML_ERR_NOT_WELL_BALANCED: |
1175 | 101 | errmsg = "chunk is not well balanced"; |
1176 | 101 | break; |
1177 | 0 | case XML_ERR_EXTRA_CONTENT: |
1178 | 0 | errmsg = "extra content at the end of well balanced chunk"; |
1179 | 0 | break; |
1180 | 1.51k | case XML_ERR_VERSION_MISSING: |
1181 | 1.51k | errmsg = "Malformed declaration expecting version"; |
1182 | 1.51k | break; |
1183 | 1.47k | case XML_ERR_NAME_TOO_LONG: |
1184 | 1.47k | errmsg = "Name too long"; |
1185 | 1.47k | break; |
1186 | 5.62k | case XML_ERR_INVALID_ENCODING: |
1187 | 5.62k | errmsg = "Invalid bytes in character encoding"; |
1188 | 5.62k | break; |
1189 | 717 | case XML_ERR_RESOURCE_LIMIT: |
1190 | 717 | errmsg = "Resource limit exceeded"; |
1191 | 717 | break; |
1192 | 0 | case XML_ERR_ARGUMENT: |
1193 | 0 | errmsg = "Invalid argument"; |
1194 | 0 | break; |
1195 | 0 | case XML_ERR_SYSTEM: |
1196 | 0 | errmsg = "Out of system resources"; |
1197 | 0 | break; |
1198 | 0 | case XML_ERR_REDECL_PREDEF_ENTITY: |
1199 | 0 | errmsg = "Invalid redeclaration of predefined entity"; |
1200 | 0 | break; |
1201 | 49 | case XML_ERR_UNSUPPORTED_ENCODING: |
1202 | 49 | errmsg = "Unsupported encoding"; |
1203 | 49 | break; |
1204 | 6.12M | case XML_ERR_INVALID_CHAR: |
1205 | 6.12M | errmsg = "Invalid character"; |
1206 | 6.12M | break; |
1207 | | |
1208 | 0 | case XML_IO_UNKNOWN: |
1209 | 0 | errmsg = "Unknown IO error"; break; |
1210 | 0 | case XML_IO_EACCES: |
1211 | 0 | errmsg = "Permission denied"; break; |
1212 | 0 | case XML_IO_EAGAIN: |
1213 | 0 | errmsg = "Resource temporarily unavailable"; break; |
1214 | 0 | case XML_IO_EBADF: |
1215 | 0 | errmsg = "Bad file descriptor"; break; |
1216 | 0 | case XML_IO_EBADMSG: |
1217 | 0 | errmsg = "Bad message"; break; |
1218 | 0 | case XML_IO_EBUSY: |
1219 | 0 | errmsg = "Resource busy"; break; |
1220 | 0 | case XML_IO_ECANCELED: |
1221 | 0 | errmsg = "Operation canceled"; break; |
1222 | 0 | case XML_IO_ECHILD: |
1223 | 0 | errmsg = "No child processes"; break; |
1224 | 0 | case XML_IO_EDEADLK: |
1225 | 0 | errmsg = "Resource deadlock avoided"; break; |
1226 | 0 | case XML_IO_EDOM: |
1227 | 0 | errmsg = "Domain error"; break; |
1228 | 0 | case XML_IO_EEXIST: |
1229 | 0 | errmsg = "File exists"; break; |
1230 | 0 | case XML_IO_EFAULT: |
1231 | 0 | errmsg = "Bad address"; break; |
1232 | 0 | case XML_IO_EFBIG: |
1233 | 0 | errmsg = "File too large"; break; |
1234 | 0 | case XML_IO_EINPROGRESS: |
1235 | 0 | errmsg = "Operation in progress"; break; |
1236 | 0 | case XML_IO_EINTR: |
1237 | 0 | errmsg = "Interrupted function call"; break; |
1238 | 0 | case XML_IO_EINVAL: |
1239 | 0 | errmsg = "Invalid argument"; break; |
1240 | 0 | case XML_IO_EIO: |
1241 | 0 | errmsg = "Input/output error"; break; |
1242 | 0 | case XML_IO_EISDIR: |
1243 | 0 | errmsg = "Is a directory"; break; |
1244 | 0 | case XML_IO_EMFILE: |
1245 | 0 | errmsg = "Too many open files"; break; |
1246 | 0 | case XML_IO_EMLINK: |
1247 | 0 | errmsg = "Too many links"; break; |
1248 | 0 | case XML_IO_EMSGSIZE: |
1249 | 0 | errmsg = "Inappropriate message buffer length"; break; |
1250 | 0 | case XML_IO_ENAMETOOLONG: |
1251 | 0 | errmsg = "Filename too long"; break; |
1252 | 0 | case XML_IO_ENFILE: |
1253 | 0 | errmsg = "Too many open files in system"; break; |
1254 | 0 | case XML_IO_ENODEV: |
1255 | 0 | errmsg = "No such device"; break; |
1256 | 0 | case XML_IO_ENOENT: |
1257 | 0 | errmsg = "No such file or directory"; break; |
1258 | 0 | case XML_IO_ENOEXEC: |
1259 | 0 | errmsg = "Exec format error"; break; |
1260 | 0 | case XML_IO_ENOLCK: |
1261 | 0 | errmsg = "No locks available"; break; |
1262 | 0 | case XML_IO_ENOMEM: |
1263 | 0 | errmsg = "Not enough space"; break; |
1264 | 0 | case XML_IO_ENOSPC: |
1265 | 0 | errmsg = "No space left on device"; break; |
1266 | 0 | case XML_IO_ENOSYS: |
1267 | 0 | errmsg = "Function not implemented"; break; |
1268 | 0 | case XML_IO_ENOTDIR: |
1269 | 0 | errmsg = "Not a directory"; break; |
1270 | 0 | case XML_IO_ENOTEMPTY: |
1271 | 0 | errmsg = "Directory not empty"; break; |
1272 | 0 | case XML_IO_ENOTSUP: |
1273 | 0 | errmsg = "Not supported"; break; |
1274 | 0 | case XML_IO_ENOTTY: |
1275 | 0 | errmsg = "Inappropriate I/O control operation"; break; |
1276 | 0 | case XML_IO_ENXIO: |
1277 | 0 | errmsg = "No such device or address"; break; |
1278 | 0 | case XML_IO_EPERM: |
1279 | 0 | errmsg = "Operation not permitted"; break; |
1280 | 0 | case XML_IO_EPIPE: |
1281 | 0 | errmsg = "Broken pipe"; break; |
1282 | 0 | case XML_IO_ERANGE: |
1283 | 0 | errmsg = "Result too large"; break; |
1284 | 0 | case XML_IO_EROFS: |
1285 | 0 | errmsg = "Read-only file system"; break; |
1286 | 0 | case XML_IO_ESPIPE: |
1287 | 0 | errmsg = "Invalid seek"; break; |
1288 | 0 | case XML_IO_ESRCH: |
1289 | 0 | errmsg = "No such process"; break; |
1290 | 0 | case XML_IO_ETIMEDOUT: |
1291 | 0 | errmsg = "Operation timed out"; break; |
1292 | 0 | case XML_IO_EXDEV: |
1293 | 0 | errmsg = "Improper link"; break; |
1294 | 0 | case XML_IO_NETWORK_ATTEMPT: |
1295 | 0 | errmsg = "Attempt to load network entity"; break; |
1296 | 0 | case XML_IO_ENCODER: |
1297 | 0 | errmsg = "encoder error"; break; |
1298 | 0 | case XML_IO_FLUSH: |
1299 | 0 | errmsg = "flush error"; break; |
1300 | 0 | case XML_IO_WRITE: |
1301 | 0 | errmsg = "write error"; break; |
1302 | 0 | case XML_IO_NO_INPUT: |
1303 | 0 | errmsg = "no input"; break; |
1304 | 0 | case XML_IO_BUFFER_FULL: |
1305 | 0 | errmsg = "buffer full"; break; |
1306 | 0 | case XML_IO_LOAD_ERROR: |
1307 | 0 | errmsg = "loading error"; break; |
1308 | 0 | case XML_IO_ENOTSOCK: |
1309 | 0 | errmsg = "not a socket"; break; |
1310 | 0 | case XML_IO_EISCONN: |
1311 | 0 | errmsg = "already connected"; break; |
1312 | 0 | case XML_IO_ECONNREFUSED: |
1313 | 0 | errmsg = "connection refused"; break; |
1314 | 0 | case XML_IO_ENETUNREACH: |
1315 | 0 | errmsg = "unreachable network"; break; |
1316 | 0 | case XML_IO_EADDRINUSE: |
1317 | 0 | errmsg = "address in use"; break; |
1318 | 0 | case XML_IO_EALREADY: |
1319 | 0 | errmsg = "already in use"; break; |
1320 | 0 | case XML_IO_EAFNOSUPPORT: |
1321 | 0 | errmsg = "unknown address family"; break; |
1322 | 0 | case XML_IO_UNSUPPORTED_PROTOCOL: |
1323 | 0 | errmsg = "unsupported protocol"; break; |
1324 | | |
1325 | 4.44k | default: |
1326 | 4.44k | errmsg = "Unregistered error message"; |
1327 | 6.61M | } |
1328 | | |
1329 | 6.61M | return(errmsg); |
1330 | 6.61M | } |
1331 | | |
1332 | | void |
1333 | 0 | xmlVPrintErrorMessage(const char *fmt, va_list ap) { |
1334 | 0 | vfprintf(stderr, fmt, ap); |
1335 | 0 | } |
1336 | | |
1337 | | void |
1338 | 0 | xmlPrintErrorMessage(const char *fmt, ...) { |
1339 | 0 | va_list ap; |
1340 | |
|
1341 | 0 | va_start(ap, fmt); |
1342 | 0 | xmlVPrintErrorMessage(fmt, ap); |
1343 | 0 | va_end(ap); |
1344 | 0 | } |
1345 | | |
1346 | | void |
1347 | 0 | xmlAbort(const char *fmt, ...) { |
1348 | 0 | va_list ap; |
1349 | |
|
1350 | 0 | va_start(ap, fmt); |
1351 | 0 | xmlVPrintErrorMessage(fmt, ap); |
1352 | 0 | va_end(ap); |
1353 | |
|
1354 | 0 | abort(); |
1355 | 0 | } |