dovecot-2.0: imap, pop3 no longer assume that there's only a sin...

dovecot at dovecot.org dovecot at dovecot.org
Sat May 23 02:24:32 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/d6d4ec8ac06d
changeset: 9355:d6d4ec8ac06d
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 22 19:24:26 2009 -0400
description:
imap, pop3 no longer assume that there's only a single client in process.

diffstat:

6 files changed, 35 insertions(+), 47 deletions(-)
src/imap/imap-client.c |   29 +++++++++++------------------
src/imap/imap-client.h |    7 ++++---
src/imap/main.c        |    4 +---
src/pop3/main.c        |    4 +---
src/pop3/pop3-client.c |   33 +++++++++++++++------------------
src/pop3/pop3-client.h |    5 +++--

diffs (231 lines):

diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/imap/imap-client.c
--- a/src/imap/imap-client.c	Fri May 22 19:16:45 2009 -0400
+++ b/src/imap/imap-client.c	Fri May 22 19:24:26 2009 -0400
@@ -21,7 +21,7 @@ extern struct mail_storage_callbacks mai
 extern struct mail_storage_callbacks mail_storage_callbacks;
 struct imap_module_register imap_module_register = { 0 };
 
-static struct client *my_client; /* we don't need more than one currently */
+static struct client *imap_clients = NULL;
 
 static void client_idle_timeout(struct client *client)
 {
@@ -77,9 +77,7 @@ struct client *client_create(int fd_in, 
 		client->anvil_sent = TRUE;
 	}
 
-	i_assert(my_client == NULL);
-	my_client = client;
-
+	DLLIST_PREPEND(&imap_clients, client);
 	if (hook_client_created != NULL)
 		hook_client_created(&client);
 	return client;
@@ -162,6 +160,8 @@ void client_destroy(struct client *clien
 		i_info("%s %s", reason, client_stats(client));
 	}
 
+	DLLIST_REMOVE(&imap_clients, client);
+
 	i_stream_close(client->input);
 	o_stream_close(client->output);
 
@@ -217,8 +217,6 @@ void client_destroy(struct client *clien
 	pool_unref(&client->command_pool);
 	i_free(client);
 
-	/* quit the program */
-	my_client = NULL;
 	master_service_client_connection_destroyed(master_service);
 }
 
@@ -941,15 +939,10 @@ void client_search_updates_free(struct c
 	array_clear(&client->search_updates);
 }
 
-void clients_init(void)
-{
-	my_client = NULL;
-}
-
-void clients_deinit(void)
-{
-	if (my_client != NULL) {
-		client_send_line(my_client, "* BYE Server shutting down.");
-		client_destroy(my_client, "Server shutting down");
-	}
-}
+void clients_destroy_all(void)
+{
+	while (imap_clients != NULL) {
+		client_send_line(imap_clients, "* BYE Server shutting down.");
+		client_destroy(imap_clients, "Server shutting down.");
+	}
+}
diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/imap/imap-client.h
--- a/src/imap/imap-client.h	Fri May 22 19:16:45 2009 -0400
+++ b/src/imap/imap-client.h	Fri May 22 19:24:26 2009 -0400
@@ -86,6 +86,8 @@ struct client_command_context {
 };
 
 struct client {
+	struct client *prev, *next;
+
 	int fd_in, fd_out;
 	struct io *io;
 	struct istream *input;
@@ -185,9 +187,6 @@ client_search_update_lookup(struct clien
 			    unsigned int *idx_r);
 void client_search_updates_free(struct client *client);
 
-void clients_init(void);
-void clients_deinit(void);
-
 void client_command_cancel(struct client_command_context **cmd);
 void client_command_free(struct client_command_context **cmd);
 
@@ -198,4 +197,6 @@ bool client_handle_input(struct client *
 bool client_handle_input(struct client *client);
 int client_output(struct client *client);
 
+void clients_destroy_all(void);
+
 #endif
diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/imap/main.c
--- a/src/imap/main.c	Fri May 22 19:16:45 2009 -0400
+++ b/src/imap/main.c	Fri May 22 19:24:26 2009 -0400
@@ -115,8 +115,6 @@ static void main_init(const struct imap_
 				log_error_callback, NULL);
 	}
 
-	clients_init();
-
 	client = client_create(0, 1, user, set);
         client->workarounds = parse_workarounds(set);
 
@@ -137,7 +135,7 @@ static void main_deinit(void)
 {
 	if (log_io != NULL)
 		io_remove(&log_io);
-	clients_deinit();
+	clients_destroy_all();
 }
 
 static void client_connected(const struct master_service_connection *conn)
diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/pop3/main.c
--- a/src/pop3/main.c	Fri May 22 19:16:45 2009 -0400
+++ b/src/pop3/main.c	Fri May 22 19:24:26 2009 -0400
@@ -42,8 +42,6 @@ static bool main_init(const struct pop3_
 				log_error_callback, NULL);
 	}
 
-	clients_init();
-
 	client = client_create(0, 1, user, set);
 	if (client == NULL)
 		return FALSE;
@@ -68,7 +66,7 @@ static void main_deinit(void)
 {
 	if (log_io != NULL)
 		io_remove(&log_io);
-	clients_deinit();
+	clients_destroy_all();
 }
 
 static void client_connected(const struct master_service_connection *conn)
diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c	Fri May 22 19:16:45 2009 -0400
+++ b/src/pop3/pop3-client.c	Fri May 22 19:24:26 2009 -0400
@@ -7,6 +7,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
+#include "llist.h"
 #include "hostpid.h"
 #include "var-expand.h"
 #include "master-service.h"
@@ -45,7 +46,7 @@ static struct client_workaround_list cli
 	{ NULL, 0 }
 };
 
