X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_virt_db.cpp;h=e2f7023556e0abca8a7130a105ad7d727e06c6af;hb=cddf94628ebaa0856a97d02a959ab8c9939f9549;hp=5ac0c2b2ba2f81b033ac2c2cc97cdf58682b04f1;hpb=0c26d703ff27cfbde7ec568a9ca5659b9d088bd1;p=metaproxy-moved-to-github.git diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index 5ac0c2b..e2f7023 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.18 2006-01-09 15:32:46 adam Exp $ +/* $Id: filter_virt_db.cpp,v 1.21 2006-01-12 14:09:08 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -6,9 +6,7 @@ #include "config.hpp" -#include "xmlutil.hpp" #include "filter.hpp" -#include "router.hpp" #include "package.hpp" #include @@ -30,13 +28,14 @@ namespace yp2 { namespace filter { struct Virt_db_set { Virt_db_set(yp2::Session &id, std::string setname, - std::string vhost, bool named_result_sets); - Virt_db_set(); - ~Virt_db_set(); + std::string vhost, std::string route, + bool named_result_sets); + Virt_db_set(); ~Virt_db_set(); yp2::Session m_backend_session; std::string m_backend_setname; std::string m_vhost; + std::string m_route; bool m_named_result_sets; }; struct Virt_db_session { @@ -47,15 +46,16 @@ namespace yp2 { std::map m_sets; }; struct Virt_db_map { - Virt_db_map(std::string vhost); + Virt_db_map(std::string vhost, std::string route); Virt_db_map(); std::string m_vhost; + std::string m_route; }; struct Frontend { Frontend(); ~Frontend(); yp2::Session m_session; - bool m_use_vhost; + bool m_is_virtual; bool m_in_use; std::map m_sets; void search(Package &package, Z_APDU *apdu, @@ -93,7 +93,7 @@ using namespace yp2; yf::Frontend::Frontend() { - m_use_vhost = false; + m_is_virtual = false; } void yf::Frontend::close(Package &package) @@ -105,7 +105,7 @@ void yf::Frontend::close(Package &package) Package close_package(sit->second.m_backend_session, package.origin()); close_package.copy_filter(package); - close_package.move(); + close_package.move(sit->second.m_route); } } @@ -149,7 +149,6 @@ void yf::Virt_db::Rep::release_frontend(Package &package) { if (package.session().is_closed()) { - std::cout << "Closing IT\n"; it->second->close(package); delete it->second; m_clients.erase(it); @@ -163,9 +162,10 @@ void yf::Virt_db::Rep::release_frontend(Package &package) } yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname, - std::string vhost, bool named_result_sets) + std::string vhost, std::string route, + bool named_result_sets) : m_backend_session(id), m_backend_setname(setname), m_vhost(vhost), - m_named_result_sets(named_result_sets) + m_route(route), m_named_result_sets(named_result_sets) { } @@ -179,8 +179,8 @@ yf::Virt_db_set::~Virt_db_set() { } -yf::Virt_db_map::Virt_db_map(std::string vhost) - : m_vhost(vhost) +yf::Virt_db_map::Virt_db_map(std::string vhost, std::string route) + : m_vhost(vhost), m_route(route) { } @@ -223,7 +223,7 @@ void yf::Virt_db::Rep::release_session(Package &package) Package close_package(sit->second.m_backend_session, package.origin()); close_package.copy_filter(package); - close_package.move(); + close_package.move(sit->second.m_route); } } m_sessions.erase(package.session()); @@ -370,6 +370,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) std::string vhost; std::string database; std::string resultSetId = req->resultSetName; + std::string route; bool support_named_result_sets = false; // whether backend supports it yp2::odr odr; { @@ -443,6 +444,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) } it->second.m_sets.erase(req->resultSetName); vhost = map_it->second.m_vhost; + route = map_it->second.m_route; } // we might look for an existing session with same vhost Session id; @@ -459,7 +461,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) init_package.request() = init_apdu; - init_package.move(); // sending init + init_package.move(route); // sending init if (init_package.session().is_closed()) { @@ -511,7 +513,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str()); search_package.request() = yazpp_1::GDU(apdu); - search_package.move(); + search_package.move(route); if (search_package.session().is_closed()) { @@ -533,7 +535,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) Ses_it it = m_sessions.find(package.session()); if (it != m_sessions.end()) it->second.m_sets[resultSetId] = - Virt_db_set(id, backend_resultSetId, vhost, + Virt_db_set(id, backend_resultSetId, vhost, route, support_named_result_sets); } @@ -600,6 +602,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu, } m_sets.erase(req->resultSetName); vhost = map_it->second.m_vhost; + std::string route = map_it->second.m_route; // we might look for an existing session with same vhost Session id; const char *vhost_cstr = vhost.c_str(); @@ -615,7 +618,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu, init_package.request() = init_apdu; - init_package.move(); // sending init + init_package.move(route); // sending init if (init_package.session().is_closed()) { @@ -667,7 +670,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu, req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str()); search_package.request() = yazpp_1::GDU(apdu); - search_package.move(); + search_package.move(route); if (search_package.session().is_closed()) { @@ -686,7 +689,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu, package.response() = search_package.response(); m_sets[resultSetId] = - Virt_db_set(id, backend_resultSetId, vhost, + Virt_db_set(id, backend_resultSetId, vhost, route, support_named_result_sets); } @@ -736,9 +739,10 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later) } } -void yf::Virt_db::add_map_db2vhost(std::string db, std::string vhost) +void yf::Virt_db::add_map_db2vhost(std::string db, std::string vhost, + std::string route) { - m_p->m_maps[db] = Virt_db_map(vhost); + m_p->m_maps[db] = Virt_db_map(vhost, route); } #if 0 @@ -748,50 +752,56 @@ void yf::Virt_db::process(Package &package) const if (f) { Z_GDU *gdu = package.request().get(); - if (!gdu || gdu->which != Z_GDU_Z3950 || f->m_use_vhost) + + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == + Z_APDU_initRequest) + { + Z_InitRequest *req = gdu->u.z3950->u.initRequest; + + const char *vhost = + yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0); + if (!vhost) + { + yp2::odr odr; + Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); + Z_InitResponse *resp = apdu->u.initResponse; + + int i; + static const int masks[] = { + Z_Options_search, + Z_Options_present, + Z_Options_namedResultSets, + -1 + }; + for (i = 0; masks[i] != -1; i++) + if (ODR_MASK_GET(req->options, masks[i])) + ODR_MASK_SET(resp->options, masks[i]); + + static const int versions[] = { + Z_ProtocolVersion_1, + Z_ProtocolVersion_2, + Z_ProtocolVersion_3, + -1 + }; + for (i = 0; versions[i] != -1; i++) + if (ODR_MASK_GET(req->protocolVersion, versions[i])) + ODR_MASK_SET(resp->protocolVersion, versions[i]); + else + break; + + package.response() = apdu; + f->m_is_virtual = true; + } + else + package.move(); + } + else if (!f->m_is_virtual) package.move(); - else + else if (gdu && gdu->which == Z_GDU_Z3950) { Z_APDU *apdu = gdu->u.z3950; if (apdu->which == Z_APDU_initRequest) { - Z_InitRequest *req = apdu->u.initRequest; - - const char *vhost = - yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0); - if (!vhost) - { - yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); - Z_InitResponse *resp = apdu->u.initResponse; - - int i; - static const int masks[] = { - Z_Options_search, Z_Options_present, Z_Options_namedResultSets, -1 - }; - for (i = 0; masks[i] != -1; i++) - if (ODR_MASK_GET(req->options, masks[i])) - ODR_MASK_SET(resp->options, masks[i]); - - static const int versions[] = { - Z_ProtocolVersion_1, - Z_ProtocolVersion_2, - Z_ProtocolVersion_3, - -1 - }; - for (i = 0; versions[i] != -1; i++) - if (ODR_MASK_GET(req->protocolVersion, versions[i])) - ODR_MASK_SET(resp->protocolVersion, versions[i]); - else - break; - - package.response() = apdu; - } - else - { - f->m_use_vhost = true; - package.move(); - } } else if (apdu->which == Z_APDU_searchRequest) { @@ -890,8 +900,10 @@ void yp2::filter::Virt_db::configure(const xmlNode * ptr) + " in virtual section" ); } - add_map_db2vhost(database, target); - std::cout << "Add " << database << "->" << target << "\n"; + std::string route = yp2::xml::get_route(ptr); + add_map_db2vhost(database, target, route); + std::cout << "Add " << database << "->" << target + << "," << route << "\n"; } else {