Named routes for filter virt_db. Example in etc/config2.xml
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 11 Jan 2006 11:51:49 +0000 (11:51 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 11 Jan 2006 11:51:49 +0000 (11:51 +0000)
20 files changed:
configure.ac
etc/config2.xml [new file with mode: 0644]
src/ex_filter_frontend_net.cpp
src/filter.cpp
src/filter.hpp
src/filter_frontend_net.cpp
src/filter_log.cpp
src/filter_virt_db.cpp
src/filter_virt_db.hpp
src/filter_z3950_client.cpp
src/package.cpp
src/package.hpp
src/router.hpp
src/router_chain.cpp
src/router_flexml.cpp
src/router_flexml.hpp
src/test_filter_virt_db.cpp
src/test_router_flexml.cpp
src/xmlutil.cpp
src/xmlutil.hpp

index 6c5246f..6f171c6 100644 (file)
@@ -3,7 +3,7 @@
 
 # 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)
 
diff --git a/etc/config2.xml b/etc/config2.xml
new file mode 100644 (file)
index 0000000..d6f4338
--- /dev/null
@@ -0,0 +1,46 @@
+<?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>
+
index 44e12f2..2abf158 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -104,9 +104,11 @@ int main(int argc, char **argv)
 
             // 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;
index f28700d..150b90f 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -9,10 +9,9 @@
 #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:
index 9b13cfb..d61fa45 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -10,6 +10,7 @@
 #include <string>
 #include <stdexcept>
 #include <libxml/tree.h>
+#include "xmlutil.hpp"
 
 namespace yp2 {
 
@@ -23,7 +24,7 @@ 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 {
index cd4dd14..3554d63 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -6,7 +6,6 @@
 
 #include "config.hpp"
 
-#include "xmlutil.hpp"
 #include "pipe.hpp"
 #include "filter.hpp"
 #include "package.hpp"
index 2f521d2..96a6f7d 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -6,7 +6,6 @@
 
 #include "config.hpp"
 
-#include "xmlutil.hpp"
 #include "package.hpp"
 
 #include <string>
index e314451..20ae5c9 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -6,7 +6,6 @@
 
 #include "config.hpp"
 
-#include "xmlutil.hpp"
 #include "filter.hpp"
 #include "package.hpp"
 
@@ -29,13 +28,15 @@ namespace yp2 {
     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 {
@@ -46,9 +47,10 @@ namespace yp2 {
             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();
@@ -104,7 +106,7 @@ void yf::Frontend::close(Package &package)
         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);
     }
 }
 
@@ -162,9 +164,10 @@ void yf::Virt_db::Rep::release_frontend(Package &package)
 }
 
 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)
 {
 }
 
@@ -178,8 +181,8 @@ yf::Virt_db_set::~Virt_db_set()
 {
 }
 
-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) 
 {
 }
 
@@ -222,7 +225,7 @@ void yf::Virt_db::Rep::release_session(Package &package)
             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());
@@ -369,6 +372,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     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;
     {
@@ -442,6 +446,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
         }
         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;
@@ -458,7 +463,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
         
         init_package.request() = init_apdu;
 
-        init_package.move();  // sending init 
+        init_package.move(route);  // sending init 
 
         if (init_package.session().is_closed())
         {
@@ -510,7 +515,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     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())
     {
@@ -532,7 +537,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later)
     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);
 }
 
@@ -599,6 +604,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu,
     }
     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();
@@ -614,7 +620,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu,
         
         init_package.request() = init_apdu;
 
-        init_package.move();  // sending init 
+        init_package.move(route);  // sending init 
 
         if (init_package.session().is_closed())
         {
@@ -666,7 +672,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu,
     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())
     {
@@ -685,7 +691,7 @@ void yf::Frontend::search(Package &package, Z_APDU *apdu,
     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);
 }
 
@@ -735,9 +741,10 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later)
     }
 }
 
-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
@@ -889,8 +896,10 @@ void yp2::filter::Virt_db::configure(const xmlNode * ptr)
                          + " 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
         {
index 39647ed..7ce5dce 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -22,7 +22,8 @@ namespace yp2 {
             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;
         };
index 44d5450..7c0d88f 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -6,7 +6,6 @@
 
 #include "config.hpp"
 
-#include "xmlutil.hpp"
 #include "filter.hpp"
 #include "package.hpp"
 #include "util.hpp"
index 165145f..2e3276b 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -35,12 +35,24 @@ void yp2::Package::move()
 {
     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;
index 85bcb45..ee9516b 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -41,6 +41,9 @@ namespace yp2 {
 
         /// 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();
index 72ee73e..5c5ce07 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -34,7 +34,7 @@ namespace yp2
 
     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() {};
     };
index 7d7e779..0114fd2 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -19,7 +19,7 @@ namespace yp2
     };
     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;
@@ -35,7 +35,7 @@ yp2::RouterChain::~RouterChain()
 {
 }
 
-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;
index e24fa19..0f6619b 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -65,7 +65,7 @@ namespace yp2 {
 
     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;
@@ -106,7 +106,7 @@ bool yp2::RouterFleXML::Rep::check_element_yp2(const xmlNode *ptr,
                                                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;
 }
 
@@ -135,8 +135,8 @@ void yp2::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
             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);
@@ -144,7 +144,7 @@ void yp2::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
         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);
@@ -176,9 +176,9 @@ void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
             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;
@@ -207,9 +207,9 @@ void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
                 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())
             {
@@ -217,7 +217,8 @@ void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
                     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);
             }
@@ -236,7 +237,8 @@ void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
         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);
@@ -246,7 +248,7 @@ void yp2::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
 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);
     
@@ -269,8 +271,8 @@ void yp2::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr 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);
     }
@@ -284,6 +286,13 @@ void yp2::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc)
     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)
@@ -311,7 +320,7 @@ yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FactoryFilter &factory
     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);
@@ -323,8 +332,19 @@ yp2::RouterFleXML::~RouterFleXML()
 {
 }
 
-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();
index aa68125..6cd78e4 100644 (file)
@@ -1,9 +1,12 @@
-/* $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"
@@ -26,9 +29,9 @@ namespace yp2
         ~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:
@@ -36,7 +39,7 @@ namespace yp2
     };
  
 };
-
+#endif
 
 /*
  * Local variables:
index 4ec8efc..0a581b1 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -202,7 +202,7 @@ BOOST_AUTO_UNIT_TEST( test_filter_virt_db_3 )
    
         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);
index 1a30019..99aa27c 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -43,13 +43,13 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
             "      <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"  
@@ -95,7 +95,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
         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;
     }
@@ -121,7 +121,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_3 )
             "      <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"  
index c2aef1a..eca6f16 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -33,6 +33,30 @@ bool yp2::xml::is_element_yp2(const xmlNode *ptr,
     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:
index ac0409c..6a2cc5d 100644 (file)
@@ -1,4 +1,4 @@
-/* $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%
@@ -18,7 +18,14 @@ namespace yp2 {
                         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