]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Improved handling of hosts with explicit IP address.
authorStephan Bosch <stephan@dovecot.fi>
Sun, 11 Sep 2016 15:46:10 +0000 (17:46 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Nov 2016 12:16:54 +0000 (14:16 +0200)
src/lib-http/http-client-host.c
src/lib-http/http-client-private.h

index 5c3c7d242c483d766dfa2f2940b1f03a1920deed..f23ade0ce1e4a3fff2923ef1c53bd84d142be2d3 100644 (file)
@@ -99,15 +99,13 @@ static void http_client_host_lookup
 {
        struct http_client *client = host->client;
        struct dns_lookup_settings dns_set;
-       struct ip_addr ip, *ips;
+       struct ip_addr *ips;
        unsigned int ips_count;
        int ret;
 
-       if (net_addr2ip(host->name, &ip) == 0) {
-               host->ips_count = 1;
-               host->ips = i_new(struct ip_addr, host->ips_count);
-               host->ips[0] = ip;
-       } else if (client->set.dns_client != NULL) {
+       i_assert(!host->explicit_ip);
+
+       if (client->set.dns_client != NULL) {
                http_client_host_debug(host,
                        "Performing asynchronous DNS lookup");
                (void)dns_client_lookup(client->set.dns_client, host->name,
@@ -177,6 +175,7 @@ struct http_client_host *http_client_host_get
 
        } else {
                const char *hostname = host_url->host_name;
+               struct ip_addr ip = host_url->host_ip;
 
                host = hash_table_lookup(client->hosts, hostname);
                if (host == NULL) {
@@ -185,10 +184,11 @@ struct http_client_host *http_client_host_get
                        hostname = host->name;
                        hash_table_insert(client->hosts, hostname, host);
 
-                       if (host_url->have_host_ip) {
+                       if (ip.family != 0 || net_addr2ip(host->name, &ip) == 0) {
                                host->ips_count = 1;
                                host->ips = i_new(struct ip_addr, host->ips_count);
-                               host->ips[0] = host_url->host_ip;
+                               host->ips[0] = ip;
+                               host->explicit_ip = TRUE;
                        }
 
                        http_client_host_debug(host, "Host created");
index 0090e4112765f36ec7b8a64523f7f3a0937349fb..f5fbe257776ce463021d954914438571f0494c91 100644 (file)
@@ -252,6 +252,7 @@ struct http_client_host {
        struct dns_lookup *dns_lookup;
 
        unsigned int unix_local:1;
+       unsigned int explicit_ip:1;
 };
 
 struct http_client {