X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_virt_db.cpp;h=b84e08753ef707962d80161aae0b6eae01dc6c31;hb=a65b7be116265cf331eb823acc9e48738f30e33a;hp=c9474c894dfdd75882ff627a2977dfb516bb6c18;hpb=fa059d055896a26b113e0e486531b71e7ec63c14;p=metaproxy-moved-to-github.git diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index c9474c8..b84e087 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2012 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 @@ -26,13 +26,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "torus.hpp" #include #include #include #include -#include #include #include @@ -60,15 +58,12 @@ namespace metaproxy_1 { std::string m_dbpattern; std::list m_targets; std::string m_route; - public: - std::string query_encoding; }; struct VirtualDB::Backend { mp::Session m_backend_session; std::list m_frontend_databases; std::list m_targets; std::string m_route; - std::string query_encoding; bool m_named_result_sets; int m_number_of_sets; }; @@ -122,7 +117,6 @@ namespace metaproxy_1 { boost::condition m_cond_session_ready; std::map m_clients; bool pass_vhosts; - mp::Torus torus; }; } } @@ -189,14 +183,6 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::create_backend_from_databases return ptr; } b->m_route = map_it->m_route; - if (!first_route && b->query_encoding != map_it->query_encoding) - { - // we have a conflict. query encoding must be same for all - error_code = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; - BackendPtr ptr; - return ptr; - } - b->query_encoding = map_it->query_encoding; first_route = false; } return b; @@ -247,10 +233,9 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( Z_GDU *gdu = init_package.response().get(); // we hope to get an init response - error_code = YAZ_BIB1_DATABASE_UNAVAILABLE; + error_code = 0; if (gdu && gdu->which == Z_GDU_Z3950 - && gdu->u.z3950->which == Z_APDU_initResponse - && *gdu->u.z3950->u.initResponse->result) + && gdu->u.z3950->which == Z_APDU_initResponse) { Z_InitResponse *res = gdu->u.z3950->u.initResponse; if (ODR_MASK_GET(res->options, Z_Options_namedResultSets)) @@ -264,6 +249,13 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( } mp::util::get_init_diagnostics(res, error_code, addinfo); } + if (error_code == 0) + { + std::list::const_iterator db_it = databases.begin(); + error_code = YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED; + if (db_it != databases.end()) + addinfo = *db_it; + } if (!init_package.session().is_closed()) { Package close_package(b->m_backend_session, package.origin()); @@ -277,7 +269,8 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) { - Z_SearchRequest *req = apdu_req->u.searchRequest; + yazpp_1::GDU ngdu(apdu_req); + Z_SearchRequest *req = ngdu.get()->u.z3950->u.searchRequest; std::string vhost; std::string resultSetId = req->resultSetName; mp::odr odr; @@ -364,24 +357,10 @@ void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) &req->databaseNames); } - if (b->query_encoding.length() && - (req->query->which == Z_Query_type_1 || - req->query->which == Z_Query_type_101)) - { - yaz_iconv_t cd = yaz_iconv_open(b->query_encoding.c_str(), "UTF-8"); - if (cd) - { - int r = yaz_query_charset_convert_rpnquery_check( - req->query->u.type_1, odr, cd); - yaz_iconv_close(cd); - if (r) - yaz_log(YLOG_LOG, "query could not be converted"); - } - } *req->replaceIndicator = 1; - search_package.request() = yazpp_1::GDU(apdu_req); - + search_package.request() = ngdu; + search_package.move(b->m_route); if (search_package.session().is_closed()) @@ -467,71 +446,6 @@ void yf::VirtualDB::Rep::release_frontend(mp::Package &package) } } -void yf::VirtualDB::Rep::refresh_torus(void) -{ - xmlDoc *doc = torus.get_doc(); - if (!doc) - return; - - xmlNode *ptr1 = xmlDocGetRootElement(doc); - if (!ptr1) - return ; - - for (ptr1 = ptr1->children; ptr1; ptr1 = ptr1->next) - { - if (ptr1->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr1->name, "record")) - { - xmlNode *ptr2 = ptr1; - for (ptr2 = ptr2->children; ptr2; ptr2 = ptr2->next) - { - if (ptr2->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr2->name, "layer")) - { - std::string database; - std::string target; - std::string route; - std::string solr; - std::string query_encoding; - xmlNode *ptr3 = ptr2; - for (ptr3 = ptr3->children; ptr3; ptr3 = ptr3->next) - { - if (ptr3->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) ptr3->name, "id")) - { - database = mp::xml::get_text(ptr3); - } - else if (!strcmp((const char *) ptr3->name, "zurl")) - { - target = mp::xml::get_text(ptr3); - } - else if (!strcmp((const char *) ptr3->name, "sru")) - { - solr = mp::xml::get_text(ptr3); - } - else if (!strcmp((const char *) ptr3->name, - "queryEncoding")) - { - query_encoding = mp::xml::get_text(ptr3); - } - } - if (solr.length() == 0 && - database.length() && target.length()) - { - VirtualDB::Map vmap( - mp::util::database_name_normalize(database), - target, route); - vmap.query_encoding = query_encoding; - m_maps.push_back(vmap); - } - } - } - } - } -} yf::VirtualDB::Set::Set(BackendPtr b, std::string setname) : m_backend(b), m_setname(setname) @@ -665,7 +579,8 @@ void yf::VirtualDB::Frontend::fixup_package(mp::Package &p, BackendPtr b) void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req) { - Z_PresentRequest *req = apdu_req->u.presentRequest; + yazpp_1::GDU ngdu(apdu_req); + Z_PresentRequest *req = ngdu.get()->u.z3950->u.presentRequest; std::string resultSetId = req->resultSetId; mp::odr odr; @@ -689,7 +604,7 @@ void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req) req->resultSetId = odr_strdup(odr, sets_it->second.m_setname.c_str()); - present_package.request() = yazpp_1::GDU(apdu_req); + present_package.request() = ngdu; present_package.move(sets_it->second.m_backend->m_route); @@ -731,7 +646,8 @@ int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req) void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) { - Z_ScanRequest *req = apdu_req->u.scanRequest; + yazpp_1::GDU ngdu(apdu_req); + Z_ScanRequest *req = ngdu.get()->u.z3950->u.scanRequest; std::string vhost; mp::odr odr; @@ -782,17 +698,7 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) &req->databaseNames); } - if (b->query_encoding.length()) - { - yaz_iconv_t cd = yaz_iconv_open(b->query_encoding.c_str(), "UTF-8"); - if (cd) - { - yaz_query_charset_convert_apt(req->termListAndStartPoint, odr, cd); - yaz_iconv_close(cd); - } - } - - scan_package.request() = yazpp_1::GDU(apdu_req); + scan_package.request() = ngdu; scan_package.move(b->m_route); @@ -935,7 +841,8 @@ void yf::VirtualDB::process(mp::Package &package) const m_p->release_frontend(package); } -void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) +void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only, + const char *path) { for (ptr = ptr->children; ptr; ptr = ptr->next) { @@ -943,11 +850,10 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) continue; if (!strcmp((const char *) ptr->name, "pass-vhosts")) { - m_p->pass_vhosts = mp::xml::get_bool(ptr->children, false); + m_p->pass_vhosts = mp::xml::get_bool(ptr, false); } else if (!strcmp((const char *) ptr->name, "virtual")) { - std::string query_encoding; std::string database; std::list targets; xmlNode *v_node = ptr->children; @@ -960,8 +866,6 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) database = mp::xml::get_text(v_node); else if (mp::xml::is_element_mp(v_node, "target")) targets.push_back(mp::xml::get_text(v_node)); - else if (mp::xml::is_element_mp(v_node, "query-encoding")) - targets.push_back(mp::xml::get_text(v_node)); else throw mp::filter::FilterException ("Bad element " @@ -973,25 +877,8 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) VirtualDB::Map vmap(mp::util::database_name_normalize(database), targets, route); - vmap.query_encoding = query_encoding; m_p->m_maps.push_back(vmap); } - else if (!strcmp((const char *) ptr->name, "torus")) - { - std::string url; - const struct _xmlAttr *attr; - for (attr = ptr->properties; attr; attr = attr->next) - { - if (!strcmp((const char *) attr->name, "url")) - url = mp::xml::get_text(attr->children); - else - throw mp::filter::FilterException( - "Bad attribute " + std::string((const char *) - attr->name)); - } - m_p->torus.read_searchables(url); - m_p->refresh_torus(); - } else { throw mp::filter::FilterException