1 #ifndef MODULE_DIR_H
2 #define MODULE_DIR_H
3 
4 struct module_dir_load_settings {
5 	/* If abi_version is non-NULL and the module contains a version symbol,
6 	   fail the load if they're different. In both strings ignore anything
7 	   after the first '(' character, so the version can be e.g.:
8 	   2.2.ABIv1(2.2.15) */
9 	const char *abi_version;
10 	/* Binary name used for checking if plugin is tried to be loaded for
11 	   wrong binary. */
12 	const char *binary_name;
13 	/* Setting name used in plugin dependency error message */
14 	const char *setting_name;
15 
16 	/* If non-NULL, load only modules where filter_callback returns TRUE */
17 	bool (*filter_callback)(const char *name, void *context);
18 	void *filter_context;
19 
20 	/* Require all plugins to have <plugin_name>_init() function */
21 	bool require_init_funcs:1;
22 	/* Enable debug logging */
23 	bool debug:1;
24 	/* If dlopen() fails for some modules, silently skip it. */
25 	bool ignore_dlopen_errors:1;
26 	/* Don't fail if some specified modules weren't found */
27 	bool ignore_missing:1;
28 };
29 
30 struct module {
31 	char *path, *name;
32 
33 	void *handle;
34 	void (*init)(struct module *module);
35 	void (*deinit)(void);
36 
37 	bool initialized:1;
38 
39         struct module *next;
40 };
41 
42 /* Load modules in given directory. module_names is a space separated list of
43    module names to load. */
44 struct module *module_dir_load(const char *dir, const char *module_names,
45 			       const struct module_dir_load_settings *set)
46 	ATTR_NULL(2);
47 /* Load modules that aren't already loaded. */
48 struct module *
49 module_dir_load_missing(struct module *old_modules,
50 			const char *dir, const char *module_names,
51 			const struct module_dir_load_settings *set)
52 	ATTR_NULL(1, 3);
53 /* Load modules that aren't already loaded. */
54 int module_dir_try_load_missing(struct module **modules,
55 				const char *dir, const char *module_names,
56 				const struct module_dir_load_settings *set,
57 				const char **error_r)
58 	ATTR_NULL(1, 3);
59 /* Call init() in all modules */
60 void module_dir_init(struct module *modules);
61 /* Call deinit() in all modules and mark them NULL so module_dir_unload()
62    won't do it again. */
63 void module_dir_deinit(struct module *modules);
64 /* Unload all modules */
65 void module_dir_unload(struct module **modules);
66 /* Find a module by name. */
67 struct module *module_dir_find(struct module *modules, const char *name);
68 
69 void *module_get_symbol(struct module *module, const char *symbol);
70 void *module_get_symbol_quiet(struct module *module, const char *symbol);
71 
72 /* Returns module's base name from the filename. */
73 const char *module_file_get_name(const char *fname);
74 /* Returns module's name without "_plugin" suffix. */
75 const char *module_get_plugin_name(struct module *module);
76 
77 #endif
78