diff options
Diffstat (limited to 'src/plugins/plugin.c')
-rw-r--r-- | src/plugins/plugin.c | 147 |
1 files changed, 137 insertions, 10 deletions
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 7521008..e769df6 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -26,7 +26,12 @@ #include <gmodule.h> +#include <libgen.h> +#include <malloc.h> +#include <stdarg.h> #include <stdbool.h> +#include <stdio.h> +#include <string.h> #include "plugin-int.h" @@ -98,22 +103,26 @@ static void g_plugin_module_init(GPluginModule *line) GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref) { GPluginModule *result; /* Structure à retourner */ + get_plugin_name_fc get_name; /* Nom du greffon */ get_plugin_action_fc __get_type; /* Type(s) de greffon */ get_plugin_action_fc get_action; /* Actions du greffon */ - + char *dir; /* Répertoire modifiable */ result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); result->module = g_module_open(filename, G_MODULE_BIND_LAZY); + if (!result->module) goto bad_plugin; - if (!result->module) + if (!g_module_symbol(result->module, "get_plugin_name", (gpointer *)&get_name)) { - printf("err null mod\n"); - return NULL; - + log_variadic_message(LMT_ERROR, + _("No 'get_plugin_name' entry in plugin candidate '%s'"), + filename); + goto bad_plugin; } + result->name = get_name(); if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) { @@ -166,12 +175,21 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref) - if (!result->init(ref)) - printf("Err loading pg\n"); - else printf("Loaded '%s' : ok (%p)\n", filename, result); + if (!result->init(result, ref)) + { + log_variadic_message(LMT_ERROR, _("Initialization of plugin '%s' failed !"), filename); + goto bad_plugin; + } + + dir = strdup(filename); + dir = dirname(dir); - return result; + log_variadic_message(LMT_PROCESS, _("Loaded the '<b>%s</b>' from the '<b>%s</b>' directory"), + strrchr(filename, G_DIR_SEPARATOR) + 1, dir); + free(dir); + + return result; bad_plugin: @@ -186,6 +204,115 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref) * * * Paramètres : plugin = greffon à consulter. * * * +* Description : Fournit le nom associé au greffon. * +* * +* Retour : Désignation humaine. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_plugin_module_get_name(const GPluginModule *plugin) +{ + return plugin->name; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* msg = message à faire apparaître à l'écran. * +* * +* Description : Présente dans le journal un message simple. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_plugin_module_log_simple_message(const GPluginModule *plugin, LogMessageType type, const char *msg) +{ + size_t len; /* Taille tampon disponible */ + char *buffer; /* Tampon du msg reconstitué */ + + len = 1 + strlen(plugin->name) + 2 + strlen(msg) + 1; + buffer = calloc(len, sizeof(char)); + + strcpy(buffer, "["); + strcat(buffer, plugin->name); + strcat(buffer, "] "); + strcat(buffer, msg); + + log_simple_message(type, buffer); + + free(buffer); + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* type = espèce du message à ajouter. * +* fmt = format du message à faire apparaître à l'écran. * +* ... = éventuels arguments venant compléter le message. * +* * +* Description : Présente dans le journal un message complexe. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_plugin_module_log_variadic_message(const GPluginModule *plugin, LogMessageType type, const char *fmt, ...) +{ + size_t len; /* Taille tampon disponible */ + char *buffer; /* Tampon du msg reconstitué */ + int ret; /* Bilan d'une impression */ + char *ptr; /* Nouvelle allocation */ + va_list ap; /* Liste d'arguments variable */ + + len = VARIADIC_LOG_BUFSIZE; + buffer = calloc(len, sizeof(char)); + + while (buffer != NULL) + { + va_start(ap, fmt); + ret = vsnprintf(buffer, len, fmt, ap); + va_end(ap); + + if (ret >= 0 && ret < len) break; + + else + { + if (ret > -1) len += 1; /* glibc 2.1 */ + else len *= 2; /* glibc 2.0 */ + + if ((ptr = realloc(buffer, len)) == NULL) + { + free(buffer); + buffer = NULL; + } + else buffer = ptr; + + } + + } + + g_plugin_module_log_simple_message(plugin, type, buffer); + + free(buffer); + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* * * Description : Indique les opérations offertes par un greffon donné. * * * * Retour : Action(s) offerte(s) par le greffon. * @@ -262,7 +389,7 @@ MatchingFormatAction g_plugin_module_is_matching(const GPluginModule *plugin, ch bool g_plugin_module_execute_action_on_binary(const GPluginModule *plugin, GOpenidaBinary *binary, PluginAction action) { - return plugin->exec_on_bin(binary, action); + return plugin->exec_on_bin(plugin, binary, action); } |