From c23b3002b19ba3fcc016eb3fab454f22e0ecacee Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 23 Sep 2013 10:06:35 +0200 Subject: [PATCH] zoom: authenticationMode YAZ-686 --- doc/zoom.xml | 22 +++++++++++++++++++--- src/zoom-c.c | 8 +++++++- src/zoom-p.h | 1 + src/zoom-sru.c | 25 +++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/doc/zoom.xml b/doc/zoom.xml index 930d979..1261c4e 100644 --- a/doc/zoom.xml +++ b/doc/zoom.xml @@ -190,6 +190,9 @@ ZOOM_options_set_int(opt, name, value) passwordAuthentication password. none + authenticationModeHow authentication is encoded. + basic + hostTarget host. This setting is "read-only". It's automatically set internally when connecting to a target. none @@ -390,9 +393,9 @@ ZOOM_options_set_int(opt, name, value) SRU/Solr Protocol behavior - The HTTP based protocols (SRU, SRW, Solr) doesn't feature an Inititialize Request, so - the connection phase merely establishes a TCP/IP connection - with the SOAP service. + The HTTP based protocols (SRU, SRW, Solr) doesn't feature an + Inititialize Request, so the connection phase merely establishes a + TCP/IP connection with the HTTP server. Most of the ZOOM connection options do not affect SRU/Solr and they are ignored. However, future versions @@ -403,6 +406,19 @@ ZOOM_options_set_int(opt, name, value) The charset is used in the Content-Type header of HTTP requests. + + Setting authentcationMode specifies how + authentication parameters are encoded for HTTP. The default is + "basic" where user and + password are encoded by using HTTP basic + authentication. + + + If authentcationMode is "url", then + user and password are encoded in the URL by parameters + x-username and x-password as + given by the SRU standard. + Queries diff --git a/src/zoom-c.c b/src/zoom-c.c index 03e6fe3..5f52d7c 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -287,6 +287,7 @@ ZOOM_API(ZOOM_connection) c->user = 0; c->group = 0; c->password = 0; + c->url_authentication = 0; c->maximum_record_size = 0; c->preferred_message_size = 0; @@ -525,10 +526,15 @@ ZOOM_API(void) val = ZOOM_options_get(c->options, "password"); if (!val) val = ZOOM_options_get(c->options, "pass"); - if (val && *val) c->password = xstrdup(val); + val = ZOOM_options_get(c->options, "authenticationMode"); + if (val && !strcmp(val, "url")) + c->url_authentication = 1; + else + c->url_authentication = 0; + c->maximum_record_size = ZOOM_options_get_int(c->options, "maximumRecordSize", 64*1024*1024); c->preferred_message_size = diff --git a/src/zoom-p.h b/src/zoom-p.h index 0f53b04..3be4591 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -91,6 +91,7 @@ struct ZOOM_connection_p { char *user; char *group; char *password; + int url_authentication; int async; int support_named_resultsets; diff --git a/src/zoom-sru.c b/src/zoom-sru.c index b829738..0776057 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -62,8 +62,29 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr) static Z_SRW_PDU *ZOOM_srw_get_pdu(ZOOM_connection c, int type) { Z_SRW_PDU *sr = yaz_srw_get_pdu(c->odr_out, type, c->sru_version); - sr->username = c->user; - sr->password = c->password; + if (c->url_authentication && c->user) + { + Z_SRW_extra_arg **ea = &sr->extra_args; + while (*ea) + ea = &(*ea)->next; + *ea = (Z_SRW_extra_arg *) odr_malloc(c->odr_out, sizeof(**ea)); + (*ea)->name = "x-username"; + (*ea)->value = c->user; + ea = &(*ea)->next; + if (c->password) + { + *ea = (Z_SRW_extra_arg *) odr_malloc(c->odr_out, sizeof(**ea)); + (*ea)->name = "x-password"; + (*ea)->value = c->password; + ea = &(*ea)->next; + } + *ea = 0; + } + else + { + sr->username = c->user; + sr->password = c->password; + } return sr; } #endif -- 1.7.10.4