/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
/**
resultset_destroy(task->u.search.resultset);
xfree(task->u.search.syntax);
xfree(task->u.search.elementSetName);
+ xfree(task->u.search.schema);
break;
case ZOOM_TASK_RETRIEVE:
resultset_destroy(task->u.retrieve.resultset);
xfree(task->u.retrieve.syntax);
xfree(task->u.retrieve.elementSetName);
+ xfree(task->u.retrieve.schema);
break;
case ZOOM_TASK_CONNECT:
break;
c->user = 0;
c->group = 0;
c->password = 0;
+ c->url_authentication = 0;
c->maximum_record_size = 0;
c->preferred_message_size = 0;
c->sru_version = 0;
c->no_redirects = 0;
+ c->cookies = 0;
+ c->saveAPDU_wrbuf = 0;
return c;
}
const char *cp = ZOOM_options_get(options, "databaseName");
if ((!cp || !*cp) && con->host_port)
- {
- if (strncmp(con->host_port, "unix:", 5) == 0)
- cp = strchr(con->host_port+5, ':');
- else
- cp = strchr(con->host_port, '/');
- if (cp)
- cp++;
- }
+ cs_get_host_args(con->host_port, &cp);
if (!cp || !*cp)
cp = "Default";
nmem_strsplit(odr_getmem(odr), "+", cp, &databaseNames, num);
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 =
c->async = ZOOM_options_get_bool(c->options, "async", 0);
+ yaz_cookies_destroy(c->cookies);
+ c->cookies = yaz_cookies_create();
+
if (c->sru_mode == zoom_sru_error)
{
ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val);
ZOOM_API(void) ZOOM_resultset_release(ZOOM_resultset r)
{
-#if ZOOM_RESULT_LISTS
-#else
if (r->connection)
{
/* remove ourselves from the resultsets in connection */
}
r->connection = 0;
}
-#endif
}
ZOOM_API(void)
ZOOM_connection_destroy(ZOOM_connection c)
{
-#if ZOOM_RESULT_LISTS
- ZOOM_resultsets list;
-#else
ZOOM_resultset r;
-#endif
if (!c)
return;
yaz_log(c->log_api, "%p ZOOM_connection_destroy", c);
if (c->cs)
cs_close(c->cs);
-#if ZOOM_RESULT_LISTS
- /* Remove the connection's usage of resultsets */
- list = c->resultsets;
- while (list) {
- ZOOM_resultsets removed = list;
- ZOOM_resultset_destroy(list->resultset);
- list = list->next;
- xfree(removed);
- }
-#else
for (r = c->resultsets; r; r = r->next)
r->connection = 0;
-#endif
xfree(c->buf_in);
xfree(c->addinfo);
xfree(c->group);
xfree(c->password);
xfree(c->sru_version);
+ yaz_cookies_destroy(c->cookies);
+ wrbuf_destroy(c->saveAPDU_wrbuf);
xfree(c);
}
r->odr = odr_createmem(ODR_ENCODE);
r->piggyback = 1;
r->setname = 0;
- r->schema = 0;
r->step = 0;
for (i = 0; i<RECORD_HASH_SIZE; i++)
r->record_hash[i] = 0;
ZOOM_task task;
const char *cp;
int start, count;
- const char *syntax, *elementSetName;
-#if ZOOM_RESULT_LISTS
- ZOOM_resultsets set;
-#endif
+ const char *syntax, *elementSetName, *schema;
yaz_log(c->log_api, "%p ZOOM_connection_search set %p query %p", c, r, q);
r->r_sort_spec = ZOOM_query_get_sortspec(q);
cp = ZOOM_options_get(r->options, "setname");
if (cp)
r->setname = xstrdup(cp);
- cp = ZOOM_options_get(r->options, "schema");
- if (cp)
- r->schema = xstrdup(cp);
r->databaseNames = ZOOM_connection_get_databases(c, c->options, &r->num_databaseNames,
r->odr);
r->connection = c;
-
-#if ZOOM_RESULT_LISTS
- yaz_log(log_details, "%p ZOOM_connection_search: Adding new resultset (%p) to resultsets (%p) ", c, r, c->resultsets);
- set = xmalloc(sizeof(*set));
- ZOOM_resultset_addref(r);
- set->resultset = r;
- set->next = c->resultsets;
- c->resultsets = set;
-#else
r->next = c->resultsets;
c->resultsets = r;
-#endif
if (c->host_port && c->proto == PROTO_HTTP)
{
if (!c->cs)
syntax = ZOOM_options_get(r->options, "preferredRecordSyntax");
task->u.search.syntax = syntax ? xstrdup(syntax) : 0;
elementSetName = ZOOM_options_get(r->options, "elementSetName");
- task->u.search.elementSetName = elementSetName
- ? xstrdup(elementSetName) : 0;
+ task->u.search.elementSetName = elementSetName ?
+ xstrdup(elementSetName) : 0;
+ schema = ZOOM_options_get(r->options, "schema");
+ task->u.search.schema = schema ? xstrdup(schema) : 0;
ZOOM_resultset_addref(r);
ZOOM_options_destroy(r->options);
odr_destroy(r->odr);
xfree(r->setname);
- xfree(r->schema);
yaz_mutex_destroy(&r->mutex);
#if SHPTR
YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
? xstrdup(elementSetName) : 0;
cp = ZOOM_options_get(r->options, "schema");
- if (cp)
- {
- if (!r->schema || strcmp(r->schema, cp))
- {
- xfree(r->schema);
- r->schema = xstrdup(cp);
- }
- }
+ task->u.retrieve.schema = cp ? xstrdup(cp) : 0;
ZOOM_resultset_addref(r);
ZOOM_options_get(s->options, "preferredRecordSyntax");
const char *elementSetName =
ZOOM_options_get(s->options, "elementSetName");
+ const char *schema =
+ ZOOM_options_get(s->options, "schema");
- return ZOOM_record_cache_lookup(s, pos, syntax, elementSetName);
+ return ZOOM_record_cache_lookup(s, pos, syntax, elementSetName, schema);
}
ZOOM_API(ZOOM_record)
#if YAZ_HAVE_XML2
-static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri,
- Z_HTTP_Response *cookie_hres)
+static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri)
{
- struct Z_HTTP_Header *h;
- char *combined_cookies = 0;
- int combined_cookies_len = 0;
Z_GDU *gdu = z_get_HTTP_Request_uri(c->odr_out, uri, 0, c->proxy ? 1 : 0);
gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET");
z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, "Accept",
"text/xml");
-
- for (h = cookie_hres->headers; h; h = h->next)
- {
- if (!strcmp(h->name, "Set-Cookie"))
- {
- char *cp;
-
- if (!(cp = strchr(h->value, ';')))
- cp = h->value + strlen(h->value);
- if (cp - h->value >= 1) {
- combined_cookies = xrealloc(combined_cookies, combined_cookies_len + cp - h->value + 3);
- memcpy(combined_cookies+combined_cookies_len, h->value, cp - h->value);
- combined_cookies[combined_cookies_len + cp - h->value] = '\0';
- strcat(combined_cookies,"; ");
- combined_cookies_len = strlen(combined_cookies);
- }
- }
- }
-
- if (combined_cookies_len)
- {
- z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers,
- "Cookie", combined_cookies);
- xfree(combined_cookies);
- }
-
+ yaz_cookies_request(c->cookies, c->odr_out, gdu->u.HTTP_Request);
if (c->user && c->password)
{
z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
c->user, c->password);
}
- if (!z_GDU(c->odr_out, &gdu, 0, 0))
+ return ZOOM_send_GDU(c, gdu);
+}
+
+zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
+{
+ ZOOM_Event event;
+
+ int r = z_GDU(c->odr_out, &gdu, 0, 0);
+ if (!r)
return zoom_complete;
if (c->odr_print)
z_GDU(c->odr_print, &gdu, 0, 0);
if (c->odr_save)
z_GDU(c->odr_save, &gdu, 0, 0);
c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
-
odr_reset(c->odr_out);
+
+ event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
+ ZOOM_connection_put_event(c, event);
+
return ZOOM_send_buf(c);
}
ZOOM_connection_set_mask(c, 0);
yaz_log(c->log_details, "%p handle_http", c);
+ yaz_cookies_response(c->cookies, hres);
if ((hres->code == 301 || hres->code == 302) && c->sru_mode == zoom_sru_get
&& (location = z_HTTP_header_lookup(hres->headers, "Location")))
{
{
/* since redirect may change host we just reconnect. A smarter
implementation might check whether it's the same server */
- do_connect_host(c, location);
- send_HTTP_redirect(c, location, hres);
- /* we're OK for now. Operation is not really complete */
+ if (*location != '/')
+ {
+ /* full header */
+ do_connect_host(c, location);
+ send_HTTP_redirect(c, location);
+ }
+ else
+ { /* relative header - same host */
+ char *args = 0;
+ char *nlocation = odr_malloc(c->odr_in, strlen(location)
+ + strlen(c->host_port) + 3);
+ strcpy(nlocation, c->host_port);
+ cs_get_host_args(nlocation, (const char **) &args);
+ if (!args || !*args)
+ args = nlocation + strlen(nlocation);
+ else
+ args--;
+ strcpy(args, location);
+ send_HTTP_redirect(c, nlocation);
+ }
return;
}
}
ZOOM_API(const char *)
ZOOM_connection_option_get(ZOOM_connection c, const char *key)
{
- return ZOOM_options_get(c->options, key);
+ if (!strcmp(key, "APDU"))
+ {
+ return c->saveAPDU_wrbuf ? wrbuf_cstr(c->saveAPDU_wrbuf) : "";
+ }
+ else
+ return ZOOM_options_get(c->options, key);
}
ZOOM_API(const char *)
ZOOM_connection_option_getl(ZOOM_connection c, const char *key, int *lenp)
{
- return ZOOM_options_getl(c->options, key, lenp);
+ if (!strcmp(key, "APDU"))
+ {
+ if (c->saveAPDU_wrbuf)
+ {
+ *lenp = wrbuf_len(c->saveAPDU_wrbuf);
+ return wrbuf_cstr(c->saveAPDU_wrbuf);
+ }
+ else
+ {
+ *lenp = 0;
+ return "";
+ }
+ }
+ else
+ return ZOOM_options_getl(c->options, key, lenp);
}
ZOOM_API(void)
ZOOM_connection_option_set(ZOOM_connection c, const char *key,
const char *val)
{
- ZOOM_options_set(c->options, key, val);
+ if (!strcmp(key, "saveAPDU"))
+ {
+ if (val && strcmp(val, "0"))
+ {
+ if (!c->saveAPDU_wrbuf)
+ c->saveAPDU_wrbuf = wrbuf_alloc();
+ else
+ wrbuf_rewind(c->saveAPDU_wrbuf);
+ }
+ else
+ {
+ wrbuf_destroy(c->saveAPDU_wrbuf);
+ c->saveAPDU_wrbuf = 0;
+ }
+ ZOOM_connection_save_apdu_wrbuf(c, c->saveAPDU_wrbuf);
+ }
+ else
+ ZOOM_options_set(c->options, key, val);
}
ZOOM_API(void)