[dovecot-cvs] dovecot/src/lib-storage mail-storage-private.h, 1.43, 1.44 mail-storage.c, 1.71, 1.72 mailbox-list-private.h, 1.3, 1.4 mailbox-list.c, 1.8, 1.9
tss at dovecot.org
tss at dovecot.org
Thu Mar 29 14:51:25 EEST 2007
Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv16171/lib-storage
Modified Files:
mail-storage-private.h mail-storage.c mailbox-list-private.h
mailbox-list.c
Log Message:
Better type safety to module_contexts arrays. Already fixed some bugs.
Index: mail-storage-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage-private.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- mail-storage-private.h 29 Mar 2007 07:59:15 -0000 1.43
+++ mail-storage-private.h 29 Mar 2007 11:51:21 -0000 1.44
@@ -1,14 +1,24 @@
#ifndef __MAIL_STORAGE_PRIVATE_H
#define __MAIL_STORAGE_PRIVATE_H
+#include "module-context.h"
#include "file-lock.h"
#include "mail-storage.h"
+#include "mail-index-private.h"
/* Called after mail storage has been created */
extern void (*hook_mail_storage_created)(struct mail_storage *storage);
/* Called after mailbox has been opened */
extern void (*hook_mailbox_opened)(struct mailbox *box);
+struct mail_storage_module_register {
+ unsigned int id;
+};
+
+struct mail_module_register {
+ unsigned int id;
+};
+
struct mail_storage_vfuncs {
void (*class_init)(void);
void (*class_deinit)(void);
@@ -38,6 +48,11 @@
bool *temporary_error_r);
};
+union mail_storage_module_context {
+ struct mail_storage_vfuncs super;
+ struct mail_storage_module_register *reg;
+};
+
struct mail_storage {
const char *name;
bool mailbox_is_file;
@@ -56,7 +71,7 @@
void *callback_context;
/* Module-specific contexts. See mail_storage_module_id. */
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
/* IMAP: Give a BAD reply instead of NO */
unsigned int syntax_error:1;
@@ -141,6 +156,11 @@
bool (*is_inconsistent)(struct mailbox *box);
};
+union mailbox_module_context {
+ struct mailbox_vfuncs super;
+ struct mail_storage_module_register *reg;
+};
+
struct mailbox {
char *name;
struct mail_storage *storage;
@@ -152,7 +172,7 @@
unsigned int transaction_count;
/* Module-specific contexts. See mail_storage_module_id. */
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
/* When FAST open flag is used, the mailbox isn't actually opened until
it's synced for the first time. */
@@ -194,12 +214,17 @@
int (*expunge)(struct mail *mail);
};
+union mail_module_context {
+ struct mail_vfuncs super;
+ struct mail_module_register *reg;
+};
+
struct mail_private {
struct mail mail;
struct mail_vfuncs v;
pool_t pool;
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts, union mail_module_context *);
};
struct mailbox_list_context {
@@ -208,9 +233,18 @@
bool failed;
};
+union mailbox_transaction_module_context {
+ struct mail_storage_module_register *reg;
+};
+
struct mailbox_transaction_context {
struct mailbox *box;
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts,
+ union mailbox_transaction_module_context *);
+};
+
+union mail_search_module_context {
+ struct mail_storage_module_register *reg;
};
struct mail_search_context {
@@ -221,7 +255,7 @@
struct mail_search_sort_program *sort_program;
uint32_t seq;
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
};
struct mail_save_context {
@@ -239,25 +273,15 @@
/* Modules should use do "my_id = mail_storage_module_id++" and
use objects' module_contexts[id] for their own purposes. */
-extern unsigned int mail_storage_module_id;
+extern struct mail_storage_module_register mail_storage_module_register;
/* Storage's module_id for mail_index. */
-extern unsigned int mail_storage_mail_index_module_id;
-
-#define MAIL_STORAGE_INDEX(index) \
- *((void **)array_idx_modifiable( \
- &(index)->mail_index_module_contexts, \
- mail_storage_mail_index_module_id))
-
-#define MAIL_STORAGE_VIEW(view) \
- *((void **)array_idx_modifiable( \
- &(view)->mail_index_view_module_contexts, \
- mail_storage_mail_index_module_id))
+extern struct mail_module_register mail_module_register;
-#define MAIL_STORAGE_TRANSACTION(trans) \
- *((void **)array_idx_modifiable( \
- &(trans)->mail_index_transaction_module_contexts, \
- mail_storage_mail_index_module_id))
+#define MAIL_STORAGE_CONTEXT(obj) \
+ MODULE_CONTEXT(obj, mail_storage_mail_index_module)
+extern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
+ &mail_index_module_register);
/* Set error message in storage. Critical errors are logged with i_error(),
but user sees only "internal error" message. */
Index: mail-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- mail-storage.c 29 Mar 2007 07:59:15 -0000 1.71
+++ mail-storage.c 29 Mar 2007 11:51:22 -0000 1.72
@@ -17,8 +17,11 @@
"Internal error occurred. Refer to server log for more information."
#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
-unsigned int mail_storage_module_id = 0;
-unsigned int mail_storage_mail_index_module_id = 0;
+struct mail_storage_module_register mail_storage_module_register = { 0 };
+struct mail_module_register mail_module_register = { 0 };
+
+struct mail_storage_mail_index_module mail_storage_mail_index_module =
+ MODULE_CONTEXT_INIT(&mail_index_module_register);
void (*hook_mail_storage_created)(struct mail_storage *storage);
void (*hook_mailbox_opened)(struct mailbox *box) = NULL;
@@ -28,8 +31,6 @@
void mail_storage_init(void)
{
i_array_init(&storages, 8);
-
- mail_storage_mail_index_module_id = mail_index_module_id++;
}
void mail_storage_deinit(void)
Index: mailbox-list-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list-private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mailbox-list-private.h 29 Mar 2007 07:59:15 -0000 1.3
+++ mailbox-list-private.h 29 Mar 2007 11:51:22 -0000 1.4
@@ -51,6 +51,15 @@
const char *newname);
};
+struct mailbox_list_module_register {
+ unsigned int id;
+};
+
+union mailbox_list_module_context {
+ struct mailbox_list_vfuncs super;
+ struct mailbox_list_module_register *reg;
+};
+
struct mailbox_list {
const char *name;
char hierarchy_sep;
@@ -66,7 +75,7 @@
char *error;
bool temporary_error;
- ARRAY_DEFINE(module_contexts, void);
+ ARRAY_DEFINE(module_contexts, union mailbox_list_module_context *);
};
struct mailbox_list_iterate_context {
@@ -77,7 +86,7 @@
/* Modules should use do "my_id = mailbox_list_module_id++" and
use objects' module_contexts[id] for their own purposes. */
-extern unsigned int mailbox_list_module_id;
+extern struct mailbox_list_module_register mailbox_list_module_register;
extern void (*hook_mailbox_list_created)(struct mailbox_list *list);
Index: mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mailbox-list.c 29 Mar 2007 07:59:15 -0000 1.8
+++ mailbox-list.c 29 Mar 2007 11:51:22 -0000 1.9
@@ -23,7 +23,7 @@
"Internal error occurred. Refer to server log for more information."
#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
-unsigned int mailbox_list_module_id = 0;
+struct mailbox_list_module_register mailbox_list_module_register = { 0 };
void (*hook_mailbox_list_created)(struct mailbox_list *list);
More information about the dovecot-cvs
mailing list