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