blob: 722ffbb5bc1356eb19e6d8f6b01b1394f859805b [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * error.c: module displaying/handling XML parser errors
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * Daniel Veillard <daniel@veillard.com>
Owen Taylor3473f882001-02-23 17:55:21 +00007 */
8
Daniel Veillard34ce8be2002-03-18 19:37:11 +00009#define IN_LIBXML
Bjorn Reese70a9da52001-04-21 16:57:29 +000010#include "libxml.h"
Owen Taylor3473f882001-02-23 17:55:21 +000011
Daniel Veillard2b8c4a12003-10-02 22:28:19 +000012#include <string.h>
Owen Taylor3473f882001-02-23 17:55:21 +000013#include <stdarg.h>
14#include <libxml/parser.h>
15#include <libxml/xmlerror.h>
Daniel Veillarde356c282001-03-10 12:32:04 +000016#include <libxml/xmlmemory.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000017#include <libxml/globals.h>
Owen Taylor3473f882001-02-23 17:55:21 +000018
Daniel Veillardffa3c742005-07-21 13:24:09 +000019void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED,
Daniel Veillard635ef722001-10-29 11:48:19 +000020 const char *msg,
21 ...);
22
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000023#define XML_GET_VAR_STR(msg, str) { \
Daniel Veillarddbf7bfe2005-10-28 08:25:51 +000024 int size, prev_size = -1; \
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000025 int chars; \
26 char *larger; \
27 va_list ap; \
28 \
29 str = (char *) xmlMalloc(150); \
Daniel Veillard2b8c4a12003-10-02 22:28:19 +000030 if (str != NULL) { \
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000031 \
32 size = 150; \
33 \
34 while (1) { \
35 va_start(ap, msg); \
36 chars = vsnprintf(str, size, msg, ap); \
37 va_end(ap); \
Daniel Veillarddbf7bfe2005-10-28 08:25:51 +000038 if ((chars > -1) && (chars < size)) { \
39 if (prev_size == chars) { \
40 break; \
41 } else { \
42 prev_size = chars; \
43 } \
44 } \
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000045 if (chars > -1) \
46 size += chars + 1; \
47 else \
48 size += 100; \
49 if ((larger = (char *) xmlRealloc(str, size)) == NULL) {\
Daniel Veillard2b8c4a12003-10-02 22:28:19 +000050 break; \
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000051 } \
52 str = larger; \
Daniel Veillard2b8c4a12003-10-02 22:28:19 +000053 }} \
Daniel Veillard1c43dbf2001-06-05 17:12:52 +000054}
Bjorn Reese570ff082001-06-05 12:45:55 +000055
Owen Taylor3473f882001-02-23 17:55:21 +000056/************************************************************************
57 * *
58 * Handling of out of context errors *
59 * *
60 ************************************************************************/
61
62/**
63 * xmlGenericErrorDefaultFunc:
64 * @ctx: an error context
65 * @msg: the message to display/transmit
66 * @...: extra parameters for the message display
67 *
68 * Default handler for out of context error messages.
69 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000070void XMLCDECL
Daniel Veillardc86a4fa2001-03-26 16:28:29 +000071xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
Owen Taylor3473f882001-02-23 17:55:21 +000072 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 Veillard9d06d302002-01-22 18:15:52 +000082/**
83 * initGenericErrorDefaultFunc:
84 * @handler: the handler
85 *
86 * Set or reset (if NULL) the default handler for generic errors
Daniel Veillard7424eb62003-01-24 14:14:52 +000087 * to the builtin error function.
Daniel Veillard9d06d302002-01-22 18:15:52 +000088 */
Daniel Veillardd0463562001-10-13 09:15:48 +000089void
Daniel Veillarddb5850a2002-01-18 11:49:26 +000090initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
Daniel Veillardd0463562001-10-13 09:15:48 +000091{
Daniel Veillarddb5850a2002-01-18 11:49:26 +000092 if (handler == NULL)
93 xmlGenericError = xmlGenericErrorDefaultFunc;
94 else
Daniel Veillardda0ff5d2004-04-20 09:45:26 +000095 xmlGenericError = (*handler);
Daniel Veillardd0463562001-10-13 09:15:48 +000096}
Owen Taylor3473f882001-02-23 17:55:21 +000097
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 Veillardda3b29a2004-08-14 11:15:13 +0000110 * For multi-threaded applications, this must be set separately for each thread.
Owen Taylor3473f882001-02-23 17:55:21 +0000111 */
112void
113xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
114 xmlGenericErrorContext = ctx;
115 if (handler != NULL)
116 xmlGenericError = handler;
117 else
118 xmlGenericError = xmlGenericErrorDefaultFunc;
119}
120
Daniel Veillard659e71e2003-10-10 14:10:40 +0000121/**
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 Veillardda3b29a2004-08-14 11:15:13 +0000131 * For multi-threaded applications, this must be set separately for each thread.
Daniel Veillard659e71e2003-10-10 14:10:40 +0000132 */
133void
134xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
135 xmlGenericErrorContext = ctx;
136 xmlStructuredError = handler;
137}
138
Owen Taylor3473f882001-02-23 17:55:21 +0000139/************************************************************************
140 * *
141 * Handling of parsing errors *
142 * *
143 ************************************************************************/
144
145/**
146 * xmlParserPrintFileInfo:
147 * @input: an xmlParserInputPtr input
148 *
149 * Displays the associated file and line informations for the current input
150 */
151
152void
153xmlParserPrintFileInfo(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
168 *
169 * Displays current context within the input content for error tracking
170 */
171
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000172static void
173xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
174 xmlGenericErrorFunc channel, void *data ) {
Daniel Veillard561b7f82002-03-20 21:55:57 +0000175 const xmlChar *cur, *base;
William M. Brackc1939562003-08-05 15:52:22 +0000176 unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
William M. Brack3dd57f72003-05-13 02:06:18 +0000177 xmlChar content[81]; /* space for 80 chars + line terminator */
Daniel Veillard2be30642001-03-27 00:32:28 +0000178 xmlChar *ctnt;
Owen Taylor3473f882001-02-23 17:55:21 +0000179
Daniel Veillard561b7f82002-03-20 21:55:57 +0000180 if (input == NULL) return;
Owen Taylor3473f882001-02-23 17:55:21 +0000181 cur = input->cur;
182 base = input->base;
Daniel Veillard2be30642001-03-27 00:32:28 +0000183 /* skip backwards over any end-of-lines */
William M. Brackc1939562003-08-05 15:52:22 +0000184 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
Daniel Veillard561b7f82002-03-20 21:55:57 +0000185 cur--;
Owen Taylor3473f882001-02-23 17:55:21 +0000186 }
187 n = 0;
William M. Brack3dd57f72003-05-13 02:06:18 +0000188 /* search backwards for beginning-of-line (to max buff size) */
William M. Brackc1939562003-08-05 15:52:22 +0000189 while ((n++ < (sizeof(content)-1)) && (cur > base) &&
190 (*(cur) != '\n') && (*(cur) != '\r'))
Owen Taylor3473f882001-02-23 17:55:21 +0000191 cur--;
William M. Brackc1939562003-08-05 15:52:22 +0000192 if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
William M. Brack3dd57f72003-05-13 02:06:18 +0000193 /* calculate the error position in terms of the current position */
194 col = input->cur - cur;
195 /* search forward for end-of-line (to max buff size) */
Owen Taylor3473f882001-02-23 17:55:21 +0000196 n = 0;
Daniel Veillard2be30642001-03-27 00:32:28 +0000197 ctnt = content;
William M. Brack3dd57f72003-05-13 02:06:18 +0000198 /* copy selected text to our buffer */
William M. Brackc1939562003-08-05 15:52:22 +0000199 while ((*cur != 0) && (*(cur) != '\n') &&
200 (*(cur) != '\r') && (n < sizeof(content)-1)) {
Daniel Veillard561b7f82002-03-20 21:55:57 +0000201 *ctnt++ = *cur++;
202 n++;
Owen Taylor3473f882001-02-23 17:55:21 +0000203 }
Daniel Veillard2be30642001-03-27 00:32:28 +0000204 *ctnt = 0;
William M. Brack3dd57f72003-05-13 02:06:18 +0000205 /* print out the selected text */
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000206 channel(data ,"%s\n", content);
Daniel Veillard2be30642001-03-27 00:32:28 +0000207 /* create blank line with problem pointer */
Owen Taylor3473f882001-02-23 17:55:21 +0000208 n = 0;
Daniel Veillard7533cc82001-04-24 15:52:00 +0000209 ctnt = content;
William M. Brack3dd57f72003-05-13 02:06:18 +0000210 /* (leave buffer space for pointer + line terminator) */
211 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
William M. Brackc1939562003-08-05 15:52:22 +0000212 if (*(ctnt) != '\t')
213 *(ctnt) = ' ';
William M. Brack69848302003-09-22 00:24:51 +0000214 ctnt++;
Owen Taylor3473f882001-02-23 17:55:21 +0000215 }
William M. Brack3dd57f72003-05-13 02:06:18 +0000216 *ctnt++ = '^';
217 *ctnt = 0;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000218 channel(data ,"%s\n", content);
Owen Taylor3473f882001-02-23 17:55:21 +0000219}
220
Daniel Veillard561b7f82002-03-20 21:55:57 +0000221/**
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000222 * xmlParserPrintFileContext:
223 * @input: an xmlParserInputPtr input
224 *
225 * Displays current context within the input content for error tracking
Daniel Veillard561b7f82002-03-20 21:55:57 +0000226 */
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000227void
228xmlParserPrintFileContext(xmlParserInputPtr input) {
229 xmlParserPrintFileContextInternal(input, xmlGenericError,
230 xmlGenericErrorContext);
Daniel Veillard561b7f82002-03-20 21:55:57 +0000231}
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000232
233/**
234 * xmlReportError:
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000235 * @err: the error
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000236 * @ctx: the parser context or NULL
237 * @str: the formatted error message
238 *
239 * Report an erro with its context, replace the 4 old error/warning
240 * routines.
241 */
242static void
Daniel Veillard4c004142003-10-07 11:33:24 +0000243xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
244 xmlGenericErrorFunc channel, void *data)
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000245{
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000246 char *file = NULL;
247 int line = 0;
248 int code = -1;
249 int domain;
Daniel Veillard4c004142003-10-07 11:33:24 +0000250 const xmlChar *name = NULL;
251 xmlNodePtr node;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000252 xmlErrorLevel level;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000253 xmlParserInputPtr input = NULL;
254 xmlParserInputPtr cur = NULL;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000255
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000256 if (err == NULL)
257 return;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000258
Daniel Veillard4c004142003-10-07 11:33:24 +0000259 if (channel == NULL) {
260 channel = xmlGenericError;
261 data = xmlGenericErrorContext;
262 }
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000263 file = err->file;
264 line = err->line;
265 code = err->code;
266 domain = err->domain;
267 level = err->level;
Daniel Veillard4c004142003-10-07 11:33:24 +0000268 node = err->node;
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000269
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000270 if (code == XML_ERR_OK)
271 return;
272
Daniel Veillard4c004142003-10-07 11:33:24 +0000273 if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
274 name = node->name;
275
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000276 /*
277 * Maintain the compatibility with the legacy error handling
278 */
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000279 if (ctxt != NULL) {
280 input = ctxt->input;
281 if ((input != NULL) && (input->filename == NULL) &&
282 (ctxt->inputNr > 1)) {
283 cur = input;
284 input = ctxt->inputTab[ctxt->inputNr - 2];
285 }
286 if (input != NULL) {
287 if (input->filename)
288 channel(data, "%s:%d: ", input->filename, input->line);
Daniel Veillardd96f6d32003-10-07 21:25:12 +0000289 else if ((line != 0) && (domain == XML_FROM_PARSER))
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000290 channel(data, "Entity: line %d: ", input->line);
291 }
292 } else {
293 if (file != NULL)
294 channel(data, "%s:%d: ", file, line);
Daniel Veillardd96f6d32003-10-07 21:25:12 +0000295 else if ((line != 0) && (domain == XML_FROM_PARSER))
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000296 channel(data, "Entity: line %d: ", line);
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000297 }
Daniel Veillard4c004142003-10-07 11:33:24 +0000298 if (name != NULL) {
299 channel(data, "element %s: ", name);
300 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000301 switch (domain) {
302 case XML_FROM_PARSER:
303 channel(data, "parser ");
304 break;
305 case XML_FROM_NAMESPACE:
306 channel(data, "namespace ");
307 break;
308 case XML_FROM_DTD:
Daniel Veillard72b9e292003-10-28 15:44:17 +0000309 case XML_FROM_VALID:
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000310 channel(data, "validity ");
311 break;
312 case XML_FROM_HTML:
313 channel(data, "HTML parser ");
314 break;
315 case XML_FROM_MEMORY:
316 channel(data, "memory ");
317 break;
318 case XML_FROM_OUTPUT:
319 channel(data, "output ");
320 break;
321 case XML_FROM_IO:
322 channel(data, "I/O ");
323 break;
324 case XML_FROM_XINCLUDE:
325 channel(data, "XInclude ");
326 break;
327 case XML_FROM_XPATH:
328 channel(data, "XPath ");
329 break;
330 case XML_FROM_XPOINTER:
331 channel(data, "parser ");
332 break;
333 case XML_FROM_REGEXP:
334 channel(data, "regexp ");
335 break;
Daniel Veillardce1648b2005-01-04 15:10:22 +0000336 case XML_FROM_MODULE:
337 channel(data, "module ");
338 break;
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000339 case XML_FROM_SCHEMASV:
Daniel Veillard87db3a82003-10-10 10:52:58 +0000340 channel(data, "Schemas validity ");
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000341 break;
342 case XML_FROM_SCHEMASP:
Daniel Veillard87db3a82003-10-10 10:52:58 +0000343 channel(data, "Schemas parser ");
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000344 break;
Daniel Veillard4c004142003-10-07 11:33:24 +0000345 case XML_FROM_RELAXNGP:
346 channel(data, "Relax-NG parser ");
347 break;
348 case XML_FROM_RELAXNGV:
Daniel Veillardd0c9c322003-10-10 00:49:42 +0000349 channel(data, "Relax-NG validity ");
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000350 break;
351 case XML_FROM_CATALOG:
352 channel(data, "Catalog ");
353 break;
354 case XML_FROM_C14N:
355 channel(data, "C14N ");
356 break;
357 case XML_FROM_XSLT:
358 channel(data, "XSLT ");
359 break;
Daniel Veillard1fc3ed02005-08-24 12:46:09 +0000360 case XML_FROM_I18N:
361 channel(data, "encoding ");
362 break;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000363 default:
364 break;
365 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000366 switch (level) {
367 case XML_ERR_NONE:
368 channel(data, ": ");
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000369 break;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000370 case XML_ERR_WARNING:
371 channel(data, "warning : ");
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000372 break;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000373 case XML_ERR_ERROR:
374 channel(data, "error : ");
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000375 break;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000376 case XML_ERR_FATAL:
377 channel(data, "error : ");
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000378 break;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000379 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000380 if (str != NULL) {
Daniel Veillard828ce832003-10-08 19:19:10 +0000381 int len;
382 len = xmlStrlen((const xmlChar *)str);
383 if ((len > 0) && (str[len - 1] != '\n'))
Daniel Veillard828ce832003-10-08 19:19:10 +0000384 channel(data, "%s\n", str);
Daniel Veillarda8856222003-10-08 19:26:03 +0000385 else
386 channel(data, "%s", str);
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000387 } else {
Daniel Veillard828ce832003-10-08 19:19:10 +0000388 channel(data, "%s\n", "out of memory error");
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000389 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000390
391 if (ctxt != NULL) {
392 xmlParserPrintFileContextInternal(input, channel, data);
393 if (cur != NULL) {
394 if (cur->filename)
395 channel(data, "%s:%d: \n", cur->filename, cur->line);
Daniel Veillardd96f6d32003-10-07 21:25:12 +0000396 else if ((line != 0) && (domain == XML_FROM_PARSER))
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000397 channel(data, "Entity: line %d: \n", cur->line);
398 xmlParserPrintFileContextInternal(cur, channel, data);
399 }
400 }
Daniel Veillardd96f6d32003-10-07 21:25:12 +0000401 if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
402 (err->int1 < 100) &&
403 (err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
404 xmlChar buf[150];
405 int i;
406
407 channel(data, "%s\n", err->str1);
408 for (i=0;i < err->int1;i++)
409 buf[i] = ' ';
410 buf[i++] = '^';
411 buf[i] = 0;
412 channel(data, "%s\n", buf);
413 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000414}
415
416/**
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000417 * __xmlRaiseError:
William M. Brackd233e392004-05-16 03:12:08 +0000418 * @schannel: the structured callback channel
Daniel Veillard659e71e2003-10-10 14:10:40 +0000419 * @channel: the old callback channel
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000420 * @data: the callback data
421 * @ctx: the parser context or NULL
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000422 * @ctx: the parser context or NULL
423 * @domain: the domain for the error
424 * @code: the code for the error
425 * @level: the xmlErrorLevel for the error
426 * @file: the file source of the error (or NULL)
427 * @line: the line of the error or 0 if N/A
428 * @str1: extra string info
429 * @str2: extra string info
430 * @str3: extra string info
431 * @int1: extra int info
Aleksey Sanin8fdc32a2005-01-05 15:37:55 +0000432 * @col: column number of the error or 0 if N/A
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000433 * @msg: the message to display/transmit
434 * @...: extra parameters for the message display
435 *
William M. Brackd233e392004-05-16 03:12:08 +0000436 * Update the appropriate global or contextual error structure,
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000437 * then forward the error message down the parser or generic
438 * error callback handler
439 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000440void XMLCDECL
Daniel Veillard659e71e2003-10-10 14:10:40 +0000441__xmlRaiseError(xmlStructuredErrorFunc schannel,
442 xmlGenericErrorFunc channel, void *data, void *ctx,
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000443 void *nod, int domain, int code, xmlErrorLevel level,
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000444 const char *file, int line, const char *str1,
Aleksey Sanin8fdc32a2005-01-05 15:37:55 +0000445 const char *str2, const char *str3, int int1, int col,
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000446 const char *msg, ...)
447{
Daniel Veillardcd6ff282003-10-08 22:38:13 +0000448 xmlParserCtxtPtr ctxt = NULL;
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000449 xmlNodePtr node = (xmlNodePtr) nod;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000450 char *str = NULL;
451 xmlParserInputPtr input = NULL;
452 xmlErrorPtr to = &xmlLastError;
William M. Brackd0407522004-10-02 03:54:00 +0000453 xmlNodePtr baseptr = NULL;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000454
Daniel Veillardb5fa0202003-12-08 17:41:29 +0000455 if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING))
456 return;
Daniel Veillardcd6ff282003-10-08 22:38:13 +0000457 if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
458 (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
Daniel Veillard370ba3d2004-10-25 16:23:56 +0000459 (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
Daniel Veillardcd6ff282003-10-08 22:38:13 +0000460 ctxt = (xmlParserCtxtPtr) ctx;
Daniel Veillard659e71e2003-10-10 14:10:40 +0000461 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
462 (ctxt->sax->initialized == XML_SAX2_MAGIC))
463 schannel = ctxt->sax->serror;
Daniel Veillardcd6ff282003-10-08 22:38:13 +0000464 }
William M. Brackcd3628b2004-07-25 21:07:29 +0000465 /*
466 * Check if structured error handler set
467 */
468 if (schannel == NULL) {
Daniel Veillardf88d8cf2003-12-08 10:25:02 +0000469 schannel = xmlStructuredError;
William M. Brackcd3628b2004-07-25 21:07:29 +0000470 /*
471 * if user has defined handler, change data ptr to user's choice
472 */
473 if (schannel != NULL)
474 data = xmlGenericErrorContext;
475 }
Daniel Veillard72b9e292003-10-28 15:44:17 +0000476 if ((domain == XML_FROM_VALID) &&
477 ((channel == xmlParserValidityError) ||
478 (channel == xmlParserValidityWarning))) {
479 ctxt = (xmlParserCtxtPtr) ctx;
480 if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
481 (ctxt->sax->initialized == XML_SAX2_MAGIC))
482 schannel = ctxt->sax->serror;
483 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000484 if (code == XML_ERR_OK)
485 return;
486 /*
487 * Formatting the message
488 */
489 if (msg == NULL) {
490 str = (char *) xmlStrdup(BAD_CAST "No error message provided");
491 } else {
492 XML_GET_VAR_STR(msg, str);
493 }
494
495 /*
496 * specific processing if a parser context is provided
497 */
498 if (ctxt != NULL) {
499 if (file == NULL) {
500 input = ctxt->input;
501 if ((input != NULL) && (input->filename == NULL) &&
502 (ctxt->inputNr > 1)) {
503 input = ctxt->inputTab[ctxt->inputNr - 2];
504 }
505 if (input != NULL) {
506 file = input->filename;
507 line = input->line;
Aleksey Sanin8fdc32a2005-01-05 15:37:55 +0000508 col = input->col;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000509 }
510 }
511 to = &ctxt->lastError;
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000512 } else if ((node != NULL) && (file == NULL)) {
513 int i;
Daniel Veillard4c004142003-10-07 11:33:24 +0000514
Daniel Veillarddbee0f12005-06-27 13:42:57 +0000515 if ((node->doc != NULL) && (node->doc->URL != NULL)) {
William M. Brackd0407522004-10-02 03:54:00 +0000516 baseptr = node;
Daniel Veillard8ce01ce2005-08-25 20:14:38 +0000517/* file = (const char *) node->doc->URL; */
Daniel Veillarddbee0f12005-06-27 13:42:57 +0000518 }
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000519 for (i = 0;
520 ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE));
521 i++)
522 node = node->parent;
William M. Brackd0407522004-10-02 03:54:00 +0000523 if ((baseptr == NULL) && (node != NULL) &&
Daniel Veillard4c004142003-10-07 11:33:24 +0000524 (node->doc != NULL) && (node->doc->URL != NULL))
William M. Brackd0407522004-10-02 03:54:00 +0000525 baseptr = node;
Daniel Veillard4c004142003-10-07 11:33:24 +0000526
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000527 if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
Daniel Veillard3e35f8e2003-10-21 00:05:38 +0000528 line = node->line;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000529 }
530
531 /*
William M. Brackd233e392004-05-16 03:12:08 +0000532 * Save the information about the error
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000533 */
534 xmlResetError(to);
535 to->domain = domain;
536 to->code = code;
537 to->message = str;
538 to->level = level;
539 if (file != NULL)
540 to->file = (char *) xmlStrdup((const xmlChar *) file);
William M. Brackd0407522004-10-02 03:54:00 +0000541 else if (baseptr != NULL) {
542#ifdef LIBXML_XINCLUDE_ENABLED
543 /*
544 * We check if the error is within an XInclude section and,
545 * if so, attempt to print out the href of the XInclude instead
546 * of the usual "base" (doc->URL) for the node (bug 152623).
547 */
548 xmlNodePtr prev = baseptr;
549 int inclcount = 0;
550 while (prev != NULL) {
551 if (prev->prev == NULL)
552 prev = prev->parent;
553 else {
554 prev = prev->prev;
555 if (prev->type == XML_XINCLUDE_START) {
556 if (--inclcount < 0)
557 break;
558 } else if (prev->type == XML_XINCLUDE_END)
559 inclcount++;
560 }
561 }
562 if (prev != NULL) {
Daniel Veillard8ce01ce2005-08-25 20:14:38 +0000563 if (prev->type == XML_XINCLUDE_START) {
564 prev->type = XML_ELEMENT_NODE;
565 to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
566 prev->type = XML_XINCLUDE_START;
567 } else {
568 to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
569 }
William M. Brackd0407522004-10-02 03:54:00 +0000570 } else
571#endif
572 to->file = (char *) xmlStrdup(baseptr->doc->URL);
Daniel Veillard8ce01ce2005-08-25 20:14:38 +0000573 if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) {
574 to->file = (char *) xmlStrdup(node->doc->URL);
575 }
William M. Brackd0407522004-10-02 03:54:00 +0000576 file = to->file;
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000577 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000578 to->line = line;
579 if (str1 != NULL)
580 to->str1 = (char *) xmlStrdup((const xmlChar *) str1);
581 if (str2 != NULL)
582 to->str2 = (char *) xmlStrdup((const xmlChar *) str2);
583 if (str3 != NULL)
584 to->str3 = (char *) xmlStrdup((const xmlChar *) str3);
585 to->int1 = int1;
Aleksey Sanin8fdc32a2005-01-05 15:37:55 +0000586 to->int2 = col;
Daniel Veillard4c004142003-10-07 11:33:24 +0000587 to->node = node;
Daniel Veillardcd6ff282003-10-08 22:38:13 +0000588 to->ctxt = ctx;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000589
Daniel Veillardd34b0b82004-01-02 20:26:01 +0000590 if (to != &xmlLastError)
591 xmlCopyError(to,&xmlLastError);
592
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000593 /*
William M. Brackcd3628b2004-07-25 21:07:29 +0000594 * Find the callback channel if channel param is NULL
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000595 */
William M. Brack9f797ab2004-07-28 07:40:12 +0000596 if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (ctxt->sax != NULL)) {
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000597 if (level == XML_ERR_WARNING)
598 channel = ctxt->sax->warning;
599 else
600 channel = ctxt->sax->error;
Daniel Veillard4c004142003-10-07 11:33:24 +0000601 data = ctxt->userData;
Daniel Veillardbb5abab2003-10-03 22:21:51 +0000602 } else if (channel == NULL) {
Daniel Veillard659e71e2003-10-10 14:10:40 +0000603 if (xmlStructuredError != NULL)
604 schannel = xmlStructuredError;
605 else
606 channel = xmlGenericError;
Daniel Veillardda0aa4c2005-07-13 23:07:49 +0000607 if (!data) {
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000608 data = xmlGenericErrorContext;
609 }
Daniel Veillardda0aa4c2005-07-13 23:07:49 +0000610 }
Daniel Veillard659e71e2003-10-10 14:10:40 +0000611 if (schannel != NULL) {
612 schannel(data, to);
613 return;
614 }
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000615 if (channel == NULL)
616 return;
617
618 if ((channel == xmlParserError) ||
619 (channel == xmlParserWarning) ||
620 (channel == xmlParserValidityError) ||
621 (channel == xmlParserValidityWarning))
Daniel Veillard4c004142003-10-07 11:33:24 +0000622 xmlReportError(to, ctxt, str, NULL, NULL);
623 else if ((channel == (xmlGenericErrorFunc) fprintf) ||
624 (channel == xmlGenericErrorDefaultFunc))
625 xmlReportError(to, ctxt, str, channel, data);
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000626 else
627 channel(data, "%s", str);
628}
Daniel Veillard561b7f82002-03-20 21:55:57 +0000629
Daniel Veillarde356c282001-03-10 12:32:04 +0000630/**
Daniel Veillard18ec16e2003-10-07 23:16:40 +0000631 * __xmlSimpleError:
632 * @domain: where the error comes from
633 * @code: the error code
634 * @node: the context node
635 * @extra: extra informations
636 *
637 * Handle an out of memory condition
638 */
639void
640__xmlSimpleError(int domain, int code, xmlNodePtr node,
641 const char *msg, const char *extra)
642{
643
644 if (code == XML_ERR_NO_MEMORY) {
645 if (extra)
Daniel Veillard659e71e2003-10-10 14:10:40 +0000646 __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Daniel Veillard18ec16e2003-10-07 23:16:40 +0000647 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
648 NULL, NULL, 0, 0,
649 "Memory allocation failed : %s\n", extra);
650 else
Daniel Veillard659e71e2003-10-10 14:10:40 +0000651 __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Daniel Veillard18ec16e2003-10-07 23:16:40 +0000652 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
653 NULL, NULL, 0, 0, "Memory allocation failed\n");
654 } else {
Daniel Veillard659e71e2003-10-10 14:10:40 +0000655 __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
Daniel Veillard18ec16e2003-10-07 23:16:40 +0000656 code, XML_ERR_ERROR, NULL, 0, extra,
657 NULL, NULL, 0, 0, msg, extra);
658 }
659}
660/**
Owen Taylor3473f882001-02-23 17:55:21 +0000661 * xmlParserError:
662 * @ctx: an XML parser context
663 * @msg: the message to display/transmit
664 * @...: extra parameters for the message display
665 *
666 * Display and format an error messages, gives file, line, position and
667 * extra parameters.
668 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000669void XMLCDECL
Owen Taylor3473f882001-02-23 17:55:21 +0000670xmlParserError(void *ctx, const char *msg, ...)
671{
672 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
673 xmlParserInputPtr input = NULL;
674 xmlParserInputPtr cur = NULL;
Daniel Veillarde356c282001-03-10 12:32:04 +0000675 char * str;
Owen Taylor3473f882001-02-23 17:55:21 +0000676
677 if (ctxt != NULL) {
678 input = ctxt->input;
679 if ((input != NULL) && (input->filename == NULL) &&
680 (ctxt->inputNr > 1)) {
681 cur = input;
682 input = ctxt->inputTab[ctxt->inputNr - 2];
683 }
684 xmlParserPrintFileInfo(input);
685 }
686
687 xmlGenericError(xmlGenericErrorContext, "error: ");
Daniel Veillard1c43dbf2001-06-05 17:12:52 +0000688 XML_GET_VAR_STR(msg, str);
Daniel Veillard635ef722001-10-29 11:48:19 +0000689 xmlGenericError(xmlGenericErrorContext, "%s", str);
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000690 if (str != NULL)
691 xmlFree(str);
Owen Taylor3473f882001-02-23 17:55:21 +0000692
693 if (ctxt != NULL) {
694 xmlParserPrintFileContext(input);
695 if (cur != NULL) {
696 xmlParserPrintFileInfo(cur);
697 xmlGenericError(xmlGenericErrorContext, "\n");
698 xmlParserPrintFileContext(cur);
699 }
700 }
701}
702
703/**
704 * xmlParserWarning:
705 * @ctx: an XML parser context
706 * @msg: the message to display/transmit
707 * @...: extra parameters for the message display
708 *
709 * Display and format a warning messages, gives file, line, position and
710 * extra parameters.
711 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000712void XMLCDECL
Owen Taylor3473f882001-02-23 17:55:21 +0000713xmlParserWarning(void *ctx, const char *msg, ...)
714{
715 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
716 xmlParserInputPtr input = NULL;
717 xmlParserInputPtr cur = NULL;
Daniel Veillarde356c282001-03-10 12:32:04 +0000718 char * str;
Owen Taylor3473f882001-02-23 17:55:21 +0000719
720 if (ctxt != NULL) {
721 input = ctxt->input;
722 if ((input != NULL) && (input->filename == NULL) &&
723 (ctxt->inputNr > 1)) {
724 cur = input;
725 input = ctxt->inputTab[ctxt->inputNr - 2];
726 }
727 xmlParserPrintFileInfo(input);
728 }
729
730 xmlGenericError(xmlGenericErrorContext, "warning: ");
Daniel Veillard1c43dbf2001-06-05 17:12:52 +0000731 XML_GET_VAR_STR(msg, str);
Daniel Veillard635ef722001-10-29 11:48:19 +0000732 xmlGenericError(xmlGenericErrorContext, "%s", str);
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000733 if (str != NULL)
734 xmlFree(str);
Owen Taylor3473f882001-02-23 17:55:21 +0000735
736 if (ctxt != NULL) {
737 xmlParserPrintFileContext(input);
738 if (cur != NULL) {
739 xmlParserPrintFileInfo(cur);
740 xmlGenericError(xmlGenericErrorContext, "\n");
741 xmlParserPrintFileContext(cur);
742 }
743 }
744}
745
746/************************************************************************
747 * *
748 * Handling of validation errors *
749 * *
750 ************************************************************************/
751
752/**
753 * xmlParserValidityError:
754 * @ctx: an XML parser context
755 * @msg: the message to display/transmit
756 * @...: extra parameters for the message display
757 *
758 * Display and format an validity error messages, gives file,
759 * line, position and extra parameters.
760 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000761void XMLCDECL
Owen Taylor3473f882001-02-23 17:55:21 +0000762xmlParserValidityError(void *ctx, const char *msg, ...)
763{
764 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
765 xmlParserInputPtr input = NULL;
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000766 char * str;
Daniel Veillard76575762002-09-05 14:21:15 +0000767 int len = xmlStrlen((const xmlChar *) msg);
768 static int had_info = 0;
Owen Taylor3473f882001-02-23 17:55:21 +0000769
Daniel Veillard76575762002-09-05 14:21:15 +0000770 if ((len > 1) && (msg[len - 2] != ':')) {
771 if (ctxt != NULL) {
772 input = ctxt->input;
773 if ((input->filename == NULL) && (ctxt->inputNr > 1))
774 input = ctxt->inputTab[ctxt->inputNr - 2];
775
776 if (had_info == 0) {
777 xmlParserPrintFileInfo(input);
778 }
779 }
780 xmlGenericError(xmlGenericErrorContext, "validity error: ");
Daniel Veillard76575762002-09-05 14:21:15 +0000781 had_info = 0;
782 } else {
783 had_info = 1;
Owen Taylor3473f882001-02-23 17:55:21 +0000784 }
785
Daniel Veillard1c43dbf2001-06-05 17:12:52 +0000786 XML_GET_VAR_STR(msg, str);
Daniel Veillard635ef722001-10-29 11:48:19 +0000787 xmlGenericError(xmlGenericErrorContext, "%s", str);
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000788 if (str != NULL)
789 xmlFree(str);
Owen Taylor3473f882001-02-23 17:55:21 +0000790
Daniel Veillard76575762002-09-05 14:21:15 +0000791 if ((ctxt != NULL) && (input != NULL)) {
Owen Taylor3473f882001-02-23 17:55:21 +0000792 xmlParserPrintFileContext(input);
793 }
794}
795
796/**
797 * xmlParserValidityWarning:
798 * @ctx: an XML parser context
799 * @msg: the message to display/transmit
800 * @...: extra parameters for the message display
801 *
802 * Display and format a validity warning messages, gives file, line,
803 * position and extra parameters.
804 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000805void XMLCDECL
Owen Taylor3473f882001-02-23 17:55:21 +0000806xmlParserValidityWarning(void *ctx, const char *msg, ...)
807{
808 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
809 xmlParserInputPtr input = NULL;
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000810 char * str;
Daniel Veillard76575762002-09-05 14:21:15 +0000811 int len = xmlStrlen((const xmlChar *) msg);
Owen Taylor3473f882001-02-23 17:55:21 +0000812
Daniel Veillard76575762002-09-05 14:21:15 +0000813 if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) {
Owen Taylor3473f882001-02-23 17:55:21 +0000814 input = ctxt->input;
815 if ((input->filename == NULL) && (ctxt->inputNr > 1))
816 input = ctxt->inputTab[ctxt->inputNr - 2];
817
818 xmlParserPrintFileInfo(input);
819 }
820
821 xmlGenericError(xmlGenericErrorContext, "validity warning: ");
Daniel Veillard1c43dbf2001-06-05 17:12:52 +0000822 XML_GET_VAR_STR(msg, str);
Daniel Veillard635ef722001-10-29 11:48:19 +0000823 xmlGenericError(xmlGenericErrorContext, "%s", str);
Daniel Veillard9e7160d2001-03-18 23:17:47 +0000824 if (str != NULL)
825 xmlFree(str);
Owen Taylor3473f882001-02-23 17:55:21 +0000826
827 if (ctxt != NULL) {
828 xmlParserPrintFileContext(input);
829 }
830}
831
832
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000833/************************************************************************
834 * *
835 * Extended Error Handling *
836 * *
837 ************************************************************************/
838
839/**
840 * xmlGetLastError:
841 *
842 * Get the last global error registered. This is per thread if compiled
843 * with thread support.
844 *
845 * Returns NULL if no error occured or a pointer to the error
846 */
847xmlErrorPtr
848xmlGetLastError(void)
849{
850 if (xmlLastError.code == XML_ERR_OK)
851 return (NULL);
852 return (&xmlLastError);
853}
854
855/**
856 * xmlResetError:
857 * @err: pointer to the error.
858 *
859 * Cleanup the error.
860 */
861void
862xmlResetError(xmlErrorPtr err)
863{
864 if (err == NULL)
865 return;
866 if (err->code == XML_ERR_OK)
867 return;
868 if (err->message != NULL)
869 xmlFree(err->message);
870 if (err->file != NULL)
871 xmlFree(err->file);
872 if (err->str1 != NULL)
873 xmlFree(err->str1);
874 if (err->str2 != NULL)
875 xmlFree(err->str2);
876 if (err->str3 != NULL)
877 xmlFree(err->str3);
878 memset(err, 0, sizeof(xmlError));
879 err->code = XML_ERR_OK;
880}
881
882/**
883 * xmlResetLastError:
884 *
885 * Cleanup the last global error registered. For parsing error
886 * this does not change the well-formedness result.
887 */
888void
889xmlResetLastError(void)
890{
891 if (xmlLastError.code == XML_ERR_OK)
892 return;
893 xmlResetError(&xmlLastError);
894}
895
896/**
897 * xmlCtxtGetLastError:
898 * @ctx: an XML parser context
899 *
900 * Get the last parsing error registered.
901 *
902 * Returns NULL if no error occured or a pointer to the error
903 */
904xmlErrorPtr
905xmlCtxtGetLastError(void *ctx)
906{
907 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
908
909 if (ctxt == NULL)
910 return (NULL);
911 if (ctxt->lastError.code == XML_ERR_OK)
912 return (NULL);
913 return (&ctxt->lastError);
914}
915
916/**
917 * xmlCtxtResetLastError:
918 * @ctx: an XML parser context
919 *
920 * Cleanup the last global error registered. For parsing error
921 * this does not change the well-formedness result.
922 */
923void
924xmlCtxtResetLastError(void *ctx)
925{
926 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
927
928 if (ctxt == NULL)
929 return;
930 if (ctxt->lastError.code == XML_ERR_OK)
931 return;
932 xmlResetError(&ctxt->lastError);
933}
934
935/**
936 * xmlCopyError:
937 * @from: a source error
938 * @to: a target error
939 *
940 * Save the original error to the new place.
941 *
942 * Returns 0 in case of success and -1 in case of error.
943 */
944int
945xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
William M. Bracka3215c72004-07-31 16:24:01 +0000946 char *message, *file, *str1, *str2, *str3;
947
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000948 if ((from == NULL) || (to == NULL))
949 return(-1);
William M. Bracka3215c72004-07-31 16:24:01 +0000950
951 message = (char *) xmlStrdup((xmlChar *) from->message);
952 file = (char *) xmlStrdup ((xmlChar *) from->file);
953 str1 = (char *) xmlStrdup ((xmlChar *) from->str1);
954 str2 = (char *) xmlStrdup ((xmlChar *) from->str2);
955 str3 = (char *) xmlStrdup ((xmlChar *) from->str3);
956
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000957 if (to->message != NULL)
958 xmlFree(to->message);
959 if (to->file != NULL)
960 xmlFree(to->file);
961 if (to->str1 != NULL)
962 xmlFree(to->str1);
963 if (to->str2 != NULL)
964 xmlFree(to->str2);
965 if (to->str3 != NULL)
966 xmlFree(to->str3);
967 to->domain = from->domain;
968 to->code = from->code;
969 to->level = from->level;
970 to->line = from->line;
Daniel Veillard4c004142003-10-07 11:33:24 +0000971 to->node = from->node;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000972 to->int1 = from->int1;
973 to->int2 = from->int2;
Daniel Veillard4c004142003-10-07 11:33:24 +0000974 to->node = from->node;
975 to->ctxt = from->ctxt;
William M. Bracka3215c72004-07-31 16:24:01 +0000976 to->message = message;
977 to->file = file;
978 to->str1 = str1;
979 to->str2 = str2;
980 to->str3 = str3;
981
982 return 0;
Daniel Veillard2b8c4a12003-10-02 22:28:19 +0000983}
984
Daniel Veillard5d4644e2005-04-01 13:11:58 +0000985#define bottom_error
986#include "elfgcchack.h"