-static struct client *my_client; /* we don't need more than one currently */
+static struct client *pop3_clients;
 
 static void client_input(struct client *client);
 static int client_output(struct client *client);
@@ -294,9 +295,7 @@ struct client *client_create(int fd_in, 
 		client->anvil_sent = TRUE;
 	}
 
-	i_assert(my_client == NULL);
-	my_client = client;
-
+	DLLIST_PREPEND(&pop3_clients, client);
 	if (hook_client_created != NULL)
 		hook_client_created(&client);
 	return client;
@@ -364,6 +363,8 @@ void client_destroy(struct client *clien
 		client->cmd(client);
 		i_assert(client->cmd == NULL);
 	}
+	DLLIST_REMOVE(&pop3_clients, client);
+
 	if (client->trans != NULL) {
 		/* client didn't QUIT, but we still want to save any changes
 		   done in this transaction. especially the cached virtual
@@ -402,8 +403,6 @@ void client_destroy(struct client *clien
 
 	i_free(client);
 
-	/* quit the program */
-	my_client = NULL;
 	master_service_client_connection_destroyed(master_service);
 }
 
@@ -586,15 +585,13 @@ static int client_output(struct client *
 	return client->cmd == NULL;
 }
 
-void clients_init(void)
-{
-	my_client = NULL;
-}
-
-void clients_deinit(void)
-{
-	if (my_client != NULL) {
-		client_send_line(my_client, "-ERR Server shutting down.");
-		client_destroy(my_client, "Server shutting down");
-	}
-}
+void clients_destroy_all(void)
+{
+	while (pop3_clients != NULL) {
+		if (pop3_clients->cmd == NULL) {
+			client_send_line(pop3_clients,
+				"-ERR Server shutting down.");
+		}
+		client_destroy(pop3_clients, "Server shutting down.");
+	}
+}
diff -r 8cf39c0b88d9 -r d6d4ec8ac06d src/pop3/pop3-client.h
--- a/src/pop3/pop3-client.h	Fri May 22 19:16:45 2009 -0400
+++ b/src/pop3/pop3-client.h	Fri May 22 19:24:26 2009 -0400
@@ -10,6 +10,8 @@ typedef void command_func_t(struct clien
 	(((client)->messages_count + (CHAR_BIT-1)) / CHAR_BIT)
 
 struct client {
+	struct client *prev, *next;
+
 	int fd_in, fd_out;
 	struct io *io;
 	struct istream *input;
@@ -76,7 +78,6 @@ bool client_handle_input(struct client *
 bool client_handle_input(struct client *client);
 bool client_update_mails(struct client *client);
 
-void clients_init(void);
-void clients_deinit(void);
+void clients_destroy_all(void);
 
 #endif


More information about the dovecot-cvs mailing list