dovecot-2.0: lib-storage: Added mailbox_list_get_root_path() to ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 4 18:51:26 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/e747257bc382
changeset: 11475:e747257bc382
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 04 16:51:16 2010 +0100
description:
lib-storage: Added mailbox_list_get_root_path() to reduce code duplication.

diffstat:

 src/lib-storage/list/mailbox-list-fs.c      |  24 ++----------------------
 src/lib-storage/list/mailbox-list-maildir.c |  16 +---------------
 src/lib-storage/mailbox-list-private.h      |   3 +++
 src/lib-storage/mailbox-list.c              |  33 +++++++++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 37 deletions(-)

diffs (119 lines):

diff -r e056d42c9711 -r e747257bc382 src/lib-storage/list/mailbox-list-fs.c
--- a/src/lib-storage/list/mailbox-list-fs.c	Fri Jun 04 16:36:24 2010 +0100
+++ b/src/lib-storage/list/mailbox-list-fs.c	Fri Jun 04 16:51:16 2010 +0100
@@ -140,31 +140,11 @@
 		 enum mailbox_list_path_type type)
 {
 	const struct mailbox_list_settings *set = &_list->set;
-	const char *path, *root_dir;
+	const char *root_dir;
 
 	if (name == NULL) {
 		/* return root directories */
-		switch (type) {
-		case MAILBOX_LIST_PATH_TYPE_DIR:
-			return set->root_dir;
-		case MAILBOX_LIST_PATH_TYPE_ALT_DIR:
-			return _list->set.alt_dir;
-		case MAILBOX_LIST_PATH_TYPE_MAILBOX:
-			path = t_strconcat(set->root_dir, "/",
-					   set->mailbox_dir_name, NULL);
-			return t_strndup(path, strlen(path)-1);
-		case MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX:
-			path = t_strconcat(set->alt_dir, "/",
-					   set->mailbox_dir_name, NULL);
-			return t_strndup(path, strlen(path)-1);
-		case MAILBOX_LIST_PATH_TYPE_CONTROL:
-			return set->control_dir != NULL ?
-				set->control_dir : set->root_dir;
-		case MAILBOX_LIST_PATH_TYPE_INDEX:
-			return set->index_dir != NULL ?
-				set->index_dir : set->root_dir;
-		}
-		i_unreached();
+		return mailbox_list_get_root_path(set, type);
 	}
 
 	i_assert(mailbox_list_is_valid_pattern(_list, name));
diff -r e056d42c9711 -r e747257bc382 src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c	Fri Jun 04 16:36:24 2010 +0100
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Fri Jun 04 16:51:16 2010 +0100
@@ -176,21 +176,7 @@
 
 	if (name == NULL) {
 		/* return root directories */
-		switch (type) {
-		case MAILBOX_LIST_PATH_TYPE_DIR:
-		case MAILBOX_LIST_PATH_TYPE_MAILBOX:
-			return _list->set.root_dir;
-		case MAILBOX_LIST_PATH_TYPE_ALT_DIR:
-		case MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX:
-			return _list->set.alt_dir;
-		case MAILBOX_LIST_PATH_TYPE_CONTROL:
-			return _list->set.control_dir != NULL ?
-				_list->set.control_dir : _list->set.root_dir;
-		case MAILBOX_LIST_PATH_TYPE_INDEX:
-			return _list->set.index_dir != NULL ?
-				_list->set.index_dir : _list->set.root_dir;
-		}
-		i_unreached();
+		return mailbox_list_get_root_path(&_list->set, type);
 	}
 
 	if (_list->mail_set->mail_full_filesystem_access &&
diff -r e056d42c9711 -r e747257bc382 src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Fri Jun 04 16:36:24 2010 +0100
+++ b/src/lib-storage/mailbox-list-private.h	Fri Jun 04 16:51:16 2010 +0100
@@ -140,6 +140,9 @@
 int mailbox_list_settings_parse(struct mail_user *user, const char *data,
 				struct mailbox_list_settings *set_r,
 				const char **error_r);
+const char *
+mailbox_list_get_root_path(const struct mailbox_list_settings *set,
+			   enum mailbox_list_path_type type);
 
 int mailbox_list_delete_index_control(struct mailbox_list *list,
 				      const char *name);
diff -r e056d42c9711 -r e747257bc382 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Fri Jun 04 16:36:24 2010 +0100
+++ b/src/lib-storage/mailbox-list.c	Fri Jun 04 16:51:16 2010 +0100
@@ -539,6 +539,39 @@
 	return list->v.get_path(list, name, type);
 }
 
+const char *
+mailbox_list_get_root_path(const struct mailbox_list_settings *set,
+			   enum mailbox_list_path_type type)
+{
+	const char *path;
+
+	switch (type) {
+	case MAILBOX_LIST_PATH_TYPE_DIR:
+		return set->root_dir;
+	case MAILBOX_LIST_PATH_TYPE_ALT_DIR:
+		return set->alt_dir;
+	case MAILBOX_LIST_PATH_TYPE_MAILBOX:
+		if (*set->mailbox_dir_name == '\0')
+			return set->root_dir;
+		path = t_strconcat(set->root_dir, "/",
+				   set->mailbox_dir_name, NULL);
+		return t_strndup(path, strlen(path)-1);
+	case MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX:
+		if (*set->mailbox_dir_name == '\0')
+			return set->root_dir;
+		path = t_strconcat(set->alt_dir, "/",
+				   set->mailbox_dir_name, NULL);
+		return t_strndup(path, strlen(path)-1);
+	case MAILBOX_LIST_PATH_TYPE_CONTROL:
+		return set->control_dir != NULL ?
+			set->control_dir : set->root_dir;
+	case MAILBOX_LIST_PATH_TYPE_INDEX:
+		return set->index_dir != NULL ?
+			set->index_dir : set->root_dir;
+	}
+	i_unreached();
+}
+
 const char *mailbox_list_get_temp_prefix(struct mailbox_list *list)
 {
 	return list->v.get_temp_prefix(list, FALSE);


More information about the dovecot-cvs mailing list