/*
- * Copyright (c) 1995-2003, Index Data
+ * Copyright (c) 1995-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: seshigh.c,v 1.14 2004-01-07 20:36:44 adam Exp $
+ * $Id: seshigh.c,v 1.33 2004-10-15 00:19:00 adam Exp $
*/
-
-/*
+/**
+ * \file seshigh.c
+ * \brief Implements GFS session logic.
+ *
* Frontend server logic.
*
* This code receives incoming APDUs, and handles client requests by means
ce = yaz_set_proposal_charneg(assoc->decode, &encoding, 1, 0, 0, 1);
assoc->init->charneg_request = ce->u.charNeg3;
#endif
+ assoc->backend = 0;
if (!(binitres = (*cb->bend_init)(assoc->init)))
{
yaz_log(LOG_WARN, "Bad response from backend.");
rr.comp->u.complex->generic = (Z_Specification *)
odr_malloc(assoc->decode, sizeof(Z_Specification));
+
+ /* schema uri = recordSchema (or NULL if recordSchema is not given) */
rr.comp->u.complex->generic->which = Z_Schema_uri;
rr.comp->u.complex->generic->schema.uri = srw_req->recordSchema;
+
+ /* ESN = recordSchema if recordSchema is present */
rr.comp->u.complex->generic->elementSpec = 0;
+ if (srw_req->recordSchema)
+ {
+ rr.comp->u.complex->generic->elementSpec =
+ (Z_ElementSpec *) odr_malloc(assoc->encode, sizeof(Z_ElementSpec));
+ rr.comp->u.complex->generic->elementSpec->which =
+ Z_ElementSpec_elementSetName;
+ rr.comp->u.complex->generic->elementSpec->u.elementSetName =
+ srw_req->recordSchema;
+ }
rr.stream = assoc->encode;
rr.print = assoc->print;
(*assoc->init->bend_fetch)(assoc->backend, &rr);
- if (rr.len >= 0)
+ if (rr.errcode && rr.surrogate_flag)
+ {
+ int code = yaz_diag_bib1_to_srw(rr.errcode);
+ const char *message = yaz_diag_srw_str(code);
+ int len = 200;
+ if (message)
+ len += strlen(message);
+ if (rr.errstring)
+ len += strlen(rr.errstring);
+
+ record->recordData_buf = 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 (rr.errstring)
+ sprintf(record->recordData_buf + strlen(record->recordData_buf),
+ " <details>%s</details>\n", rr.errstring);
+ 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 = "info:srw/schema/1/diagnostics-v1.1";
+ return 0;
+ }
+ else if (rr.len >= 0)
{
record->recordData_buf = rr.record;
record->recordData_len = rr.len;
{
srw_error = 3; /* assume Authentication error */
- srw_res->num_diagnostics = 1;
- srw_res->diagnostics = (Z_SRW_diagnostic *)
- odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
- srw_res->diagnostics[0].code =
- odr_intdup(assoc->encode, srw_error);
- srw_res->diagnostics[0].details = 0;
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics, 1, 0);
return;
}
}
const char *pqf_msg;
size_t off;
int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
- yaz_log(LOG_LOG, "%*s^\n", off+4, "");
+ if (off < 200)
+ yaz_log(LOG_LOG, "%*s^\n", (int)off+4, "");
yaz_log(LOG_LOG, "Bad PQF: %s (code %d)\n", pqf_msg, code);
srw_error = 10;
srw_res->num_diagnostics = 1;
srw_res->diagnostics = (Z_SRW_diagnostic *)
odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
- srw_res->diagnostics[0].code =
- odr_intdup(assoc->encode, srw_error);
- srw_res->diagnostics[0].details = 0;
+ yaz_mk_std_diagnostic(assoc->encode,
+ srw_res->diagnostics, srw_error, 0);
return;
}
rr.search_info = 0;
yaz_log_zquery(rr.query);
(assoc->init->bend_search)(assoc->backend, &rr);
- srw_res->numberOfRecords = odr_intdup(assoc->encode, rr.hits);
if (rr.errcode)
{
yaz_log(LOG_DEBUG, "bend_search returned Bib-1 code %d", rr.errcode);
srw_res->num_diagnostics = 1;
srw_res->diagnostics = (Z_SRW_diagnostic *)
odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
- srw_res->diagnostics[0].code =
- odr_intdup(assoc->encode,
- yaz_diag_bib1_to_srw (rr.errcode));
- srw_res->diagnostics[0].details = rr.errstring;
- yaz_log(LOG_DEBUG, "srw_bend_search returned SRW error %d",
- *srw_res->diagnostics[0].code);
-
+ yaz_mk_std_diagnostic(assoc->encode, srw_res->diagnostics,
+ yaz_diag_bib1_to_srw (rr.errcode),
+ rr.errstring);
+ yaz_log(LOG_DEBUG, "srw_bend_search returned SRW error %s",
+ srw_res->diagnostics[0].uri);
}
else
{
if (start > rr.hits)
{
- yaz_log(LOG_LOG, "Request out or range");
+ srw_res->num_diagnostics = 1;
+ srw_res->diagnostics = (Z_SRW_diagnostic *)
+ odr_malloc(assoc->encode,
+ sizeof(*srw_res->diagnostics));
+ yaz_mk_std_diagnostic(assoc->encode, srw_res->diagnostics,
+ 61, 0);
}
else
{
srw_res->diagnostics = (Z_SRW_diagnostic *)
odr_malloc(assoc->encode,
sizeof(*srw_res->diagnostics));
- srw_res->diagnostics[0].code =
- odr_intdup(assoc->encode,
- yaz_diag_bib1_to_srw (errcode));
- srw_res->diagnostics[0].details = rr.errstring;
+
+ yaz_mk_std_diagnostic(assoc->encode,
+ srw_res->diagnostics,
+ yaz_diag_bib1_to_srw (errcode),
+ rr.errstring);
break;
}
if (srw_res->records[j].recordData_buf)
rr.print = assoc->print;
rr.explain_buf = 0;
rr.database = srw_req->database;
+ rr.schema = "http://explain.z3950.org/dtd/2.0/";
(*assoc->init->bend_explain)(assoc->backend, &rr);
if (rr.explain_buf)
{
if (srw_req->recordPacking &&
!strcmp(srw_req->recordPacking, "xml"))
packing = Z_SRW_recordPacking_XML;
- srw_res->record.recordSchema = 0;
+ srw_res->record.recordSchema = rr.schema;
srw_res->record.recordPacking = packing;
srw_res->record.recordData_buf = rr.explain_buf;
srw_res->record.recordData_len = strlen(rr.explain_buf);
{
Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request;
ODR o = assoc->encode;
- int r;
+ int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */
Z_SRW_PDU *sr = 0;
Z_SOAP *soap_package = 0;
Z_GDU *p = 0;
char *charset = 0;
- Z_HTTP_Response *hres;
+ Z_HTTP_Response *hres = 0;
int keepalive = 1;
char *stylesheet = 0;
+ Z_SRW_diagnostic *diagnostic = 0;
+ int num_diagnostic = 0;
- r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
+ if (!strcmp(hreq->path, "/test"))
+ {
+ p = z_get_HTTP_Response(o, 200);
+ hres = p->u.HTTP_Response;
+ hres->content_buf = "1234567890\n";
+ hres->content_len = strlen(hres->content_buf);
+ r = 1;
+ }
+ if (r == 2)
+ {
+ r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
+ yaz_log(LOG_DEBUG, "yaz_srw_decode returned %d", r);
+ }
if (r == 2) /* not taken */
- r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
+ {
+ r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset,
+ &diagnostic, &num_diagnostic);
+ yaz_log(LOG_DEBUG, "yaz_sru_decode returned %d", r);
+ }
if (r == 0) /* decode SRW/SRU OK .. */
{
int http_code = 200;
yaz_srw_get(assoc->encode, Z_SRW_searchRetrieve_response);
stylesheet = sr->u.request->stylesheet;
- srw_bend_search(assoc, req, sr->u.request, res->u.response,
- &http_code);
+ if (num_diagnostic)
+ {
+ res->u.response->diagnostics = diagnostic;
+ res->u.response->num_diagnostics = num_diagnostic;
+ }
+ else
+ {
+ srw_bend_search(assoc, req, sr->u.request, res->u.response,
+ &http_code);
+ }
if (http_code == 200)
soap_package->u.generic->p = res;
}
{
Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_explain_response);
stylesheet = sr->u.explain_request->stylesheet;
- srw_bend_explain(assoc, req, sr->u.explain_request,
+ if (num_diagnostic)
+ {
+ res->u.explain_response->diagnostics = diagnostic;
+ res->u.explain_response->num_diagnostics = num_diagnostic;
+ }
+ srw_bend_explain(assoc, req, sr->u.explain_request,
res->u.explain_response, &http_code);
if (http_code == 200)
soap_package->u.generic->p = res;
}
+ else if (sr->which == Z_SRW_scan_request)
+ {
+ Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_scan_response);
+ stylesheet = sr->u.scan_request->stylesheet;
+ if (num_diagnostic)
+ {
+ res->u.scan_response->diagnostics = diagnostic;
+ res->u.scan_response->num_diagnostics = num_diagnostic;
+ }
+ yaz_add_srw_diagnostic(o,
+ &res->u.scan_response->diagnostics,
+ &res->u.scan_response->num_diagnostics,
+ 4, "scan");
+ if (http_code == 200)
+ soap_package->u.generic->p = res;
+ }
else
{
+ yaz_log(LOG_LOG, "generate soap error");
http_code = 500;
z_soap_error(assoc->encode, soap_package,
"SOAP-ENV:Client", "Bad method", 0);
int ret;
p = z_get_HTTP_Response(o, 200);
hres = p->u.HTTP_Response;
- ret = z_soap_codec_enc(assoc->encode, &soap_package,
- &hres->content_buf, &hres->content_len,
- soap_handlers, charset, stylesheet);
+ ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package,
+ &hres->content_buf, &hres->content_len,
+ soap_handlers, charset, stylesheet);
hres->code = http_code;
strcpy(ctype, "text/xml");
else
p = z_get_HTTP_Response(o, http_code);
}
- else
+
+ if (p == 0)
p = z_get_HTTP_Response(o, 500);
hres = p->u.HTTP_Response;
if (!strcmp(hreq->version, "1.0"))
return -1;
}
break;
+ case Z_APDU_triggerResourceControlRequest:
+ return 0;
default:
*msg = "Bad APDU received";
return -1;
{
Z_CharSetandLanguageNegotiation *negotiation =
yaz_get_charneg_record (req->otherInfo);
- if (negotiation->which == Z_CharSetandLanguageNegotiation_proposal)
+ if (negotiation &&
+ negotiation->which == Z_CharSetandLanguageNegotiation_proposal)
assoc->init->charneg_request = negotiation;
}
+ assoc->backend = 0;
if (!(binitres = (*cb->bend_init)(assoc->init)))
{
yaz_log(LOG_WARN, "Bad response from backend.");
ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
strcat(options, " negotiation");
}
+
+ ODR_MASK_SET(resp->options, Z_Options_triggerResourceCtrl);
if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
{
ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
- assoc->version = 2; /* 1 & 2 are equivalent */
+ assoc->version = 1; /* 1 & 2 are equivalent */
}
if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
{
assoc->init->implementation_name,
odr_prepend(assoc->encode, "GFS", resp->implementationName));
- version = odr_strdup(assoc->encode, "$Revision: 1.14 $");
+ version = odr_strdup(assoc->encode, "$Revision: 1.33 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
resp->implementationVersion = odr_prepend(assoc->encode,
e->which = Z_DiagnosticFormat_s_defaultDiagRec;
e->u.defaultDiagRec = justdiag(odr, error, addinfo);
+ e->message = 0;
return x;
}
records->u.databaseOrSurDiagnostics = reclist;
reclist->num_records = 0;
reclist->records = list;
- *pres = Z_PRES_SUCCESS;
+ *pres = Z_PresentStatus_success;
*num = 0;
*next = 0;
if (!freq.surrogate_flag)
{
char s[20];
- *pres = Z_PRES_FAILURE;
+ *pres = Z_PresentStatus_failure;
/* for 'present request out of range',
set addinfo to record position if not set */
if (freq.errcode == 13 && freq.errstring == 0)
this_length = odr_total(a->encode) - total_length - dumped_records;
yaz_log(LOG_DEBUG, " fetched record, len=%d, total=%d dumped=%d",
this_length, total_length, dumped_records);
- if (this_length + total_length > a->preferredMessageSize)
+ if (a->preferredMessageSize > 0 &&
+ this_length + total_length > a->preferredMessageSize)
{
/* record is small enough, really */
if (this_length <= a->preferredMessageSize && recno > start)
{
yaz_log(LOG_DEBUG, " Dropped last normal-sized record");
- *pres = Z_PRES_PARTIAL_2;
+ *pres = Z_PresentStatus_partial_2;
break;
}
/* record can only be fetched by itself */
int *nulint = odr_intdup (assoc->encode, 0);
bool_t *sr = odr_intdup(assoc->encode, 1);
int *next = odr_intdup(assoc->encode, 0);
- int *none = odr_intdup(assoc->encode, Z_RES_NONE);
+ int *none = odr_intdup(assoc->encode, Z_SearchResponse_none);
apdu->which = Z_APDU_searchResponse;
apdu->u.searchResponse = resp;
if (bprr->errcode)
{
resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
- *resp->presentStatus = Z_PRES_FAILURE;
+ *resp->presentStatus = Z_PresentStatus_failure;
}
}
apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
bsrr->stream = assoc->encode;
bsrr->print = assoc->print;
- bsrr->sort_status = Z_SortStatus_failure;
+ bsrr->sort_status = Z_SortResponse_failure;
bsrr->errcode = 0;
bsrr->errstring = 0;