56
65
if (g_str_equal(desc->version, VERSION) == FALSE) {
57
DBG("version mismatch for %s", desc->name);
66
error("Version mismatch for %s", desc->name);
70
DBG("Loading %s plugin", desc->name);
61
72
plugin = g_try_new0(struct bluetooth_plugin, 1);
62
73
if (plugin == NULL)
65
76
plugin->handle = handle;
77
plugin->active = FALSE;
66
78
plugin->desc = desc;
68
if (desc->init() < 0) {
73
plugins = g_slist_append(plugins, plugin);
78
static gboolean is_disabled(const char *name, char **list)
82
for (i = 0; list[i] != NULL; i++) {
86
str = g_strdup_printf("%s.so", list[i]);
88
equal = g_str_equal(str, name);
99
gboolean plugin_init(GKeyFile *config)
80
plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
85
static gboolean enable_plugin(const char *name, char **conf_disable,
86
char **cli_enable, char **cli_disable)
89
for (; *conf_disable; conf_disable++)
90
if (g_pattern_match_simple(*conf_disable, name))
93
info("Excluding (conf) %s", name);
99
for (; *cli_disable; cli_disable++)
100
if (g_pattern_match_simple(*cli_disable, name))
103
info("Excluding (cli) %s", name);
109
for (; *cli_enable; cli_enable++)
110
if (g_pattern_match_simple(*cli_enable, name))
113
info("Ignoring (cli) %s", name);
123
gboolean plugin_init(GKeyFile *config, const char *enable, const char *disable)
102
127
const gchar *file;
105
if (strlen(PLUGINDIR) == 0)
128
char **conf_disabled, **cli_disabled, **cli_enabled;
108
131
/* Make a call to BtIO API so its symbols got resolved before the
109
132
* plugins are loaded. */
110
133
bt_io_error_quark();
113
disabled = g_key_file_get_string_list(config, "General",
136
conf_disabled = g_key_file_get_string_list(config, "General",
114
137
"DisablePlugins",
119
debug("Loading plugins %s", PLUGINDIR);
140
conf_disabled = NULL;
143
cli_enabled = g_strsplit_set(enable, ", ", -1);
148
cli_disabled = g_strsplit_set(disable, ", ", -1);
152
DBG("Loading builtin plugins");
154
for (i = 0; __bluetooth_builtin[i]; i++) {
155
if (!enable_plugin(__bluetooth_builtin[i]->name, conf_disabled,
156
cli_enabled, cli_disabled))
159
add_plugin(NULL, __bluetooth_builtin[i]);
162
if (strlen(PLUGINDIR) == 0)
165
DBG("Loading plugins %s", PLUGINDIR);
121
167
dir = g_dir_open(PLUGINDIR, 0, NULL);
123
g_strfreev(disabled);
127
171
while ((file = g_dir_read_name(dir)) != NULL) {
128
172
struct bluetooth_plugin_desc *desc;
133
176
if (g_str_has_prefix(file, "lib") == TRUE ||
134
177
g_str_has_suffix(file, ".so") == FALSE)
137
if (disabled && is_disabled(file, disabled))
140
180
filename = g_build_filename(PLUGINDIR, file, NULL);
142
if (stat(filename, &st) < 0) {
143
error("Can't find plugin %s: %s", filename,
149
182
handle = dlopen(filename, RTLD_NOW);
150
183
if (handle == NULL) {
151
184
error("Can't load plugin %s: %s", filename,