dovecot-2.2: pop3c: If base_dir isn't set, lookup pop3c_host wit...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 8 07:15:15 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/0953e6c5d931
changeset: 17762:0953e6c5d931
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 08 10:14:42 2014 +0300
description:
pop3c: If base_dir isn't set, lookup pop3c_host with regular blocking DNS lookup.

diffstat:

 src/lib-storage/index/pop3c/pop3c-client.c  |  45 ++++++++++++++++++++++------
 src/lib-storage/index/pop3c/pop3c-storage.c |   1 +
 2 files changed, 36 insertions(+), 10 deletions(-)

diffs (80 lines):

diff -r 58738244dc34 -r 0953e6c5d931 src/lib-storage/index/pop3c/pop3c-client.c
--- a/src/lib-storage/index/pop3c/pop3c-client.c	Wed Sep 03 07:29:25 2014 -0700
+++ b/src/lib-storage/index/pop3c/pop3c-client.c	Mon Sep 08 10:14:42 2014 +0300
@@ -67,6 +67,7 @@
 static void
 pop3c_dns_callback(const struct dns_lookup_result *result,
 		   struct pop3c_client *client);
+static void pop3c_client_connect_ip(struct pop3c_client *client);
 
 struct pop3c_client *
 pop3c_client_init(const struct pop3c_client_settings *set)
@@ -196,6 +197,39 @@
 	pop3c_client_disconnect(client);
 }
 
+static int pop3c_client_dns_lookup(struct pop3c_client *client)
+{
+	struct dns_lookup_settings dns_set;
+
+	i_assert(client->state == POP3C_CLIENT_STATE_CONNECTING);
+
+	if (client->set.dns_client_socket_path[0] == '\0') {
+		struct ip_addr *ips;
+		unsigned int ips_count;
+		int ret;
+
+		ret = net_gethostbyname(client->set.host, &ips, &ips_count);
+		if (ret != 0) {
+			i_error("pop3c(%s): net_gethostbyname() failed: %s",
+				client->set.host, net_gethosterror(ret));
+			return -1;
+		}
+		i_assert(ips_count > 0);
+		client->ip = ips[0];
+		pop3c_client_connect_ip(client);
+	} else {
+		memset(&dns_set, 0, sizeof(dns_set));
+		dns_set.dns_client_socket_path =
+			client->set.dns_client_socket_path;
+		dns_set.timeout_msecs = POP3C_DNS_LOOKUP_TIMEOUT_MSECS;
+		if (dns_lookup(client->set.host, &dns_set,
+			       pop3c_dns_callback, client,
+			       &client->dns_lookup) < 0)
+			return -1;
+	}
+	return 0;
+}
+
 void pop3c_client_run(struct pop3c_client *client)
 {
 	struct ioloop *ioloop, *prev_ioloop = current_ioloop;
@@ -210,16 +244,7 @@
 	if (client->ip.family == 0) {
 		/* we're connecting, start DNS lookup after our ioloop
 		   is created */
-		struct dns_lookup_settings dns_set;
-
-		i_assert(client->state == POP3C_CLIENT_STATE_CONNECTING);
-		memset(&dns_set, 0, sizeof(dns_set));
-		dns_set.dns_client_socket_path =
-			client->set.dns_client_socket_path;
-		dns_set.timeout_msecs = POP3C_DNS_LOOKUP_TIMEOUT_MSECS;
-		if (dns_lookup(client->set.host, &dns_set,
-			       pop3c_dns_callback, client,
-			       &client->dns_lookup) < 0)
+		if (pop3c_client_dns_lookup(client) < 0)
 			failed = TRUE;
 	} else if (client->to == NULL) {
 		client->to = timeout_add(POP3C_COMMAND_TIMEOUT_MSECS,
diff -r 58738244dc34 -r 0953e6c5d931 src/lib-storage/index/pop3c/pop3c-storage.c
--- a/src/lib-storage/index/pop3c/pop3c-storage.c	Wed Sep 03 07:29:25 2014 -0700
+++ b/src/lib-storage/index/pop3c/pop3c-storage.c	Mon Sep 08 10:14:42 2014 +0300
@@ -63,6 +63,7 @@
 	client_set.master_user = set->pop3c_master_user;
 	client_set.password = set->pop3c_password;
 	client_set.dns_client_socket_path =
+		storage->user->set->base_dir[0] == '\0' ? "" :
 		t_strconcat(storage->user->set->base_dir, "/",
 			    DNS_CLIENT_SOCKET_NAME, NULL);
 	str = t_str_new(128);


More information about the dovecot-cvs mailing list