From: Adam Dickmeiss Date: Thu, 6 Jul 2006 13:55:42 +0000 (+0000) Subject: Proper database fixup for virt_db+multi in case of multiple databases. X-Git-Tag: METAPROXY.1.0.6~5 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=45c064bbb3017f37aa651417defbd28a9db173bf;p=metaproxy-moved-to-github.git Proper database fixup for virt_db+multi in case of multiple databases. --- diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index a4b1402..98fb1ef 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_multi.cpp,v 1.21 2006-06-10 14:29:12 adam Exp $ +/* $Id: filter_multi.cpp,v 1.22 2006-07-06 13:55:42 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -711,17 +711,18 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) odr_malloc(odr, sizeof(Z_NamePlusRecord *) * nprl->num_records); int i = 0; std::list::const_iterator jit; - for (jit = jobs.begin(); jit != jobs.end(); jit++) + for (jit = jobs.begin(); jit != jobs.end(); jit++, i++) { PackagePtr p = jit->m_backend->m_package; Z_GDU *gdu = p->response().get(); Z_APDU *b_apdu = gdu->u.z3950; Z_PresentResponse *b_resp = b_apdu->u.presentResponse; - - nprl->records[i++] = - b_resp->records->u.databaseOrSurDiagnostics-> - records[jit->m_inside_pos]; + + nprl->records[i] = b_resp->records-> + u.databaseOrSurDiagnostics->records[jit->m_inside_pos]; + nprl->records[i]->databaseName = + odr_strdup(odr, jit->m_backend->m_vhost.c_str()); } *f_resp->nextResultSetPosition = start + i; *f_resp->numberOfRecordsReturned = i; diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index 144e46a..215ea71 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.42 2006-06-28 22:46:58 adam Exp $ +/* $Id: filter_virt_db.cpp,v 1.43 2006-07-06 13:55:42 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -68,11 +68,12 @@ namespace metaproxy_1 { void close(Package &package); typedef std::map::iterator Sets_it; - void fixup_npr(Package &p, BackendPtr b); - - void fixup_npr(Z_Records *records, std::string database, - ODR odr); - + void fixup_package(Package &p, BackendPtr b); + void fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, + BackendPtr b); + void fixup_npr_records(ODR odr, Z_Records *records, + BackendPtr b); + BackendPtr lookup_backend_from_databases( std::list databases); BackendPtr create_backend_from_databases( @@ -357,7 +358,7 @@ void yf::Virt_db::Frontend::search(mp::Package &package, Z_APDU *apdu_req) b->m_number_of_sets++; m_sets[resultSetId] = Virt_db::Set(b, backend_setname); - fixup_npr(search_package, b); + fixup_package(search_package, b); package.response() = search_package.response(); } @@ -462,9 +463,50 @@ yf::Virt_db::Virt_db() : m_p(new Virt_db::Rep) yf::Virt_db::~Virt_db() { } +void yf::Virt_db::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, + BackendPtr b) +{ + if (npr->databaseName) + { + std::string b_database = std::string(npr->databaseName); + + std::cout << "Fix up: " << b_database << "\n"; -void yf::Virt_db::Frontend::fixup_npr(Z_Records *records, std::string database, - ODR odr) + // consider each of the frontend databases.. + std::list::const_iterator db_it; + for (db_it = b->m_frontend_databases.begin(); + 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(*db_it); + if (map_it != m_p->m_maps.end()) + { + Virt_db::Map m = map_it->second; + + std::list::const_iterator t; + for (t = m.m_targets.begin(); t != m.m_targets.end(); t++) + { + if (*t == b_database) + { + npr->databaseName = odr_strdup(odr, (*db_it).c_str()); + return; + } + } + } + + } + db_it = b->m_frontend_databases.begin(); + if (db_it != b->m_frontend_databases.end()) + { + std::string database = *db_it; + npr->databaseName = odr_strdup(odr, database.c_str()); + } + } +} + +void yf::Virt_db::Frontend::fixup_npr_records(ODR odr, Z_Records *records, + BackendPtr b) { if (records && records->which == Z_Records_DBOSD) { @@ -472,33 +514,29 @@ void yf::Virt_db::Frontend::fixup_npr(Z_Records *records, std::string database, int i; for (i = 0; i < nprlist->num_records; i++) { - Z_NamePlusRecord *npr = nprlist->records[i]; - npr->databaseName = odr_strdup(odr, database.c_str()); + fixup_npr_record(odr, nprlist->records[i], b); } } } -void yf::Virt_db::Frontend::fixup_npr(mp::Package &p, BackendPtr b) +void yf::Virt_db::Frontend::fixup_package(mp::Package &p, BackendPtr b) { Z_GDU *gdu = p.response().get(); mp::odr odr; - std::string database = "dummy"; - std::list::const_iterator db_it = - b->m_frontend_databases.begin(); - if (db_it != b->m_frontend_databases.end()) - database = *db_it; - if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == - Z_APDU_presentResponse) + if (gdu && gdu->which == Z_GDU_Z3950) { - fixup_npr(gdu->u.z3950->u.presentResponse->records, database, odr); - p.response() = gdu; - } - if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == - Z_APDU_searchResponse) - { - fixup_npr(gdu->u.z3950->u.searchResponse->records, database, odr); - p.response() = gdu; + Z_APDU *apdu = gdu->u.z3950; + if (apdu->which == Z_APDU_presentResponse) + { + fixup_npr_records(odr, apdu->u.presentResponse->records, b); + p.response() = gdu; + } + else if (apdu->which == Z_APDU_searchResponse) + { + fixup_npr_records(odr, apdu->u.searchResponse->records, b); + p.response() = gdu; + } } } @@ -532,7 +570,7 @@ void yf::Virt_db::Frontend::present(mp::Package &package, Z_APDU *apdu_req) present_package.move(sets_it->second.m_backend->m_route); - fixup_npr(present_package, sets_it->second.m_backend); + fixup_package(present_package, sets_it->second.m_backend); if (present_package.session().is_closed()) {