From 184f0911dd1ef651b6ba659df0eb33ff2455014c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 16 Aug 2006 22:47:09 +0000 Subject: [PATCH] Implemented bug #635: YAZ/ZOOM layer should include non SRU options in the HTTP/GET URL. ZOOM-C reads option extraArgs. If set the value of extraArgs is appended to SRU URI (POST/GET). Value is _raw_ URI part, such as x-id-a=v1&x-id-b=v2 . --- NEWS | 3 +++ include/yaz/srw.h | 4 +++- src/srw.c | 22 ++++++++++++++-------- src/srwutil.c | 39 +++++++++++++++++++++++++-------------- src/zoom-c.c | 49 ++++++++++++++++++++++++++++--------------------- 5 files changed, 73 insertions(+), 44 deletions(-) diff --git a/NEWS b/NEWS index bc841ef..c18b0ac 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +ZOOM-C reads option extraArgs. If set the value of extraArgs is appended to +SRU URI (POST/GET). Value is _raw_ URI part, such as x-id-a=v1&x-id-b=v2 . + --- 2.1.26 2006/08/15 Fixed problem with SRU mode type (soap, get, post) for yaz-client diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 17f4890..a82b775 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: srw.h,v 1.27 2006-06-02 13:08:27 adam Exp $ + * $Id: srw.h,v 1.28 2006-08-16 22:47:09 adam Exp $ */ /** * \file srw.h @@ -180,6 +180,7 @@ typedef struct { char *srw_version; char *username; /* From HTTP header or request */ char *password; /* From HTTP header or request */ + char *extra_args; /* For SRU GET/POST only */ } Z_SRW_PDU; YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr, @@ -188,6 +189,7 @@ YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr, 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(ODR o, int which); YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o); diff --git a/src/srw.c b/src/srw.c index aaadd43..138f8a6 100644 --- a/src/srw.c +++ b/src/srw.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: srw.c,v 1.46 2006-07-06 10:17:54 adam Exp $ + * $Id: srw.c,v 1.47 2006-08-16 22:47:10 adam Exp $ */ /** * \file srw.c @@ -522,6 +522,16 @@ static int yaz_srw_terms(ODR o, xmlNodePtr pptr, Z_SRW_scanTerm **terms, return 0; } +Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o) +{ + Z_SRW_PDU *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(*p)); + p->srw_version = odr_strdup(o, "1.1"); + p->username = 0; + p->password = 0; + p->extra_args = 0; + return p; +} + int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, void *client_data, const char *ns) { @@ -539,10 +549,7 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (method->type != XML_ELEMENT_NODE) return -1; - *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(**p)); - (*p)->srw_version = odr_strdup(o, "1.1"); - (*p)->username = 0; - (*p)->password = 0; + *p = yaz_srw_get_core_v_1_1(o); if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveRequest")) { @@ -968,8 +975,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, if (method->type != XML_ELEMENT_NODE) return -1; - *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(**p)); - (*p)->srw_version = odr_strdup(o, "1.1"); + *p = yaz_srw_get_core_v_1_1(o); if (!xmlStrcmp(method->name, BAD_CAST "updateRequest")) { diff --git a/src/srwutil.c b/src/srwutil.c index 9e698c6..624efaa 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: srwutil.c,v 1.45 2006-07-06 10:17:54 adam Exp $ + * $Id: srwutil.c,v 1.46 2006-08-16 22:47:10 adam Exp $ */ /** * \file srwutil.c @@ -41,9 +41,10 @@ void encode_uri_char(char *dst, char ch) } } -void yaz_array_to_uri(char **path, ODR o, char **name, char **value) +static void yaz_array_to_uri_ex(char **path, ODR o, char **name, char **value, + const char *extra_args) { - size_t i, szp = 0, sz = 0; + size_t i, szp = 0, sz = extra_args ? 1+strlen(extra_args) : 1; for(i = 0; name[i]; i++) sz += strlen(name[i]) + 3 + strlen(value[i]) * 3; *path = odr_malloc(o, sz); @@ -67,9 +68,21 @@ void yaz_array_to_uri(char **path, ODR o, char **name, char **value) szp += vlen; } } + if (extra_args) + { + if (i) + (*path)[szp++] = '&'; + memcpy(*path + szp, extra_args, strlen(extra_args)); + szp += strlen(extra_args); + } (*path)[szp] = '\0'; } +void yaz_array_to_uri(char **path, ODR o, char **name, char **value) +{ + return yaz_array_to_uri_ex(path, o, name, value, 0); +} + int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) { int no = 2; @@ -226,8 +239,8 @@ static int yaz_base64decode(const char *in, char *out) * Look for authentication tokens in HTTP Basic parameters or in x-username/x-password * parameters. Added by SH. */ -static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, char *username, - char *password, ODR decode) +static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, + char *username, char *password, ODR decode) { const char *basic = z_HTTP_header_lookup(hreq->headers, "Authorization"); @@ -742,11 +755,7 @@ Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o) Z_SRW_PDU *yaz_srw_get(ODR o, int which) { - Z_SRW_PDU *sr = (Z_SRW_PDU *) odr_malloc(o, sizeof(*o)); - - sr->username = 0; - sr->password = 0; - sr->srw_version = odr_strdup(o, "1.1"); + Z_SRW_PDU *sr = yaz_srw_get_core_v_1_1(o); sr->which = which; switch(which) { @@ -1168,11 +1177,13 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, if (yaz_get_sru_parms(srw_pdu, encode, name, value)) return -1; - yaz_array_to_uri(&uri_args, encode, name, value); + yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args); hreq->method = "GET"; - path = odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 3); + path = odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4 + +(srw_pdu->extra_args ? strlen(srw_pdu->extra_args) : 0) + ); sprintf(path, "%s?%s", hreq->path, uri_args); hreq->path = path; @@ -1190,7 +1201,7 @@ int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, if (yaz_get_sru_parms(srw_pdu, encode, name, value)) return -1; - yaz_array_to_uri(&uri_args, encode, name, value); + yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args); hreq->method = "POST"; diff --git a/src/zoom-c.c b/src/zoom-c.c index fe4665a..c7efa2e 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.84 2006-08-16 14:18:59 adam Exp $ + * $Id: zoom-c.c,v 1.85 2006-08-16 22:47:11 adam Exp $ */ /** * \file zoom-c.c @@ -1187,23 +1187,28 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_2); ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_3); - + /* Index Data's Z39.50 Implementor Id is 81 */ - ireq->implementationId = odr_prepend(c->odr_out, - ZOOM_options_get(c->options, "implementationId"), - odr_prepend(c->odr_out, "81", ireq->implementationId)); - - ireq->implementationName = odr_prepend(c->odr_out, - ZOOM_options_get(c->options, "implementationName"), - odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - - version = odr_strdup(c->odr_out, "$Revision: 1.84 $"); + ireq->implementationId = + odr_prepend(c->odr_out, + ZOOM_options_get(c->options, "implementationId"), + odr_prepend(c->odr_out, "81", ireq->implementationId)); + + ireq->implementationName = + odr_prepend(c->odr_out, + ZOOM_options_get(c->options, "implementationName"), + odr_prepend(c->odr_out, "ZOOM-C", + ireq->implementationName)); + + version = odr_strdup(c->odr_out, "$Revision: 1.85 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; - ireq->implementationVersion = odr_prepend(c->odr_out, - ZOOM_options_get(c->options, "implementationVersion"), - odr_prepend(c->odr_out, &version[11], ireq->implementationVersion)); - + ireq->implementationVersion = + odr_prepend(c->odr_out, + ZOOM_options_get(c->options, "implementationVersion"), + odr_prepend(c->odr_out, &version[11], + ireq->implementationVersion)); + *ireq->maximumRecordSize = ZOOM_options_get_int(c->options, "maximumRecordSize", 1024*1024); *ireq->preferredMessageSize = @@ -1313,7 +1318,7 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) int *start, *count; ZOOM_resultset resultset = 0; Z_SRW_PDU *sr = 0; - const char *recordPacking = 0; + const char *option_val = 0; if (c->error) /* don't continue on error */ return zoom_complete; @@ -1381,12 +1386,14 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) sr->u.request->maximumRecords = odr_intdup( c->odr_out, resultset->step>0 ? resultset->step : *count); sr->u.request->recordSchema = resultset->schema; - - recordPacking = ZOOM_resultset_option_get(resultset, "recordPacking"); - - if (recordPacking) - sr->u.request->recordPacking = odr_strdup(c->odr_out, recordPacking); + option_val = ZOOM_resultset_option_get(resultset, "recordPacking"); + if (option_val) + sr->u.request->recordPacking = odr_strdup(c->odr_out, option_val); + + option_val = ZOOM_resultset_option_get(resultset, "extraArgs"); + if (option_val) + sr->extra_args = odr_strdup(c->odr_out, option_val); return send_srw(c, sr); } #else -- 1.7.10.4