/* This file is part of Metaproxy.
- Copyright (C) 2005-2008 Index Data
+ 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
#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)
{
}
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()));
bit = m_backend_list.erase(bit);
continue;
}
- no_succeeded++;
-
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initResponse)
for (i = 0; i <= Z_ProtocolVersion_3; i++)
if (!ODR_MASK_GET(b_resp->protocolVersion, i))
ODR_MASK_CLEAR(f_resp->protocolVersion, i);
- // reject if any of the backends reject
- if (!*b_resp->result)
- *f_resp->result = 0;
+ if (*b_resp->result)
+ no_succeeded++;
+ else
+ no_failed++;
}
else
- {
- // if any target does not return init return that (close or
- // similar )
- package.response() = p->response();
- return;
- }
+ no_failed++;
bit++;
}
if (m_p->m_hide_unavailable)
{
if (no_succeeded == 0)
+ {
+ *f_resp->result = 0;
package.session().close();
+ }
}
else
{
if (no_failed)
+ {
+ *f_resp->result = 0;
package.session().close();
+ }
}
package.response() = f_apdu;
}
f_resp->records = z_records_diag;
*f_resp->presentStatus = Z_PresentStatus_failure;
}
+ else if (number < 0 || (size_t) 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)
{
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"))
{