[dovecot-cvs]
dovecot/src/lib module-dir.c, 1.16, 1.17 module-dir.h, 1.5, 1.6
cras at dovecot.org
cras at dovecot.org
Sun Feb 26 14:16:07 EET 2006
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv21931/src/lib
Modified Files:
module-dir.c module-dir.h
Log Message:
Replaced mail_use_modules and mail_modules settings with mail_plugins and
mail_plugin_dir. Now instead of loading all plugins from the directory,
you'll have to give a list of plugins to load. If the plugin couldn't be
loaded, the process exits instead of just ignoring the problem (this is
important with ACL plugin).
Index: module-dir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- module-dir.c 22 Feb 2006 15:48:33 -0000 1.16
+++ module-dir.c 26 Feb 2006 12:15:50 -0000 1.17
@@ -98,21 +98,44 @@
static int module_name_cmp(const void *p1, const void *p2)
{
- const char *n1 = p1, *n2 = p2;
+ const char *const *n1 = p1, *const *n2 = p2;
+ const char *s1 = *n1, *s2 = *n2;
- if (strncmp(n1, "lib", 3) == 0)
- n1 += 3;
- if (strncmp(n2, "lib", 3) == 0)
- n2 += 3;
+ if (strncmp(s1, "lib", 3) == 0)
+ s1 += 3;
+ if (strncmp(s2, "lib", 3) == 0)
+ s2 += 3;
- return strcmp(n2, n1);
+ return strcmp(s1, s2);
}
-struct module *module_dir_load(const char *dir, bool require_init_funcs)
+static bool module_want_load(const char **names, const char *name)
+{
+ size_t len;
+
+ if (names == NULL)
+ return TRUE;
+
+ len = strlen(name);
+ if (len > 7 && strcmp(name + len - 7, "_plugin") == 0)
+ name = t_strndup(name, len - 7);
+
+ for (; *names != NULL; names++) {
+ if (strcmp(*names, name) == 0) {
+ *names = "";
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+struct module *module_dir_load(const char *dir, const char *module_names,
+ bool require_init_funcs)
{
DIR *dirp;
struct dirent *d;
const char *name, *path, *p, *stripped_name, **names_p;
+ const char **module_names_arr;
struct module *modules, *module;
unsigned int i, count;
array_t ARRAY_DEFINE(names, const char *);
@@ -150,6 +173,9 @@
count = array_count(&names);
qsort(names_p, count, sizeof(const char *), module_name_cmp);
+ t_push();
+ module_names_arr = module_names == NULL ? NULL :
+ t_strsplit_spaces(module_names, ", ");
for (i = 0; i < count; i++) {
const char *name = names_p[i];
@@ -170,8 +196,15 @@
t_push();
stripped_name = t_strdup_until(stripped_name, p);
- path = t_strconcat(dir, "/", name, NULL);
- module = module_load(path, stripped_name, require_init_funcs);
+ if (!module_want_load(module_names_arr, stripped_name))
+ module = NULL;
+ else {
+ path = t_strconcat(dir, "/", name, NULL);
+ module = module_load(path, stripped_name,
+ require_init_funcs);
+ if (module == NULL && module_names_arr != NULL)
+ exit(FATAL_DEFAULT);
+ }
t_pop();
if (module != NULL) {
@@ -179,6 +212,16 @@
modules = module;
}
}
+ if (module_names_arr != NULL) {
+ /* make sure all modules were found */
+ for (; *module_names_arr != NULL; module_names_arr++) {
+ if (**module_names_arr != '\0') {
+ i_fatal("Plugin %s not found from directory %s",
+ *module_names_arr, dir);
+ }
+ }
+ }
+ t_pop();
pool_unref(pool);
if (closedir(dirp) < 0)
Index: module-dir.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- module-dir.h 5 Feb 2006 14:14:12 -0000 1.5
+++ module-dir.h 26 Feb 2006 12:15:50 -0000 1.6
@@ -10,8 +10,10 @@
struct module *next;
};
-/* Load all modules in given directory. */
-struct module *module_dir_load(const char *dir, bool require_init_funcs);
+/* Load modules in given directory. module_names is a space separated list of
+ module names to load, or NULL to load everything. */
+struct module *module_dir_load(const char *dir, const char *module_names,
+ bool require_init_funcs);
/* Call deinit() in all modules and mark them NULL so module_dir_unload()
won't do it again. */
void module_dir_deinit(struct module *modules);
More information about the dovecot-cvs
mailing list