From 2dc8030f8b97e325daa35b5162893463b8522a63 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Aug 2013 17:00:15 +0100 Subject: [PATCH] Use GString for path in creating c plugins, fixed hook name in test-c-plugin --- plugins/test-c-plugin/test-c-plugin.c | 2 +- src/plugins/c_plugins.c | 28 ++++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/plugins/test-c-plugin/test-c-plugin.c b/plugins/test-c-plugin/test-c-plugin.c index e0014e9f..965d0976 100644 --- a/plugins/test-c-plugin/test-c-plugin.c +++ b/plugins/test-c-plugin/test-c-plugin.c @@ -23,7 +23,7 @@ prof_on_connect (void) } void -c_on_message_received (const char * const jid, const char * const message) +prof_on_message_received (const char * const jid, const char * const message) { fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, message); } diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index d7852b54..8fbe71b8 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -1,3 +1,9 @@ +// FIXME on windows this might be a different header +#include +#include +#include + +#include #include "config/preferences.h" #include "log.h" @@ -7,26 +13,17 @@ #include "plugins/c_plugins.h" #include "ui/ui.h" -// FIXME on windows this might be a different header -#include -#include -#include -#include - ProfPlugin * c_plugin_create(const char * const filename) { ProfPlugin *plugin; - void * handle = NULL; - char * path = NULL; + void *handle = NULL; - // FIXME so where is the right path for the plugin dir? - if (-1 == asprintf (&path, "./plugins/%s", filename)) { - log_warning ("asprintf failed, plugin %s not loaded", filename); - return NULL; - } + // TODO use XDG for path + GString *path = g_string_new("./plugins/"); + g_string_append(path, filename); - handle = dlopen (path, RTLD_NOW | RTLD_GLOBAL); + handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL); if (!handle) { log_warning ("dlopen failed to open `%s', %s", filename, dlerror ()); @@ -42,8 +39,7 @@ c_plugin_create(const char * const filename) plugin->on_connect_func = c_on_connect_hook; plugin->on_message_received_func = c_on_message_received_hook; - if (!path) - free (path); + g_string_free(path, TRUE); return plugin; }