From 0c26d703ff27cfbde7ec568a9ca5659b9d088bd1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 9 Jan 2006 15:32:46 +0000 Subject: [PATCH] Filter virt_db reads XML config --- src/filter_virt_db.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- src/filter_virt_db.hpp | 3 ++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index b4427b2..5ac0c2b 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.17 2006-01-04 11:55:31 adam Exp $ +/* $Id: filter_virt_db.cpp,v 1.18 2006-01-09 15:32:46 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -6,6 +6,7 @@ #include "config.hpp" +#include "xmlutil.hpp" #include "filter.hpp" #include "router.hpp" #include "package.hpp" @@ -862,6 +863,45 @@ void yf::Virt_db::process(Package &package) const } #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" + ); + } + add_map_db2vhost(database, target); + std::cout << "Add " << database << "->" << target << "\n"; + } + else + { + throw yp2::filter::FilterException + ("Bad element " + + std::string((const char *) ptr->name) + + " in virt_db filter"); + } + } +} static yp2::filter::Base* filter_creator() { diff --git a/src/filter_virt_db.hpp b/src/filter_virt_db.hpp index d5065b5..39647ed 100644 --- a/src/filter_virt_db.hpp +++ b/src/filter_virt_db.hpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.hpp,v 1.6 2006-01-04 11:55:32 adam Exp $ +/* $Id: filter_virt_db.hpp,v 1.7 2006-01-09 15:32:46 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -21,6 +21,7 @@ namespace yp2 { ~Virt_db(); Virt_db(); void process(yp2::Package & package) const; + void configure(const xmlNode * ptr); void add_map_db2vhost(std::string db, std::string vhost); private: boost::scoped_ptr m_p; -- 1.7.10.4