* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: seshigh.c,v 1.75 2006-04-21 10:28:07 adam Exp $
+ * $Id: seshigh.c,v 1.76 2006-05-05 20:02:22 quinn Exp $
*/
/**
* \file seshigh.c
yaz_log(log_requestdetail, "peer %s", assoc->init->peer_name);
}
-static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num)
+static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num, Z_SRW_PDU *sr)
{
statserv_options_block *cb = statserv_getcontrol();
if (!assoc->init)
assoc->maximumRecordSize = 3000000;
assoc->preferredMessageSize = 3000000;
+
+ if (sr->username)
+ {
+ Z_IdAuthentication *auth = odr_malloc(assoc->decode, sizeof(*auth));
+ int len;
+
+ len = strlen(sr->username) + 1;
+ if (sr->password)
+ len += strlen(sr->password) + 2;
+ auth->which = Z_IdAuthentication_open;
+ auth->u.open = odr_malloc(assoc->decode, len);
+ strcpy(auth->u.open, sr->username);
+ if (sr->password && *sr->password)
+ {
+ strcat(auth->u.open, "/");
+ strcat(auth->u.open, sr->password);
+ }
+ assoc->init->auth = auth;
+ }
+
#if 1
ce = yaz_set_proposal_charneg(assoc->decode, &encoding, 1, 0, 0, 1);
assoc->init->charneg_request = ce->u.charNeg3;
return 0;
}
assoc->backend = binitres->handle;
+ assoc->init->auth = 0;
if (binitres->errcode)
{
int srw_code = yaz_diag_bib1_to_srw(binitres->errcode);
}
static void srw_bend_search(association *assoc, request *req,
- Z_SRW_searchRetrieveRequest *srw_req,
+ Z_SRW_PDU *sr,
Z_SRW_searchRetrieveResponse *srw_res,
int *http_code)
{
int srw_error = 0;
Z_External *ext;
+ Z_SRW_searchRetrieveRequest *srw_req = sr->u.request;
*http_code = 200;
yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest");
- srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
+ srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
if (srw_res->num_diagnostics == 0 && assoc->init)
{
bend_search_rr rr;
}
static void srw_bend_explain(association *assoc, request *req,
- Z_SRW_explainRequest *srw_req,
+ Z_SRW_PDU *sr,
Z_SRW_explainResponse *srw_res,
int *http_code)
{
+ Z_SRW_explainRequest *srw_req = sr->u.explain_request;
yaz_log(log_requestdetail, "Got SRW ExplainRequest");
*http_code = 404;
- srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
+ srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
if (assoc->init)
{
bend_explain_rr rr;
}
static void srw_bend_scan(association *assoc, request *req,
- Z_SRW_scanRequest *srw_req,
+ Z_SRW_PDU *sr,
Z_SRW_scanResponse *srw_res,
int *http_code)
{
+ Z_SRW_scanRequest *srw_req = sr->u.scan_request;
yaz_log(log_requestdetail, "Got SRW ScanRequest");
*http_code = 200;
- srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
+ srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
if (srw_res->num_diagnostics == 0 && assoc->init)
{
struct scan_entry *save_entries;
}
static void srw_bend_update(association *assoc, request *req,
- Z_SRW_updateRequest *srw_req,
+ Z_SRW_PDU *sr,
Z_SRW_updateResponse *srw_res,
int *http_code)
{
+ Z_SRW_updateRequest *srw_req = sr->u.update_request;
yaz_log(YLOG_DEBUG, "Got SRW UpdateRequest");
yaz_log(YLOG_DEBUG, "num_diag = %d", srw_res->num_diagnostics );
*http_code = 404;
- srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics);
+ srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
if (assoc->init)
{
bend_update_rr rr;
}
else
{
- srw_bend_search(assoc, req, sr->u.request, res->u.response,
+ srw_bend_search(assoc, req, sr, res->u.response,
&http_code);
}
if (http_code == 200)
res->u.explain_response->diagnostics = diagnostic;
res->u.explain_response->num_diagnostics = num_diagnostic;
}
- srw_bend_explain(assoc, req, sr->u.explain_request,
+ srw_bend_explain(assoc, req, sr,
res->u.explain_response, &http_code);
if (http_code == 200)
soap_package->u.generic->p = res;
res->u.scan_response->diagnostics = diagnostic;
res->u.scan_response->num_diagnostics = num_diagnostic;
}
- srw_bend_scan(assoc, req, sr->u.scan_request,
+ srw_bend_scan(assoc, req, sr,
res->u.scan_response, &http_code);
if (http_code == 200)
soap_package->u.generic->p = res;
res->u.update_response->num_diagnostics = num_diagnostic;
}
yaz_log(YLOG_DEBUG, "num_diag = %d", res->u.update_response->num_diagnostics );
- srw_bend_update(assoc, req, sr->u.update_request,
+ srw_bend_update(assoc, req, sr,
res->u.update_response, &http_code);
if (http_code == 200)
soap_package->u.generic->p = res;
assoc->init->implementation_name,
odr_prepend(assoc->encode, "GFS", resp->implementationName));
- version = odr_strdup(assoc->encode, "$Revision: 1.75 $");
+ version = odr_strdup(assoc->encode, "$Revision: 1.76 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
resp->implementationVersion = odr_prepend(assoc->encode,
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: srwutil.c,v 1.38 2006-04-20 00:01:01 adam Exp $
+ * $Id: srwutil.c,v 1.39 2006-05-05 20:02:22 quinn Exp $
*/
/**
* \file srwutil.c
return 0;
}
+static int yaz_base64decode(const char *in, char *out)
+{
+ const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
+ int olen = 0;
+ int len = strlen(in);
+
+ while (len >= 4)
+ {
+ char i0, i1, i2, i3;
+ char *p;
+
+ if (!(p = index(map, in[0])))
+ return 0;
+ i0 = p - map;
+ len--;
+ if (!(p = index(map, in[1])))
+ return 0;
+ i1 = p - map;
+ len--;
+ *(out++) = i0 << 2 | i1 >> 4;
+ olen++;
+ if (in[2] == '=')
+ break;
+ if (!(p = index(map, in[2])))
+ return 0;
+ i2 = p - map;
+ len--;
+ *(out++) = i1 << 4 | i2 >> 2;
+ olen++;
+ if (in[3] == '=')
+ break;
+ if (!(p = index(map, in[3])))
+ return 0;
+ i3 = p - map;
+ len--;
+ *(out++) = i2 << 6 | i3;
+ olen++;
+
+ in += 4;
+ }
+
+ *out = '\0';
+ return olen;
+}
+
+/**
+ * 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)
+{
+ const char *basic = z_HTTP_header_lookup(hreq->headers, "Authorization");
+
+ if (username)
+ sr->username = username;
+ if (password)
+ sr->password = password;
+
+ if (basic) {
+ int len, olen;
+ char out[256];
+ char ubuf[256] = "", pbuf[256] = "", *p;
+ if (strncmp(basic, "Basic ", 6))
+ return;
+ basic += 6;
+ len = strlen(basic);
+ if (!len || len > 256)
+ return;
+ olen = yaz_base64decode(basic, out);
+ /* Format of out should be username:password at this point */
+ strcpy(ubuf, out);
+ if ((p = index(ubuf, ':'))) {
+ *(p++) = '\0';
+ if (*p)
+ strcpy(pbuf, p);
+ }
+ if (*ubuf)
+ sr->username = odr_strdup(decode, ubuf);
+ if (*pbuf)
+ sr->password = odr_strdup(decode, pbuf);
+ }
+}
+
void yaz_uri_val_int(const char *path, const char *name, ODR o, int **intp)
{
const char *v = yaz_uri_val(path, name, o);
char *version = 0;
char *query = 0;
char *pQuery = 0;
+ char *username = 0;
+ char *password = 0;
char *sortKeys = 0;
char *stylesheet = 0;
char *scanClause = 0;
query = v;
else if (!strcmp(n, "x-pquery"))
pQuery = v;
+ else if (!strcmp(n, "x-username"))
+ username = v;
+ else if (!strcmp(n, "x-password"))
+ password = v;
else if (!strcmp(n, "operation"))
operation = v;
else if (!strcmp(n, "stylesheet"))
sr->srw_version = version;
*srw_pdu = sr;
+ yaz_srw_decodeauth(sr, hreq, username, password, decode);
if (query)
{
sr->u.request->query_type = Z_SRW_query_type_cql;
Z_SRW_PDU *sr = yaz_srw_get(decode, Z_SRW_explain_request);
sr->srw_version = version;
+ yaz_srw_decodeauth(sr, hreq, username, password, decode);
*srw_pdu = sr;
sr->u.explain_request->recordPacking = recordPacking;
sr->u.explain_request->database = db;
sr->srw_version = version;
*srw_pdu = sr;
+ yaz_srw_decodeauth(sr, hreq, username, password, decode);
if (scanClause)
{
{
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");
sr->which = which;
switch(which)