dovecot: Forgot from imap/pop3-login clients hash -> linked list...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 4 02:14:34 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/db5f55daa002
changeset: 7104:db5f55daa002
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 04 02:14:29 2008 +0200
description:
Forgot from imap/pop3-login clients hash -> linked list commit.

diffstat:

3 files changed, 40 insertions(+), 6 deletions(-)
src/login-common/client-common.c |   31 +++++++++++++++++++++++++++++++
src/login-common/client-common.h |   12 ++++++++----
src/login-common/main.c          |    3 +--

diffs (97 lines):

diff -r 284dd5f2777d -r db5f55daa002 src/login-common/client-common.c
--- a/src/login-common/client-common.c	Fri Jan 04 00:36:32 2008 +0200
+++ b/src/login-common/client-common.c	Fri Jan 04 02:14:29 2008 +0200
@@ -9,6 +9,37 @@
 #include "client-common.h"
 
 #include <stdlib.h>
+
+struct client *clients = NULL;
+unsigned int clients_count = 0;
+
+void client_link(struct client *client)
+{
+	client->prev = NULL;
+	client->next = clients;
+	if (clients != NULL)
+		clients->prev = client;
+	clients = client;
+	clients_count++;
+}
+
+void client_unlink(struct client *client)
+{
+	i_assert(clients_count > 0);
+
+	clients_count--;
+	if (client->prev == NULL)
+		clients = client->next;
+	else
+		client->prev->next = client->next;
+	if (client->next != NULL)
+		client->next->prev = client->prev;
+}
+
+unsigned int clients_get_count(void)
+{
+	return clients_count;
+}
 
 static const struct var_expand_table *
 get_var_expand_table(struct client *client)
diff -r 284dd5f2777d -r db5f55daa002 src/login-common/client-common.h
--- a/src/login-common/client-common.h	Fri Jan 04 00:36:32 2008 +0200
+++ b/src/login-common/client-common.h	Fri Jan 04 02:14:29 2008 +0200
@@ -6,6 +6,8 @@
 #include "sasl-server.h"
 
 struct client {
+	struct client *prev, *next;
+
 	struct ip_addr local_ip;
 	struct ip_addr ip;
 	unsigned int local_port, remote_port;
@@ -30,17 +32,19 @@ struct client {
 	/* ... */
 };
 
+extern struct client *clients;
+
 struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
 			     const struct ip_addr *ip);
 
+void client_link(struct client *client);
+void client_unlink(struct client *client);
+unsigned int clients_get_count(void);
+
 void client_syslog(struct client *client, const char *msg);
 
-unsigned int clients_get_count(void);
 void clients_notify_auth_connected(void);
 void client_destroy_oldest(void);
 void clients_destroy_all(void);
 
-void clients_init(void);
-void clients_deinit(void);
-
 #endif
diff -r 284dd5f2777d -r db5f55daa002 src/login-common/main.c
--- a/src/login-common/main.c	Fri Jan 04 00:36:32 2008 +0200
+++ b/src/login-common/main.c	Fri Jan 04 02:14:29 2008 +0200
@@ -337,7 +337,6 @@ static void main_init(void)
 
 	auth_client = auth_client_new(login_process_uid);
         auth_client_set_connect_notify(auth_client, auth_connect_notify, NULL);
-	clients_init();
 
 	value = getenv("LISTEN_FDS");
 	listen_count = value == NULL ? 0 : atoi(value);
@@ -368,7 +367,7 @@ static void main_deinit(void)
 
 	if (auth_client != NULL)
 		auth_client_free(&auth_client);
-	clients_deinit();
+	clients_destroy_all();
 	master_deinit();
 
 	lib_signals_deinit();


More information about the dovecot-cvs mailing list