}
void ZOOM_connection_remove_tasks(ZOOM_connection c);
+static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri);
void ZOOM_set_dset_error(ZOOM_connection c, int error,
const char *dset,
c->sru_version = 0;
c->no_redirects = 0;
c->cookies = 0;
+ c->location = 0;
c->saveAPDU_wrbuf = 0;
ZOOM_memcached_init(c);
const char *host, int portnum)
{
const char *val;
- const char *http_lead;
initlog();
ZOOM_set_error(c, ZOOM_ERROR_NONE, 0);
ZOOM_connection_remove_tasks(c);
- if (c->odr_print)
- {
- odr_setprint(c->odr_print, 0); /* prevent destroy from fclose'ing */
- odr_destroy(c->odr_print);
- }
- if (ZOOM_options_get_bool(c->options, "apdulog", 0))
- {
- c->odr_print = odr_createmem(ODR_PRINT);
- odr_setprint(c->odr_print, yaz_log_file());
- }
- else
- c->odr_print = 0;
-
if (c->cs)
{
yaz_log(c->log_details, "%p ZOOM_connection_connect reconnect ok", c);
else
c->lang = 0;
- val = ZOOM_options_get(c->options, "sru");
- if (val && *val && !strstr(host, "://"))
- http_lead = "http://";
- else
- http_lead = "";
- c->sru_mode = get_sru_mode_from_string(val);
-
if (host)
{
char hostn[128];
+ const char *http_lead;
+
+ val = ZOOM_options_get(c->options, "sru");
+ if (val && *val && !strstr(host, "://"))
+ http_lead = "http://";
+ else
+ http_lead = "";
+ c->sru_mode = get_sru_mode_from_string(val);
+
xfree(c->host_port);
if (portnum)
{
return;
}
+ if (c->odr_print)
+ odr_destroy(c->odr_print);
+ c->odr_print = 0;
+ val = ZOOM_options_get(c->options, "apdufile");
+ if (val)
+ {
+ c->odr_print = odr_createmem(ODR_PRINT);
+ if (strcmp(val, "-"))
+ {
+ FILE *f = fopen(val, "a");
+ if (!f)
+ {
+ WRBUF w = wrbuf_alloc();
+ wrbuf_printf(w, "fopen: %s", val);
+ ZOOM_set_error(c, ZOOM_ERROR_INTERNAL, wrbuf_cstr(w));
+ wrbuf_destroy(w);
+ return;
+ }
+ odr_setprint(c->odr_print, f);
+ }
+ }
+ else if (ZOOM_options_get_bool(c->options, "apdulog", 0))
+ {
+ c->odr_print = odr_createmem(ODR_PRINT);
+ odr_setprint_noclose(c->odr_print, yaz_log_file());
+ }
+
yaz_log(c->log_details, "%p ZOOM_connection_connect async=%d", c, c->async);
ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT);
if (c->odr_save)
odr_destroy(c->odr_save);
if (c->odr_print)
- {
- odr_setprint(c->odr_print, 0); /* prevent destroy from fclose'ing */
odr_destroy(c->odr_print);
- }
ZOOM_options_destroy(c->options);
ZOOM_connection_remove_tasks(c);
ZOOM_connection_remove_events(c);
xfree(c->group);
xfree(c->password);
xfree(c->sru_version);
+ xfree(c->location);
yaz_cookies_destroy(c->cookies);
wrbuf_destroy(c->saveAPDU_wrbuf);
xfree(c);
r->connection = 0;
r->databaseNames = 0;
r->num_databaseNames = 0;
+ r->req_facets = 0;
r->res_facets = 0;
r->num_res_facets = 0;
r->facets_names = 0;
ZOOM_connection_search(ZOOM_connection c, ZOOM_query q)
{
ZOOM_resultset r = ZOOM_resultset_create();
- const char *cp;
ZOOM_task task;
int start, count;
const char *syntax, *elementSetName, *schema;
r->options = ZOOM_options_create_with_parent(c->options);
+ r->req_facets = odr_strdup_null(r->odr,
+ ZOOM_options_get(r->options, "facets"));
start = ZOOM_options_get_int(r->options, "start", 0);
count = ZOOM_options_get_int(r->options, "count", 0);
{
(cp != 0 ? "presentChunk": "step"), 0);
}
r->piggyback = ZOOM_options_get_bool(r->options, "piggyback", 1);
- cp = ZOOM_options_get(r->options, "setname");
- if (cp)
- r->setname = xstrdup(cp);
-
- r->databaseNames = ZOOM_connection_get_databases(c, c->options, &r->num_databaseNames,
- r->odr);
-
+ r->setname = odr_strdup_null(r->odr,
+ ZOOM_options_get(r->options, "setname"));
+ r->databaseNames = ZOOM_connection_get_databases(c, c->options,
+ &r->num_databaseNames,
+ r->odr);
r->connection = c;
r->next = c->resultsets;
c->resultsets = r;
ZOOM_query_destroy(r->query);
ZOOM_options_destroy(r->options);
odr_destroy(r->odr);
- xfree(r->setname);
yaz_mutex_destroy(&r->mutex);
#if SHPTR
YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
if (c->cs)
cs_close(c->cs);
- c->cs = cs_create_host_proxy(logical_url, 0, &add,
+ c->cs = cs_create_host_proxy(logical_url, CS_FLAGS_DNS_NO_BLOCK, &add,
c->tproxy ? c->tproxy : c->proxy);
if (c->cs && c->cs->protocol == PROTO_HTTP)
assert(c->tasks->which == ZOOM_TASK_CONNECT);
ZOOM_connection_remove_task(c);
ZOOM_connection_set_mask(c, 0);
- ZOOM_connection_exec_task(c);
+
+ if (c->cs && c->location)
+ send_HTTP_redirect(c, c->location);
+ else
+ ZOOM_connection_exec_task(c);
}
c->state = STATE_ESTABLISHED;
return zoom_pending;
const char *schema =
ZOOM_options_get(s->options, "schema");
- return ZOOM_record_cache_lookup(s, pos, syntax, elementSetName, schema);
+ return ZOOM_record_cache_lookup_i(s, pos, syntax, elementSetName, schema);
}
ZOOM_API(ZOOM_record)
return 1;
}
-#if YAZ_HAVE_XML2
static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri)
{
z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
c->user, c->password);
}
+ xfree(c->location);
+ c->location = 0;
return ZOOM_send_GDU(c, gdu);
}
+
zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
{
ZOOM_Event event;
return ZOOM_send_buf(c);
}
-#if YAZ_HAVE_XML2
void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
const char *addinfo, const char *addinfo2)
{
ZOOM_set_dset_error(c, error, "HTTP", addinfo, addinfo2);
}
-#endif
-
+#if YAZ_HAVE_XML2
static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
{
zoom_ret cret = zoom_complete;
int host_change = 0;
location = yaz_check_location(c->odr_in, c->host_port,
location, &host_change);
- if (do_connect_host(c, location) == zoom_complete)
- return; /* connect failed.. */
- send_HTTP_redirect(c, location);
+ xfree(c->location);
+ c->location = xstrdup(location);
+ do_connect_host(c, location);
return;
}
}
if (c->cs->io_pending & CS_WANT_READ)
mask += ZOOM_SELECT_READ;
ZOOM_connection_set_mask(c, mask);
- event = ZOOM_Event_create(ZOOM_EVENT_NONE);
+ event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
ZOOM_connection_put_event(c, event);
}
else if (ret == 0)
else
{
/* no init request for SRW .. */
- assert(c->tasks->which == ZOOM_TASK_CONNECT);
- ZOOM_connection_remove_task(c);
- ZOOM_connection_set_mask(c, 0);
- ZOOM_connection_exec_task(c);
+ if (c->tasks->which == ZOOM_TASK_CONNECT)
+ {
+ ZOOM_connection_remove_task(c);
+ ZOOM_connection_set_mask(c, 0);
+ }
+ if (c->cs && c->location)
+ send_HTTP_redirect(c, c->location);
+ else
+ ZOOM_connection_exec_task(c);
}
c->state = STATE_ESTABLISHED;
}