From: Adam Dickmeiss Date: Wed, 19 Feb 2003 15:22:11 +0000 (+0000) Subject: Utility to map between Bib-1 and SRW diagnostics. X-Git-Tag: YAZ.2.0~29 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=e12377e7ea8e58cf447492b5cb9887b839a78700 Utility to map between Bib-1 and SRW diagnostics. Better handling of unsupported SRW constructs in server. --- diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 4fad9fd..18cc743 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: srw.h,v 1.3 2003-02-17 14:35:42 adam Exp $ + * $Id: srw.h,v 1.4 2003-02-19 15:22:11 adam Exp $ */ #ifndef YAZ_SRW_H @@ -64,7 +64,11 @@ YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr, void *client_data, const char *ns); YAZ_EXPORT Z_SRW_searchRetrieve *yaz_srw_get(ODR o, int which); -YAZ_EXPORT const char *yaz_srw_error_str (int code); +YAZ_EXPORT const char *yaz_diag_srw_str (int code); + +YAZ_EXPORT int yaz_diag_bib1_to_srw (int bib1_code); + +YAZ_EXPORT int yaz_diag_srw_to_bib1(int srw_code); #endif diff --git a/server/seshigh.c b/server/seshigh.c index ba96698..968b284 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.142 2003-02-18 14:47:23 adam Exp $ + * $Id: seshigh.c,v 1.143 2003-02-19 15:22:11 adam Exp $ */ /* @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -450,9 +451,9 @@ static int srw_bend_init(association *assoc) return 1; } -static void srw_bend_fetch(association *assoc, int pos, - Z_SRW_searchRetrieveRequest *srw_req, - Z_SRW_record *record) +static int srw_bend_fetch(association *assoc, int pos, + Z_SRW_searchRetrieveRequest *srw_req, + Z_SRW_record *record) { bend_fetch_rr rr; ODR o = assoc->encode; @@ -507,6 +508,7 @@ static void srw_bend_fetch(association *assoc, int pos, if (srw_req->recordSchema) record->recordSchema = odr_strdup(o, srw_req->recordSchema); } + return rr.errcode; } static void srw_bend_search(association *assoc, request *req, @@ -514,6 +516,7 @@ static void srw_bend_search(association *assoc, request *req, Z_SRW_searchRetrieveResponse *srw_res) { char *base = "Default"; + int srw_error = 0; bend_search_rr rr; Z_External *ext; @@ -528,20 +531,64 @@ static void srw_bend_search(association *assoc, request *req, rr.basenames = &srw_req->database; rr.referenceId = 0; - ext = (Z_External *) odr_malloc(assoc->decode, sizeof(*ext)); - ext->direct_reference = odr_getoidbystr(assoc->decode, - "1.2.840.10003.16.2"); - ext->indirect_reference = 0; - ext->descriptor = 0; - ext->which = Z_External_CQL; + rr.query = (Z_Query *) odr_malloc (assoc->decode, sizeof(*rr.query)); + if (srw_req->query) + { + ext = (Z_External *) odr_malloc(assoc->decode, sizeof(*ext)); + ext->direct_reference = odr_getoidbystr(assoc->decode, + "1.2.840.10003.16.2"); + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_CQL; ext->u.cql = srw_req->query; + + rr.query->which = Z_Query_type_104; + rr.query->u.type_104 = ext; + } + else if (srw_req->pQuery) + { + Z_RPNQuery *RPNquery; + YAZ_PQF_Parser pqf_parser; + + pqf_parser = yaz_pqf_create (); + + yaz_log(LOG_LOG, "PQF: %s", srw_req->pQuery); + + RPNquery = yaz_pqf_parse (pqf_parser, assoc->decode, srw_req->pQuery); + if (!RPNquery) + { + 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, ""); + yaz_log(LOG_LOG, "Bad PQF: %s (code %d)\n", pqf_msg, code); + + srw_error = 10; + } + + rr.query->which = Z_Query_type_1; + rr.query->u.type_1 = RPNquery; + + yaz_pqf_destroy (pqf_parser); + } else - ext->u.cql = "noterm"; - - rr.query = (Z_Query *) odr_malloc (assoc->decode, sizeof(*rr.query)); - rr.query->which = Z_Query_type_104; - rr.query->u.type_104 = ext; + srw_error = 11; + + if (srw_req->sortKeys || srw_req->xSortKeys) + srw_error = 80; + + if (srw_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; + return; + } + rr.stream = assoc->encode; rr.decode = assoc->decode; @@ -562,7 +609,8 @@ static void srw_bend_search(association *assoc, request *req, srw_res->diagnostics = (Z_SRW_diagnostic *) odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics)); srw_res->diagnostics[0].code = - odr_intdup(assoc->encode, rr.errcode); + odr_intdup(assoc->encode, + yaz_diag_bib1_to_srw (rr.errcode)); srw_res->diagnostics[0].details = rr.errstring; } else @@ -585,9 +633,22 @@ static void srw_bend_search(association *assoc, request *req, number * sizeof(*srw_res->records)); for (i = 0; irecords[j].recordData_buf = 0; - srw_bend_fetch(assoc, i+start, srw_req, - srw_res->records + j); + errcode = srw_bend_fetch(assoc, i+start, srw_req, + srw_res->records + j); + if (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 (errcode)); + srw_res->diagnostics[0].details = rr.errstring; + break; + } if (srw_res->records[j].recordData_buf) j++; } diff --git a/zutil/srw.c b/zutil/srw.c index 71391eb..bde6bc5 100644 --- a/zutil/srw.c +++ b/zutil/srw.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: srw.c,v 1.5 2003-02-18 14:28:53 adam Exp $ + * $Id: srw.c,v 1.6 2003-02-19 15:22:11 adam Exp $ */ #include @@ -244,6 +244,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_searchRetrieve **handler_data, (*p)->which = Z_SRW_searchRetrieve_request; req = (*p)->u.request = odr_malloc(o, sizeof(*req)); req->query = 0; + req->pQuery = 0; req->xQuery = 0; req->sortKeys = 0; req->xSortKeys = 0; @@ -504,7 +505,7 @@ static struct { {0, 0} }; -const char *yaz_srw_error_str (int code) +const char *yaz_diag_srw_str (int code) { int i; for (i = 0; yaz_srw_codes[i].code; i++) @@ -513,3 +514,196 @@ const char *yaz_srw_error_str (int code) return 0; } + +/* bib1:srw */ +static int srw_bib1_map[] = { + 1, 1, + 2, 2, + 3, 11, + 4, 35, + 5, 12, + 6, 38, + 7, 30, + 8, 32, + 9, 29, + 10, 10, + 11, 12, + 11, 23, + 12, 60, + 13, 61, + 13, 62, + 14, 63, + 14, 64, + 14, 65, + 15, 68, + 15, 69, + 16, 70, + 17, 70, + 18, 50, + 19, 55, + 20, 56, + 21, 52, + 22, 50, + 23, 1, /* bad map */ + 24, 63, /* bad map */ + 25, 63, /* bad map */ + 26, 63, /* bad map */ + 27, 51, + 28, 52, + 29, 52, + 30, 51, + 31, 57, + 32, 58, + 33, 59, + 100, 1, /* bad map */ + 101, 3, + 102, 3, + 103, 3, + 104, 3, + 105, 3, + 106, 66, + 107, 11, + 108, 10, + 108, 13, + 108, 14, + 108, 25, + 108, 26, + 108, 27, + 108, 45, + + 109, 1, + 110, 37, + 111, 1, + 112, 58, + 113, 10, + 114, 16, + 115, 16, + 116, 16, + 117, 19, + 118, 22, + 119, 32, + 119, 31, + 120, 28, + 121, 15, + 122, 32, + 123, 22, + 123, 17, + 123, 18, + 124, 24, + 125, 36, + 126, 36, + 127, 36, + 128, 51, + 129, 39, + 130, 43, + 131, 40, + 132, 42, + 201, 44, + 201, 33, + 201, 34, + 202, 41, + 203, 43, + 205, 1, /* bad map */ + 206, 1, /* bad map */ + 207, 89, + 208, 1, /* bad map */ + 209, 80, + 210, 80, + 210, 81, + 211, 84, + 212, 85, + 213, 92, + 214, 90, + 215, 91, + 216, 92, + 217, 63, + 218, 1, /* bad map */ + 219, 1, /* bad map */ + 220, 1, /* bad map */ + 221, 1, /* bad map */ + 222, 1, /* bad map */ + 223, 1, /* bad map */ + 224, 1, /* bad map */ + 225, 1, /* bad map */ + 226, 1, /* bad map */ + 227, 66, + 228, 1, /* bad map */ + 229, 36, + 230, 83, + 231, 89, + 232, 1, + 233, 1, /* bad map */ + 234, 1, /* bad map */ + 235, 2, + 236, 3, + 237, 82, + 238, 67, + 239, 66, + 240, 1, /* bad map */ + 241, 1, /* bad map */ + 242, 70, + 243, 1, /* bad map */ + 244, 66, + 245, 10, + 246, 10, + 247, 10, + 1001, 1, /* bad map */ + 1002, 1, /* bad map */ + 1003, 1, /* bad map */ + 1004, 1, /* bad map */ + 1005, 1, /* bad map */ + 1006, 1, /* bad map */ + 1007, 100, + 1008, 1, + 1009, 1, + 1010, 3, + 1011, 3, + 1012, 3, + 1013, 3, + 1014, 3, + 1015, 3, + 1015, 3, + 1016, 3, + 1017, 3, + 1018, 2, + 1019, 2, + 1020, 2, + 1021, 3, + 1022, 3, + 1023, 3, + 1024, 16, + 1025, 3, + 1026, 64, + 1027, 1, + 1028, 65, + 1029, 1, + 1040, 1, + /* 1041-1065 */ + 1066, 66, + 1066, 67, + 0 +}; + +int yaz_diag_bib1_to_srw (int code) +{ + const int *p = srw_bib1_map; + while (*p) + { + if (code == p[0]) + return p[1]; + p += 2; + } + return 1; +} + +int yaz_diag_srw_to_bib1(int code) +{ + const int *p = srw_bib1_map; + while (*p) + { + if (code == p[1]) + return p[0]; + p += 2; + } + return 1; +} diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 3716c77..72e7354 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.24 2003-02-18 11:59:15 adam Exp $ + * $Id: zoom-c.c,v 1.25 2003-02-19 15:22:11 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -1063,9 +1063,10 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) if (resultset->z_query->which == Z_Query_type_104 && resultset->z_query->u.type_104->which == Z_External_CQL) sr->u.request->query = resultset->z_query->u.type_104->u.cql; - else if (resultset->z_query->which == Z_Query_type_1) - { - set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_QUERY, "Type-1"); + else if (resultset->z_query->which == Z_Query_type_1 && + resultset->z_query->u.type_1) + { + set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_QUERY, 0); return zoom_complete; } else @@ -2728,7 +2729,7 @@ ZOOM_connection_error_x (ZOOM_connection c, const char **cp, else if (!strcmp(c->diagset, "Bib-1")) *cp = ZOOM_diag_str(error); else if (!strcmp(c->diagset, "SRW")) - *cp = yaz_srw_error_str(c->error); + *cp = yaz_diag_srw_str(c->error); else *cp = "Unknown error and diagnostic set"; }