-/* $Id: filter_virt_db.cpp,v 1.16 2006-01-04 11:19:04 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.20 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
#include "filter.hpp"
-#include "router.hpp"
#include "package.hpp"
#include <boost/thread/mutex.hpp>
namespace filter {
struct Virt_db_set {
Virt_db_set(yp2::Session &id, std::string setname,
- std::string vhost, bool named_result_sets);
+ std::string vhost, std::string route,
+ bool named_result_sets);
Virt_db_set();
~Virt_db_set();
yp2::Session m_backend_session;
std::string m_backend_setname;
std::string m_vhost;
+ std::string m_route;
bool m_named_result_sets;
};
struct Virt_db_session {
std::map<std::string,Virt_db_set> m_sets;
};
struct Virt_db_map {
- Virt_db_map(std::string vhost);
+ Virt_db_map(std::string vhost, std::string route);
Virt_db_map();
std::string m_vhost;
+ std::string m_route;
};
struct Frontend {
Frontend();
Package close_package(sit->second.m_backend_session, package.origin());
close_package.copy_filter(package);
- close_package.move();
+ close_package.move(sit->second.m_route);
}
}
}
yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname,
- std::string vhost, bool named_result_sets)
+ std::string vhost, std::string route,
+ bool named_result_sets)
: m_backend_session(id), m_backend_setname(setname), m_vhost(vhost),
- m_named_result_sets(named_result_sets)
+ m_route(route), m_named_result_sets(named_result_sets)
{
}
{
}
-yf::Virt_db_map::Virt_db_map(std::string vhost)
- : m_vhost(vhost)
+yf::Virt_db_map::Virt_db_map(std::string vhost, std::string route)
+ : m_vhost(vhost), m_route(route)
{
}
Package close_package(sit->second.m_backend_session, package.origin());
close_package.copy_filter(package);
- close_package.move();
+ close_package.move(sit->second.m_route);
}
}
m_sessions.erase(package.session());
std::string vhost;
std::string database;
std::string resultSetId = req->resultSetName;
+ std::string route;
bool support_named_result_sets = false; // whether backend supports it
yp2::odr odr;
{
}
it->second.m_sets.erase(req->resultSetName);
vhost = map_it->second.m_vhost;
+ route = map_it->second.m_route;
}
// we might look for an existing session with same vhost
Session id;
init_package.request() = init_apdu;
- init_package.move(); // sending init
+ init_package.move(route); // sending init
if (init_package.session().is_closed())
{
req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str());
search_package.request() = yazpp_1::GDU(apdu);
- search_package.move();
+ search_package.move(route);
if (search_package.session().is_closed())
{
Ses_it it = m_sessions.find(package.session());
if (it != m_sessions.end())
it->second.m_sets[resultSetId] =
- Virt_db_set(id, backend_resultSetId, vhost,
+ Virt_db_set(id, backend_resultSetId, vhost, route,
support_named_result_sets);
}
}
m_sets.erase(req->resultSetName);
vhost = map_it->second.m_vhost;
+ std::string route = map_it->second.m_route;
// we might look for an existing session with same vhost
Session id;
const char *vhost_cstr = vhost.c_str();
init_package.request() = init_apdu;
- init_package.move(); // sending init
+ init_package.move(route); // sending init
if (init_package.session().is_closed())
{
req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str());
search_package.request() = yazpp_1::GDU(apdu);
- search_package.move();
+ search_package.move(route);
if (search_package.session().is_closed())
{
package.response() = search_package.response();
m_sets[resultSetId] =
- Virt_db_set(id, backend_resultSetId, vhost,
+ Virt_db_set(id, backend_resultSetId, vhost, route,
support_named_result_sets);
}
}
}
-void yf::Virt_db::add_map_db2vhost(std::string db, std::string vhost)
+void yf::Virt_db::add_map_db2vhost(std::string db, std::string vhost,
+ std::string route)
{
- m_p->m_maps[db] = Virt_db_map(vhost);
+ m_p->m_maps[db] = Virt_db_map(vhost, route);
}
#if 0
}
#endif
+void yp2::filter::Virt_db::configure(const xmlNode * ptr)
+{
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) ptr->name, "virtual"))
+ {
+ std::string database;
+ std::string target;
+ xmlNode *v_node = ptr->children;
+ for (; v_node; v_node = v_node->next)
+ {
+ 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"))
+ target = yp2::xml::get_text(v_node);
+ else
+ throw yp2::filter::FilterException
+ ("Bad element "
+ + std::string((const char *) v_node->name)
+ + " in virtual section"
+ );
+ }
+ std::string route = yp2::xml::get_route(ptr);
+ add_map_db2vhost(database, target, route);
+ std::cout << "Add " << database << "->" << target
+ << "," << route << "\n";
+ }
+ else
+ {
+ throw yp2::filter::FilterException
+ ("Bad element "
+ + std::string((const char *) ptr->name)
+ + " in virt_db filter");
+ }
+ }
+}
static yp2::filter::Base* filter_creator()
{
}
extern "C" {
- const struct yp2_filter_struct yp2_filter_virt_db = {
+ struct yp2_filter_struct yp2_filter_virt_db = {
0,
"virt_db",
filter_creator