* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: seshigh.c,v 1.117 2007-05-02 12:36:34 adam Exp $
+ * $Id: seshigh.c,v 1.128 2007-09-11 08:37:53 adam Exp $
*/
/**
* \file seshigh.c
#include <yaz/srw.h>
#include <yaz/backend.h>
+#include <yaz/yaz-ccl.h>
static void process_gdu_request(association *assoc, request *req);
static int process_z_request(association *assoc, request *req, char **msg);
if (sr->username)
{
- Z_IdAuthentication *auth = odr_malloc(assoc->decode, sizeof(*auth));
+ Z_IdAuthentication *auth = (Z_IdAuthentication *)
+ odr_malloc(assoc->decode, sizeof(*auth));
int len;
len = strlen(sr->username) + 1;
if (sr->password)
len += strlen(sr->password) + 2;
auth->which = Z_IdAuthentication_open;
- auth->u.open = odr_malloc(assoc->decode, len);
+ auth->u.open = (char *) odr_malloc(assoc->decode, len);
strcpy(auth->u.open, sr->username);
if (sr->password && *sr->password)
{
#if YAZ_HAVE_XML2
yaz_record_conv_t rc = 0;
const char *match_schema = 0;
- int *match_syntax = 0;
+ Odr_oid *match_syntax = 0;
if (assoc->server)
{
else
{
rr->len = wrbuf_len(output_record);
- rr->record = odr_malloc(rr->stream, rr->len);
+ rr->record = (char *) odr_malloc(rr->stream, rr->len);
memcpy(rr->record, wrbuf_buf(output_record), rr->len);
}
wrbuf_destroy(output_record);
if (rr.errstring)
len += strlen(rr.errstring);
- record->recordData_buf = odr_malloc(o, len);
+ record->recordData_buf = (char *) odr_malloc(o, len);
sprintf(record->recordData_buf, "<diagnostic "
"xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">\n"
record->recordData_buf = rr.record;
record->recordData_len = rr.len;
record->recordPosition = odr_intdup(o, pos);
- if (rr.schema)
- record->recordSchema = odr_strdup(o, rr.schema);
- else
- record->recordSchema = 0;
+ record->recordSchema = odr_strdup_null(o, rr.schema);
}
if (rr.errcode)
{
return 0;
}
+
+static int ccl2pqf(ODR odr, const Odr_oct *ccl, CCL_bibset bibset,
+ bend_search_rr *bsrr) {
+ char *ccl0;
+ struct ccl_rpn_node *node;
+ int errcode, pos;
+
+ ccl0 = odr_strdupn(odr, (char*) ccl->buf, ccl->len);
+ if ((node = ccl_find_str(bibset, ccl0, &errcode, &pos)) == 0) {
+ bsrr->errstring = (char*) ccl_err_msg(errcode);
+ return 10; /* Query syntax error */
+ }
+
+ bsrr->query->which = Z_Query_type_1;
+ bsrr->query->u.type_1 = ccl_rpn_query(odr, node);
+ return 0;
+}
+
+
static void srw_bend_search(association *assoc, request *req,
Z_SRW_PDU *sr,
Z_SRW_searchRetrieveResponse *srw_res,
odr_intdup(assoc->encode, *rr.srw_setnameIdleTime );
}
- if ((rr.hits > 0 && start > rr.hits) || start < 1)
+ if (start > rr.hits || start < 1)
{
- yaz_add_srw_diagnostic(
- assoc->encode,
- &srw_res->diagnostics, &srw_res->num_diagnostics,
- YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0);
+ /* if hits<=0 and start=1 we don't return a diagnostic */
+ if (start != 1)
+ yaz_add_srw_diagnostic(
+ assoc->encode,
+ &srw_res->diagnostics, &srw_res->num_diagnostics,
+ YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0);
}
else if (number > 0)
{
static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr)
{
#if YAZ_HAVE_XML2
- xmlNodePtr ptr = rr->server_node_ptr;
+ xmlNodePtr ptr = (xmlNode *) rr->server_node_ptr;
if (!ptr)
return 0;
for (ptr = ptr->children; ptr; ptr = ptr->next)
bsrr->print = assoc->print;
bsrr->step_size = odr_intdup(assoc->decode, 0);
bsrr->entries = 0;
+ bsrr->setname = 0;
if (bsrr->num_entries > 0)
{
int i;
- bsrr->entries = odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
- bsrr->num_entries);
+ bsrr->entries = (struct scan_entry *)
+ odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
+ bsrr->num_entries);
for (i = 0; i<bsrr->num_entries; i++)
{
bsrr->entries[i].term = 0;
int srw_error;
bsrr->scanClause = 0;
bsrr->attributeset = 0;
- bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term));
+ bsrr->term = (Z_AttributesPlusTerm *)
+ odr_malloc(assoc->decode, sizeof(*bsrr->term));
srw_error = cql2pqf_scan(assoc->encode,
srw_req->scanClause.cql,
assoc->server->cql_transform,
fseek(inf, 0L, SEEK_END);
*sz = ftell(inf);
rewind(inf);
- buf = odr_malloc(o, *sz);
+ buf = (char *) odr_malloc(o, *sz);
fread(buf, 1, *sz, inf);
fclose(inf);
return buf;
if (sr->which == Z_SRW_searchRetrieve_request)
{
Z_SRW_PDU *res =
- yaz_srw_get(assoc->encode, Z_SRW_searchRetrieve_response);
-
+ yaz_srw_get_pdu(assoc->encode, Z_SRW_searchRetrieve_response,
+ sr->srw_version);
stylesheet = sr->u.request->stylesheet;
if (num_diagnostic)
{
}
else if (sr->which == Z_SRW_explain_request)
{
- Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_explain_response);
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_explain_response,
+ sr->srw_version);
stylesheet = sr->u.explain_request->stylesheet;
if (num_diagnostic)
{
}
else if (sr->which == Z_SRW_scan_request)
{
- Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_scan_response);
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_scan_response,
+ sr->srw_version);
stylesheet = sr->u.scan_request->stylesheet;
if (num_diagnostic)
{
}
else if (sr->which == Z_SRW_update_request)
{
- Z_SRW_PDU *res = yaz_srw_get(o, Z_SRW_update_response);
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_update_response,
+ sr->srw_version);
yaz_log(YLOG_DEBUG, "handling SRW UpdateRequest");
if (num_diagnostic)
{
#endif
{0, 0, 0}
};
- char ctype[60];
+ char ctype[80];
int ret;
p = z_get_HTTP_Response(o, 200);
hres = p->u.HTTP_Response;
hres->code = http_code;
strcpy(ctype, "text/xml");
- if (charset)
+ if (charset && strlen(charset) < sizeof(ctype)-30)
{
strcat(ctype, "; charset=");
strcat(ctype, charset);
else
{
/* no backend. return error */
- binitres = odr_malloc(assoc->encode, sizeof(*binitres));
+ binitres = (bend_initresult *)
+ odr_malloc(assoc->encode, sizeof(*binitres));
binitres->errstring = 0;
binitres->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR;
iochan_settimeout(assoc->client_chan, 10);
strcat(options, " sort");
}
- if (!assoc->init->charneg_response && !assoc->init->charneg_request)
+ if (ODR_MASK_GET(req->options, Z_Options_negotiationModel))
{
- if (assoc->init->query_charset)
+ Z_OtherInformationUnit *p0;
+
+ if (!assoc->init->charneg_response)
{
- assoc->init->charneg_response = yaz_set_response_charneg(
- assoc->encode, assoc->init->query_charset, 0,
- assoc->init->records_in_same_charset);
+ if (assoc->init->query_charset)
+ {
+ assoc->init->charneg_response = yaz_set_response_charneg(
+ assoc->encode, assoc->init->query_charset, 0,
+ assoc->init->records_in_same_charset);
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "default query_charset not defined by backend");
+ }
}
- else
+ if (assoc->init->charneg_response
+ && (p0=yaz_oi_update(&resp->otherInfo, assoc->encode, NULL, 0, 0)))
{
- yaz_log(YLOG_WARN, "default query_charset not defined by backend");
- }
- }
- if (assoc->init->charneg_response
- && ODR_MASK_GET(req->options, Z_Options_negotiationModel))
- {
- Z_OtherInformation **p;
- Z_OtherInformationUnit *p0;
-
- yaz_oi_APDU(apdu, &p);
-
- if ((p0=yaz_oi_update(p, assoc->encode, NULL, 0, 0))) {
- ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
-
p0->which = Z_OtherInfo_externallyDefinedInfo;
p0->information.externallyDefinedInfo =
assoc->init->charneg_response;
+ ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
+ strcat(options, " negotiation");
}
- ODR_MASK_SET(resp->options, Z_Options_negotiationModel);
- strcat(options, " negotiation");
}
if (ODR_MASK_GET(req->options, Z_Options_triggerResourceCtrl))
ODR_MASK_SET(resp->options, Z_Options_triggerResourceCtrl);
assoc->init->implementation_name,
odr_prepend(assoc->encode, "GFS", resp->implementationName));
- version = odr_strdup(assoc->encode, "$Revision: 1.117 $");
+ version = odr_strdup(assoc->encode, "$Revision: 1.128 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
resp->implementationVersion = odr_prepend(assoc->encode,
int *num, Z_RecordComposition *comp,
int *next, int *pres,
Z_ReferenceId *referenceId,
- int *oid, int *errcode)
+ Odr_oid *oid, int *errcode)
{
int recno, total_length = 0, toget = *num, dumped_records = 0;
Z_Records *records =
if (!(thisrec = (Z_NamePlusRecord *)
odr_malloc(a->encode, sizeof(*thisrec))))
return 0;
- if (freq.basename)
- thisrec->databaseName = odr_strdup(a->encode, freq.basename);
- else
- thisrec->databaseName = 0;
+ thisrec->databaseName = odr_strdup_null(a->encode, freq.basename);
thisrec->which = Z_NamePlusRecord_databaseRecord;
if (!freq.output_format)
if (srw_errcode)
bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
}
+
+ if (assoc->server && assoc->server->ccl_transform
+ && req->query->which == Z_Query_type_2) /*CCL*/
+ {
+ /* have a CCL query and a CCL to PQF transform .. */
+ int srw_errcode =
+ ccl2pqf(bsrr->stream, req->query->u.type_2,
+ assoc->server->ccl_transform, bsrr);
+ if (srw_errcode)
+ bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode);
+ }
+
if (!bsrr->errcode)
(assoc->init->bend_search)(assoc->backend, bsrr);
if (!bsrr->request) /* backend not ready with the search response */
bsrr->stream = assoc->encode;
bsrr->print = assoc->print;
bsrr->step_size = res->stepSize;
+ bsrr->setname = yaz_oi_get_string_oid(&req->otherInfo,
+ yaz_oid_userinfo_scan_set, 1, 0);
bsrr->entries = 0;
/* For YAZ 2.0 and earlier it was the backend handler that
initialized entries (member display_term did not exist)
if (bsrr->num_entries > 0)
{
int i;
- bsrr->entries = odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
- bsrr->num_entries);
+ bsrr->entries = (struct scan_entry *)
+ odr_malloc(assoc->decode, sizeof(*bsrr->entries) *
+ bsrr->num_entries);
for (i = 0; i<bsrr->num_entries; i++)
{
bsrr->entries[i].term = 0;
int i;
WRBUF wr = wrbuf_alloc();
wrbuf_printf(wr, "Scan ");
- for (i = 0 ; i < req->num_databaseNames; i++){
+ for (i = 0 ; i < req->num_databaseNames; i++)
+ {
if (i)
wrbuf_printf(wr, "+");
wrbuf_printf(wr, req->databaseNames[i]);
}
+
wrbuf_printf(wr, " ");
- if (bsrr->errcode){
+ if (bsrr->errcode)
wr_diag(wr, bsrr->errcode, bsrr->errstring);
- wrbuf_printf(wr, " ");
- }
- else
- wrbuf_printf(wr, "OK ");
- /* else if (*res->scanStatus == Z_Scan_success) */
- /* wrbuf_printf(wr, "OK "); */
- /* else */
- /* wrbuf_printf(wr, "Partial "); */
-
- if (*res->numberOfEntriesReturned)
- wrbuf_printf(wr, "%d - ", *res->numberOfEntriesReturned);
else
- wrbuf_printf(wr, "0 - ");
+ wrbuf_printf(wr, "OK");
- wrbuf_printf(wr, "%d+%d+%d ",
+ wrbuf_printf(wr, " %d - %d+%d+%d",
+ res->numberOfEntriesReturned ?
+ *res->numberOfEntriesReturned : 0,
(req->preferredPositionInResponse ?
*req->preferredPositionInResponse : 1),
*req->numberOfTermsRequested,
(res->stepSize ? *res->stepSize : 1));
+
+ if (bsrr->setname)
+ wrbuf_printf(wr, "+%s", bsrr->setname);
+ wrbuf_printf(wr, " ");
yaz_scan_to_wrbuf(wr, req->termListAndStartPoint,
bsrr->attributeset);
yaz_log(log_request, "%s", wrbuf_cstr(wr) );