From: Adam Dickmeiss Date: Mon, 8 May 2006 10:16:46 +0000 (+0000) Subject: LibEXSLT support. New configure option --with-exslt. X-Git-Tag: YAZ.2.1.20~60 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=0b20fc2dcafe8d56501a3b34626b3174c60eefb5;p=yaz-moved-to-github.git LibEXSLT support. New configure option --with-exslt. --- diff --git a/configure.ac b/configure.ac index d55af6f..c2820e4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2006 dnl See the file LICENSE for details. -dnl $Id: configure.ac,v 1.10 2006-05-03 12:02:23 adam Exp $ +dnl $Id: configure.ac,v 1.11 2006-05-08 10:16:46 adam Exp $ AC_PREREQ(2.59) AC_INIT([yaz],[2.1.19],[adam@indexdata.dk]) AC_CONFIG_SRCDIR(configure.ac) @@ -317,46 +317,135 @@ if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then LIBS="$OLIBS $LIBTHREAD" fi -dnl ----- libXSLT -AC_SUBST(XSLT_CFLAGS) +dnl ----- libXSLT/libEXLT/libXML2 AC_SUBST(XML2_CFLAGS) + +xml2dir=default +AC_ARG_WITH(xml2,[[ --with-xml2[=PREFIX] use libxml2 in PREFIX]],xml2dir=$withval) +dnl -- if no PREFIX or not specified we just search in default locations +dnl -- try pkg-config. If not found, use xml2-config +if test "$xml2dir" = "yes" -o "$xml2dir" = "default"; then + if test "$pkgconfigpath" != "NONE"; then + if $pkgconfigpath --exists libxml-2.0; then + pkgmodule="libxml-2.0" + fi + fi + if test -z "$pkgmodule"; then + for d in /usr /usr/local; do + if test -x $d/bin/xml2-config; then + xml2dir=$d + fi + done + fi +fi +dnl --- do the real check (pkg-config, xml2-config, not-found) +if test "$xml2dir" != "no"; then + AC_MSG_CHECKING(for libXML2) + if test "$pkgmodule"; then + XML2_LIBS=`$pkgconfigpath --libs $pkgmodule` + XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule` + XML2_VER=`$pkgconfigpath --modversion $pkgmodule` + AC_MSG_RESULT($XML2_VER) + AC_DEFINE(HAVE_XML2) + elif test -x $xml2dir/bin/xml2-config; then + XML2_LIBS=`$xml2dir/bin/xml2-config --libs` + XML2_CFLAGS=`$xml2dir/bin/xml2-config --cflags` + XML2_VER=`$xml2dir/bin/xml2-config --version` + AC_MSG_RESULT($XML2_VER) + AC_DEFINE(HAVE_XML2) + else + AC_MSG_RESULT(Not found) + + if test "$xml2dir" = "default"; then + AC_MSG_WARN([libxml2 development libraries not found.]) + AC_MSG_WARN([YAZ will NOT support SRU.]) + else + AC_MSG_ERROR([libxml2 development libraries not found.]) + fi + fi +fi + +dnl ----- libXSLT xsltdir=default -AC_ARG_WITH(xslt,[[ --with-xslt[=PREFIX] use libxslt in PREFIX]],xsltdir=$withval) +pkgmodule="" +AC_ARG_WITH(xslt,[[ --with-xslt[=PREFIX] use libXSLT in PREFIX]],xsltdir=$withval) + +dnl -- if no PREFIX or not specified we just search in default locations +dnl -- try pkg-config. If not found, use xslt-config if test "$xsltdir" = "yes" -o "$xsltdir" = "default"; then - for d in /usr /usr/local; do - if test -x $d/bin/xslt-config; then - xsltdir=$d + if test "$pkgconfigpath" != "NONE"; then + if $pkgconfigpath --exists libxslt; then + pkgmodule="libxslt" fi - done + fi + if test -z "$pkgmodule"; then + for d in /usr /usr/local; do + if test -x $d/bin/xslt-config; then + xsltdir=$d + fi + done + fi fi +dnl --- do the real check (pkg-config, xslt-config, not-found) if test "$xsltdir" != "no"; then AC_MSG_CHECKING(for libXSLT) - if test -x $xsltdir/bin/xslt-config; then - XSLT_LIBS=`$xsltdir/bin/xslt-config --libs` - XSLT_CFLAGS=`$xsltdir/bin/xslt-config --cflags` - XML2_CFLAGS=$XSLT_CFLAGS + if test "$pkgmodule"; then + XML2_LIBS=`$pkgconfigpath --libs $pkgmodule` + XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule` + XSLT_VER=`$pkgconfigpath --modversion $pkgmodule` + AC_MSG_RESULT($XSLT_VER) + AC_DEFINE(HAVE_XSLT) + elif test -x $xsltdir/bin/xslt-config; then + XML2_LIBS=`$xsltdir/bin/xslt-config --libs` + XML2_CFLAGS=`$xsltdir/bin/xslt-config --cflags` XSLT_VER=`$xsltdir/bin/xslt-config --version` - LIBS="$XSLT_LIBS $LIBS" AC_MSG_RESULT($XSLT_VER) AC_DEFINE(HAVE_XSLT) - AC_DEFINE(HAVE_XML2) else AC_MSG_RESULT(Not found) if test "$xsltdir" = "default"; then - AC_MSG_WARN([libxslt development libraries not found.]) - AC_MSG_WARN([YAZ will NOT support SRU.]) + AC_MSG_WARN([libXSLT development libraries not found.]) else - AC_MSG_ERROR([libxslt development libraries not found.]) + AC_MSG_ERROR([libXSLT development libraries not found.]) fi fi fi -xml2dir=default -AC_ARG_WITH(xml2,[[ --with-xml2[=PREFIX] OBSOLETE. Use --with-xslt instead]],xml2dir=$withval) -if test "$xml2dir" != "default"; then - AC_MSG_ERROR([--with-xml2 OBSOLETE. Use --with-xslt instead.]) +dnl -- get libEXSLT. xslt-config is no good. So use pkg-config only +exsltdir=default +pkgmodule="" +AC_ARG_WITH(exslt,[[ --with-exslt[=PREFIX] use libEXSLT in PREFIX]],exsltdir=$withval) +if test "$exsltdir" = "yes" -o "$exsltdir" = "default"; then + if test "$pkgconfigpath" != "NONE"; then + if $pkgconfigpath --exists libexslt; then + pkgmodule="libexslt" + fi + fi fi +if test "$exsltdir" != "no"; then + AC_MSG_CHECKING(for libEXSLT) + if test "$pkgmodule"; then + XML2_LIBS=`$pkgconfigpath --libs $pkgmodule` + XML2_CFLAGS=`$pkgconfigpath --cflags $pkgmodule` + EXSLT_VER=`$pkgconfigpath --modversion $pkgmodule` + AC_MSG_RESULT($EXSLT_VER) + AC_DEFINE(HAVE_EXSLT) + else + AC_MSG_RESULT(Not found) + + if test "$exsltdir" = "default"; then + AC_MSG_WARN([libEXSLT development libraries not found.]) + else + AC_MSG_ERROR([libEXSLT development libraries not found.]) + fi + fi +fi + +if test "$XML2_LIBS"; then + LIBS="$XML2_LIBS $LIBS" +fi + dnl dnl ------ Memory debugging AC_ARG_ENABLE(memdebug, [ --enable-memdebug enable memory debugging],[enable_memdebug=$enableval],[enable_memdebug=none]) diff --git a/src/record_conv.c b/src/record_conv.c index 8c00ebb..9cb2e4c 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: record_conv.c,v 1.6 2006-05-07 17:45:41 adam Exp $ + * $Id: record_conv.c,v 1.7 2006-05-08 10:16:47 adam Exp $ */ /** * \file record_conv.c @@ -22,12 +22,17 @@ #include #include -#if HAVE_XSLT +#if HAVE_XML2 #include #include #include +#if HAVE_XSLT #include #include +#endif +#if HAVE_EXSLT +#include +#endif /** \brief The internal structure for yaz_record_conv_t */ struct yaz_record_conv_struct { @@ -59,10 +64,11 @@ enum YAZ_RECORD_CONV_RULE struct yaz_record_conv_rule { enum YAZ_RECORD_CONV_RULE which; union { +#if HAVE_XSLT struct { xsltStylesheetPtr xsp; - int dummy; } xslt; +#endif struct { yaz_iconv_t iconv_t; int input_format; @@ -83,10 +89,12 @@ static void yaz_record_conv_reset(yaz_record_conv_t p) if (r->u.marc.iconv_t) yaz_iconv_close(r->u.marc.iconv_t); } +#if HAVE_XSLT else if (r->which == YAZ_RECORD_CONV_RULE_XSLT) { xsltFreeStylesheet(r->u.xslt.xsp); } +#endif } wrbuf_rewind(p->wr_error); nmem_reset(p->nmem); @@ -104,6 +112,9 @@ yaz_record_conv_t yaz_record_conv_create() p->rules = 0; p->path = 0; +#if HAVE_EXSLT + exsltDynRegister(); +#endif yaz_record_conv_reset(p); return p; } @@ -135,6 +146,7 @@ static struct yaz_record_conv_rule *add_rule(yaz_record_conv_t p, /** \brief parse 'xslt' conversion node */ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) { +#if HAVE_XSLT struct _xmlAttr *attr; const char *stylesheet = 0; @@ -179,6 +191,11 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr) } } return 0; +#else + wrbuf_printf(p->wr_error, "xslt unsupported." + " YAZ compiled without XSLT support"); + return -1; +#endif } /** \brief parse 'marc' conversion node */ @@ -315,6 +332,17 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const void *ptr_v) if (conv_xslt(p, ptr)) return -1; } + else if (!strcmp((const char *) ptr->name, "exslt")) + { +#if HAVE_EXSLT + if (conv_xslt(p, ptr)) + return -1; +#else + wrbuf_printf(p->wr_error, "exslt unsupported." + " YAZ compiled without EXSLT support"); + return -1; +#endif + } else if (!strcmp((const char *) ptr->name, "marc")) { if (conv_marc(p, ptr)) @@ -349,39 +377,7 @@ int yaz_record_conv_record(yaz_record_conv_t p, wrbuf_write(record, input_record_buf, input_record_len); for (; ret == 0 && r; r = r->next) { - if (r->which == YAZ_RECORD_CONV_RULE_XSLT) - { - xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record), - wrbuf_len(record)); - if (!doc) - { - wrbuf_printf(p->wr_error, "xmlParseMemory failed"); - ret = -1; - } - else - { - xmlDocPtr res = xsltApplyStylesheet(r->u.xslt.xsp, doc, 0); - if (res) - { - xmlChar *out_buf; - int out_len; - xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1); - - wrbuf_rewind(record); - wrbuf_write(record, (const char *) out_buf, out_len); - - xmlFree(out_buf); - xmlFreeDoc(res); - } - else - { - wrbuf_printf(p->wr_error, "xsltApplyStylesheet faailed"); - ret = -1; - } - xmlFreeDoc(doc); - } - } - else if (r->which == YAZ_RECORD_CONV_RULE_MARC) + if (r->which == YAZ_RECORD_CONV_RULE_MARC) { yaz_marc_t mt = yaz_marc_create(); @@ -429,6 +425,40 @@ int yaz_record_conv_record(yaz_record_conv_t p, } yaz_marc_destroy(mt); } +#if HAVE_XSLT + else if (r->which == YAZ_RECORD_CONV_RULE_XSLT) + { + xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record), + wrbuf_len(record)); + if (!doc) + { + wrbuf_printf(p->wr_error, "xmlParseMemory failed"); + ret = -1; + } + else + { + xmlDocPtr res = xsltApplyStylesheet(r->u.xslt.xsp, doc, 0); + if (res) + { + xmlChar *out_buf; + int out_len; + xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1); + + wrbuf_rewind(record); + wrbuf_write(record, (const char *) out_buf, out_len); + + xmlFree(out_buf); + xmlFreeDoc(res); + } + else + { + wrbuf_printf(p->wr_error, "xsltApplyStylesheet faailed"); + ret = -1; + } + xmlFreeDoc(doc); + } + } +#endif } return ret; } diff --git a/src/retrieval.c b/src/retrieval.c index 3ca6d8d..af13ae9 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: retrieval.c,v 1.4 2006-05-07 17:45:41 adam Exp $ + * $Id: retrieval.c,v 1.5 2006-05-08 10:16:47 adam Exp $ */ /** * \file retrieval.c @@ -21,12 +21,10 @@ #include #include -#if HAVE_XSLT +#if HAVE_XML2 #include #include #include -#include -#include /** \brief The internal structure for yaz_retrieval_t */ struct yaz_retrieval_struct { diff --git a/src/seshigh.c b/src/seshigh.c index 6112316..d355260 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.77 2006-05-07 14:48:25 adam Exp $ + * $Id: seshigh.c,v 1.78 2006-05-08 10:16:47 adam Exp $ */ /** * \file seshigh.c @@ -577,7 +577,7 @@ static void set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem) static int retrieve_fetch(association *assoc, bend_fetch_rr *rr) { -#if HAVE_XSLT +#if HAVE_XML2 yaz_record_conv_t rc = 0; const char *match_schema = 0; int *match_syntax = 0; @@ -2241,7 +2241,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.77 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.78 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, diff --git a/src/statserv.c b/src/statserv.c index 94382c7..1735314 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -5,7 +5,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.37 2006-05-07 14:48:25 adam Exp $ + * $Id: statserv.c,v 1.38 2006-05-08 10:16:47 adam Exp $ */ /** @@ -222,7 +222,7 @@ static struct gfs_server * gfs_server_new() n->directory = 0; n->docpath = 0; n->stylesheet = 0; -#if HAVE_XSLT +#if HAVE_XML2 n->retrieval = yaz_retrieval_create(); #endif return n; diff --git a/test/tst_record_conv.c b/test/tst_record_conv.c index c4f09c4..7846373 100644 --- a/test/tst_record_conv.c +++ b/test/tst_record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_record_conv.c,v 1.7 2006-05-07 17:45:41 adam Exp $ + * $Id: tst_record_conv.c,v 1.8 2006-05-08 10:16:47 adam Exp $ * */ #include @@ -16,7 +16,7 @@ #include #endif -#if HAVE_XSLT +#if HAVE_XML2 #include #include @@ -113,6 +113,7 @@ static void tst_configure() YAZ_CHECK(conv_configure_test("", "Bad element 'bad'." "Expected marc, xslt, ..", 0)); +#if HAVE_XSLT YAZ_CHECK(conv_configure_test("" "" "" "", 0, 0)); +#else + YAZ_CHECK(conv_configure_test("" + "" + "", + "xslt unsupported." + " YAZ compiled without XSLT support", 0)); +#endif } static int conv_convert_test(yaz_record_conv_t p, @@ -287,8 +295,10 @@ int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); libxml2_error_to_yazlog(0 /* disable log */, 0); -#if HAVE_XSLT +#if HAVE_XML2 tst_configure(); +#endif +#if HAVE_XSLT tst_convert(); #endif YAZ_CHECK_TERM;