OLD | NEW |
1 /* | 1 /* |
2 * error.c: module displaying/handling XML parser errors | 2 * error.c: module displaying/handling XML parser errors |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * Daniel Veillard <daniel@veillard.com> | 6 * Daniel Veillard <daniel@veillard.com> |
7 */ | 7 */ |
8 | 8 |
9 #define IN_LIBXML | 9 #define IN_LIBXML |
10 #include "libxml.h" | 10 #include "libxml.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 char *larger; \ | 26 char *larger; \ |
27 va_list ap; \ | 27 va_list ap; \ |
28 \ | 28 \ |
29 str = (char *) xmlMalloc(150); \ | 29 str = (char *) xmlMalloc(150); \ |
30 if (str != NULL) { \ | 30 if (str != NULL) { \ |
31 \ | 31 \ |
32 size = 150; \ | 32 size = 150; \ |
33 \ | 33 \ |
34 while (size < 64000) { \ | 34 while (size < 64000) { \ |
35 va_start(ap, msg); \ | 35 va_start(ap, msg); \ |
36 » chars = vsnprintf(str, size, msg, ap);» » » \ | 36 » chars = vsnprintf(str, size, msg, ap);» » » \ |
37 va_end(ap); \ | 37 va_end(ap); \ |
38 if ((chars > -1) && (chars < size)) { \ | 38 if ((chars > -1) && (chars < size)) { \ |
39 if (prev_size == chars) { \ | 39 if (prev_size == chars) { \ |
40 break; \ | 40 break; \ |
41 } else { \ | 41 } else { \ |
42 prev_size = chars; \ | 42 prev_size = chars; \ |
43 } \ | 43 } \ |
44 } \ | 44 } \ |
45 if (chars > -1) \ | 45 if (chars > -1) \ |
46 size += chars + 1; \ | 46 size += chars + 1; \ |
47 else \ | 47 else \ |
48 size += 100; \ | 48 size += 100; \ |
49 if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\ | 49 if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\ |
50 break; \ | 50 break; \ |
51 } \ | 51 } \ |
52 str = larger; \ | 52 str = larger; \ |
53 }} \ | 53 }} \ |
54 } | 54 } |
55 | 55 |
56 /************************************************************************ | 56 /************************************************************************ |
57 * » » » » » » » » » * | 57 *» » » » » » » » » * |
58 * » » » Handling of out of context errors» » * | 58 *» » » Handling of out of context errors» » * |
59 * » » » » » » » » » * | 59 *» » » » » » » » » * |
60 ************************************************************************/ | 60 ************************************************************************/ |
61 | 61 |
62 /** | 62 /** |
63 * xmlGenericErrorDefaultFunc: | 63 * xmlGenericErrorDefaultFunc: |
64 * @ctx: an error context | 64 * @ctx: an error context |
65 * @msg: the message to display/transmit | 65 * @msg: the message to display/transmit |
66 * @...: extra parameters for the message display | 66 * @...: extra parameters for the message display |
67 * | 67 * |
68 * Default handler for out of context error messages. | 68 * Default handler for out of context error messages. |
69 */ | 69 */ |
70 void XMLCDECL | 70 void XMLCDECL |
71 xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { | 71 xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { |
72 va_list args; | 72 va_list args; |
73 | 73 |
74 if (xmlGenericErrorContext == NULL) | 74 if (xmlGenericErrorContext == NULL) |
75 xmlGenericErrorContext = (void *) stderr; | 75 xmlGenericErrorContext = (void *) stderr; |
76 | 76 |
77 va_start(args, msg); | 77 va_start(args, msg); |
78 vfprintf((FILE *)xmlGenericErrorContext, msg, args); | 78 vfprintf((FILE *)xmlGenericErrorContext, msg, args); |
79 va_end(args); | 79 va_end(args); |
80 } | 80 } |
81 | 81 |
82 /** | 82 /** |
83 * initGenericErrorDefaultFunc: | 83 * initGenericErrorDefaultFunc: |
84 * @handler: the handler | 84 * @handler: the handler |
85 * | 85 * |
86 * Set or reset (if NULL) the default handler for generic errors | 86 * Set or reset (if NULL) the default handler for generic errors |
87 * to the builtin error function. | 87 * to the builtin error function. |
88 */ | 88 */ |
89 void | 89 void |
90 initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler) | 90 initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler) |
91 { | 91 { |
92 if (handler == NULL) | 92 if (handler == NULL) |
93 xmlGenericError = xmlGenericErrorDefaultFunc; | 93 xmlGenericError = xmlGenericErrorDefaultFunc; |
94 else | 94 else |
95 xmlGenericError = (*handler); | 95 xmlGenericError = (*handler); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 * be passed as first argument to @handler | 130 * be passed as first argument to @handler |
131 * For multi-threaded applications, this must be set separately for each thread. | 131 * For multi-threaded applications, this must be set separately for each thread. |
132 */ | 132 */ |
133 void | 133 void |
134 xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { | 134 xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { |
135 xmlStructuredErrorContext = ctx; | 135 xmlStructuredErrorContext = ctx; |
136 xmlStructuredError = handler; | 136 xmlStructuredError = handler; |
137 } | 137 } |
138 | 138 |
139 /************************************************************************ | 139 /************************************************************************ |
140 * » » » » » » » » » * | 140 *» » » » » » » » » * |
141 * » » » Handling of parsing errors» » » * | 141 *» » » Handling of parsing errors» » » * |
142 * » » » » » » » » » * | 142 *» » » » » » » » » * |
143 ************************************************************************/ | 143 ************************************************************************/ |
144 | 144 |
145 /** | 145 /** |
146 * xmlParserPrintFileInfo: | 146 * xmlParserPrintFileInfo: |
147 * @input: an xmlParserInputPtr input | 147 * @input: an xmlParserInputPtr input |
148 * | 148 * |
149 * Displays the associated file and line informations for the current input | 149 * Displays the associated file and line informations for the current input |
150 */ | 150 */ |
151 | 151 |
152 void | 152 void |
153 xmlParserPrintFileInfo(xmlParserInputPtr input) { | 153 xmlParserPrintFileInfo(xmlParserInputPtr input) { |
154 if (input != NULL) { | 154 if (input != NULL) { |
155 if (input->filename) | 155 if (input->filename) |
156 xmlGenericError(xmlGenericErrorContext, | 156 xmlGenericError(xmlGenericErrorContext, |
157 "%s:%d: ", input->filename, | 157 "%s:%d: ", input->filename, |
158 input->line); | 158 input->line); |
159 else | 159 else |
160 xmlGenericError(xmlGenericErrorContext, | 160 xmlGenericError(xmlGenericErrorContext, |
161 "Entity: line %d: ", input->line); | 161 "Entity: line %d: ", input->line); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 /** | 165 /** |
166 * xmlParserPrintFileContext: | 166 * xmlParserPrintFileContext: |
167 * @input: an xmlParserInputPtr input | 167 * @input: an xmlParserInputPtr input |
168 * | 168 * |
169 * Displays current context within the input content for error tracking | 169 * Displays current context within the input content for error tracking |
170 */ | 170 */ |
171 | 171 |
172 static void | 172 static void |
173 xmlParserPrintFileContextInternal(xmlParserInputPtr input , | 173 xmlParserPrintFileContextInternal(xmlParserInputPtr input , |
174 xmlGenericErrorFunc channel, void *data ) { | 174 xmlGenericErrorFunc channel, void *data ) { |
175 const xmlChar *cur, *base; | 175 const xmlChar *cur, *base; |
176 unsigned int n, col; /* GCC warns if signed, because compared with si
zeof() */ | 176 unsigned int n, col; /* GCC warns if signed, because compared with si
zeof() */ |
177 xmlChar content[81]; /* space for 80 chars + line terminator */ | 177 xmlChar content[81]; /* space for 80 chars + line terminator */ |
178 xmlChar *ctnt; | 178 xmlChar *ctnt; |
179 | 179 |
180 if (input == NULL) return; | 180 if (input == NULL) return; |
181 cur = input->cur; | 181 cur = input->cur; |
182 base = input->base; | 182 base = input->base; |
183 /* skip backwards over any end-of-lines */ | 183 /* skip backwards over any end-of-lines */ |
184 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { | 184 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { |
185 cur--; | 185 cur--; |
186 } | 186 } |
187 n = 0; | 187 n = 0; |
188 /* search backwards for beginning-of-line (to max buff size) */ | 188 /* search backwards for beginning-of-line (to max buff size) */ |
189 while ((n++ < (sizeof(content)-1)) && (cur > base) && | 189 while ((n++ < (sizeof(content)-1)) && (cur > base) && |
190 » (*(cur) != '\n') && (*(cur) != '\r')) | 190 » (*(cur) != '\n') && (*(cur) != '\r')) |
191 cur--; | 191 cur--; |
192 if ((*(cur) == '\n') || (*(cur) == '\r')) cur++; | 192 if ((*(cur) == '\n') || (*(cur) == '\r')) cur++; |
193 /* calculate the error position in terms of the current position */ | 193 /* calculate the error position in terms of the current position */ |
194 col = input->cur - cur; | 194 col = input->cur - cur; |
195 /* search forward for end-of-line (to max buff size) */ | 195 /* search forward for end-of-line (to max buff size) */ |
196 n = 0; | 196 n = 0; |
197 ctnt = content; | 197 ctnt = content; |
198 /* copy selected text to our buffer */ | 198 /* copy selected text to our buffer */ |
199 while ((*cur != 0) && (*(cur) != '\n') && | 199 while ((*cur != 0) && (*(cur) != '\n') && |
200 » (*(cur) != '\r') && (n < sizeof(content)-1)) { | 200 » (*(cur) != '\r') && (n < sizeof(content)-1)) { |
201 *ctnt++ = *cur++; | 201 *ctnt++ = *cur++; |
202 n++; | 202 n++; |
203 } | 203 } |
204 *ctnt = 0; | 204 *ctnt = 0; |
205 /* print out the selected text */ | 205 /* print out the selected text */ |
206 channel(data ,"%s\n", content); | 206 channel(data ,"%s\n", content); |
207 /* create blank line with problem pointer */ | 207 /* create blank line with problem pointer */ |
208 n = 0; | 208 n = 0; |
209 ctnt = content; | 209 ctnt = content; |
210 /* (leave buffer space for pointer + line terminator) */ | 210 /* (leave buffer space for pointer + line terminator) */ |
211 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { | 211 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { |
212 if (*(ctnt) != '\t') | 212 if (*(ctnt) != '\t') |
213 *(ctnt) = ' '; | 213 *(ctnt) = ' '; |
214 ctnt++; | 214 ctnt++; |
215 } | 215 } |
216 *ctnt++ = '^'; | 216 *ctnt++ = '^'; |
217 *ctnt = 0; | 217 *ctnt = 0; |
218 channel(data ,"%s\n", content); | 218 channel(data ,"%s\n", content); |
219 } | 219 } |
220 | 220 |
221 /** | 221 /** |
222 * xmlParserPrintFileContext: | 222 * xmlParserPrintFileContext: |
223 * @input: an xmlParserInputPtr input | 223 * @input: an xmlParserInputPtr input |
224 * | 224 * |
225 * Displays current context within the input content for error tracking | 225 * Displays current context within the input content for error tracking |
226 */ | 226 */ |
227 void | 227 void |
228 xmlParserPrintFileContext(xmlParserInputPtr input) { | 228 xmlParserPrintFileContext(xmlParserInputPtr input) { |
229 xmlParserPrintFileContextInternal(input, xmlGenericError, | 229 xmlParserPrintFileContextInternal(input, xmlGenericError, |
230 xmlGenericErrorContext); | 230 xmlGenericErrorContext); |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
234 * xmlReportError: | 234 * xmlReportError: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 285 } |
286 if (input != NULL) { | 286 if (input != NULL) { |
287 if (input->filename) | 287 if (input->filename) |
288 channel(data, "%s:%d: ", input->filename, input->line); | 288 channel(data, "%s:%d: ", input->filename, input->line); |
289 else if ((line != 0) && (domain == XML_FROM_PARSER)) | 289 else if ((line != 0) && (domain == XML_FROM_PARSER)) |
290 channel(data, "Entity: line %d: ", input->line); | 290 channel(data, "Entity: line %d: ", input->line); |
291 } | 291 } |
292 } else { | 292 } else { |
293 if (file != NULL) | 293 if (file != NULL) |
294 channel(data, "%s:%d: ", file, line); | 294 channel(data, "%s:%d: ", file, line); |
295 else if ((line != 0) && (domain == XML_FROM_PARSER)) | 295 else if ((line != 0) && |
| 296 » ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)|| |
| 297 » » (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) || |
| 298 » » (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV))) |
296 channel(data, "Entity: line %d: ", line); | 299 channel(data, "Entity: line %d: ", line); |
297 } | 300 } |
298 if (name != NULL) { | 301 if (name != NULL) { |
299 channel(data, "element %s: ", name); | 302 channel(data, "element %s: ", name); |
300 } | 303 } |
301 switch (domain) { | 304 switch (domain) { |
302 case XML_FROM_PARSER: | 305 case XML_FROM_PARSER: |
303 channel(data, "parser "); | 306 channel(data, "parser "); |
304 break; | 307 break; |
305 case XML_FROM_NAMESPACE: | 308 case XML_FROM_NAMESPACE: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 break; | 356 break; |
354 case XML_FROM_C14N: | 357 case XML_FROM_C14N: |
355 channel(data, "C14N "); | 358 channel(data, "C14N "); |
356 break; | 359 break; |
357 case XML_FROM_XSLT: | 360 case XML_FROM_XSLT: |
358 channel(data, "XSLT "); | 361 channel(data, "XSLT "); |
359 break; | 362 break; |
360 case XML_FROM_I18N: | 363 case XML_FROM_I18N: |
361 channel(data, "encoding "); | 364 channel(data, "encoding "); |
362 break; | 365 break; |
| 366 case XML_FROM_SCHEMATRONV: |
| 367 channel(data, "schematron "); |
| 368 break; |
| 369 case XML_FROM_BUFFER: |
| 370 channel(data, "internal buffer "); |
| 371 break; |
| 372 case XML_FROM_URI: |
| 373 channel(data, "URI "); |
| 374 break; |
363 default: | 375 default: |
364 break; | 376 break; |
365 } | 377 } |
366 switch (level) { | 378 switch (level) { |
367 case XML_ERR_NONE: | 379 case XML_ERR_NONE: |
368 channel(data, ": "); | 380 channel(data, ": "); |
369 break; | 381 break; |
370 case XML_ERR_WARNING: | 382 case XML_ERR_WARNING: |
371 channel(data, "warning : "); | 383 channel(data, "warning : "); |
372 break; | 384 break; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 * @ctx: the parser context or NULL | 434 * @ctx: the parser context or NULL |
423 * @domain: the domain for the error | 435 * @domain: the domain for the error |
424 * @code: the code for the error | 436 * @code: the code for the error |
425 * @level: the xmlErrorLevel for the error | 437 * @level: the xmlErrorLevel for the error |
426 * @file: the file source of the error (or NULL) | 438 * @file: the file source of the error (or NULL) |
427 * @line: the line of the error or 0 if N/A | 439 * @line: the line of the error or 0 if N/A |
428 * @str1: extra string info | 440 * @str1: extra string info |
429 * @str2: extra string info | 441 * @str2: extra string info |
430 * @str3: extra string info | 442 * @str3: extra string info |
431 * @int1: extra int info | 443 * @int1: extra int info |
432 * @col: column number of the error or 0 if N/A | 444 * @col: column number of the error or 0 if N/A |
433 * @msg: the message to display/transmit | 445 * @msg: the message to display/transmit |
434 * @...: extra parameters for the message display | 446 * @...: extra parameters for the message display |
435 * | 447 * |
436 * Update the appropriate global or contextual error structure, | 448 * Update the appropriate global or contextual error structure, |
437 * then forward the error message down the parser or generic | 449 * then forward the error message down the parser or generic |
438 * error callback handler | 450 * error callback handler |
439 */ | 451 */ |
440 void XMLCDECL | 452 void XMLCDECL |
441 __xmlRaiseError(xmlStructuredErrorFunc schannel, | 453 __xmlRaiseError(xmlStructuredErrorFunc schannel, |
442 xmlGenericErrorFunc channel, void *data, void *ctx, | 454 xmlGenericErrorFunc channel, void *data, void *ctx, |
443 void *nod, int domain, int code, xmlErrorLevel level, | 455 void *nod, int domain, int code, xmlErrorLevel level, |
444 const char *file, int line, const char *str1, | 456 const char *file, int line, const char *str1, |
445 const char *str2, const char *str3, int int1, int col, | 457 const char *str2, const char *str3, int int1, int col, |
446 const char *msg, ...) | 458 const char *msg, ...) |
447 { | 459 { |
448 xmlParserCtxtPtr ctxt = NULL; | 460 xmlParserCtxtPtr ctxt = NULL; |
449 xmlNodePtr node = (xmlNodePtr) nod; | 461 xmlNodePtr node = (xmlNodePtr) nod; |
450 char *str = NULL; | 462 char *str = NULL; |
451 xmlParserInputPtr input = NULL; | 463 xmlParserInputPtr input = NULL; |
452 xmlErrorPtr to = &xmlLastError; | 464 xmlErrorPtr to = &xmlLastError; |
453 xmlNodePtr baseptr = NULL; | 465 xmlNodePtr baseptr = NULL; |
454 | 466 |
| 467 if (code == XML_ERR_OK) |
| 468 return; |
455 if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING)) | 469 if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING)) |
456 return; | 470 return; |
457 if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || | 471 if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
458 (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || | 472 (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
459 (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { | 473 (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
460 ctxt = (xmlParserCtxtPtr) ctx; | 474 ctxt = (xmlParserCtxtPtr) ctx; |
461 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && | 475 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && |
462 » (ctxt->sax->initialized == XML_SAX2_MAGIC)) | 476 » (ctxt->sax->initialized == XML_SAX2_MAGIC) && |
| 477 » (ctxt->sax->serror != NULL)) { |
463 schannel = ctxt->sax->serror; | 478 schannel = ctxt->sax->serror; |
| 479 data = ctxt->userData; |
| 480 } |
464 } | 481 } |
465 /* | 482 /* |
466 * Check if structured error handler set | 483 * Check if structured error handler set |
467 */ | 484 */ |
468 if (schannel == NULL) { | 485 if (schannel == NULL) { |
469 schannel = xmlStructuredError; | 486 schannel = xmlStructuredError; |
470 /* | 487 /* |
471 * if user has defined handler, change data ptr to user's choice | 488 * if user has defined handler, change data ptr to user's choice |
472 */ | 489 */ |
473 if (schannel != NULL) | 490 if (schannel != NULL) |
474 data = xmlStructuredErrorContext; | 491 data = xmlStructuredErrorContext; |
475 } | 492 } |
476 if ((domain == XML_FROM_VALID) && | |
477 ((channel == xmlParserValidityError) || | |
478 (channel == xmlParserValidityWarning))) { | |
479 ctxt = (xmlParserCtxtPtr) ctx; | |
480 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) && | |
481 (ctxt->sax->initialized == XML_SAX2_MAGIC)) | |
482 schannel = ctxt->sax->serror; | |
483 } | |
484 if (code == XML_ERR_OK) | |
485 return; | |
486 /* | 493 /* |
487 * Formatting the message | 494 * Formatting the message |
488 */ | 495 */ |
489 if (msg == NULL) { | 496 if (msg == NULL) { |
490 str = (char *) xmlStrdup(BAD_CAST "No error message provided"); | 497 str = (char *) xmlStrdup(BAD_CAST "No error message provided"); |
491 } else { | 498 } else { |
492 XML_GET_VAR_STR(msg, str); | 499 XML_GET_VAR_STR(msg, str); |
493 } | 500 } |
494 | 501 |
495 /* | 502 /* |
(...skipping 23 matching lines...) Expand all Loading... |
519 for (i = 0; | 526 for (i = 0; |
520 ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE)); | 527 ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE)); |
521 i++) | 528 i++) |
522 node = node->parent; | 529 node = node->parent; |
523 if ((baseptr == NULL) && (node != NULL) && | 530 if ((baseptr == NULL) && (node != NULL) && |
524 (node->doc != NULL) && (node->doc->URL != NULL)) | 531 (node->doc != NULL) && (node->doc->URL != NULL)) |
525 baseptr = node; | 532 baseptr = node; |
526 | 533 |
527 if ((node != NULL) && (node->type == XML_ELEMENT_NODE)) | 534 if ((node != NULL) && (node->type == XML_ELEMENT_NODE)) |
528 line = node->line; | 535 line = node->line; |
| 536 if ((line == 0) || (line == 65535)) |
| 537 line = xmlGetLineNo(node); |
529 } | 538 } |
530 | 539 |
531 /* | 540 /* |
532 * Save the information about the error | 541 * Save the information about the error |
533 */ | 542 */ |
534 xmlResetError(to); | 543 xmlResetError(to); |
535 to->domain = domain; | 544 to->domain = domain; |
536 to->code = code; | 545 to->code = code; |
537 to->message = str; | 546 to->message = str; |
538 to->level = level; | 547 to->level = level; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (str3 != NULL) | 591 if (str3 != NULL) |
583 to->str3 = (char *) xmlStrdup((const xmlChar *) str3); | 592 to->str3 = (char *) xmlStrdup((const xmlChar *) str3); |
584 to->int1 = int1; | 593 to->int1 = int1; |
585 to->int2 = col; | 594 to->int2 = col; |
586 to->node = node; | 595 to->node = node; |
587 to->ctxt = ctx; | 596 to->ctxt = ctx; |
588 | 597 |
589 if (to != &xmlLastError) | 598 if (to != &xmlLastError) |
590 xmlCopyError(to,&xmlLastError); | 599 xmlCopyError(to,&xmlLastError); |
591 | 600 |
| 601 if (schannel != NULL) { |
| 602 schannel(data, to); |
| 603 return; |
| 604 } |
| 605 |
592 /* | 606 /* |
593 * Find the callback channel if channel param is NULL | 607 * Find the callback channel if channel param is NULL |
594 */ | 608 */ |
595 if ((ctxt != NULL) && (channel == NULL) && | 609 if ((ctxt != NULL) && (channel == NULL) && |
596 (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { | 610 (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { |
597 if (level == XML_ERR_WARNING) | 611 if (level == XML_ERR_WARNING) |
598 channel = ctxt->sax->warning; | 612 channel = ctxt->sax->warning; |
599 else | 613 else |
600 channel = ctxt->sax->error; | 614 channel = ctxt->sax->error; |
601 data = ctxt->userData; | 615 data = ctxt->userData; |
602 } else if (channel == NULL) { | 616 } else if (channel == NULL) { |
603 if ((schannel == NULL) && (xmlStructuredError != NULL)) { | 617 » channel = xmlGenericError; |
604 » schannel = xmlStructuredError; | 618 » if (ctxt != NULL) { |
605 » data = xmlStructuredErrorContext; | 619 » data = ctxt; |
606 } else { | 620 } else { |
607 » channel = xmlGenericError; | 621 » data = xmlGenericErrorContext; |
608 » if (!data) { | |
609 » » data = xmlGenericErrorContext; | |
610 » } | |
611 } | 622 } |
612 } | 623 } |
613 if (schannel != NULL) { | |
614 schannel(data, to); | |
615 return; | |
616 } | |
617 if (channel == NULL) | 624 if (channel == NULL) |
618 return; | 625 return; |
619 | 626 |
620 if ((channel == xmlParserError) || | 627 if ((channel == xmlParserError) || |
621 (channel == xmlParserWarning) || | 628 (channel == xmlParserWarning) || |
622 (channel == xmlParserValidityError) || | 629 (channel == xmlParserValidityError) || |
623 (channel == xmlParserValidityWarning)) | 630 (channel == xmlParserValidityWarning)) |
624 xmlReportError(to, ctxt, str, NULL, NULL); | 631 xmlReportError(to, ctxt, str, NULL, NULL); |
625 else if ((channel == (xmlGenericErrorFunc) fprintf) || | 632 else if ((channel == (xmlGenericErrorFunc) fprintf) || |
626 (channel == xmlGenericErrorDefaultFunc)) | 633 (channel == xmlGenericErrorDefaultFunc)) |
(...skipping 30 matching lines...) Expand all Loading... |
657 __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain, | 664 __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain, |
658 code, XML_ERR_ERROR, NULL, 0, extra, | 665 code, XML_ERR_ERROR, NULL, 0, extra, |
659 NULL, NULL, 0, 0, msg, extra); | 666 NULL, NULL, 0, 0, msg, extra); |
660 } | 667 } |
661 } | 668 } |
662 /** | 669 /** |
663 * xmlParserError: | 670 * xmlParserError: |
664 * @ctx: an XML parser context | 671 * @ctx: an XML parser context |
665 * @msg: the message to display/transmit | 672 * @msg: the message to display/transmit |
666 * @...: extra parameters for the message display | 673 * @...: extra parameters for the message display |
667 * | 674 * |
668 * Display and format an error messages, gives file, line, position and | 675 * Display and format an error messages, gives file, line, position and |
669 * extra parameters. | 676 * extra parameters. |
670 */ | 677 */ |
671 void XMLCDECL | 678 void XMLCDECL |
672 xmlParserError(void *ctx, const char *msg, ...) | 679 xmlParserError(void *ctx, const char *msg, ...) |
673 { | 680 { |
674 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 681 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
675 xmlParserInputPtr input = NULL; | 682 xmlParserInputPtr input = NULL; |
676 xmlParserInputPtr cur = NULL; | 683 xmlParserInputPtr cur = NULL; |
677 char * str; | 684 char * str; |
(...skipping 22 matching lines...) Expand all Loading... |
700 xmlParserPrintFileContext(cur); | 707 xmlParserPrintFileContext(cur); |
701 } | 708 } |
702 } | 709 } |
703 } | 710 } |
704 | 711 |
705 /** | 712 /** |
706 * xmlParserWarning: | 713 * xmlParserWarning: |
707 * @ctx: an XML parser context | 714 * @ctx: an XML parser context |
708 * @msg: the message to display/transmit | 715 * @msg: the message to display/transmit |
709 * @...: extra parameters for the message display | 716 * @...: extra parameters for the message display |
710 * | 717 * |
711 * Display and format a warning messages, gives file, line, position and | 718 * Display and format a warning messages, gives file, line, position and |
712 * extra parameters. | 719 * extra parameters. |
713 */ | 720 */ |
714 void XMLCDECL | 721 void XMLCDECL |
715 xmlParserWarning(void *ctx, const char *msg, ...) | 722 xmlParserWarning(void *ctx, const char *msg, ...) |
716 { | 723 { |
717 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 724 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
718 xmlParserInputPtr input = NULL; | 725 xmlParserInputPtr input = NULL; |
719 xmlParserInputPtr cur = NULL; | 726 xmlParserInputPtr cur = NULL; |
720 char * str; | 727 char * str; |
721 | 728 |
722 if (ctxt != NULL) { | 729 if (ctxt != NULL) { |
723 input = ctxt->input; | 730 input = ctxt->input; |
724 if ((input != NULL) && (input->filename == NULL) && | 731 if ((input != NULL) && (input->filename == NULL) && |
725 (ctxt->inputNr > 1)) { | 732 (ctxt->inputNr > 1)) { |
726 cur = input; | 733 cur = input; |
727 input = ctxt->inputTab[ctxt->inputNr - 2]; | 734 input = ctxt->inputTab[ctxt->inputNr - 2]; |
728 } | 735 } |
729 xmlParserPrintFileInfo(input); | 736 xmlParserPrintFileInfo(input); |
730 } | 737 } |
731 | 738 |
732 xmlGenericError(xmlGenericErrorContext, "warning: "); | 739 xmlGenericError(xmlGenericErrorContext, "warning: "); |
733 XML_GET_VAR_STR(msg, str); | 740 XML_GET_VAR_STR(msg, str); |
734 xmlGenericError(xmlGenericErrorContext, "%s", str); | 741 xmlGenericError(xmlGenericErrorContext, "%s", str); |
735 if (str != NULL) | 742 if (str != NULL) |
736 xmlFree(str); | 743 xmlFree(str); |
737 | 744 |
738 if (ctxt != NULL) { | 745 if (ctxt != NULL) { |
739 xmlParserPrintFileContext(input); | 746 xmlParserPrintFileContext(input); |
740 if (cur != NULL) { | 747 if (cur != NULL) { |
741 xmlParserPrintFileInfo(cur); | 748 xmlParserPrintFileInfo(cur); |
742 xmlGenericError(xmlGenericErrorContext, "\n"); | 749 xmlGenericError(xmlGenericErrorContext, "\n"); |
743 xmlParserPrintFileContext(cur); | 750 xmlParserPrintFileContext(cur); |
744 } | 751 } |
745 } | 752 } |
746 } | 753 } |
747 | 754 |
748 /************************************************************************ | 755 /************************************************************************ |
749 * » » » » » » » » » * | 756 *» » » » » » » » » * |
750 * » » » Handling of validation errors» » » * | 757 *» » » Handling of validation errors» » » * |
751 * » » » » » » » » » * | 758 *» » » » » » » » » * |
752 ************************************************************************/ | 759 ************************************************************************/ |
753 | 760 |
754 /** | 761 /** |
755 * xmlParserValidityError: | 762 * xmlParserValidityError: |
756 * @ctx: an XML parser context | 763 * @ctx: an XML parser context |
757 * @msg: the message to display/transmit | 764 * @msg: the message to display/transmit |
758 * @...: extra parameters for the message display | 765 * @...: extra parameters for the message display |
759 * | 766 * |
760 * Display and format an validity error messages, gives file, | 767 * Display and format an validity error messages, gives file, |
761 * line, position and extra parameters. | 768 * line, position and extra parameters. |
762 */ | 769 */ |
763 void XMLCDECL | 770 void XMLCDECL |
764 xmlParserValidityError(void *ctx, const char *msg, ...) | 771 xmlParserValidityError(void *ctx, const char *msg, ...) |
765 { | 772 { |
766 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 773 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
767 xmlParserInputPtr input = NULL; | 774 xmlParserInputPtr input = NULL; |
768 char * str; | 775 char * str; |
769 int len = xmlStrlen((const xmlChar *) msg); | 776 int len = xmlStrlen((const xmlChar *) msg); |
770 static int had_info = 0; | 777 static int had_info = 0; |
771 | 778 |
772 if ((len > 1) && (msg[len - 2] != ':')) { | 779 if ((len > 1) && (msg[len - 2] != ':')) { |
773 if (ctxt != NULL) { | 780 if (ctxt != NULL) { |
774 input = ctxt->input; | 781 input = ctxt->input; |
775 if ((input->filename == NULL) && (ctxt->inputNr > 1)) | 782 if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
776 input = ctxt->inputTab[ctxt->inputNr - 2]; | 783 input = ctxt->inputTab[ctxt->inputNr - 2]; |
777 » » | 784 |
778 if (had_info == 0) { | 785 if (had_info == 0) { |
779 xmlParserPrintFileInfo(input); | 786 xmlParserPrintFileInfo(input); |
780 } | 787 } |
781 } | 788 } |
782 xmlGenericError(xmlGenericErrorContext, "validity error: "); | 789 xmlGenericError(xmlGenericErrorContext, "validity error: "); |
783 had_info = 0; | 790 had_info = 0; |
784 } else { | 791 } else { |
785 had_info = 1; | 792 had_info = 1; |
786 } | 793 } |
787 | 794 |
788 XML_GET_VAR_STR(msg, str); | 795 XML_GET_VAR_STR(msg, str); |
789 xmlGenericError(xmlGenericErrorContext, "%s", str); | 796 xmlGenericError(xmlGenericErrorContext, "%s", str); |
790 if (str != NULL) | 797 if (str != NULL) |
791 xmlFree(str); | 798 xmlFree(str); |
792 | 799 |
793 if ((ctxt != NULL) && (input != NULL)) { | 800 if ((ctxt != NULL) && (input != NULL)) { |
794 xmlParserPrintFileContext(input); | 801 xmlParserPrintFileContext(input); |
795 } | 802 } |
796 } | 803 } |
797 | 804 |
798 /** | 805 /** |
799 * xmlParserValidityWarning: | 806 * xmlParserValidityWarning: |
800 * @ctx: an XML parser context | 807 * @ctx: an XML parser context |
801 * @msg: the message to display/transmit | 808 * @msg: the message to display/transmit |
802 * @...: extra parameters for the message display | 809 * @...: extra parameters for the message display |
803 * | 810 * |
804 * Display and format a validity warning messages, gives file, line, | 811 * Display and format a validity warning messages, gives file, line, |
805 * position and extra parameters. | 812 * position and extra parameters. |
806 */ | 813 */ |
807 void XMLCDECL | 814 void XMLCDECL |
808 xmlParserValidityWarning(void *ctx, const char *msg, ...) | 815 xmlParserValidityWarning(void *ctx, const char *msg, ...) |
809 { | 816 { |
810 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 817 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
811 xmlParserInputPtr input = NULL; | 818 xmlParserInputPtr input = NULL; |
812 char * str; | 819 char * str; |
813 int len = xmlStrlen((const xmlChar *) msg); | 820 int len = xmlStrlen((const xmlChar *) msg); |
814 | 821 |
815 if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { | 822 if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { |
816 input = ctxt->input; | 823 input = ctxt->input; |
817 if ((input->filename == NULL) && (ctxt->inputNr > 1)) | 824 if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
818 input = ctxt->inputTab[ctxt->inputNr - 2]; | 825 input = ctxt->inputTab[ctxt->inputNr - 2]; |
819 | 826 |
820 xmlParserPrintFileInfo(input); | 827 xmlParserPrintFileInfo(input); |
821 } | 828 } |
822 | 829 |
823 xmlGenericError(xmlGenericErrorContext, "validity warning: "); | 830 xmlGenericError(xmlGenericErrorContext, "validity warning: "); |
824 XML_GET_VAR_STR(msg, str); | 831 XML_GET_VAR_STR(msg, str); |
825 xmlGenericError(xmlGenericErrorContext, "%s", str); | 832 xmlGenericError(xmlGenericErrorContext, "%s", str); |
826 if (str != NULL) | 833 if (str != NULL) |
827 xmlFree(str); | 834 xmlFree(str); |
828 | 835 |
829 if (ctxt != NULL) { | 836 if (ctxt != NULL) { |
830 xmlParserPrintFileContext(input); | 837 xmlParserPrintFileContext(input); |
831 } | 838 } |
832 } | 839 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 to->file = file; | 987 to->file = file; |
981 to->str1 = str1; | 988 to->str1 = str1; |
982 to->str2 = str2; | 989 to->str2 = str2; |
983 to->str3 = str3; | 990 to->str3 = str3; |
984 | 991 |
985 return 0; | 992 return 0; |
986 } | 993 } |
987 | 994 |
988 #define bottom_error | 995 #define bottom_error |
989 #include "elfgcchack.h" | 996 #include "elfgcchack.h" |
OLD | NEW |