X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fhost.c;h=5c7c15f0aa96f5a45359a780c53a154c88338acd;hb=f7bf5626d6ae623cbcf86b8c4c9f9ed023a92499;hp=20979b6d661a27fa36f9b3810ba5d07b94ee5ea8;hpb=65c19cd0aac859eb0554be572828e121a2cd977c;p=pazpar2-moved-to-github.git diff --git a/src/host.c b/src/host.c index 20979b6..5c7c15f 100644 --- a/src/host.c +++ b/src/host.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2013 Index Data + 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 @@ -39,26 +39,6 @@ struct database_hosts { YAZ_MUTEX mutex; }; -#if YAZ_VERSIONL > 0x4023e -#define strcmp_null(x, y) yaz_strcmp_null(x, y) -#else -#define strcmp_null(x, y) local_strcmp_null(x, y) - -static int local_strcmp_null(const char *v1, const char *v2) -{ - if (v1) - { - if (v2) - return strcmp(v1, v2); - else - return 1; - } - else if (v2) - return -1; - return 0; -} -#endif - // Create a new host structure for hostport static struct host *create_host(const char *proxy, const char *tproxy, @@ -79,6 +59,7 @@ static struct host *create_host(const char *proxy, host->connections = 0; host->ipport = 0; host->mutex = 0; + host->error = 0; if (host_getaddrinfo(host, iochan_man)) { @@ -108,7 +89,13 @@ struct host *find_host(database_hosts_t hosts, const char *url, tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */ strcpy(tproxy, url); - for (cp = tproxy; *cp; cp++) + 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'; @@ -120,8 +107,8 @@ struct host *find_host(database_hosts_t hosts, const char *url, yaz_mutex_enter(hosts->mutex); for (p = hosts->hosts; p; p = p->next) { - if (!strcmp_null(p->tproxy, tproxy) && - !strcmp_null(p->proxy, proxy)) + if (!yaz_strcmp_null(p->tproxy, tproxy) && + !yaz_strcmp_null(p->proxy, proxy)) { break; } @@ -135,6 +122,8 @@ struct host *find_host(database_hosts_t hosts, const char *url, hosts->hosts = p; } } + if (p && p->error) /* already resolved error */ + p = 0; yaz_mutex_leave(hosts->mutex); xfree(tproxy); return p;