#include <yaz/oid_db.h>
#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
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}
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, "<diagnostic "
+ "xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">\n"
+ " <uri>info:srw/diagnostic/1/%d</uri>\n", code);
+ if (details)
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ " <details>%s</details>\n", details);
+ if (message)
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ " <message>%s</message>\n", message);
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ "</diagnostic>\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();
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;
}
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
}
}
}
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);
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)