Update to use Odr_int
[metaproxy-moved-to-github.git] / src / filter_multi.cpp
index 3952649..f728724 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2008 Index Data
+   Copyright (C) 2005-2009 Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/zgdu.h>
 #include <yaz/otherinfo.h>
 #include <yaz/diagbib1.h>
+#include <yaz/match_glob.h>
 
 #include <vector>
 #include <algorithm>
@@ -106,11 +107,20 @@ namespace metaproxy_1 {
             void scan2(Package &package, Z_APDU *apdu);
             Rep *m_p;
         };            
-        struct Multi::Map {
-            Map(std::list<std::string> hosts, std::string route);
-            Map();
-            std::list<std::string> 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<std::string,std::string> m_target_route;
+            std::list<Multi::Map> m_route_patterns;
             boost::mutex m_mutex;
             boost::condition m_cond_session_ready;
             std::map<mp::Session, FrontendPtr> m_clients;
@@ -212,15 +222,6 @@ yf::Multi::FrontendSet::~FrontendSet()
 {
 }
 
-yf::Multi::Map::Map(std::list<std::string> 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<Multi::Map>::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()));
 
@@ -968,7 +976,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
                     {
                         ScanTermInfo my;
 
-                        int *occur = ent->u.termInfo->globalOccurrences;
+                        Odr_int *occur = ent->u.termInfo->globalOccurrences;
                         my.m_count = occur ? *occur : 0;
 
                         if (ent->u.termInfo->term->which == Z_Term_general)
@@ -1009,7 +1017,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
                     {
                         ScanTermInfo my;
 
-                        int *occur = ent->u.termInfo->globalOccurrences;
+                        Odr_int *occur = ent->u.termInfo->globalOccurrences;
                         my.m_count = occur ? *occur : 0;
 
                         if (ent->u.termInfo->term->which == Z_Term_general)
@@ -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"))
         {
@@ -1225,8 +1233,9 @@ extern "C" {
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+