[dovecot-cvs] dovecot/src/plugins/acl Makefile.am, 1.3, 1.4 acl-mailbox-list.c, 1.3, 1.4 acl-mailbox.c, 1.4, 1.5 acl-plugin.h, 1.3, 1.4 acl-storage.c, 1.4, 1.5

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


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

Modified Files:
	Makefile.am acl-mailbox-list.c acl-mailbox.c acl-plugin.h 
	acl-storage.c 
Log Message:
Better type safety to module_contexts arrays. Already fixed some bugs.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am	16 Nov 2006 00:17:14 -0000	1.3
+++ Makefile.am	29 Mar 2007 11:51:09 -0000	1.4
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
 	-I$(top_srcdir)/src/lib-mail \
+	-I$(top_srcdir)/src/lib-index \
 	-I$(top_srcdir)/src/lib-storage
 
 lib01_acl_plugin_la_LDFLAGS = -module -avoid-version

Index: acl-mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-mailbox-list.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- acl-mailbox-list.c	29 Mar 2007 07:59:11 -0000	1.3
+++ acl-mailbox-list.c	29 Mar 2007 11:51:09 -0000	1.4
@@ -7,11 +7,10 @@
 #include "acl-plugin.h"
 
 #define ACL_LIST_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					acl_mailbox_list_module_id))
