X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_sru_to_z3950.cpp;h=8bd684b384721f051ab9d1c2ada819adbc75019e;hb=d0123337d70b0fb97b578cc57467bb94980f1014;hp=bb397656bfe7421fed26bfa851c55ed60b35f2d3;hpb=59f87be1f883639171b1293f33691e406d75f5ed;p=metaproxy-moved-to-github.git diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index bb39765..8bd684b 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2008 Index Data + Copyright (C) 2005-2009 Index Data 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 @@ -16,6 +16,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// make std::min actually work on Windows +#define NOMINMAX 1 + #include "config.hpp" #include "filter.hpp" #include "package.hpp" @@ -29,8 +32,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include +#include #include #include @@ -52,8 +57,14 @@ namespace metaproxy_1 { union SRW_query {char * cql; char * xcql; char * pqf;}; typedef const int& SRW_query_type; std::map m_database_explain; - private: + typedef std::map ActiveUrlMap; + + boost::mutex m_mutex; + boost::condition m_cond_url_ready; + ActiveUrlMap m_active_urls; + private: + void sru(metaproxy_1::Package &package, Z_GDU *zgdu_req); bool z3950_build_query(mp::odr &odr_en, Z_Query *z_query, const SRW_query &query, SRW_query_type query_type) const; @@ -91,6 +102,8 @@ namespace metaproxy_1 { int z3950_to_srw_diag(mp::odr &odr_en, Z_SRW_searchRetrieveResponse *srw_res, Z_DefaultDiagFormat *ddf) const; + + }; } } @@ -144,18 +157,8 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) } } -void yf::SRUtoZ3950::Impl::process(mp::Package &package) +void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { - Z_GDU *zgdu_req = package.request().get(); - - // ignoring all non HTTP_Request packages - if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)){ - package.move(); - return; - } - - // only working on HTTP_Request packages now - bool ok = true; mp::odr odr_de(ODR_DECODE); @@ -217,6 +220,10 @@ void yf::SRUtoZ3950::Impl::process(mp::Package &package) { zurl = std::string(arg->value); } + else if (!strcmp(arg->name, "x-max-sockets")) + { + package.origin().set_max_sockets(atoi(arg->value)); + } // filter acts as sink for SRU explain requests @@ -295,6 +302,49 @@ void yf::SRUtoZ3950::Impl::process(mp::Package &package) } +void yf::SRUtoZ3950::Impl::process(mp::Package &package) +{ + Z_GDU *zgdu_req = package.request().get(); + + // ignoring all non HTTP_Request packages + if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)){ + package.move(); + return; + } + + // only working on HTTP_Request packages now + + // see if HTTP request is already being executed.. + // we consider only the SRU - GET case.. + if (zgdu_req->u.HTTP_Request->content_len == 0) + { + const char *path = zgdu_req->u.HTTP_Request->path; + boost::mutex::scoped_lock lock(m_mutex); + while (1) + { + ActiveUrlMap::iterator it = m_active_urls.find(path); + if (it == m_active_urls.end()) + { + m_active_urls[path] = 1; + break; + } + yaz_log(YLOG_LOG, "Waiting for %s to complete", path); + m_cond_url_ready.wait(lock); + } + } + sru(package, zgdu_req); + if (zgdu_req->u.HTTP_Request->content_len == 0) + { + const char *path = zgdu_req->u.HTTP_Request->path; + boost::mutex::scoped_lock lock(m_mutex); + + ActiveUrlMap::iterator it = m_active_urls.find(path); + + m_active_urls.erase(it); + m_cond_url_ready.notify_all(); + } +} + bool yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, @@ -865,8 +915,9 @@ extern "C" { /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil - * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +