From 857894d3c2350542a0de5baec17edbde29c9953c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 26 Oct 2012 14:32:35 +0200 Subject: [PATCH] sru_z3950: using yaz_decode_init_diag --- src/filter_sru_to_z3950.cpp | 73 +++++++++++++------------------------------ 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 4f9618c..0e4c742 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -26,8 +26,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "sru_util.hpp" #include "filter_sru_to_z3950.hpp" -#include -#include #include #include #include @@ -39,7 +37,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -/* #include */ #include namespace mp = metaproxy_1; @@ -433,51 +430,6 @@ void yf::SRUtoZ3950::Impl::process(mp::Package &package) release_frontend(package); } -static void interpret_default_diag(int *error, - const char **addinfo, - Z_DefaultDiagFormat *r) -{ - *error = *r->condition; - *addinfo = r->u.v2Addinfo; -} - -static void interpret_init_diag2(int *error, - const char **addinfo, - Z_DiagnosticFormat *diag) -{ - if (diag->num > 0) - { - Z_DiagnosticFormat_s *ds = diag->elements[0]; - if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec) - interpret_default_diag(error, addinfo, ds->u.defaultDiagRec); - } -} - -static void interpret_init_diag(int *error, - const char **addinfo, - Z_InitResponse *initrs) -{ - Z_External *uif = initrs->userInformationField; - if (uif && uif->which == Z_External_userInfo1) - { - int i; - Z_OtherInformation *ui = uif->u.userInfo1; - for (i = 0; i < ui->num_elements; i++) - { - Z_OtherInformationUnit *unit = ui->list[i]; - if (unit->which == Z_OtherInfo_externallyDefinedInfo && - unit->information.externallyDefinedInfo && - unit->information.externallyDefinedInfo->which == - Z_External_diag1) - { - interpret_init_diag2( - error, addinfo, - unit->information.externallyDefinedInfo->u.diag1); - } - } - } -} - bool yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, mp::odr &odr_en, @@ -548,11 +500,28 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, Z_InitResponse *initrs = z3950_gdu->u.z3950->u.initResponse; if (*initrs->result) return true; - int z_error = 0; - interpret_init_diag(&error, &addinfo, initrs); - if (z_error) - error = yaz_diag_bib1_to_srw(z_error); + int no = 0; + while (1) + { + Z_DefaultDiagFormat *df = yaz_decode_init_diag(no, initrs); + + if (!df) + break; + yaz_add_srw_diagnostic(odr_en, + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), + yaz_diag_bib1_to_srw(*df->condition), + df->u.v2Addinfo); + no++; + } + if (no) + return false; // got least one diagnostic from init + + // we just have result=false. + error = YAZ_SRW_AUTHENTICATION_ERROR; } + else + addinfo = "sru_z3950: expected initResponse"; yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics), -- 1.7.10.4