From 54ea41d5b6acac199926842a57f125a1142bdeb1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Sep 2013 23:27:10 +0100 Subject: [PATCH] Added /plugins command to list installed plugins --- src/command/command.c | 32 +++++++++++++++++++++++++++++++- src/plugins/c_plugins.c | 6 +++++- src/plugins/plugins.c | 22 ++++++++++++++++++++++ src/plugins/plugins.h | 2 ++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index c06671bc..9ca80678 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -94,6 +94,7 @@ static gboolean _cmd_autoaway(gchar **args, struct cmd_help_t help); static gboolean _cmd_autoping(gchar **args, struct cmd_help_t help); static gboolean _cmd_away(gchar **args, struct cmd_help_t help); static gboolean _cmd_beep(gchar **args, struct cmd_help_t help); +static gboolean _cmd_bookmark(gchar **args, struct cmd_help_t help); static gboolean _cmd_caps(gchar **args, struct cmd_help_t help); static gboolean _cmd_chat(gchar **args, struct cmd_help_t help); static gboolean _cmd_chlog(gchar **args, struct cmd_help_t help); @@ -124,12 +125,12 @@ static gboolean _cmd_nick(gchar **args, struct cmd_help_t help); static gboolean _cmd_notify(gchar **args, struct cmd_help_t help); static gboolean _cmd_online(gchar **args, struct cmd_help_t help); static gboolean _cmd_outtype(gchar **args, struct cmd_help_t help); +static gboolean _cmd_plugins(gchar **args, struct cmd_help_t help); static gboolean _cmd_prefs(gchar **args, struct cmd_help_t help); static gboolean _cmd_priority(gchar **args, struct cmd_help_t help); static gboolean _cmd_quit(gchar **args, struct cmd_help_t help); static gboolean _cmd_reconnect(gchar **args, struct cmd_help_t help); static gboolean _cmd_rooms(gchar **args, struct cmd_help_t help); -static gboolean _cmd_bookmark(gchar **args, struct cmd_help_t help); static gboolean _cmd_roster(gchar **args, struct cmd_help_t help); static gboolean _cmd_software(gchar **args, struct cmd_help_t help); static gboolean _cmd_splash(gchar **args, struct cmd_help_t help); @@ -757,6 +758,14 @@ static struct cmd_t command_defs[] = " : /account rename work gtalk", NULL } } }, + { "/plugins", + _cmd_plugins, parse_args, 0, 0, NULL, + { "/plugins", "Show installed plugins.", + { "/plugins", + "-------------", + "Show currently installed plugins.", + NULL } } }, + { "/prefs", _cmd_prefs, parse_args, 0, 1, NULL, { "/prefs [area]", "Show configuration.", @@ -1867,6 +1876,27 @@ _cmd_about(gchar **args, struct cmd_help_t help) return TRUE; } +static gboolean +_cmd_plugins(gchar **args, struct cmd_help_t help) +{ + GSList *plugins = plugins_get_list(); + + GSList *curr = plugins; + if (curr == NULL) { + cons_show("No plugins installed."); + } else { + cons_show("Installed plugins:"); + while (curr != NULL) { + ProfPlugin *plugin = curr->data; + char *lang = plugins_get_lang_string(plugin); + cons_show(" %s (%s)", plugin->name, lang); + curr = g_slist_next(curr); + } + } + g_slist_free(curr); + return TRUE; +} + static gboolean _cmd_prefs(gchar **args, struct cmd_help_t help) { diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index 78ba6dfe..5691308a 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -40,8 +41,10 @@ c_plugin_create(const char * const filename) return NULL; } + gchar *module_name = g_strndup(filename, strlen(filename) - 3); + plugin = malloc(sizeof(ProfPlugin)); - plugin->name = g_strdup(filename); + plugin->name = strdup(module_name); plugin->lang = LANG_C; plugin->module = handle; plugin->init_func = c_init_hook; @@ -51,6 +54,7 @@ c_plugin_create(const char * const filename) plugin->on_message_send_func = c_on_message_send_hook; g_string_free(path, TRUE); + g_free(module_name); return plugin; } diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index b60f0574..41763b17 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -91,6 +91,28 @@ plugins_init(void) return; } +GSList * +plugins_get_list(void) +{ + return plugins; +} + +char * +plugins_get_lang_string(ProfPlugin *plugin) +{ + switch (plugin->lang) + { + case LANG_PYTHON: + return "Python"; + case LANG_RUBY: + return "Ruby"; + case LANG_C: + return "C"; + default: + return "Unknown"; + } +} + void plugins_on_start(void) { diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 1a0b3857..6e254c82 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -45,6 +45,8 @@ typedef struct prof_plugin_t { } ProfPlugin; void plugins_init(void); +GSList * plugins_get_list(void); +char * plugins_get_lang_string(ProfPlugin *plugin); void plugins_on_start(void); void plugins_on_connect(const char * const account_name, const char * const fulljid); char * plugins_on_message_received(const char * const jid, const char *message);