projects
/
metaproxy-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Filter multu: scan opt part of init response
[metaproxy-moved-to-github.git]
/
src
/
filter_multi.cpp
diff --git
a/src/filter_multi.cpp
b/src/filter_multi.cpp
index
f02ecc7
..
c0a03fb
100644
(file)
--- a/
src/filter_multi.cpp
+++ b/
src/filter_multi.cpp
@@
-1,7
+1,5
@@
-/* $Id: filter_multi.cpp,v 1.28 2007-11-18 10:44:40 adam Exp $
- Copyright (c) 2005-2007, Index Data.
-
-This file is part of Metaproxy.
+/* This file is part of Metaproxy.
+ Copyright (C) 2005-2011 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
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
@@
-14,29
+12,29
@@
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
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 <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 <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 "filter_multi.hpp"
#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>
@@
-67,10
+65,13
@@
namespace metaproxy_1 {
Z_Entry *get_entry(ODR odr);
};
struct Multi::FrontendSet {
Z_Entry *get_entry(ODR odr);
};
struct Multi::FrontendSet {
- struct PresentJob {
+ class PresentJob {
+ public:
BackendPtr m_backend;
BackendPtr m_backend;
- int m_pos;
- int m_inside_pos;
+ int m_pos; // position for backend (1=first, 2=second,..
+ int m_start; // present request start
+ PresentJob(BackendPtr ptr, int pos) :
+ m_backend(ptr), m_pos(pos), m_start(0) {};
};
FrontendSet(std::string setname);
FrontendSet();
};
FrontendSet(std::string setname);
FrontendSet();
@@
-106,11
+107,20
@@
namespace metaproxy_1 {
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;
std::string m_route;
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;
};
class Multi::Rep {
friend class Multi;
@@
-120,7
+130,7
@@
namespace metaproxy_1 {
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;
@@
-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)
{
}
yf::Multi::Multi() : m_p(new Multi::Rep)
{
}
@@
-274,10
+275,7
@@
void yf::Multi::FrontendSet::serve_order(int start, int number,
{
if (offset >= voffset && offset < voffset + bsit->m_count)
{
{
if (offset >= voffset && offset < voffset + bsit->m_count)
{
- PresentJob job;
- job.m_backend = bsit->m_backend;
- job.m_inside_pos = 0;
- job.m_pos = offset - voffset + 1;
+ PresentJob job(bsit->m_backend, offset - voffset + 1);
jobs.push_back(job);
break;
}
jobs.push_back(job);
break;
}
@@
-290,12
+288,10
@@
void yf::Multi::FrontendSet::round_robin(int start, int number,
std::list<PresentJob> &jobs)
{
std::list<int> pos;
std::list<PresentJob> &jobs)
{
std::list<int> pos;
- std::list<int> inside_pos;
std::list<BackendSet>::const_iterator bsit;
for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end(); bsit++)
{
pos.push_back(1);
std::list<BackendSet>::const_iterator bsit;
for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end(); bsit++)
{
pos.push_back(1);
- inside_pos.push_back(0);
}
int p = 1;
}
int p = 1;
@@
-334,8
+330,6
@@
void yf::Multi::FrontendSet::round_robin(int start, int number,
// skip on each set.. before "present range"..
p = p + skip;
// 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;
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
*psit += min;
@@
-349,10
+343,9
@@
void yf::Multi::FrontendSet::round_robin(int start, int number,
{
more = false;
std::list<int>::iterator psit = pos.begin();
{
more = false;
std::list<int>::iterator psit = pos.begin();
- std::list<int>::iterator esit = inside_pos.begin();
bsit = m_backend_sets.begin();
bsit = m_backend_sets.begin();
- for (; bsit != m_backend_sets.end(); psit++,esit++,bsit++)
+ for (; bsit != m_backend_sets.end(); psit++,bsit++)
{
if (fetched >= number)
{
{
if (fetched >= number)
{
@@
-363,12
+356,8
@@
void yf::Multi::FrontendSet::round_robin(int start, int number,
{
if (p >= start)
{
{
if (p >= start)
{
- PresentJob job;
- job.m_backend = bsit->m_backend;
- job.m_pos = *psit;
- job.m_inside_pos = *esit;
+ PresentJob job(bsit->m_backend, *psit);
jobs.push_back(job);
jobs.push_back(job);
- (*esit)++;
fetched++;
}
(*psit)++;
fetched++;
}
(*psit)++;
@@
-400,7
+389,14
@@
void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
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()));
@@
-421,6
+417,8
@@
void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo,
odr, vhost_one);
mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo,
odr, vhost_one);
+ init_apdu->u.initRequest->idAuthentication = req->idAuthentication;
+
Z_InitRequest *req = init_apdu->u.initRequest;
ODR_MASK_SET(req->options, Z_Options_search);
Z_InitRequest *req = init_apdu->u.initRequest;
ODR_MASK_SET(req->options, Z_Options_search);
@@
-447,6
+445,7
@@
void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
ODR_MASK_SET(f_resp->options, Z_Options_search);
ODR_MASK_SET(f_resp->options, Z_Options_present);
ODR_MASK_SET(f_resp->options, Z_Options_namedResultSets);
ODR_MASK_SET(f_resp->options, Z_Options_search);
ODR_MASK_SET(f_resp->options, Z_Options_present);
ODR_MASK_SET(f_resp->options, Z_Options_namedResultSets);
+ ODR_MASK_SET(f_resp->options, Z_Options_scan);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_1);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_1);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_2);
@@
-465,8
+464,6
@@
void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
bit = m_backend_list.erase(bit);
continue;
}
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)
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initResponse)
@@
-485,28
+482,30
@@
void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu)
for (i = 0; i <= Z_ProtocolVersion_3; i++)
if (!ODR_MASK_GET(b_resp->protocolVersion, i))
ODR_MASK_CLEAR(f_resp->protocolVersion, i);
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
}
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)
bit++;
}
if (m_p->m_hide_unavailable)
{
if (no_succeeded == 0)
+ {
+ *f_resp->result = 0;
package.session().close();
package.session().close();
+ }
}
else
{
if (no_failed)
}
else
{
if (no_failed)
+ {
+ *f_resp->result = 0;
package.session().close();
package.session().close();
+ }
}
package.response() = f_apdu;
}
}
package.response() = f_apdu;
}
@@
-677,8
+676,7
@@
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
std::list<Multi::FrontendSet::PresentJob>::const_iterator jit;
for (jit = jobs.begin(); jit != jobs.end(); jit++)
{
std::list<Multi::FrontendSet::PresentJob>::const_iterator jit;
for (jit = jobs.begin(); jit != jobs.end(); jit++)
{
- yaz_log(YLOG_LOG, "job pos=%d inside_pos=%d",
- jit->m_pos, jit->m_inside_pos);
+ yaz_log(YLOG_LOG, "job pos=%d", jit->m_pos);
}
}
}
}
@@
-688,22
+686,33
@@
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
bsit = it->second.m_backend_sets.begin();
for (; bsit != it->second.m_backend_sets.end(); bsit++)
{
bsit = it->second.m_backend_sets.begin();
for (; bsit != it->second.m_backend_sets.end(); bsit++)
{
- std::list<Multi::FrontendSet::PresentJob>::const_iterator jit;
int start = -1;
int end = -1;
int start = -1;
int end = -1;
-
- for (jit = jobs.begin(); jit != jobs.end(); jit++)
{
{
- if (jit->m_backend == bsit->m_backend)
+ std::list<Multi::FrontendSet::PresentJob>::const_iterator jit;
+ for (jit = jobs.begin(); jit != jobs.end(); jit++)
{
{
- if (start == -1 || jit->m_pos < start)
- start = jit->m_pos;
- if (end == -1 || jit->m_pos > end)
- end = jit->m_pos;
+ if (jit->m_backend == bsit->m_backend)
+ {
+ if (start == -1 || jit->m_pos < start)
+ start = jit->m_pos;
+ if (end == -1 || jit->m_pos > end)
+ end = jit->m_pos;
+ }
}
}
if (start != -1)
{
}
}
if (start != -1)
{
+ std::list<Multi::FrontendSet::PresentJob>::iterator jit;
+ for (jit = jobs.begin(); jit != jobs.end(); jit++)
+ {
+ if (jit->m_backend == bsit->m_backend)
+ {
+ if (jit->m_pos >= start && jit->m_pos <= end)
+ jit->m_start = start;
+ }
+ }
+
PackagePtr p = bsit->m_backend->m_package;
*req->resultSetStartPoint = start;
PackagePtr p = bsit->m_backend->m_package;
*req->resultSetStartPoint = start;
@@
-760,6
+769,14
@@
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
f_resp->records = z_records_diag;
*f_resp->presentStatus = Z_PresentStatus_failure;
}
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));
else
{
f_resp->records = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
@@
-784,7
+801,7
@@
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
nprl->records[i] = (Z_NamePlusRecord*)
odr_malloc(odr, sizeof(Z_NamePlusRecord));
nprl->records[i] = (Z_NamePlusRecord*)
odr_malloc(odr, sizeof(Z_NamePlusRecord));
- int inside_pos = jit->m_inside_pos;
+ int inside_pos = jit->m_pos - jit->m_start;
if (inside_pos >= b_resp->records->
u.databaseOrSurDiagnostics->num_records)
break;
if (inside_pos >= b_resp->records->
u.databaseOrSurDiagnostics->num_records)
break;
@@
-970,7
+987,7
@@
void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
{
ScanTermInfo my;
{
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)
my.m_count = occur ? *occur : 0;
if (ent->u.termInfo->term->which == Z_Term_general)
@@
-1011,7
+1028,7
@@
void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
{
ScanTermInfo my;
{
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)
my.m_count = occur ? *occur : 0;
if (ent->u.termInfo->term->which == Z_Term_general)
@@
-1050,7
+1067,7
@@
void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req)
}
}
}
}
- if (true)
+ if (false)
{
std::cout << "BEFORE\n";
ScanTermInfoList::iterator it = entries_before.begin();
{
std::cout << "BEFORE\n";
ScanTermInfoList::iterator it = entries_before.begin();
@@
-1172,7
+1189,7
@@
void yf::Multi::process(mp::Package &package) const
m_p->release_frontend(package);
}
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)
{
{
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
@@
-1182,8
+1199,7
@@
void mp::filter::Multi::configure(const xmlNode * ptr)
{
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);
- 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"))
{
}
else if (!strcmp((const char *) ptr->name, "hideunavailable"))
{
@@
-1228,8
+1244,9
@@
extern "C" {
/*
* Local variables:
* c-basic-offset: 4
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* indent-tabs-mode: nil
- * c-file-style: "stroustrup"
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
+