From: Marc Cromme Date: Thu, 28 Dec 2006 14:59:43 +0000 (+0000) Subject: added first version of ZeeRex Explain filter for SRU explain X-Git-Tag: METAPROXY.1.0.8~59 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=6e73632396c2ed75df235eb038ad9701b97b4c73;p=metaproxy-moved-to-github.git added first version of ZeeRex Explain filter for SRU explain need much more configuration work to be done --- diff --git a/etc/config-sru-to-z3950.xml b/etc/config-sru-to-z3950.xml index 455658f..aa3e4dd 100644 --- a/etc/config-sru-to-z3950.xml +++ b/etc/config-sru-to-z3950.xml @@ -1,5 +1,5 @@ - + @@ -15,11 +15,15 @@ - SRU/W + ZEEREX + + + + SRU/Z3950 - Z3950 + VIRTDB @@ -27,11 +31,6 @@ localhost:9999/Default - diff --git a/src/Makefile.am b/src/Makefile.am index 05dc669..ba5da16 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.59 2006-10-03 14:04:22 marc Exp $ +## $Id: Makefile.am,v 1.60 2006-12-28 14:59:44 marc Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -29,6 +29,7 @@ libmetaproxy_la_SOURCES = \ filter_template.cpp filter_template.hpp \ filter_virt_db.cpp filter_virt_db.hpp \ filter_z3950_client.cpp filter_z3950_client.hpp \ + filter_zeerex_explain.cpp filter_zeerex_explain.hpp \ gduutil.cpp gduutil.hpp \ origin.cpp origin.hpp \ package.cpp package.hpp \ diff --git a/src/factory_static.cpp b/src/factory_static.cpp index b4ababc..da415b3 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -1,4 +1,4 @@ -/* $Id: factory_static.cpp,v 1.13 2006-10-03 14:04:22 marc Exp $ +/* $Id: factory_static.cpp,v 1.14 2006-12-28 14:59:44 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -29,6 +29,7 @@ #include "filter_template.hpp" #include "filter_virt_db.hpp" #include "filter_z3950_client.hpp" +#include "filter_zeerex_explain.hpp" namespace mp = metaproxy_1; @@ -49,6 +50,7 @@ mp::FactoryStatic::FactoryStatic() &metaproxy_1_filter_template, &metaproxy_1_filter_virt_db, &metaproxy_1_filter_z3950_client, + &metaproxy_1_filter_zeerex_explain, 0 }; int i; diff --git a/src/filter_zeerex_explain.cpp b/src/filter_zeerex_explain.cpp new file mode 100644 index 0000000..a721413 --- /dev/null +++ b/src/filter_zeerex_explain.cpp @@ -0,0 +1,155 @@ +/* $Id: filter_zeerex_explain.cpp,v 1.1 2006-12-28 14:59:44 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "config.hpp" +#include "filter.hpp" +#include "package.hpp" +#include "util.hpp" +#include "gduutil.hpp" +#include "sru_util.hpp" +#include "filter_zeerex_explain.hpp" + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace mp = metaproxy_1; +namespace mp_util = metaproxy_1::util; +namespace yf = mp::filter; + + +namespace metaproxy_1 { + namespace filter { + class ZeeRexExplain::Impl { + public: + void configure(const xmlNode *xmlnode); + void process(metaproxy_1::Package &package) const; + private: + }; + } +} + +yf::ZeeRexExplain::ZeeRexExplain() : m_p(new Impl) +{ +} + +yf::ZeeRexExplain::~ZeeRexExplain() +{ // must have a destructor because of boost::scoped_ptr +} + +void yf::ZeeRexExplain::configure(const xmlNode *xmlnode) +{ + m_p->configure(xmlnode); +} + +void yf::ZeeRexExplain::process(mp::Package &package) const +{ + m_p->process(package); +} + +void yf::ZeeRexExplain::Impl::configure(const xmlNode *xmlnode) +{ +} + +void yf::ZeeRexExplain::Impl::process(mp::Package &package) const +{ + Z_GDU *zgdu_req = package.request().get(); + + // ignoring all non HTTP_Request packages + if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)){ + package.move(); + return; + } + + // only working on HTTP_Request packages now + + mp::odr odr_de(ODR_DECODE); + Z_SRW_PDU *sru_pdu_req = 0; + + mp::odr odr_en(ODR_ENCODE); + //Z_SRW_PDU *sru_pdu_res = 0; + Z_SRW_PDU *sru_pdu_res = yaz_srw_get(odr_en, Z_SRW_explain_response); + + Z_SOAP *soap = 0; + char *charset = 0; + char *stylesheet = 0; + + + // if SRU package could not be decoded, send minimal explain and + // close connection + if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, + sru_pdu_res, soap, + charset, stylesheet))) + { + mp_util::build_simple_explain(package, odr_en, sru_pdu_res, 0); + mp_util::build_sru_response(package, odr_en, soap, + sru_pdu_res, charset, stylesheet); + package.session().close(); + return; + } + + + // SRU request package translation to Z3950 package + //if (sru_pdu_req) + // std::cout << *sru_pdu_req << "\n"; + //else + // std::cout << "SRU empty\n"; + + + if (sru_pdu_req->which != Z_SRW_explain_request){ + // Let pass all other SRU actions + package.move(); + return; + } + // except valid SRU explain request, construct ZeeRex Explain response + else { + Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request; + + mp_util::build_simple_explain(package, odr_en, sru_pdu_res, er_req); + + mp_util::build_sru_response(package, odr_en, soap, + sru_pdu_res, charset, stylesheet); + + return; + } + + // should never arrive here + package.session().close(); + return; +} + + + +static mp::filter::Base* filter_creator() +{ + return new mp::filter::ZeeRexExplain; +} + +extern "C" { + struct metaproxy_1_filter_struct metaproxy_1_filter_zeerex_explain = { + 0, + "zeerex_explain", + filter_creator + }; +} + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/filter_zeerex_explain.hpp b/src/filter_zeerex_explain.hpp new file mode 100644 index 0000000..d9dd0ce --- /dev/null +++ b/src/filter_zeerex_explain.hpp @@ -0,0 +1,41 @@ +/* $Id: filter_zeerex_explain.hpp,v 1.1 2006-12-28 14:59:44 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +// Filter that constructs valid ZeeRex Explain SRU responses +#ifndef FILTER_ZEEREX_EXPLAIN_HPP +#define FILTER_ZEEREX_EXPLAIN_HPP + +#include + +#include "filter.hpp" + +namespace metaproxy_1 { + namespace filter { + class ZeeRexExplain : public Base { + class Impl; + boost::scoped_ptr m_p; + public: + ZeeRexExplain(); + ~ZeeRexExplain(); + void configure(const xmlNode *xmlnode); + void process(metaproxy_1::Package & package) const; + }; + } +} + +extern "C" { + extern struct metaproxy_1_filter_struct metaproxy_1_filter_zeerex_explain; +} + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/xml/schema/metaproxy.rnc b/xml/schema/metaproxy.rnc index 56f403d..c31d760 100644 --- a/xml/schema/metaproxy.rnc +++ b/xml/schema/metaproxy.rnc @@ -1,5 +1,5 @@ # Metaproxy XML config file schemas -# $Id: metaproxy.rnc,v 1.11 2006-12-01 12:37:26 marc Exp $ +# $Id: metaproxy.rnc,v 1.12 2006-12-28 14:59:44 marc Exp $ # # Copyright (c) 2005-2006, Index Data. # @@ -58,6 +58,7 @@ filter = | filter_sru_z3950 | filter_virt_db | filter_z3950_client + | filter_zeerex_explain } filter_refid = attribute refid { xsd:NCName } @@ -169,3 +170,8 @@ filter_z3950_client = attribute id { xsd:NCName }?, attribute name { xsd:NCName }?, element mp:timeout { xsd:integer }? + +filter_zeerex_explain = + attribute type { "zeerex_explain" }, + attribute id { xsd:NCName }?, + attribute name { xsd:NCName }?