Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * error.c: module displaying/handling XML parser errors |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * Daniel Veillard <daniel@veillard.com> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 9 | #define IN_LIBXML |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 10 | #include "libxml.h" |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 12 | #include <string.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 13 | #include <stdarg.h> |
| 14 | #include <libxml/parser.h> |
| 15 | #include <libxml/xmlerror.h> |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 16 | #include <libxml/xmlmemory.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 17 | #include <libxml/globals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 18 | |
Nick Wellnhofer | 0f568c0 | 2022-08-26 01:22:33 +0200 | [diff] [blame] | 19 | #include "private/error.h" |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 20 | |
Nick Wellnhofer | 59b3366 | 2022-12-27 14:15:51 +0100 | [diff] [blame] | 21 | #define XML_MAX_ERRORS 100 |
| 22 | |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 23 | #define XML_GET_VAR_STR(msg, str) { \ |
Daniel Veillard | dbf7bfe | 2005-10-28 08:25:51 +0000 | [diff] [blame] | 24 | int size, prev_size = -1; \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 25 | int chars; \ |
| 26 | char *larger; \ |
| 27 | va_list ap; \ |
| 28 | \ |
| 29 | str = (char *) xmlMalloc(150); \ |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 30 | if (str != NULL) { \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 31 | \ |
| 32 | size = 150; \ |
| 33 | \ |
Daniel Veillard | fa75097 | 2008-04-03 07:31:25 +0000 | [diff] [blame] | 34 | while (size < 64000) { \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 35 | va_start(ap, msg); \ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 36 | chars = vsnprintf(str, size, msg, ap); \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 37 | va_end(ap); \ |
Daniel Veillard | dbf7bfe | 2005-10-28 08:25:51 +0000 | [diff] [blame] | 38 | if ((chars > -1) && (chars < size)) { \ |
| 39 | if (prev_size == chars) { \ |
| 40 | break; \ |
| 41 | } else { \ |
| 42 | prev_size = chars; \ |
| 43 | } \ |
| 44 | } \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 45 | if (chars > -1) \ |
| 46 | size += chars + 1; \ |
| 47 | else \ |
| 48 | size += 100; \ |
| 49 | if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\ |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 50 | break; \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 51 | } \ |
| 52 | str = larger; \ |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 53 | }} \ |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 54 | } |
Bjorn Reese | 570ff08 | 2001-06-05 12:45:55 +0000 | [diff] [blame] | 55 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 56 | /************************************************************************ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 57 | * * |
| 58 | * Handling of out of context errors * |
| 59 | * * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 60 | ************************************************************************/ |
| 61 | |
| 62 | /** |
| 63 | * xmlGenericErrorDefaultFunc: |
| 64 | * @ctx: an error context |
| 65 | * @msg: the message to display/transmit |
| 66 | * @...: extra parameters for the message display |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 67 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 68 | * Default handler for out of context error messages. |
| 69 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 70 | void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 71 | xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 72 | va_list args; |
| 73 | |
| 74 | if (xmlGenericErrorContext == NULL) |
| 75 | xmlGenericErrorContext = (void *) stderr; |
| 76 | |
| 77 | va_start(args, msg); |
| 78 | vfprintf((FILE *)xmlGenericErrorContext, msg, args); |
| 79 | va_end(args); |
| 80 | } |
| 81 | |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 82 | /** |
| 83 | * initGenericErrorDefaultFunc: |
| 84 | * @handler: the handler |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 85 | * |
Nick Wellnhofer | a966967 | 2022-09-09 01:44:00 +0200 | [diff] [blame] | 86 | * DEPRECATED: Use xmlSetGenericErrorFunc. |
| 87 | * |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 88 | * Set or reset (if NULL) the default handler for generic errors |
Daniel Veillard | 7424eb6 | 2003-01-24 14:14:52 +0000 | [diff] [blame] | 89 | * to the builtin error function. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 90 | */ |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 91 | void |
Daniel Veillard | db5850a | 2002-01-18 11:49:26 +0000 | [diff] [blame] | 92 | initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler) |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 93 | { |
Daniel Veillard | db5850a | 2002-01-18 11:49:26 +0000 | [diff] [blame] | 94 | if (handler == NULL) |
| 95 | xmlGenericError = xmlGenericErrorDefaultFunc; |
| 96 | else |
Daniel Veillard | da0ff5d | 2004-04-20 09:45:26 +0000 | [diff] [blame] | 97 | xmlGenericError = (*handler); |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 98 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * xmlSetGenericErrorFunc: |
| 102 | * @ctx: the new error handling context |
| 103 | * @handler: the new handler function |
| 104 | * |
| 105 | * Function to reset the handler and the error context for out of |
| 106 | * context error messages. |
| 107 | * This simply means that @handler will be called for subsequent |
| 108 | * error messages while not parsing nor validating. And @ctx will |
| 109 | * be passed as first argument to @handler |
| 110 | * One can simply force messages to be emitted to another FILE * than |
| 111 | * stderr by setting @ctx to this file handle and @handler to NULL. |
Daniel Veillard | da3b29a | 2004-08-14 11:15:13 +0000 | [diff] [blame] | 112 | * For multi-threaded applications, this must be set separately for each thread. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 113 | */ |
| 114 | void |
| 115 | xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { |
| 116 | xmlGenericErrorContext = ctx; |
| 117 | if (handler != NULL) |
| 118 | xmlGenericError = handler; |
| 119 | else |
| 120 | xmlGenericError = xmlGenericErrorDefaultFunc; |
| 121 | } |
| 122 | |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 123 | /** |
| 124 | * xmlSetStructuredErrorFunc: |
| 125 | * @ctx: the new error handling context |
| 126 | * @handler: the new handler function |
| 127 | * |
| 128 | * Function to reset the handler and the error context for out of |
| 129 | * context structured error messages. |
| 130 | * This simply means that @handler will be called for subsequent |
| 131 | * error messages while not parsing nor validating. And @ctx will |
| 132 | * be passed as first argument to @handler |
Daniel Veillard | da3b29a | 2004-08-14 11:15:13 +0000 | [diff] [blame] | 133 | * For multi-threaded applications, this must be set separately for each thread. |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 134 | */ |
| 135 | void |
| 136 | xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { |
Wang Lam | 1de382e | 2009-08-24 17:34:25 +0200 | [diff] [blame] | 137 | xmlStructuredErrorContext = ctx; |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 138 | xmlStructuredError = handler; |
| 139 | } |
| 140 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 141 | /************************************************************************ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 142 | * * |
| 143 | * Handling of parsing errors * |
| 144 | * * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 145 | ************************************************************************/ |
| 146 | |
| 147 | /** |
| 148 | * xmlParserPrintFileInfo: |
| 149 | * @input: an xmlParserInputPtr input |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 150 | * |
Nick Wellnhofer | 20c6088 | 2020-03-08 17:19:42 +0100 | [diff] [blame] | 151 | * Displays the associated file and line information for the current input |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 152 | */ |
| 153 | |
| 154 | void |
| 155 | xmlParserPrintFileInfo(xmlParserInputPtr input) { |
| 156 | if (input != NULL) { |
| 157 | if (input->filename) |
| 158 | xmlGenericError(xmlGenericErrorContext, |
| 159 | "%s:%d: ", input->filename, |
| 160 | input->line); |
| 161 | else |
| 162 | xmlGenericError(xmlGenericErrorContext, |
| 163 | "Entity: line %d: ", input->line); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 168 | * xmlParserPrintFileContextInternal: |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 169 | * @input: an xmlParserInputPtr input |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 170 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 171 | * Displays current context within the input content for error tracking |
| 172 | */ |
| 173 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 174 | static void |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 175 | xmlParserPrintFileContextInternal(xmlParserInputPtr input , |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 176 | xmlGenericErrorFunc channel, void *data ) { |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 177 | const xmlChar *cur, *base, *start; |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 178 | unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */ |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 179 | xmlChar content[81]; /* space for 80 chars + line terminator */ |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 180 | xmlChar *ctnt; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 181 | |
Pavel Raiskup | c4184ba | 2015-12-01 13:24:44 +0100 | [diff] [blame] | 182 | if ((input == NULL) || (input->cur == NULL)) |
| 183 | return; |
Daniel Veillard | ce0b0d0 | 2015-11-20 15:01:22 +0800 | [diff] [blame] | 184 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 185 | cur = input->cur; |
| 186 | base = input->base; |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 187 | /* skip backwards over any end-of-lines */ |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 188 | while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 189 | cur--; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 190 | } |
| 191 | n = 0; |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 192 | /* search backwards for beginning-of-line (to max buff size) */ |
Nick Wellnhofer | d9a8dab | 2023-01-22 12:00:59 +0100 | [diff] [blame] | 193 | while ((n < sizeof(content) - 1) && (cur > base) && |
| 194 | (*cur != '\n') && (*cur != '\r')) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 195 | cur--; |
Nick Wellnhofer | d9a8dab | 2023-01-22 12:00:59 +0100 | [diff] [blame] | 196 | n++; |
| 197 | } |
| 198 | if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) { |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 199 | cur++; |
| 200 | } else { |
| 201 | /* skip over continuation bytes */ |
| 202 | while ((cur < input->cur) && ((*cur & 0xC0) == 0x80)) |
| 203 | cur++; |
| 204 | } |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 205 | /* calculate the error position in terms of the current position */ |
| 206 | col = input->cur - cur; |
| 207 | /* search forward for end-of-line (to max buff size) */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 208 | n = 0; |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 209 | start = cur; |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 210 | /* copy selected text to our buffer */ |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 211 | while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) { |
| 212 | int len = input->end - cur; |
| 213 | int c = xmlGetUTF8Char(cur, &len); |
| 214 | |
| 215 | if ((c < 0) || (n + len > sizeof(content)-1)) |
| 216 | break; |
| 217 | cur += len; |
| 218 | n += len; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 219 | } |
Nick Wellnhofer | 76c6da4 | 2022-12-04 23:01:00 +0100 | [diff] [blame] | 220 | memcpy(content, start, n); |
| 221 | content[n] = 0; |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 222 | /* print out the selected text */ |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 223 | channel(data ,"%s\n", content); |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 224 | /* create blank line with problem pointer */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 225 | n = 0; |
Daniel Veillard | 7533cc8 | 2001-04-24 15:52:00 +0000 | [diff] [blame] | 226 | ctnt = content; |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 227 | /* (leave buffer space for pointer + line terminator) */ |
| 228 | while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 229 | if (*(ctnt) != '\t') |
| 230 | *(ctnt) = ' '; |
William M. Brack | 6984830 | 2003-09-22 00:24:51 +0000 | [diff] [blame] | 231 | ctnt++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 232 | } |
William M. Brack | 3dd57f7 | 2003-05-13 02:06:18 +0000 | [diff] [blame] | 233 | *ctnt++ = '^'; |
| 234 | *ctnt = 0; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 235 | channel(data ,"%s\n", content); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 238 | /** |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 239 | * xmlParserPrintFileContext: |
| 240 | * @input: an xmlParserInputPtr input |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 241 | * |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 242 | * Displays current context within the input content for error tracking |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 243 | */ |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 244 | void |
| 245 | xmlParserPrintFileContext(xmlParserInputPtr input) { |
| 246 | xmlParserPrintFileContextInternal(input, xmlGenericError, |
| 247 | xmlGenericErrorContext); |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 248 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * xmlReportError: |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 252 | * @err: the error |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 253 | * @ctx: the parser context or NULL |
| 254 | * @str: the formatted error message |
| 255 | * |
Jared Yanovich | 2a350ee | 2019-09-30 17:04:54 +0200 | [diff] [blame] | 256 | * Report an error with its context, replace the 4 old error/warning |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 257 | * routines. |
| 258 | */ |
| 259 | static void |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 260 | xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, |
| 261 | xmlGenericErrorFunc channel, void *data) |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 262 | { |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 263 | char *file = NULL; |
| 264 | int line = 0; |
| 265 | int code = -1; |
| 266 | int domain; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 267 | const xmlChar *name = NULL; |
| 268 | xmlNodePtr node; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 269 | xmlErrorLevel level; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 270 | xmlParserInputPtr input = NULL; |
| 271 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 272 | |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 273 | if (err == NULL) |
| 274 | return; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 275 | |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 276 | if (channel == NULL) { |
| 277 | channel = xmlGenericError; |
| 278 | data = xmlGenericErrorContext; |
| 279 | } |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 280 | file = err->file; |
| 281 | line = err->line; |
| 282 | code = err->code; |
| 283 | domain = err->domain; |
| 284 | level = err->level; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 285 | node = err->node; |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 286 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 287 | if (code == XML_ERR_OK) |
| 288 | return; |
| 289 | |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 290 | if ((node != NULL) && (node->type == XML_ELEMENT_NODE)) |
| 291 | name = node->name; |
| 292 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 293 | /* |
| 294 | * Maintain the compatibility with the legacy error handling |
| 295 | */ |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 296 | if (ctxt != NULL) { |
| 297 | input = ctxt->input; |
| 298 | if ((input != NULL) && (input->filename == NULL) && |
| 299 | (ctxt->inputNr > 1)) { |
| 300 | cur = input; |
| 301 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 302 | } |
| 303 | if (input != NULL) { |
| 304 | if (input->filename) |
| 305 | channel(data, "%s:%d: ", input->filename, input->line); |
Daniel Veillard | d96f6d3 | 2003-10-07 21:25:12 +0000 | [diff] [blame] | 306 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 307 | channel(data, "Entity: line %d: ", input->line); |
| 308 | } |
| 309 | } else { |
| 310 | if (file != NULL) |
| 311 | channel(data, "%s:%d: ", file, line); |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 312 | else if ((line != 0) && |
Daniel Veillard | 97fa5b3 | 2012-08-14 11:01:07 +0800 | [diff] [blame] | 313 | ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)|| |
| 314 | (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) || |
| 315 | (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV))) |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 316 | channel(data, "Entity: line %d: ", line); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 317 | } |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 318 | if (name != NULL) { |
| 319 | channel(data, "element %s: ", name); |
| 320 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 321 | switch (domain) { |
| 322 | case XML_FROM_PARSER: |
| 323 | channel(data, "parser "); |
| 324 | break; |
| 325 | case XML_FROM_NAMESPACE: |
| 326 | channel(data, "namespace "); |
| 327 | break; |
| 328 | case XML_FROM_DTD: |
Daniel Veillard | 72b9e29 | 2003-10-28 15:44:17 +0000 | [diff] [blame] | 329 | case XML_FROM_VALID: |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 330 | channel(data, "validity "); |
| 331 | break; |
| 332 | case XML_FROM_HTML: |
| 333 | channel(data, "HTML parser "); |
| 334 | break; |
| 335 | case XML_FROM_MEMORY: |
| 336 | channel(data, "memory "); |
| 337 | break; |
| 338 | case XML_FROM_OUTPUT: |
| 339 | channel(data, "output "); |
| 340 | break; |
| 341 | case XML_FROM_IO: |
| 342 | channel(data, "I/O "); |
| 343 | break; |
| 344 | case XML_FROM_XINCLUDE: |
| 345 | channel(data, "XInclude "); |
| 346 | break; |
| 347 | case XML_FROM_XPATH: |
| 348 | channel(data, "XPath "); |
| 349 | break; |
| 350 | case XML_FROM_XPOINTER: |
| 351 | channel(data, "parser "); |
| 352 | break; |
| 353 | case XML_FROM_REGEXP: |
| 354 | channel(data, "regexp "); |
| 355 | break; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 356 | case XML_FROM_MODULE: |
| 357 | channel(data, "module "); |
| 358 | break; |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 359 | case XML_FROM_SCHEMASV: |
Daniel Veillard | 87db3a8 | 2003-10-10 10:52:58 +0000 | [diff] [blame] | 360 | channel(data, "Schemas validity "); |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 361 | break; |
| 362 | case XML_FROM_SCHEMASP: |
Daniel Veillard | 87db3a8 | 2003-10-10 10:52:58 +0000 | [diff] [blame] | 363 | channel(data, "Schemas parser "); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 364 | break; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 365 | case XML_FROM_RELAXNGP: |
| 366 | channel(data, "Relax-NG parser "); |
| 367 | break; |
| 368 | case XML_FROM_RELAXNGV: |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 369 | channel(data, "Relax-NG validity "); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 370 | break; |
| 371 | case XML_FROM_CATALOG: |
| 372 | channel(data, "Catalog "); |
| 373 | break; |
| 374 | case XML_FROM_C14N: |
| 375 | channel(data, "C14N "); |
| 376 | break; |
| 377 | case XML_FROM_XSLT: |
| 378 | channel(data, "XSLT "); |
| 379 | break; |
Daniel Veillard | 1fc3ed0 | 2005-08-24 12:46:09 +0000 | [diff] [blame] | 380 | case XML_FROM_I18N: |
| 381 | channel(data, "encoding "); |
| 382 | break; |
Daniel Veillard | 5756038 | 2012-07-24 11:44:23 +0800 | [diff] [blame] | 383 | case XML_FROM_SCHEMATRONV: |
| 384 | channel(data, "schematron "); |
| 385 | break; |
| 386 | case XML_FROM_BUFFER: |
| 387 | channel(data, "internal buffer "); |
| 388 | break; |
| 389 | case XML_FROM_URI: |
| 390 | channel(data, "URI "); |
| 391 | break; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 392 | default: |
| 393 | break; |
| 394 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 395 | switch (level) { |
| 396 | case XML_ERR_NONE: |
| 397 | channel(data, ": "); |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 398 | break; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 399 | case XML_ERR_WARNING: |
| 400 | channel(data, "warning : "); |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 401 | break; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 402 | case XML_ERR_ERROR: |
| 403 | channel(data, "error : "); |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 404 | break; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 405 | case XML_ERR_FATAL: |
| 406 | channel(data, "error : "); |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 407 | break; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 408 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 409 | if (str != NULL) { |
Daniel Veillard | 828ce83 | 2003-10-08 19:19:10 +0000 | [diff] [blame] | 410 | int len; |
| 411 | len = xmlStrlen((const xmlChar *)str); |
| 412 | if ((len > 0) && (str[len - 1] != '\n')) |
Daniel Veillard | 828ce83 | 2003-10-08 19:19:10 +0000 | [diff] [blame] | 413 | channel(data, "%s\n", str); |
Daniel Veillard | a885622 | 2003-10-08 19:26:03 +0000 | [diff] [blame] | 414 | else |
| 415 | channel(data, "%s", str); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 416 | } else { |
Daniel Veillard | 828ce83 | 2003-10-08 19:19:10 +0000 | [diff] [blame] | 417 | channel(data, "%s\n", "out of memory error"); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 418 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 419 | |
| 420 | if (ctxt != NULL) { |
| 421 | xmlParserPrintFileContextInternal(input, channel, data); |
| 422 | if (cur != NULL) { |
| 423 | if (cur->filename) |
| 424 | channel(data, "%s:%d: \n", cur->filename, cur->line); |
Daniel Veillard | d96f6d3 | 2003-10-07 21:25:12 +0000 | [diff] [blame] | 425 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 426 | channel(data, "Entity: line %d: \n", cur->line); |
| 427 | xmlParserPrintFileContextInternal(cur, channel, data); |
| 428 | } |
| 429 | } |
Daniel Veillard | d96f6d3 | 2003-10-07 21:25:12 +0000 | [diff] [blame] | 430 | if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) && |
| 431 | (err->int1 < 100) && |
| 432 | (err->int1 < xmlStrlen((const xmlChar *)err->str1))) { |
| 433 | xmlChar buf[150]; |
| 434 | int i; |
| 435 | |
| 436 | channel(data, "%s\n", err->str1); |
| 437 | for (i=0;i < err->int1;i++) |
| 438 | buf[i] = ' '; |
| 439 | buf[i++] = '^'; |
| 440 | buf[i] = 0; |
| 441 | channel(data, "%s\n", buf); |
| 442 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /** |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 446 | * __xmlRaiseError: |
William M. Brack | d233e39 | 2004-05-16 03:12:08 +0000 | [diff] [blame] | 447 | * @schannel: the structured callback channel |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 448 | * @channel: the old callback channel |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 449 | * @data: the callback data |
| 450 | * @ctx: the parser context or NULL |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 451 | * @ctx: the parser context or NULL |
| 452 | * @domain: the domain for the error |
| 453 | * @code: the code for the error |
| 454 | * @level: the xmlErrorLevel for the error |
| 455 | * @file: the file source of the error (or NULL) |
| 456 | * @line: the line of the error or 0 if N/A |
| 457 | * @str1: extra string info |
| 458 | * @str2: extra string info |
| 459 | * @str3: extra string info |
| 460 | * @int1: extra int info |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 461 | * @col: column number of the error or 0 if N/A |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 462 | * @msg: the message to display/transmit |
| 463 | * @...: extra parameters for the message display |
| 464 | * |
William M. Brack | d233e39 | 2004-05-16 03:12:08 +0000 | [diff] [blame] | 465 | * Update the appropriate global or contextual error structure, |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 466 | * then forward the error message down the parser or generic |
| 467 | * error callback handler |
| 468 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 469 | void |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 470 | __xmlRaiseError(xmlStructuredErrorFunc schannel, |
| 471 | xmlGenericErrorFunc channel, void *data, void *ctx, |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 472 | void *nod, int domain, int code, xmlErrorLevel level, |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 473 | const char *file, int line, const char *str1, |
Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 474 | const char *str2, const char *str3, int int1, int col, |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 475 | const char *msg, ...) |
| 476 | { |
Daniel Veillard | cd6ff28 | 2003-10-08 22:38:13 +0000 | [diff] [blame] | 477 | xmlParserCtxtPtr ctxt = NULL; |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 478 | xmlNodePtr node = (xmlNodePtr) nod; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 479 | char *str = NULL; |
| 480 | xmlParserInputPtr input = NULL; |
| 481 | xmlErrorPtr to = &xmlLastError; |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 482 | xmlNodePtr baseptr = NULL; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 483 | |
Dmitry V. Levin | 111d705 | 2011-02-23 22:14:19 +0800 | [diff] [blame] | 484 | if (code == XML_ERR_OK) |
| 485 | return; |
Daniel Veillard | b5fa020 | 2003-12-08 17:41:29 +0000 | [diff] [blame] | 486 | if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING)) |
| 487 | return; |
Daniel Veillard | cd6ff28 | 2003-10-08 22:38:13 +0000 | [diff] [blame] | 488 | if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
| 489 | (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
Daniel Veillard | 370ba3d | 2004-10-25 16:23:56 +0000 | [diff] [blame] | 490 | (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
Daniel Veillard | cd6ff28 | 2003-10-08 22:38:13 +0000 | [diff] [blame] | 491 | ctxt = (xmlParserCtxtPtr) ctx; |
Nick Wellnhofer | 59b3366 | 2022-12-27 14:15:51 +0100 | [diff] [blame] | 492 | |
| 493 | if (ctxt != NULL) { |
| 494 | if (level == XML_ERR_WARNING) { |
| 495 | if (ctxt->nbWarnings >= XML_MAX_ERRORS) |
| 496 | return; |
| 497 | ctxt->nbWarnings += 1; |
| 498 | } else { |
| 499 | if (ctxt->nbErrors >= XML_MAX_ERRORS) |
| 500 | return; |
| 501 | ctxt->nbErrors += 1; |
| 502 | } |
| 503 | |
| 504 | if ((schannel == NULL) && (ctxt->sax != NULL) && |
| 505 | (ctxt->sax->initialized == XML_SAX2_MAGIC) && |
| 506 | (ctxt->sax->serror != NULL)) { |
| 507 | schannel = ctxt->sax->serror; |
| 508 | data = ctxt->userData; |
| 509 | } |
| 510 | } |
Daniel Veillard | cd6ff28 | 2003-10-08 22:38:13 +0000 | [diff] [blame] | 511 | } |
William M. Brack | cd3628b | 2004-07-25 21:07:29 +0000 | [diff] [blame] | 512 | /* |
| 513 | * Check if structured error handler set |
| 514 | */ |
| 515 | if (schannel == NULL) { |
Daniel Veillard | f88d8cf | 2003-12-08 10:25:02 +0000 | [diff] [blame] | 516 | schannel = xmlStructuredError; |
William M. Brack | cd3628b | 2004-07-25 21:07:29 +0000 | [diff] [blame] | 517 | /* |
| 518 | * if user has defined handler, change data ptr to user's choice |
| 519 | */ |
| 520 | if (schannel != NULL) |
Wang Lam | 1de382e | 2009-08-24 17:34:25 +0200 | [diff] [blame] | 521 | data = xmlStructuredErrorContext; |
William M. Brack | cd3628b | 2004-07-25 21:07:29 +0000 | [diff] [blame] | 522 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 523 | /* |
| 524 | * Formatting the message |
| 525 | */ |
| 526 | if (msg == NULL) { |
| 527 | str = (char *) xmlStrdup(BAD_CAST "No error message provided"); |
| 528 | } else { |
| 529 | XML_GET_VAR_STR(msg, str); |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | * specific processing if a parser context is provided |
| 534 | */ |
| 535 | if (ctxt != NULL) { |
| 536 | if (file == NULL) { |
| 537 | input = ctxt->input; |
| 538 | if ((input != NULL) && (input->filename == NULL) && |
| 539 | (ctxt->inputNr > 1)) { |
| 540 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 541 | } |
| 542 | if (input != NULL) { |
| 543 | file = input->filename; |
| 544 | line = input->line; |
Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 545 | col = input->col; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | to = &ctxt->lastError; |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 549 | } else if ((node != NULL) && (file == NULL)) { |
| 550 | int i; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 551 | |
Daniel Veillard | dbee0f1 | 2005-06-27 13:42:57 +0000 | [diff] [blame] | 552 | if ((node->doc != NULL) && (node->doc->URL != NULL)) { |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 553 | baseptr = node; |
Daniel Veillard | 8ce01ce | 2005-08-25 20:14:38 +0000 | [diff] [blame] | 554 | /* file = (const char *) node->doc->URL; */ |
Daniel Veillard | dbee0f1 | 2005-06-27 13:42:57 +0000 | [diff] [blame] | 555 | } |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 556 | for (i = 0; |
| 557 | ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE)); |
| 558 | i++) |
| 559 | node = node->parent; |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 560 | if ((baseptr == NULL) && (node != NULL) && |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 561 | (node->doc != NULL) && (node->doc->URL != NULL)) |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 562 | baseptr = node; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 563 | |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 564 | if ((node != NULL) && (node->type == XML_ELEMENT_NODE)) |
Daniel Veillard | 3e35f8e | 2003-10-21 00:05:38 +0000 | [diff] [blame] | 565 | line = node->line; |
Daniel Veillard | 968a03a | 2012-08-13 12:41:33 +0800 | [diff] [blame] | 566 | if ((line == 0) || (line == 65535)) |
| 567 | line = xmlGetLineNo(node); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* |
William M. Brack | d233e39 | 2004-05-16 03:12:08 +0000 | [diff] [blame] | 571 | * Save the information about the error |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 572 | */ |
| 573 | xmlResetError(to); |
| 574 | to->domain = domain; |
| 575 | to->code = code; |
| 576 | to->message = str; |
| 577 | to->level = level; |
| 578 | if (file != NULL) |
| 579 | to->file = (char *) xmlStrdup((const xmlChar *) file); |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 580 | else if (baseptr != NULL) { |
| 581 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 582 | /* |
| 583 | * We check if the error is within an XInclude section and, |
| 584 | * if so, attempt to print out the href of the XInclude instead |
| 585 | * of the usual "base" (doc->URL) for the node (bug 152623). |
| 586 | */ |
| 587 | xmlNodePtr prev = baseptr; |
Nick Wellnhofer | 2c74712 | 2020-08-17 00:54:12 +0200 | [diff] [blame] | 588 | char *href = NULL; |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 589 | int inclcount = 0; |
| 590 | while (prev != NULL) { |
| 591 | if (prev->prev == NULL) |
| 592 | prev = prev->parent; |
| 593 | else { |
| 594 | prev = prev->prev; |
| 595 | if (prev->type == XML_XINCLUDE_START) { |
Nick Wellnhofer | 2c74712 | 2020-08-17 00:54:12 +0200 | [diff] [blame] | 596 | if (inclcount > 0) { |
| 597 | --inclcount; |
| 598 | } else { |
| 599 | href = (char *) xmlGetProp(prev, BAD_CAST "href"); |
| 600 | if (href != NULL) |
| 601 | break; |
| 602 | } |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 603 | } else if (prev->type == XML_XINCLUDE_END) |
| 604 | inclcount++; |
| 605 | } |
| 606 | } |
Nick Wellnhofer | 2c74712 | 2020-08-17 00:54:12 +0200 | [diff] [blame] | 607 | if (href != NULL) |
| 608 | to->file = href; |
| 609 | else |
William M. Brack | d040752 | 2004-10-02 03:54:00 +0000 | [diff] [blame] | 610 | #endif |
| 611 | to->file = (char *) xmlStrdup(baseptr->doc->URL); |
Daniel Veillard | 8ce01ce | 2005-08-25 20:14:38 +0000 | [diff] [blame] | 612 | if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) { |
| 613 | to->file = (char *) xmlStrdup(node->doc->URL); |
| 614 | } |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 615 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 616 | to->line = line; |
| 617 | if (str1 != NULL) |
| 618 | to->str1 = (char *) xmlStrdup((const xmlChar *) str1); |
| 619 | if (str2 != NULL) |
| 620 | to->str2 = (char *) xmlStrdup((const xmlChar *) str2); |
| 621 | if (str3 != NULL) |
| 622 | to->str3 = (char *) xmlStrdup((const xmlChar *) str3); |
| 623 | to->int1 = int1; |
Aleksey Sanin | 8fdc32a | 2005-01-05 15:37:55 +0000 | [diff] [blame] | 624 | to->int2 = col; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 625 | to->node = node; |
Daniel Veillard | cd6ff28 | 2003-10-08 22:38:13 +0000 | [diff] [blame] | 626 | to->ctxt = ctx; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 627 | |
Daniel Veillard | d34b0b8 | 2004-01-02 20:26:01 +0000 | [diff] [blame] | 628 | if (to != &xmlLastError) |
| 629 | xmlCopyError(to,&xmlLastError); |
| 630 | |
Dmitry V. Levin | c2a0fdc | 2011-02-23 22:44:05 +0800 | [diff] [blame] | 631 | if (schannel != NULL) { |
| 632 | schannel(data, to); |
| 633 | return; |
| 634 | } |
| 635 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 636 | /* |
William M. Brack | cd3628b | 2004-07-25 21:07:29 +0000 | [diff] [blame] | 637 | * Find the callback channel if channel param is NULL |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 638 | */ |
Wang Lam | 1de382e | 2009-08-24 17:34:25 +0200 | [diff] [blame] | 639 | if ((ctxt != NULL) && (channel == NULL) && |
| 640 | (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 641 | if (level == XML_ERR_WARNING) |
| 642 | channel = ctxt->sax->warning; |
| 643 | else |
| 644 | channel = ctxt->sax->error; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 645 | data = ctxt->userData; |
Daniel Veillard | bb5abab | 2003-10-03 22:21:51 +0000 | [diff] [blame] | 646 | } else if (channel == NULL) { |
Dmitry V. Levin | c2a0fdc | 2011-02-23 22:44:05 +0800 | [diff] [blame] | 647 | channel = xmlGenericError; |
Pietro Cerutti | 890faa5 | 2012-08-27 13:24:08 +0800 | [diff] [blame] | 648 | if (ctxt != NULL) { |
| 649 | data = ctxt; |
| 650 | } else { |
Dmitry V. Levin | c2a0fdc | 2011-02-23 22:44:05 +0800 | [diff] [blame] | 651 | data = xmlGenericErrorContext; |
Pietro Cerutti | 890faa5 | 2012-08-27 13:24:08 +0800 | [diff] [blame] | 652 | } |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 653 | } |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 654 | if (channel == NULL) |
| 655 | return; |
| 656 | |
| 657 | if ((channel == xmlParserError) || |
| 658 | (channel == xmlParserWarning) || |
| 659 | (channel == xmlParserValidityError) || |
| 660 | (channel == xmlParserValidityWarning)) |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 661 | xmlReportError(to, ctxt, str, NULL, NULL); |
Nick Wellnhofer | 19f0950 | 2019-01-01 16:38:42 +0100 | [diff] [blame] | 662 | else if (((void(*)(void)) channel == (void(*)(void)) fprintf) || |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 663 | (channel == xmlGenericErrorDefaultFunc)) |
| 664 | xmlReportError(to, ctxt, str, channel, data); |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 665 | else |
| 666 | channel(data, "%s", str); |
| 667 | } |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 668 | |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 669 | /** |
Daniel Veillard | 18ec16e | 2003-10-07 23:16:40 +0000 | [diff] [blame] | 670 | * __xmlSimpleError: |
| 671 | * @domain: where the error comes from |
| 672 | * @code: the error code |
| 673 | * @node: the context node |
Nick Wellnhofer | 20c6088 | 2020-03-08 17:19:42 +0100 | [diff] [blame] | 674 | * @extra: extra information |
Daniel Veillard | 18ec16e | 2003-10-07 23:16:40 +0000 | [diff] [blame] | 675 | * |
| 676 | * Handle an out of memory condition |
| 677 | */ |
| 678 | void |
| 679 | __xmlSimpleError(int domain, int code, xmlNodePtr node, |
| 680 | const char *msg, const char *extra) |
| 681 | { |
| 682 | |
| 683 | if (code == XML_ERR_NO_MEMORY) { |
| 684 | if (extra) |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 685 | __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain, |
Daniel Veillard | 18ec16e | 2003-10-07 23:16:40 +0000 | [diff] [blame] | 686 | XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra, |
| 687 | NULL, NULL, 0, 0, |
| 688 | "Memory allocation failed : %s\n", extra); |
| 689 | else |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 690 | __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain, |
Daniel Veillard | 18ec16e | 2003-10-07 23:16:40 +0000 | [diff] [blame] | 691 | XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL, |
| 692 | NULL, NULL, 0, 0, "Memory allocation failed\n"); |
| 693 | } else { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 694 | __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain, |
Daniel Veillard | 18ec16e | 2003-10-07 23:16:40 +0000 | [diff] [blame] | 695 | code, XML_ERR_ERROR, NULL, 0, extra, |
| 696 | NULL, NULL, 0, 0, msg, extra); |
| 697 | } |
| 698 | } |
| 699 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 700 | * xmlParserError: |
| 701 | * @ctx: an XML parser context |
| 702 | * @msg: the message to display/transmit |
| 703 | * @...: extra parameters for the message display |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 704 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 705 | * Display and format an error messages, gives file, line, position and |
| 706 | * extra parameters. |
| 707 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 708 | void |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 709 | xmlParserError(void *ctx, const char *msg, ...) |
| 710 | { |
| 711 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 712 | xmlParserInputPtr input = NULL; |
| 713 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 714 | char * str; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 715 | |
| 716 | if (ctxt != NULL) { |
| 717 | input = ctxt->input; |
| 718 | if ((input != NULL) && (input->filename == NULL) && |
| 719 | (ctxt->inputNr > 1)) { |
| 720 | cur = input; |
| 721 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 722 | } |
| 723 | xmlParserPrintFileInfo(input); |
| 724 | } |
| 725 | |
| 726 | xmlGenericError(xmlGenericErrorContext, "error: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 727 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 728 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 729 | if (str != NULL) |
| 730 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 731 | |
| 732 | if (ctxt != NULL) { |
| 733 | xmlParserPrintFileContext(input); |
| 734 | if (cur != NULL) { |
| 735 | xmlParserPrintFileInfo(cur); |
| 736 | xmlGenericError(xmlGenericErrorContext, "\n"); |
| 737 | xmlParserPrintFileContext(cur); |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * xmlParserWarning: |
| 744 | * @ctx: an XML parser context |
| 745 | * @msg: the message to display/transmit |
| 746 | * @...: extra parameters for the message display |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 747 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 748 | * Display and format a warning messages, gives file, line, position and |
| 749 | * extra parameters. |
| 750 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 751 | void |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 752 | xmlParserWarning(void *ctx, const char *msg, ...) |
| 753 | { |
| 754 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 755 | xmlParserInputPtr input = NULL; |
| 756 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 757 | char * str; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 758 | |
| 759 | if (ctxt != NULL) { |
| 760 | input = ctxt->input; |
| 761 | if ((input != NULL) && (input->filename == NULL) && |
| 762 | (ctxt->inputNr > 1)) { |
| 763 | cur = input; |
| 764 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 765 | } |
| 766 | xmlParserPrintFileInfo(input); |
| 767 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 768 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 769 | xmlGenericError(xmlGenericErrorContext, "warning: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 770 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 771 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 772 | if (str != NULL) |
| 773 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 774 | |
| 775 | if (ctxt != NULL) { |
| 776 | xmlParserPrintFileContext(input); |
| 777 | if (cur != NULL) { |
| 778 | xmlParserPrintFileInfo(cur); |
| 779 | xmlGenericError(xmlGenericErrorContext, "\n"); |
| 780 | xmlParserPrintFileContext(cur); |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /************************************************************************ |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 786 | * * |
| 787 | * Handling of validation errors * |
| 788 | * * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 789 | ************************************************************************/ |
| 790 | |
| 791 | /** |
| 792 | * xmlParserValidityError: |
| 793 | * @ctx: an XML parser context |
| 794 | * @msg: the message to display/transmit |
| 795 | * @...: extra parameters for the message display |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 796 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 797 | * Display and format an validity error messages, gives file, |
| 798 | * line, position and extra parameters. |
| 799 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 800 | void |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 801 | xmlParserValidityError(void *ctx, const char *msg, ...) |
| 802 | { |
| 803 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 804 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 805 | char * str; |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 806 | int len = xmlStrlen((const xmlChar *) msg); |
| 807 | static int had_info = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 808 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 809 | if ((len > 1) && (msg[len - 2] != ':')) { |
| 810 | if (ctxt != NULL) { |
| 811 | input = ctxt->input; |
| 812 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 813 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 814 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 815 | if (had_info == 0) { |
| 816 | xmlParserPrintFileInfo(input); |
| 817 | } |
| 818 | } |
| 819 | xmlGenericError(xmlGenericErrorContext, "validity error: "); |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 820 | had_info = 0; |
| 821 | } else { |
| 822 | had_info = 1; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 825 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 826 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 827 | if (str != NULL) |
| 828 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 829 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 830 | if ((ctxt != NULL) && (input != NULL)) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 831 | xmlParserPrintFileContext(input); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * xmlParserValidityWarning: |
| 837 | * @ctx: an XML parser context |
| 838 | * @msg: the message to display/transmit |
| 839 | * @...: extra parameters for the message display |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 840 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 841 | * Display and format a validity warning messages, gives file, line, |
| 842 | * position and extra parameters. |
| 843 | */ |
Nick Wellnhofer | dd3569e | 2022-12-08 02:43:17 +0100 | [diff] [blame] | 844 | void |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 845 | xmlParserValidityWarning(void *ctx, const char *msg, ...) |
| 846 | { |
| 847 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 848 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 849 | char * str; |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 850 | int len = xmlStrlen((const xmlChar *) msg); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 851 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 852 | if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 853 | input = ctxt->input; |
| 854 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 855 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 856 | |
| 857 | xmlParserPrintFileInfo(input); |
| 858 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 859 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 860 | xmlGenericError(xmlGenericErrorContext, "validity warning: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 861 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 862 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 863 | if (str != NULL) |
| 864 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 865 | |
| 866 | if (ctxt != NULL) { |
| 867 | xmlParserPrintFileContext(input); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 872 | /************************************************************************ |
| 873 | * * |
| 874 | * Extended Error Handling * |
| 875 | * * |
| 876 | ************************************************************************/ |
| 877 | |
| 878 | /** |
| 879 | * xmlGetLastError: |
| 880 | * |
| 881 | * Get the last global error registered. This is per thread if compiled |
| 882 | * with thread support. |
| 883 | * |
Nick Wellnhofer | 8bbe450 | 2017-06-17 16:15:09 +0200 | [diff] [blame] | 884 | * Returns NULL if no error occurred or a pointer to the error |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 885 | */ |
| 886 | xmlErrorPtr |
| 887 | xmlGetLastError(void) |
| 888 | { |
| 889 | if (xmlLastError.code == XML_ERR_OK) |
| 890 | return (NULL); |
| 891 | return (&xmlLastError); |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * xmlResetError: |
| 896 | * @err: pointer to the error. |
| 897 | * |
| 898 | * Cleanup the error. |
| 899 | */ |
| 900 | void |
| 901 | xmlResetError(xmlErrorPtr err) |
| 902 | { |
| 903 | if (err == NULL) |
| 904 | return; |
| 905 | if (err->code == XML_ERR_OK) |
| 906 | return; |
| 907 | if (err->message != NULL) |
| 908 | xmlFree(err->message); |
| 909 | if (err->file != NULL) |
| 910 | xmlFree(err->file); |
| 911 | if (err->str1 != NULL) |
| 912 | xmlFree(err->str1); |
| 913 | if (err->str2 != NULL) |
| 914 | xmlFree(err->str2); |
| 915 | if (err->str3 != NULL) |
| 916 | xmlFree(err->str3); |
| 917 | memset(err, 0, sizeof(xmlError)); |
| 918 | err->code = XML_ERR_OK; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * xmlResetLastError: |
| 923 | * |
| 924 | * Cleanup the last global error registered. For parsing error |
| 925 | * this does not change the well-formedness result. |
| 926 | */ |
| 927 | void |
| 928 | xmlResetLastError(void) |
| 929 | { |
| 930 | if (xmlLastError.code == XML_ERR_OK) |
| 931 | return; |
| 932 | xmlResetError(&xmlLastError); |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * xmlCtxtGetLastError: |
| 937 | * @ctx: an XML parser context |
| 938 | * |
| 939 | * Get the last parsing error registered. |
| 940 | * |
Nick Wellnhofer | 8bbe450 | 2017-06-17 16:15:09 +0200 | [diff] [blame] | 941 | * Returns NULL if no error occurred or a pointer to the error |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 942 | */ |
| 943 | xmlErrorPtr |
| 944 | xmlCtxtGetLastError(void *ctx) |
| 945 | { |
| 946 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 947 | |
| 948 | if (ctxt == NULL) |
| 949 | return (NULL); |
| 950 | if (ctxt->lastError.code == XML_ERR_OK) |
| 951 | return (NULL); |
| 952 | return (&ctxt->lastError); |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * xmlCtxtResetLastError: |
| 957 | * @ctx: an XML parser context |
| 958 | * |
| 959 | * Cleanup the last global error registered. For parsing error |
| 960 | * this does not change the well-formedness result. |
| 961 | */ |
| 962 | void |
| 963 | xmlCtxtResetLastError(void *ctx) |
| 964 | { |
| 965 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 966 | |
| 967 | if (ctxt == NULL) |
| 968 | return; |
Daniel Veillard | 26b0687 | 2010-03-15 15:59:07 +0100 | [diff] [blame] | 969 | ctxt->errNo = XML_ERR_OK; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 970 | if (ctxt->lastError.code == XML_ERR_OK) |
| 971 | return; |
| 972 | xmlResetError(&ctxt->lastError); |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * xmlCopyError: |
| 977 | * @from: a source error |
| 978 | * @to: a target error |
| 979 | * |
| 980 | * Save the original error to the new place. |
| 981 | * |
| 982 | * Returns 0 in case of success and -1 in case of error. |
| 983 | */ |
| 984 | int |
| 985 | xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) { |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 986 | char *message, *file, *str1, *str2, *str3; |
| 987 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 988 | if ((from == NULL) || (to == NULL)) |
| 989 | return(-1); |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 990 | |
| 991 | message = (char *) xmlStrdup((xmlChar *) from->message); |
| 992 | file = (char *) xmlStrdup ((xmlChar *) from->file); |
| 993 | str1 = (char *) xmlStrdup ((xmlChar *) from->str1); |
| 994 | str2 = (char *) xmlStrdup ((xmlChar *) from->str2); |
| 995 | str3 = (char *) xmlStrdup ((xmlChar *) from->str3); |
| 996 | |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 997 | if (to->message != NULL) |
| 998 | xmlFree(to->message); |
| 999 | if (to->file != NULL) |
| 1000 | xmlFree(to->file); |
| 1001 | if (to->str1 != NULL) |
| 1002 | xmlFree(to->str1); |
| 1003 | if (to->str2 != NULL) |
| 1004 | xmlFree(to->str2); |
| 1005 | if (to->str3 != NULL) |
| 1006 | xmlFree(to->str3); |
| 1007 | to->domain = from->domain; |
| 1008 | to->code = from->code; |
| 1009 | to->level = from->level; |
| 1010 | to->line = from->line; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 1011 | to->node = from->node; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 1012 | to->int1 = from->int1; |
| 1013 | to->int2 = from->int2; |
Daniel Veillard | 4c00414 | 2003-10-07 11:33:24 +0000 | [diff] [blame] | 1014 | to->node = from->node; |
| 1015 | to->ctxt = from->ctxt; |
William M. Brack | a3215c7 | 2004-07-31 16:24:01 +0000 | [diff] [blame] | 1016 | to->message = message; |
| 1017 | to->file = file; |
| 1018 | to->str1 = str1; |
| 1019 | to->str2 = str2; |
| 1020 | to->str3 = str3; |
| 1021 | |
| 1022 | return 0; |
Daniel Veillard | 2b8c4a1 | 2003-10-02 22:28:19 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |