-/* $Id: filter_multi.cpp,v 1.2 2006-01-16 01:10:19 adam Exp $
+/* $Id: filter_multi.cpp,v 1.5 2006-01-17 17:55:40 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
struct Multi::Frontend {
Frontend(Rep *rep);
~Frontend();
- yp2::Session m_session;
bool m_is_multi;
bool m_in_use;
std::list<BackendPtr> m_backend_list;
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
- // empty or non-existang vhost is the same..
- const char *vhost_cstr =
- yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
- std::string vhost;
- if (vhost_cstr)
- vhost = std::string(vhost_cstr);
+ std::list<std::string> targets;
- std::map<std::string, Map>::const_iterator it;
- it = m_p->m_maps.find(std::string(vhost));
- if (it == m_p->m_maps.end())
+ yp2::util::get_vhost_otherinfo(&req->otherInfo, false, targets);
+
+ if (targets.size() < 1)
{
- // might return diagnostics if no match
package.move();
return;
}
- std::list<std::string>::const_iterator hit = it->second.m_hosts.begin();
- for (; hit != it->second.m_hosts.end(); hit++)
+
+ std::list<std::string>::const_iterator t_it = targets.begin();
+ for (; t_it != targets.end(); t_it++)
{
Session s;
Backend *b = new Backend;
- b->m_vhost = *hit;
- b->m_route = it->second.m_route;
+ b->m_vhost = *t_it;
+
+ // b->m_route unset
b->m_package = PackagePtr(new Package(s, package.origin()));
m_backend_list.push_back(BackendPtr(b));
}
- // we're going to deal with this for sure..
-
m_is_multi = true;
// create init request
// create the frontend init response based on each backend init response
yp2::odr odr;
- int i;
-
Z_APDU *f_apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *f_resp = f_apdu->u.initResponse;
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initResponse)
{
+ int i;
Z_APDU *b_apdu = gdu->u.z3950;
Z_InitResponse *b_resp = b_apdu->u.initResponse;
// create search request
Z_SearchRequest *req = apdu_req->u.searchRequest;
- // deal with piggy back (for now disable)
+ // save these for later
+ int smallSetUpperBound = *req->smallSetUpperBound;
+ int largeSetLowerBound = *req->largeSetLowerBound;
+ int mediumSetPresentNumber = *req->mediumSetPresentNumber;
+
+ // they are altered now - to disable piggyback
*req->smallSetUpperBound = 0;
*req->largeSetLowerBound = 1;
*req->mediumSetPresentNumber = 1;
+ int default_num_db = req->num_databaseNames;
+ char **default_db = req->databaseNames;
+
std::list<BackendPtr>::const_iterator bit;
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
- // we don't modify database name yet!
-
+ yp2::odr odr;
+
+ if (!yp2::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
+ &req->num_databaseNames,
+ &req->databaseNames))
+ {
+ req->num_databaseNames = default_num_db;
+ req->databaseNames = default_db;
+ }
p->request() = apdu_req;
p->copy_filter(package);
}
// look at each response
FrontendSet resultSet(std::string(req->resultSetName));
- int total_count = 0;
+ int result_set_size = 0;
Z_Records *z_records_diag = 0; // no diagnostics (yet)
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
BackendSet backendSet;
backendSet.m_backend = *bit;
backendSet.m_count = *b_resp->resultCount;
- total_count += *b_resp->resultCount;
+ result_set_size += *b_resp->resultCount;
resultSet.m_backend_sets.push_back(backendSet);
}
else
Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, 0, 0);
Z_SearchResponse *f_resp = f_apdu->u.searchResponse;
+ *f_resp->resultCount = result_set_size;
if (z_records_diag)
{
// search error
f_resp->records = z_records_diag;
+ package.response() = f_apdu;
+ return;
}
- else
- { // assume OK
- m_sets[resultSet.m_setname] = resultSet;
+ // assume OK
+ m_sets[resultSet.m_setname] = resultSet;
+
+ int number;
+ yp2::util::piggyback(smallSetUpperBound,
+ largeSetLowerBound,
+ mediumSetPresentNumber,
+ result_set_size,
+ number);
+ Package pp(package.session(), package.origin());
+ if (number > 0)
+ {
+ pp.copy_filter(package);
+ Z_APDU *p_apdu = zget_APDU(odr, Z_APDU_presentRequest);
+ Z_PresentRequest *p_req = p_apdu->u.presentRequest;
+ p_req->preferredRecordSyntax = req->preferredRecordSyntax;
+ p_req->resultSetId = req->resultSetName;
+ *p_req->resultSetStartPoint = 1;
+ *p_req->numberOfRecordsRequested = number;
+ pp.request() = p_apdu;
+ present(pp, p_apdu);
+
+ if (pp.session().is_closed())
+ package.session().close();
+
+ Z_GDU *gdu = pp.response().get();
+ if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
+ Z_APDU_presentResponse)
+ {
+ Z_PresentResponse *p_res = gdu->u.z3950->u.presentResponse;
+ f_resp->records = p_res->records;
+ *f_resp->numberOfRecordsReturned =
+ *p_res->numberOfRecordsReturned;
+ *f_resp->nextResultSetPosition =
+ *p_res->nextResultSetPosition;
+ }
+ else
+ {
+ package.response() = pp.response();
+ return;
+ }
}
- *f_resp->resultCount = total_count;
-
- package.response() = f_apdu;
+ package.response() = f_apdu; // in this scope because of p
}
void yf::Multi::Frontend::present(Package &package, Z_APDU *apdu_req)