ReactOS 0.4.15-dev-5669-g09dde2c
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 <libxml/globals.h>
Include dependency graph for error.c:

Go to the source code of this file.

Macros

#define IN_LIBXML
 
#define XML_GET_VAR_STR(msg, str)
 

Functions

void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg,...) LIBXML_ATTR_FORMAT(2
 
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 23 of file error.c.

Function Documentation

◆ initGenericErrorDefaultFunc()

void initGenericErrorDefaultFunc ( xmlGenericErrorFunc handler)

initGenericErrorDefaultFunc: @handler: the handler

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

Definition at line 90 of file error.c.

91{
92 if (handler == NULL)
94 else
95 xmlGenericError = (*handler);
96}
#define NULL
Definition: types.h:112
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg,...) LIBXML_ATTR_FORMAT(2
Definition: error.c:71

Referenced by xmlInitParser().

◆ xmlGenericErrorDefaultFunc()

void XMLCDECL 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 71 of file error.c.

71 {
73
76
79 va_end(args);
80}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define msg(x)
Definition: auth_time.c:54
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
#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 230 of file error.c.

230 {
233}
GLenum GLenum GLenum input
Definition: glext.h:9031
static void xmlParserPrintFileContextInternal(xmlParserInputPtr input, xmlGenericErrorFunc channel, void *data)
Definition: error.c:173

◆ xmlParserPrintFileContextInternal()

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

xmlParserPrintFileContext: @input: an xmlParserInputPtr input

Displays current context within the input content for error tracking

Definition at line 173 of file error.c.

174 {
175 const xmlChar *cur, *base;
176 unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
177 xmlChar content[81]; /* space for 80 chars + line terminator */
178 xmlChar *ctnt;
179
180 if ((input == NULL) || (input->cur == NULL))
181 return;
182
183 cur = input->cur;
184 base = input->base;
185 /* skip backwards over any end-of-lines */
186 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
187 cur--;
188 }
189 n = 0;
190 /* search backwards for beginning-of-line (to max buff size) */
191 while ((n++ < (sizeof(content)-1)) && (cur > base) &&
192 (*(cur) != '\n') && (*(cur) != '\r'))
193 cur--;
194 if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
195 /* calculate the error position in terms of the current position */
196 col = input->cur - cur;
197 /* search forward for end-of-line (to max buff size) */
198 n = 0;
199 ctnt = content;
200 /* copy selected text to our buffer */
201 while ((*cur != 0) && (*(cur) != '\n') &&
202 (*(cur) != '\r') && (n < sizeof(content)-1)) {
203 *ctnt++ = *cur++;
204 n++;
205 }
206 *ctnt = 0;
207 /* print out the selected text */
208 channel(data ,"%s\n", content);
209 /* create blank line with problem pointer */
210 n = 0;
211 ctnt = content;
212 /* (leave buffer space for pointer + line terminator) */
213 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
214 if (*(ctnt) != '\t')
215 *(ctnt) = ' ';
216 ctnt++;
217 }
218 *ctnt++ = '^';
219 *ctnt = 0;
220 channel(data ,"%s\n", content);
221}
content
Definition: atl_ax.c:994
FxCollectionEntry * cur
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
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 153 of file error.c.

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

◆ 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 245 of file error.c.

