-/* $Id: filter_virt_db.cpp,v 1.32 2006-01-18 10:30:28 adam Exp $
- Copyright (c) 2005, Index Data.
+/* This file is part of Metaproxy.
+ Copyright (C) 2005-2011 Index Data
-%LICENSE%
- */
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
#include "config.hpp"
-#include "filter.hpp"
-#include "package.hpp"
+#include "filter_virt_db.hpp"
+#include <metaproxy/package.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/shared_ptr.hpp>
-#include "util.hpp"
-#include "filter_virt_db.hpp"
+#include <metaproxy/util.hpp>
#include <yaz/zgdu.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
+#include <yaz/match_glob.h>
+#include <yaz/query-charset.h>
+#include <yaz/log.h>
#include <map>
#include <iostream>
-namespace yf = yp2::filter;
+namespace mp = metaproxy_1;
+namespace yf = mp::filter;
-namespace yp2 {
+namespace metaproxy_1 {
namespace filter {
- struct Virt_db::Set {
+ struct VirtualDB::Set {
Set(BackendPtr b, std::string setname);
Set();
~Set();
BackendPtr m_backend;
std::string m_setname;
};
- struct Virt_db::Map {
- Map(std::list<std::string> targets, std::string route);
+ struct VirtualDB::Map {
+ Map(std::string database, std::list<std::string> 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<std::string> m_targets;
std::string m_route;
+ public:
+ std::string query_encoding;
};
- struct Virt_db::Backend {
- yp2::Session m_backend_session;
+ struct VirtualDB::Backend {
+ mp::Session m_backend_session;
std::list<std::string> m_frontend_databases;
std::list<std::string> m_targets;
std::string m_route;
+ std::string query_encoding;
bool m_named_result_sets;
int m_number_of_sets;
};
- struct Virt_db::Frontend {
+ struct VirtualDB::Frontend {
Frontend(Rep *rep);
~Frontend();
- yp2::Session m_session;
+ mp::Session m_session;
bool m_is_virtual;
bool m_in_use;
yazpp_1::GDU m_init_gdu;
std::list<BackendPtr> m_backend_list;
- std::map<std::string,Virt_db::Set> m_sets;
+ std::map<std::string,VirtualDB::Set> m_sets;
void search(Package &package, Z_APDU *apdu);
void present(Package &package, Z_APDU *apdu);
void scan(Package &package, Z_APDU *apdu);
+ int relay_apdu(Package &package, Z_APDU *apdu);
void close(Package &package);
- typedef std::map<std::string,Virt_db::Set>::iterator Sets_it;
+ typedef std::map<std::string,VirtualDB::Set>::iterator Sets_it;
+ 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<std::string> databases);
BackendPtr create_backend_from_databases(
int &error_code, std::string &addinfo);
Rep *m_p;
};
- class Virt_db::Rep {
- friend class Virt_db;
- friend class Frontend;
+ class VirtualDB::Rep {
+ friend class VirtualDB;
+ friend struct Frontend;
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
+ void refresh_torus();
private:
- boost::mutex m_sessions_mutex;
- std::map<std::string, Virt_db::Map>m_maps;
-
- typedef std::map<std::string,Virt_db::Set>::iterator Sets_it;
-
+ std::list<VirtualDB::Map>m_maps;
+ typedef std::map<std::string,VirtualDB::Set>::iterator Sets_it;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
- std::map<yp2::Session, FrontendPtr> m_clients;
+ std::map<mp::Session, FrontendPtr> m_clients;
+ bool pass_vhosts;
};
}
}
-using namespace yp2;
-
-yf::Virt_db::BackendPtr yf::Virt_db::Frontend::lookup_backend_from_databases(
+yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::lookup_backend_from_databases(
std::list<std::string> databases)
{
std::list<BackendPtr>::const_iterator map_it;
return null;
}
-yf::Virt_db::BackendPtr yf::Virt_db::Frontend::create_backend_from_databases(
+yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::create_backend_from_databases(
std::list<std::string> databases, int &error_code, std::string &addinfo)
{
BackendPtr b(new Backend);
std::map<std::string,bool> targets_dedup;
for (; db_it != databases.end(); db_it++)
{
- std::map<std::string, Virt_db::Map>::iterator map_it;
- map_it = m_p->m_maps.find(*db_it);
+ std::list<VirtualDB::Map>::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_UNAVAILABLE;
+ error_code = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
addinfo = *db_it;
BackendPtr ptr;
return ptr;
}
std::list<std::string>::const_iterator t_it =
- map_it->second.m_targets.begin();
- for (; t_it != map_it->second.m_targets.end(); t_it++)
- targets_dedup[*t_it] = true;
+ 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;
+ b->m_targets.push_back(*t_it);
+ }
+ }
// 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..
+ // 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->second.m_route;
+ 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;
}
- std::map<std::string,bool>::const_iterator tm_it = targets_dedup.begin();
- for (; tm_it != targets_dedup.end(); tm_it++)
- b->m_targets.push_back(tm_it->first);
-
return b;
}
-yf::Virt_db::BackendPtr yf::Virt_db::Frontend::init_backend(
- std::list<std::string> databases, Package &package,
+yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
+ std::list<std::string> databases, mp::Package &package,
int &error_code, std::string &addinfo)
{
BackendPtr b = create_backend_from_databases(databases, error_code,
Package init_package(b->m_backend_session, package.origin());
init_package.copy_filter(package);
- yp2::odr odr;
+ mp::odr odr;
Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest);
- std::list<std::string>::const_iterator t_it = b->m_targets.begin();
- int cat = 1;
- for (; t_it != b->m_targets.end(); t_it++, cat++)
- {
- yaz_oi_set_string_oidval(&init_apdu->u.initRequest->otherInfo, odr,
- VAL_PROXY, cat, t_it->c_str());
- }
-
+ mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo, odr,
+ b->m_targets);
Z_InitRequest *req = init_apdu->u.initRequest;
// copy stuff from Frontend Init Request
req->implementationId = org_init->implementationId;
req->implementationName = org_init->implementationName;
req->implementationVersion = org_init->implementationVersion;
+ *req->preferredMessageSize = *org_init->preferredMessageSize;
+ *req->maximumRecordSize = *org_init->maximumRecordSize;
ODR_MASK_SET(req->options, Z_Options_search);
ODR_MASK_SET(req->options, Z_Options_present);
Z_GDU *gdu = init_package.response().get();
// we hope to get an init response
- if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
- Z_APDU_initResponse)
+ error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
+ if (gdu && gdu->which == Z_GDU_Z3950
+ && gdu->u.z3950->which == Z_APDU_initResponse)
{
Z_InitResponse *res = gdu->u.z3950->u.initResponse;
if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
{
b->m_named_result_sets = true;
}
- std::cout << "GOT INIT res=" << *res->result << "\n";
- if (!*res->result)
+ if (*res->result && !init_package.session().is_closed())
{
- yp2::util::get_init_diagnostics(res, error_code, addinfo);
- BackendPtr null;
- return null;
+ m_backend_list.push_back(b);
+ return b;
}
+ mp::util::get_init_diagnostics(res, error_code, addinfo);
}
- else
- {
- error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
- // addinfo = database;
- BackendPtr null;
- return null;
- }
- if (init_package.session().is_closed())
+ 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::Virt_db::Frontend::search(Package &package, Z_APDU *apdu_req)
+void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
{
Z_SearchRequest *req = apdu_req->u.searchRequest;
std::string vhost;
std::string resultSetId = req->resultSetName;
- yp2::odr odr;
+ mp::odr odr;
std::list<std::string> databases;
int i;
for (i = 0; i<req->num_databaseNames; i++)
databases.push_back(req->databaseNames[i]);
- BackendPtr b; // null for now
Sets_it sets_it = m_sets.find(req->resultSetName);
if (sets_it != m_sets.end())
{
return;
}
sets_it->second.m_backend->m_number_of_sets--;
-
- // pick up any existing backend with a database match
- std::list<BackendPtr>::const_iterator map_it;
- map_it = m_backend_list.begin();
- for (; map_it != m_backend_list.end(); map_it++)
- {
- BackendPtr tmp = *map_it;
- if (tmp->m_frontend_databases == databases)
- break;
- }
- if (map_it != m_backend_list.end())
- b = *map_it;
}
- else
+ // pick up any existing database with named result sets ..
+ // or one which has no result sets.. yet.
+ BackendPtr b; // null for now
+ std::list<BackendPtr>::const_iterator map_it;
+ map_it = m_backend_list.begin();
+ for (; map_it != m_backend_list.end(); map_it++)
{
- // new result set.
-
- // pick up any existing database with named result sets ..
- // or one which has no result sets.. yet.
- std::list<BackendPtr>::const_iterator map_it;
- map_it = m_backend_list.begin();
- for (; map_it != m_backend_list.end(); map_it++)
+ BackendPtr tmp = *map_it;
+ if (tmp->m_frontend_databases == databases &&
+ (tmp->m_named_result_sets ||
+ tmp->m_number_of_sets == 0))
{
- BackendPtr tmp = *map_it;
- if (tmp->m_frontend_databases == databases &&
- (tmp->m_named_result_sets ||
- tmp->m_number_of_sets == 0))
- break;
- }
- if (map_it != m_backend_list.end())
b = *map_it;
+ break;
+ }
}
if (!b) // no backend yet. Must create a new one
{
std::list<std::string>::const_iterator t_it = b->m_targets.begin();
if (t_it != b->m_targets.end())
{
- if (!yp2::util::set_databases_from_zurl(odr, *t_it,
+ mp::util::set_databases_from_zurl(odr, *t_it,
&req->num_databaseNames,
- &req->databaseNames));
+ &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);
package.session().close();
return;
}
- package.response() = search_package.response();
-
b->m_number_of_sets++;
- m_sets[resultSetId] = Virt_db::Set(b, backend_setname);
+ m_sets[resultSetId] = VirtualDB::Set(b, backend_setname);
+ fixup_package(search_package, b);
+ package.response() = search_package.response();
}
-yf::Virt_db::Frontend::Frontend(Rep *rep)
+yf::VirtualDB::Frontend::Frontend(Rep *rep)
{
m_p = rep;
m_is_virtual = false;
}
-void yf::Virt_db::Frontend::close(Package &package)
+void yf::VirtualDB::Frontend::close(mp::Package &package)
{
std::list<BackendPtr>::const_iterator b_it;
m_backend_list.clear();
}
-yf::Virt_db::Frontend::~Frontend()
+yf::VirtualDB::Frontend::~Frontend()
{
}
-yf::Virt_db::FrontendPtr yf::Virt_db::Rep::get_frontend(Package &package)
+yf::VirtualDB::FrontendPtr yf::VirtualDB::Rep::get_frontend(mp::Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<yp2::Session,yf::Virt_db::FrontendPtr>::iterator it;
+ std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
while(true)
{
return f;
}
-void yf::Virt_db::Rep::release_frontend(Package &package)
+void yf::VirtualDB::Rep::release_frontend(mp::Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<yp2::Session,yf::Virt_db::FrontendPtr>::iterator it;
+ std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
it = m_clients.find(package.session());
if (it != m_clients.end())
}
}
-yf::Virt_db::Set::Set(BackendPtr b, std::string setname)
+
+yf::VirtualDB::Set::Set(BackendPtr b, std::string setname)
: m_backend(b), m_setname(setname)
{
}
-yf::Virt_db::Set::Set()
+yf::VirtualDB::Set::Set()
{
}
-yf::Virt_db::Set::~Set()
+yf::VirtualDB::Set::~Set()
{
}
-yf::Virt_db::Map::Map(std::list<std::string> targets, std::string route)
- : m_targets(targets), m_route(route)
+yf::VirtualDB::Map::Map(std::string database,
+ std::list<std::string> targets, std::string route)
+ : m_dbpattern(database), m_targets(targets), m_route(route)
{
}
-yf::Virt_db::Map::Map()
+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::Virt_db::Virt_db() : m_p(new Virt_db::Rep)
+
+yf::VirtualDB::Map::Map()
{
}
-yf::Virt_db::~Virt_db() {
+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;
}
-void yf::Virt_db::Frontend::present(Package &package, Z_APDU *apdu_req)
+yf::VirtualDB::VirtualDB() : m_p(new VirtualDB::Rep)
+{
+ m_p->pass_vhosts = false;
+}
+
+yf::VirtualDB::~VirtualDB() {
+}
+
+void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
+ BackendPtr b)
+{
+ if (npr->databaseName)
+ {
+ std::string b_database = std::string(npr->databaseName);
+
+ // consider each of the frontend databases..
+ std::list<std::string>::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::list<VirtualDB::Map>::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())
+ {
+ std::list<std::string>::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++;
+ }
+ }
+
+ }
+ 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::VirtualDB::Frontend::fixup_npr_records(ODR odr, Z_Records *records,
+ BackendPtr b)
+{
+ if (records && records->which == Z_Records_DBOSD)
+ {
+ Z_NamePlusRecordList *nprlist = records->u.databaseOrSurDiagnostics;
+ int i;
+ for (i = 0; i < nprlist->num_records; i++)
+ {
+ fixup_npr_record(odr, nprlist->records[i], b);
+ }
+ }
+}
+
+void yf::VirtualDB::Frontend::fixup_package(mp::Package &p, BackendPtr b)
+{
+ Z_GDU *gdu = p.response().get();
+ mp::odr odr;
+
+ if (gdu && gdu->which == Z_GDU_Z3950)
+ {
+ 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;
+ }
+ }
+}
+
+void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
Z_PresentRequest *req = apdu_req->u.presentRequest;
std::string resultSetId = req->resultSetId;
- yp2::odr odr;
+ mp::odr odr;
Sets_it sets_it = m_sets.find(resultSetId);
if (sets_it == m_sets.end())
return;
}
Session *id =
- new yp2::Session(sets_it->second.m_backend->m_backend_session);
+ new mp::Session(sets_it->second.m_backend->m_backend_session);
// sending present to backend
Package present_package(*id, package.origin());
present_package.move(sets_it->second.m_backend->m_route);
+ fixup_package(present_package, sets_it->second.m_backend);
+
if (present_package.session().is_closed())
{
package.response() = present_package.response();
delete id;
}
-void yf::Virt_db::Frontend::scan(Package &package, Z_APDU *apdu_req)
+int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req)
+{
+ int no = 0;
+ std::list<BackendPtr>::const_iterator map_it;
+ map_it = m_backend_list.begin();
+ for (; map_it != m_backend_list.end(); map_it++)
+ {
+ BackendPtr b = *map_it;
+
+ Package relay_package(b->m_backend_session, package.origin());
+ relay_package.copy_filter(package);
+
+ relay_package.request() = yazpp_1::GDU(apdu_req);
+
+ relay_package.move(b->m_route);
+ package.response() = relay_package.response();
+ no++;
+ }
+ return no;
+}
+
+void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
{
Z_ScanRequest *req = apdu_req->u.scanRequest;
std::string vhost;
- yp2::odr odr;
+ mp::odr odr;
std::list<std::string> databases;
int i;
std::list<std::string>::const_iterator t_it = b->m_targets.begin();
if (t_it != b->m_targets.end())
{
- if (!yp2::util::set_databases_from_zurl(odr, *t_it,
+ mp::util::set_databases_from_zurl(odr, *t_it,
&req->num_databaseNames,
- &req->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);
}
-void yf::Virt_db::add_map_db2targets(std::string db,
- std::list<std::string> targets,
- std::string route)
+void yf::VirtualDB::add_map_db2targets(std::string db,
+ std::list<std::string> targets,
+ std::string route)
{
- m_p->m_maps[db] = Virt_db::Map(targets, route);
+ m_p->m_maps.push_back(
+ VirtualDB::Map(mp::util::database_name_normalize(db), targets, route));
}
-void yf::Virt_db::add_map_db2target(std::string db,
- std::string target,
- std::string route)
-{
- std::list<std::string> targets;
- targets.push_back(target);
+void yf::VirtualDB::add_map_db2target(std::string db,
+ std::string target,
+ std::string route)
- m_p->m_maps[db] = Virt_db::Map(targets, route);
+{
+ m_p->m_maps.push_back(
+ VirtualDB::Map(mp::util::database_name_normalize(db), target, route));
}
-void yf::Virt_db::process(Package &package) const
+void yf::VirtualDB::process(mp::Package &package) const
{
FrontendPtr f = m_p->get_frontend(package);
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
- const char *vhost =
- yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
- if (!vhost)
+ std::list<std::string> vhosts;
+ mp::util::get_vhost_otherinfo(req->otherInfo, vhosts);
+
+ if (vhosts.size() > 0 && m_p->pass_vhosts)
+ {
+ package.move();
+ }
+ else
{
f->m_init_gdu = gdu;
- yp2::odr odr;
+ mp::odr odr;
Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *resp = apdu->u.initResponse;
else
break;
+ *resp->preferredMessageSize = *req->preferredMessageSize;
+ *resp->maximumRecordSize = *req->maximumRecordSize;
+
package.response() = apdu;
f->m_is_virtual = true;
}
- else
- package.move();
}
else if (!f->m_is_virtual)
package.move();
Z_APDU *apdu = gdu->u.z3950;
if (apdu->which == Z_APDU_initRequest)
{
- yp2::odr odr;
+ mp::odr odr;
package.response() = odr.create_close(
apdu,
{
f->scan(package, apdu);
}
+ else if (apdu->which == Z_APDU_close)
+ {
+ if (f->relay_apdu(package, apdu) == 0)
+ {
+ mp::odr odr;
+
+ package.response() = odr.create_close(
+ apdu, Z_Close_finished, "virt_db");
+
+ package.session().close();
+ }
+ }
else
{
- yp2::odr odr;
+ mp::odr odr;
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
m_p->release_frontend(package);
}
-
-void yp2::filter::Virt_db::configure(const xmlNode * ptr)
+void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only)
{
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
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, false);
+ }
+ else if (!strcmp((const char *) ptr->name, "virtual"))
+ {
+ std::string query_encoding;
std::string database;
std::list<std::string> targets;
xmlNode *v_node = ptr->children;
if (v_node->type != XML_ELEMENT_NODE)
continue;
- if (yp2::xml::is_element_yp2(v_node, "database"))
- database = yp2::xml::get_text(v_node);
- else if (yp2::xml::is_element_yp2(v_node, "target"))
- targets.push_back(yp2::xml::get_text(v_node));
+ if (mp::xml::is_element_mp(v_node, "database"))
+ 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 yp2::filter::FilterException
+ throw mp::filter::FilterException
("Bad element "
+ std::string((const char *) v_node->name)
+ " in virtual section"
);
}
- std::string route = yp2::xml::get_route(ptr);
- add_map_db2targets(database, targets, route);
+ std::string route = mp::xml::get_route(ptr);
+
+ VirtualDB::Map vmap(mp::util::database_name_normalize(database),
+ targets, route);
+ vmap.query_encoding = query_encoding;
+ m_p->m_maps.push_back(vmap);
}
else
{
- throw yp2::filter::FilterException
+ throw mp::filter::FilterException
("Bad element "
+ std::string((const char *) ptr->name)
+ " in virt_db filter");
}
}
-static yp2::filter::Base* filter_creator()
+static mp::filter::Base* filter_creator()
{
- return new yp2::filter::Virt_db;
+ return new mp::filter::VirtualDB;
}
extern "C" {
- struct yp2_filter_struct yp2_filter_virt_db = {
+ struct metaproxy_1_filter_struct metaproxy_1_filter_virt_db = {
0,
"virt_db",
filter_creator
/*
* 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
*/
+