From: Adam Dickmeiss Date: Thu, 23 Aug 2007 14:23:23 +0000 (+0000) Subject: Added new ZOOM connection option "sru_version" which specifies SRU X-Git-Tag: YAZ.3.0.12~21 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=3f36e04a60f21ed11fbb7bdb32923cffcb519f2f Added new ZOOM connection option "sru_version" which specifies SRU version - say 1.1 or 1.2. Fixed YAZ server's SRU GET/POST decoding WRT version checking. Anything but 1.1 was rejected and this turned out to be a mistake. For the GFS, anything but version 1.1 is negotiated to 1.2, except 1.1 which is negotiated to 1.1. --- diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 4f34a49..a81581b 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: srw.h,v 1.34 2007-05-23 11:54:47 adam Exp $ */ +/* $Id: srw.h,v 1.35 2007-08-23 14:23:23 adam Exp $ */ /** * \file srw.h @@ -216,6 +216,7 @@ YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr, Z_SRW_PDU **handler_data, void *client_data, const char *ns); YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o); +YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version); YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which); YAZ_EXPORT Z_SRW_recordVersion *yaz_srw_get_record_versions(ODR o, int num); YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o); @@ -266,6 +267,8 @@ YAZ_EXPORT int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, YAZ_EXPORT int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, ODR odr, const char *charset); +YAZ_EXPORT char *yaz_negotiate_sru_version(char *input_ver); + #define YAZ_XMLNS_SRU_v1_0 "http://www.loc.gov/zing/srw/v1.0/" #define YAZ_XMLNS_SRU_v1_1 "http://www.loc.gov/zing/srw/" #define YAZ_XMLNS_DIAG_v1_1 "http://www.loc.gov/zing/srw/diagnostic/" diff --git a/src/seshigh.c b/src/seshigh.c index c68af21..7b7db0c 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.126 2007-08-22 08:11:28 adam Exp $ + * $Id: seshigh.c,v 1.127 2007-08-23 14:23:23 adam Exp $ */ /** * \file seshigh.c @@ -1801,8 +1801,8 @@ static void process_http_request(association *assoc, request *req) 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) { @@ -1819,7 +1819,8 @@ static void process_http_request(association *assoc, request *req) } 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) { @@ -1833,7 +1834,8 @@ static void process_http_request(association *assoc, request *req) } 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) { @@ -1847,7 +1849,8 @@ static void process_http_request(association *assoc, request *req) } 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) { @@ -2377,7 +2380,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.126 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.127 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, diff --git a/src/srw.c b/src/srw.c index ae768d4..54aa7ba 100644 --- a/src/srw.c +++ b/src/srw.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: srw.c,v 1.56 2007-05-23 13:11:11 adam Exp $ + * $Id: srw.c,v 1.57 2007-08-23 14:23:23 adam Exp $ */ /** * \file srw.c @@ -196,6 +196,16 @@ static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, int **val) return 1; } +char *yaz_negotiate_sru_version(char *input_ver) +{ + if (!input_ver) + input_ver = "1.1"; + + if (!strcmp(input_ver, "1.1")) + return "1.1"; + return "1.2"; /* our latest supported version */ +} + static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec, Z_SRW_extra_record **extra, void *client_data, const char *ns) @@ -594,6 +604,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, { Z_SRW_PDU **p = handler_data; xmlNodePtr method = pptr->children; + char *neg_version; while (method && method->type == XML_TEXT_NODE) method = method->next; @@ -851,6 +862,9 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, *p = 0; return -1; } + neg_version = yaz_negotiate_sru_version((*p)->srw_version); + if (neg_version) + (*p)->srw_version = neg_version; } else if (o->direction == ODR_ENCODE) { diff --git a/src/srwutil.c b/src/srwutil.c index b115ffc..eac75ed 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: srwutil.c,v 1.59 2007-05-24 10:18:36 adam Exp $ + * $Id: srwutil.c,v 1.60 2007-08-23 14:23:23 adam Exp $ */ /** * \file srwutil.c @@ -594,9 +594,16 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, "version"); version = "1.1"; } - if (strcmp(version, "1.1")) + + version = yaz_negotiate_sru_version(version); + + if (!version) + { /* negotiation failed. */ yaz_add_srw_diagnostic(decode, diag, num_diag, - YAZ_SRW_UNSUPP_VERSION, "1.1"); + YAZ_SRW_UNSUPP_VERSION, "1.2"); + version = "1.2"; + } + if (!operation) { if (uri_name) @@ -814,19 +821,30 @@ Z_SRW_record *yaz_srw_get_record(ODR o) return yaz_srw_get_records(o, 1); } -Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o) +static Z_SRW_PDU *yaz_srw_get_core_ver(ODR o, const char *version) { Z_SRW_PDU *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(*p)); - p->srw_version = odr_strdup(o, "1.1"); + p->srw_version = odr_strdup(o, version); p->username = 0; p->password = 0; p->extra_args = 0; return p; } +Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o) +{ + return yaz_srw_et_core_ver(o, "1.1"); +} + Z_SRW_PDU *yaz_srw_get(ODR o, int which) { - Z_SRW_PDU *sr = yaz_srw_get_core_v_1_1(o); + return yaz_srw_get_pdu(o, which, "1.2"); +} + +Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version) +{ + Z_SRW_PDU *sr = yaz_srw_get_core_ver(o, version); + sr->which = which; switch(which) { diff --git a/src/zoom-c.c b/src/zoom-c.c index 742847b..796d904 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.142 2007-08-23 12:24:38 adam Exp $ + * $Id: zoom-c.c,v 1.143 2007-08-23 14:23:23 adam Exp $ */ /** * \file zoom-c.c @@ -395,6 +395,8 @@ ZOOM_API(ZOOM_connection) c->m_queue_front = 0; c->m_queue_back = 0; + + c->sru_version = xstrdup("1.1"); return c; } @@ -541,6 +543,10 @@ ZOOM_API(void) val = ZOOM_options_get(c->options, "sru"); c->sru_mode = get_sru_mode_from_string(val); + xfree(c->sru_version); + val = ZOOM_options_get(c->options, "sru_version"); + c->sru_version = xstrdup(val ? val : "1.1"); + ZOOM_options_set(c->options, "host", c->host_port); xfree(c->cookie_out); @@ -781,6 +787,7 @@ ZOOM_API(void) xfree(c->user); xfree(c->group); xfree(c->password); + xfree(c->sru_version); xfree(c); } @@ -1346,7 +1353,7 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.142 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.143 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1493,7 +1500,8 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) } assert(resultset->query); - sr = yaz_srw_get(c->odr_out, Z_SRW_searchRetrieve_request); + sr = yaz_srw_get_pdu(c->odr_out, Z_SRW_searchRetrieve_request, + c->sru_version); if (resultset->query->z_query->which == Z_Query_type_104 && resultset->query->z_query->u.type_104->which == Z_External_CQL) @@ -2832,7 +2840,7 @@ static zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c) assert (c->tasks->which == ZOOM_TASK_SCAN); scan = c->tasks->u.scan.scan; - sr = yaz_srw_get(c->odr_out, Z_SRW_scan_request); + sr = yaz_srw_get_pdu(c->odr_out, Z_SRW_scan_request, c->sru_version); /* SRU scan can only carry CQL and PQF */ if (scan->query->z_query->which == Z_Query_type_104) diff --git a/src/zoom-p.h b/src/zoom-p.h index 174d952..5fd0b86 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-p.h,v 1.21 2007-08-16 10:09:36 adam Exp $ + * $Id: zoom-p.h,v 1.22 2007-08-23 14:23:23 adam Exp $ */ /** * \file zoom-p.h @@ -63,6 +63,7 @@ struct ZOOM_connection_p { char *cookie_out; char *cookie_in; char *client_IP; + char *sru_version; char *user; char *group;