247{
248 char *file = NULL;
249 int line = 0;
250 int code = -1;
251 int domain;
252 const xmlChar *name = NULL;
257
258 if (err == NULL)
259 return;
260
261 if (channel == NULL) {
262 channel = xmlGenericError;
264 }
265 file = err->file;
266 line = err->line;
267 code = err->code;
268 domain = err->domain;
269 level = err->level;
270 node = err->node;
271
272 if (code == XML_ERR_OK)
273 return;
274
275 if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
276 name = node->name;
277
278 /*
279 * Maintain the compatibility with the legacy error handling
280 */
281 if (ctxt != NULL) {
282 input = ctxt->input;
283 if ((input != NULL) && (input->filename == NULL) &&
284 (ctxt->inputNr > 1)) {
285 cur = input;
286 input = ctxt->inputTab[ctxt->inputNr - 2];
287 }
288 if (input != NULL) {
289 if (input->filename)
290 channel(data, "%s:%d: ", input->filename, input->line);
291 else if ((line != 0) && (domain == XML_FROM_PARSER))
292 channel(data, "Entity: line %d: ", input->line);
293 }
294 } else {
295 if (file != NULL)
296 channel(data, "%s:%d: ", file, line);
297 else if ((line != 0) &&
301 channel(data, "Entity: line %d: ", line);
302 }
303 if (name != NULL) {
304 channel(data, "element %s: ", name);
305 }
306 switch (domain) {
307 case XML_FROM_PARSER:
308 channel(data, "parser ");
309 break;
311 channel(data, "namespace ");
312 break;
313 case XML_FROM_DTD:
314 case XML_FROM_VALID:
315 channel(data, "validity ");
316 break;
317 case XML_FROM_HTML:
318 channel(data, "HTML parser ");
319 break;
320 case XML_FROM_MEMORY:
321 channel(data, "memory ");
322 break;
323 case XML_FROM_OUTPUT:
324 channel(data, "output ");
325 break;
326 case XML_FROM_IO:
327 channel(data, "I/O ");
328 break;
330 channel(data, "XInclude ");
331 break;
332 case XML_FROM_XPATH:
333 channel(data, "XPath ");
334 break;
336 channel(data, "parser ");
337 break;
338 case XML_FROM_REGEXP:
339 channel(data, "regexp ");
340 break;
341 case XML_FROM_MODULE:
342 channel(data, "module ");
343 break;
345 channel(data, "Schemas validity ");
346 break;
348 channel(data, "Schemas parser ");
349 break;
351 channel(data, "Relax-NG parser ");
352 break;
354 channel(data, "Relax-NG validity ");
355 break;
356 case XML_FROM_CATALOG:
357 channel(data, "Catalog ");
358 break;
359 case XML_FROM_C14N:
360 channel(data, "C14N ");
361 break;
362 case XML_FROM_XSLT:
363 channel(data, "XSLT ");
364 break;
365 case XML_FROM_I18N:
366 channel(data, "encoding ");
367 break;
369 channel(data, "schematron ");
370 break;
371 case XML_FROM_BUFFER:
372 channel(data, "internal buffer ");
373 break;
374 case XML_FROM_URI:
375 channel(data, "URI ");
376 break;
377 default:
378 break;
379 }
380 switch (level) {
381 case XML_ERR_NONE:
382 channel(data, ": ");
383 break;
384 case XML_ERR_WARNING:
385 channel(data, "warning : ");
386 break;
387 case XML_ERR_ERROR:
388 channel(data, "error : ");
389 break;
390 case XML_ERR_FATAL:
391 channel(data, "error : ");
392 break;
393 }
394 if (str != NULL) {
395 int len;
396 len = xmlStrlen((const xmlChar *)str);
397 if ((len > 0) && (str[len - 1] != '\n'))
398 channel(data, "%s\n", str);
399 else
400 channel(data, "%s", str);
401 } else {
402 channel(data, "%s\n", "out of memory error");
403 }
404
405 if (ctxt != NULL) {
407 if (cur != NULL) {
408 if (cur->filename)
409 channel(data, "%s:%d: \n", cur->filename, cur->line);
410 else if ((line != 0) && (domain == XML_FROM_PARSER))
411 channel(data, "Entity: line %d: \n", cur->line);
413 }
414 }
415 if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
416 (err->int1 < 100) &&
417 (err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
418 xmlChar buf[150];
419 int i;
420
421 channel(data, "%s\n", err->str1);
422 for (i=0;i < err->int1;i++)
423 buf[i] = ' ';
424 buf[i++] = '^';
425 buf[i] = 0;
426 channel(data, "%s\n", buf);
427 }
428}
GLint level
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
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
@ XML_ELEMENT_NODE
Definition: tree.h:160
Definition: tree.h:489
xmlParserInputPtr * inputTab
Definition: parser.h:202
xmlParserInputPtr input
Definition: parser.h:199
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 XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426

◆ 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 113 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 134 of file error.c.

134 {
137}
XMLPUBVAR void * xmlStructuredErrorContext
Definition: globals.h:361
XMLPUBVAR xmlStructuredErrorFunc xmlStructuredError
Definition: globals.h:345