Update headers and omit CVS Ids.
[yaz-moved-to-github.git] / src / libxml2_error.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file libxml2_error.c
7  * \brief Libxml2 error handling
8  */
9
10 #include <stdlib.h>
11 #include <stdarg.h>
12 #include <yaz/log.h>
13 #include <yaz/snprintf.h>
14 #include <yaz/libxml2_error.h>
15
16 #if YAZ_HAVE_XML2
17 #include <libxml/xmlerror.h>
18 #endif
19
20 #if YAZ_HAVE_XSLT
21 #include <libxslt/xsltutils.h>
22 #endif
23
24 static int libxml2_error_level = 0;
25
26 static void proxy_xml_error_handler(void *ctx, const char *fmt, ...)
27 {
28     char buf[1024];
29
30     va_list ap;
31     va_start(ap, fmt);
32
33     yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap);
34     yaz_log(libxml2_error_level, "%s: %s", (char*) ctx, buf);
35
36     va_end (ap);
37 }
38
39 int libxml2_error_to_yazlog(int level, const char *lead_msg)
40 {
41     libxml2_error_level = level;
42 #if YAZ_HAVE_XSLT
43     xsltSetGenericErrorFunc((void *) "XSLT", proxy_xml_error_handler);
44 #endif
45 #if YAZ_HAVE_XML2
46     xmlSetGenericErrorFunc((void *) "XML", proxy_xml_error_handler);
47     return 0;
48 #else
49     return -1;
50 #endif
51 }
52
53 /*
54  * Local variables:
55  * c-basic-offset: 4
56  * indent-tabs-mode: nil
57  * End:
58  * vim: shiftwidth=4 tabstop=8 expandtab
59  */
60