X-Git-Url: http://git.indexdata.com/?p=yazproxy-moved-to-github.git;a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=1d6e22c09adb4133c072b432fbae361b3d3083ea;hp=314c71d4478deddaac20eb8ae7f385e5f6d57fc2;hb=dfdff5f2d2825a500d3d27200d2ec32ee063a975;hpb=47e64a294a4548ee3c7eaf9fb244672dd380e959 diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 314c71d..1d6e22c 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 @@ -1173,7 +1179,7 @@ int Yaz_Proxy::send_srw_response(Z_SRW_PDU *srw_pdu, int http_code /* = 200 */) static Z_SOAP_Handler soap_handlers[2] = { #if YAZ_HAVE_XSLT - {"http://www.loc.gov/zing/srw/", 0, + { (char*) "http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec}, #endif {0, 0, 0} @@ -1231,6 +1237,37 @@ int Yaz_Proxy::z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res, return 0; } +#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; + if (message) + len += strlen(message); + if (details) + len += strlen(details); + + record->recordData_buf = (char *) odr_malloc(o, len); + + sprintf(record->recordData_buf, "\n" + " info:srw/diagnostic/1/%d\n", code); + if (details) + sprintf(record->recordData_buf + strlen(record->recordData_buf), + "
%s
\n", details); + if (message) + sprintf(record->recordData_buf + strlen(record->recordData_buf), + " %s\n", message); + sprintf(record->recordData_buf + strlen(record->recordData_buf), + "
\n"); + record->recordData_len = strlen(record->recordData_buf); + 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) { ODR o = odr_encode(); @@ -1250,11 +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) { - srw_res->records[i].recordSchema = "diagnostic"; - srw_res->records[i].recordPacking = m_s2z_packing; - srw_res->records[i].recordData_buf = "67"; - srw_res->records[i].recordData_len = 2; - srw_res->records[i].recordPosition = odr_intdup(o, i+start); +#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; @@ -1271,11 +1312,15 @@ int Yaz_Proxy::send_to_srw_client_ok(int hits, Z_Records *records, int start) } else { - srw_res->records[i].recordSchema = "diagnostic"; - srw_res->records[i].recordPacking = m_s2z_packing; - srw_res->records[i].recordData_buf = "67"; - srw_res->records[i].recordData_len = 2; - srw_res->records[i].recordPosition = odr_intdup(o, i+start); +#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 } } } @@ -1306,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); @@ -1320,14 +1366,15 @@ int Yaz_Proxy::send_srw_explain_response(Z_SRW_diagnostic *diagnostics, er->record.recordData_buf = b; er->record.recordData_len = len; er->record.recordPacking = m_s2z_packing; - er->record.recordSchema = "http://explain.z3950.org/dtd/2.0/"; + er->record.recordSchema = odr_strdup(odr_encode(), + "http://explain.z3950.org/dtd/2.0/"); er->diagnostics = diagnostics; er->num_diagnostics = num_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) @@ -3920,6 +3967,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