]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, pop3 no longer assume that there's only a single client in process.
authorTimo Sirainen <tss@iki.fi>
Fri, 22 May 2009 23:24:26 +0000 (19:24 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 22 May 2009 23:24:26 +0000 (19:24 -0400)
--HG--
branch : HEAD

src/imap/imap-client.c
src/imap/imap-client.h
src/imap/main.c
src/pop3/main.c
src/pop3/pop3-client.c
src/pop3/pop3-client.h

index 30a05ddb11b0c946528e8f7e0be2ea56c5d2b280..1b8e9de7c260acf3839516a02964184070f36523 100644 (file)
@@ -21,7 +21,7 @@
 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, int fd_out, struct mail_user *user,
                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 *client, const char *reason)
                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 *client, const char *reason)
        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 client *client)
        array_clear(&client->search_updates);
 }
 
-void clients_init(void)
-{
-       my_client = NULL;
-}
-
-void clients_deinit(void)
+void clients_destroy_all(void)
 {
-       if (my_client != NULL) {
-               client_send_line(my_client, "* BYE Server shutting down.");
-               client_destroy(my_client, "Server shutting down");
+       while (imap_clients != NULL) {
+               client_send_line(imap_clients, "* BYE Server shutting down.");
+               client_destroy(imap_clients, "Server shutting down.");
        }
 }
index 4a94b963e65730b4861214cb29e41692993a0932..d86f9e167fa2929f5427de1915911cb0dc55c80a 100644 (file)
@@ -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 client *client, const char *tag,
                            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 @@ void client_input(struct client *client);
 bool client_handle_input(struct client *client);
 int client_output(struct client *client);
 
+void clients_destroy_all(void);
+
 #endif
index e40c416421ff0fd51f6eea0adca237dd572b3ec4..1e7a038739f09d554a212bf3790ce2059af44426 100644 (file)
@@ -115,8 +115,6 @@ static void main_init(const struct imap_settings *set, struct mail_user *user,
                                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)
index a2bb49fb9608b12986ba1ec4be5bf002632c3010..c9d397dd69ed902b72d68d6f4f7057d2deea6543 100644 (file)
@@ -42,8 +42,6 @@ static bool main_init(const struct pop3_settings *set, struct mail_user *user)
                                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)
index bf23cab2057ab7060acb565d2bf0c180e7432331..524d828f413346cd9dbbb2dae25ec8f71555734c 100644 (file)
@@ -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 client_workaround_list[] = {
        { 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, int fd_out, struct mail_user *user,
                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 *client, const char *reason)
                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 *client, const char *reason)
 
        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 *client)
        return client->cmd == NULL;
 }
 
-void clients_init(void)
-{
-       my_client = NULL;
-}
-
-void clients_deinit(void)
+void clients_destroy_all(void)
 {
-       if (my_client != NULL) {
-               client_send_line(my_client, "-ERR Server shutting down.");
-               client_destroy(my_client, "Server shutting down");
+       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.");
        }
 }
index 909d4575dc29c9da820a7c9dd26ee8d1618490a2..8bc503d99efd6273898d303d15e5d2a157da1534 100644 (file)
@@ -10,6 +10,8 @@ typedef void command_func_t(struct client *client);
        (((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 @@ void client_send_storage_error(struct client *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