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 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12 | #include <stdarg.h> |
| 13 | #include <libxml/parser.h> |
| 14 | #include <libxml/xmlerror.h> |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 15 | #include <libxml/xmlmemory.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 16 | #include <libxml/globals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 17 | |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 18 | void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, |
| 19 | const char *msg, |
| 20 | ...); |
| 21 | |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 22 | #define XML_GET_VAR_STR(msg, str) { \ |
| 23 | int size; \ |
| 24 | int chars; \ |
| 25 | char *larger; \ |
| 26 | va_list ap; \ |
| 27 | \ |
| 28 | str = (char *) xmlMalloc(150); \ |
| 29 | if (str == NULL) \ |
| 30 | return; \ |
| 31 | \ |
| 32 | size = 150; \ |
| 33 | \ |
| 34 | while (1) { \ |
| 35 | va_start(ap, msg); \ |
| 36 | chars = vsnprintf(str, size, msg, ap); \ |
| 37 | va_end(ap); \ |
| 38 | if ((chars > -1) && (chars < size)) \ |
| 39 | break; \ |
| 40 | if (chars > -1) \ |
| 41 | size += chars + 1; \ |
| 42 | else \ |
| 43 | size += 100; \ |
| 44 | if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\ |
| 45 | xmlFree(str); \ |
| 46 | return; \ |
| 47 | } \ |
| 48 | str = larger; \ |
| 49 | } \ |
| 50 | } |
Bjorn Reese | 570ff08 | 2001-06-05 12:45:55 +0000 | [diff] [blame] | 51 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 52 | /************************************************************************ |
| 53 | * * |
| 54 | * Handling of out of context errors * |
| 55 | * * |
| 56 | ************************************************************************/ |
| 57 | |
| 58 | /** |
| 59 | * xmlGenericErrorDefaultFunc: |
| 60 | * @ctx: an error context |
| 61 | * @msg: the message to display/transmit |
| 62 | * @...: extra parameters for the message display |
| 63 | * |
| 64 | * Default handler for out of context error messages. |
| 65 | */ |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 66 | void |
Daniel Veillard | c86a4fa | 2001-03-26 16:28:29 +0000 | [diff] [blame] | 67 | xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 68 | va_list args; |
| 69 | |
| 70 | if (xmlGenericErrorContext == NULL) |
| 71 | xmlGenericErrorContext = (void *) stderr; |
| 72 | |
| 73 | va_start(args, msg); |
| 74 | vfprintf((FILE *)xmlGenericErrorContext, msg, args); |
| 75 | va_end(args); |
| 76 | } |
| 77 | |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 78 | /** |
| 79 | * initGenericErrorDefaultFunc: |
| 80 | * @handler: the handler |
| 81 | * |
| 82 | * Set or reset (if NULL) the default handler for generic errors |
Daniel Veillard | 7424eb6 | 2003-01-24 14:14:52 +0000 | [diff] [blame] | 83 | * to the builtin error function. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 84 | */ |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 85 | void |
Daniel Veillard | db5850a | 2002-01-18 11:49:26 +0000 | [diff] [blame] | 86 | initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler) |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 87 | { |
Daniel Veillard | db5850a | 2002-01-18 11:49:26 +0000 | [diff] [blame] | 88 | if (handler == NULL) |
| 89 | xmlGenericError = xmlGenericErrorDefaultFunc; |
| 90 | else |
| 91 | (*handler) = xmlGenericErrorDefaultFunc; |
Daniel Veillard | d046356 | 2001-10-13 09:15:48 +0000 | [diff] [blame] | 92 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * xmlSetGenericErrorFunc: |
| 96 | * @ctx: the new error handling context |
| 97 | * @handler: the new handler function |
| 98 | * |
| 99 | * Function to reset the handler and the error context for out of |
| 100 | * context error messages. |
| 101 | * This simply means that @handler will be called for subsequent |
| 102 | * error messages while not parsing nor validating. And @ctx will |
| 103 | * be passed as first argument to @handler |
| 104 | * One can simply force messages to be emitted to another FILE * than |
| 105 | * stderr by setting @ctx to this file handle and @handler to NULL. |
| 106 | */ |
| 107 | void |
| 108 | xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { |
| 109 | xmlGenericErrorContext = ctx; |
| 110 | if (handler != NULL) |
| 111 | xmlGenericError = handler; |
| 112 | else |
| 113 | xmlGenericError = xmlGenericErrorDefaultFunc; |
| 114 | } |
| 115 | |
| 116 | /************************************************************************ |
| 117 | * * |
| 118 | * Handling of parsing errors * |
| 119 | * * |
| 120 | ************************************************************************/ |
| 121 | |
| 122 | /** |
| 123 | * xmlParserPrintFileInfo: |
| 124 | * @input: an xmlParserInputPtr input |
| 125 | * |
| 126 | * Displays the associated file and line informations for the current input |
| 127 | */ |
| 128 | |
| 129 | void |
| 130 | xmlParserPrintFileInfo(xmlParserInputPtr input) { |
| 131 | if (input != NULL) { |
| 132 | if (input->filename) |
| 133 | xmlGenericError(xmlGenericErrorContext, |
| 134 | "%s:%d: ", input->filename, |
| 135 | input->line); |
| 136 | else |
| 137 | xmlGenericError(xmlGenericErrorContext, |
| 138 | "Entity: line %d: ", input->line); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * xmlParserPrintFileContext: |
| 144 | * @input: an xmlParserInputPtr input |
| 145 | * |
| 146 | * Displays current context within the input content for error tracking |
| 147 | */ |
| 148 | |
| 149 | void |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 150 | xmlParserPrintFileContext(xmlParserInputPtr input) { |
| 151 | const xmlChar *cur, *base; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 152 | int n; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 153 | xmlChar content[81]; |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 154 | xmlChar *ctnt; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 155 | |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 156 | if (input == NULL) return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 157 | cur = input->cur; |
| 158 | base = input->base; |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 159 | /* skip backwards over any end-of-lines */ |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 160 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 161 | cur--; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 162 | } |
| 163 | n = 0; |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 164 | /* search backwards for beginning-of-line maximum 80 characters */ |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 165 | while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 166 | cur--; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 167 | if ((*cur == '\n') || (*cur == '\r')) cur++; |
| 168 | /* search forward for end-of-line maximum 80 characters */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 169 | n = 0; |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 170 | ctnt = content; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 171 | while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { |
| 172 | *ctnt++ = *cur++; |
| 173 | n++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 174 | } |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 175 | *ctnt = 0; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 176 | xmlGenericError(xmlGenericErrorContext,"%s\n", content); |
Daniel Veillard | 2be3064 | 2001-03-27 00:32:28 +0000 | [diff] [blame] | 177 | /* create blank line with problem pointer */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 178 | cur = input->cur; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 179 | while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { |
| 180 | cur--; |
| 181 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 182 | n = 0; |
Daniel Veillard | 7533cc8 | 2001-04-24 15:52:00 +0000 | [diff] [blame] | 183 | ctnt = content; |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 184 | while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r')) { |
| 185 | *ctnt++ = ' '; |
| 186 | cur--; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 187 | } |
Daniel Veillard | 5a7c345 | 2001-04-26 09:16:13 +0000 | [diff] [blame] | 188 | if (ctnt > content) { |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 189 | *(--ctnt) = '^'; |
| 190 | *(++ctnt) = 0; |
Daniel Veillard | 5a7c345 | 2001-04-26 09:16:13 +0000 | [diff] [blame] | 191 | } else { |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 192 | *ctnt = '^'; |
| 193 | *(++ctnt) = 0; |
Daniel Veillard | 5a7c345 | 2001-04-26 09:16:13 +0000 | [diff] [blame] | 194 | } |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 195 | xmlGenericError(xmlGenericErrorContext,"%s\n", content); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Daniel Veillard | 561b7f8 | 2002-03-20 21:55:57 +0000 | [diff] [blame] | 198 | #if 0 |
| 199 | /** |
| 200 | * xmlGetVarStr: |
| 201 | * @msg: the message format |
| 202 | * @args: a va_list argument list |
| 203 | * |
| 204 | * SGS contribution |
| 205 | * Get an arbitrary-sized string for an error argument |
| 206 | * The caller must free() the returned string |
| 207 | */ |
| 208 | static char * |
| 209 | xmlGetVarStr(const char * msg, va_list args) { |
| 210 | int size; |
| 211 | int length; |
| 212 | int chars, left; |
| 213 | char *str, *larger; |
| 214 | va_list ap; |
| 215 | |
| 216 | str = (char *) xmlMalloc(150); |
| 217 | if (str == NULL) |
| 218 | return(NULL); |
| 219 | |
| 220 | size = 150; |
| 221 | length = 0; |
| 222 | |
| 223 | while (1) { |
| 224 | left = size - length; |
| 225 | /* Try to print in the allocated space. */ |
| 226 | va_start(msg, ap); |
| 227 | chars = vsnprintf(str + length, left, msg, ap); |
| 228 | va_end(ap); |
| 229 | /* If that worked, we're done. */ |
| 230 | if ((chars > -1) && (chars < left )) |
| 231 | break; |
| 232 | /* Else try again with more space. */ |
| 233 | if (chars > -1) /* glibc 2.1 */ |
| 234 | size += chars + 1; /* precisely what is needed */ |
| 235 | else /* glibc 2.0 */ |
| 236 | size += 100; |
| 237 | if ((larger = (char *) xmlRealloc(str, size)) == NULL) { |
| 238 | xmlFree(str); |
| 239 | return(NULL); |
| 240 | } |
| 241 | str = larger; |
| 242 | } |
| 243 | return(str); |
| 244 | } |
| 245 | #endif |
| 246 | |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 247 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 248 | * xmlParserError: |
| 249 | * @ctx: an XML parser context |
| 250 | * @msg: the message to display/transmit |
| 251 | * @...: extra parameters for the message display |
| 252 | * |
| 253 | * Display and format an error messages, gives file, line, position and |
| 254 | * extra parameters. |
| 255 | */ |
| 256 | void |
| 257 | xmlParserError(void *ctx, const char *msg, ...) |
| 258 | { |
| 259 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 260 | xmlParserInputPtr input = NULL; |
| 261 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 262 | char * str; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 263 | |
| 264 | if (ctxt != NULL) { |
| 265 | input = ctxt->input; |
| 266 | if ((input != NULL) && (input->filename == NULL) && |
| 267 | (ctxt->inputNr > 1)) { |
| 268 | cur = input; |
| 269 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 270 | } |
| 271 | xmlParserPrintFileInfo(input); |
| 272 | } |
| 273 | |
| 274 | xmlGenericError(xmlGenericErrorContext, "error: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 275 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 276 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 277 | if (str != NULL) |
| 278 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 279 | |
| 280 | if (ctxt != NULL) { |
| 281 | xmlParserPrintFileContext(input); |
| 282 | if (cur != NULL) { |
| 283 | xmlParserPrintFileInfo(cur); |
| 284 | xmlGenericError(xmlGenericErrorContext, "\n"); |
| 285 | xmlParserPrintFileContext(cur); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * xmlParserWarning: |
| 292 | * @ctx: an XML parser context |
| 293 | * @msg: the message to display/transmit |
| 294 | * @...: extra parameters for the message display |
| 295 | * |
| 296 | * Display and format a warning messages, gives file, line, position and |
| 297 | * extra parameters. |
| 298 | */ |
| 299 | void |
| 300 | xmlParserWarning(void *ctx, const char *msg, ...) |
| 301 | { |
| 302 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 303 | xmlParserInputPtr input = NULL; |
| 304 | xmlParserInputPtr cur = NULL; |
Daniel Veillard | e356c28 | 2001-03-10 12:32:04 +0000 | [diff] [blame] | 305 | char * str; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 306 | |
| 307 | if (ctxt != NULL) { |
| 308 | input = ctxt->input; |
| 309 | if ((input != NULL) && (input->filename == NULL) && |
| 310 | (ctxt->inputNr > 1)) { |
| 311 | cur = input; |
| 312 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 313 | } |
| 314 | xmlParserPrintFileInfo(input); |
| 315 | } |
| 316 | |
| 317 | xmlGenericError(xmlGenericErrorContext, "warning: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 318 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 319 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 320 | if (str != NULL) |
| 321 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 322 | |
| 323 | if (ctxt != NULL) { |
| 324 | xmlParserPrintFileContext(input); |
| 325 | if (cur != NULL) { |
| 326 | xmlParserPrintFileInfo(cur); |
| 327 | xmlGenericError(xmlGenericErrorContext, "\n"); |
| 328 | xmlParserPrintFileContext(cur); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /************************************************************************ |
| 334 | * * |
| 335 | * Handling of validation errors * |
| 336 | * * |
| 337 | ************************************************************************/ |
| 338 | |
| 339 | /** |
| 340 | * xmlParserValidityError: |
| 341 | * @ctx: an XML parser context |
| 342 | * @msg: the message to display/transmit |
| 343 | * @...: extra parameters for the message display |
| 344 | * |
| 345 | * Display and format an validity error messages, gives file, |
| 346 | * line, position and extra parameters. |
| 347 | */ |
| 348 | void |
| 349 | xmlParserValidityError(void *ctx, const char *msg, ...) |
| 350 | { |
| 351 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 352 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 353 | char * str; |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 354 | int len = xmlStrlen((const xmlChar *) msg); |
| 355 | static int had_info = 0; |
| 356 | int need_context = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 357 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 358 | if ((len > 1) && (msg[len - 2] != ':')) { |
| 359 | if (ctxt != NULL) { |
| 360 | input = ctxt->input; |
| 361 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 362 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 363 | |
| 364 | if (had_info == 0) { |
| 365 | xmlParserPrintFileInfo(input); |
| 366 | } |
| 367 | } |
| 368 | xmlGenericError(xmlGenericErrorContext, "validity error: "); |
| 369 | need_context = 1; |
| 370 | had_info = 0; |
| 371 | } else { |
| 372 | had_info = 1; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 375 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 376 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 377 | if (str != NULL) |
| 378 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 379 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 380 | if ((ctxt != NULL) && (input != NULL)) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 381 | xmlParserPrintFileContext(input); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * xmlParserValidityWarning: |
| 387 | * @ctx: an XML parser context |
| 388 | * @msg: the message to display/transmit |
| 389 | * @...: extra parameters for the message display |
| 390 | * |
| 391 | * Display and format a validity warning messages, gives file, line, |
| 392 | * position and extra parameters. |
| 393 | */ |
| 394 | void |
| 395 | xmlParserValidityWarning(void *ctx, const char *msg, ...) |
| 396 | { |
| 397 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 398 | xmlParserInputPtr input = NULL; |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 399 | char * str; |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 400 | int len = xmlStrlen((const xmlChar *) msg); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 401 | |
Daniel Veillard | 7657576 | 2002-09-05 14:21:15 +0000 | [diff] [blame] | 402 | if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 403 | input = ctxt->input; |
| 404 | if ((input->filename == NULL) && (ctxt->inputNr > 1)) |
| 405 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 406 | |
| 407 | xmlParserPrintFileInfo(input); |
| 408 | } |
| 409 | |
| 410 | xmlGenericError(xmlGenericErrorContext, "validity warning: "); |
Daniel Veillard | 1c43dbf | 2001-06-05 17:12:52 +0000 | [diff] [blame] | 411 | XML_GET_VAR_STR(msg, str); |
Daniel Veillard | 635ef72 | 2001-10-29 11:48:19 +0000 | [diff] [blame] | 412 | xmlGenericError(xmlGenericErrorContext, "%s", str); |
Daniel Veillard | 9e7160d | 2001-03-18 23:17:47 +0000 | [diff] [blame] | 413 | if (str != NULL) |
| 414 | xmlFree(str); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 415 | |
| 416 | if (ctxt != NULL) { |
| 417 | xmlParserPrintFileContext(input); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | |