X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fseshigh.c;h=34510abf10f8ce8d5160632b9f510ba6cf13b9cf;hb=b853eb3de1a249859eef71c9a285172a199656ce;hp=1aea6702e99b8e4e42a44bffbb96c77021ff1741;hpb=7a5a8c9cbc588f8c52f54bacca3e8e07058f713f;p=yaz-moved-to-github.git diff --git a/src/seshigh.c b/src/seshigh.c index 1aea670..34510ab 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.50 2005-03-05 09:17:27 adam Exp $ + * $Id: seshigh.c,v 1.56 2005-05-20 19:29:18 adam Exp $ */ /** * \file seshigh.c @@ -506,7 +506,8 @@ static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num) if (!(binitres = (*cb->bend_init)(assoc->init))) { assoc->state = ASSOC_DEAD; - yaz_add_srw_diagnostic(assoc->encode, d, num, 3, 0); + yaz_add_srw_diagnostic(assoc->encode, d, num, + YAZ_SRW_AUTHENTICATION_ERROR, 0); return 0; } assoc->backend = binitres->handle; @@ -712,10 +713,7 @@ static void srw_bend_search(association *assoc, request *req, *http_code = 200; yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest"); srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics); - if (srw_req->sort_type != Z_SRW_sort_type_none) - yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, - &srw_res->num_diagnostics, 80, 0); - else if (srw_res->num_diagnostics == 0 && assoc->init) + if (srw_res->num_diagnostics == 0 && assoc->init) { bend_search_rr rr; rr.setname = "default"; @@ -723,6 +721,7 @@ static void srw_bend_search(association *assoc, request *req, rr.num_bases = 1; rr.basenames = &srw_req->database; rr.referenceId = 0; + rr.srw_sortKeys = 0; rr.query = (Z_Query *) odr_malloc (assoc->decode, sizeof(*rr.query)); rr.query->u.type_1 = 0; @@ -772,7 +771,7 @@ static void srw_bend_search(association *assoc, request *req, int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off); yaz_log(log_requestdetail, "Parse error %d %s near offset %d", code, pqf_msg, off); - srw_error = 10; + srw_error = YAZ_SRW_QUERY_SYNTAX_ERROR; } rr.query->which = Z_Query_type_1; @@ -783,7 +782,8 @@ static void srw_bend_search(association *assoc, request *req, else { yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, - &srw_res->num_diagnostics, 11, 0); + &srw_res->num_diagnostics, + YAZ_SRW_UNSUPP_QUERY_TYPE, 0); } if (rr.query->u.type_1) { @@ -791,6 +791,9 @@ static void srw_bend_search(association *assoc, request *req, rr.decode = assoc->decode; rr.print = assoc->print; rr.request = req; + if ( srw_req->sort.sortKeys ) + rr.srw_sortKeys = odr_strdup(assoc->encode, + srw_req->sort.sortKeys ); rr.association = assoc; rr.fd = 0; rr.hits = 0; @@ -802,7 +805,7 @@ static void srw_bend_search(association *assoc, request *req, (assoc->init->bend_search)(assoc->backend, &rr); if (rr.errcode) { - if (rr.errcode == 109) /* database unavailable */ + if (rr.errcode == YAZ_BIB1_DATABASE_UNAVAILABLE) { *http_code = 404; } @@ -832,7 +835,7 @@ static void srw_bend_search(association *assoc, request *req, { yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, &srw_res->num_diagnostics, - 61, 0); + YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0); } else { @@ -927,15 +930,16 @@ static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr) if (!strcmp((const char *) ptr->name, "explain")) { int len; - ptr = xmlCopyNode(ptr, 1); + xmlDocPtr doc = xmlNewDoc("1.0"); + xmlChar *buf_out; + char *content; - xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0"); + ptr = xmlCopyNode(ptr, 1); xmlDocSetRootElement(doc, ptr); - xmlChar *buf_out; xmlDocDumpMemory(doc, &buf_out, &len); - char *content = (char*) odr_malloc(rr->stream, 1+len); + content = (char*) odr_malloc(rr->stream, 1+len); memcpy(content, buf_out, len); content[len] = '\0'; @@ -1063,10 +1067,11 @@ static void srw_bend_scan(association *assoc, request *req, { if (assoc->cql_transform) { + int srw_error; bsrr->scanClause = 0; bsrr->attributeset = VAL_NONE; bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term)); - int srw_error = cql2pqf_scan(assoc->encode, + srw_error = cql2pqf_scan(assoc->encode, srw_req->scanClause.cql, assoc->cql_transform, bsrr->term); @@ -1092,12 +1097,13 @@ static void srw_bend_scan(association *assoc, request *req, else { yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, - &srw_res->num_diagnostics, 4, "scan"); + &srw_res->num_diagnostics, + YAZ_SRW_UNSUPP_OPERATION, "scan"); } if (bsrr->errcode) { int srw_error; - if (bsrr->errcode == 109) /* database unavailable */ + if (bsrr->errcode == YAZ_BIB1_DATABASE_UNAVAILABLE) { *http_code = 404; return; @@ -1637,8 +1643,8 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) /* no backend. return error */ binitres = odr_malloc(assoc->encode, sizeof(*binitres)); binitres->errstring = 0; - binitres->errcode = 1; - iochan_settimeout(assoc->client_chan, 10); + binitres->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR; + iochan_settimeout(assoc->client_chan, 10); } if ((assoc->init->bend_sort)) yaz_log (YLOG_DEBUG, "Sort handler installed"); @@ -1758,7 +1764,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.50 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.56 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -1901,7 +1907,8 @@ static Z_Records *pack_records(association *a, char *setname, int start, *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) + if (freq.errcode == YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE && + freq.errstring == 0) { sprintf (s, "%d", recno); freq.errstring = s; @@ -1964,10 +1971,10 @@ static Z_Records *pack_records(association *a, char *setname, int start, if (!(thisrec = (Z_NamePlusRecord *) odr_malloc(a->encode, sizeof(*thisrec)))) return 0; - if (!(thisrec->databaseName = (char *)odr_malloc(a->encode, - strlen(freq.basename) + 1))) - return 0; - strcpy(thisrec->databaseName, freq.basename); + if (freq.basename) + thisrec->databaseName = odr_strdup(a->encode, freq.basename); + else + thisrec->databaseName = 0; thisrec->which = Z_NamePlusRecord_databaseRecord; if (freq.output_format_raw) @@ -2000,6 +2007,7 @@ static Z_APDU *process_searchRequest(association *assoc, request *reqb, bsrr->association = assoc; bsrr->referenceId = req->referenceId; save_referenceId (reqb, bsrr->referenceId); + bsrr->srw_sortKeys = 0; yaz_log (log_requestdetail, "ResultSet '%s'", req->resultSetName); if (req->databaseNames) @@ -2333,9 +2341,9 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) for (i = 0; i < req->num_databaseNames; i++) yaz_log (log_requestdetail, "Database '%s'", req->databaseNames[i]); } - yaz_log(log_requestdetail, "pos %d step %d entries %d", - *req->preferredPositionInResponse, *res->stepSize, - *req->numberOfTermsRequested); + bsrr->scanClause = 0; + bsrr->errcode = 0; + bsrr->errstring = 0; bsrr->num_bases = req->num_databaseNames; bsrr->basenames = req->databaseNames; bsrr->num_entries = *req->numberOfTermsRequested; @@ -2467,7 +2475,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) wrbuf_printf(wr, "Partial"); wrbuf_printf(wr, " %d+%d %d ", - *req->preferredPositionInResponse, + (req->preferredPositionInResponse ? + *req->preferredPositionInResponse : 1), *req->numberOfTermsRequested, (res->stepSize ? *res->stepSize : 0)); wrbuf_scan_term(wr, req->termListAndStartPoint,