Merge branch 'master' into paz-927
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Sep 2014 12:33:05 +0000 (14:33 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Sep 2014 12:33:05 +0000 (14:33 +0200)
15 files changed:
src/Makefile.am
src/client.c
src/client.h
src/connection.c
src/connection.h
src/database.c
src/getaddrinfo.c [deleted file]
src/host.c [deleted file]
src/host.h [deleted file]
src/pazpar2_config.c
src/pazpar2_config.h
src/session.c
test/test_http.urls
test/test_limit_limitmap.urls
win/makefile

index 156d677..d537ba9 100644 (file)
@@ -22,8 +22,6 @@ libpazpar2_a_SOURCES = \
        database.c database.h \
        eventl.c eventl.h \
        facet_limit.c facet_limit.h \
-       getaddrinfo.c \
-       host.c host.h \
        http.c http.h http_command.c \
        incref.c incref.h \
        jenkins_hash.c jenkins_hash.h \
index 723f8be..dd4405f 100644 (file)
@@ -1163,6 +1163,12 @@ void client_disconnect(struct client *cl)
     client_set_connection(cl, 0);
 }
 
+void client_mark_dead(struct client *cl)
+{
+    if (cl->connection)
+        connection_mark_dead(cl->connection);
+}
+
 // Initialize CCL map for a target
 static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset)
 {
index 5d8bace..c7f5d3a 100644 (file)
@@ -69,6 +69,7 @@ int client_destroy(struct client *c);
 
 void client_set_connection(struct client *cl, struct connection *con);
 void client_disconnect(struct client *cl);
+void client_mark_dead(struct client *cl);
 int client_prep_connection(struct client *cl,
                            int operation_timeout, int session_timeout,
                            iochan_man_t iochan,
index 3afc75f..2c7c0c2 100644 (file)
@@ -43,7 +43,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/tcpip.h>
 #include "connection.h"
 #include "session.h"
-#include "host.h"
 #include "client.h"
 #include "settings.h"
 
@@ -89,7 +88,6 @@ int connections_count(void)
 struct connection {
     IOCHAN iochan;
     ZOOM_connection link;
-    struct host *host;
     struct client *client;
     char *zproxy;
     char *url;
@@ -105,42 +103,14 @@ struct connection {
 
 static int connection_connect(struct connection *con, iochan_man_t iochan_man);
 
-static int connection_is_idle(struct connection *co)
-{
-    ZOOM_connection link = co->link;
-    int event;
-
-    if (co->state != Conn_Open || !link)
-        return 0;
-
-    if (!ZOOM_connection_is_idle(link))
-        return 0;
-    event = ZOOM_connection_peek_event(link);
-    if (event == ZOOM_EVENT_NONE)
-        return 1;
-    else
-        return 0;
-}
-
 ZOOM_connection connection_get_link(struct connection *co)
 {
     return co->link;
 }
 
-static void remove_connection_from_host(struct connection *con)
-{
-    struct connection **conp = &con->host->connections;
-    assert(con);
-    while (*conp)
-    {
-        if (*conp == con)
-        {
-            *conp = (*conp)->next;
-            break;
-        }
-        conp = &(*conp)->next;
-    }
-    yaz_cond_broadcast(con->host->cond_ready);
+void connection_mark_dead(struct connection *co)
+{ 
+    iochan_settimeout(co->iochan, 1);
 }
 
 // Close connection and recycle structure
@@ -168,7 +138,7 @@ static void connection_destroy(struct connection *co)
 // client's database
 static struct connection *connection_create(struct client *cl,
                                             const char *url,
-                                            struct host *host,
+                                            const char *zproxy,
                                             int operation_timeout,
                                             int session_timeout,
                                             iochan_man_t iochan_man)
@@ -176,24 +146,20 @@ static struct connection *connection_create(struct client *cl,
     struct connection *co;
 
     co = xmalloc(sizeof(*co));
-    co->host = host;
 
     co->client = cl;
     co->url = xstrdup(url);
     co->zproxy = 0;
+    if (zproxy)
+        co->zproxy = xstrdup(zproxy);
+
     client_set_connection(cl, co);
     co->link = 0;
     co->state = Conn_Closed;
     co->operation_timeout = operation_timeout;
     co->session_timeout = session_timeout;
 
-    if (host->ipport)
-        connection_connect(co, iochan_man);
-
-    yaz_mutex_enter(host->mutex);
-    co->next = co->host->connections;
-    co->host->connections = co;
-    yaz_mutex_leave(host->mutex);
+    connection_connect(co, iochan_man);
 
     connection_use(1);
     return co;
@@ -240,7 +206,6 @@ static void non_block_events(struct connection *co)
                     iochan_settimeout(iochan, co->session_timeout);
                     client_set_state(cl, Client_Idle);
                 }
-                yaz_cond_broadcast(co->host->cond_ready);
             }
             break;
         case ZOOM_EVENT_SEND_DATA:
@@ -264,6 +229,8 @@ static void non_block_events(struct connection *co)
         case ZOOM_EVENT_RECV_RECORD:
             client_record_response(cl, &got_records);
             break;
+        case ZOOM_EVENT_NONE:
+            break;
         default:
             yaz_log(YLOG_LOG, "Unhandled event (%d) from %s",
                     ev, client_get_id(cl));
@@ -281,6 +248,19 @@ static void non_block_events(struct connection *co)
     }
 }
 
+static void iochan_update(struct connection *co)
+{
+    if (co->link)
+    {
+        int m = ZOOM_connection_get_mask(co->link);
+
+        if (m == 0)
+            m = ZOOM_SELECT_READ;
+        iochan_setflags(co->iochan, m);
+        iochan_setfd(co->iochan, ZOOM_connection_get_socket(co->link));
+    }
+}
+
 void connection_continue(struct connection *co)
 {
     int r = ZOOM_connection_exec_task(co->link);
@@ -293,19 +273,14 @@ void connection_continue(struct connection *co)
         client_unlock(cl);
     }
     else
-    {
-        iochan_setflags(co->iochan, ZOOM_connection_get_mask(co->link));
-        iochan_setfd(co->iochan, ZOOM_connection_get_socket(co->link));
-    }
+        iochan_update(co);
 }
 
 static void connection_handler(IOCHAN iochan, int event)
 {
     struct connection *co = iochan_getdata(iochan);
     struct client *cl;
-    struct host *host = co->host;
 
-    yaz_mutex_enter(host->mutex);
     cl = co->client;
     if (!cl)
     {
@@ -313,8 +288,6 @@ static void connection_handler(IOCHAN iochan, int event)
            a closed connection from the target.. Or, perhaps, an unexpected
            package.. We will just close the connection */
         yaz_log(YLOG_LOG, "timeout connection %p event=%d", co, event);
-        remove_connection_from_host(co);
-        yaz_mutex_leave(host->mutex);
         connection_destroy(co);
     }
     else if (event & EVENT_TIMEOUT)
@@ -324,14 +297,15 @@ static void connection_handler(IOCHAN iochan, int event)
         non_block_events(co);
         client_unlock(cl);
 
-        remove_connection_from_host(co);
-        yaz_mutex_leave(host->mutex);
         connection_destroy(co);
     }
     else
     {
-        yaz_mutex_leave(host->mutex);
-
+        if (ZOOM_connection_is_idle(co->link))
+        {
+            connection_destroy(co);
+            return;
+        }
         client_lock(cl);
         non_block_events(co);
 
@@ -340,77 +314,12 @@ static void connection_handler(IOCHAN iochan, int event)
         non_block_events(co);
         client_unlock(cl);
 
-        if (co->link)
-        {
-            iochan_setflags(iochan, ZOOM_connection_get_mask(co->link));
-            iochan_setfd(iochan, ZOOM_connection_get_socket(co->link));
-        }
-    }
-}
-
-
-// Disassociate connection from client
-static void connection_release(struct connection *co)
-{
-    struct client *cl = co->client;
-
-    if (!cl)
-        return;
-    client_set_connection(cl, 0);
-    co->client = 0;
-}
-
-void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
-{
-    struct connection *con;
-
-    yaz_mutex_enter(host->mutex);
-    con = host->connections;
-    while (con)
-    {
-        if (con->state == Conn_Closed)
-        {
-            if (!host->ipport || !con->client) /* unresolved or no client */
-            {
-                remove_connection_from_host(con);
-                yaz_mutex_leave(host->mutex);
-                connection_destroy(con);
-            }
-            else
-            {
-                struct session_database *sdb = client_get_database(con->client);
-                if (sdb)
-                {
-                    yaz_mutex_leave(host->mutex);
-                    client_start_search(con->client);
-                }
-                else
-                {
-                    remove_connection_from_host(con);
-                    yaz_mutex_leave(host->mutex);
-                    connection_destroy(con);
-                }
-            }
-            /* start all over .. at some point it will be NULL */
-            yaz_mutex_enter(host->mutex);
-            con = host->connections;
-        }
-        else
-        {
-            con = con->next;
-        }
+        iochan_update(co);
     }
-    yaz_mutex_leave(host->mutex);
-}
-
-static struct host *connection_get_host(struct connection *con)
-{
-    return con->host;
 }
 
 static int connection_connect(struct connection *con, iochan_man_t iochan_man)
 {
-    struct host *host = connection_get_host(con);
     ZOOM_options zoptions = ZOOM_options_create();
     const char *auth;
     const char *charset;
@@ -437,19 +346,11 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man)
     if (redis && *redis)
         ZOOM_options_set(zoptions, "redis", redis);
 
-    assert(host->ipport);
-    if (host->proxy)
-    {
-        yaz_log(YLOG_LOG, "proxy=%s", host->ipport);
-        ZOOM_options_set(zoptions, "proxy", host->ipport);
-    }
-    else
+    if (con->zproxy)
     {
-        assert(host->tproxy);
-        yaz_log(YLOG_LOG, "tproxy=%s", host->ipport);
-        ZOOM_options_set(zoptions, "tproxy", host->ipport);
+        yaz_log(YLOG_LOG, "proxy=%s", con->zproxy);
+        ZOOM_options_set(zoptions, "proxy", con->zproxy);
     }
-
     if (apdulog && *apdulog)
         ZOOM_options_set(zoptions, "apdulog", apdulog);
 
@@ -533,9 +434,6 @@ int client_prep_connection(struct client *cl,
     struct session_database *sdb = client_get_database(cl);
     const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
     const char *url = session_setting_oneval(sdb, PZ_URL);
-    const char *sru = session_setting_oneval(sdb, PZ_SRU);
-    struct host *host = 0;
-    int default_port = *sru ? 80 : 210;
 
     if (zproxy && zproxy[0] == '\0')
         zproxy = 0;
@@ -543,110 +441,15 @@ int client_prep_connection(struct client *cl,
     if (!url || !*url)
         url = sdb->database->id;
 
-    host = find_host(client_get_session(cl)->service->server->database_hosts,
-                     url, zproxy, default_port, iochan_man);
-
     yaz_log(YLOG_DEBUG, "client_prep_connection: target=%s url=%s",
             client_get_id(cl), url);
-    if (!host)
-        return 0;
 
     co = client_get_connection(cl);
-    if (co)
-    {
-        assert(co->host);
-        if (co->host == host && client_get_state(cl) == Client_Idle)
-        {
-            return 2;
-        }
-        connection_release(co);
-        co = 0;
-    }
     if (!co)
     {
-        int max_connections = 0;
-        int reuse_connections = 1;
-        const char *v = session_setting_oneval(client_get_database(cl),
-                                               PZ_MAX_CONNECTIONS);
-        if (v && *v)
-            max_connections = atoi(v);
-
-        v = session_setting_oneval(client_get_database(cl),
-                PZ_REUSE_CONNECTIONS);
-        if (v && *v)
-            reuse_connections = atoi(v);
-
-        // See if someone else has an idle connection
-        // We should look at timestamps here to select the longest-idle connection
-        yaz_mutex_enter(host->mutex);
-        while (1)
-        {
-            int num_connections = 0;
-            for (co = host->connections; co; co = co->next)
-                num_connections++;
-            if (reuse_connections)
-            {
-                for (co = host->connections; co; co = co->next)
-                {
-                    if (connection_is_idle(co) &&
-                        !strcmp(url, co->url) &&
-                        (!co->client || client_get_state(co->client) == Client_Idle) &&
-                        !strcmp(ZOOM_connection_option_get(co->link, "user"),
-                                session_setting_oneval(client_get_database(cl),
-                                                       PZ_AUTHENTICATION)))
-                    {
-                        if (zproxy == 0 && co->zproxy == 0)
-                            break;
-                        if (zproxy && co->zproxy && !strcmp(zproxy, co->zproxy))
-                            break;
-                    }
-                }
-                if (co)
-                {
-                    yaz_log(YLOG_LOG, "num_connections = %d (reusing)", num_connections);
-                    break;
-                }
-            }
-            if (max_connections <= 0 || num_connections < max_connections)
-            {
-                yaz_log(YLOG_LOG, "num_connections = %d (new); max = %d",
-                        num_connections, max_connections);
-                break;
-            }
-            yaz_log(YLOG_LOG, "num_connections = %d (waiting) max = %d",
-                    num_connections, max_connections);
-            if (yaz_cond_wait(host->cond_ready, host->mutex, abstime))
-            {
-                yaz_log(YLOG_LOG, "out of connections %s", client_get_id(cl));
-                client_set_state(cl, Client_Error);
-                yaz_mutex_leave(host->mutex);
-                return 0;
-            }
-        }
-        if (co)
-        {
-            yaz_log(YLOG_LOG,  "%p Connection reuse. state: %d", co, co->state);
-            connection_release(co);
-            client_set_connection(cl, co);
-            co->client = cl;
-            /* ensure that connection is only assigned to this client
-               by marking the client non Idle */
-            client_set_state(cl, Client_Working);
-            yaz_mutex_leave(host->mutex);
-            co->operation_timeout = operation_timeout;
-            co->session_timeout = session_timeout;
-            /* tells ZOOM to reconnect if necessary. Disabled becuase
-               the ZOOM_connection_connect flushes the task queue */
-            ZOOM_connection_connect(co->link, 0, 0);
-        }
-        else
-        {
-            yaz_mutex_leave(host->mutex);
-            co = connection_create(cl, url, host,
-                                   operation_timeout, session_timeout,
-                                   iochan_man);
-        }
-        assert(co->host);
+        co = connection_create(cl, url, zproxy,
+                               operation_timeout, session_timeout,
+                               iochan_man);
     }
 
     if (co && co->link)
index e92019e..fe4f83a 100644 (file)
@@ -28,12 +28,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "eventl.h"
 
 struct connection;
-struct host;
 
-void connect_resolver_host(struct host *host, iochan_man_t iochan);
 ZOOM_connection connection_get_link(struct connection *co);
 void connection_continue(struct connection *co);
-void connect_resolver_host(struct host *host, iochan_man_t iochan_man);
+void connection_mark_dead(struct connection *co);
 
 #endif
 
index a23c6fd..2064fee 100644 (file)
@@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "ppmutex.h"
 #include "session.h"
-#include "host.h"
 #include "pazpar2_config.h"
 #include "settings.h"
 #include "http.h"
diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c
deleted file mode 100644 (file)
index 4bce64e..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/* This file is part of Pazpar2.
-   Copyright (C) Index Data
-
-Pazpar2 is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-*/
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "sel_thread.h"
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-
-#include <assert.h>
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#endif
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#include <yaz/log.h>
-#include <yaz/nmem.h>
-#include <yaz/tcpip.h>
-
-#include "session.h"
-#include "connection.h"
-#include "host.h"
-
-/* Only use a threaded resolver on Unix that offers getaddrinfo.
-   gethostbyname is NOT reentrant.
- */
-#ifndef WIN32
-#define USE_THREADED_RESOLVER 1
-#endif
-
-struct work {
-    char *hostport;  /* hostport to be resolved in separate thread */
-    char *ipport;    /* result or NULL if it could not be resolved */
-    struct host *host; /* host that we're dealing with - mother thread */
-    iochan_man_t iochan_man; /* iochan manager */
-    int error;
-};
-
-static int log_level = YLOG_LOG;
-
-static void perform_getaddrinfo(struct work *w)
-{
-    struct addrinfo hints, *res;
-    char host[512], *cp;
-    char *port = "210";
-    int error;
-
-    hints.ai_flags = 0;
-    hints.ai_family = AF_UNSPEC;
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_protocol = 0;
-    hints.ai_addrlen        = 0;
-    hints.ai_addr           = NULL;
-    hints.ai_canonname      = NULL;
-    hints.ai_next           = NULL;
-
-    if (!strncmp(w->hostport, "http://", 7))
-    {
-        port = "80";
-        strncpy(host, w->hostport + 7, sizeof(host)-1);
-    }
-    else if (!strncmp(w->hostport, "https://", 8))
-    {
-        port = "443";
-        strncpy(host, w->hostport + 8, sizeof(host)-1);
-    }
-    else
-    {
-        strncpy(host, w->hostport, sizeof(host)-1);
-    }
-    host[sizeof(host)-1] = 0;
-    if ((cp = strrchr(host, ':')))
-    {
-        *cp = '\0';
-        port = cp + 1;
-    }
-    error = getaddrinfo(host, port, &hints, &res);
-    if (error)
-    {
-        yaz_log(YLOG_WARN, "Failed to resolve %s: %s",
-                w->hostport, gai_strerror(error));
-        w->error = error;
-    }
-    else
-    {
-        char n_host[512];
-        if (getnameinfo((struct sockaddr *) res->ai_addr, res->ai_addrlen,
-                        n_host, sizeof(n_host)-1,
-                        0, 0,
-                        NI_NUMERICHOST) == 0)
-        {
-            w->ipport = xmalloc(strlen(n_host) + (port ? strlen(port) : 0) + 2);
-            strcpy(w->ipport, n_host);
-            if (port)
-            {
-                strcat(w->ipport, ":");
-                strcat(w->ipport, port);
-            }
-            yaz_log(log_level, "Resolved %s -> %s", w->hostport, w->ipport);
-        }
-        else
-        {
-            yaz_log(YLOG_LOG|YLOG_ERRNO, "getnameinfo failed for %s",
-                    w->hostport);
-        }
-        freeaddrinfo(res);
-    }
-}
-
-static void work_handler(void *vp)
-{
-    struct work *w = vp;
-
-    int sec = 0;  /* >0 for debugging/testing purposes */
-    if (sec)
-    {
-        yaz_log(log_level, "waiting %d seconds", sec);
-#if HAVE_UNISTD_H
-        sleep(sec);
-#endif
-    }
-    perform_getaddrinfo(w);
-}
-
-#if USE_THREADED_RESOLVER
-void iochan_handler(struct iochan *i, int event)
-{
-    sel_thread_t p = iochan_getdata(i);
-
-    if (event & EVENT_INPUT)
-    {
-        struct work *w = sel_thread_result(p);
-        w->host->ipport = w->ipport;
-        w->host->error = w->error;
-        connect_resolver_host(w->host, w->iochan_man);
-        xfree(w);
-    }
-}
-
-static sel_thread_t resolver_thread = 0;
-
-static void getaddrinfo_start(iochan_man_t iochan_man)
-{
-    int fd;
-    sel_thread_t p = resolver_thread =
-        sel_thread_create(work_handler, 0 /* work_destroy */, &fd,
-                          3 /* no of resolver threads */);
-    if (!p)
-    {
-        yaz_log(YLOG_FATAL|YLOG_ERRNO, "sel_create_create failed");
-        exit(1);
-    }
-    else
-    {
-        IOCHAN chan = iochan_create(fd, iochan_handler, EVENT_INPUT,
-            "getaddrinfo_socket");
-        iochan_setdata(chan, p);
-        iochan_add(iochan_man, chan);
-    }
-    yaz_log(log_level, "resolver start");
-    resolver_thread = p;
-}
-#endif
-
-int host_getaddrinfo(struct host *host, iochan_man_t iochan_man)
-{
-    struct work *w = xmalloc(sizeof(*w));
-    int use_thread = 1; /* =0 to disable threading entirely */
-
-    w->hostport = host->tproxy ? host->tproxy : host->proxy;
-    w->ipport = 0;
-    w->host = host;
-    w->iochan_man = iochan_man;
-    w->error = 0;
-#if USE_THREADED_RESOLVER
-    if (use_thread)
-    {
-        if (resolver_thread == 0)
-            getaddrinfo_start(iochan_man);
-        assert(resolver_thread);
-        sel_thread_add(resolver_thread, w);
-        return 0;
-    }
-#endif
-    perform_getaddrinfo(w);
-    host->ipport = w->ipport;
-    host->error = w->error;
-    xfree(w);
-    if (!host->ipport)
-        return -1;
-    return 0;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/src/host.c b/src/host.c
deleted file mode 100644 (file)
index 5c7c15f..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/* This file is part of Pazpar2.
-   Copyright (C) Index Data
-
-Pazpar2 is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-*/
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <yaz/log.h>
-#include <yaz/nmem.h>
-#include <yaz/matchstr.h>
-
-#include "ppmutex.h"
-#include "session.h"
-#include "host.h"
-
-#include <sys/types.h>
-
-struct database_hosts {
-    struct host *hosts;
-    YAZ_MUTEX mutex;
-};
-
-// Create a new host structure for hostport
-static struct host *create_host(const char *proxy,
-                                const char *tproxy,
-                                iochan_man_t iochan_man)
-{
-    struct host *host;
-
-    host = xmalloc(sizeof(struct host));
-    host->proxy = 0;
-    host->tproxy = 0;
-    if (proxy && *proxy)
-        host->proxy = xstrdup(proxy);
-    else
-    {
-        assert(tproxy);
-        host->tproxy = xstrdup(tproxy);
-    }
-    host->connections = 0;
-    host->ipport = 0;
-    host->mutex = 0;
-    host->error = 0;
-
-    if (host_getaddrinfo(host, iochan_man))
-    {
-        xfree(host->ipport);
-        xfree(host->tproxy);
-        xfree(host->proxy);
-        xfree(host);
-        return 0;
-    }
-    pazpar2_mutex_create(&host->mutex, "host");
-
-    yaz_cond_create(&host->cond_ready);
-
-    return host;
-}
-
-struct host *find_host(database_hosts_t hosts, const char *url,
-                       const char *proxy, int port,
-                       iochan_man_t iochan_man)
-{
-    struct host *p;
-    char *tproxy = 0;
-
-    if (!proxy || !*proxy)
-    {
-        char *cp;
-
-        tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */
-        strcpy(tproxy, url);
-        if (!strncmp(tproxy, "http://", 7))
-            cp = tproxy + 7;
-        else if (!strncmp(tproxy, "https://", 8))
-            cp = tproxy + 8;
-        else
-            cp = tproxy;
-        for (; *cp; cp++)
-            if (strchr("/?#~", *cp))
-            {
-                *cp = '\0';
-                break;
-            }
-        if (!strchr(tproxy, ':'))
-            sprintf(cp, ":%d", port); /* no port given, add it */
-    }
-    yaz_mutex_enter(hosts->mutex);
-    for (p = hosts->hosts; p; p = p->next)
-    {
-        if (!yaz_strcmp_null(p->tproxy, tproxy) &&
-            !yaz_strcmp_null(p->proxy, proxy))
-        {
-            break;
-        }
-    }
-    if (!p)
-    {
-        p = create_host(proxy, tproxy, iochan_man);
-        if (p)
-        {
-            p->next = hosts->hosts;
-            hosts->hosts = p;
-        }
-    }
-    if (p && p->error) /* already resolved error */
-        p = 0;
-    yaz_mutex_leave(hosts->mutex);
-    xfree(tproxy);
-    return p;
-}
-
-database_hosts_t database_hosts_create(void)
-{
-    database_hosts_t p = xmalloc(sizeof(*p));
-    p->hosts = 0;
-    p->mutex = 0;
-    pazpar2_mutex_create(&p->mutex, "database");
-    return p;
-}
-
-void database_hosts_destroy(database_hosts_t *pp)
-{
-    if (*pp)
-    {
-        struct host *p = (*pp)->hosts;
-        while (p)
-        {
-            struct host *p_next = p->next;
-            yaz_mutex_destroy(&p->mutex);
-            yaz_cond_destroy(&p->cond_ready);
-            xfree(p->ipport);
-            xfree(p);
-            p = p_next;
-        }
-        yaz_mutex_destroy(&(*pp)->mutex);
-        xfree(*pp);
-    }
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/src/host.h b/src/host.h
deleted file mode 100644 (file)
index 7854a22..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/* This file is part of Pazpar2.
-   Copyright (C) Index Data
-
-Pazpar2 is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-*/
-
-#ifndef HOST_H
-#define HOST_H
-
-#include <yaz/mutex.h>
-
-typedef struct database_hosts *database_hosts_t;
-
-/** \brief Represents a host (irrespective of databases) */
-struct host {
-    char *tproxy;   // tproxy address (no Z39.50 UI)
-    char *proxy;    // logical proxy address
-    char *ipport;   // tproxy or proxy resolved
-    struct connection *connections; // All connections to this
-    int error;      // resolving error
-    struct host *next;
-    YAZ_MUTEX mutex;
-    YAZ_COND cond_ready;
-};
-
-database_hosts_t database_hosts_create(void);
-void database_hosts_destroy(database_hosts_t *);
-
-struct host *find_host(database_hosts_t hosts, const char *hostport,
-                      const char *proxy, int port, iochan_man_t iochan_man);
-
-int host_getaddrinfo(struct host *host, iochan_man_t iochan_man);
-
-#endif
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
index dbfd850..838d322 100644 (file)
@@ -56,7 +56,6 @@ struct conf_config
     WRBUF confdir;
     char *path;
     iochan_man_t iochan_man;
-    database_hosts_t database_hosts;
 };
 
 struct service_xslt
@@ -872,7 +871,6 @@ static struct conf_server *server_create(struct conf_config *config,
     server->charsets = 0;
     server->http_server = 0;
     server->iochan_man = 0;
-    server->database_hosts = config->database_hosts;
     server->settings_fname = 0;
 
     if (server_id)
@@ -1310,7 +1308,6 @@ struct conf_config *config_create(const char *fname)
     config->path = nmem_strdup(nmem, ".");
     config->no_threads = 0;
     config->iochan_man = 0;
-    config->database_hosts = database_hosts_create();
 
     config->confdir = wrbuf_alloc();
     if ((p = strrchr(fname,
@@ -1373,7 +1370,6 @@ void config_destroy(struct conf_config *config)
             struct conf_server *s_next = server->next;
             server_destroy(server);
             server = s_next;
-            database_hosts_destroy(&config->database_hosts);
         }
         wrbuf_destroy(config->confdir);
         nmem_destroy(config->nmem);
index 1343790..ab10abd 100644 (file)
@@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "charsets.h"
 #include "http.h"
 #include "database.h"
-#include "host.h"
 
 enum conf_metadata_type {
     Metadata_type_generic,    // Generic text field
@@ -154,7 +153,6 @@ struct conf_server
     struct conf_config *config;
     http_server_t http_server;
     iochan_man_t iochan_man;
-    database_hosts_t database_hosts;
 };
 
 struct conf_config *config_create(const char *fname);
index 5cba1d6..f760ca5 100644 (file)
@@ -508,7 +508,6 @@ static void select_targets_callback(struct session *se,
         l->next = se->clients_cached;
         se->clients_cached = l;
     }
-    /* set session always. If may be 0 if client is not active */
     client_set_session(cl, se);
 
     l = xmalloc(sizeof(*l));
@@ -557,6 +556,7 @@ static void session_remove_cached_clients(struct session *se)
         client_lock(l->client);
         client_set_session(l->client, 0);
         client_set_database(l->client, 0);
+        client_mark_dead(l->client);
         client_unlock(l->client);
         client_destroy(l->client);
         xfree(l);
index 64619da..7d98283 100644 (file)
@@ -62,13 +62,13 @@ http://localhost:9763/search.pz2?session=9&command=settings&pz:limitmap:author%5
 w http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author
 w http://localhost:9763/search.pz2?session=9&command=show&block=1
 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author&filter=pz%3Aid%3Dz3950.indexdata.com%2Fmarc
-http://localhost:9763/search.pz2?session=9&command=bytarget
+1 http://localhost:9763/search.pz2?session=9&command=bytarget
 http://localhost:9763/search.pz2?session=9&command=show
 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author&filter=pz%3Aid%3Dnone
 http://localhost:9763/search.pz2?session=9&command=bytarget
 http://localhost:9763/search.pz2?session=9&command=show
 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author
-http://localhost:9763/search.pz2?session=9&command=bytarget
+1 http://localhost:9763/search.pz2?session=9&command=bytarget
 http://localhost:9763/search.pz2?session=9&command=show
 http://localhost:9763/search.pz2?session=9&command=search&query=computer&limit=Mysubject%3DRailroads
 http://localhost:9763/search.pz2?session=9&command=show&block=1
index 0d77e59..df671c9 100644 (file)
@@ -17,7 +17,7 @@ test_limit_limitmap_settings_3.xml http://localhost:9763/search.pz2?session=1&co
 w http://localhost:9763/search.pz2?session=1&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author
 w http://localhost:9763/search.pz2?session=1&command=show&block=1
 http://localhost:9763/search.pz2?session=1&command=search&query=greece&limit=author%3Dadam\,+james%7Cother_author&filter=pz%3Aid%3DTarget-1
-http://localhost:9763/search.pz2?session=1&command=bytarget
+1 http://localhost:9763/search.pz2?session=1&command=bytarget
 http://localhost:9763/search.pz2?session=1&command=show
 test_limit_limitmap_settings_4.xml http://localhost:9763/search.pz2?session=1&command=settings
 http://localhost:9763/search.pz2?session=1&command=search&query=computer&limit=Mysubject%3DRailroads
index 4ec8213..ac0bb56 100644 (file)
@@ -179,8 +179,6 @@ LNKOPT= $(COMMON_LNK_OPTIONS) $(RELEASE_LNK_OPTIONS) $(LNK_LIBS)
 # Source and object modules
 
 PAZPAR2_OBJS = \
-   "$(OBJDIR)\getaddrinfo.obj" \
-   "$(OBJDIR)\host.obj" \
    "$(OBJDIR)\pazpar2.obj" \
    "$(OBJDIR)\pazpar2_config.obj" \
    "$(OBJDIR)\http.obj" \