From: Timo Sirainen Date: Sun, 22 Mar 2015 18:52:16 +0000 (+0200) Subject: lib-fs: When autoloading fs plugins with '-' in the name, translate them to '_' X-Git-Tag: 2.2.17.rc1~239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bf2d5782f1637e6816efa82865ca7eacbadd20c;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index 4124c7d6d8..63b70904d5 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -81,9 +81,28 @@ static void fs_class_deinit_modules(void) 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 @@ static void fs_class_try_load_plugin(const char *driver) 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);