File: xmlerror.c

package info (click to toggle)
yaz 5.27.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,184 kB
  • sloc: xml: 123,414; ansic: 72,530; sh: 5,007; tcl: 2,169; makefile: 1,321; yacc: 382
file content (69 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* This file is part of the YAZ toolkit.
 * Copyright (C) Index Data
 * See the file LICENSE for details.
 */
/** \file
    \brief Log XML / XSLT Errors via yaz_log
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <yaz/log.h>
#include <yaz/snprintf.h>

#if YAZ_HAVE_XML2
#include <libxml/parser.h>
#include <libxml/tree.h>
#endif
#if YAZ_HAVE_XSLT
#include <libxslt/xsltutils.h>
#endif

static int xml_error_log_level = YLOG_WARN;

#if YAZ_HAVE_XML2
static void xml_error_handler(void *ctx, const char *fmt, ...)
{
    char buf[1024];
    const char *prefix = (const char *) ctx;

    va_list ap;
    va_start(ap, fmt);

    yaz_vsnprintf(buf, sizeof(buf), fmt, ap);
    size_t l = strlen(buf);
    if (l > 0 && buf[l-1] == '\n')
        buf[l-1] = '\0';
    yaz_log(xml_error_log_level, "%s: %s", prefix, buf);

    va_end (ap);
}
#endif

void yaz_log_xml_errors(const char *prefix, int log_level)
{
    xml_error_log_level = log_level;

#if YAZ_HAVE_XML2
    xmlSetGenericErrorFunc((void *) (prefix ? prefix : "XML"),
                           xml_error_handler);
#if YAZ_HAVE_XSLT
    xsltSetGenericErrorFunc((void *) (prefix ? prefix : "XSLT"),
                            xml_error_handler);
#endif
#endif
}

/*
 * Local variables:
 * c-basic-offset: 4
 * c-file-style: "Stroustrup"
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */