diff options
author | Marius Halden <marius.h@lden.org> | 2016-05-26 15:07:34 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-05-26 15:07:34 +0200 |
commit | 3448d86a3f329ec4d625bd72e64a96061e71e675 (patch) | |
tree | ff41da0d1f55d449b24a91e4b7a91cab0cbcc84d /protocols/nogaim.c | |
parent | 8e4d9a1769a7d566278ed95d94a1cabd8fdc62e7 (diff) | |
parent | 59a7dc58dcf39b7eaed2015423f8a4fc2da3c7fd (diff) |
Merge branch 'master' into patched-master
Diffstat (limited to 'protocols/nogaim.c')
-rw-r--r-- | protocols/nogaim.c | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/protocols/nogaim.c b/protocols/nogaim.c index c9cbb033..ab11508b 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -39,24 +39,84 @@ GSList *connections; #ifdef WITH_PLUGINS +GList *plugins = NULL; + +static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data) +{ + const struct plugin_info *ia = a; + const struct plugin_info *ib = b; + + return g_strcasecmp(ia->name, ib->name); +} + gboolean load_plugin(char *path) { + GList *l; + struct plugin_info *i; + struct plugin_info *info; + struct plugin_info * (*info_function) (void) = NULL; void (*init_function) (void); GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); + gboolean loaded = FALSE; if (!mod) { log_message(LOGLVL_ERROR, "Error loading plugin `%s': %s\n", path, g_module_error()); return FALSE; } + if (g_module_symbol(mod, "init_plugin_info", (gpointer *) &info_function)) { + info = info_function(); + + if (info->abiver != BITLBEE_ABI_VERSION_CODE) { + log_message(LOGLVL_ERROR, + "`%s' uses ABI %u but %u is required\n", + path, info->abiver, + BITLBEE_ABI_VERSION_CODE); + g_module_close(mod); + return FALSE; + } + + if (!info->name || !info->version) { + log_message(LOGLVL_ERROR, + "Name or version missing from the " + "plugin info in `%s'\n", path); + g_module_close(mod); + return FALSE; + } + + for (l = plugins; l; l = l->next) { + i = l->data; + + if (g_strcasecmp(i->name, info->name) == 0) { + loaded = TRUE; + break; + } + } + + if (loaded) { + log_message(LOGLVL_WARNING, + "%s plugin already loaded\n", + info->name); + g_module_close(mod); + return FALSE; + } + } else { + log_message(LOGLVL_WARNING, "Can't find function `init_plugin_info' in `%s'\n", path); + } + if (!g_module_symbol(mod, "init_plugin", (gpointer *) &init_function)) { log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); + g_module_close(mod); return FALSE; } - init_function(); + if (info_function) { + plugins = g_list_insert_sorted_with_data(plugins, info, + pluginscmp, NULL); + } + init_function(); return TRUE; } @@ -72,6 +132,10 @@ void load_plugins(void) char *path; while ((entry = g_dir_read_name(dir))) { + if (!g_str_has_suffix(entry, "." G_MODULE_SUFFIX)) { + continue; + } + path = g_build_filename(global.conf->plugindir, entry, NULL); if (!path) { log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); @@ -86,6 +150,11 @@ void load_plugins(void) g_dir_close(dir); } } + +GList *get_plugins() +{ + return plugins; +} #endif GList *protocols = NULL; @@ -164,6 +233,16 @@ void nogaim_init() #endif } +GList *get_protocols() +{ + return protocols; +} + +GList *get_protocols_disabled() +{ + return disabled_protocols; +} + GSList *get_connections() { return connections; |