X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_virt_db.cpp;h=55cb6dfe56d00c138656797583870ab64d30d258;hb=b0c61b7f8b17d876c88347a96c246c47493140da;hp=bd142a0a8dd17ffa77ca20eca4c1ab0d72797a77;hpb=85189f2d04df4cfc8b16ee78187fb89d00dfe3ff;p=metaproxy-moved-to-github.git diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index bd142a0..55cb6df 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,7 +1,5 @@ -/* $Id: filter_virt_db.cpp,v 1.54 2008-02-20 15:07:52 adam Exp $ - Copyright (c) 2005-2007, Index Data. - -This file is part of Metaproxy. +/* This file is part of Metaproxy. + Copyright (C) 2005-2010 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 @@ -14,15 +12,9 @@ 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. - */ -/* $Id: filter_virt_db.cpp,v 1.54 2008-02-20 15:07:52 adam Exp $ - Copyright (c) 2005-2007, Index Data. - - See the LICENSE file for details - */ +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include "config.hpp" @@ -39,6 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include #include @@ -58,8 +51,10 @@ namespace metaproxy_1 { std::string m_setname; }; struct VirtualDB::Map { - Map(std::list targets, std::string route); + Map(std::string database, std::list targets, std::string route); Map(); + bool match(const std::string db) const; + std::string m_dbpattern; std::list m_targets; std::string m_route; }; @@ -113,11 +108,12 @@ namespace metaproxy_1 { FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); private: - std::mapm_maps; + std::listm_maps; typedef std::map::iterator Sets_it; boost::mutex m_mutex; boost::condition m_cond_session_ready; std::map m_clients; + bool pass_vhosts; }; } } @@ -149,8 +145,15 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::create_backend_from_databases std::map targets_dedup; for (; db_it != databases.end(); db_it++) { - std::map::iterator map_it; - map_it = m_p->m_maps.find(mp::util::database_name_normalize(*db_it)); + std::list::const_iterator map_it; + map_it = m_p->m_maps.begin(); + while (map_it != m_p->m_maps.end()) + { + if (map_it->match(*db_it)) + break; + map_it++; + } + if (map_it == m_p->m_maps.end()) // database not found { error_code = YAZ_BIB1_DATABASE_DOES_NOT_EXIST; @@ -159,8 +162,8 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::create_backend_from_databases return ptr; } std::list::const_iterator t_it = - map_it->second.m_targets.begin(); - for (; t_it != map_it->second.m_targets.end(); t_it++) { + map_it->m_targets.begin(); + for (; t_it != map_it->m_targets.end(); t_it++) { if (!targets_dedup[*t_it]) { targets_dedup[*t_it] = true; @@ -169,14 +172,14 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::create_backend_from_databases } // see if we have a route conflict. - if (!first_route && b->m_route != map_it->second.m_route) + if (!first_route && b->m_route != map_it->m_route) { // we have a conflict.. error_code = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; BackendPtr ptr; return ptr; } - b->m_route = map_it->second.m_route; + b->m_route = map_it->m_route; first_route = false; } return b; @@ -233,31 +236,24 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( { b->m_named_result_sets = true; } - if (!*res->result) + if (*res->result) { - error_code = YAZ_BIB1_DATABASE_UNAVAILABLE; - mp::util::get_init_diagnostics(res, error_code, addinfo); - BackendPtr null; - return null; + m_backend_list.push_back(b); + return b; + } - } - else - { error_code = YAZ_BIB1_DATABASE_UNAVAILABLE; - // addinfo = database; - BackendPtr null; - return null; - } - if (init_package.session().is_closed()) + mp::util::get_init_diagnostics(res, error_code, addinfo); + } + if (!init_package.session().is_closed()) { - error_code = YAZ_BIB1_DATABASE_UNAVAILABLE; - // addinfo = database; - BackendPtr null; - return null; + Package close_package(b->m_backend_session, package.origin()); + close_package.copy_filter(package); + close_package.session().close(); + close_package.move(b->m_route); // closing it } - - m_backend_list.push_back(b); - return b; + BackendPtr null; + return null; } void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) @@ -469,8 +465,9 @@ yf::VirtualDB::Set::~Set() { } -yf::VirtualDB::Map::Map(std::list targets, std::string route) - : m_targets(targets), m_route(route) +yf::VirtualDB::Map::Map(std::string database, + std::list targets, std::string route) + : m_dbpattern(database), m_targets(targets), m_route(route) { } @@ -478,8 +475,17 @@ yf::VirtualDB::Map::Map() { } +bool yf::VirtualDB::Map::match(const std::string db) const +{ + std::string norm_db = mp::util::database_name_normalize(db); + if (yaz_match_glob(m_dbpattern.c_str(), norm_db.c_str())) + return true; + return false; +} + yf::VirtualDB::VirtualDB() : m_p(new VirtualDB::Rep) { + m_p->pass_vhosts = false; } yf::VirtualDB::~VirtualDB() { @@ -498,21 +504,26 @@ void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, db_it != b->m_frontend_databases.end(); db_it++) { // see which target it corresponds to.. (if any) - std::map::const_iterator map_it; - - map_it = m_p->m_maps.find(mp::util::database_name_normalize(*db_it)); + std::list::const_iterator map_it = + m_p->m_maps.begin(); + while (map_it != m_p->m_maps.end()) + { + if (map_it->match(*db_it)) + break; + map_it++; + } if (map_it != m_p->m_maps.end()) { - VirtualDB::Map m = map_it->second; - - std::list::const_iterator t; - for (t = m.m_targets.begin(); t != m.m_targets.end(); t++) + std::list::const_iterator t + = map_it->m_targets.begin(); + while (t != map_it->m_targets.end()) { if (*t == b_database) { npr->databaseName = odr_strdup(odr, (*db_it).c_str()); return; } + t++; } } @@ -676,8 +687,8 @@ void yf::VirtualDB::add_map_db2targets(std::string db, std::list targets, std::string route) { - m_p->m_maps[mp::util::database_name_normalize(db)] - = VirtualDB::Map(targets, route); + m_p->m_maps.push_back( + VirtualDB::Map(mp::util::database_name_normalize(db), targets, route)); } @@ -688,8 +699,7 @@ void yf::VirtualDB::add_map_db2target(std::string db, std::list targets; targets.push_back(target); - m_p->m_maps[mp::util::database_name_normalize(db)] - = VirtualDB::Map(targets, route); + add_map_db2targets(db, targets, route); } void yf::VirtualDB::process(mp::Package &package) const @@ -705,7 +715,12 @@ void yf::VirtualDB::process(mp::Package &package) const std::list vhosts; mp::util::get_vhost_otherinfo(req->otherInfo, vhosts); - if (vhosts.size() == 0) + + if (vhosts.size() > 0 && m_p->pass_vhosts) + { + package.move(); + } + else { f->m_init_gdu = gdu; @@ -740,8 +755,6 @@ void yf::VirtualDB::process(mp::Package &package) const package.response() = apdu; f->m_is_virtual = true; } - else - package.move(); } else if (!f->m_is_virtual) package.move(); @@ -796,7 +809,11 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) { if (ptr->type != XML_ELEMENT_NODE) continue; - if (!strcmp((const char *) ptr->name, "virtual")) + if (!strcmp((const char *) ptr->name, "pass-vhosts")) + { + m_p->pass_vhosts = mp::xml::get_bool(ptr->children, false); + } + else if (!strcmp((const char *) ptr->name, "virtual")) { std::string database; std::list targets; @@ -847,8 +864,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 */ +