X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fseshigh.c;h=ddb7288cb4293e747c7379032e3000dd6130ad01;hp=44d6619001283a2fc22244cc12c73b0609e7498f;hb=bdc72ca302452e555308e716c2f1e1743866a9ef;hpb=92e360a6e22fc5fda22d7f6a6449c3c8f0ee8fb9 diff --git a/src/seshigh.c b/src/seshigh.c index 44d6619..ddb7288 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ /** @@ -25,12 +25,14 @@ * minimize memory allocation/deallocation during normal operation. * */ +#if HAVE_CONFIG_H +#include +#endif #include #include #include #include -#include #if HAVE_SYS_TYPES_H #include @@ -54,7 +56,6 @@ #include #endif -#include #include #include #include "eventl.h" @@ -224,10 +225,6 @@ void destroy_association(association *h) request_delq(&h->outgoing); xfree(h); xmalloc_trav("session closed"); - if (cb && cb->one_shot) - { - exit(0); - } } static void do_close_req(association *a, int reason, char *message, @@ -541,6 +538,9 @@ static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num, Z_S len = strlen(sr->username) + 1; if (sr->password) len += strlen(sr->password) + 2; + yaz_log(log_requestdetail, "username=%s password-len=%ld", + sr->username, (long) + (sr->password ? strlen(sr->password) : 0)); auth->which = Z_IdAuthentication_open; auth->u.open = (char *) odr_malloc(assoc->decode, len); strcpy(auth->u.open, sr->username); @@ -755,7 +755,7 @@ static int srw_bend_fetch(association *assoc, int pos, } static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct, - Z_Query *query_result) + Z_Query *query_result, char **sortkeys_p) { /* have a CQL query and CQL to PQF transform .. */ CQL_parser cp = cql_parser_create(); @@ -763,7 +763,8 @@ static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct, int srw_errcode = 0; const char *add = 0; char rpn_buf[5120]; - + + *sortkeys_p = 0; r = cql_parser_string(cp, cql); if (r) { @@ -771,12 +772,29 @@ static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct, } if (!r) { + struct cql_node *cn = cql_parser_result(cp); + /* Syntax OK */ - r = cql_transform_buf(ct, - cql_parser_result(cp), - rpn_buf, sizeof(rpn_buf)-1); + r = cql_transform_buf(ct, cn, rpn_buf, sizeof(rpn_buf)-1); if (r) srw_errcode = cql_transform_error(ct, &add); + else + { + char out[100]; + int r = cql_sortby_to_sortkeys_buf(cn, out, sizeof(out)-1); + + if (r == 0) + { + if (*out) + yaz_log (log_requestdetail, "srw_sortKeys '%s'", out); + *sortkeys_p = odr_strdup(odr, out); + } + else + { + yaz_log(log_requestdetail, "failed to create srw_sortKeys"); + srw_errcode = YAZ_SRW_UNSUPP_SORT_TYPE; + } + } } if (!r) { @@ -809,7 +827,8 @@ static int cql2pqf_scan(ODR odr, const char *cql, cql_transform_t ct, { Z_Query query; Z_RPNQuery *rpn; - int srw_error = cql2pqf(odr, cql, ct, &query); + char *sortkeys = 0; + int srw_error = cql2pqf(odr, cql, ct, &query, &sortkeys); if (srw_error) return srw_error; if (query.which != Z_Query_type_1 && query.which != Z_Query_type_101) @@ -883,7 +902,9 @@ static void srw_bend_search(association *assoc, { int srw_errcode = cql2pqf(assoc->encode, srw_req->query.cql, assoc->server->cql_transform, - rr.query); + rr.query, + &rr.srw_sortKeys); + if (srw_errcode) { yaz_add_srw_diagnostic(assoc->encode, @@ -942,14 +963,15 @@ static void srw_bend_search(association *assoc, rr.stream = assoc->encode; rr.decode = assoc->decode; rr.print = assoc->print; - if ( srw_req->sort.sortKeys ) + if (srw_req->sort.sortKeys) rr.srw_sortKeys = odr_strdup(assoc->encode, - srw_req->sort.sortKeys ); + srw_req->sort.sortKeys); rr.association = assoc; rr.hits = 0; rr.errcode = 0; rr.errstring = 0; rr.search_info = 0; + rr.search_input = 0; yaz_log_zquery_level(log_requestdetail,rr.query); (assoc->init->bend_search)(assoc->backend, &rr); @@ -1139,7 +1161,7 @@ static void srw_bend_search(association *assoc, (srw_res->numberOfRecords ? *srw_res->numberOfRecords : 0)); } - wrbuf_printf(wr, " %s " ODR_INT_PRINTF " +%d", + wrbuf_printf(wr, " %s " ODR_INT_PRINTF "+%d", (srw_res->resultSetId ? srw_res->resultSetId : "-"), (srw_req->startRecord ? *srw_req->startRecord : 1), @@ -1906,7 +1928,7 @@ static void process_http_request(association *assoc, request *req) keepalive = 1; hres->version = "1.1"; } - if (!keepalive) + if (!keepalive || !assoc->last_control->keepalive) { z_HTTP_header_add(o, &hres->headers, "Connection", "close"); assoc->state = ASSOC_DEAD; @@ -1917,7 +1939,7 @@ static void process_http_request(association *assoc, request *req) int t; const char *alive = z_HTTP_header_lookup(hreq->headers, "Keep-Alive"); - if (alive && isdigit(*(const unsigned char *) alive)) + if (alive && yaz_isdigit(*(const unsigned char *) alive)) t = atoi(alive); else t = 15; @@ -2032,7 +2054,7 @@ static int process_z_request(association *assoc, request *req, char **msg) } else { - yaz_log(YLOG_DEBUG, " result unavailble"); + yaz_log(YLOG_DEBUG, " result unavailable"); retval = -1; } return retval; @@ -2088,7 +2110,7 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res) */ static int process_z_response(association *assoc, request *req, Z_APDU *res) { - Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*res)); + Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*gres)); gres->which = Z_GDU_Z3950; gres->u.z3950 = res; @@ -2158,7 +2180,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) yaz_log(log_requestdetail, "Config: %s", cb->configname); - iochan_settimeout(assoc->client_chan, cb->idle_timeout * 60); + iochan_settimeout(assoc->client_chan, cb->idle_timeout); /* we have a backend control block, so call that init function */ if (!(binitres = (*cb->bend_init)(assoc->init))) @@ -2501,6 +2523,7 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, } if (freq.record == 0) /* no error and no record ? */ { + *pres = Z_PresentStatus_partial_4; *next = 0; /* signal end-of-set and stop */ break; } @@ -2518,6 +2541,8 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, { yaz_log(log_requestdetail, " Dropped last normal-sized record"); *pres = Z_PresentStatus_partial_2; + if (*next > 0) + (*next)--; break; } /* record can only be fetched by itself */ @@ -2528,7 +2553,9 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, { yaz_log(YLOG_DEBUG, " Dropped it"); reclist->records[reclist->num_records] = - surrogatediagrec(a, freq.basename, 16, 0); + surrogatediagrec( + a, freq.basename, + YAZ_BIB1_RECORD_EXCEEDS_PREFERRED_MESSAGE_SIZE, 0); reclist->num_records++; dumped_records += this_length; continue; @@ -2540,7 +2567,9 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, "this=%d max=%d", this_length, a->maximumRecordSize); reclist->records[reclist->num_records] = - surrogatediagrec(a, freq.basename, 17, 0); + surrogatediagrec( + a, freq.basename, + YAZ_BIB1_RECORD_EXCEEDS_MAXIMUM_RECORD_SIZE, 0); reclist->num_records++; dumped_records += this_length; continue; @@ -2554,7 +2583,10 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start, thisrec->which = Z_NamePlusRecord_databaseRecord; if (!freq.output_format) - freq.output_format = freq.request_format; + { + yaz_log(YLOG_WARN, "bend_fetch output_format not set"); + return 0; + } thisrec->u.databaseRecord = z_ext_record_oid( a->encode, freq.output_format, freq.record, freq.len); if (!thisrec->u.databaseRecord) @@ -2608,6 +2640,7 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb) bsrr->errcode = 0; bsrr->errstring = NULL; bsrr->search_info = NULL; + bsrr->search_input = req->otherInfo; if (assoc->server && assoc->server->cql_transform && req->query->which == Z_Query_type_104 @@ -2616,7 +2649,8 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb) /* have a CQL query and a CQL to PQF transform .. */ int srw_errcode = cql2pqf(bsrr->stream, req->query->u.type_104->u.cql, - assoc->server->cql_transform, bsrr->query); + assoc->server->cql_transform, bsrr->query, + &bsrr->srw_sortKeys); if (srw_errcode) bsrr->errcode = yaz_diag_srw_to_bib1(srw_errcode); }