dovecot-2.2: pop3: Added module contexts to struct client, and m...

dovecot at dovecot.org dovecot at dovecot.org
Mon Feb 27 10:32:14 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/771fab474b1c
changeset: 14220:771fab474b1c
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Feb 27 10:32:03 2012 +0200
description:
pop3: Added module contexts to struct client, and made client_destroy() a virtual method.

diffstat:

 src/pop3/main.c        |  11 ++++++++++-
 src/pop3/pop3-client.c |  22 ++++++++++++++++++++--
 src/pop3/pop3-client.h |  21 +++++++++++++++++++++
 src/pop3/pop3-common.h |   9 ++++++++-
 4 files changed, 59 insertions(+), 4 deletions(-)

diffs (169 lines):

diff -r e20af99c6d20 -r 771fab474b1c src/pop3/main.c
--- a/src/pop3/main.c	Mon Feb 27 10:30:57 2012 +0200
+++ b/src/pop3/main.c	Mon Feb 27 10:32:03 2012 +0200
@@ -29,7 +29,16 @@
 static struct mail_storage_service_ctx *storage_service;
 static struct master_login *master_login = NULL;
 
-void (*hook_client_created)(struct client **client) = NULL;
+pop3_client_created_func_t *hook_client_created = NULL;
+
+pop3_client_created_func_t *
+pop3_client_created_hook_set(pop3_client_created_func_t *new_hook)
+{
+	pop3_client_created_func_t *old_hook = hook_client_created;
+
+	hook_client_created = new_hook;
+	return old_hook;
+}
 
 void pop3_refresh_proctitle(void)
 {
diff -r e20af99c6d20 -r 771fab474b1c src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c	Mon Feb 27 10:30:57 2012 +0200
+++ b/src/pop3/pop3-client.c	Mon Feb 27 10:32:03 2012 +0200
@@ -36,6 +36,10 @@
    transaction. This allows the mailbox to become unlocked. */
 #define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
+extern struct pop3_client_vfuncs pop3_client_vfuncs;
+
+struct pop3_module_register pop3_module_register = { 0 };
+
 struct client *pop3_clients;
 unsigned int pop3_client_count;
 
@@ -281,13 +285,17 @@
         enum mailbox_flags flags;
 	const char *errmsg;
 	enum mail_error error;
+	pool_t pool;
 
 	/* always use nonblocking I/O */
 	net_set_nonblock(fd_in, TRUE);
 	net_set_nonblock(fd_out, TRUE);
 
-	client = i_new(struct client, 1);
+	pool = pool_alloconly_create("pop3 client", 256);
+	client = p_new(pool, struct client, 1);
+	client->pool = pool;
 	client->service_user = service_user;
+	client->v = pop3_client_vfuncs;
 	client->set = set;
 	client->fd_in = fd_in;
 	client->fd_out = fd_out;
@@ -295,6 +303,7 @@
 	client->output = o_stream_create_fd(fd_out, (size_t)-1, FALSE);
 	o_stream_set_flush_callback(client->output, client_output, client);
 
+	p_array_init(&client->module_contexts, client->pool, 5);
 	client->io = io_add(fd_in, IO_READ, client_input, client);
         client->last_input = ioloop_time;
 	client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS,
@@ -458,6 +467,11 @@
 
 void client_destroy(struct client *client, const char *reason)
 {
+	client->v.destroy(client, reason);
+}
+
+static void client_default_destroy(struct client *client, const char *reason)
+{
 	if (client->seen_change_count > 0)
 		client_update_mails(client);
 
@@ -512,7 +526,7 @@
 	if (client->fd_in != client->fd_out)
 		net_disconnect(client->fd_out);
 	mail_storage_service_user_free(&client->service_user);
-	i_free(client);
+	pool_unref(&client->pool);
 
 	master_service_client_connection_destroyed(master_service);
 	pop3_refresh_proctitle();
@@ -722,3 +736,7 @@
 		client_destroy(pop3_clients, "Server shutting down.");
 	}
 }
+
+struct pop3_client_vfuncs pop3_client_vfuncs = {
+	client_default_destroy
+};
diff -r e20af99c6d20 -r 771fab474b1c src/pop3/pop3-client.h
--- a/src/pop3/pop3-client.h	Mon Feb 27 10:30:57 2012 +0200
+++ b/src/pop3/pop3-client.h	Mon Feb 27 10:32:03 2012 +0200
@@ -9,6 +9,11 @@
 #define MSGS_BITMASK_SIZE(client) \
 	(((client)->messages_count + (CHAR_BIT-1)) / CHAR_BIT)
 
+struct pop3_client_vfuncs {
+	void (*destroy)(struct client *client, const char *reason);
+
+};
+
 /*
    pop3_msn = 1..n in the POP3 protocol
    msgnum = 0..n-1 = pop3_msn-1
@@ -18,6 +23,8 @@
 struct client {
 	struct client *prev, *next;
 
+	struct pop3_client_vfuncs v;
+
 	int fd_in, fd_out;
 	struct io *io;
 	struct istream *input;
@@ -27,6 +34,7 @@
 	command_func_t *cmd;
 	void *cmd_context;
 
+	pool_t pool;
 	struct mail_storage_service_user *service_user;
 	struct mail_user *user;
 	struct mail_namespace *inbox_ns;
@@ -65,6 +73,9 @@
 	const struct mail_storage_settings *mail_set;
 	enum uidl_keys uidl_keymask;
 
+	/* Module-specific contexts. */
+	ARRAY_DEFINE(module_contexts, union pop3_module_context *);
+
 	unsigned int disconnected:1;
 	unsigned int deleted:1;
 	unsigned int waiting_input:1;
@@ -72,6 +83,16 @@
 	unsigned int message_uidl_hashes_save:1;
 };
 
+struct pop3_module_register {
+	unsigned int id;
+};
+
+union pop3_module_context {
+	struct pop3_client_vfuncs super;
+	struct pop3_module_register *reg;
+};
+extern struct pop3_module_register pop3_module_register;
+
 extern struct client *pop3_clients;
 extern unsigned int pop3_client_count;
 
diff -r e20af99c6d20 -r 771fab474b1c src/pop3/pop3-common.h
--- a/src/pop3/pop3-common.h	Mon Feb 27 10:30:57 2012 +0200
+++ b/src/pop3/pop3-common.h	Mon Feb 27 10:32:03 2012 +0200
@@ -13,7 +13,14 @@
 #include "pop3-client.h"
 #include "pop3-settings.h"
 
-extern void (*hook_client_created)(struct client **client);
+typedef void pop3_client_created_func_t(struct client **client);
+
+extern pop3_client_created_func_t *hook_client_created;
+
+/* Sets the hook_client_created and returns the previous hook,
+   which the new_hook should call if it's non-NULL. */
+pop3_client_created_func_t *
+pop3_client_created_hook_set(pop3_client_created_func_t *new_hook);
 
 void pop3_refresh_proctitle(void);
 


More information about the dovecot-cvs mailing list