X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;ds=sidebyside;f=src%2Futil.cpp;h=c8cf573b81248f97cb8d22aadc49962a4a46e1e7;hb=1751782d8e3c9d4574754463ffd43373cf92133a;hp=15aa7aea4ffb7be59ba8ba4b5bd5e9d2f1161c66;hpb=33243335d807707f1ae5eb0468cc74b574eb4b69;p=metaproxy-moved-to-github.git diff --git a/src/util.cpp b/src/util.cpp index 15aa7ae..c8cf573 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.9 2006-01-17 17:55:40 adam Exp $ +/* $Id: util.cpp,v 1.12 2006-01-19 21:43:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -124,6 +124,19 @@ int yp2::util::get_vhost_otherinfo(Z_OtherInformation **otherInformation, return cat; } +void yp2::util::set_vhost_otherinfo(Z_OtherInformation **otherInformation, + ODR odr, + const std::list &vhosts) +{ + int cat; + std::list::const_iterator it = vhosts.begin(); + for (cat = 1; it != vhosts.end() ; cat++, it++) + { + yaz_oi_set_string_oidval(otherInformation, odr, + VAL_PROXY, cat, it->c_str()); + } +} + void yp2::util::split_zurl(std::string zurl, std::string &host, std::list &db) { @@ -269,6 +282,7 @@ Z_APDU *yp2::odr::create_presentResponse(Z_APDU *in_apdu, { Z_Records *rec = (Z_Records *) odr_malloc(m_odr, sizeof(Z_Records)); apdu->u.presentResponse->records = rec; + rec->which = Z_Records_NSD; rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(m_odr, error, addinfo); @@ -281,23 +295,62 @@ Z_APDU *yp2::odr::create_scanResponse(Z_APDU *in_apdu, int error, const char *addinfo) { Z_APDU *apdu = create_APDU(Z_APDU_scanResponse, in_apdu); + Z_ScanResponse *res = apdu->u.scanResponse; + res->entries = (Z_ListEntries *) odr_malloc(m_odr, sizeof(*res->entries)); + res->entries->num_entries = 0; + res->entries->entries = 0; + if (error) { - Z_ScanResponse *res = apdu->u.scanResponse; - res->entries = (Z_ListEntries *) odr_malloc(m_odr, sizeof(*res->entries)); *res->scanStatus = Z_Scan_failure; - res->entries->num_entries = 0; - res->entries->entries = 0; res->entries->num_nonsurrogateDiagnostics = 1; res->entries->nonsurrogateDiagnostics = (Z_DiagRec **) odr_malloc(m_odr, sizeof(Z_DiagRec *)); res->entries->nonsurrogateDiagnostics[0] = zget_DiagRec(m_odr, error, addinfo); } + else + { + res->entries->num_nonsurrogateDiagnostics = 0; + res->entries->nonsurrogateDiagnostics = 0; + } return apdu; } +Z_GDU *yp2::odr::create_HTTP_Response(yp2::Session &session, + Z_HTTP_Request *hreq, int code) +{ + const char *response_version = "1.0"; + bool keepalive = false; + if (!strcmp(hreq->version, "1.0")) + { + const char *v = z_HTTP_header_lookup(hreq->headers, "Connection"); + if (v && !strcmp(v, "Keep-Alive")) + keepalive = true; + else + session.close(); + response_version = "1.0"; + } + else + { + const char *v = z_HTTP_header_lookup(hreq->headers, "Connection"); + if (v && !strcmp(v, "close")) + session.close(); + else + keepalive = true; + response_version = "1.1"; + } + + Z_GDU *gdu = z_get_HTTP_Response(m_odr, code); + Z_HTTP_Response *hres = gdu->u.HTTP_Response; + hres->version = odr_strdup(m_odr, response_version); + if (keepalive) + z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive"); + + return gdu; +} + Z_ReferenceId **yp2::util::get_referenceId(Z_APDU *apdu) { switch (apdu->which)