From: Adam Dickmeiss Date: Fri, 3 Dec 2004 14:28:18 +0000 (+0000) Subject: Added support for MARC record conversion with Usemarcon X-Git-Tag: YAZPROXY.0.9~20 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=af0d95244ac549130bd45c54620df98f636984db;p=yazproxy-moved-to-github.git Added support for MARC record conversion with Usemarcon --- diff --git a/Makefile.am b/Makefile.am index ca05423..16e47c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,8 +2,7 @@ AUTOMAKE_OPTIONS = foreign SUBDIRS = src include etc doc -EXTRA_DIST= README LICENSE yazpp.m4 yaz.m4 buildconf.sh - +EXTRA_DIST= README LICENSE yazpp.m4 yaz.m4 usemarcon.m4 buildconf.sh dist-hook: mkdir $(distdir)/win diff --git a/configure.in b/configure.in index b79e9a4..8a9a848 100644 --- a/configure.in +++ b/configure.in @@ -10,6 +10,7 @@ AM_PROG_LIBTOOL YAZPP_INIT(threads,1.0) YAZ_DOC +USEMARCON_INIT AC_CHECK_FUNCS(setrlimit getrlimit gettimeofday) dnl diff --git a/etc/Makefile.am b/etc/Makefile.am index 7904c47..3a58871 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.4 2004-11-09 14:24:22 adam Exp $ +# $Id: Makefile.am,v 1.5 2004-12-03 14:28:18 adam Exp $ proxydatadir=$(datadir)/yazproxy proxydata_DATA = \ @@ -11,6 +11,7 @@ proxydata_DATA = \ config.xml \ explain.xml \ voyager.xml \ + config-mafi2ma.xml \ pqf.properties \ yazproxy.xsd \ zeerex-2.0.xsd \ diff --git a/etc/config-mafi2ma.xml b/etc/config-mafi2ma.xml new file mode 100644 index 0000000..7e4c0e5 --- /dev/null +++ b/etc/config-mafi2ma.xml @@ -0,0 +1,40 @@ + + + + + + 193.166.7.193:7590 + 30 + 60 + + 1000000 + 1000 + + + 2000000 + 50 + 100 + + + + + + + + + 0 + + pqf.properties + + + 60 + 30 + + + 50 + client-requests server-requests + diff --git a/etc/yazproxy.xsd b/etc/yazproxy.xsd index 531a339..f447afc 100644 --- a/etc/yazproxy.xsd +++ b/etc/yazproxy.xsd @@ -1,6 +1,6 @@ + + diff --git a/include/yazproxy/proxy.h b/include/yazproxy/proxy.h index c9c64ee..9ddd94f 100644 --- a/include/yazproxy/proxy.h +++ b/include/yazproxy/proxy.h @@ -1,4 +1,4 @@ -/* $Id: proxy.h,v 1.8 2004-10-23 23:12:24 adam Exp $ +/* $Id: proxy.h,v 1.9 2004-12-03 14:28:18 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -19,6 +19,9 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifndef YAZ_PROXY_H_INCLUDED +#define YAZ_PROXY_H_INCLUDED + #include #include #include @@ -37,6 +40,7 @@ class Yaz_Proxy; struct Yaz_RecordCache_Entry; class Yaz_ProxyConfigP; +class Yaz_usemarcon; class YAZ_EXPORT Yaz_ProxyConfig { public: @@ -74,7 +78,9 @@ public: int check_syntax(ODR odr, const char *name, Odr_oid *syntax, Z_RecordComposition *comp, char **addinfo, char **stylesheet, char **schema, - char **backend_type, char **backend_charset); + char **backend_type, char **backend_charset, + char **usemarcon_ini_stage1, char **usemarcon_ini_stage2 + ); char *get_explain_doc(ODR odr, const char *name, const char *db, int *len); const char *get_explain_name(const char *db, const char **backend_db); @@ -259,6 +265,9 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { int m_lo_fd[NO_SPARE_SOLARIS_FD]; void low_socket_open(); void low_socket_close(); + char *m_usemarcon_ini_stage1; + char *m_usemarcon_ini_stage2; + Yaz_usemarcon *m_usemarcon; public: Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, Yaz_Proxy *parent = 0); @@ -291,3 +300,4 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { int handle_init_response_for_invalid_session(Z_APDU *apdu); }; +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 029f8c5..86142f9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,15 +1,16 @@ -## $Id: Makefile.am,v 1.2 2004-04-11 11:58:35 adam Exp $ +## $Id: Makefile.am,v 1.3 2004-12-03 14:28:18 adam Exp $ -AM_CXXFLAGS = $(YAZPPINC) -I$(srcdir)/../include $(XSLT_CFLAGS) +AM_CXXFLAGS = $(YAZPPINC) -I$(srcdir)/../include $(XSLT_CFLAGS) $(USEMARCONINC) lib_LTLIBRARIES = libyazproxy.la libyazproxy_la_LDFLAGS=-version-info 1:0:0 -libyazproxy_la_SOURCES= yaz-proxy.cpp yaz-proxy-config.cpp yaz-bw.cpp +libyazproxy_la_SOURCES= yaz-proxy.cpp yaz-proxy-config.cpp yaz-bw.cpp \ + proxyp.h yaz-usemarcon.cpp bin_PROGRAMS = yazproxy yazproxy_SOURCES=yaz-proxy-main.cpp -LDADD=libyazproxy.la $(YAZPPLALIB) $(XSLT_LIBS) +LDADD=libyazproxy.la $(YAZPPLALIB) $(XSLT_LIBS) $(USEMARCONLALIB) libyazproxy_la_LIBADD = $(XSLT_LIBS) diff --git a/src/proxyp.h b/src/proxyp.h new file mode 100644 index 0000000..8839106 --- /dev/null +++ b/src/proxyp.h @@ -0,0 +1,50 @@ +/* $Id: proxyp.h,v 1.1 2004-12-03 14:28:18 adam Exp $ + Copyright (c) 1998-2004, Index Data. + +This file is part of the yaz-proxy. + +YAZ proxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with YAZ proxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + */ + +#if HAVE_XSLT +#include +#include +#include +#include +#include +#endif + +#if HAVE_USEMARCON +#include +#endif + +#include + +class Yaz_usemarcon { + public: + Yaz_usemarcon(); + ~Yaz_usemarcon(); + + int convert(const char *stage1, const char *stage2, + const char *input, int input_len, + char **output, int *output_len); +#if HAVE_USEMARCON + CDetails *m_stage1; + CDetails *m_stage2; +#else + int dummy; +#endif +}; diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index 804018b..2bc8cfe 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy-config.cpp,v 1.10 2004-11-30 21:10:45 adam Exp $ +/* $Id: yaz-proxy-config.cpp,v 1.11 2004-12-03 14:28:18 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -21,15 +21,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include - -#if HAVE_XSLT -#include -#include -#include -#include -#include -#endif +#include "proxyp.h" class Yaz_ProxyConfigP { friend class Yaz_ProxyConfig; @@ -464,7 +456,10 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, char **addinfo, char **stylesheet, char **schema, char **backend_type, - char **backend_charset) + char **backend_charset, + char **usemarcon_ini_stage1, + char **usemarcon_ini_stage2 + ) { if (stylesheet) { @@ -486,6 +481,16 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, xfree (*backend_charset); *backend_charset = 0; } + if (usemarcon_ini_stage1) + { + xfree (*usemarcon_ini_stage1); + *usemarcon_ini_stage1 = 0; + } + if (usemarcon_ini_stage2) + { + xfree (*usemarcon_ini_stage2); + *usemarcon_ini_stage2 = 0; + } #if HAVE_XSLT int syntax_has_matched = 0; xmlNodePtr ptr; @@ -506,6 +511,8 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, const char *match_identifier = 0; const char *match_backend_type = 0; const char *match_backend_charset = 0; + const char *match_usemarcon_ini_stage1 = 0; + const char *match_usemarcon_ini_stage2 = 0; struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { @@ -532,6 +539,14 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, attr->children && attr->children->type == XML_TEXT_NODE) match_backend_charset = (const char *) attr->children->content; + if (!strcmp((const char *) attr->name, "usemarconstage1") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_usemarcon_ini_stage1 = (const char *) + attr->children->content; + if (!strcmp((const char *) attr->name, "usemarconstage2") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_usemarcon_ini_stage2 = (const char *) + attr->children->content; } if (match_type) { @@ -579,6 +594,16 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, xfree(*backend_charset); *backend_charset = xstrdup(match_backend_charset); } + if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1) + { + xfree(*usemarcon_ini_stage1); + *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1); + } + if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2) + { + xfree(*usemarcon_ini_stage2); + *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2); + } if (match_marcxml) { return -1; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index fa3b441..6857d0c 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.12 2004-11-30 21:10:45 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.13 2004-12-03 14:28:18 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -38,17 +38,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include +#include "proxyp.h" #include #include -#if HAVE_XSLT -#include -#include -#include -#include -#endif - static const char *apdu_name(Z_APDU *apdu) { switch (apdu->which) @@ -170,6 +163,9 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, #else m_time_tv = 0; #endif + m_usemarcon_ini_stage1 = 0; + m_usemarcon_ini_stage2 = 0; + m_usemarcon = new Yaz_usemarcon(); if (!m_parent) low_socket_open(); } @@ -196,6 +192,9 @@ Yaz_Proxy::~Yaz_Proxy() xfree (m_schema); xfree (m_backend_type); xfree (m_backend_charset); + xfree (m_usemarcon_ini_stage1); + xfree (m_usemarcon_ini_stage2); + delete m_usemarcon; if (m_s2z_odr_init) odr_destroy(m_s2z_odr_init); if (m_s2z_odr_search) @@ -756,6 +755,54 @@ void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p) Z_External *r = npr->u.databaseRecord; if (r->which == Z_External_octet) { +#if HAVE_USEMARCON + if (m_usemarcon_ini_stage1 && *m_usemarcon_ini_stage1) + { + if (!m_usemarcon->m_stage1) + { + m_usemarcon->m_stage1 = new CDetails(); + } + m_usemarcon->m_stage1->SetIniFileName(m_usemarcon_ini_stage1); + m_usemarcon->m_stage1->SetMarcRecord((char*) r->u.octet_aligned->buf, r->u.octet_aligned->len); + int res = m_usemarcon->m_stage1->Start(); + if (res == 0) + { + char *converted; + int convlen; + m_usemarcon->m_stage1->GetMarcRecord(converted, convlen); + if (m_usemarcon_ini_stage2 && *m_usemarcon_ini_stage2) + { + if (!m_usemarcon->m_stage2) + { + m_usemarcon->m_stage2 = new CDetails(); + } + m_usemarcon->m_stage2->SetIniFileName(m_usemarcon_ini_stage2); + m_usemarcon->m_stage2->SetMarcRecord(converted, convlen); + res = m_usemarcon->m_stage2->Start(); + if (res == 0) + { + free(converted); + m_usemarcon->m_stage2->GetMarcRecord(converted, convlen); + } + else + { + yaz_log(YLOG_LOG, "%sUSEMARCON stage 2 error %d", m_session_str, res); + } + } + npr->u.databaseRecord = + z_ext_record(odr_encode(), + m_frontend_type, + converted, + strlen(converted)); + free(converted); + } + else + { + yaz_log(YLOG_LOG, "%sUSEMARCON stage 1 error %d", m_session_str, res); + } + continue; + } +#endif npr->u.databaseRecord = z_ext_record(odr_encode(), m_frontend_type, @@ -1107,7 +1154,11 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) { if (p && p->which == Z_Records_DBOSD) { - if (m_backend_type) + if (m_backend_type +#if HAVE_USEMARCON + || m_usemarcon_ini_stage1 || m_usemarcon_ini_stage2 +#endif + ) convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics, @@ -1148,7 +1199,11 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) } if (p && p->which == Z_Records_DBOSD) { - if (m_backend_type) + if (m_backend_type +#if HAVE_USEMARCON + || m_usemarcon_ini_stage1 || m_usemarcon_ini_stage2 +#endif + ) convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics, @@ -1664,7 +1719,9 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) m_default_target, sr->preferredRecordSyntax, rc, &addinfo, &stylesheet_name, &m_schema, - &m_backend_type, &m_backend_charset); + &m_backend_type, &m_backend_charset, + &m_usemarcon_ini_stage1, + &m_usemarcon_ini_stage2); if (stylesheet_name) { m_parent->low_socket_close(); @@ -1738,7 +1795,10 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) pr->preferredRecordSyntax, pr->recordComposition, &addinfo, &stylesheet_name, &m_schema, - &m_backend_type, &m_backend_charset); + &m_backend_type, &m_backend_charset, + &m_usemarcon_ini_stage1, + &m_usemarcon_ini_stage2 + ); if (stylesheet_name) { m_parent->low_socket_close(); diff --git a/src/yaz-usemarcon.cpp b/src/yaz-usemarcon.cpp new file mode 100644 index 0000000..d769e25 --- /dev/null +++ b/src/yaz-usemarcon.cpp @@ -0,0 +1,83 @@ +/* $Id: yaz-usemarcon.cpp,v 1.1 2004-12-03 14:28:18 adam Exp $ + Copyright (c) 1998-2004, Index Data. + +This file is part of the yaz-proxy. + +YAZ proxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with YAZ proxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + */ + +#include "proxyp.h" + +Yaz_usemarcon::Yaz_usemarcon() +{ +#if HAVE_USEMARCON + m_stage1 = 0; + m_stage2 = 0; +#endif +} + +Yaz_usemarcon::~Yaz_usemarcon() +{ +#if HAVE_USEMARCON + delete m_stage1; + delete m_stage2; +#endif +} + +int Yaz_usemarcon::convert(const char *stage1, const char *stage2, + const char *input, int input_len, + char **output, int *output_len) +{ +#if HAVE_USEMARCON + if (stage1 && *stage1) + { + char *converted; + int convlen; + if (!m_stage1) + { + m_stage1 = new CDetails(); + } + m_stage1->SetIniFileName(stage1); + m_stage1->SetMarcRecord((char*) input, input_len); + int res = m_stage1->Start(); + if (res == 0) + { + m_stage1->GetMarcRecord(converted, convlen); + if (stage2 && *stage2) + { + if (!m_stage2) + { + m_stage2 = new CDetails(); + } + m_stage2->SetIniFileName(stage2); + m_stage2->SetMarcRecord(converted, convlen); + res = m_stage2->Start(); + if (res == 0) + { + free(converted); + m_stage2->GetMarcRecord(converted, convlen); + } + else + return 0; + } + *output = converted; + *output_len = convlen; + return 1; + } + } +#endif + return 0; +} diff --git a/usemarcon.m4 b/usemarcon.m4 new file mode 100644 index 0000000..5b9ae5c --- /dev/null +++ b/usemarcon.m4 @@ -0,0 +1,42 @@ +## $Id: usemarcon.m4,v 1.1 2004-12-03 14:28:18 adam Exp $ +AC_DEFUN([USEMARCON_INIT], +[ + AC_SUBST(USEMARCONLALIB) + AC_SUBST(USEMARCONINC) + usemarconconfig=NONE + usemarconpath=NONE + AC_ARG_WITH(usemarcon, [ --with-usemarcon=DIR usemarcon-config in DIR (example /home/usemarcon145)], [usemarconpath=$withval]) + + if test "x$usemarconpath" != "xNONE"; then + usemarconconfig=$usemarconpath/usemarcon-config + else + if test "x$srcdir" = "x"; then + usemarconsrcdir=. + else + usemarconsrcdir=$srcdir + fi + for i in ${usemarconsrcdir}/../usemarcon*; do + if test -d $i; then + if test -r $i/usemarcon-config; then + usemarconconfig=$i/usemarcon-config + fi + fi + done + if test "x$usemarconconfig" = "xNONE"; then + AC_PATH_PROG(usemarconconfig, usemarcon-config, NONE) + fi + fi + + AC_MSG_CHECKING(for USEMARCON) + if $usemarconconfig --version >/dev/null 2>&1; then + USEMARCONLALIB=`$usemarconconfig --lalibs $1` + USEMARCONINC=`$usemarconconfig --cflags $1` + USEMARCONVERSION=`$usemarconconfig --version` + AC_MSG_RESULT($usemarconconfig) + AC_DEFINE(HAVE_USEMARCON) + else + AC_MSG_RESULT(Not found) + USEMARCONVERSION=NONE + fi +]) +