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