dovecot-2.2: lib-storage: Added mailbox_list_fs_get_list()
dovecot at dovecot.org
dovecot at dovecot.org
Sun Mar 22 18:55:50 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/0bbdc413285e
changeset: 18384:0bbdc413285e
user: Timo Sirainen <tss at iki.fi>
date: Sun Mar 22 20:54:29 2015 +0200
description:
lib-storage: Added mailbox_list_fs_get_list()
Using mailbox_list_init_fs() now sets the mailbox_list pointer to root fs,
which allows the fs backends to lookup the list. Although this can't be done
in the init() function since the list is set only afterwards.
diffstat:
src/lib-storage/mailbox-list-private.h | 4 ---
src/lib-storage/mailbox-list.c | 38 ++++++++++++++++++++++++++++++++-
src/lib-storage/mailbox-list.h | 9 ++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diffs (106 lines):
diff -r 66689aaa85de -r 0bbdc413285e src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h Sun Mar 22 20:52:56 2015 +0200
+++ b/src/lib-storage/mailbox-list-private.h Sun Mar 22 20:54:29 2015 +0200
@@ -213,8 +213,4 @@
void mailbox_list_set_internal_error(struct mailbox_list *list);
bool mailbox_list_set_error_from_errno(struct mailbox_list *list);
-int mailbox_list_init_fs(struct mailbox_list *list, const char *driver,
- const char *args, const char *root_dir,
- struct fs **fs_r, const char **error_r);
-
#endif
diff -r 66689aaa85de -r 0bbdc413285e src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c Sun Mar 22 20:52:56 2015 +0200
+++ b/src/lib-storage/mailbox-list.c Sun Mar 22 20:54:29 2015 +0200
@@ -13,7 +13,7 @@
#include "unichar.h"
#include "settings-parser.h"
#include "iostream-ssl.h"
-#include "fs-api.h"
+#include "fs-api-private.h"
#include "imap-utf7.h"
#include "mailbox-log.h"
#include "mailbox-tree.h"
@@ -36,9 +36,19 @@
#define MAILBOX_MAX_HIERARCHY_LEVELS 16
#define MAILBOX_MAX_HIERARCHY_NAME_LENGTH 255
+#define MAILBOX_LIST_FS_CONTEXT(obj) \
+ MODULE_CONTEXT(obj, mailbox_list_fs_module)
+
+struct mailbox_list_fs_context {
+ union fs_api_module_context module_ctx;
+ struct mailbox_list *list;
+};
+
struct mailbox_list_module_register mailbox_list_module_register = { 0 };
static ARRAY(const struct mailbox_list *) mailbox_list_drivers;
+static MODULE_CONTEXT_DEFINE_INIT(mailbox_list_fs_module,
+ &fs_api_module_register);
void mailbox_lists_init(void)
{
@@ -1831,6 +1841,8 @@
{
struct fs_settings fs_set;
struct ssl_iostream_settings ssl_set;
+ struct mailbox_list_fs_context *ctx;
+ struct fs *parent_fs;
memset(&ssl_set, 0, sizeof(ssl_set));
memset(&fs_set, 0, sizeof(fs_set));
@@ -1838,5 +1850,27 @@
fs_set.root_path = root_dir;
fs_set.temp_file_prefix = mailbox_list_get_global_temp_prefix(list);
- return fs_init(driver, args, &fs_set, fs_r, error_r);
+ if (fs_init(driver, args, &fs_set, fs_r, error_r) < 0)
+ return -1;
+
+ /* add mailbox_list context to the parent fs, which allows
+ mailbox_list_fs_get_list() to work */
+ for (parent_fs = *fs_r; parent_fs->parent != NULL;
+ parent_fs = parent_fs->parent) ;
+
+ ctx = p_new(list->pool, struct mailbox_list_fs_context, 1);
+ ctx->list = list;
+ MODULE_CONTEXT_SET(parent_fs, mailbox_list_fs_module, ctx);
+ return 0;
}
+
+struct mailbox_list *mailbox_list_fs_get_list(struct fs *fs)
+{
+ struct mailbox_list_fs_context *ctx;
+
+ while (fs->parent != NULL)
+ fs = fs->parent;
+
+ ctx = MAILBOX_LIST_FS_CONTEXT(fs);
+ return ctx->list;
+}
diff -r 66689aaa85de -r 0bbdc413285e src/lib-storage/mailbox-list.h
--- a/src/lib-storage/mailbox-list.h Sun Mar 22 20:52:56 2015 +0200
+++ b/src/lib-storage/mailbox-list.h Sun Mar 22 20:54:29 2015 +0200
@@ -9,6 +9,7 @@
# define MAILBOX_LIST_NAME_MAX_LENGTH 4096
#endif
+struct fs;
struct mail_namespace;
struct mail_storage;
struct mailbox_list;
@@ -257,4 +258,12 @@
mailbox_list_get_last_error(struct mailbox_list *list,
enum mail_error *error_r);
+/* Create a fs based on the settings in the given mailbox_list. */
+int mailbox_list_init_fs(struct mailbox_list *list, const char *driver,
+ const char *args, const char *root_dir,
+ struct fs **fs_r, const char **error_r);
+/* Return mailbox_list that was used to create the fs via
+ mailbox_list_init_fs(). */
+struct mailbox_list *mailbox_list_fs_get_list(struct fs *fs);
+
#endif
More information about the dovecot-cvs
mailing list