The multi filters target may be be specified as a glob based pattern,
for example <target route="utf8-route">*UTF8</target>.
#include <yaz/zgdu.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
#include <yaz/zgdu.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
+#include <yaz/match_glob.h>
#include <vector>
#include <algorithm>
#include <vector>
#include <algorithm>
void scan2(Package &package, Z_APDU *apdu);
Rep *m_p;
};
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;
+ 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;
};
class Multi::Rep {
friend class Multi;
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
private:
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;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
std::map<mp::Session, FrontendPtr> m_clients;
-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)
{
}
yf::Multi::Multi() : m_p(new Multi::Rep)
{
}
Backend *b = new Backend;
b->m_vhost = *t_it;
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()));
// b->m_route unset
b->m_package = PackagePtr(new Package(s, package.origin()));
{
std::string route = mp::xml::get_route(ptr);
std::string target = mp::xml::get_text(ptr);
{
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"))
{
}
else if (!strcmp((const char *) ptr->name, "hideunavailable"))
{