From 9f255f52501e9429f643772a186cc7a72a5e8893 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Thu, 31 Aug 2006 13:01:09 +0000 Subject: [PATCH] Coded bounce filter which returns all packages unprocessed, not sending any package further down the row. It sets Z3959 packages to Z_Close, and HTTP_Request packages to HTTP_Response err code 400 packages, and adds suitable bounce message. Added bounce filter at end of each filter chain config.xml to prevent infinite hanging of for example HTTP requests when only Z3950 client filter is configured. --- etc/config-bytarget.xml | 5 +- etc/config-imagine.xml | 7 ++- etc/config-local.xml | 3 +- etc/config-shared1.xml | 3 +- etc/config-simple-multi.xml | 1 + etc/config-zurg.xml | 3 +- etc/config0.xml | 6 +-- etc/config1.xml | 5 +- etc/config2.xml | 4 +- etc/config3.xml | 3 +- etc/config4.xml | 3 +- etc/config5.xml | 3 +- src/Makefile.am | 3 +- src/factory_static.cpp | 4 +- src/filter_bounce.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++ src/filter_bounce.hpp | 41 +++++++++++++++ 16 files changed, 197 insertions(+), 17 deletions(-) create mode 100644 src/filter_bounce.cpp create mode 100644 src/filter_bounce.hpp diff --git a/etc/config-bytarget.xml b/etc/config-bytarget.xml index 009c55e..9557f25 100644 --- a/etc/config-bytarget.xml +++ b/etc/config-bytarget.xml @@ -1,5 +1,5 @@ - + @@ -30,6 +30,7 @@ z3950.loc.gov:7090/voyager indexdata.dk/gils + @@ -41,6 +42,7 @@ 30 + + localhost:9999/A + localhost:9999/B - + + + @@ -60,6 +64,7 @@ + diff --git a/etc/config-local.xml b/etc/config-local.xml index f390301..576d4eb 100644 --- a/etc/config-local.xml +++ b/etc/config-local.xml @@ -1,5 +1,5 @@ - + @@ -30,6 +30,7 @@ 30 + diff --git a/etc/config-shared1.xml b/etc/config-shared1.xml index 6d4c382..18656ac 100644 --- a/etc/config-shared1.xml +++ b/etc/config-shared1.xml @@ -1,5 +1,5 @@ - + @@ -25,6 +25,7 @@ + diff --git a/etc/config-simple-multi.xml b/etc/config-simple-multi.xml index 3b50be7..2677c3d 100644 --- a/etc/config-simple-multi.xml +++ b/etc/config-simple-multi.xml @@ -26,6 +26,7 @@ 30 + diff --git a/etc/config-zurg.xml b/etc/config-zurg.xml index def5522..e7ff942 100644 --- a/etc/config-zurg.xml +++ b/etc/config-zurg.xml @@ -1,5 +1,5 @@ - + @@ -78,6 +78,7 @@ 30 + diff --git a/etc/config0.xml b/etc/config0.xml index fd8a22c..fc4333a 100644 --- a/etc/config0.xml +++ b/etc/config0.xml @@ -1,19 +1,17 @@ - + @:9000 - - - + diff --git a/etc/config1.xml b/etc/config1.xml index 9ec8b3e..393a4bc 100644 --- a/etc/config1.xml +++ b/etc/config1.xml @@ -1,5 +1,5 @@ - + @@ -15,9 +15,10 @@ - B + log + diff --git a/etc/config2.xml b/etc/config2.xml index 15625fe..98089fa 100644 --- a/etc/config2.xml +++ b/etc/config2.xml @@ -1,5 +1,5 @@ - + @@ -53,12 +53,14 @@ 30 + T + diff --git a/etc/config3.xml b/etc/config3.xml index d3bd65f..878d646 100644 --- a/etc/config3.xml +++ b/etc/config3.xml @@ -1,5 +1,5 @@ - + @@ -55,6 +55,7 @@ 30 + diff --git a/etc/config4.xml b/etc/config4.xml index d28bf03..c0044ca 100644 --- a/etc/config4.xml +++ b/etc/config4.xml @@ -1,5 +1,5 @@ - + @@ -19,6 +19,7 @@ /etc + diff --git a/etc/config5.xml b/etc/config5.xml index e500af5..9151604 100644 --- a/etc/config5.xml +++ b/etc/config5.xml @@ -1,5 +1,5 @@ - + @@ -26,6 +26,7 @@ /> + diff --git a/src/Makefile.am b/src/Makefile.am index 3a115ac..f16e172 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.52 2006-08-30 10:48:52 adam Exp $ +## $Id: Makefile.am,v 1.53 2006-08-31 13:01:09 marc Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -17,6 +17,7 @@ libmetaproxy_la_SOURCES = \ filter.hpp filter.cpp \ filter_auth_simple.cpp filter_auth_simple.hpp \ filter_backend_test.cpp filter_backend_test.hpp \ + filter_bounce.cpp filter_bounce.hpp \ filter_frontend_net.cpp filter_frontend_net.hpp \ filter_http_file.cpp filter_http_file.hpp \ filter_log.cpp filter_log.hpp \ diff --git a/src/factory_static.cpp b/src/factory_static.cpp index 55d24f8..378a742 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -1,4 +1,4 @@ -/* $Id: factory_static.cpp,v 1.10 2006-06-10 14:29:12 adam Exp $ +/* $Id: factory_static.cpp,v 1.11 2006-08-31 13:01:09 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -17,6 +17,7 @@ #include "filter_auth_simple.hpp" #include "filter_backend_test.hpp" +#include "filter_bounce.hpp" #include "filter_frontend_net.hpp" #include "filter_http_file.hpp" #include "filter_log.hpp" @@ -34,6 +35,7 @@ mp::FactoryStatic::FactoryStatic() struct metaproxy_1_filter_struct *buildins[] = { &metaproxy_1_filter_auth_simple, &metaproxy_1_filter_backend_test, + &metaproxy_1_filter_bounce, &metaproxy_1_filter_frontend_net, &metaproxy_1_filter_http_file, &metaproxy_1_filter_log, diff --git a/src/filter_bounce.cpp b/src/filter_bounce.cpp new file mode 100644 index 0000000..ac50f00 --- /dev/null +++ b/src/filter_bounce.cpp @@ -0,0 +1,120 @@ +/* $Id: filter_bounce.cpp,v 1.1 2006-08-31 13:01:09 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +#include "filter_bounce.hpp" +#include "package.hpp" +#include "util.hpp" +#include "gduutil.hpp" + +#include + +#include + +//#include "config.hpp" +//#include "filter.hpp" + +//#include + + + + + +namespace mp = metaproxy_1; +namespace yf = mp::filter; + +namespace metaproxy_1 { + namespace filter { + class Bounce::Rep { + friend class Bounce; + bool bounce; + }; + } +} + +yf::Bounce::Bounce() : m_p(new Rep) +{ + m_p->bounce = true; +} + +yf::Bounce::~Bounce() +{ // must have a destructor because of boost::scoped_ptr +} + +void yf::Bounce::process(mp::Package &package) const +{ + + if (! m_p->bounce ){ + package.move(); + return; + } + + + package.session().close(); + + Z_GDU *zgdu = package.request().get(); + + if (!zgdu) + return; + + //std::string message("BOUNCE "); + std::ostringstream message; + message << "BOUNCE " << *zgdu; + + metaproxy_1::odr odr; + + if (zgdu->which == Z_GDU_Z3950){ + Z_APDU *apdu_res = 0; + apdu_res = odr.create_close(zgdu->u.z3950, + Z_Close_systemProblem, + message.str().c_str()); + package.response() = apdu_res; + } + else if (zgdu->which == Z_GDU_HTTP_Request){ + Z_GDU *zgdu_res = 0; + zgdu_res + = odr.create_HTTP_Response(package.session(), + zgdu->u.HTTP_Request, 400); + + //zgdu_res->u.HTTP_Response->content_len = message.str().size(); + //zgdu_res->u.HTTP_Response->content_buf + // = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len); + + //strncpy(zgdu_res->u.HTTP_Response->content_buf, + // message.str().c_str(), zgdu_res->u.HTTP_Response->content_len); + + // z_HTTP_header_add(o, &hres->headers, + // "Content-Type", content_type.c_str()); + package.response() = zgdu_res; + } + else if (zgdu->which == Z_GDU_HTTP_Response){ + } + + + return; +} + +static mp::filter::Base* filter_creator() +{ + return new mp::filter::Bounce; +} + +extern "C" { + struct metaproxy_1_filter_struct metaproxy_1_filter_bounce = { + 0, + "bounce", + 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_bounce.hpp b/src/filter_bounce.hpp new file mode 100644 index 0000000..91a3fa8 --- /dev/null +++ b/src/filter_bounce.hpp @@ -0,0 +1,41 @@ +/* $Id: filter_bounce.hpp,v 1.1 2006-08-31 13:01:09 marc Exp $ + Copyright (c) 2005-2006, Index Data. + + See the LICENSE file for details + */ + +// Filter that bounces all requests packages +// No packages are ever passed to later filters in the chain +#ifndef FILTER_BOUNCE_HPP +#define FILTER_BOUNCE_HPP + +#include + +#include "filter.hpp" + +namespace metaproxy_1 { + namespace filter { + class Bounce : public Base { + class Rep; + boost::scoped_ptr m_p; + public: + Bounce(); + ~Bounce(); + void process(metaproxy_1::Package & package) const; + }; + } +} + +extern "C" { + extern struct metaproxy_1_filter_struct metaproxy_1_filter_bounce; +} + +#endif +/* + * 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