-## $Id: Makefile.am,v 1.30 2006-05-04 20:00:45 adam Exp $
+## $Id: Makefile.am,v 1.31 2006-05-07 17:45:41 adam Exp $
pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \
diagbib1.h diagsrw.h sortspec.h log.h logrpn.h marcdisp.h nfa.h \
readconf.h record_conv.h retrieval.h statserv.h \
tcpip.h test.h unix.h tpath.h wrbuf.h xmalloc.h \
yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \
- xmlquery.h \
+ xmlquery.h libxml2_error.h \
\
ill.h ill-core.h item-req.h z-accdes1.h z-accform1.h \
z-acckrb1.h z-core.h z-date.h z-diag1.h z-espec1.h z-estask.h z-exp.h \
--- /dev/null
+/*
+ * Copyright (C) 2006, Index Data ApS
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation, in whole or in part, for any purpose, is hereby granted,
+ * provided that:
+ *
+ * 1. This copyright and permission notice appear in all copies of the
+ * software and its documentation. Notices of copyright or attribution
+ * which appear at the beginning of any file must remain unchanged.
+ *
+ * 2. The name of Index Data or the individual authors may not be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
+ * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * $Id: libxml2_error.h,v 1.1 2006-05-07 17:45:41 adam Exp $
+ */
+
+/**
+ * \file libxml2_error.h
+ * \brief Libxml2 error handler
+ */
+
+#ifndef YAZ_LIBXML2_ERROR_H
+#define YAZ_LIBXML2_ERROR_H
+
+#include <stdio.h>
+#include <yaz/yconfig.h>
+
+YAZ_BEGIN_CDECL
+
+/** \brief direct Libxml2/Libxslt errors to yaz_log
+ \param level yaz_log level to use
+ \param lead_msg leading message (or NULL if none)
+ \retval 0 successful; libxml2 is present
+ \retval -1 failure; libxml2 is not present
+*/
+YAZ_EXPORT
+int libxml2_error_to_yazlog(int level, const char *lead_msg);
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
## This file is part of the YAZ toolkit.
## Copyright (C) 1994-2006, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.35 2006-05-04 20:00:45 adam Exp $
+## $Id: Makefile.am,v 1.36 2006-05-07 17:45:41 adam Exp $
YAZ_VERSION_INFO=2:1:0
odr_null.c ber_null.c odr_int.c ber_int.c odr_tag.c odr_cons.c \
odr_seq.c odr_oct.c ber_oct.c odr_bit.c ber_bit.c odr_oid.c \
ber_oid.c odr_use.c odr_choice.c odr_any.c ber_any.c odr.c odr_mem.c \
- dumpber.c odr_enum.c odr-priv.h \
+ dumpber.c odr_enum.c odr-priv.h libxml2_error.c \
comstack.c tcpip.c waislen.c unix.c \
z-accdes1.c z-accform1.c z-acckrb1.c z-core.c \
z-diag1.c z-espec1.c z-estask.c z-exp.c z-grs.c z-mterm2.c z-opac.c \
--- /dev/null
+/*
+ * Copyright (C) 2006, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: libxml2_error.c,v 1.1 2006-05-07 17:45:41 adam Exp $
+ */
+/**
+ * \file libxml2_error.c
+ * \brief Libxml2 error handling
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <yaz/log.h>
+#include <yaz/libxml2_error.h>
+
+#if HAVE_XML2
+#include <libxml/xmlerror.h>
+#endif
+
+#if HAVE_XSLT
+#include <libxslt/xsltutils.h>
+#endif
+
+static int libxml2_error_level = 0;
+
+static void proxy_xml_error_handler(void *ctx, const char *fmt, ...)
+{
+ char buf[1024];
+
+ va_list ap;
+ va_start(ap, fmt);
+
+#ifdef WIN32
+ vsprintf(buf, fmt, ap);
+#else
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+#endif
+ yaz_log(libxml2_error_level, "%s: %s", (char*) ctx, buf);
+
+ va_end (ap);
+}
+
+int libxml2_error_to_yazlog(int level, const char *lead_msg)
+{
+ libxml2_error_level = level;
+#if HAVE_XSLT
+ xsltSetGenericErrorFunc((void *) "XSLT", proxy_xml_error_handler);
+#endif
+#if HAVE_XML2
+ xmlSetGenericErrorFunc((void *) "XML", proxy_xml_error_handler);
+ return 0;
+#else
+ return -1;
+#endif
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
* Copyright (C) 2005-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: record_conv.c,v 1.5 2006-05-07 14:48:25 adam Exp $
+ * $Id: record_conv.c,v 1.6 2006-05-07 17:45:41 adam Exp $
*/
/**
* \file record_conv.c
stylesheet = (const char *) attr->children->content;
else
{
- wrbuf_printf(p->wr_error, "Bad attribute '%s'."
+ wrbuf_printf(p->wr_error, "Bad attribute '%s'"
"Expected stylesheet.", attr->name);
return -1;
}
output_format = (const char *) attr->children->content;
else
{
- wrbuf_printf(p->wr_error, "Bad attribute '%s'.", attr->name);
+ wrbuf_printf(p->wr_error, "Bad attribute '%s'", attr->name);
return -1;
}
}
else
{
wrbuf_printf(p->wr_error, "Bad element '%s'."
- "Expected marc, xslt, ..", ptr->name);
+ "Expected marc, xslt, ..", ptr->name);
return -1;
}
}
* Copyright (C) 2005-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
+ * $Id: retrieval.c,v 1.4 2006-05-07 17:45:41 adam Exp $
*/
/**
* \file retrieval.c
}
if (!el->syntax)
{
- wrbuf_printf(p->wr_error, "Missing 'syntax' attribute.", attr->name);
+ wrbuf_printf(p->wr_error, "Missing 'syntax' attribute");
return -1;
}
tstpquery
tst_filepath
tst_record_conv
+tst_retrieval
nfatest1
* Copyright (C) 2005-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tst_record_conv.c,v 1.6 2006-05-07 14:48:25 adam Exp $
+ * $Id: tst_record_conv.c,v 1.7 2006-05-07 17:45:41 adam Exp $
*
*/
#include <yaz/record_conv.h>
#include <yaz/test.h>
#include <yaz/wrbuf.h>
#include <string.h>
+#include <yaz/log.h>
+#include <yaz/libxml2_error.h>
#if HAVE_CONFIG_H
#include <config.h>
"</convert>",
"Attribute 'inputformat' required", 0));
YAZ_CHECK(conv_configure_test("<convert>"
+ "<xslt/>"
+ "</convert>",
+ "Missing attribute 'stylesheet'", 0));
+ YAZ_CHECK(conv_configure_test("<convert>"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
" inputcharset=\"utf-8\""
int main(int argc, char **argv)
{
YAZ_CHECK_INIT(argc, argv);
+ libxml2_error_to_yazlog(0 /* disable log */, 0);
#if HAVE_XSLT
tst_configure();
tst_convert();
* Copyright (C) 2005-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tst_retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
+ * $Id: tst_retrieval.c,v 1.4 2006-05-07 17:45:41 adam Exp $
*
*/
#include <yaz/retrieval.h>
#include <yaz/test.h>
#include <yaz/wrbuf.h>
#include <string.h>
+#include <yaz/log.h>
+#include <yaz/libxml2_error.h>
#if HAVE_CONFIG_H
#include <config.h>
" Expected 'retrieval'", 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
- "</retrievalinfo>", 0, 0));
+ "</retrievalinfo>",
+ "Missing 'syntax' attribute", 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval>\n"
+ "<retrieval syntax=\"usmarc\">\n"
" "
"<convert>"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
0, 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval>"
+ "<retrieval syntax=\"usmarc\">"
"<convert>"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
"/>"
"</convert>"
"</retrieval>"
- "<retrieval>"
+ "<retrieval syntax=\"usmarc\">"
"<convert>"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
int main(int argc, char **argv)
{
YAZ_CHECK_INIT(argc, argv);
+
+ libxml2_error_to_yazlog(0 /* disable it */, "");
+
#if HAVE_XSLT
tst_configure();
#endif