BackendPtr m_backend;
int m_pos; // position for backend (1=first, 2=second,..
int m_start; // present request start
- PresentJob(BackendPtr ptr, int pos) :
+ PresentJob(BackendPtr ptr, int pos) :
m_backend(ptr), m_pos(pos), m_start(0) {};
};
FrontendSet(std::string setname);
void scan2(Package &package, Z_APDU *apdu);
void relay_apdu(Package &package, Z_APDU *apdu);
Rep *m_p;
- };
+ };
class Multi::Map {
std::string m_target_pattern;
std::string m_route;
std::string m_auth;
public:
- Map(std::string pattern, std::string route, std::string auth) :
+ Map(std::string pattern, std::string route, std::string auth) :
m_target_pattern(pattern), m_route(route), m_auth(auth) {};
bool match(const std::string target, std::string *ret,
std::string *auth) const {
class Multi::Rep {
friend class Multi;
friend struct Frontend;
-
+
Rep();
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Multi::FrontendPtr>::iterator it;
-
+
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;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Multi::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
}
-void yf::Multi::Backend::operator() (void)
+void yf::Multi::Backend::operator() (void)
{
m_package->move(m_route);
}
std::list<BackendSet>::const_iterator bsit;
int voffset = 0;
int offset = start + i - 1;
- for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end();
+ for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end();
bsit++)
{
if (offset >= voffset && offset < voffset + bsit->m_count)
// Yes. skip until start.. Rounding off is deliberate!
min = (start-p) / no_left;
p += no_left * min;
-
+
// update positions in each set..
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
}
// skip on each set.. before "present range"..
p = p + skip;
-
+
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
*psit += min;
-
+
omin = min; // update so we consider next class (with higher count)
}
#endif
}
m_is_multi = true;
- // create init request
+ // create init request
std::list<BackendPtr>::iterator bit;
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
mp::odr odr;
BackendPtr b = *bit;
Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
std::list<std::string>vhost_one;
vhost_one.push_back(b->m_vhost);
mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo,
}
else
breq->idAuthentication = req->idAuthentication;
-
+
*breq->preferredMessageSize = *req->preferredMessageSize;
*breq->maximumRecordSize = *req->maximumRecordSize;
ODR_MASK_SET(breq->options, Z_Options_present);
ODR_MASK_SET(breq->options, Z_Options_namedResultSets);
ODR_MASK_SET(breq->options, Z_Options_scan);
-
+
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_1);
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_3);
-
+
b->m_package->request() = init_apdu;
b->m_package->copy_filter(package);
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_3);
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); )
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed())
{
// failed. Remove from list and increment number of failed
}
else
{
- if (!f_resp->userInformationField
+ if (!f_resp->userInformationField
&& b_resp->userInformationField)
f_resp->userInformationField = b_resp->userInformationField;
no_failed++;
void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
{
- // create search request
+ // create search request
Z_SearchRequest *req = apdu_req->u.searchRequest;
// save these for later
Odr_int smallSetUpperBound = *req->smallSetUpperBound;
Odr_int largeSetLowerBound = *req->largeSetLowerBound;
Odr_int mediumSetPresentNumber = *req->mediumSetPresentNumber;
-
+
// they are altered now - to disable piggyback
*req->smallSetUpperBound = 0;
*req->largeSetLowerBound = 1;
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
// save closing package for at least one target
- if (p->session().is_closed())
+ if (p->session().is_closed())
close_p = p;
Z_GDU *gdu = p->response().get();
{
Z_APDU *b_apdu = gdu->u.z3950;
Z_SearchResponse *b_resp = b_apdu->u.searchResponse;
-
+
// see we get any errors (AKA diagnstics)
if (b_resp->records)
{
*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 =
+ *f_resp->numberOfRecordsReturned =
*p_res->numberOfRecordsReturned;
- *f_resp->nextResultSetPosition =
+ *f_resp->nextResultSetPosition =
*p_res->nextResultSetPosition;
}
- else
+ else
{
- package.response() = pp.response();
+ package.response() = pp.response();
return;
}
}
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
- // create present request
+ // create present request
Z_PresentRequest *req = apdu_req->u.presentRequest;
Sets_it it;
if (it == m_sets.end())
{
mp::odr odr;
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
*req->resultSetStartPoint = start;
*req->numberOfRecordsRequested = end - start + 1;
-
+
p->request() = apdu_req;
p->copy_filter(package);
for (; pbit != present_backend_list.end(); pbit++)
{
PackagePtr p = (*pbit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_presentResponse)
{
Z_APDU *b_apdu = gdu->u.z3950;
Z_PresentResponse *b_resp = b_apdu->u.presentResponse;
-
+
// see we get any errors (AKA diagnstics)
if (b_resp->records)
{
}
else
{
- // if any target does not return present response - return that
+ // if any target does not return present response - return that
package.response() = p->response();
return;
}
}
else if (number < 0 || (size_t) number > jobs.size())
{
- f_apdu =
+ f_apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
for (jit = jobs.begin(); jit != jobs.end(); jit++, i++)
{
PackagePtr p = jit->m_backend->m_package;
-
+
Z_GDU *gdu = p->response().get();
Z_APDU *b_apdu = gdu->u.z3950;
Z_PresentResponse *b_resp = b_apdu->u.presentResponse;
nprl->records[i] = (Z_NamePlusRecord*)
odr_malloc(odr, sizeof(Z_NamePlusRecord));
int inside_pos = jit->m_pos - jit->m_start;
- if (inside_pos >= b_resp->records->
+ if (!b_resp->records || inside_pos >= b_resp->records->
u.databaseOrSurDiagnostics->num_records)
break;
*nprl->records[i] = *b_resp->records->
if (m_backend_list.size() > 1)
{
mp::odr odr;
- Z_APDU *f_apdu =
+ Z_APDU *f_apdu =
odr.create_scanResponse(
apdu_req, YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP, 0);
package.response() = f_apdu;
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_scanResponse)
}
else
{
- // if any target does not return scan response - return that
+ // if any target does not return scan response - return that
package.response() = p->response();
return;
}
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
p->request() = apdu_req;
p->copy_filter(package);
}
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
package.response() = p->response();
}
}
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_scanResponse)
Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 1, 0);
Z_ScanResponse *f_res = f_apdu->u.scanResponse;
- f_res->entries->nonsurrogateDiagnostics =
+ f_res->entries->nonsurrogateDiagnostics =
res->entries->nonsurrogateDiagnostics;
- f_res->entries->num_nonsurrogateDiagnostics =
+ f_res->entries->num_nonsurrogateDiagnostics =
res->entries->num_nonsurrogateDiagnostics;
package.response() = f_apdu;
}
if (my.m_norm_term.length())
{
- ScanTermInfoList::iterator it =
+ ScanTermInfoList::iterator it =
entries_before.begin();
while (it != entries_before.end() && my <*it)
it++;
}
if (my.m_norm_term.length())
{
- ScanTermInfoList::iterator it =
+ ScanTermInfoList::iterator it =
entries_after.begin();
while (it != entries_after.end() && *it < my)
it++;
}
}
- }
+ }
}
else
{
- // if any target does not return scan response - return that
+ // if any target does not return scan response - return that
package.response() = p->response();
return;
}
{
std::cout << " " << it->m_norm_term << " " << it->m_count << "\n";
}
-
+
std::cout << "AFTER\n";
it = entries_after.begin();
for(; it != entries_after.end(); it++)
mp::odr odr;
Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 0, 0);
Z_ScanResponse *resp = f_apdu->u.scanResponse;
-
+
int number_returned = *req->numberOfTermsRequested;
int position_returned = *req->preferredPositionInResponse;
-
+
resp->entries->num_entries = number_returned;
resp->entries->entries = (Z_Entry**)
odr_malloc(odr, sizeof(Z_Entry*) * number_returned);
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_multi)
{
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
-
+
package.session().close();
}
else if (apdu->which == Z_APDU_searchRequest)
else
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter multi");
-
+
package.session().close();
}
}
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in multi filter");
}