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