[dovecot-cvs] dovecot/src/plugins/mail-log mail-log-plugin.c, 1.8, 1.9

tss at dovecot.org tss at dovecot.org
Thu Mar 29 14:51:14 EEST 2007


Update of /var/lib/cvs/dovecot/src/plugins/mail-log
In directory talvi:/tmp/cvs-serv16171/plugins/mail-log

Modified Files:
	mail-log-plugin.c 
Log Message:
Better type safety to module_contexts arrays. Already fixed some bugs.



Index: mail-log-plugin.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/mail-log/mail-log-plugin.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mail-log-plugin.c	29 Mar 2007 07:59:14 -0000	1.8
+++ mail-log-plugin.c	29 Mar 2007 11:51:12 -0000	1.9
@@ -11,27 +11,11 @@
 #define MSGID_LOG_LEN 80
 
 #define MAIL_LOG_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					mail_log_storage_module_id))
+	MODULE_CONTEXT(obj, mail_log_storage_module)
+#define MAIL_LOG_MAIL_CONTEXT(obj) \
+	MODULE_CONTEXT(obj, mail_log_mail_module)
 #define MAIL_LOG_LIST_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					mail_log_mailbox_list_module_id))
-
-struct mail_log_mailbox_list {
-	struct mailbox_list_vfuncs super;
-};
-
-struct mail_log_mail_storage {
-	struct mail_storage_vfuncs super;
-};
-
-struct mail_log_mailbox {
-	struct mailbox_vfuncs super;
-};
-
-struct mail_log_mail {
-	struct mail_vfuncs super;
-};
+	MODULE_CONTEXT(obj, mail_log_mailbox_list_module)
 
 const char *mail_log_plugin_version = PACKAGE_VERSION;
 
@@ -40,11 +24,11 @@
 static void (*mail_log_next_hook_mailbox_list_created)
 	(struct mailbox_list *list);
 
-static unsigned int mail_log_storage_module_id = 0;
-static bool mail_log_storage_module_id_set = FALSE;
-
-static unsigned int mail_log_mailbox_list_module_id = 0;
-static bool mail_log_mailbox_list_module_id_set = FALSE;
+static MODULE_CONTEXT_DEFINE_INIT(mail_log_storage_module,
+				  &mail_storage_module_register);
+static MODULE_CONTEXT_DEFINE_INIT(mail_log_mail_module, &mail_module_register);
+static MODULE_CONTEXT_DEFINE_INIT(mail_log_mailbox_list_module,
+				  &mailbox_list_module_register);
 
 static void mail_log_action(struct mail *mail, const char *action)
 {
@@ -69,7 +53,7 @@
 static int mail_log_mail_expunge(struct mail *_mail)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct mail_log_mail *lmail = MAIL_LOG_CONTEXT(mail);
+	union mail_module_context *lmail = MAIL_LOG_MAIL_CONTEXT(mail);
 
 	if (lmail->super.expunge(_mail) < 0)
 		return -1;
@@ -83,7 +67,7 @@
 			   enum mail_flags flags)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct mail_log_mail *lmail = MAIL_LOG_CONTEXT(mail);
+	union mail_module_context *lmail = MAIL_LOG_MAIL_CONTEXT(mail);
 	enum mail_flags old_flags, new_flags;
 
 	old_flags = mail_get_flags(_mail);
@@ -115,21 +99,20 @@
 		    enum mail_fetch_field wanted_fields,
 		    struct mailbox_header_lookup_ctx *wanted_headers)
 {
-	struct mail_log_mailbox *lbox = MAIL_LOG_CONTEXT(t->box);
-	struct mail_log_mail *lmail;
+	union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
+	union mail_module_context *lmail;
 	struct mail *_mail;
 	struct mail_private *mail;
 
 	_mail = lbox->super.mail_alloc(t, wanted_fields, wanted_headers);
 	mail = (struct mail_private *)_mail;
 
-	lmail = p_new(mail->pool, struct mail_log_mail, 1);
+	lmail = p_new(mail->pool, union mail_module_context, 1);
 	lmail->super = mail->v;
 
 	mail->v.update_flags = mail_log_mail_update_flags;
 	mail->v.expunge = mail_log_mail_expunge;
-	array_idx_set(&mail->module_contexts,
-		      mail_log_storage_module_id, &lmail);
+	MODULE_CONTEXT_SET_SELF(mail, mail_log_mail_module, lmail);
 	return _mail;
 }
 
