From: Adam Dickmeiss Date: Sun, 30 Oct 2005 18:51:20 +0000 (+0000) Subject: Added methods create_{close,initResponse} for odr class. X-Git-Tag: YP2.0.0.2~159 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=93d4dd6d4f9698c7aaa74cadb343a2da8ef8ff5a;p=metaproxy-moved-to-github.git Added methods create_{close,initResponse} for odr class. --- diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index d93ae1a..998e69e 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_backend_test.cpp,v 1.7 2005-10-30 17:13:36 adam Exp $ +/* $Id: filter_backend_test.cpp,v 1.8 2005-10-30 18:51:20 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -64,11 +64,8 @@ void yf::Backend_test::process(Package &package) const if (apdu_req->which != Z_APDU_initRequest && !m_p->m_sessions.exist(package.session())) { - apdu_res = zget_APDU(odr, Z_APDU_close); - *apdu_res->u.close->closeReason = Z_Close_protocolError; - apdu_res->u.close->diagnosticInformation = - odr_strdup(odr, "no init for filter_backend_test"); - + apdu_res = odr.create_close(Z_Close_protocolError, + "no init for filter_backend_test"); package.session().close(); } else if (apdu_req->which == Z_APDU_initRequest) @@ -132,11 +129,8 @@ void yf::Backend_test::process(Package &package) const } else { - apdu_res = zget_APDU(odr, Z_APDU_close); - *apdu_res->u.close->closeReason = Z_Close_protocolError; - apdu_res->u.close->diagnosticInformation = - odr_strdup(odr, "bad APDU in filter_backend_test"); - + apdu_res = odr.create_close(Z_Close_protocolError, + "bad APDU in filter_backend_test"); package.session().close(); } if (apdu_res) diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index aa5af9d..f39b4f5 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.11 2005-10-30 17:13:36 adam Exp $ +/* $Id: filter_virt_db.cpp,v 1.12 2005-10-30 18:51:20 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -133,15 +133,10 @@ void yf::Virt_db::Rep::present(Package &package, Z_APDU *apdu, bool &move_later) Ses_it it = m_sessions.find(package.session()); if (it == m_sessions.end()) { - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_protocolError; - apdu->u.close->diagnosticInformation = - odr_strdup(odr, "no session for present request"); - - package.response() = apdu; + package.response() = odr.create_close( + Z_Close_protocolError, + "no session for present request"); package.session().close(); - return; } if (it->second.m_use_vhost) @@ -218,13 +213,9 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) Ses_it it = m_sessions.find(package.session()); if (it == m_sessions.end()) { - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_protocolError; - apdu->u.close->diagnosticInformation = - odr_strdup(odr, "no session for search request"); - - package.response() = apdu; + package.response() = odr.create_close( + Z_Close_protocolError, + "no session for search request"); package.session().close(); return; @@ -458,14 +449,10 @@ void yf::Virt_db::process(Package &package) const { yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_protocolError; - - apdu->u.close->diagnosticInformation = - odr_strdup(odr, "unsupported APDU in filter_virt_db"); - - package.response() = apdu; + package.response() = odr.create_close( + Z_Close_protocolError, + "unsupported APDU in filter_virt_db"); + package.session().close(); } if (move_later) diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index f64a4c5..b3aae8d 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_z3950_client.cpp,v 1.8 2005-10-30 17:13:36 adam Exp $ +/* $Id: filter_z3950_client.cpp,v 1.9 2005-10-30 18:51:21 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -100,13 +100,9 @@ void yf::Z3950Client::Assoc::failNotify() yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_peerAbort; - if (m_package) { - m_package->response() = apdu; + m_package->response() = odr.create_close(Z_Close_peerAbort, 0); m_package->session().close(); } } @@ -117,13 +113,9 @@ void yf::Z3950Client::Assoc::timeoutNotify() yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_lackOfActivity; - if (m_package) { - m_package->response() = apdu; + m_package->response() = odr.create_close(Z_Close_lackOfActivity, 0); m_package->session().close(); } } @@ -188,14 +180,9 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) if (apdu->which != Z_APDU_initRequest) { yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_close); - - *apdu->u.close->closeReason = Z_Close_protocolError; - apdu->u.close->diagnosticInformation = - odr_strdup(odr, "no init request for session"); - - package.response() = apdu; + package.response() = odr.create_close(Z_Close_protocolError, + "no init request for session"); package.session().close(); return 0; } @@ -206,14 +193,10 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) if (!vhost) { yp2::odr odr; - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); + package.response() = odr.create_initResponse( + YAZ_BIB1_INIT_NEGOTIATION_OPTION_REQUIRED, + "Virtual host not given"); - apdu->u.initResponse->userInformationField = - zget_init_diagnostics(odr, - YAZ_BIB1_INIT_NEGOTIATION_OPTION_REQUIRED, - "Virtual host not given"); - package.response() = apdu; - package.session().close(); return 0; } diff --git a/src/util.cpp b/src/util.cpp index ab2351b..479aebf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.2 2005-10-30 17:13:36 adam Exp $ +/* $Id: util.cpp,v 1.3 2005-10-30 18:51:21 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -48,6 +48,28 @@ yp2::odr::operator ODR() const return m_odr; } +Z_APDU *yp2::odr::create_close(int reason, const char *addinfo) +{ + Z_APDU *apdu = zget_APDU(m_odr, Z_APDU_close); + + *apdu->u.close->closeReason = reason; + if (addinfo) + apdu->u.close->diagnosticInformation = odr_strdup(m_odr, addinfo); + return apdu; +} + +Z_APDU *yp2::odr::create_initResponse(int error, const char *addinfo) +{ + Z_APDU *apdu = zget_APDU(m_odr, Z_APDU_initResponse); + if (error) + { + apdu->u.initResponse->userInformationField = + zget_init_diagnostics(m_odr, error, addinfo); + *apdu->u.initResponse->result = 0; + } + return apdu; +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/util.hpp b/src/util.hpp index 505108e..9918d45 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -1,4 +1,4 @@ -/* $Id: util.hpp,v 1.2 2005-10-30 17:13:36 adam Exp $ +/* $Id: util.hpp,v 1.3 2005-10-30 18:51:21 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -23,6 +23,8 @@ namespace yp2 { odr(); ~odr(); operator ODR() const; + Z_APDU *create_close(int reason, const char *addinfo); + Z_APDU *create_initResponse(int error, const char *addinfo); private: ODR m_odr; };