aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/nogaim.c88
1 files changed, 53 insertions, 35 deletions
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index e4db7024..3fed2728 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -49,16 +49,64 @@ static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data)
return g_strcasecmp(ia->name, ib->name);
}
-gboolean load_plugin(char *path)
+/* semi-private */
+gboolean plugin_info_validate(struct plugin_info *info, const char *path)
{
GList *l;
- struct plugin_info *i;
+ gboolean loaded = FALSE;
+
+ if (!path) {
+ path = "(null)";
+ }
+
+ 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);
+ return FALSE;
+ }
+
+ if (!info->name || !info->version) {
+ log_message(LOGLVL_ERROR,
+ "Name or version missing from the "
+ "plugin info in `%s'\n", path);
+ return FALSE;
+ }
+
+ for (l = plugins; l; l = l->next) {
+ struct plugin_info *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);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* semi-private */
+gboolean plugin_info_add(struct plugin_info *info)
+{
+ plugins = g_list_insert_sorted_with_data(plugins, info, pluginscmp, NULL);
+ return TRUE;
+}
+
+gboolean load_plugin(char *path)
+{
struct plugin_info *info = NULL;
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());
@@ -68,36 +116,7 @@ gboolean load_plugin(char *path)
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);
+ if (!plugin_info_validate(info, path)) {
g_module_close(mod);
return FALSE;
}
@@ -112,8 +131,7 @@ gboolean load_plugin(char *path)
}
if (info_function) {
- plugins = g_list_insert_sorted_with_data(plugins, info,
- pluginscmp, NULL);
+ plugin_info_add(info);
}
init_function();