From 1b26df87d5244f5bc093935dedd51cbf6858c703 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 13 Apr 2011 15:34:15 +0200 Subject: [PATCH] z3950_client filter: force_apdu facility Filter z3950_client may be configured to always send a close APDU to backend target when connection/session is closed. This will only happen if close APDU is not already sent. Enabled by configuration for z3950_client (force_close). --- NEWS | 5 ++++ doc/z3950_client.xml | 10 ++++++++ etc/config1.xml | 3 ++- src/filter_z3950_client.cpp | 53 ++++++++++++++++++++++++++++--------------- xml/schema/metaproxy.rnc | 4 +++- xml/schema/metaproxy.rng | 10 ++++++++ xml/schema/metaproxy.xsd | 3 +++ 7 files changed, 68 insertions(+), 20 deletions(-) diff --git a/NEWS b/NEWS index ebd171b..103f8a6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Filter z3950_client may be configured to always send a close APDU +to backend target when connection/session is closed. This will only +happen if close APDU is not already sent. Enabled by configuration +for z3950_client (force_close). + Filter virt_db and multi relays close APDU. Filter virt_db and multi: relay init size parameters diff --git a/doc/z3950_client.xml b/doc/z3950_client.xml index 7e38fa5..2c29028 100644 --- a/doc/z3950_client.xml +++ b/doc/z3950_client.xml @@ -55,6 +55,16 @@ + force_close + + + Is a boolean value (false, true). If true, the Z39.50 client will + terminate Z39.50 sessions with a close APDU followed by a socket close. + If false (default), the Z39.50 client will be transparent and only + send a close if the peer client does it too. + + + diff --git a/etc/config1.xml b/etc/config1.xml index b945abd..4e98e47 100644 --- a/etc/config1.xml +++ b/etc/config1.xml @@ -11,7 +11,8 @@ 30 - z3950.indexdata.dk + localhost:9999 + true diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index a493ae2..b975f50 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -66,6 +66,7 @@ namespace metaproxy_1 { bool m_waiting; bool m_destroyed; bool m_connected; + bool m_has_closed; int m_queue_len; int m_time_elapsed; int m_time_max; @@ -78,6 +79,7 @@ namespace metaproxy_1 { // number of seconds to wait before we give up request int m_timeout_sec; int m_max_sockets; + bool m_force_close; std::string m_default_target; std::string m_force_target; boost::mutex m_mutex; @@ -99,7 +101,8 @@ yf::Z3950Client::Assoc::Assoc(yazpp_1::SocketManager *socket_manager, : Z_Assoc(PDU_Observable), m_socket_manager(socket_manager), m_PDU_Observable(PDU_Observable), m_package(0), m_in_use(true), m_waiting(false), - m_destroyed(false), m_connected(false), m_queue_len(1), + m_destroyed(false), m_connected(false), m_has_closed(false), + m_queue_len(1), m_time_elapsed(0), m_time_max(timeout_sec), m_time_connect_max(10), m_host(host) { @@ -185,6 +188,7 @@ yf::Z3950Client::Z3950Client() : m_p(new yf::Z3950Client::Rep) { m_p->m_timeout_sec = 30; m_p->m_max_sockets = 0; + m_p->m_force_close = false; } yf::Z3950Client::~Z3950Client() { @@ -198,12 +202,6 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) std::map::iterator it; Z_GDU *gdu = package.request().get(); - // only deal with Z39.50 - if (!gdu || gdu->which != Z_GDU_Z3950) - { - package.move(); - return 0; - } int max_sockets = package.origin().get_max_sockets(); if (max_sockets == 0) @@ -237,6 +235,11 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) m_cond_session_ready.wait(lock); } } + if (!gdu || gdu->which != Z_GDU_Z3950) + { + package.move(); + return 0; + } // new Z39.50 session .. Z_APDU *apdu = gdu->u.z3950; // check that it is init. If not, close @@ -356,16 +359,30 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) void yf::Z3950Client::Rep::send_and_receive(Package &package, yf::Z3950Client::Assoc *c) { - Z_GDU *gdu = package.request().get(); - if (c->m_destroyed) return; + c->m_package = &package; + + if (package.session().is_closed() && c->m_connected && !c->m_has_closed + && m_force_close) + { + mp::odr odr; + + package.request() = odr.create_close( + 0, Z_Close_finished, "z3950_client"); + c->m_package = 0; // don't inspect response + } + Z_GDU *gdu = package.request().get(); + if (!gdu || gdu->which != Z_GDU_Z3950) return; + if (gdu->u.z3950->which == Z_APDU_close) + c->m_has_closed = true; + + // prepare connect c->m_time_elapsed = 0; - c->m_package = &package; c->m_waiting = true; if (!c->m_connected) { @@ -389,7 +406,7 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, int len; c->send_GDU(gdu, &len); - switch(gdu->u.z3950->which) + switch (gdu->u.z3950->which) { case Z_APDU_triggerResourceControlRequest: // request only.. @@ -411,12 +428,8 @@ void yf::Z3950Client::Rep::release_assoc(Package &package) it = m_clients.find(package.session()); if (it != m_clients.end()) { - Z_GDU *gdu = package.request().get(); - if (gdu && gdu->which == Z_GDU_Z3950) - { // only Z39.50 packages lock in get_assoc.. release it - it->second->m_in_use = false; - it->second->m_queue_len--; - } + it->second->m_in_use = false; + it->second->m_queue_len--; if (package.session().is_closed()) { @@ -440,8 +453,8 @@ void yf::Z3950Client::process(Package &package) const if (c) { m_p->send_and_receive(package, c); + m_p->release_assoc(package); } - m_p->release_assoc(package); } void yf::Z3950Client::configure(const xmlNode *ptr, bool test_only) @@ -466,6 +479,10 @@ void yf::Z3950Client::configure(const xmlNode *ptr, bool test_only) { m_p->m_max_sockets = mp::xml::get_int(ptr->children, 0); } + else if (!strcmp((const char *) ptr->name, "force_close")) + { + m_p->m_force_close = mp::xml::get_bool(ptr->children, 0); + } else { throw mp::filter::FilterException("Bad element " diff --git a/xml/schema/metaproxy.rnc b/xml/schema/metaproxy.rnc index d80c9e6..2eccb00 100644 --- a/xml/schema/metaproxy.rnc +++ b/xml/schema/metaproxy.rnc @@ -132,6 +132,7 @@ filter_log = attribute init-options { xsd:boolean }?, attribute request-session { xsd:boolean }?, attribute response-session { xsd:boolean }?, + attribute session { xsd:boolean }?, attribute apdu { xsd:boolean }?, attribute request-apdu { xsd:boolean }?, attribute response-apdu { xsd:boolean }? @@ -201,7 +202,8 @@ filter_z3950_client = attribute name { xsd:NCName }?, element mp:timeout { xsd:integer }?, element mp:default_target { xsd:string }?, - element mp:force_target { xsd:string }? + element mp:force_target { xsd:string }?, + element mp:force_close { xsd:boolean }? filter_limit = attribute type { "limit" }, diff --git a/xml/schema/metaproxy.rng b/xml/schema/metaproxy.rng index 1e7ae21..769fd9d 100644 --- a/xml/schema/metaproxy.rng +++ b/xml/schema/metaproxy.rng @@ -323,6 +323,11 @@ + + + + + @@ -533,6 +538,11 @@ + + + + + diff --git a/xml/schema/metaproxy.xsd b/xml/schema/metaproxy.xsd index d893dd0..00dc21b 100644 --- a/xml/schema/metaproxy.xsd +++ b/xml/schema/metaproxy.xsd @@ -262,6 +262,7 @@ + @@ -436,10 +437,12 @@ + + -- 1.7.10.4