From 66651add5da56151f986e44957cfafc8ee81578c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 28 Jan 2008 09:51:02 +0000 Subject: [PATCH] Changed definition of extra_args in Z_SRW_PDU. Changed definition of extra_args in Z_SRW_PDU. The extra_args was a char* before. Is not a Z_SRW_extra_arg list. The extra args is used for both encoding and decoding of SRU GET/POST (was only used in SRU encoding earlier). --- include/yaz/srw.h | 15 ++++++++-- src/srwutil.c | 85 +++++++++++++++++++++++++++++++++++++---------------- src/zoom-c.c | 11 +++---- 3 files changed, 77 insertions(+), 34 deletions(-) diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 7662818..633af53 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.36 2007-09-09 05:54:45 adam Exp $ */ +/* $Id: srw.h,v 1.37 2008-01-28 09:51:02 adam Exp $ */ /** * \file srw.h @@ -169,6 +169,13 @@ typedef struct { char *stylesheet; } Z_SRW_updateRequest; +typedef struct Z_SRW_extra_arg Z_SRW_extra_arg; +struct Z_SRW_extra_arg { + char *name; + char *value; + Z_SRW_extra_arg *next; +}; + typedef struct { char *operationStatus; char *recordId; @@ -206,7 +213,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_extra_arg *extra_args; /* only used for SRU GET/POST */ } Z_SRW_PDU; YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr, @@ -269,6 +276,10 @@ YAZ_EXPORT int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, YAZ_EXPORT char *yaz_negotiate_sru_version(char *input_ver); +YAZ_EXPORT +void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args); + + #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/srwutil.c b/src/srwutil.c index ca6ecfb..a3459fe 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.64 2007-09-07 17:41:47 mike Exp $ + * $Id: srwutil.c,v 1.65 2008-01-28 09:51:02 adam Exp $ */ /** * \file srwutil.c @@ -42,10 +42,9 @@ void encode_uri_char(char *dst, char ch) } } -static void yaz_array_to_uri_ex(char **path, ODR o, char **name, char **value, - const char *extra_args) +static void yaz_array_to_uri(char **path, ODR o, char **name, char **value) { - size_t i, szp = 0, sz = extra_args ? 1+strlen(extra_args) : 1; + size_t i, szp = 0, sz = 1; for(i = 0; name[i]; i++) sz += strlen(name[i]) + 3 + strlen(value[i]) * 3; *path = (char *) odr_malloc(o, sz); @@ -69,22 +68,10 @@ static void yaz_array_to_uri_ex(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) -{ - yaz_array_to_uri_ex(path, o, name, value, 0); -} - -int yaz_uri_array(const char *path, ODR o, char ***name, char ***val) +int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val) { int no = 2; const char *cp; @@ -515,6 +502,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, char *maximumTerms = 0; char *responsePosition = 0; char *extraRequestData = 0; + Z_SRW_extra_arg *extra_args = 0; #endif char **uri_name; char **uri_val; @@ -536,7 +524,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, } if (!strcmp(hreq->method, "POST")) p1 = hreq->content_buf; - yaz_uri_array(p1, decode, &uri_name, &uri_val); + yaz_uri_to_array(p1, decode, &uri_name, &uri_val); #if YAZ_HAVE_XML2 if (uri_name) { @@ -581,6 +569,16 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, responsePosition = v; else if (!strcmp(n, "extraRequestData")) extraRequestData = v; + else if (n[0] == 'x' && n[1] == '-') + { + Z_SRW_extra_arg **l = &extra_args; + while (*l) + l = &(*l)->next; + *l = odr_malloc(decode, sizeof(**l)); + (*l)->name = odr_strdup(decode, n); + (*l)->value = odr_strdup(decode, v); + (*l)->next = 0; + } else yaz_add_srw_diagnostic(decode, diag, num_diag, YAZ_SRW_UNSUPP_PARAMETER, n); @@ -617,6 +615,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_searchRetrieve_request); sr->srw_version = version; + sr->extra_args = extra_args; *srw_pdu = sr; yaz_srw_decodeauth(sr, hreq, username, password, decode); if (query) @@ -676,6 +675,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request); sr->srw_version = version; + sr->extra_args = extra_args; yaz_srw_decodeauth(sr, hreq, username, password, decode); *srw_pdu = sr; sr->u.explain_request->recordPacking = recordPacking; @@ -705,6 +705,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_scan_request); sr->srw_version = version; + sr->extra_args = extra_args; *srw_pdu = sr; yaz_srw_decodeauth(sr, hreq, username, password, decode); @@ -1186,7 +1187,7 @@ static void add_val_str(ODR o, char **name, char **value, int *i, } static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, - char **name, char **value) + char **name, char **value, int max_names) { int i = 0; add_val_str(encode, name, value, &i, "version", srw_pdu->srw_version); @@ -1270,7 +1271,18 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode, default: return -1; } + if (srw_pdu->extra_args) + { + Z_SRW_extra_arg *ea = srw_pdu->extra_args; + for (; ea && i < max_names-1; ea = ea->next) + { + name[i] = ea->name; + value[i] = ea->value; + i++; + } + } name[i++] = 0; + return 0; } @@ -1283,15 +1295,14 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, z_HTTP_header_add_basic_auth(encode, &hreq->headers, srw_pdu->username, srw_pdu->password); - if (yaz_get_sru_parms(srw_pdu, encode, name, value)) + if (yaz_get_sru_parms(srw_pdu, encode, name, value, 30)) return -1; - yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args); + yaz_array_to_uri(&uri_args, encode, name, value); hreq->method = "GET"; path = (char *) - odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4 - +(srw_pdu->extra_args ? strlen(srw_pdu->extra_args) : 0)); + odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4); sprintf(path, "%s?%s", hreq->path, uri_args); hreq->path = path; @@ -1309,10 +1320,10 @@ int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, z_HTTP_header_add_basic_auth(encode, &hreq->headers, srw_pdu->username, srw_pdu->password); - if (yaz_get_sru_parms(srw_pdu, encode, name, value)) + if (yaz_get_sru_parms(srw_pdu, encode, name, value, 30)) return -1; - yaz_array_to_uri_ex(&uri_args, encode, name, value, srw_pdu->extra_args); + yaz_array_to_uri(&uri_args, encode, name, value); hreq->method = "POST"; @@ -1400,6 +1411,30 @@ int yaz_srw_str_to_pack(const char *str) return -1; } +void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args) +{ + if (extra_args) + { + char **name; + char **val; + Z_SRW_extra_arg **ea = &sr->extra_args; + yaz_uri_to_array(extra_args, odr, &name, &val); + + while (*name) + { + *ea = odr_malloc(odr, sizeof(**ea)); + (*ea)->name = *name; + (*ea)->value = *val; + ea = &(*ea)->next; + val++; + name++; + } + *ea = 0; + } +} + + + /* * Local variables: * c-basic-offset: 4 diff --git a/src/zoom-c.c b/src/zoom-c.c index a0a1341..34f4c60 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.153 2007-12-11 13:35:45 adam Exp $ + * $Id: zoom-c.c,v 1.154 2008-01-28 09:51:02 adam Exp $ */ /** * \file zoom-c.c @@ -1356,7 +1356,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.153 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.154 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1448,7 +1448,6 @@ static Z_SRW_PDU *ZOOM_srw_get_pdu(ZOOM_connection c, int type) { return sr; } - #if YAZ_HAVE_XML2 static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) { @@ -1534,8 +1533,7 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) 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); + yaz_encode_sru_extra(sr, c->odr_out, option_val); return send_srw(c, sr); } #else @@ -2902,8 +2900,7 @@ static zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c) c->odr_out, ZOOM_options_get_int(scan->options, "position", 1)); option_val = ZOOM_options_get(scan->options, "extraArgs"); - if (option_val) - sr->extra_args = odr_strdup(c->odr_out, option_val); + yaz_encode_sru_extra(sr, c->odr_out, option_val); return send_srw(c, sr); } #else -- 1.7.10.4