@@ -138,7 +121,7 @@
 	      enum mail_flags flags, struct mail_keywords *keywords,
 	      struct mail *dest_mail)
 {
-	struct mail_log_mailbox *lbox = MAIL_LOG_CONTEXT(t->box);
+	union mailbox_module_context *lbox = MAIL_LOG_CONTEXT(t->box);
 	const char *name;
 
 	if (lbox->super.copy(t, mail, flags, keywords, dest_mail) < 0)
@@ -155,27 +138,27 @@
 mail_log_mailbox_open(struct mail_storage *storage, const char *name,
 		      struct istream *input, enum mailbox_open_flags flags)
 {
-	struct mail_log_mail_storage *lstorage = MAIL_LOG_CONTEXT(storage);
+	union mail_storage_module_context *lstorage = MAIL_LOG_CONTEXT(storage);
 	struct mailbox *box;
-	struct mail_log_mailbox *lbox;
+	union mailbox_module_context *lbox;
 
 	box = lstorage->super.mailbox_open(storage, name, input, flags);
 	if (box == NULL)
 		return NULL;
 
-	lbox = p_new(box->pool, struct mail_log_mailbox, 1);
+	lbox = p_new(box->pool, union mailbox_module_context, 1);
 	lbox->super = box->v;
 
 	box->v.mail_alloc = mail_log_mail_alloc;
 	box->v.copy = mail_log_copy;
-	array_idx_set(&box->module_contexts, mail_log_storage_module_id, &lbox);
+	MODULE_CONTEXT_SET_SELF(box, mail_log_storage_module, lbox);
 	return box;
 }
 
 static int
 mail_log_mailbox_list_delete(struct mailbox_list *list, const char *name)
 {
-	struct mail_log_mailbox_list *llist = MAIL_LOG_LIST_CONTEXT(list);
+	union mailbox_list_module_context *llist = MAIL_LOG_LIST_CONTEXT(list);
 
 	if (llist->super.delete_mailbox(list, name) < 0)
 		return -1;
@@ -186,42 +169,30 @@
 
 static void mail_log_mail_storage_created(struct mail_storage *storage)
 {
-	struct mail_log_mail_storage *lstorage;
+	union mail_storage_module_context *lstorage;
 
 	if (mail_log_next_hook_mail_storage_created != NULL)
 		mail_log_next_hook_mail_storage_created(storage);
 
-	lstorage = p_new(storage->pool, struct mail_log_mail_storage, 1);
+	lstorage = p_new(storage->pool, union mail_storage_module_context, 1);
 	lstorage->super = storage->v;
 	storage->v.mailbox_open = mail_log_mailbox_open;
 
-	if (!mail_log_storage_module_id_set) {
-		mail_log_storage_module_id = mail_storage_module_id++;
-		mail_log_storage_module_id_set = TRUE;
-	}
-
-	array_idx_set(&storage->module_contexts,
-		      mail_log_storage_module_id, &lstorage);
+	MODULE_CONTEXT_SET_SELF(storage, mail_log_storage_module, lstorage);
 }
 
 static void mail_log_mailbox_list_created(struct mailbox_list *list)
 {
-	struct mail_log_mailbox_list *llist;
+	union mailbox_list_module_context *llist;
 
 	if (mail_log_next_hook_mailbox_list_created != NULL)
 		mail_log_next_hook_mailbox_list_created(list);
 
-	llist = p_new(list->pool, struct mail_log_mailbox_list, 1);
+	llist = p_new(list->pool, union mailbox_list_module_context, 1);
 	llist->super = list->v;
 	list->v.delete_mailbox = mail_log_mailbox_list_delete;
 
-	if (!mail_log_mailbox_list_module_id_set) {
-		mail_log_mailbox_list_module_id = mailbox_list_module_id++;
-		mail_log_mailbox_list_module_id_set = TRUE;
-	}
-
-	array_idx_set(&list->module_contexts,
-		      mail_log_mailbox_list_module_id, &llist);
+	MODULE_CONTEXT_SET_SELF(list, mail_log_mailbox_list_module, llist);
 }
 
 void mail_log_plugin_init(void)



More information about the dovecot-cvs mailing list