X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_z3950_client.cpp;h=60b93909ae636b2d9ea0ea46b3bac69558ebfe1d;hb=1158dc8bbcb0bd5d161333380fe91e93185674a6;hp=6d91c5443e71636a3c0bb3caa936c99af7b41cf1;hpb=c03de7dafac23351fed3dd22486f5362f9ff7232;p=metaproxy-moved-to-github.git diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index 6d91c54..60b9390 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2012 Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -56,6 +56,7 @@ namespace metaproxy_1 { void timeoutNotify(); void recv_GDU(Z_GDU *gdu, int len); void fixup_nsd(ODR odr, Z_Records *records); + void fixup_init(ODR odr, Z_InitResponse *initrs); yazpp_1::IPDU_Observer* sessionNotify( yazpp_1::IPDU_Observable *the_PDU_Observable, int fd); @@ -174,17 +175,66 @@ void yf::Z3950Client::Assoc::fixup_nsd(ODR odr, Z_Records *records) if (records && records->which == Z_Records_NSD) { Z_DefaultDiagFormat *nsd = records->u.nonSurrogateDiagnostic; - if (nsd->which == Z_DiagRec_defaultFormat) + std::string addinfo; + + // should really check for nsd->which.. But union has two members + // containing almost same data + const char *v2Addinfo = nsd->u.v2Addinfo; + // Z_InternationalString *v3Addinfo; + + if (v2Addinfo && *v2Addinfo) { - std::string addinfo; + addinfo.assign(nsd->u.v2Addinfo); + addinfo += " "; + } + addinfo += "(backend=" + m_host + ")"; + nsd->u.v2Addinfo = odr_strdup(odr, addinfo.c_str()); + } +} - if (nsd->u.v2Addinfo) +void yf::Z3950Client::Assoc::fixup_init(ODR odr, Z_InitResponse *initrs) +{ + Z_External *uif = initrs->userInformationField; + + if (uif && uif->which == Z_External_userInfo1) + { + Z_OtherInformation *ui = uif->u.userInfo1; + int i; + 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) { - addinfo.assign(nsd->u.v2Addinfo); - addinfo += " "; - } - addinfo += "(backend=" + m_host + ")"; - nsd->u.v2Addinfo = odr_strdup(odr, addinfo.c_str()); + Z_DiagnosticFormat *diag = + unit->information.externallyDefinedInfo->u.diag1; + int j; + for (j = 0; j < diag->num; j++) + { + Z_DiagnosticFormat_s *ds = diag->elements[j]; + if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec) + { + Z_DefaultDiagFormat *r = ds->u.defaultDiagRec; + char *oaddinfo = r->u.v2Addinfo; + char *naddinfo = (char *) odr_malloc( + odr, + (oaddinfo ? strlen(oaddinfo) : 0) + 20 + + m_host.length()); + if (oaddinfo && *oaddinfo) + { + strcpy(naddinfo, oaddinfo); + strcat(naddinfo, " "); + } + strcat(naddinfo, "(backend="); + strcat(naddinfo, m_host.c_str()); + strcat(naddinfo, ")"); + + r->u.v2Addinfo = naddinfo; + } + } + } } } } @@ -207,6 +257,9 @@ void yf::Z3950Client::Assoc::recv_GDU(Z_GDU *gdu, int len) case Z_APDU_presentResponse: fixup_nsd(odr, apdu->u.presentResponse->records); break; + case Z_APDU_initResponse: + fixup_init(odr, apdu->u.initResponse); + break; } } m_package->response() = gdu;