X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Futil.cpp;h=15aa7aea4ffb7be59ba8ba4b5bd5e9d2f1161c66;hb=33243335d807707f1ae5eb0468cc74b574eb4b69;hp=4a533b1e6be8fce4494f5ef918538580292cf712;hpb=627806c9d1a499273ecea94fbc3e01f4cfc0de8a;p=metaproxy-moved-to-github.git diff --git a/src/util.cpp b/src/util.cpp index 4a533b1..15aa7ae 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.6 2006-01-17 13:34:51 adam Exp $ +/* $Id: util.cpp,v 1.9 2006-01-17 17:55:40 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -11,6 +11,32 @@ #include #include "util.hpp" +void yp2::util::piggyback(int smallSetUpperBound, + int largeSetLowerBound, + int mediumSetPresentNumber, + int result_set_size, + int &number_to_present) +{ + // deal with piggyback + + if (result_set_size < smallSetUpperBound) + { + // small set . Return all records in set + number_to_present = result_set_size; + } + else if (result_set_size > largeSetLowerBound) + { + // large set . Return no records + number_to_present = 0; + } + else + { + // medium set . Return mediumSetPresentNumber records + number_to_present = mediumSetPresentNumber; + if (number_to_present > result_set_size) + number_to_present = result_set_size; + } +} bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); @@ -30,6 +56,53 @@ bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { return true; } +void yp2::util::get_default_diag(Z_DefaultDiagFormat *r, + int &error_code, std::string &addinfo) +{ + error_code = *r->condition; + switch (r->which) + { + case Z_DefaultDiagFormat_v2Addinfo: + addinfo = std::string(r->u.v2Addinfo); + break; + case Z_DefaultDiagFormat_v3Addinfo: + addinfo = r->u.v3Addinfo; + break; + } +} + +void yp2::util::get_init_diagnostics(Z_InitResponse *initrs, + int &error_code, std::string &addinfo) +{ + 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) + { + Z_DiagnosticFormat *diag = + unit->information.externallyDefinedInfo->u.diag1; + + if (diag->num > 0) + { + Z_DiagnosticFormat_s *ds = diag->elements[0]; + if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec) + yp2::util::get_default_diag(ds->u.defaultDiagRec, + error_code, addinfo); + } + } + } + } +} + int yp2::util::get_vhost_otherinfo(Z_OtherInformation **otherInformation, bool remove_flag, std::list &vhosts) @@ -199,6 +272,7 @@ Z_APDU *yp2::odr::create_presentResponse(Z_APDU *in_apdu, rec->which = Z_Records_NSD; rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(m_odr, error, addinfo); + *apdu->u.presentResponse->presentStatus = Z_PresentStatus_failure; } return apdu; }