From f26cca046b4879a78261ea436c3e21bb3b851b52 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 30 Oct 2005 17:13:36 +0000 Subject: [PATCH] Implemented yp2::odr which is a noncopyable wrapper for YAZ' ODR. --- src/ex_filter_frontend_net.cpp | 6 ++--- src/filter_backend_test.cpp | 6 ++--- src/filter_log.cpp | 20 +++++++--------- src/filter_virt_db.cpp | 49 +++++++------------------------------- src/filter_z3950_client.cpp | 16 +++++-------- src/test_filter_backend_test.cpp | 11 ++++----- src/test_filter_frontend_net.cpp | 9 ++++--- src/test_filter_log.cpp | 10 ++++---- src/test_filter_virt_db.cpp | 16 ++++--------- src/test_filter_z3950_client.cpp | 12 ++++------ src/util.cpp | 24 ++++++++++++++++++- src/util.hpp | 16 ++++++++++++- 12 files changed, 90 insertions(+), 105 deletions(-) diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index df2e214..fbe608b 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -13,6 +13,7 @@ namespace po = boost::program_options; #include "config.hpp" +#include "util.hpp" #include "filter_frontend_net.hpp" #include "filter_z3950_client.hpp" #include "filter_virt_db.hpp" @@ -33,7 +34,7 @@ public: 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; @@ -45,7 +46,6 @@ public: http_res->content_len = strlen(http_res->content_buf); package.response() = gdu; - odr_destroy(odr); } return package.move(); }; diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index bec5daf..d93ae1a 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -12,6 +12,7 @@ #include +#include "util.hpp" #include "filter_backend_test.hpp" #include @@ -58,7 +59,7 @@ void yf::Backend_test::process(Package &package) const { 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())) @@ -140,7 +141,6 @@ void yf::Backend_test::process(Package &package) const } if (apdu_res) package.response() = apdu_res; - odr_destroy(odr); } if (package.session().is_closed()) m_p->m_sessions.release(package.session()); diff --git a/src/filter_log.cpp b/src/filter_log.cpp index 1e21fb7..cb3b67d 100644 --- a/src/filter_log.cpp +++ b/src/filter_log.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -11,6 +11,7 @@ #include "router.hpp" #include "package.hpp" +#include "util.hpp" #include "filter_log.hpp" #include @@ -42,9 +43,8 @@ void yp2::filter::Log::process(Package &package) const { 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); } } @@ -69,14 +69,12 @@ void yp2::filter::Log::process(Package &package) const { //<< "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); + } } } diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index 2ea70c4..aa5af9d 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -12,6 +12,7 @@ #include +#include "util.hpp" #include "filter_virt_db.hpp" #include @@ -125,14 +126,13 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) 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; @@ -141,8 +141,7 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) package.response() = apdu; package.session().close(); - odr_destroy(odr); - assert(false); + return; } if (it->second.m_use_vhost) @@ -153,7 +152,6 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -165,12 +163,11 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) 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()); @@ -179,13 +176,10 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -198,8 +192,6 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) 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()) @@ -219,14 +211,13 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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; @@ -235,7 +226,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) package.response() = apdu; package.session().close(); - odr_destroy(odr); + return; } if (it->second.m_use_vhost) @@ -245,7 +236,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) } 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)); @@ -256,7 +246,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) odr, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0); package.response() = apdu; - odr_destroy(odr); return; } database = req->databaseNames[0]; @@ -264,7 +253,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -275,7 +263,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) odr, YAZ_BIB1_DATABASE_DOES_NOT_EXIST, database.c_str()); package.response() = apdu; - odr_destroy(odr); return; } if (*req->replaceIndicator == 0) @@ -283,7 +270,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -296,7 +282,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 0); package.response() = apdu; - odr_destroy(odr); return; } } @@ -311,20 +296,17 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -334,8 +316,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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 @@ -348,7 +328,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) } 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)); @@ -359,7 +338,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str()); package.response() = apdu; - odr_destroy(odr); return; } } @@ -368,7 +346,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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); @@ -378,13 +355,10 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) 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)); @@ -395,7 +369,6 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str()); package.response() = apdu; - odr_destroy(odr); return; } package.response() = search_package.response(); @@ -419,8 +392,7 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later) 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; @@ -446,8 +418,6 @@ void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later) package.response() = apdu; - odr_destroy(odr); - m_sessions[package.session()] = Virt_db_session(package.session(), false); } else @@ -486,7 +456,7 @@ void yf::Virt_db::process(Package &package) const } else { - ODR odr = odr_createmem(ODR_ENCODE); + yp2::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); @@ -497,7 +467,6 @@ void yf::Virt_db::process(Package &package) const package.response() = apdu; package.session().close(); - odr_destroy(odr); } if (move_later) package.move(); diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index f0323dc..f64a4c5 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -14,6 +14,7 @@ #include #include +#include "util.hpp" #include "filter_z3950_client.hpp" #include @@ -97,7 +98,7 @@ void yf::Z3950Client::Assoc::failNotify() { m_waiting = false; - ODR odr = odr_createmem(ODR_ENCODE); + yp2::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); @@ -108,15 +109,13 @@ void yf::Z3950Client::Assoc::failNotify() 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); @@ -127,7 +126,6 @@ void yf::Z3950Client::Assoc::timeoutNotify() m_package->response() = apdu; m_package->session().close(); } - odr_destroy(odr); } void yf::Z3950Client::Assoc::recv_GDU(Z_GDU *gdu, int len) @@ -189,7 +187,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) // 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; @@ -199,7 +197,6 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) package.response() = apdu; package.session().close(); - odr_destroy(odr); return 0; } // check virtual host @@ -208,7 +205,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) 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 = @@ -218,7 +215,6 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) package.response() = apdu; package.session().close(); - odr_destroy(odr); return 0; } diff --git a/src/test_filter_backend_test.cpp b/src/test_filter_backend_test.cpp index f1836b5..ee107d7 100644 --- a/src/test_filter_backend_test.cpp +++ b/src/test_filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -46,13 +46,12 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 ) 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(); @@ -87,7 +86,7 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 ) // 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"); @@ -100,7 +99,6 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 ) BOOST_CHECK(apdu); pack.request() = apdu; - odr_destroy(odr); // Put it in router pack.router(router).move(); @@ -135,13 +133,12 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 ) // 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(); diff --git a/src/test_filter_frontend_net.cpp b/src/test_filter_frontend_net.cpp index 9969b21..ce53512 100644 --- a/src/test_filter_frontend_net.cpp +++ b/src/test_filter_frontend_net.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -8,6 +8,7 @@ #include #include +#include "util.hpp" #include "filter_frontend_net.hpp" #include "router_chain.hpp" @@ -32,13 +33,12 @@ public: 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(); }; @@ -75,11 +75,10 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) // 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 diff --git a/src/test_filter_log.cpp b/src/test_filter_log.cpp index 2e3af23..b449417 100644 --- a/src/test_filter_log.cpp +++ b/src/test_filter_log.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -9,7 +9,7 @@ #include #include "filter_log.hpp" - +#include "util.hpp" #include "router_chain.hpp" #include "session.hpp" #include "package.hpp" @@ -32,13 +32,12 @@ public: 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(); }; @@ -74,11 +73,10 @@ BOOST_AUTO_TEST_CASE( test_filter_log_2 ) // 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 diff --git a/src/test_filter_virt_db.cpp b/src/test_filter_virt_db.cpp index 04bdca1..ded4057 100644 --- a/src/test_filter_virt_db.cpp +++ b/src/test_filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -52,13 +52,12 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 ) // 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(); @@ -84,7 +83,7 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 ) 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); @@ -92,7 +91,6 @@ static void init(yp2::Package &pack, yp2::Router &router) return; pack.request() = apdu; - odr_destroy(odr); // Put it in router pack.router(router).move(); @@ -116,7 +114,7 @@ static void search(yp2::Package &pack, yp2::Router &router, { // 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); @@ -134,8 +132,6 @@ static void search(yp2::Package &pack, yp2::Router &router, pack.request() = apdu; - odr_destroy(odr); - Z_GDU *gdu_test = pack.request().get(); BOOST_CHECK(gdu_test); @@ -161,7 +157,7 @@ static void present(yp2::Package &pack, yp2::Router &router, { // 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); @@ -174,8 +170,6 @@ static void present(yp2::Package &pack, yp2::Router &router, pack.request() = apdu; - odr_destroy(odr); - Z_GDU *gdu_test = pack.request().get(); BOOST_CHECK(gdu_test); diff --git a/src/test_filter_z3950_client.cpp b/src/test_filter_z3950_client.cpp index 37f64a7..0391b9e 100644 --- a/src/test_filter_z3950_client.cpp +++ b/src/test_filter_z3950_client.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -9,6 +9,7 @@ #include #include "filter_z3950_client.hpp" +#include "util.hpp" #include "router_chain.hpp" #include "session.hpp" @@ -46,13 +47,12 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 ) // 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(); @@ -88,13 +88,12 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 ) // 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(); @@ -130,7 +129,7 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 ) // 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"; @@ -140,7 +139,6 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 ) BOOST_CHECK(apdu); pack.request() = apdu; - odr_destroy(odr); // Put it in router pack.router(router).move(); diff --git a/src/util.cpp b/src/util.cpp index a5eda13..ab2351b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $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% @@ -6,6 +6,7 @@ #include "config.hpp" +#include #include #include "util.hpp" @@ -26,6 +27,27 @@ bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { 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 diff --git a/src/util.hpp b/src/util.hpp index fa6f96b..505108e 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -1,4 +1,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% @@ -9,10 +9,24 @@ #include #include + +#include + 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 /* -- 1.7.10.4