From 5d4b02d90ec640b97faac0b8e0629c84dd333d2a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 Jul 2009 11:41:46 +0200 Subject: [PATCH] Routing target pattern may be glob pattern based The multi filters target may be be specified as a glob based pattern, for example *UTF8. --- src/filter_multi.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index b0bf21f..33367e7 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include @@ -106,11 +107,20 @@ namespace metaproxy_1 { void scan2(Package &package, Z_APDU *apdu); Rep *m_p; }; - struct Multi::Map { - Map(std::list hosts, std::string route); - Map(); - std::list m_hosts; + class Multi::Map { + std::string m_target_pattern; std::string m_route; + public: + Map(std::string pattern, std::string route) : + m_target_pattern(pattern), m_route(route) {}; + bool match(const std::string target, std::string *ret) const { + if (yaz_match_glob(m_target_pattern.c_str(), target.c_str())) + { + *ret = m_route; + return true; + } + return false; + }; }; class Multi::Rep { friend class Multi; @@ -120,7 +130,7 @@ namespace metaproxy_1 { FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); private: - std::map m_target_route; + std::list m_route_patterns; boost::mutex m_mutex; boost::condition m_cond_session_ready; std::map m_clients; @@ -212,15 +222,6 @@ yf::Multi::FrontendSet::~FrontendSet() { } -yf::Multi::Map::Map(std::list hosts, std::string route) - : m_hosts(hosts), m_route(route) -{ -} - -yf::Multi::Map::Map() -{ -} - yf::Multi::Multi() : m_p(new Multi::Rep) { } @@ -388,7 +389,14 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) Backend *b = new Backend; b->m_vhost = *t_it; - b->m_route = m_p->m_target_route[*t_it]; + std::list::const_iterator it = + m_p->m_route_patterns.begin(); + while (it != m_p->m_route_patterns.end()) { + if (it->match(*t_it, &b->m_route)) + break; + it++; + } + // b->m_route = m_p->m_target_route[*t_it]; // b->m_route unset b->m_package = PackagePtr(new Package(s, package.origin())); @@ -1180,7 +1188,7 @@ void mp::filter::Multi::configure(const xmlNode * ptr, bool test_only) { std::string route = mp::xml::get_route(ptr); std::string target = mp::xml::get_text(ptr); - m_p->m_target_route[target] = route; + m_p->m_route_patterns.push_back(Multi::Map(target, route)); } else if (!strcmp((const char *) ptr->name, "hideunavailable")) { -- 1.7.10.4