From e637fc7750457b84b070b71e009c733887b0dd73 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Tue, 3 Oct 2006 14:04:22 +0000 Subject: [PATCH] added scaffolding for a Z3950 present record transform filter. much to do yet --- src/Makefile.am | 6 +- src/factory_static.cpp | 4 +- src/filter_record_transform.cpp | 204 ++++++++++++++++++++++++++++++++++ src/filter_record_transform.hpp | 42 +++++++ src/test_filter_record_transform.cpp | 119 ++++++++++++++++++++ 5 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 src/filter_record_transform.cpp create mode 100644 src/filter_record_transform.hpp create mode 100644 src/test_filter_record_transform.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 9eb869f..05dc669 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.58 2006-09-28 10:38:00 marc Exp $ +## $Id: Makefile.am,v 1.59 2006-10-03 14:04:22 marc Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -23,6 +23,7 @@ libmetaproxy_la_SOURCES = \ filter_log.cpp filter_log.hpp \ filter_multi.cpp filter_multi.hpp \ filter_query_rewrite.cpp filter_query_rewrite.hpp \ + filter_record_transform.cpp filter_record_transform.hpp \ filter_session_shared.cpp filter_session_shared.hpp \ filter_sru_to_z3950.cpp filter_sru_to_z3950.hpp \ filter_template.cpp filter_template.hpp \ @@ -78,6 +79,7 @@ check_PROGRAMS = \ test_filter_z3950_client \ test_filter_backend_test \ test_filter_bounce \ + test_filter_record_transform \ test_filter_sru_to_z3950 \ test_filter_virt_db \ test_ses_map \ @@ -103,6 +105,7 @@ test_filter_query_rewrite_SOURCES = test_filter_query_rewrite.cpp test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp test_filter_backend_test_SOURCES = test_filter_backend_test.cpp test_filter_bounce_SOURCES = test_filter_bounce.cpp +test_filter_record_transform_SOURCES = test_filter_record_transform.cpp test_filter_sru_to_z3950_SOURCES = test_filter_sru_to_z3950.cpp test_filter_virt_db_SOURCES = test_filter_virt_db.cpp test_ses_map_SOURCES = test_ses_map.cpp @@ -127,6 +130,7 @@ test_filter_query_rewrite_LDADD = $(TESTLDADD) test_filter_z3950_client_LDADD = $(TESTLDADD) test_filter_backend_test_LDADD = $(TESTLDADD) test_filter_bounce_LDADD = $(TESTLDADD) +test_filter_record_transform_LDADD = $(TESTLDADD) test_filter_sru_to_z3950_LDADD = $(TESTLDADD) test_filter_virt_db_LDADD = $(TESTLDADD) test_router_flexml_LDADD = $(TESTLDADD) diff --git a/src/factory_static.cpp b/src/factory_static.cpp index 38466f1..b4ababc 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -1,4 +1,4 @@ -/* $Id: factory_static.cpp,v 1.12 2006-09-13 10:43:24 marc Exp $ +/* $Id: factory_static.cpp,v 1.13 2006-10-03 14:04:22 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -23,6 +23,7 @@ #include "filter_log.hpp" #include "filter_multi.hpp" #include "filter_query_rewrite.hpp" +#include "filter_record_transform.hpp" #include "filter_session_shared.hpp" #include "filter_sru_to_z3950.hpp" #include "filter_template.hpp" @@ -42,6 +43,7 @@ mp::FactoryStatic::FactoryStatic() &metaproxy_1_filter_log, &metaproxy_1_filter_multi, &metaproxy_1_filter_query_rewrite, + &metaproxy_1_filter_record_transform, &metaproxy_1_filter_session_shared, &metaproxy_1_filter_sru_to_z3950, &metaproxy_1_filter_template, diff --git a/src/filter_record_transform.cpp b/src/filter_record_transform.cpp new file mode 100644 index 0000000..0fe086d --- /dev/null +++ b/src/filter_record_transform.cpp @@ -0,0 +1,204 @@ +/* $Id: filter_record_transform.cpp,v 1.1 2006-10-03 14:04:22 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "config.hpp" +#include "filter.hpp" +#include "filter_record_transform.hpp" +#include "package.hpp" +#include "util.hpp" +#include "gduutil.hpp" + +#include + +//#include + +#include + +namespace mp = metaproxy_1; +namespace yf = mp::filter; + +namespace metaproxy_1 { + namespace filter { + class RecordTransform::Impl { + public: + Impl(); + ~Impl(); + void process(metaproxy_1::Package & package) const; + void configure(const xmlNode * xml_node); + private: + + }; + } +} + +// define Pimpl wrapper forwarding to Impl + +yf::RecordTransform::RecordTransform() : m_p(new Impl) +{ +} + +yf::RecordTransform::~RecordTransform() +{ // must have a destructor because of boost::scoped_ptr +} + +void yf::RecordTransform::configure(const xmlNode *xmlnode) +{ + m_p->configure(xmlnode); +} + +void yf::RecordTransform::process(mp::Package &package) const +{ + m_p->process(package); +} + + +// define Implementation stuff + + + +yf::RecordTransform::Impl::Impl() +{ +} + +yf::RecordTransform::Impl::~Impl() +{ +} + +void yf::RecordTransform::Impl::configure(const xmlNode *xml_node) +{ +// for (xml_node = xml_node->children; xml_node; xml_node = xml_node->next) +// { +// if (xml_node->type != XML_ELEMENT_NODE) +// continue; +// if (!strcmp((const char *) xml_node->name, "target")) +// { +// std::string route = mp::xml::get_route(xml_node); +// std::string target = mp::xml::get_text(xml_node); +// std::cout << "route=" << route << " target=" << target << "\n"; +// m_p->m_target_route[target] = route; +// } +// else if (!strcmp((const char *) xml_node->name, "hideunavailable")) +// { +// m_p->m_hide_unavailable = true; +// } +// else +// { +// throw mp::filter::FilterException +// ("Bad element " +// + std::string((const char *) xml_node->name) +// + " in virt_db filter"); +// } +// } +} + +void yf::RecordTransform::Impl::process(mp::Package &package) const +{ + + Z_GDU *gdu = package.request().get(); + + // only working on z3950 present packages + if (!gdu + || !(gdu->which == Z_GDU_Z3950) + || !(gdu->u.z3950->which == Z_APDU_presentRequest)) + { + package.move(); + return; + } + + // getting original present request + Z_PresentRequest *front_pr = gdu->u.z3950->u.presentRequest; + + // setting up ODR's for memory during encoding/decoding + mp::odr odr_de(ODR_DECODE); + mp::odr odr_en(ODR_ENCODE); + + // now packaging the z3950 backend present request + Package back_package(package.session(), package.origin()); + back_package.copy_filter(package); + + Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_presentRequest); + + assert(apdu->u.presentRequest); + + // z3950'fy start record position + //if () + // *(apdu->u.presentRequest->resultSetStartPoint) + // = + + // z3950'fy number of records requested + //if () + // *(apdu->u.presentRequest->numberOfRecordsRequested) + + // z3950'fy record syntax + //if() + //(apdu->u.presentRequest->preferredRecordSyntax) + // = yaz_oidval_to_z3950oid (odr_en, CLASS_RECSYN, VAL_TEXT_XML); + + // z3950'fy record schema + //if () + // { + // apdu->u.presentRequest->recordComposition + // = (Z_RecordComposition *) + // odr_malloc(odr_en, sizeof(Z_RecordComposition)); + // apdu->u.presentRequest->recordComposition->which + // = Z_RecordComp_simple; + // apdu->u.presentRequest->recordComposition->u.simple + // = build_esn_from_schema(odr_en, + // (const char *) sr_req->recordSchema); + // } + + // attaching Z3950 package to filter chain + back_package.request() = apdu; + + // std::cout << "z3950_present_request " << *apdu << "\n"; + + // sending backend package + back_package.move(); + + //check successful Z3950 present response + Z_GDU *back_gdu = back_package.response().get(); + if (!back_gdu || back_gdu->which != Z_GDU_Z3950 + || back_gdu->u.z3950->which != Z_APDU_presentResponse + || !back_gdu->u.z3950->u.presentResponse) + + { + std::cout << "record-transform: error back present\n"; + package.session().close(); + return; + } + + + // everything fine, continuing + // std::cout << "z3950_present_request OK\n"; + // std::cout << "back z3950 " << *back_gdu << "\n"; + + + return; +} + + +static mp::filter::Base* filter_creator() +{ + return new mp::filter::RecordTransform; +} + +extern "C" { + struct metaproxy_1_filter_struct metaproxy_1_filter_record_transform = { + 0, + "record_transform", + 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_record_transform.hpp b/src/filter_record_transform.hpp new file mode 100644 index 0000000..2cf8dbe --- /dev/null +++ b/src/filter_record_transform.hpp @@ -0,0 +1,42 @@ +/* $Id: filter_record_transform.hpp,v 1.1 2006-10-03 14:04:22 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +// Filter that does nothing. Use as RecordTransform for new filters +#ifndef FILTER_RECORD_TRANSFORM_HPP +#define FILTER_RECORD_TRANSFORM_HPP + +#include + +#include "filter.hpp" + +namespace metaproxy_1 { + namespace filter { + class RecordTransform : public Base { + class Impl; + boost::scoped_ptr m_p; + public: + RecordTransform(); + ~RecordTransform(); + void process(metaproxy_1::Package & package) const; + void configure(const xmlNode * ptr); + }; + } +} + +extern "C" { + extern struct metaproxy_1_filter_struct metaproxy_1_filter_record_transform; +} + +#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/src/test_filter_record_transform.cpp b/src/test_filter_record_transform.cpp new file mode 100644 index 0000000..cf54ff4 --- /dev/null +++ b/src/test_filter_record_transform.cpp @@ -0,0 +1,119 @@ +/* $Id: test_filter_record_transform.cpp,v 1.1 2006-10-03 14:04:22 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "config.hpp" +#include "filter_record_transform.hpp" +//#include "util.hpp" +//#include "sru_util.hpp" +#include "router_chain.hpp" +#include "session.hpp" +#include "package.hpp" + +//#include +//#include + +#define BOOST_AUTO_TEST_MAIN +#include + +using namespace boost::unit_test; + +namespace mp = metaproxy_1; +//using namespace mp::util; + + + +BOOST_AUTO_UNIT_TEST( test_filter_record_transform_1 ) +{ + try + { + mp::filter::RecordTransform f_rec_trans; + } + catch ( ... ) { + BOOST_CHECK (false); + } +} + +BOOST_AUTO_UNIT_TEST( test_filter_record_transform_2 ) +{ + try + { + mp::RouterChain router; + + mp::filter::RecordTransform f_rec_trans; + + router.append(f_rec_trans); + + //check_sru_to_z3950_init(router); + //check_sru_to_z3950_search(router, + // "@attrset Bib-1 @attr 1=4 the", + // "@attrset Bib-1 @attr 1=4 the"); + + } + catch ( ... ) { + BOOST_CHECK (false); + } +} + + +// BOOST_AUTO_UNIT_TEST( test_filter_record_transform_3 ) +// { + + +// try +// { +// mp::RouterChain router; + + +// std::string xmlconf = +// "\n" +// "\n" +// "\n" +// ; + +// //std::cout << xmlconf << std::endl; + +// // reading and parsing XML conf +// xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); +// BOOST_CHECK(doc); +// xmlNode *root_element = xmlDocGetRootElement(doc); + +// // creating and configuring filter +// mp::filter::RecordTransform f_rec_trans; +// f_rec_trans.configure(root_element); + +// // remeber to free XML DOM +// xmlFreeDoc(doc); + +// // add only filter to router +// router.append(f_rec_trans); + +// // start testing +// check_sru_to_z3950_init(router); +// check_sru_to_z3950_search(router, +// "@attrset Bib-1 @attr 1=4 the", +// "@attrset Bib-1 @attr 1=4 the"); + +// } + +// catch (std::exception &e) { +// std::cout << e.what() << "\n"; +// BOOST_CHECK (false); +// } + +// catch ( ... ) { +// BOOST_CHECK (false); +// } +// } + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ -- 1.7.10.4