+	MODULE_CONTEXT(obj, acl_mailbox_list_module)
 
 struct acl_mailbox_list {
-	struct mailbox_list_vfuncs super;
+	union mailbox_list_module_context module_ctx;
 
 	/* FIXME: this is wrong. multiple storages can use the same
 	   mailbox_list, so the whole ACL plugin probably needs redesigning.
@@ -19,9 +18,9 @@
 	struct mail_storage *storage;
 };
 
-unsigned int acl_mailbox_list_module_id = 0;
+static MODULE_CONTEXT_DEFINE_INIT(acl_mailbox_list_module,
+				  &mailbox_list_module_register);
 
-static bool acl_mailbox_list_module_id_set = FALSE;
 
 static struct mailbox_info *
 acl_mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx)
@@ -31,7 +30,7 @@
 	int ret;
 
 	for (;;) {
-		info = alist->super.iter_next(ctx);
+		info = alist->module_ctx.super.iter_next(ctx);
 		if (info == NULL)
 			return NULL;
 
@@ -69,7 +68,8 @@
 	if (ret < 0)
 		return -1;
 
-	if (alist->super.get_mailbox_name_status(list, name, status) < 0)
+	if (alist->module_ctx.super.get_mailbox_name_status(list, name,
+							    status) < 0)
 		return -1;
 	if (ret > 0)
 		return 0;
@@ -124,7 +124,7 @@
 		return -1;
 	}
 
-	return alist->super.delete_mailbox(list, name);
+	return alist->module_ctx.super.delete_mailbox(list, name);
 }
 
 static int
@@ -169,7 +169,7 @@
 		return -1;
 	}
 
-	return alist->super.rename_mailbox(list, oldname, newname);
+	return alist->module_ctx.super.rename_mailbox(list, oldname, newname);
 }
 
 void acl_mailbox_list_created(struct mailbox_list *list)
@@ -180,19 +180,13 @@
 		acl_next_hook_mailbox_list_created(list);
 
 	alist = p_new(list->pool, struct acl_mailbox_list, 1);
-	alist->super = list->v;
+	alist->module_ctx.super = list->v;
 	list->v.iter_next = acl_mailbox_list_iter_next;
 	list->v.get_mailbox_name_status = acl_get_mailbox_name_status;
 	list->v.delete_mailbox = acl_mailbox_list_delete;
 	list->v.rename_mailbox = acl_mailbox_list_rename;
 
-	if (!acl_mailbox_list_module_id_set) {
-		acl_mailbox_list_module_id = mailbox_list_module_id++;
-		acl_mailbox_list_module_id_set = TRUE;
-	}
-
-	array_idx_set(&list->module_contexts,
-		      acl_mailbox_list_module_id, &alist);
+	MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist);
 }
 
 void acl_mailbox_list_set_storage(struct mail_storage *storage)

Index: acl-mailbox.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-mailbox.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- acl-mailbox.c	29 Mar 2007 07:59:11 -0000	1.4
+++ acl-mailbox.c	29 Mar 2007 11:51:09 -0000	1.5
@@ -13,29 +13,26 @@
 
 #include <sys/stat.h>
 
-#define ACL_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					acl_storage_module_id))
+#define ACL_MAIL_CONTEXT(obj) \
+	MODULE_CONTEXT(obj, acl_mail_module)
 
 struct acl_mailbox {
-	struct mailbox_vfuncs super;
+	union mailbox_module_context module_ctx;
 	struct acl_object *aclobj;
 
 	unsigned int save_hack:1;
 };
 
-struct acl_mail {
-	struct mail_vfuncs super;
-};
-
 static int acl_mailbox_close(struct mailbox *box)
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(box);
 
 	acl_object_deinit(&abox->aclobj);
-	return abox->super.close(box);
+	return abox->module_ctx.super.close(box);
 }
 
+static MODULE_CONTEXT_DEFINE_INIT(acl_mail_module, &mail_module_register);
+
 static int mailbox_acl_right_lookup(struct mailbox *box, unsigned int right_idx)
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(box);
@@ -81,7 +78,7 @@
 		      enum mail_flags flags)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct acl_mail *amail = ACL_CONTEXT(mail);
+	union mail_module_context *amail = ACL_MAIL_CONTEXT(mail);
 	bool acl_flags, acl_flag_seen, acl_flag_del;
 	int ret;
 
@@ -122,7 +119,7 @@
 			 struct mail_keywords *keywords)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct acl_mail *amail = ACL_CONTEXT(mail);
+	union mail_module_context *amail = ACL_MAIL_CONTEXT(mail);
 	int ret;
 
 	ret = mailbox_acl_right_lookup(_mail->box, ACL_STORAGE_RIGHT_WRITE);
@@ -137,7 +134,7 @@
 static int acl_mail_expunge(struct mail *_mail)
 {
 	struct mail_private *mail = (struct mail_private *)_mail;
-	struct acl_mail *amail = ACL_CONTEXT(mail);
+	union mail_module_context *amail = ACL_MAIL_CONTEXT(mail);
 	int ret;
 
 	ret = mailbox_acl_right_lookup(_mail->box, ACL_STORAGE_RIGHT_EXPUNGE);
@@ -157,20 +154,21 @@
 	       struct mailbox_header_lookup_ctx *wanted_headers)
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(t->box);
-	struct acl_mail *amail;
+	union mail_module_context *amail;
 	struct mail *_mail;
 	struct mail_private *mail;
 
-	_mail = abox->super.mail_alloc(t, wanted_fields, wanted_headers);
+	_mail = abox->module_ctx.super.
+		mail_alloc(t, wanted_fields, wanted_headers);
 	mail = (struct mail_private *)_mail;
 
-	amail = p_new(mail->pool, struct acl_mail, 1);
+	amail = p_new(mail->pool, union mail_module_context, 1);
 	amail->super = mail->v;
 
 	mail->v.update_flags = acl_mail_update_flags;
 	mail->v.update_keywords = acl_mail_update_keywords;
 	mail->v.expunge = acl_mail_expunge;
-	array_idx_set(&mail->module_contexts, acl_storage_module_id, &amail);
+	MODULE_CONTEXT_SET_SELF(mail, acl_mail_module, amail);
 	return _mail;
 }
 
@@ -186,9 +184,10 @@
 	if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
 		return -1;
 
-	return abox->super.save_init(t, flags, keywords, received_date,
-				     timezone_offset, from_envelope,
-				     input, dest_mail, ctx_r);
+	return abox->module_ctx.super.
+		save_init(t, flags, keywords, received_date,
+			  timezone_offset, from_envelope,
+			  input, dest_mail, ctx_r);
 }
 
 static int
@@ -201,7 +200,7 @@
 	if (mailbox_acl_right_lookup(t->box, ACL_STORAGE_RIGHT_INSERT) <= 0)
 		return -1;
 
-	return abox->super.copy(t, mail, flags, keywords, dest_mail);
+	return abox->module_ctx.super.copy(t, mail, flags, keywords, dest_mail);
 }
 
 struct mailbox *acl_mailbox_open_box(struct mailbox *box)
@@ -210,7 +209,7 @@
 	struct acl_mailbox *abox;
 
 	abox = p_new(box->pool, struct acl_mailbox, 1);
-	abox->super = box->v;
+	abox->module_ctx.super = box->v;
 	abox->aclobj = acl_object_init_from_name(astorage->backend,
 						 mailbox_get_name(box));
 	
@@ -218,6 +217,6 @@
 	box->v.mail_alloc = acl_mail_alloc;
 	box->v.save_init = acl_save_init;
 	box->v.copy = acl_copy;
-	array_idx_set(&box->module_contexts, acl_storage_module_id, &abox);
+	MODULE_CONTEXT_SET(box, acl_storage_module, abox);
 	return box;
 }

Index: acl-plugin.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-plugin.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- acl-plugin.h	16 Nov 2006 00:17:15 -0000	1.3
+++ acl-plugin.h	29 Mar 2007 11:51:09 -0000	1.4
@@ -4,8 +4,7 @@
 #include "mail-storage-private.h"
 
 #define ACL_CONTEXT(obj) \
-	*((void **)array_idx_modifiable(&(obj)->module_contexts, \
-					acl_storage_module_id))
+	MODULE_CONTEXT(obj, acl_storage_module)
 
 enum acl_storage_rights {
 	ACL_STORAGE_RIGHT_LOOKUP,
@@ -23,7 +22,8 @@
 };
 
 struct acl_mail_storage {
-	struct mail_storage_vfuncs super;
+	union mail_storage_module_context module_ctx;
+
 	struct acl_backend *backend;
 	unsigned int acl_storage_right_idx[ACL_STORAGE_RIGHT_COUNT];
 };
@@ -31,7 +31,7 @@
 extern void (*acl_next_hook_mail_storage_created)
 	(struct mail_storage *storage);
 extern void (*acl_next_hook_mailbox_list_created)(struct mailbox_list *list);
-extern unsigned int acl_storage_module_id;
+extern MODULE_CONTEXT_DEFINE(acl_storage_module, &mail_storage_module_register);
 
 void acl_mail_storage_created(struct mail_storage *storage);
 void acl_mailbox_list_created(struct mailbox_list *list);

Index: acl-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/acl/acl-storage.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- acl-storage.c	29 Mar 2007 07:59:11 -0000	1.4
+++ acl-storage.c	29 Mar 2007 11:51:09 -0000	1.5
@@ -9,9 +9,8 @@
 
 #include <stdlib.h>
 
-unsigned int acl_storage_module_id = 0;
-
-static bool acl_storage_module_id_set = FALSE;
+struct acl_storage_module acl_storage_module =
+	MODULE_CONTEXT_INIT(&mail_storage_module_register);
 
 static const char *acl_storage_right_names[ACL_STORAGE_RIGHT_COUNT] = {
 	MAIL_ACL_LOOKUP,
@@ -66,7 +65,7 @@
 	struct acl_mail_storage *astorage = ACL_CONTEXT(storage);
 
 	acl_backend_deinit(&astorage->backend);
-	astorage->super.destroy(storage);
+	astorage->module_ctx.super.destroy(storage);
 }
 
 static struct mailbox *
@@ -101,7 +100,8 @@
 		return NULL;
 	}
 
-	box = astorage->super.mailbox_open(storage, name, input, flags);
+	box = astorage->module_ctx.super.
+		mailbox_open(storage, name, input, flags);
 	if (box == NULL)
 		return NULL;
 
@@ -131,7 +131,8 @@
 		return -1;
 	}
 
-	return astorage->super.mailbox_create(storage, name, directory);
+	return astorage->module_ctx.super.
+		mailbox_create(storage, name, directory);
 }
 
 void acl_mail_storage_created(struct mail_storage *storage)
@@ -168,7 +169,7 @@
 	}
 
 	astorage = p_new(storage->pool, struct acl_mail_storage, 1);
-	astorage->super = storage->v;
+	astorage->module_ctx.super = storage->v;
 	astorage->backend = backend;
 	storage->v.destroy = acl_storage_destroy;
 	storage->v.mailbox_open = acl_mailbox_open;
@@ -183,12 +184,6 @@
 						 acl_storage_right_names[i]);
 	}
 
-	if (!acl_storage_module_id_set) {
-		acl_storage_module_id = mail_storage_module_id++;
-		acl_storage_module_id_set = TRUE;
-	}
-
-	array_idx_set(&storage->module_contexts,
-		      acl_storage_module_id, &astorage);
+	MODULE_CONTEXT_SET(storage, acl_storage_module, astorage);
 }
 



More information about the dovecot-cvs mailing list