dovecot-2.2: lib-fs: When autoloading fs plugins with '-' in the...

dovecot at dovecot.org dovecot at dovecot.org
Sun Mar 22 18:55:45 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/35a4828d11f7
changeset: 18382:35a4828d11f7
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Mar 22 20:52:16 2015 +0200
description:
lib-fs: When autoloading fs plugins with '-' in the name, translate them to '_'
It's not possible for the function names to contain '-' in any case. Also
Dovecot in general uses '-' instead of '_' in the configuration names. This
change actually allows using either of them.

diffstat:

 src/lib-fs/fs-api.c |  24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diffs (43 lines):

diff -r 36ca0e03bd06 -r 35a4828d11f7 src/lib-fs/fs-api.c
--- a/src/lib-fs/fs-api.c	Sun Mar 22 18:59:51 2015 +0200
+++ b/src/lib-fs/fs-api.c	Sun Mar 22 20:52:16 2015 +0200
@@ -81,9 +81,28 @@
 	module_dir_unload(&fs_modules);
 }
 
+static const char *fs_driver_module_name(const char *driver)
+{
+	string_t *str;
+	unsigned int i;
+
+	if (strchr(driver, '-') == NULL)
+		return driver;
+
+	str = t_str_new(32);
+	for (i = 0; driver[i] != '\0'; i++) {
+		if (driver[i] == '-')
+			str_append_c(str, '_');
+		else
+			str_append_c(str, driver[i]);
+	}
+	return str_c(str);
+}
+
 static void fs_class_try_load_plugin(const char *driver)
 {
-	const char *module_name = t_strdup_printf("fs_%s", driver);
+	const char *module_name =
+		t_strdup_printf("fs_%s", fs_driver_module_name(driver));
 	struct module *module;
 	struct module_dir_load_settings mod_set;
 	const struct fs *fs_class;
@@ -98,7 +117,8 @@
 
 	module = module_dir_find(fs_modules, module_name);
 	fs_class = module == NULL ? NULL :
-		module_get_symbol(module, t_strdup_printf("fs_class_%s", driver));
+		module_get_symbol(module, t_strdup_printf(
+			"fs_class_%s", fs_driver_module_name(driver)));
 	if (fs_class != NULL)
 		fs_class_register(fs_class);
 


More information about the dovecot-cvs mailing list