[dovecot-cvs] dovecot/src/lib-storage mail-storage-private.h, 1.46, 1.47 mail-storage.c, 1.73, 1.74 mail-storage.h, 1.127, 1.128

tss at dovecot.org tss at dovecot.org
Fri Mar 30 16:40:15 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv19658/lib-storage

Modified Files:
	mail-storage-private.h mail-storage.c mail-storage.h 
Log Message:
Removed mail_storage_create_with_data(). mail_storage_create() with
driver=NULL behaves the same way. Removed parameters from
mail_storage.create(), they're now put into the storage structure before
calling create().



Index: mail-storage-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage-private.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- mail-storage-private.h	30 Mar 2007 12:58:50 -0000	1.46
+++ mail-storage-private.h	30 Mar 2007 13:40:12 -0000	1.47
@@ -24,10 +24,7 @@
 	void (*class_deinit)(void);
 
 	struct mail_storage *(*alloc)(void);
-	int (*create)(struct mail_storage *storage,
-		      const char *data, const char *user,
-		      enum mail_storage_flags flags,
-		      enum file_lock_method lock_method);
+	int (*create)(struct mail_storage *storage, const char *data);
 	void (*destroy)(struct mail_storage *storage);
 
 	bool (*autodetect)(const char *data, enum mail_storage_flags flags);

Index: mail-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- mail-storage.c	30 Mar 2007 12:58:50 -0000	1.73
+++ mail-storage.c	30 Mar 2007 13:40:12 -0000	1.74
@@ -114,107 +114,95 @@
 	return NULL;
 }
 
-struct mail_storage *
-mail_storage_create(const char *driver, const char *data, const char *user,
-		    enum mail_storage_flags flags,
-		    enum file_lock_method lock_method)
-{
-	struct mail_storage *storage_class, *storage;
-
-	storage_class = mail_storage_find(driver);
-	if (storage_class == NULL)
-		return NULL;
-
-	storage = storage_class->v.alloc();
-	if (storage_class->v.create(storage, data, user,
-				    flags, lock_method) < 0) {
-		pool_unref(storage->pool);
-		return NULL;
-	}
-
-	if (hook_mail_storage_created != NULL)
-		hook_mail_storage_created(storage);
-	return storage;
-}
-
 static struct mail_storage *
-mail_storage_create_default(const char *user, enum mail_storage_flags flags,
-			    enum file_lock_method lock_method)
+mail_storage_autodetect(const char *data, enum mail_storage_flags flags)
 {
 	struct mail_storage *const *classes;
-	struct mail_storage *storage;
 	unsigned int i, count;
 
 	classes = array_get(&storages, &count);
 	for (i = 0; i < count; i++) {
-		storage = classes[i]->v.alloc();
-		if (classes[i]->v.create(storage, NULL, user,
-					 flags, lock_method) < 0)
-			pool_unref(storage->pool);
-		else {
-			if (hook_mail_storage_created != NULL)
-				hook_mail_storage_created(storage);
-			return storage;
-		}
+		if (classes[i]->v.autodetect(data, flags))
+			return classes[i];
 	}
 	return NULL;
 }
 
