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
rpn_cql: allow conversion from RPN to CQL MP-537
[metaproxy-moved-to-github.git]
/
src
/
filter_virt_db.cpp
diff --git
a/src/filter_virt_db.cpp
b/src/filter_virt_db.cpp
index
b583757
..
6849917
100644
(file)
--- a/
src/filter_virt_db.cpp
+++ b/
src/filter_virt_db.cpp
@@
-1,5
+1,5
@@
/* This file is part of Metaproxy.
/* This file is part of Metaproxy.
- Copyright (C) 2005-2012 Index Data
+ Copyright (C) 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
@@
-32,6
+32,7
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <yaz/diagbib1.h>
#include <yaz/match_glob.h>
#include <yaz/log.h>
#include <yaz/diagbib1.h>
#include <yaz/match_glob.h>
#include <yaz/log.h>
+#include <yaz/oid_db.h>
#include <map>
#include <iostream>
#include <map>
#include <iostream>
@@
-90,23
+91,23
@@
namespace metaproxy_1 {
BackendPtr b);
void fixup_npr_records(ODR odr, Z_Records *records,
BackendPtr b);
BackendPtr b);
void fixup_npr_records(ODR odr, Z_Records *records,
BackendPtr b);
-
+
BackendPtr lookup_backend_from_databases(
std::list<std::string> databases);
BackendPtr create_backend_from_databases(
std::list<std::string> databases,
int &error_code,
std::string &failing_database);
BackendPtr lookup_backend_from_databases(
std::list<std::string> databases);
BackendPtr create_backend_from_databases(
std::list<std::string> databases,
int &error_code,
std::string &failing_database);
-
+
BackendPtr init_backend(std::list<std::string> database,
Package &package,
int &error_code, std::string &addinfo);
Rep *m_p;
BackendPtr init_backend(std::list<std::string> database,
Package &package,
int &error_code, std::string &addinfo);
Rep *m_p;
- };
+ };
class VirtualDB::Rep {
friend class VirtualDB;
friend struct Frontend;
class VirtualDB::Rep {
friend class VirtualDB;
friend struct Frontend;
-
+
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
void refresh_torus();
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
void refresh_torus();
@@
-211,6
+212,13
@@
yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
Z_GDU *org_gdu = m_init_gdu.get();
Z_InitRequest *org_init = org_gdu->u.z3950->u.initRequest;
Z_GDU *org_gdu = m_init_gdu.get();
Z_InitRequest *org_init = org_gdu->u.z3950->u.initRequest;
+
+ const char *peer_name = yaz_oi_get_string_oid(
+ &org_init->otherInfo, yaz_oid_userinfo_client_ip, 1, 0);
+ if (peer_name)
+ yaz_oi_set_string_oid(&init_apdu->u.initRequest->otherInfo, odr,
+ yaz_oid_userinfo_client_ip, 1, peer_name);
+
req->idAuthentication = org_init->idAuthentication;
req->implementationId = org_init->implementationId;
req->implementationName = org_init->implementationName;
req->idAuthentication = org_init->idAuthentication;
req->implementationId = org_init->implementationId;
req->implementationName = org_init->implementationName;
@@
-228,12
+236,12
@@
yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
init_package.request() = init_apdu;
ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
init_package.request() = init_apdu;
-
- init_package.move(b->m_route); // sending init
+
+ init_package.move(b->m_route); // sending init
Z_GDU *gdu = init_package.response().get();
// we hope to get an init response
Z_GDU *gdu = init_package.response().get();
// we hope to get an init response
- error_code = YAZ_BIB1_DATABASE_UNAVAILABLE;
+ error_code = 0;
if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_initResponse)
{
if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_initResponse)
{
@@
-249,6
+257,13
@@
yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
}
mp::util::get_init_diagnostics(res, error_code, addinfo);
}
}
mp::util::get_init_diagnostics(res, error_code, addinfo);
}
+ if (error_code == 0)
+ {
+ std::list<std::string>::const_iterator db_it = databases.begin();
+ error_code = YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED;
+ if (db_it != databases.end())
+ addinfo = *db_it;
+ }
if (!init_package.session().is_closed())
{
Package close_package(b->m_backend_session, package.origin());
if (!init_package.session().is_closed())
{
Package close_package(b->m_backend_session, package.origin());
@@
-257,12
+272,13
@@
yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend(
close_package.move(b->m_route); // closing it
}
BackendPtr null;
close_package.move(b->m_route); // closing it
}
BackendPtr null;
- return null;
+ return null;
}
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
{
}
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
{
- Z_SearchRequest *req = apdu_req->u.searchRequest;
+ yazpp_1::GDU ngdu(apdu_req);
+ Z_SearchRequest *req = ngdu.get()->u.z3950->u.searchRequest;
std::string vhost;
std::string resultSetId = req->resultSetName;
mp::odr odr;
std::string vhost;
std::string resultSetId = req->resultSetName;
mp::odr odr;
@@
-275,20
+291,20
@@
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
Sets_it sets_it = m_sets.find(req->resultSetName);
if (sets_it != m_sets.end())
{
Sets_it sets_it = m_sets.find(req->resultSetName);
if (sets_it != m_sets.end())
{
- // result set already exist
+ // result set already exist
// if replace indicator is off: we return diagnostic if
// result set already exist.
if (*req->replaceIndicator == 0)
{
// if replace indicator is off: we return diagnostic if
// result set already exist.
if (*req->replaceIndicator == 0)
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req,
YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
0);
package.response() = apdu;
odr.create_searchResponse(
apdu_req,
YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
0);
package.response() = apdu;
-
+
return;
return;
- }
+ }
sets_it->second.m_backend->m_number_of_sets--;
}
// pick up any existing database with named result sets ..
sets_it->second.m_backend->m_number_of_sets--;
}
// pick up any existing database with named result sets ..
@@
-315,8
+331,8
@@
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
if (!b)
{
// did not get a backend (unavailable somehow?)
if (!b)
{
// did not get a backend (unavailable somehow?)
-
- Z_APDU *apdu =
+
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
odr.create_searchResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
@@
-351,8
+367,8
@@
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
*req->replaceIndicator = 1;
*req->replaceIndicator = 1;
- search_package.request() = yazpp_1::GDU(apdu_req);
-
+ search_package.request() = ngdu;
+
search_package.move(b->m_route);
if (search_package.session().is_closed())
search_package.move(b->m_route);
if (search_package.session().is_closed())
@@
-377,7
+393,7
@@
yf::VirtualDB::Frontend::Frontend(Rep *rep)
void yf::VirtualDB::Frontend::close(mp::Package &package)
{
std::list<BackendPtr>::const_iterator b_it;
void yf::VirtualDB::Frontend::close(mp::Package &package)
{
std::list<BackendPtr>::const_iterator b_it;
-
+
for (b_it = m_backend_list.begin(); b_it != m_backend_list.end(); b_it++)
{
(*b_it)->m_backend_session.close();
for (b_it = m_backend_list.begin(); b_it != m_backend_list.end(); b_it++)
{
(*b_it)->m_backend_session.close();
@@
-397,13
+413,13
@@
yf::VirtualDB::FrontendPtr yf::VirtualDB::Rep::get_frontend(mp::Package &package
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
@@
-421,7
+437,7
@@
void yf::VirtualDB::Rep::release_frontend(mp::Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
it = m_clients.find(package.session());
if (it != m_clients.end())
{
@@
-454,15
+470,15
@@
yf::VirtualDB::Set::~Set()
{
}
{
}
-yf::VirtualDB::Map::Map(std::string database,
+yf::VirtualDB::Map::Map(std::string database,
std::list<std::string> targets, std::string route)
std::list<std::string> targets, std::string route)
- : m_dbpattern(database), m_targets(targets), m_route(route)
+ : m_dbpattern(database), m_targets(targets), m_route(route)
{
}
{
}
-yf::VirtualDB::Map::Map(std::string database,
+yf::VirtualDB::Map::Map(std::string database,
std::string target, std::string route)
std::string target, std::string route)
- : m_dbpattern(database), m_route(route)
+ : m_dbpattern(database), m_route(route)
{
m_targets.push_back(target);
}
{
m_targets.push_back(target);
}
@@
-497,7
+513,7
@@
void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
// consider each of the frontend databases..
std::list<std::string>::const_iterator db_it;
// consider each of the frontend databases..
std::list<std::string>::const_iterator db_it;
- for (db_it = b->m_frontend_databases.begin();
+ for (db_it = b->m_frontend_databases.begin();
db_it != b->m_frontend_databases.end(); db_it++)
{
// see which target it corresponds to.. (if any)
db_it != b->m_frontend_databases.end(); db_it++)
{
// see which target it corresponds to.. (if any)
@@
-510,7
+526,7
@@
void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
map_it++;
}
if (map_it != m_p->m_maps.end())
map_it++;
}
if (map_it != m_p->m_maps.end())
- {
+ {
std::list<std::string>::const_iterator t
= map_it->m_targets.begin();
while (t != map_it->m_targets.end())
std::list<std::string>::const_iterator t
= map_it->m_targets.begin();
while (t != map_it->m_targets.end())
@@
-523,7
+539,7
@@
void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr,
t++;
}
}
t++;
}
}
-
+
}
db_it = b->m_frontend_databases.begin();
if (db_it != b->m_frontend_databases.end())
}
db_it = b->m_frontend_databases.begin();
if (db_it != b->m_frontend_databases.end())
@@
-571,14
+587,15
@@
void yf::VirtualDB::Frontend::fixup_package(mp::Package &p, BackendPtr b)
void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
- Z_PresentRequest *req = apdu_req->u.presentRequest;
+ yazpp_1::GDU ngdu(apdu_req);
+ Z_PresentRequest *req = ngdu.get()->u.z3950->u.presentRequest;
std::string resultSetId = req->resultSetId;
mp::odr odr;
Sets_it sets_it = m_sets.find(resultSetId);
if (sets_it == m_sets.end())
{
std::string resultSetId = req->resultSetId;
mp::odr odr;
Sets_it sets_it = m_sets.find(resultSetId);
if (sets_it == m_sets.end())
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
@@
-588,14
+605,14
@@
void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
}
Session *id =
new mp::Session(sets_it->second.m_backend->m_backend_session);
}
Session *id =
new mp::Session(sets_it->second.m_backend->m_backend_session);
-
+
// sending present to backend
Package present_package(*id, package.origin());
present_package.copy_filter(package);
req->resultSetId = odr_strdup(odr, sets_it->second.m_setname.c_str());
// sending present to backend
Package present_package(*id, package.origin());
present_package.copy_filter(package);
req->resultSetId = odr_strdup(odr, sets_it->second.m_setname.c_str());
-
- present_package.request() = yazpp_1::GDU(apdu_req);
+
+ present_package.request() = ngdu;
present_package.move(sets_it->second.m_backend->m_route);
present_package.move(sets_it->second.m_backend->m_route);
@@
-605,7
+622,6
@@
void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
package.response() = present_package.response();
package.session().close();
{
package.response() = present_package.response();
package.session().close();
- return;
}
else
{
}
else
{
@@
-622,7
+638,7
@@
int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req)
for (; map_it != m_backend_list.end(); map_it++)
{
BackendPtr b = *map_it;
for (; map_it != m_backend_list.end(); map_it++)
{
BackendPtr b = *map_it;
-
+
Package relay_package(b->m_backend_session, package.origin());
relay_package.copy_filter(package);
Package relay_package(b->m_backend_session, package.origin());
relay_package.copy_filter(package);
@@
-637,7
+653,8
@@
int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req)
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
{
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
{
- Z_ScanRequest *req = apdu_req->u.scanRequest;
+ yazpp_1::GDU ngdu(apdu_req);
+ Z_ScanRequest *req = ngdu.get()->u.z3950->u.scanRequest;
std::string vhost;
mp::odr odr;
std::string vhost;
mp::odr odr;
@@
-656,7
+673,7
@@
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
if (tmp->m_frontend_databases == databases)
break;
}
if (tmp->m_frontend_databases == databases)
break;
}
- if (map_it != m_backend_list.end())
+ if (map_it != m_backend_list.end())
b = *map_it;
if (!b) // no backend yet. Must create a new one
{
b = *map_it;
if (!b) // no backend yet. Must create a new one
{
@@
-670,7
+687,7
@@
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
odr.create_scanResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
odr.create_scanResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
-
+
return;
}
}
return;
}
}
@@
-688,8
+705,8
@@
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
&req->databaseNames);
}
&req->databaseNames);
}
- scan_package.request() = yazpp_1::GDU(apdu_req);
-
+ scan_package.request() = ngdu;
+
scan_package.move(b->m_route);
if (scan_package.session().is_closed())
scan_package.move(b->m_route);
if (scan_package.session().is_closed())
@@
-702,7
+719,7
@@
void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req)
}
}
-void yf::VirtualDB::add_map_db2targets(std::string db,
+void yf::VirtualDB::add_map_db2targets(std::string db,
std::list<std::string> targets,
std::string route)
{
std::list<std::string> targets,
std::string route)
{
@@
-711,7
+728,7
@@
void yf::VirtualDB::add_map_db2targets(std::string db,
}
}
-void yf::VirtualDB::add_map_db2target(std::string db,
+void yf::VirtualDB::add_map_db2target(std::string db,
std::string target,
std::string route)
std::string target,
std::string route)
@@
-725,12
+742,12
@@
void yf::VirtualDB::process(mp::Package &package) const
FrontendPtr f = m_p->get_frontend(package);
Z_GDU *gdu = package.request().get();
FrontendPtr f = m_p->get_frontend(package);
Z_GDU *gdu = package.request().get();
-
+
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initRequest && !f->m_is_virtual)
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initRequest && !f->m_is_virtual)
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
-
+
std::list<std::string> vhosts;
mp::util::get_vhost_otherinfo(req->otherInfo, vhosts);
std::list<std::string> vhosts;
mp::util::get_vhost_otherinfo(req->otherInfo, vhosts);
@@
-741,23
+758,23
@@
void yf::VirtualDB::process(mp::Package &package) const
else
{
f->m_init_gdu = gdu;
else
{
f->m_init_gdu = gdu;
-
+
mp::odr odr;
Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *resp = apdu->u.initResponse;
mp::odr odr;
Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *resp = apdu->u.initResponse;
-
+
int i;
static const int masks[] = {
Z_Options_search,
Z_Options_present,
Z_Options_namedResultSets,
Z_Options_scan,
int i;
static const int masks[] = {
Z_Options_search,
Z_Options_present,
Z_Options_namedResultSets,
Z_Options_scan,
- -1
+ -1
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
ODR_MASK_SET(resp->options, masks[i]);
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
ODR_MASK_SET(resp->options, masks[i]);
-
+
static const int versions[] = {
Z_ProtocolVersion_1,
Z_ProtocolVersion_2,
static const int versions[] = {
Z_ProtocolVersion_1,
Z_ProtocolVersion_2,
@@
-769,7
+786,7
@@
void yf::VirtualDB::process(mp::Package &package) const
ODR_MASK_SET(resp->protocolVersion, versions[i]);
else
break;
ODR_MASK_SET(resp->protocolVersion, versions[i]);
else
break;
-
+
*resp->preferredMessageSize = *req->preferredMessageSize;
*resp->maximumRecordSize = *req->maximumRecordSize;
*resp->preferredMessageSize = *req->preferredMessageSize;
*resp->maximumRecordSize = *req->maximumRecordSize;
@@
-785,12
+802,12
@@
void yf::VirtualDB::process(mp::Package &package) const
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
-
+
package.session().close();
}
else if (apdu->which == Z_APDU_searchRequest)
package.session().close();
}
else if (apdu->which == Z_APDU_searchRequest)
@@
-810,21
+827,21
@@
void yf::VirtualDB::process(mp::Package &package) const
if (f->relay_apdu(package, apdu) == 0)
{
mp::odr odr;
if (f->relay_apdu(package, apdu) == 0)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_finished, "virt_db");
package.response() = odr.create_close(
apdu, Z_Close_finished, "virt_db");
-
+
package.session().close();
}
}
else
{
mp::odr odr;
package.session().close();
}
}
else
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter_virt_db");
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter_virt_db");
-
+
package.session().close();
}
}
package.session().close();
}
}
@@
-851,14
+868,14
@@
void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only,
{
if (v_node->type != XML_ELEMENT_NODE)
continue;
{
if (v_node->type != XML_ELEMENT_NODE)
continue;
-
+
if (mp::xml::is_element_mp(v_node, "database"))
database = mp::xml::get_text(v_node);
else if (mp::xml::is_element_mp(v_node, "target"))
targets.push_back(mp::xml::get_text(v_node));
else
throw mp::filter::FilterException
if (mp::xml::is_element_mp(v_node, "database"))
database = mp::xml::get_text(v_node);
else if (mp::xml::is_element_mp(v_node, "target"))
targets.push_back(mp::xml::get_text(v_node));
else
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) v_node->name)
+ " in virtual section"
);
+ std::string((const char *) v_node->name)
+ " in virtual section"
);
@@
-872,7
+889,7
@@
void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only,
else
{
throw mp::filter::FilterException
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in virt_db filter");
}
+ std::string((const char *) ptr->name)
+ " in virt_db filter");
}