dovecot-2.2: lib-http: Support DNS lookups via the new dns-clien...

dovecot at dovecot.org dovecot at dovecot.org
Tue Oct 22 15:36:15 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/864e74223d55
changeset: 16861:864e74223d55
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Oct 22 15:35:27 2013 +0300
description:
lib-http: Support DNS lookups via the new dns-client API.

diffstat:

 src/lib-http/http-client-host.c |  33 +++++++++++++++++----------------
 src/lib-http/http-client.c      |   1 +
 src/lib-http/http-client.h      |   5 +++++
 3 files changed, 23 insertions(+), 16 deletions(-)

diffs (79 lines):

diff -r a6abdf4b6222 -r 864e74223d55 src/lib-http/http-client-host.c
--- a/src/lib-http/http-client-host.c	Tue Oct 22 15:34:55 2013 +0300
+++ b/src/lib-http/http-client-host.c	Tue Oct 22 15:35:27 2013 +0300
@@ -394,18 +394,26 @@
 	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 @@
 		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
diff -r a6abdf4b6222 -r 864e74223d55 src/lib-http/http-client.c
--- a/src/lib-http/http-client.c	Tue Oct 22 15:34:55 2013 +0300
+++ b/src/lib-http/http-client.c	Tue Oct 22 15:35:27 2013 +0300
@@ -75,6 +75,7 @@
 	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);
diff -r a6abdf4b6222 -r 864e74223d55 src/lib-http/http-client.h
--- a/src/lib-http/http-client.h	Tue Oct 22 15:34:55 2013 +0300
+++ b/src/lib-http/http-client.h	Tue Oct 22 15:35:27 2013 +0300
@@ -34,6 +34,11 @@
 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;


More information about the dovecot-cvs mailing list