summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-05-16 10:19:23 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2008-05-16 10:19:23 +0000
commit7c67f70b684870920af46c1561eedc475c4ad31f (patch)
tree23c02801402cebdfb875c4570614ee0a96d748a0 /hcid
parent4de66ff306262950a6da54399cef89a9134247f0 (diff)
Implement support for disabling specific plugins from loading
Diffstat (limited to 'hcid')
-rw-r--r--hcid/hcid.h2
-rw-r--r--hcid/main.c25
-rw-r--r--hcid/plugin.c36
3 files changed, 60 insertions, 3 deletions
diff --git a/hcid/hcid.h b/hcid/hcid.h
index 6d28bb67..099357f0 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -212,7 +212,7 @@ GSList *list_trusts(bdaddr_t *local, const char *service);
int write_device_profiles(bdaddr_t *src, bdaddr_t *dst, const char *profiles);
int delete_entry(bdaddr_t *src, const char *storage, const char *key);
-gboolean plugin_init(void);
+gboolean plugin_init(GKeyFile *config);
void plugin_cleanup(void);
void __probe_servers(const char *adapter);
void __remove_servers(const char *adapter);
diff --git a/hcid/main.c b/hcid/main.c
index 980afec2..1afd3475 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -64,6 +64,23 @@ struct device_opts *parser_device;
static struct device_list *device_list = NULL;
static int child_pipe[2];
+static GKeyFile *load_config(const char *file)
+{
+ GError *err = NULL;
+ GKeyFile *keyfile;
+
+ keyfile = g_key_file_new();
+
+ if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
+ error("Parsing %s failed: %s", file, err->message);
+ g_error_free(err);
+ g_key_file_free(keyfile);
+ return NULL;
+ }
+
+ return keyfile;
+}
+
static inline void init_device_defaults(struct device_opts *device_opts)
{
memset(device_opts, 0, sizeof(*device_opts));
@@ -769,6 +786,7 @@ int main(int argc, char *argv[])
GIOChannel *ctl_io, *child_io;
uint16_t mtu = 0;
int opt, daemonize = 1, debug = 0, sdp = 1, experimental = 0;
+ GKeyFile *config;
/* Default HCId settings */
memset(&hcid, 0, sizeof(hcid));
@@ -871,6 +889,8 @@ int main(int argc, char *argv[])
exit(1);
}
+ config = load_config(CONFIGDIR "/main.conf");
+
if (read_config(hcid.config_file) < 0)
error("Config load failed");
@@ -920,7 +940,7 @@ int main(int argc, char *argv[])
* the plugins might wanna expose some paths on the bus. However the
* best order of how to init various subsystems of the Bluetooth
* daemon needs to be re-worked. */
- plugin_init();
+ plugin_init(config);
/* Start event processor */
g_main_loop_run(event_loop);
@@ -939,6 +959,9 @@ int main(int argc, char *argv[])
g_main_loop_unref(event_loop);
+ if (config)
+ g_key_file_free(config);
+
info("Exit");
stop_logging();
diff --git a/hcid/plugin.c b/hcid/plugin.c
index f99966bf..acebed61 100644
--- a/hcid/plugin.c
+++ b/hcid/plugin.c
@@ -64,10 +64,39 @@ static gboolean add_plugin(GModule *module, struct bluetooth_plugin_desc *desc)
return TRUE;
}
-gboolean plugin_init(void)
+static gboolean is_disabled(const char *name, char **list)
+{
+ int i;
+
+ for (i = 0; list[i] != NULL; i++) {
+ char *str;
+ gboolean equal;
+
+ str = g_strdup_printf("lib%s.so", list[i]);
+
+ equal = g_str_equal(str, name);
+
+ g_free(str);
+
+ if (equal)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean plugin_init(GKeyFile *config)
{
GDir *dir;
const gchar *file;
+ gchar **disabled;
+
+ if (config)
+ disabled = g_key_file_get_string_list(config, "General",
+ "DisablePlugins",
+ NULL, NULL);
+ else
+ disabled = NULL;
debug("Loading plugins %s", PLUGINDIR);
@@ -85,6 +114,9 @@ gboolean plugin_init(void)
g_str_has_suffix(file, ".so") == FALSE)
continue;
+ if (disabled && is_disabled(file, disabled))
+ continue;
+
filename = g_build_filename(PLUGINDIR, file, NULL);
if (stat(filename, &st) < 0) {
@@ -125,6 +157,8 @@ gboolean plugin_init(void)
g_dir_close(dir);
+ g_strfreev(disabled);
+
return TRUE;
}