# Autoconf and automake setup
AC_PREREQ(2.57)
-AC_INIT(yp2, 0.0.1, marc@indexdata.dk)
+AC_INIT(yp2, 0.0.1, adam@indexdata.dk)
AC_CONFIG_HEADERS(src/config.hpp)
--- /dev/null
+<?xml version="1.0"?>
+<!-- $Id: config2.xml,v 1.1 2006-01-11 11:51:49 adam Exp $ -->
+<yp2 xmlns="http://indexdata.dk/yp2/config/1">
+ <start route="start"/>
+ <filters>
+ <filter id="frontend" type="frontend_net">
+ <threads>10</threads>
+ <port>@:9000</port>
+ </filter>
+ </filters>
+ <routes>
+ <route id="start">
+ <filter refid="frontend"/>
+ <filter type="log">
+ <message>F</message>
+ </filter>
+ <filter type="virt_db">
+ <virtual>
+ <database>loc</database>
+ <target>z3950.loc.gov:7090/voyager</target>
+ </virtual>
+ <virtual>
+ <database>idgils</database>
+ <target>indexdata.dk/gils</target>
+ </virtual>
+ <virtual route="test">
+ <database>test</database>
+ <target>localhost:9999</target>
+ </virtual>
+ </filter>
+ <filter type="log">
+ <message>B</message>
+ </filter>
+ <filter type="z3950_client">
+ <timeout>30</timeout>
+ </filter>
+ </route>
+ <route id="test">
+ <filter type="log">
+ <message>T</message>
+ </filter>
+ <filter type="backend_test"/>
+ </route>
+ </routes>
+</yp2>
+
-/* $Id: ex_filter_frontend_net.cpp,v 1.21 2006-01-09 13:43:59 adam Exp $
+/* $Id: ex_filter_frontend_net.cpp,v 1.22 2006-01-11 11:51:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
// put Virt db filter in router
yp2::filter::Virt_db filter_virt_db;
- filter_virt_db.add_map_db2vhost("gils", "indexdata.dk/gils");
- filter_virt_db.add_map_db2vhost("Default", "localhost:9999/Default");
- filter_virt_db.add_map_db2vhost("2", "localhost:9999/2");
+ filter_virt_db.add_map_db2vhost("gils", "indexdata.dk/gils",
+ "");
+ filter_virt_db.add_map_db2vhost("Default", "localhost:9999/Default",
+ "");
+ filter_virt_db.add_map_db2vhost("2", "localhost:9999/2", "");
// router.append(filter_virt_db);
yp2::filter::SessionShared filter_session_shared;
-/* $Id: filter.cpp,v 1.3 2005-11-07 21:57:10 adam Exp $
+/* $Id: filter.cpp,v 1.4 2006-01-11 11:51:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
#include "filter.hpp"
-
-// defining and initializing static members
-// std::string yp2::filter::Base:m_type("Base");
-
+void yp2::filter::Base::configure(const xmlNode * ptr)
+{
+}
/*
* Local variables:
-/* $Id: filter.hpp,v 1.14 2006-01-09 21:20:15 adam Exp $
+/* $Id: filter.hpp,v 1.15 2006-01-11 11:51:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <string>
#include <stdexcept>
#include <libxml/tree.h>
+#include "xmlutil.hpp"
namespace yp2 {
///sends Package off to next Filter, returns altered Package
virtual void process(Package & package) const = 0;
- virtual void configure(const xmlNode * ptr) { };
+ virtual void configure(const xmlNode * ptr);
};
class FilterException : public std::runtime_error {
-/* $Id: filter_frontend_net.cpp,v 1.14 2006-01-09 21:19:11 adam Exp $
+/* $Id: filter_frontend_net.cpp,v 1.15 2006-01-11 11:51:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
-#include "xmlutil.hpp"
#include "pipe.hpp"
#include "filter.hpp"
#include "package.hpp"
-/* $Id: filter_log.cpp,v 1.14 2006-01-11 08:53:52 adam Exp $
+/* $Id: filter_log.cpp,v 1.15 2006-01-11 11:51:49 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
-#include "xmlutil.hpp"
#include "package.hpp"
#include <string>
-/* $Id: filter_virt_db.cpp,v 1.19 2006-01-09 21:20:15 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 "xmlutil.hpp"
#include "filter.hpp"
#include "package.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
+ " in virtual section"
);
}
- add_map_db2vhost(database, target);
- std::cout << "Add " << database << "->" << target << "\n";
+ std::string route = yp2::xml::get_route(ptr);
+ add_map_db2vhost(database, target, route);
+ std::cout << "Add " << database << "->" << target
+ << "," << route << "\n";
}
else
{
-/* $Id: filter_virt_db.hpp,v 1.7 2006-01-09 15:32:46 adam Exp $
+/* $Id: filter_virt_db.hpp,v 1.8 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
Virt_db();
void process(yp2::Package & package) const;
void configure(const xmlNode * ptr);
- void add_map_db2vhost(std::string db, std::string vhost);
+ void add_map_db2vhost(std::string db, std::string vhost,
+ std::string route);
private:
boost::scoped_ptr<Rep> m_p;
};
-/* $Id: filter_z3950_client.cpp,v 1.18 2006-01-09 21:20:15 adam Exp $
+/* $Id: filter_z3950_client.cpp,v 1.19 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
-#include "xmlutil.hpp"
#include "filter.hpp"
#include "package.hpp"
#include "util.hpp"
-/* $Id: package.cpp,v 1.5 2006-01-09 13:53:13 adam Exp $
+/* $Id: package.cpp,v 1.6 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
{
if (m_route_pos)
{
- const filter::Base *next_filter = m_route_pos->move();
+ const filter::Base *next_filter = m_route_pos->move(0);
if (next_filter)
next_filter->process(*this);
}
}
+void yp2::Package::move(std::string route)
+{
+ if (m_route_pos)
+ {
+ const char *r_cstr = route.length() ? route.c_str() : 0;
+ const filter::Base *next_filter = m_route_pos->move(r_cstr);
+ if (next_filter)
+ next_filter->process(*this);
+ }
+}
+
+
yp2::Session & yp2::Package::session()
{
return m_session;
-/* $Id: package.hpp,v 1.13 2006-01-09 13:53:13 adam Exp $
+/* $Id: package.hpp,v 1.14 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
/// send Package to it's next Filter defined in Router
void move();
+
+ /// send Package to other route
+ void move(std::string route);
/// access session - left val in assignment
yp2::Session & session();
-/* $Id: router.hpp,v 1.9 2006-01-09 13:53:13 adam Exp $
+/* $Id: router.hpp,v 1.10 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
class RoutePos : boost::noncopyable {
public:
- virtual const filter::Base *move() = 0;
+ virtual const filter::Base *move(const char *route) = 0;
virtual RoutePos *clone() = 0;
virtual ~RoutePos() {};
};
-/* $Id: router_chain.cpp,v 1.4 2006-01-09 13:53:13 adam Exp $
+/* $Id: router_chain.cpp,v 1.5 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
};
class RouterChain::Pos : public RoutePos {
public:
- virtual const filter::Base *move();
+ virtual const filter::Base *move(const char *route);
virtual RoutePos *clone();
virtual ~Pos();
std::list<const filter::Base *>::const_iterator it;
{
}
-const yp2::filter::Base *yp2::RouterChain::Pos::move()
+const yp2::filter::Base *yp2::RouterChain::Pos::move(const char *route)
{
if (it == m_p->m_filter_list.end())
return 0;
-/* $Id: router_flexml.cpp,v 1.12 2006-01-09 13:53:13 adam Exp $
+/* $Id: router_flexml.cpp,v 1.13 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
class RouterFleXML::Pos : public RoutePos {
public:
- virtual const filter::Base *move();
+ virtual const filter::Base *move(const char *route);
virtual RoutePos *clone();
virtual ~Pos();
yp2::RouterFleXML::Rep *m_p;
const std::string &name)
{
if (!yp2::xml::is_element_yp2(ptr, name))
- throw XMLError("Expected element name " + name);
+ throw yp2::XMLError("Expected element name " + name);
return true;
}
else if (name == "type")
type_value = value;
else
- throw XMLError("Only attribute id or type allowed"
- " in filter element. Got " + name);
+ throw yp2::XMLError("Only attribute id or type allowed"
+ " in filter element. Got " + name);
}
yp2::filter::Base* filter_base = m_factory->create(type_value);
filter_base->configure(node);
if (m_id_filter_map.find(id_value) != m_id_filter_map.end())
- throw XMLError("Filter " + id_value + " already defined");
+ throw yp2::XMLError("Filter " + id_value + " already defined");
m_id_filter_map[id_value] =
boost::shared_ptr<yp2::filter::Base>(filter_base);
if (name == "id")
id_value = value;
else
- throw XMLError("Only attribute 'id' allowed for element"
- "'route'."
- " Got " + name);
+ throw yp2::XMLError("Only attribute 'id' allowed for"
+ " element 'route'."
+ " Got " + name);
}
Route route;
else if (name == "type")
type_value = value;
else
- throw XMLError("Only attribute 'refid' or 'type'"
- " allowed for element 'filter'."
- " Got " + name);
+ throw yp2::XMLError("Only attribute 'refid' or 'type'"
+ " allowed for element 'filter'."
+ " Got " + name);
}
if (refid_value.length())
{
boost::shared_ptr<const yp2::filter::Base > >::iterator it;
it = m_id_filter_map.find(refid_value);
if (it == m_id_filter_map.end())
- throw XMLError("Unknown filter refid " + refid_value);
+ throw yp2::XMLError("Unknown filter refid "
+ + refid_value);
else
route.m_list.push_back(it->second);
}
std::map<std::string,RouterFleXML::Route>::iterator it;
it = m_routes.find(id_value);
if (it != m_routes.end())
- throw XMLError("Route id='" + id_value + "' already exist");
+ throw yp2::XMLError("Route id='" + id_value
+ + "' already exist");
else
m_routes[id_value] = route;
node = jump_to_next(node, XML_ELEMENT_NODE);
void yp2::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc)
{
if (!doc)
- throw XMLError("Empty XML Document");
+ throw yp2::XMLError("Empty XML Document");
const xmlNode* root = xmlDocGetRootElement(doc);
if (name == "route")
m_start_route = value;
else
- throw XMLError("Only attribute start allowed"
- " in element 'start'. Got " + name);
+ throw yp2::XMLError("Only attribute start allowed"
+ " in element 'start'. Got " + name);
}
node = jump_to_next(node, XML_ELEMENT_NODE);
}
check_element_yp2(node, "routes");
parse_xml_routes(doc, jump_to_children(node, XML_ELEMENT_NODE));
+
+ node = jump_to_next(node, XML_ELEMENT_NODE);
+ if (node)
+ {
+ throw yp2::XMLError("Unexpected element "
+ + std::string((const char *)node->name));
+ }
}
yp2::RouterFleXML::Rep::Rep() : m_xinclude(false)
xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(),
xmlconf.size());
if (!doc)
- throw XMLError("xmlParseMemory failed");
+ throw yp2::XMLError("xmlParseMemory failed");
else
{
m_p->base(doc, factory);
{
}
-const yp2::filter::Base *yp2::RouterFleXML::Pos::move()
+const yp2::filter::Base *yp2::RouterFleXML::Pos::move(const char *route)
{
+ if (route && *route)
+ {
+ std::cout << "move to " << route << "\n";
+ m_route_it = m_p->m_routes.find(route);
+ if (m_route_it == m_p->m_routes.end())
+ {
+ std::cout << "no such route " << route << "\n";
+ throw yp2::XMLError("bad route " + std::string(route));
+ }
+ m_filter_it = m_route_it->second.m_list.begin();
+ }
if (m_filter_it == m_route_it->second.m_list.end())
return 0;
const yp2::filter::Base *f = (*m_filter_it).get();
-/* $Id: router_flexml.hpp,v 1.12 2006-01-09 13:53:13 adam Exp $
+/* $Id: router_flexml.hpp,v 1.13 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
*/
+#ifndef ROUTER_FLEXML_HPP
+#define ROUTER_FLEXML_HPP
+
#include "router.hpp"
#include "factory_filter.hpp"
~RouterFleXML();
virtual RoutePos *createpos() const;
- class XMLError : public std::runtime_error {
+ class XMLError1 : public std::runtime_error {
public:
- XMLError(const std::string msg) :
+ XMLError1(const std::string msg) :
std::runtime_error("XMLError : " + msg) {} ;
};
private:
};
};
-
+#endif
/*
* Local variables:
-/* $Id: test_filter_virt_db.cpp,v 1.9 2005-12-02 12:21:07 adam Exp $
+/* $Id: test_filter_virt_db.cpp,v 1.10 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
yp2::filter::Virt_db vdb;
router.append(vdb);
- vdb.add_map_db2vhost("Default", "localhost:210");
+ vdb.add_map_db2vhost("Default", "localhost:210", "");
yp2::filter::Log filter_log2("BACK");
#if 0
router.append(filter_log2);
-/* $Id: test_router_flexml.cpp,v 1.13 2006-01-09 13:43:59 adam Exp $
+/* $Id: test_router_flexml.cpp,v 1.14 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
" <port>@:210</port>\n"
" </filter>\n"
" <filter id=\"log_cout1\" type=\"log\">\n"
- " <logfile>mylog1.log</logfile>\n"
+ " <message>my msg</message>\n"
" </filter>\n"
" <filter id=\"tfilter_id\" type=\"tfilter\">\n"
" <someelement/>\n"
" </filter>\n"
" <filter id=\"log_cout2\" type=\"log\">\n"
- " <logfile>mylog2.log</logfile>\n"
+ " <message>other</message>\n"
" </filter>\n"
" </filters>\n"
" <routes>\n"
yp2::FactoryFilter factory;
yp2::RouterFleXML rflexml(xmlconf_invalid, factory);
}
- catch ( yp2::RouterFleXML::XMLError &e) {
+ catch ( yp2::XMLError &e) {
std::cout << "XMLError: " << e.what() << "\n";
got_error_as_expected = true;
}
" <port>@:210</port>\n"
" </y:filter>\n"
" <y:filter id=\"log_cout\" type=\"log\">\n"
- " <logfile>mylog.log</logfile>\n"
+ " <message>my msg</message>\n"
" </y:filter>\n"
" </y:filters>\n"
" <y:routes>\n"
-/* $Id: xmlutil.cpp,v 1.1 2006-01-09 13:43:59 adam Exp $
+/* $Id: xmlutil.cpp,v 1.2 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
return yp2::xml::is_element(ptr, "http://indexdata.dk/yp2/config/1", name);
}
+std::string yp2::xml::get_route(const xmlNode *node)
+{
+ std::string route_value;
+ if (node)
+ {
+ const struct _xmlAttr *attr;
+ for (attr = node->properties; attr; attr = attr->next)
+ {
+ std::string name = std::string((const char *) attr->name);
+ std::string value;
+
+ if (attr->children && attr->children->type == XML_TEXT_NODE)
+ value = std::string((const char *)attr->children->content);
+
+ if (name == "route")
+ route_value = value;
+ else
+ throw XMLError("Only attribute route allowed"
+ " in " + std::string((const char *)node->name)
+ + " element. Got " + std::string(name));
+ }
+ }
+ return route_value;
+}
/*
* Local variables:
-/* $Id: xmlutil.hpp,v 1.1 2006-01-09 13:43:59 adam Exp $
+/* $Id: xmlutil.hpp,v 1.2 2006-01-11 11:51:50 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
const std::string &ns,
const std::string &name);
bool is_element_yp2(const xmlNode *ptr, const std::string &name);
+ std::string get_route(const xmlNode *node);
+
}
+ class XMLError : public std::runtime_error {
+ public:
+ XMLError(const std::string msg) :
+ std::runtime_error("XMLError : " + msg) {} ;
+ };
}
#endif