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