-/* $Id: filter_virt_db.cpp,v 1.23 2006-01-13 15:09:35 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.24 2006-01-14 08:38:57 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
friend class Virt_db;
friend class Frontend;
- Frontend *get_frontend(Package &package);
+ FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
private:
boost::mutex m_sessions_mutex;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
- std::map<yp2::Session,Frontend *> m_clients;
+ std::map<yp2::Session, FrontendPtr> m_clients;
};
}
}
std::string backend_setname;
if (b->m_named_result_sets)
{
- std::cout << "named_result_sets TRUE\n";
backend_setname = std::string(req->resultSetName);
}
else
{
- std::cout << "named_result_sets FALSE\n";
backend_setname = "default";
req->resultSetName = odr_strdup(odr, backend_setname.c_str());
}
{
}
-yf::Virt_db::Frontend *yf::Virt_db::Rep::get_frontend(Package &package)
+yf::Virt_db::FrontendPtr yf::Virt_db::Rep::get_frontend(Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<yp2::Session,yf::Virt_db::Frontend *>::iterator it;
+ std::map<yp2::Session,yf::Virt_db::FrontendPtr>::iterator it;
while(true)
{
}
m_cond_session_ready.wait(lock);
}
- Frontend *f = new Frontend(this);
+ FrontendPtr f(new Frontend(this));
m_clients[package.session()] = f;
f->m_in_use = true;
return f;
}
-
void yf::Virt_db::Rep::release_frontend(Package &package)
{
boost::mutex::scoped_lock lock(m_mutex);
- std::map<yp2::Session,yf::Virt_db::Frontend *>::iterator it;
+ std::map<yp2::Session,yf::Virt_db::FrontendPtr>::iterator it;
it = m_clients.find(package.session());
if (it != m_clients.end())
if (package.session().is_closed())
{
it->second->close(package);
- delete it->second;
m_clients.erase(it);
}
else
void yf::Virt_db::process(Package &package) const
{
- yf::Virt_db::Frontend *f = m_p->get_frontend(package);
- if (f)
+ 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_GDU *gdu = package.request().get();
+ 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)
+ const char *vhost =
+ yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
+ if (!vhost)
{
- Z_InitRequest *req = gdu->u.z3950->u.initRequest;
-
- const char *vhost =
- yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
- if (!vhost)
- {
- yp2::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,
- -1
- };
- 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,
- Z_ProtocolVersion_3,
- -1
- };
- for (i = 0; versions[i] != -1; i++)
- if (ODR_MASK_GET(req->protocolVersion, versions[i]))
- ODR_MASK_SET(resp->protocolVersion, versions[i]);
- else
- break;
-
- package.response() = apdu;
- f->m_is_virtual = true;
- }
- else
- package.move();
+ yp2::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,
+ -1
+ };
+ 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,
+ Z_ProtocolVersion_3,
+ -1
+ };
+ for (i = 0; versions[i] != -1; i++)
+ if (ODR_MASK_GET(req->protocolVersion, versions[i]))
+ ODR_MASK_SET(resp->protocolVersion, versions[i]);
+ else
+ break;
+
+ package.response() = apdu;
+ f->m_is_virtual = true;
}
- else if (!f->m_is_virtual)
+ else
package.move();
- else if (gdu && gdu->which == Z_GDU_Z3950)
+ }
+ else if (!f->m_is_virtual)
+ package.move();
+ else if (gdu && gdu->which == Z_GDU_Z3950)
+ {
+ Z_APDU *apdu = gdu->u.z3950;
+ if (apdu->which == Z_APDU_initRequest)
{
- Z_APDU *apdu = gdu->u.z3950;
- if (apdu->which == Z_APDU_initRequest)
- {
- yp2::odr odr;
-
- package.response() = odr.create_close(
- apdu,
- Z_Close_protocolError,
- "double init");
-
- package.session().close();
- }
- else if (apdu->which == Z_APDU_searchRequest)
- {
- f->search(package, apdu);
- }
- else if (apdu->which == Z_APDU_presentRequest)
- {
- f->present(package, apdu);
- }
- else if (apdu->which == Z_APDU_scanRequest)
- {
- f->scan(package, apdu);
- }
- else
- {
- yp2::odr odr;
-
- package.response() = odr.create_close(
- apdu, Z_Close_protocolError,
- "unsupported APDU in filter_virt_db");
-
- package.session().close();
- }
+ yp2::odr odr;
+
+ package.response() = odr.create_close(
+ apdu,
+ Z_Close_protocolError,
+ "double init");
+
+ package.session().close();
+ }
+ else if (apdu->which == Z_APDU_searchRequest)
+ {
+ f->search(package, apdu);
+ }
+ else if (apdu->which == Z_APDU_presentRequest)
+ {
+ f->present(package, apdu);
+ }
+ else if (apdu->which == Z_APDU_scanRequest)
+ {
+ f->scan(package, apdu);
+ }
+ else
+ {
+ yp2::odr odr;
+
+ package.response() = odr.create_close(
+ apdu, Z_Close_protocolError,
+ "unsupported APDU in filter_virt_db");
+
+ package.session().close();
}
}
m_p->release_frontend(package);