-static struct mail_storage *
-mail_storage_autodetect(const char *data, enum mail_storage_flags flags)
+static void
+mail_storage_set_autodetection(const char **data, const char **driver,
+			       enum mail_storage_flags *flags)
 {
-	struct mail_storage *const *classes;
-	unsigned int i, count;
+	const char *p;
 
-	classes = array_get(&storages, &count);
-	for (i = 0; i < count; i++) {
-		if (classes[i]->v.autodetect(data, flags))
-			return classes[i];
+	/* check if data is in driver:data format (eg. mbox:~/mail) */
+	p = *data;
+	while (i_isalnum(*p)) p++;
+
+	if (*p == ':' && p != *data) {
+		/* no autodetection if the storage format is given. */
+		*flags |= MAIL_STORAGE_FLAG_NO_AUTODETECTION;
+
+		*driver = t_strdup_until(*data, p);
+		*data = p + 1;
 	}
-	return NULL;
 }
 
 struct mail_storage *
-mail_storage_create_with_data(const char *data, const char *user,
-			      enum mail_storage_flags flags,
-			      enum file_lock_method lock_method)
+mail_storage_create(const char *driver, const char *data, const char *user,
+		    enum mail_storage_flags flags,
+		    enum file_lock_method lock_method)
 {
 	struct mail_storage *storage_class, *storage;
-	const char *p, *name;
+	struct mail_storage *const *classes;
+	unsigned int i, count;
 
-	if (data == NULL || *data == '\0')
-		return mail_storage_create_default(user, flags, lock_method);
+	if (data == NULL)
+		data = "";
+	else if (driver == NULL)
+		mail_storage_set_autodetection(&data, &driver, &flags);
 
-	/* check if we're in the form of mailformat:data
-	   (eg. maildir:Maildir) */
-	p = data;
-	while (i_isalnum(*p)) p++;
+	if (*data == '\0' && driver == NULL) {
+		/* use the first driver that works */
+		classes = array_get(&storages, &count);
+	} else if (driver == NULL) {
+		storage_class = mail_storage_autodetect(data, flags);
+		if (storage_class == NULL) {
+			i_error("Ambiguous mail location setting, "
+				"don't know what to do with it: %s "
+				"(try prefixing it with mbox: or maildir:)",
+				data);
+			return NULL;
+		}
+		classes = &storage_class;
+		count = 1;
+	} else {
+		storage_class = mail_storage_find(driver);
+		if (storage_class == NULL)
+			return NULL;
+		classes = &storage_class;
+		count = 1;
+	}
 
-	if (*p == ':') {
-		/* no autodetection if the storage format is given. */
-		flags |= MAIL_STORAGE_FLAG_NO_AUTODETECTION;
+	for (i = 0; i < count; i++) {
+		storage = classes[i]->v.alloc();
+		storage->flags = flags;
+		storage->lock_method = lock_method;
+		storage->user = p_strdup(storage->pool, user);
 
-		name = t_strdup_until(data, p);
-		return mail_storage_create(name, p+1, user, flags, lock_method);
-	}
+		storage->callbacks =
+			p_new(storage->pool, struct mail_storage_callbacks, 1);
+		p_array_init(&storage->module_contexts, storage->pool, 5);
 
-	storage_class = mail_storage_autodetect(data, flags);
-	if (storage_class == NULL) {
-		i_error("Ambiguous mail location setting, "
-			"don't know what to do with it: %s "
-			"(try prefixing it with mbox: or maildir:)",
-			data);
-		storage = NULL;
-	} else {
-		storage = storage_class->v.alloc();
-		if (storage_class->v.create(storage, data, user,
-					    flags, lock_method) < 0) {
-			pool_unref(storage->pool);
-			storage = NULL;
-		}
+		if (classes[i]->v.create(storage, data) == 0)
+			break;
+
+		/* try the next one */
+		pool_unref(storage->pool);
 	}
+	if (i == count)
+		return NULL;
 
-	if (hook_mail_storage_created != NULL && storage != NULL)
+	if (hook_mail_storage_created != NULL)
 		hook_mail_storage_created(storage);
 	return storage;
 }

Index: mail-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.h,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- mail-storage.h	29 Mar 2007 07:59:15 -0000	1.127
+++ mail-storage.h	30 Mar 2007 13:40:12 -0000	1.128
@@ -202,16 +202,13 @@
 			    enum file_lock_method *lock_method_r);
 
 /* Create a new instance of registered mail storage class with given
-   storage-specific data. If data is NULL, it tries to autodetect defaults.
+   storage-specific data. If driver is NULL, it's tried to be autodetected
+   from data. If data is NULL, it uses the first storage that exists.
    May return NULL if anything fails. */
 struct mail_storage *
 mail_storage_create(const char *driver, const char *data, const char *user,
 		    enum mail_storage_flags flags,
 		    enum file_lock_method lock_method);
-struct mail_storage *
-mail_storage_create_with_data(const char *data, const char *user,
-			      enum mail_storage_flags flags,
-			      enum file_lock_method lock_method);
 void mail_storage_destroy(struct mail_storage **storage);
 
 char mail_storage_get_hierarchy_sep(struct mail_storage *storage);



More information about the dovecot-cvs mailing list