]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Support DNS lookups via the new dns-client API.
authorTimo Sirainen <tss@iki.fi>
Tue, 22 Oct 2013 12:35:27 +0000 (15:35 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 22 Oct 2013 12:35:27 +0000 (15:35 +0300)
src/lib-http/http-client-host.c
src/lib-http/http-client.c
src/lib-http/http-client.h

index bc20ba78ff1eeabc19391eb74d9e416fa11e2362..2d8c18b65c875e2b1cf3664305168d6572a01585 100644 (file)
@@ -394,18 +394,26 @@ static void http_client_host_lookup
        unsigned int ips_count;
        int ret;
 
-       memset(&dns_set, 0, sizeof(dns_set));
-       dns_set.dns_client_socket_path =
-               client->set.dns_client_socket_path;
-       dns_set.timeout_msecs = HTTP_CLIENT_DNS_LOOKUP_TIMEOUT_MSECS;
-
-       if (host->ips_count == 0 &&
-           net_addr2ip(host->name, &ip) == 0) { // FIXME: remove this?
+       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 (dns_set.dns_client_socket_path == NULL) {
-               ret = net_gethostbyname(host->name,     &ips, &ips_count);
+       } else 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,
+                       http_client_host_dns_callback, host, &host->dns_lookup);
+       } else if (dns_set.dns_client_socket_path != NULL) {
+               http_client_host_debug(host,
+                       "Performing asynchronous DNS lookup");
+               memset(&dns_set, 0, sizeof(dns_set));
+               dns_set.dns_client_socket_path =
+                       client->set.dns_client_socket_path;
+               dns_set.timeout_msecs = HTTP_CLIENT_DNS_LOOKUP_TIMEOUT_MSECS;
+               (void)dns_lookup(host->name, &dns_set,
+                                http_client_host_dns_callback, host, &host->dns_lookup);
+       } else {
+               ret = net_gethostbyname(host->name, &ips, &ips_count);
                if (ret != 0) {
                        http_client_host_lookup_failure(host, net_gethosterror(ret));
                        return;
@@ -418,13 +426,6 @@ static void http_client_host_lookup
                host->ips = i_new(struct ip_addr, ips_count);
                memcpy(host->ips, ips, ips_count * sizeof(*ips));
        }
-
-       if (host->ips_count == 0) {
-               http_client_host_debug(host,
-                       "Performing asynchronous DNS lookup");
-               (void)dns_lookup(host->name, &dns_set,
-                                http_client_host_dns_callback, host, &host->dns_lookup);
-       }
 }
 
 struct http_client_host *http_client_host_get
index 09c56d96c52ecb92003f913f38835db3cac0601a..7760c0488211f269eaf0d03ab69a8bd1f923cb49 100644 (file)
@@ -75,6 +75,7 @@ struct http_client *http_client_init(const struct http_client_settings *set)
        pool = pool_alloconly_create("http client", 1024);
        client = p_new(pool, struct http_client, 1);
        client->pool = pool;
+       client->set.dns_client = set->dns_client;
        client->set.dns_client_socket_path =
                p_strdup_empty(pool, set->dns_client_socket_path);
        client->set.user_agent = p_strdup_empty(pool, set->user_agent);
index e21ec2b43bfdb73370abd955ec2a8dab4ad7cc5d..7d0e97041d56804bfce619c566b8501b47537a1e 100644 (file)
@@ -34,6 +34,11 @@ enum http_request_state {
 extern const char *http_request_state_names[];
 
 struct http_client_settings {
+       /* a) If dns_client is set, all lookups are done via it.
+          b) If dns_client_socket_path is set, each DNS lookup does its own
+          dns-lookup UNIX socket connection.
+          c) Otherwise, blocking gethostbyname() lookups are used. */
+       struct dns_client *dns_client;
        const char *dns_client_socket_path;
 
        const char *ssl_ca_dir, *ssl_ca_file, *ssl_ca;