ReactOS 0.4.16-dev-2208-g6350669
error.c File Reference
#include "libxml.h"
#include <string.h>
#include <stdarg.h>
#include <libxml/parser.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlmemory.h>
#include "private/error.h"
Include dependency graph for error.c:

Go to the source code of this file.

Macros

#define IN_LIBXML
 
#define XML_MAX_ERRORS   100
 
#define XML_GET_VAR_STR(msg, str)
 

Functions

void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg,...)
 
void initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler)
 
void xmlSetGenericErrorFunc (void *ctx, xmlGenericErrorFunc handler)
 
void xmlSetStructuredErrorFunc (void *ctx, xmlStructuredErrorFunc handler)
 
void xmlParserPrintFileInfo (xmlParserInputPtr input)
 
static void xmlParserPrintFileContextInternal (xmlParserInputPtr input, xmlGenericErrorFunc channel, void *data)
 
void xmlParserPrintFileContext (xmlParserInputPtr input)
 
static void xmlReportError (xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, xmlGenericErrorFunc channel, void *data)
 

Macro Definition Documentation

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 9 of file error.c.

◆ XML_GET_VAR_STR

#define XML_GET_VAR_STR (   msg,
  str 
)

Definition at line 22 of file error.c.

◆ XML_MAX_ERRORS

#define XML_MAX_ERRORS   100

Definition at line 20 of file error.c.

Function Documentation

◆ initGenericErrorDefaultFunc()

void initGenericErrorDefaultFunc ( xmlGenericErrorFunc handler)

initGenericErrorDefaultFunc: @handler: the handler

DEPRECATED: Use xmlSetGenericErrorFunc.

Set or reset (if NULL) the default handler for generic errors to the builtin error function.

Definition at line 91 of file error.c.

92{
93 if (handler == NULL)
95 else
96 xmlGenericError = (*handler);
97}
#define NULL
Definition: types.h:112
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
void xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg,...)
Definition: error.c:70
xmlGenericErrorFunc xmlGenericError
Definition: globals.c:396

◆ xmlGenericErrorDefaultFunc()

void xmlGenericErrorDefaultFunc ( void *ctx  ATTRIBUTE_UNUSED,
const char msg,
  ... 
)

xmlGenericErrorDefaultFunc: @ctx: an error context @msg: the message to display/transmit ...: extra parameters for the message display

Default handler for out of context error messages.

Definition at line 70 of file error.c.

70 {
72
75
78 va_end(args);
79}
#define msg(x)
Definition: auth_time.c:54
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
Definition: file.c:5349
#define stderr
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
void * xmlGenericErrorContext
Definition: globals.c:410
#define args
Definition: format.c:66
Definition: match.c:390

Referenced by initGenericErrorDefaultFunc(), xmlSetGenericErrorFunc(), and xmlThrDefSetGenericErrorFunc().

◆ xmlParserPrintFileContext()

void xmlParserPrintFileContext ( xmlParserInputPtr  input)

xmlParserPrintFileContext: @input: an xmlParserInputPtr input

Displays current context within the input content for error tracking

Definition at line 244 of file error.c.

244 {
247}
GLenum GLenum GLenum input
Definition: glext.h:9031
static void xmlParserPrintFileContextInternal(xmlParserInputPtr input, xmlGenericErrorFunc channel, void *data)
Definition: error.c:174

◆ xmlParserPrintFileContextInternal()

static void xmlParserPrintFileContextInternal ( xmlParserInputPtr  input,
xmlGenericErrorFunc  channel,
void data 
)
static

xmlParserPrintFileContextInternal: @input: an xmlParserInputPtr input

Displays current context within the input content for error tracking

Definition at line 174 of file error.c.

175 {
176 const xmlChar *cur, *base, *start;
177 unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
178 xmlChar content[81]; /* space for 80 chars + line terminator */
179 xmlChar *ctnt;
180
181 if ((input == NULL) || (input->cur == NULL))
182 return;
183
184 cur = input->cur;
185 base = input->base;
186 /* skip backwards over any end-of-lines */
187 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
188 cur--;
189 }
190 n = 0;
191 /* search backwards for beginning-of-line (to max buff size) */
192 while ((n < sizeof(content) - 1) && (cur > base) &&
193 (*cur != '\n') && (*cur != '\r')) {
194 cur--;
195 n++;
196 }
197 if ((n > 0) && ((*cur == '\n') || (*cur == '\r'))) {
198 cur++;
199 } else {
200 /* skip over continuation bytes */
201 while ((cur < input->cur) && ((*cur & 0xC0) == 0x80))
202 cur++;
203 }
204 /* calculate the error position in terms of the current position */
205 col = input->cur - cur;
206 /* search forward for end-of-line (to max buff size) */
207 n = 0;
208 start = cur;
209 /* copy selected text to our buffer */
210 while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) {
211 int len = input->end - cur;
212 int c = xmlGetUTF8Char(cur, &len);
213
214 if ((c < 0) || (n + len > sizeof(content)-1))
215 break;
216 cur += len;
217 n += len;
218 }
220 content[n] = 0;
221 /* print out the selected text */
222 channel(data ,"%s\n", content);
223 /* create blank line with problem pointer */
224 n = 0;
225 ctnt = content;
226 /* (leave buffer space for pointer + line terminator) */
227 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
228 if (*(ctnt) != '\t')
229 *(ctnt) = ' ';
230 ctnt++;
231 }
232 *ctnt++ = '^';
233 *ctnt = 0;
234 channel(data ,"%s\n", content);
235}
content
Definition: atl_ax.c:994
FxCollectionEntry * cur
GLuint start
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
const GLubyte * c
Definition: glext.h:8905
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
XMLPUBFUN int XMLPUBFUN int XMLPUBFUN int xmlGetUTF8Char(const unsigned char *utf, int *len)
Definition: xmlstring.c:708
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlParserPrintFileContext(), and xmlReportError().

