-/* $Id: filter_sru_to_z3950.cpp,v 1.14 2006-09-26 13:15:33 marc Exp $
+/* $Id: filter_sru_to_z3950.cpp,v 1.15 2006-09-29 08:42:47 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
namespace mp = metaproxy_1;
+namespace mp_util = metaproxy_1::util;
namespace yf = mp::filter;
-namespace metaproxy_1
-{
-
- template<typename T>
- std::string to_string(const T& t)
- {
- std::ostringstream o;
- if(o << t)
- return o.str();
-
- return std::string();
- }
-
- std::string http_header_value(const Z_HTTP_Header* header,
- const std::string name)
- {
- while (header && header->name
- && std::string(header->name) != name)
- header = header->next;
-
- if (header && header->name && std::string(header->name) == name
- && header->value)
- return std::string(header->value);
-
- return std::string();
- }
-
-
-}
-
namespace metaproxy_1 {
namespace filter {
// building SRU explain record
std::string explain_xml
- = mp::to_string(
+ = mp_util::to_string(
"<explain>\n"
" <serverInfo protocol='SRU'>\n"
" <host>")
+ package.origin().server_host()
- + mp::to_string("</host>\n"
+ + mp_util::to_string("</host>\n"
" <port>")
- + mp::to_string(package.origin().server_port())
- + mp::to_string("</port>\n"
+ + mp_util::to_string(package.origin().server_port())
+ + mp_util::to_string("</port>\n"
" <database>")
+ database
- + mp::to_string("</database>\n"
+ + mp_util::to_string("</database>\n"
" </serverInfo>\n"
"</explain>\n");
const std::string http_method(http_req.method);
const std::string http_type
- = http_header_value(http_req.headers, "Content-Type");
+ = mp_util::http_header_value(http_req.headers, "Content-Type");
if (http_method == "GET")
return "SRU GET";
message += "<b>Path: </b> " + std::string(http_req.path) + "<br/>\n";
message += "<b>Content-Type:</b>"
- + http_header_value(http_req.headers, "Content-Type")
+ + mp_util::http_header_value(http_req.headers, "Content-Type")
+ "<br/>\n";
message += "<b>Content-Length:</b>"
- + http_header_value(http_req.headers, "Content-Length")
+ + mp_util::http_header_value(http_req.headers, "Content-Length")
+ "<br/>\n";
message += "</p>\n";
-/* $Id: filter_virt_db.cpp,v 1.45 2006-08-30 12:27:34 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.46 2006-09-29 08:42:47 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
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 {
+ struct VirtualDB::Map {
Map(std::list<std::string> targets, std::string route);
Map();
std::list<std::string> m_targets;
std::string m_route;
};
- struct Virt_db::Backend {
+ struct VirtualDB::Backend {
mp::Session m_backend_session;
std::list<std::string> m_frontend_databases;
std::list<std::string> m_targets;
bool m_named_result_sets;
int m_number_of_sets;
};
- struct Virt_db::Frontend {
+ struct VirtualDB::Frontend {
Frontend(Rep *rep);
~Frontend();
mp::Session m_session;
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);
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,
int &error_code, std::string &addinfo);
Rep *m_p;
};
- class Virt_db::Rep {
- friend class Virt_db;
+ class VirtualDB::Rep {
+ friend class VirtualDB;
friend struct Frontend;
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
private:
- std::map<std::string, Virt_db::Map>m_maps;
- typedef std::map<std::string,Virt_db::Set>::iterator Sets_it;
+ std::map<std::string, 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<mp::Session, FrontendPtr> m_clients;
}
}
-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;
+ std::map<std::string, VirtualDB::Map>::iterator map_it;
map_it = m_p->m_maps.find(mp::util::database_name_normalize(*db_it));
if (map_it == m_p->m_maps.end()) // database not found
{
return b;
}
-yf::Virt_db::BackendPtr yf::Virt_db::Frontend::init_backend(
+yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
std::list<std::string> databases, mp::Package &package,
int &error_code, std::string &addinfo)
{
return b;
}
-void yf::Virt_db::Frontend::search(mp::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;
}
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(mp::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(mp::Package &package)
+yf::VirtualDB::FrontendPtr yf::VirtualDB::Rep::get_frontend(mp::Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<mp::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(mp::Package &package)
+void yf::VirtualDB::Rep::release_frontend(mp::Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<mp::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)
+yf::VirtualDB::Map::Map(std::list<std::string> targets, std::string route)
: m_targets(targets), m_route(route)
{
}
-yf::Virt_db::Map::Map()
+yf::VirtualDB::Map::Map()
{
}
-yf::Virt_db::Virt_db() : m_p(new Virt_db::Rep)
+yf::VirtualDB::VirtualDB() : m_p(new VirtualDB::Rep)
{
}
-yf::Virt_db::~Virt_db() {
+yf::VirtualDB::~VirtualDB() {
}
-void yf::Virt_db::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
+void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
BackendPtr b)
{
if (npr->databaseName)
db_it != b->m_frontend_databases.end(); db_it++)
{
// see which target it corresponds to.. (if any)
- std::map<std::string,Virt_db::Map>::const_iterator map_it;
+ std::map<std::string,VirtualDB::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;
+ VirtualDB::Map m = map_it->second;
std::list<std::string>::const_iterator t;
for (t = m.m_targets.begin(); t != m.m_targets.end(); t++)
}
}
-void yf::Virt_db::Frontend::fixup_npr_records(ODR odr, Z_Records *records,
+void yf::VirtualDB::Frontend::fixup_npr_records(ODR odr, Z_Records *records,
BackendPtr b)
{
if (records && records->which == Z_Records_DBOSD)
}
}
-void yf::Virt_db::Frontend::fixup_package(mp::Package &p, BackendPtr b)
+void yf::VirtualDB::Frontend::fixup_package(mp::Package &p, BackendPtr b)
{
Z_GDU *gdu = p.response().get();
mp::odr odr;
}
}
-void yf::Virt_db::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
+void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
Z_PresentRequest *req = apdu_req->u.presentRequest;
std::string resultSetId = req->resultSetId;
delete id;
}
-void yf::Virt_db::Frontend::scan(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;
std::string vhost;
}
-void yf::Virt_db::add_map_db2targets(std::string db,
+void yf::VirtualDB::add_map_db2targets(std::string db,
std::list<std::string> targets,
std::string route)
{
m_p->m_maps[mp::util::database_name_normalize(db)]
- = Virt_db::Map(targets, route);
+ = VirtualDB::Map(targets, route);
}
-void yf::Virt_db::add_map_db2target(std::string db,
+void yf::VirtualDB::add_map_db2target(std::string db,
std::string target,
std::string route)
{
targets.push_back(target);
m_p->m_maps[mp::util::database_name_normalize(db)]
- = Virt_db::Map(targets, route);
+ = VirtualDB::Map(targets, route);
}
-void yf::Virt_db::process(mp::Package &package) const
+void yf::VirtualDB::process(mp::Package &package) const
{
FrontendPtr f = m_p->get_frontend(package);
}
-void mp::filter::Virt_db::configure(const xmlNode * ptr)
+void mp::filter::VirtualDB::configure(const xmlNode * ptr)
{
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
static mp::filter::Base* filter_creator()
{
- return new mp::filter::Virt_db;
+ return new mp::filter::VirtualDB;
}
extern "C" {