-## $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
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 \
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 \
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
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)
-/* $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
#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"
&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,
--- /dev/null
+/* $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 <yaz/zgdu.h>
+
+//#include <boost/thread/mutex.hpp>
+
+#include <iostream>
+
+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
+ */
--- /dev/null
+/* $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 <boost/scoped_ptr.hpp>
+
+#include "filter.hpp"
+
+namespace metaproxy_1 {
+ namespace filter {
+ class RecordTransform : public Base {
+ class Impl;
+ boost::scoped_ptr<Impl> 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
+ */
+
--- /dev/null
+/* $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 <iostream>
+//#include <stdexcept>
+
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
+
+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 =
+// "<?xml version='1.0'?>\n"
+// "<filter xmlns='http://indexdata.dk/yp2/config/1'\n"
+// " id='qrw1' type='sru_to_z3950'>\n"
+// "</filter>\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
+ */