X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_virt_db.cpp;h=93ed3d0a238b7af830a913eaa309287241076d7e;hb=0c6b0bda325d897e4c1e959747317fa8e76638f6;hp=e6f23383d597420c59e398508c1e983885621ddb;hpb=8d19ec229f799ca5f13fdf4e64ec9d877d95a92a;p=metaproxy-moved-to-github.git diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index e6f2338..93ed3d0 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -26,12 +26,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "torus.hpp" #include #include #include #include +#include #include #include @@ -53,17 +53,21 @@ namespace metaproxy_1 { }; struct VirtualDB::Map { Map(std::string database, std::list targets, std::string route); + Map(std::string database, std::string target, std::string route); Map(); bool match(const std::string db) const; 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; }; @@ -109,6 +113,7 @@ namespace metaproxy_1 { FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); + void refresh_torus(); private: std::listm_maps; typedef std::map::iterator Sets_it; @@ -116,7 +121,6 @@ namespace metaproxy_1 { boost::condition m_cond_session_ready; std::map m_clients; bool pass_vhosts; - mp::Torus torus; }; } } @@ -177,12 +181,20 @@ 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->m_route) { - // we have a conflict.. + // we have a conflict.. routing must be same for all error_code = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; BackendPtr ptr; 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; @@ -235,8 +247,7 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( // we hope to get an init response error_code = YAZ_BIB1_DATABASE_UNAVAILABLE; 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)) @@ -350,6 +361,20 @@ 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); @@ -439,58 +464,6 @@ void yf::VirtualDB::Rep::release_frontend(mp::Package &package) } } -void yf::VirtualDB::refresh_torus(void) -{ - xmlDoc *doc = m_p->torus.get_doc(); - xmlNode *ptr1 = 0; - if (doc && (ptr1 = xmlDocGetRootElement(doc))) - { - 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; - 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); - } - } - if (solr.length() == 0 && - database.length() && target.length()) - { - add_map_db2target(database, target, route); - } - } - } - } - } - } -} yf::VirtualDB::Set::Set(BackendPtr b, std::string setname) : m_backend(b), m_setname(setname) @@ -513,6 +486,14 @@ yf::VirtualDB::Map::Map(std::string database, { } +yf::VirtualDB::Map::Map(std::string database, + std::string target, std::string route) + : m_dbpattern(database), m_route(route) +{ + m_targets.push_back(target); +} + + yf::VirtualDB::Map::Map() { } @@ -732,6 +713,17 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) &req->num_databaseNames, &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.move(b->m_route); @@ -758,11 +750,10 @@ void yf::VirtualDB::add_map_db2targets(std::string db, void yf::VirtualDB::add_map_db2target(std::string db, std::string target, std::string route) -{ - std::list targets; - targets.push_back(target); - add_map_db2targets(db, targets, route); +{ + m_p->m_maps.push_back( + VirtualDB::Map(mp::util::database_name_normalize(db), target, route)); } void yf::VirtualDB::process(mp::Package &package) const @@ -884,10 +875,11 @@ 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; @@ -900,6 +892,8 @@ 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 " @@ -908,23 +902,11 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only) ); } std::string route = mp::xml::get_route(ptr); - add_map_db2targets(database, targets, route); - } - 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); - refresh_torus(); + + VirtualDB::Map vmap(mp::util::database_name_normalize(database), + targets, route); + vmap.query_encoding = query_encoding; + m_p->m_maps.push_back(vmap); } else {