dovecot-2.2: lib-storage: Added mail_namespaces_init_add/finish(...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 15 21:22:13 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/98f937eed2e5
changeset: 17805:98f937eed2e5
user: Timo Sirainen <tss at iki.fi>
date: Tue Sep 16 00:21:52 2014 +0300
description:
lib-storage: Added mail_namespaces_init_add/finish() to manually initializing namespaces.
diffstat:
src/lib-storage/mail-namespace.c | 94 ++++++++++++++++++++++-----------------
src/lib-storage/mail-namespace.h | 8 +++
2 files changed, 61 insertions(+), 41 deletions(-)
diffs (155 lines):
diff -r 9c673534ae93 -r 98f937eed2e5 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c Tue Sep 16 00:21:13 2014 +0300
+++ b/src/lib-storage/mail-namespace.c Tue Sep 16 00:21:52 2014 +0300
@@ -81,13 +81,13 @@
return FALSE;
}
-static int
-namespace_add(struct mail_user *user,
- struct mail_namespace_settings *ns_set,
- struct mail_namespace_settings *unexpanded_ns_set,
- const struct mail_storage_settings *mail_set,
- struct mail_namespace **ns_p, const char **error_r)
+int mail_namespaces_init_add(struct mail_user *user,
+ struct mail_namespace_settings *ns_set,
+ struct mail_namespace_settings *unexpanded_ns_set,
+ struct mail_namespace **ns_p, const char **error_r)
{
+ const struct mail_storage_settings *mail_set =
+ mail_user_set_get_storage_set(user);
struct mail_namespace *ns;
const char *driver, *error;
@@ -314,6 +314,48 @@
return TRUE;
}
+int mail_namespaces_init_finish(struct mail_namespace *namespaces,
+ const char **error_r)
+{
+ struct mail_namespace *ns;
+ bool prefixless_found = FALSE;
+
+ for (ns = namespaces; ns != NULL; ns = ns->next) {
+ if (ns->prefix_len == 0)
+ prefixless_found = TRUE;
+ }
+ if (!prefixless_found) {
+ prefixless_ns_set = prefixless_ns_unexpanded_set;
+ /* a pretty evil way to expand the values */
+ prefixless_ns_set.prefix++;
+ prefixless_ns_set.location++;
+
+ if (mail_namespaces_init_add(namespaces->user,
+ &prefixless_ns_set,
+ &prefixless_ns_unexpanded_set,
+ &ns, error_r) < 0)
+ i_unreached();
+ ns->next = namespaces;
+ namespaces = ns;
+ }
+ if (!namespaces_check(namespaces, error_r)) {
+ *error_r = t_strconcat("namespace configuration error: ",
+ *error_r, NULL);
+ while (namespaces != NULL) {
+ ns = namespaces;
+ namespaces = ns->next;
+ mail_namespace_free(ns);
+ }
+ return -1;
+ }
+ mail_user_add_namespace(namespaces->user, &namespaces);
+
+ T_BEGIN {
+ hook_mail_namespaces_created(namespaces);
+ } T_END;
+ return 0;
+}
+
int mail_namespaces_init(struct mail_user *user, const char **error_r)
{
const struct mail_storage_settings *mail_set;
@@ -321,7 +363,6 @@
struct mail_namespace_settings *const *unexpanded_ns_set;
struct mail_namespace *namespaces, *ns, **ns_p;
unsigned int i, count, count2;
- bool prefixless_found = FALSE;
i_assert(user->initialized);
@@ -341,8 +382,9 @@
if (ns_set[i]->disabled)
continue;
- if (namespace_add(user, ns_set[i], unexpanded_ns_set[i],
- mail_set, ns_p, error_r) < 0) {
+ if (mail_namespaces_init_add(user, ns_set[i],
+ unexpanded_ns_set[i],
+ ns_p, error_r) < 0) {
if (!ns_set[i]->ignore_on_failure)
return -1;
if (mail_set->mail_debug) {
@@ -350,42 +392,12 @@
ns_set[i]->prefix, *error_r);
}
} else {
- if ((*ns_p)->prefix_len == 0)
- prefixless_found = TRUE;
ns_p = &(*ns_p)->next;
}
}
- if (namespaces != NULL) {
- if (!prefixless_found) {
- prefixless_ns_set = prefixless_ns_unexpanded_set;
- /* a pretty evil way to expand the values */
- prefixless_ns_set.prefix++;
- prefixless_ns_set.location++;
-
- if (namespace_add(user, &prefixless_ns_set,
- &prefixless_ns_unexpanded_set,
- mail_set, ns_p,
- error_r) < 0)
- i_unreached();
- }
- if (!namespaces_check(namespaces, error_r)) {
- *error_r = t_strconcat("namespace configuration error: ",
- *error_r, NULL);
- while (namespaces != NULL) {
- ns = namespaces;
- namespaces = ns->next;
- mail_namespace_free(ns);
- }
- return -1;
- }
- mail_user_add_namespace(user, &namespaces);
-
- T_BEGIN {
- hook_mail_namespaces_created(namespaces);
- } T_END;
- return 0;
- }
+ if (namespaces != NULL)
+ return mail_namespaces_init_finish(namespaces, error_r);
/* no namespaces defined, create a default one */
return mail_namespaces_init_location(user, NULL, error_r);
diff -r 9c673534ae93 -r 98f937eed2e5 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h Tue Sep 16 00:21:13 2014 +0300
+++ b/src/lib-storage/mail-namespace.h Tue Sep 16 00:21:52 2014 +0300
@@ -85,6 +85,14 @@
for user's namespaces. */
void mail_namespaces_deinit(struct mail_namespace **namespaces);
+/* Manually initialize namespaces one by one. */
+int mail_namespaces_init_add(struct mail_user *user,
+ struct mail_namespace_settings *ns_set,
+ struct mail_namespace_settings *unexpanded_ns_set,
+ struct mail_namespace **ns_p, const char **error_r);
+int mail_namespaces_init_finish(struct mail_namespace *namespaces,
+ const char **error_r);
+
void mail_namespace_ref(struct mail_namespace *ns);
void mail_namespace_unref(struct mail_namespace **ns);
More information about the dovecot-cvs
mailing list