-/* $Id: filter_multi.cpp,v 1.29 2007-11-26 21:21:12 adam Exp $
- Copyright (c) 2005-2007, Index Data.
-
-This file is part of Metaproxy.
+/* This file is part of Metaproxy.
+ Copyright (C) 2005-2010 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
for more details.
You should have received a copy of the GNU General Public License
-along with Metaproxy; see the file LICENSE. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
#include <yaz/log.h>
#include "config.hpp"
-#include "filter.hpp"
-#include "package.hpp"
+#include <metaproxy/filter.hpp>
+#include <metaproxy/package.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/shared_ptr.hpp>
-#include "util.hpp"
+#include <metaproxy/util.hpp>
#include "filter_multi.hpp"
#include <yaz/zgdu.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
+#include <yaz/match_glob.h>
#include <vector>
#include <algorithm>
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;
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;
{
}
-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)
{
}
// skip on each set.. before "present range"..
p = p + skip;
- std::cout << "\nSKIP min=" << min << " no_left=" << no_left << "\n\n";
-
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
*psit += min;
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()));
f_resp->records = z_records_diag;
*f_resp->presentStatus = Z_PresentStatus_failure;
}
+ else if (number < 0 || number > jobs.size())
+ {
+ f_apdu =
+ odr.create_presentResponse(
+ apdu_req,
+ YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
+ 0);
+ }
else
{
f_resp->records = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
{
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)
{
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)
}
}
- if (true)
+ if (false)
{
std::cout << "BEFORE\n";
ScanTermInfoList::iterator it = entries_before.begin();
m_p->release_frontend(package);
}
-void mp::filter::Multi::configure(const xmlNode * ptr)
+void mp::filter::Multi::configure(const xmlNode * ptr, bool test_only)
{
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
{
std::string route = mp::xml::get_route(ptr);
std::string target = mp::xml::get_text(ptr);
- std::cout << "route=" << route << " target=" << target << "\n";
- 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"))
{
/*
* 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
*/
+