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