◆ xmlParserPrintFileInfo()

void xmlParserPrintFileInfo ( xmlParserInputPtr  input)

xmlParserPrintFileInfo: @input: an xmlParserInputPtr input

Displays the associated file and line information for the current input

Definition at line 154 of file error.c.

154 {
155 if (input != NULL) {
156 if (input->filename)
158 "%s:%d: ", input->filename,
159 input->line);
160 else
162 "Entity: line %d: ", input->line);
163 }
164}

◆ xmlReportError()

static void xmlReportError ( xmlErrorPtr  err,
xmlParserCtxtPtr  ctxt,
const char str,
xmlGenericErrorFunc  channel,
void data 
)
static

xmlReportError: @err: the error @ctx: the parser context or NULL @str: the formatted error message

Report an error with its context, replace the 4 old error/warning routines.

Definition at line 259 of file error.c.

261{
262 char *file = NULL;
263 int line = 0;
264 int code = -1;
265 int domain;
266 const xmlChar *name = NULL;
267 xmlNodePtr node;
269 xmlParserInputPtr input = NULL;
270 xmlParserInputPtr cur = NULL;
271
272 if (err == NULL)
273 return;
274
275 if (channel == NULL) {
276 channel = xmlGenericError;
278 }
279 file = err->file;
280 line = err->line;
281 code = err->code;
282 domain = err->domain;
283 level = err->level;
284 node = err->node;
285
286 if (code == XML_ERR_OK)
287 return;
288
289 if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
290 name = node->name;
291
292 /*
293 * Maintain the compatibility with the legacy error handling
294 */
295 if (ctxt != NULL) {
296 input = ctxt->input;
297 if ((input != NULL) && (input->filename == NULL) &&
298 (ctxt->inputNr > 1)) {
299 cur = input;
300 input = ctxt->inputTab[ctxt->inputNr - 2];
301 }
302 if (input != NULL) {
303 if (input->filename)
304 channel(data, "%s:%d: ", input->filename, input->line);
305 else if ((line != 0) && (domain == XML_FROM_PARSER))
306 channel(data, "Entity: line %d: ", input->line);
307 }
308 } else {
309 if (file != NULL)
310 channel(data, "%s:%d: ", file, line);
311 else if ((line != 0) &&
315 channel(data, "Entity: line %d: ", line);
316 }
317 if (name != NULL) {
318 channel(data, "element %s: ", name);
319 }
320 switch (domain) {
321 case XML_FROM_PARSER:
322 channel(data, "parser ");
323 break;
325 channel(data, "namespace ");
326 break;
327 case XML_FROM_DTD:
328 case XML_FROM_VALID:
329 channel(data, "validity ");
330 break;
331 case XML_FROM_HTML:
332 channel(data, "HTML parser ");
333 break;
334 case XML_FROM_MEMORY:
335 channel(data, "memory ");
336 break;
337 case XML_FROM_OUTPUT:
338 channel(data, "output ");
339 break;
340 case XML_FROM_IO:
341 channel(data, "I/O ");
342 break;
344 channel(data, "XInclude ");
345 break;
346 case XML_FROM_XPATH:
347 channel(data, "XPath ");
348 break;
350 channel(data, "parser ");
351 break;
352 case XML_FROM_REGEXP:
353 channel(data, "regexp ");
354 break;
355 case XML_FROM_MODULE:
356 channel(data, "module ");
357 break;
359 channel(data, "Schemas validity ");
360 break;
362 channel(data, "Schemas parser ");
363 break;
365 channel(data, "Relax-NG parser ");
366 break;
368 channel(data, "Relax-NG validity ");
369 break;
370 case XML_FROM_CATALOG:
371 channel(data, "Catalog ");
372 break;
373 case XML_FROM_C14N:
374 channel(data, "C14N ");
375 break;
376 case XML_FROM_XSLT:
377 channel(data, "XSLT ");
378 break;
379 case XML_FROM_I18N:
380 channel(data, "encoding ");
381 break;
383 channel(data, "schematron ");
384 break;
385 case XML_FROM_BUFFER:
386 channel(data, "internal buffer ");
387 break;
388 case XML_FROM_URI:
389 channel(data, "URI ");
390 break;
391 default:
392 break;
393 }
394 switch (level) {
395 case XML_ERR_NONE:
396 channel(data, ": ");
397 break;
398 case XML_ERR_WARNING:
399 channel(data, "warning : ");
400 break;
401 case XML_ERR_ERROR:
402 channel(data, "error : ");
403 break;
404 case XML_ERR_FATAL:
405 channel(data, "error : ");
406 break;
407 }
408 if (str != NULL) {
409 int len;
410 len = xmlStrlen((const xmlChar *)str);
411 if ((len > 0) && (str[len - 1] != '\n'))
412 channel(data, "%s\n", str);
413 else
414 channel(data, "%s", str);
415 } else {
416 channel(data, "%s\n", "out of memory error");
417 }
418
419 if (ctxt != NULL) {
421 if (cur != NULL) {
422 if (cur->filename)
423 channel(data, "%s:%d: \n", cur->filename, cur->line);
424 else if ((line != 0) && (domain == XML_FROM_PARSER))
425 channel(data, "Entity: line %d: \n", cur->line);
427 }
428 }
429 if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
430 (err->int1 < 100) &&
431 (err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
432 xmlChar buf[150];
433 int i;
434
435 channel(data, "%s\n", err->str1);
436 for (i=0;i < err->int1;i++)
437 buf[i] = ' ';
438 buf[i++] = '^';
439 buf[i] = 0;
440 channel(data, "%s\n", buf);
441 }
442}
GLint level
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define err(...)
const WCHAR * str
Definition: inflate.c:139
Definition: cookie.c:42
Definition: fci.c:127
Definition: parser.c:49
Definition: name.c:39
Definition: dlist.c:348
xmlErrorLevel
Definition: xmlerror.h:24
@ XML_ERR_WARNING
Definition: xmlerror.h:26
@ XML_ERR_ERROR
Definition: xmlerror.h:27
@ XML_ERR_NONE
Definition: xmlerror.h:25
@ XML_ERR_FATAL
Definition: xmlerror.h:28
@ XML_FROM_PARSER
Definition: xmlerror.h:38
@ XML_FROM_XPOINTER
Definition: xmlerror.h:50
@ XML_FROM_SCHEMASP
Definition: xmlerror.h:53
@ XML_FROM_REGEXP
Definition: xmlerror.h:51
@ XML_FROM_CATALOG
Definition: xmlerror.h:57
@ XML_FROM_SCHEMASV
Definition: xmlerror.h:54
@ XML_FROM_MODULE
Definition: xmlerror.h:63
@ XML_FROM_URI
Definition: xmlerror.h:67
@ XML_FROM_IO
Definition: xmlerror.h:45
@ XML_FROM_VALID
Definition: xmlerror.h:60
@ XML_FROM_MEMORY
Definition: xmlerror.h:43
@ XML_FROM_BUFFER
Definition: xmlerror.h:66
@ XML_FROM_XPATH
Definition: xmlerror.h:49
@ XML_FROM_OUTPUT
Definition: xmlerror.h:44
@ XML_FROM_HTML
Definition: xmlerror.h:42
@ XML_FROM_NAMESPACE
Definition: xmlerror.h:40
@ XML_FROM_XSLT
Definition: xmlerror.h:59
@ XML_FROM_SCHEMATRONV
Definition: xmlerror.h:65
@ XML_FROM_RELAXNGV
Definition: xmlerror.h:56
@ XML_FROM_RELAXNGP
Definition: xmlerror.h:55
@ XML_FROM_XINCLUDE
Definition: xmlerror.h:48
@ XML_FROM_C14N
Definition: xmlerror.h:58
@ XML_FROM_I18N
Definition: xmlerror.h:64
@ XML_FROM_DTD
Definition: xmlerror.h:41
@ XML_ERR_OK
Definition: xmlerror.h:100
XMLPUBFUN int xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:428

◆ xmlSetGenericErrorFunc()

void xmlSetGenericErrorFunc ( void ctx,
xmlGenericErrorFunc  handler 
)

xmlSetGenericErrorFunc: @ctx: the new error handling context @handler: the new handler function

Function to reset the handler and the error context for out of context error messages. This simply means that @handler will be called for subsequent error messages while not parsing nor validating. And @ctx will be passed as first argument to @handler One can simply force messages to be emitted to another FILE * than stderr by setting @ctx to this file handle and @handler to NULL. For multi-threaded applications, this must be set separately for each thread.

Definition at line 114 of file error.c.

◆ xmlSetStructuredErrorFunc()

void xmlSetStructuredErrorFunc ( void ctx,
xmlStructuredErrorFunc  handler 
)

xmlSetStructuredErrorFunc: @ctx: the new error handling context @handler: the new handler function

Function to reset the handler and the error context for out of context structured error messages. This simply means that @handler will be called for subsequent error messages while not parsing nor validating. And @ctx will be passed as first argument to @handler For multi-threaded applications, this must be set separately for each thread.

Definition at line 135 of file error.c.

135 {
138}
void * xmlStructuredErrorContext
Definition: globals.c:417
xmlStructuredErrorFunc xmlStructuredError
Definition: globals.c:403