X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_frontend_net.cpp;h=38ed62bd8fb8517acff375037fef8c6905649528;hb=0ab6e8aba7de1ea5cf109de175f56c9d8f7f49bc;hp=66d4cfce4662c079e2bfd5d60cf8a35695e2f361;hpb=53fa483f7ee74290fa3a34530a9826160c1a8a4c;p=metaproxy-moved-to-github.git diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index 66d4cfc..38ed62b 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -1,11 +1,27 @@ -/* $Id: filter_frontend_net.cpp,v 1.17 2006-03-29 13:44:45 adam Exp $ - Copyright (c) 2005-2006, Index Data. +/* $Id: filter_frontend_net.cpp,v 1.24 2007-05-09 21:23:09 adam Exp $ + Copyright (c) 2005-2007, Index Data. -%LICENSE% +This file is part of Metaproxy. + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Metaproxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ #include "config.hpp" +#include "util.hpp" #include "pipe.hpp" #include "filter.hpp" #include "package.hpp" @@ -27,6 +43,7 @@ namespace metaproxy_1 { int m_no_threads; std::vector m_ports; int m_listen_duration; + int m_session_timeout; }; } class My_Timer_Thread : public yazpp_1::ISocketObserver { @@ -80,7 +97,8 @@ namespace metaproxy_1 { ~ZAssocServer(); ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, mp::ThreadPoolSocketObserver *m_thread_pool_observer, - const mp::Package *package); + const mp::Package *package, + int timeout); private: yazpp_1::IPDU_Observer* sessionNotify( yazpp_1::IPDU_Observable *the_PDU_Observable, @@ -93,6 +111,7 @@ namespace metaproxy_1 { private: mp::ThreadPoolSocketObserver *m_thread_pool_observer; const mp::Package *m_package; + int m_session_timeout; }; } @@ -106,11 +125,32 @@ void mp::ThreadPoolPackage::result() m_session->m_no_requests--; yazpp_1::GDU *gdu = &m_package->response(); + if (gdu->get()) { int len; m_session->send_GDU(gdu->get(), &len); } + else if (!m_package->session().is_closed()) + { + // no response package and yet the session is still open.. + // means that request is unhandled.. + yazpp_1::GDU *gdu_req = &m_package->request(); + Z_GDU *z_gdu = gdu_req->get(); + if (z_gdu && z_gdu->which == Z_GDU_Z3950) + { + // For Z39.50, response with a Close and shutdown + mp::odr odr; + int len; + Z_APDU *apdu_response = odr.create_close( + z_gdu->u.z3950, Z_Close_systemProblem, + "unhandled Z39.50 request"); + + m_session->send_Z_PDU(apdu_response, &len); + m_package->session().close(); + } + } + if (m_session->m_no_requests == 0 && m_package->session().is_closed()) delete m_session; delete this; @@ -132,6 +172,10 @@ mp::ZAssocChild::ZAssocChild(yazpp_1::IPDU_Observable *PDU_Observable, m_no_requests = 0; m_delete_flag = false; m_package = package; + const char *peername = PDU_Observable->getpeername(); + if (!peername) + peername = "unknown"; + m_origin.set_tcpip_address(std::string(peername), m_session.id()); } @@ -184,9 +228,10 @@ void mp::ZAssocChild::connectNotify() } mp::ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *PDU_Observable, - mp::ThreadPoolSocketObserver *thread_pool_observer, - const mp::Package *package) - : Z_Assoc(PDU_Observable) + mp::ThreadPoolSocketObserver *thread_pool_observer, + const mp::Package *package, + int timeout) + : Z_Assoc(PDU_Observable), m_session_timeout(timeout) { m_thread_pool_observer = thread_pool_observer; m_package = package; @@ -199,6 +244,7 @@ yazpp_1::IPDU_Observer *mp::ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable mp::ZAssocChild *my = new mp::ZAssocChild(the_PDU_Observable, m_thread_pool_observer, m_package); + my->timeout(m_session_timeout); return my; } @@ -226,6 +272,7 @@ mp::filter::FrontendNet::FrontendNet() : m_p(new Rep) { m_p->m_no_threads = 5; m_p->m_listen_duration = 0; + m_p->m_session_timeout = 300; // 5 minutes } mp::filter::FrontendNet::~FrontendNet() @@ -275,7 +322,8 @@ void mp::filter::FrontendNet::process(Package &package) const yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&mySocketManager); // create ZAssoc with PDU Assoc - az[i] = new mp::ZAssocServer(as, &threadPool, &package); + az[i] = new mp::ZAssocServer(as, &threadPool, &package, + m_p->m_session_timeout); az[i]->server(m_p->m_ports[i].c_str()); } while (mySocketManager.processEvent() > 0) @@ -316,6 +364,15 @@ void mp::filter::FrontendNet::configure(const xmlNode * ptr) + threads_str); m_p->m_no_threads = threads; } + else if (!strcmp((const char *) ptr->name, "timeout")) + { + std::string timeout_str = mp::xml::get_text(ptr); + int timeout = atoi(timeout_str.c_str()); + if (timeout < 1) + throw mp::filter::FilterException("Bad value for timeout: " + + timeout_str); + m_p->m_session_timeout = timeout; + } else { throw mp::filter::FilterException("Bad element "