-/* $Id: ex_filter_frontend_net.cpp,v 1.15 2005-10-29 22:23:36 marc Exp $
+/* $Id: ex_filter_frontend_net.cpp,v 1.16 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
+#include "util.hpp"
#include "filter_frontend_net.hpp"
#include "filter_z3950_client.hpp"
#include "filter_virt_db.hpp"
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_HTTP_Request)
{
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
http_res->content_len = strlen(http_res->content_buf);
package.response() = gdu;
- odr_destroy(odr);
}
return package.move();
};
-/* $Id: filter_backend_test.cpp,v 1.6 2005-10-29 15:54:29 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.7 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <boost/thread/mutex.hpp>
+#include "util.hpp"
#include "filter_backend_test.hpp"
#include <yaz/zgdu.h>
{
Z_APDU *apdu_req = gdu->u.z3950;
Z_APDU *apdu_res = 0;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
if (apdu_req->which != Z_APDU_initRequest &&
!m_p->m_sessions.exist(package.session()))
}
if (apdu_res)
package.response() = apdu_res;
- odr_destroy(odr);
}
if (package.session().is_closed())
m_p->m_sessions.release(package.session());
-/* $Id: filter_log.cpp,v 1.7 2005-10-25 16:01:36 adam Exp $
+/* $Id: filter_log.cpp,v 1.8 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "router.hpp"
#include "package.hpp"
+#include "util.hpp"
#include "filter_log.hpp"
#include <yaz/zgdu.h>
gdu = package.request().get();
if (gdu)
{
- ODR odr = odr_createmem(ODR_PRINT);
+ yp2::odr odr(ODR_PRINT);
z_GDU(odr, &gdu, 0, 0);
- odr_destroy(odr);
}
}
//<< "duration=" << duration.total_seconds()
// << "." << duration.fractional_seconds()
// << "\n";
- }
-
- gdu = package.response().get();
- if (gdu)
- {
- ODR odr = odr_createmem(ODR_PRINT);
- z_GDU(odr, &gdu, 0, 0);
- odr_destroy(odr);
+ gdu = package.response().get();
+ if (gdu)
+ {
+ yp2::odr odr(ODR_PRINT);
+ z_GDU(odr, &gdu, 0, 0);
+ }
}
}
-/* $Id: filter_virt_db.cpp,v 1.10 2005-10-29 15:54:29 adam Exp $
+/* $Id: filter_virt_db.cpp,v 1.11 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <boost/thread/mutex.hpp>
+#include "util.hpp"
#include "filter_virt_db.hpp"
#include <yaz/zgdu.h>
Session *id = 0;
Z_PresentRequest *req = apdu->u.presentRequest;
std::string resultSetId = req->resultSetId;
+ yp2::odr odr;
{
boost::mutex::scoped_lock lock(m_sessions_mutex);
Ses_it it = m_sessions.find(package.session());
if (it == m_sessions.end())
{
- ODR odr = odr_createmem(ODR_ENCODE);
-
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
*apdu->u.close->closeReason = Z_Close_protocolError;
package.response() = apdu;
package.session().close();
- odr_destroy(odr);
- assert(false);
+
return;
}
if (it->second.m_use_vhost)
Sets_it sets_it = it->second.m_sets.find(resultSetId);
if (sets_it == it->second.m_sets.end())
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
resultSetId.c_str());
package.response() = apdu;
- odr_destroy(odr);
+
return;
}
id = new yp2::Session(sets_it->second.m_backend_session);
}
- ODR odr = odr_createmem(ODR_ENCODE);
// sending present to backend
Package present_package(*id, package.origin());
req->resultSetId = odr_strdup(odr, "default");
present_package.request() = yazpp_1::GDU(apdu);
- odr_destroy(odr);
-
present_package.move();
if (present_package.session().is_closed())
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
resultSetId.c_str());
package.response() = apdu;
- odr_destroy(odr);
-
boost::mutex::scoped_lock lock(m_sessions_mutex);
Ses_it it = m_sessions.find(package.session());
if (it != m_sessions.end())
std::string database;
std::string resultSetId = req->resultSetName;
bool support_named_result_sets = false; // whether backend supports it
+ yp2::odr odr;
{
boost::mutex::scoped_lock lock(m_sessions_mutex);
Ses_it it = m_sessions.find(package.session());
if (it == m_sessions.end())
{
- ODR odr = odr_createmem(ODR_ENCODE);
-
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
*apdu->u.close->closeReason = Z_Close_protocolError;
package.response() = apdu;
package.session().close();
- odr_destroy(odr);
+
return;
}
if (it->second.m_use_vhost)
}
if (req->num_databaseNames != 1)
{ // exactly one database must be specified
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
odr, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
package.response() = apdu;
- odr_destroy(odr);
return;
}
database = req->databaseNames[0];
map_it = m_maps.find(database);
if (map_it == m_maps.end())
{ // no map for database: return diagnostic
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
odr, YAZ_BIB1_DATABASE_DOES_NOT_EXIST, database.c_str());
package.response() = apdu;
- odr_destroy(odr);
return;
}
if (*req->replaceIndicator == 0)
Sets_it sets_it = it->second.m_sets.find(req->resultSetName);
if (sets_it != it->second.m_sets.end())
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
0);
package.response() = apdu;
- odr_destroy(odr);
return;
}
}
Package init_package(id, package.origin());
init_package.copy_filter(package);
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest);
yaz_oi_set_string_oidval(&init_apdu->u.initRequest->otherInfo, odr,
VAL_PROXY, 1, vhost_cstr);
init_package.request() = init_apdu;
- odr_destroy(odr);
init_package.move(); // sending init
if (init_package.session().is_closed())
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
zget_DefaultDiagFormat(
odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str());
package.response() = apdu;
-
- odr_destroy(odr);
}
Z_GDU *gdu = init_package.response().get();
// we hope to get an init response
}
else
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str());
package.response() = apdu;
- odr_destroy(odr);
return;
}
}
search_package.copy_filter(package);
const char *sep = strchr(vhost_cstr, '/');
- ODR odr = odr_createmem(ODR_ENCODE);
if (sep)
req->databaseNames[0] = odr_strdup(odr, sep+1);
req->resultSetName = odr_strdup(odr, backend_resultSetId.c_str());
search_package.request() = yazpp_1::GDU(apdu);
- odr_destroy(odr);
-
search_package.move();
if (search_package.session().is_closed())
{
- ODR odr = odr_createmem(ODR_ENCODE);
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str());
package.response() = apdu;
- odr_destroy(odr);
return;
}
package.response() = search_package.response();
yaz_oi_get_string_oidval(&req->otherInfo, VAL_PROXY, 1, 0);
if (!vhost)
{
- ODR odr = odr_createmem(ODR_ENCODE);
-
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
Z_InitResponse *resp = apdu->u.initResponse;
package.response() = apdu;
- odr_destroy(odr);
-
m_sessions[package.session()] = Virt_db_session(package.session(), false);
}
else
}
else
{
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
package.response() = apdu;
package.session().close();
- odr_destroy(odr);
}
if (move_later)
package.move();
-/* $Id: filter_z3950_client.cpp,v 1.7 2005-10-30 16:39:18 adam Exp $
+/* $Id: filter_z3950_client.cpp,v 1.8 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
+#include "util.hpp"
#include "filter_z3950_client.hpp"
#include <yaz/zgdu.h>
{
m_waiting = false;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
m_package->response() = apdu;
m_package->session().close();
}
-
- odr_destroy(odr);
}
void yf::Z3950Client::Assoc::timeoutNotify()
{
m_waiting = false;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
m_package->response() = apdu;
m_package->session().close();
}
- odr_destroy(odr);
}
void yf::Z3950Client::Assoc::recv_GDU(Z_GDU *gdu, int len)
// check that it is init. If not, close
if (apdu->which != Z_APDU_initRequest)
{
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
*apdu->u.close->closeReason = Z_Close_protocolError;
package.response() = apdu;
package.session().close();
- odr_destroy(odr);
return 0;
}
// check virtual host
VAL_PROXY, 1, 0);
if (!vhost)
{
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
apdu->u.initResponse->userInformationField =
package.response() = apdu;
package.session().close();
- odr_destroy(odr);
return 0;
}
-/* $Id: test_filter_backend_test.cpp,v 1.4 2005-10-26 18:53:49 adam Exp $
+/* $Id: test_filter_backend_test.cpp,v 1.5 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
// send search request as first request.. That should fail with
// a close from the backend
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
yp2::util::pqf(odr, apdu, "computer");
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
// send present request as first request.. That should fail with
// a close from the backend
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
-/* $Id: test_filter_frontend_net.cpp,v 1.11 2005-10-29 22:23:36 marc Exp $
+/* $Id: test_filter_frontend_net.cpp,v 1.12 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <iostream>
#include <stdexcept>
+#include "util.hpp"
#include "filter_frontend_net.hpp"
#include "router_chain.hpp"
if (gdu)
{
// std::cout << "Got PDU. Sending init response\n";
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
apdu->u.initResponse->implementationName = "YP2/YAZ";
package.response() = apdu;
- odr_destroy(odr);
}
return package.move();
};
// Create package with Z39.50 init request in it
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
pack.request() = apdu;
- odr_destroy(odr);
// Done creating query.
// Put it in router
-/* $Id: test_filter_log.cpp,v 1.5 2005-10-29 22:23:36 marc Exp $
+/* $Id: test_filter_log.cpp,v 1.6 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <stdexcept>
#include "filter_log.hpp"
-
+#include "util.hpp"
#include "router_chain.hpp"
#include "session.hpp"
#include "package.hpp"
if (gdu)
{
// std::cout << "Got PDU. Sending init response\n";
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse);
apdu->u.initResponse->implementationName = "YP2/YAZ";
package.response() = apdu;
- odr_destroy(odr);
}
return package.move();
};
// Create package with Z39.50 init request in it
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
pack.request() = apdu;
- odr_destroy(odr);
// Done creating query.
// Put it in router
-/* $Id: test_filter_virt_db.cpp,v 1.7 2005-10-26 18:53:49 adam Exp $
+/* $Id: test_filter_virt_db.cpp,v 1.8 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
// own init response (regardless of backend)
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
static void init(yp2::Package &pack, yp2::Router &router)
{
// Create package with Z39.50 init request in it
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
BOOST_CHECK(apdu);
return;
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
{
// Create package with Z39.50 search request in it
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
yp2::util::pqf(odr, apdu, query);
pack.request() = apdu;
- odr_destroy(odr);
-
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
{
// Create package with Z39.50 present request in it
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname);
pack.request() = apdu;
- odr_destroy(odr);
-
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
-/* $Id: test_filter_z3950_client.cpp,v 1.5 2005-10-26 10:55:26 marc Exp $
+/* $Id: test_filter_z3950_client.cpp,v 1.6 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <stdexcept>
#include "filter_z3950_client.hpp"
+#include "util.hpp"
#include "router_chain.hpp"
#include "session.hpp"
// Create package with Z39.50 init request in it
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
// Create package with Z39.50 present request in it
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
// Create package with Z39.50 init request in it
yp2::Package pack;
- ODR odr = odr_createmem(ODR_ENCODE);
+ yp2::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
const char *vhost = "localhost:9999";
BOOST_CHECK(apdu);
pack.request() = apdu;
- odr_destroy(odr);
// Put it in router
pack.router(router).move();
-/* $Id: util.cpp,v 1.1 2005-10-26 18:53:49 adam Exp $
+/* $Id: util.cpp,v 1.2 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "config.hpp"
+#include <yaz/odr.h>
#include <yaz/pquery.h>
#include "util.hpp"
apdu->u.searchRequest->query = query;
return true;
}
+
+yp2::odr::odr(int type)
+{
+ m_odr = odr_createmem(type);
+}
+
+yp2::odr::odr()
+{
+ m_odr = odr_createmem(ODR_ENCODE);
+}
+
+yp2::odr::~odr()
+{
+ odr_destroy(m_odr);
+}
+
+yp2::odr::operator ODR() const
+{
+ return m_odr;
+}
+
/*
* Local variables:
* c-basic-offset: 4
-/* $Id: util.hpp,v 1.1 2005-10-26 18:53:49 adam Exp $
+/* $Id: util.hpp,v 1.2 2005-10-30 17:13:36 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <yaz/z-core.h>
#include <string>
+
+#include <boost/utility.hpp>
+
namespace yp2 {
struct util {
static bool pqf(ODR odr, Z_APDU *apdu, const std::string &q);
};
+
+ class odr : public boost::noncopyable {
+ public:
+ odr(int type);
+ odr();
+ ~odr();
+ operator ODR() const;
+ private:
+ ODR m_odr;
+ };
+
}
#endif
/*