Happy new year
[yaz-moved-to-github.git] / src / xmlerror.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data
3  * See the file LICENSE for details.
4  */
5 /** \file
6     \brief Log XML / XSLT Errors via yaz_log
7 */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <assert.h>
15 #include <yaz/log.h>
16 #include <yaz/snprintf.h>
17
18 #if YAZ_HAVE_XML2
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
21 #endif
22 #if YAZ_HAVE_XSLT
23 #include <libxslt/xsltutils.h>
24 #endif
25
26 static int xml_error_log_level = YLOG_WARN;
27
28 #if YAZ_HAVE_XML2
29 static void xml_error_handler(void *ctx, const char *fmt, ...)
30 {
31     char buf[1024];
32     const char *prefix = (const char *) ctx;
33
34     va_list ap;
35     va_start(ap, fmt);
36
37     yaz_vsnprintf(buf, sizeof(buf), fmt, ap);
38     yaz_log(xml_error_log_level, "%s: %s", prefix, buf);
39
40     va_end (ap);
41 }
42 #endif
43
44 void yaz_log_xml_errors(const char *prefix, int log_level)
45 {
46     xml_error_log_level = log_level;
47     
48 #if YAZ_HAVE_XML2
49     xmlSetGenericErrorFunc((void *) (prefix ? prefix : "XML"),
50                            xml_error_handler);
51 #if YAZ_HAVE_XSLT 
52     xsltSetGenericErrorFunc((void *) (prefix ? prefix : "XSLT"),
53                             xml_error_handler);
54 #endif
55 #endif
56 }
57
58 /*
59  * Local variables:
60  * c-basic-offset: 4
61  * c-file-style: "Stroustrup"
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66