X-Git-Url: http://git.indexdata.com/?p=yazproxy-moved-to-github.git;a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=930f7c221d1f0b7777ea48f438cfac7b1a80b420;hp=f647343c6be3419acef9a1175a42ac0aa7fd009c;hb=7fa984c171c65d05d34775c4533808793b2109cb;hpb=5ace60a2d363137c0e55b78611be2aa00e1d0e2d diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index f647343..930f7c2 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,5 +1,5 @@ /* This file is part of YAZ proxy - Copyright (C) 1998-2008 Index Data + Copyright (C) 1998-2009 Index Data YAZ proxy 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 @@ -51,6 +51,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "msg-thread.h" +#if YAZ_VERSIONL >= 0x03001D +#define YAZ_HAS_MK_SURROGATE 1 +#else +#define YAZ_HAS_MK_SURROGATE 0 +#endif + using namespace yazpp_1; #ifdef WIN32 @@ -858,13 +864,13 @@ void Yaz_Proxy::display_diagrecs(Z_DiagRec **pp, int num) switch (r->which) { case Z_DefaultDiagFormat_v2Addinfo: - yaz_log(YLOG_LOG, "%sError %d %s:%s", + yaz_log(YLOG_LOG, "%sError " ODR_INT_PRINTF " %s:%s", m_session_str, *r->condition, diagbib1_str(*r->condition), r->u.v2Addinfo); break; case Z_DefaultDiagFormat_v3Addinfo: - yaz_log(YLOG_LOG, "%sError %d %s:%s", + yaz_log(YLOG_LOG, "%sError " ODR_INT_PRINTF " %s:%s", m_session_str, *r->condition, diagbib1_str(*r->condition), r->u.v3Addinfo); @@ -1231,8 +1237,10 @@ int Yaz_Proxy::z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res, return 0; } -static void yazproxy_encode_sru_surrogate(ODR o, Z_SRW_record *record, int pos, - int code, const char *details) +#if YAZ_HAS_MK_SURROGATE +#else +static void yazproxy_mk_sru_surrogate(ODR o, Z_SRW_record *record, int pos, + int code, const char *details) { const char *message = yaz_diag_srw_str(code); int len = 200; @@ -1258,7 +1266,7 @@ static void yazproxy_encode_sru_surrogate(ODR o, Z_SRW_record *record, int pos, record->recordPosition = odr_intdup(o, pos); record->recordSchema = odr_strdup(o, "info:srw/schema/1/diagnostics-v1.1"); } - +#endif int Yaz_Proxy::send_to_srw_client_ok(int hits, Z_Records *records, int start) { @@ -1279,10 +1287,15 @@ int Yaz_Proxy::send_to_srw_client_ok(int hits, Z_Records *records, int start) Z_NamePlusRecord *npr = records->u.databaseOrSurDiagnostics->records[i]; if (npr->which != Z_NamePlusRecord_databaseRecord) { - yaz_log(YLOG_LOG, "Point 1"); - yazproxy_encode_sru_surrogate( +#if YAZ_HAS_MK_SURROGATE + yaz_mk_sru_surrogate( + o, srw_res->records + i, i+start, + YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0); +#else + yazproxy_mk_sru_surrogate( o, srw_res->records + i, i+start, YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0); +#endif continue; } Z_External *r = npr->u.databaseRecord; @@ -1299,10 +1312,15 @@ int Yaz_Proxy::send_to_srw_client_ok(int hits, Z_Records *records, int start) } else { - yaz_log(YLOG_LOG, "Point 2"); - yazproxy_encode_sru_surrogate( +#if YAZ_HAS_MK_SURROGATE + yaz_mk_sru_surrogate( + o, srw_res->records + i, i+start, + YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0); +#else + yazproxy_mk_sru_surrogate( o, srw_res->records + i, i+start, YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0); +#endif } } } @@ -1333,12 +1351,13 @@ int Yaz_Proxy::send_srw_search_response(Z_SRW_diagnostic *diagnostics, int Yaz_Proxy::send_srw_explain_response(Z_SRW_diagnostic *diagnostics, int num_diagnostics) { + int http_status = 404; Yaz_ProxyConfig *cfg = check_reconfigure(); if (cfg) { int len; char *b = cfg->get_explain_doc(odr_encode(), 0 /* target */, - m_s2z_database, &len); + m_s2z_database, &len, &http_status); if (b) { Z_SRW_PDU *res = yaz_srw_get(odr_encode(), Z_SRW_explain_response); @@ -1355,7 +1374,7 @@ int Yaz_Proxy::send_srw_explain_response(Z_SRW_diagnostic *diagnostics, return send_srw_response(res); } } - return send_http_response(404); + return send_http_response(http_status); } int Yaz_Proxy::send_PDU_convert(Z_APDU *apdu) @@ -1475,7 +1494,7 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) } if (sr->resultCount) { - yaz_log(YLOG_LOG, "%s%d hits", m_session_str, + yaz_log(YLOG_LOG, "%s" ODR_INT_PRINTF " hits", m_session_str, *sr->resultCount); if (*sr->resultCount < 0) { @@ -2291,7 +2310,7 @@ Z_Records *Yaz_Proxy::create_nonSurrogateDiagnostics(ODR odr, { Z_Records *rec = (Z_Records *) odr_malloc (odr, sizeof(*rec)); - int *err = (int *) + Odr_int *err = (Odr_int *) odr_malloc (odr, sizeof(*err)); Z_DiagRec *drec = (Z_DiagRec *) odr_malloc (odr, sizeof(*drec)); @@ -2800,7 +2819,14 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) m_s2z_stylesheet = 0; Z_IdAuthentication *auth = NULL; - if (srw_pdu->username && srw_pdu->password) + if (srw_pdu->username && !srw_pdu->password) + { + yaz_log(YLOG_LOG, "username: %s\n", srw_pdu->username); + auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication)); + auth->which = Z_IdAuthentication_open; + auth->u.open = odr_strdup(m_s2z_odr_init, srw_pdu->username); + } + else if (srw_pdu->username && srw_pdu->password) { yaz_log(YLOG_LOG, "username/password: %s/%s\n", srw_pdu->username, srw_pdu->password); @@ -3948,6 +3974,7 @@ void Yaz_Proxy::base64_decode(const char *base64, char *buf, int buf_len) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab