From: Adam Dickmeiss Date: Wed, 18 Dec 2013 13:36:17 +0000 (+0100) Subject: Allow unix sockets.. Not well tested yet! X-Git-Url: http://git.indexdata.com/?p=pazpar2-moved-to-github.git;a=commitdiff_plain;h=refs%2Fheads%2Funix_socket Allow unix sockets.. Not well tested yet! --- diff --git a/src/connection.c b/src/connection.c index ca778ab..9a56b16 100644 --- a/src/connection.c +++ b/src/connection.c @@ -486,8 +486,6 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man) } w = wrbuf_alloc(); - if (sru && *sru && !strstr(con->url, "://")) - wrbuf_puts(w, "http://"); if (strchr(con->url, '#')) { const char *cp = strchr(con->url, '#'); @@ -522,7 +520,7 @@ int client_prep_connection(struct client *cl, 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; + WRBUF url_w = wrbuf_alloc(); if (zproxy && zproxy[0] == '\0') zproxy = 0; @@ -530,20 +528,27 @@ int client_prep_connection(struct client *cl, if (!url || !*url) url = sdb->database->id; + if (sru && *sru && !strstr(url, "://")) + wrbuf_puts(url_w, "http://"); + wrbuf_puts(url_w, url); + host = find_host(client_get_session(cl)->service->server->database_hosts, - url, zproxy, default_port, iochan_man); + wrbuf_cstr(url_w), zproxy, iochan_man); yaz_log(YLOG_DEBUG, "client_prep_connection: target=%s url=%s", - client_get_id(cl), url); + client_get_id(cl), wrbuf_cstr(url_w)); if (!host) + { + wrbuf_destroy(url_w); return 0; - + } co = client_get_connection(cl); if (co) { assert(co->host); if (co->host == host && client_get_state(cl) == Client_Idle) { + wrbuf_destroy(url_w); return 2; } connection_release(co); @@ -576,7 +581,7 @@ int client_prep_connection(struct client *cl, for (co = host->connections; co; co = co->next) { if (connection_is_idle(co) && - !strcmp(url, co->url) && + !strcmp(wrbuf_cstr(url_w), 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), @@ -607,6 +612,7 @@ int client_prep_connection(struct client *cl, yaz_log(YLOG_LOG, "out of connections %s", client_get_id(cl)); client_set_state(cl, Client_Error); yaz_mutex_leave(host->mutex); + wrbuf_destroy(url_w); return 0; } } @@ -629,13 +635,13 @@ int client_prep_connection(struct client *cl, else { yaz_mutex_leave(host->mutex); - co = connection_create(cl, url, host, + co = connection_create(cl, wrbuf_cstr(url_w), host, operation_timeout, session_timeout, iochan_man); } assert(co->host); } - + wrbuf_destroy(url_w); if (co && co->link) return 1; else diff --git a/src/host.c b/src/host.c index 6978dd8..75a7d04 100644 --- a/src/host.c +++ b/src/host.c @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "ppmutex.h" #include "session.h" @@ -42,6 +43,7 @@ struct database_hosts { // Create a new host structure for hostport static struct host *create_host(const char *proxy, const char *tproxy, + CS_TYPE cs_type, iochan_man_t iochan_man) { struct host *host; @@ -60,13 +62,18 @@ static struct host *create_host(const char *proxy, host->ipport = 0; host->mutex = 0; - if (host_getaddrinfo(host, iochan_man)) + if (cs_type == unix_type) + host->ipport = xstrdup(host->tproxy); + else { - xfree(host->ipport); - xfree(host->tproxy); - xfree(host->proxy); - xfree(host); - return 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"); @@ -76,26 +83,46 @@ static struct host *create_host(const char *proxy, } struct host *find_host(database_hosts_t hosts, const char *url, - const char *proxy, int port, - iochan_man_t iochan_man) + const char *proxy, iochan_man_t iochan_man) { struct host *p; char *tproxy = 0; - - if (!proxy || !*proxy) + const char *host = 0; + CS_TYPE t; + enum oid_proto proto; + char *connect_host = 0; + if (!cs_parse_host(url, &host, &t, &proto, &connect_host)) + return 0; + else { - char *cp; - - tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */ - strcpy(tproxy, url); - for (cp = tproxy; *cp; cp++) - if (strchr("/?#~", *cp)) + if (t == unix_type) + tproxy = xstrdup(url); + else + { + if (proxy && *proxy) { - *cp = '\0'; - break; + /* plain proxy host already given, but we get CS_TYPE t */ + xfree(connect_host); } - if (!strchr(tproxy, ':')) - sprintf(cp, ":%d", port); /* no port given, add it */ + else + { + if (connect_host) + { + tproxy = connect_host; + } + else + { + char *cp; + tproxy = xstrdup(host); + for (cp = tproxy; *cp; cp++) + if (strchr("/?#~", *cp)) + { + *cp = '\0'; + break; + } + } + } + } } yaz_mutex_enter(hosts->mutex); for (p = hosts->hosts; p; p = p->next) @@ -108,7 +135,7 @@ struct host *find_host(database_hosts_t hosts, const char *url, } if (!p) { - p = create_host(proxy, tproxy, iochan_man); + p = create_host(proxy, tproxy, t, iochan_man); if (p) { p->next = hosts->hosts; diff --git a/src/host.h b/src/host.h index 439bbee..67e9d7a 100644 --- a/src/host.h +++ b/src/host.h @@ -39,7 +39,7 @@ 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); + const char *proxy, iochan_man_t iochan_man); int host_getaddrinfo(struct host *host, iochan_man_t iochan_man);