X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=d6821d60b59aee78e02e5d020dc96c5f46827ba3;hp=cab02e585815368e229a2e933d894f4db32f9694;hb=aaddb3668a93e2048e2237463a375ec3f48b68bb;hpb=0ae46bd1e19dcc853c758af505c6f62f1f6be060 diff --git a/src/zoom-c.c b/src/zoom-c.c index cab02e5..d6821d6 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -1,11 +1,14 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ /** * \file zoom-c.c * \brief Implements ZOOM C interface. */ +#if HAVE_CONFIG_H +#include +#endif #include #include @@ -37,6 +40,7 @@ static zoom_ret do_write_ex(ZOOM_connection c, char *buf_out, int len_out); static void initlog(void) { static int log_level_initialized = 0; + if (!log_level_initialized) { log_api0 = yaz_log_module_level("zoom"); @@ -178,7 +182,6 @@ ZOOM_task ZOOM_connection_insert_task(ZOOM_connection c, int which) task->running = 0; task->which = which; - clear_error(c); return task; } @@ -338,6 +341,8 @@ static zoom_sru_mode get_sru_mode_from_string(const char *s) return zoom_sru_get; else if (!yaz_matchstr(s, "post")) return zoom_sru_post; + else if (!yaz_matchstr(s, "solr")) + return zoom_sru_solr; return zoom_sru_error; } @@ -346,7 +351,6 @@ ZOOM_API(void) const char *host, int portnum) { const char *val; - ZOOM_task task; initlog(); @@ -505,7 +509,7 @@ ZOOM_API(void) c->async = ZOOM_options_get_bool(c->options, "async", 0); yaz_log(c->log_details, "%p ZOOM_connection_connect async=%d", c, c->async); - task = ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); + ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); if (!c->async) { @@ -552,7 +556,7 @@ ZOOM_API(void) cs_close(c->cs); #if ZOOM_RESULT_LISTS - // Remove the connection's usage of resultsets + /* Remove the connection's usage of resultsets */ list = c->resultsets; while (list) { ZOOM_resultsets removed = list; @@ -605,6 +609,27 @@ void ZOOM_resultset_addref(ZOOM_resultset r) } } +static int g_resultsets = 0; +static YAZ_MUTEX g_resultset_mutex = 0; + +/* TODO We need to initialize this before running threaded: + * call resultset_use(0) */ + +static int resultset_use(int delta) { + int resultset_count; + if (g_resultset_mutex == 0) + yaz_mutex_create(&g_resultset_mutex); + yaz_mutex_enter(g_resultset_mutex); + g_resultsets += delta; + resultset_count = g_resultsets; + yaz_mutex_leave(g_resultset_mutex); + return resultset_count; +} + +int resultsets_count(void) { + return resultset_use(0); +} + ZOOM_resultset ZOOM_resultset_create(void) { int i; @@ -638,6 +663,7 @@ ZOOM_resultset ZOOM_resultset_create(void) YAZ_SHPTR_INIT(r->record_wrbuf, w); } #endif + resultset_use(1); return r; } @@ -827,6 +853,7 @@ static void resultset_destroy(ZOOM_resultset r) #if SHPTR YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy); #endif + resultset_use(-1); xfree(r); } else @@ -999,41 +1026,35 @@ static void get_cert(ZOOM_connection c) } static zoom_ret do_connect_host(ZOOM_connection c, - const char *effective_host, const char *logical_url); static zoom_ret do_connect(ZOOM_connection c) { - const char *effective_host; - - if (c->proxy) - effective_host = c->proxy; - else - effective_host = c->host_port; - return do_connect_host(c, effective_host, c->host_port); + return do_connect_host(c, c->host_port); } -static zoom_ret do_connect_host(ZOOM_connection c, const char *effective_host, - const char *logical_url) +static zoom_ret do_connect_host(ZOOM_connection c, const char *logical_url) { void *add; - yaz_log(c->log_details, "%p do_connect effective_host=%s", c, effective_host); - if (c->cs) cs_close(c->cs); - c->cs = cs_create_host(effective_host, 0, &add); - + c->cs = cs_create_host_proxy(logical_url, 0, &add, c->proxy); + if (c->cs && c->cs->protocol == PROTO_HTTP) { #if YAZ_HAVE_XML2 - if (logical_url) + c->proto = PROTO_HTTP; + xfree(c->path); + if (c->proxy) + { + c->path = xstrdup(logical_url); + } + else { const char *db = 0; - c->proto = PROTO_HTTP; cs_get_host_args(logical_url, &db); - xfree(c->path); c->path = xmalloc(strlen(db) * 3 + 2); yaz_encode_sru_dbpath_buf(c->path, db); @@ -1486,7 +1507,7 @@ static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri, { struct Z_HTTP_Header *h; Z_GDU *gdu = get_HTTP_Request_url(c->odr_out, uri); - char *combined_cookies; + char *combined_cookies = 0; int combined_cookies_len = 0; gdu->u.HTTP_Request->method = odr_strdup(c->odr_out, "GET"); @@ -1568,7 +1589,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) { /* since redirect may change host we just reconnect. A smarter implementation might check whether it's the same server */ - do_connect_host(c, location, 0); + do_connect_host(c, location); send_HTTP_redirect(c, location, hres); /* we're OK for now. Operation is not really complete */ ret = 0; @@ -1595,7 +1616,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) } if (cret == zoom_complete) { - yaz_log(YLOG_LOG, "removing tasks in handle_http"); + yaz_log(c->log_details, "removing tasks in handle_http"); ZOOM_connection_remove_task(c); } { @@ -1853,6 +1874,12 @@ ZOOM_API(const char *) return "CCL configuration error"; case ZOOM_ERROR_CCL_PARSE: return "CCL parsing error"; + case ZOOM_ERROR_ES_INVALID_ACTION: + return "Extended Service. invalid action"; + case ZOOM_ERROR_ES_INVALID_VERSION: + return "Extended Service. invalid version"; + case ZOOM_ERROR_ES_INVALID_SYNTAX: + return "Extended Service. invalid syntax"; default: return diagbib1_str(error); }