summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-11-01 18:04:56 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-11-01 18:04:56 +0100
commit83444b9257bf9246ad3fe065b52a5146aaf1eaea (patch)
tree048cae26dc5041e067ba27651129f7866ef82259 /src
parent79f0cb9a5c9659d9b90252910a4d7780b99a56ea (diff)
downloadweechat-83444b9257bf9246ad3fe065b52a5146aaf1eaea.zip
Add infolist "plugin", with list of plugins
Diffstat (limited to 'src')
-rw-r--r--src/plugins/plugin-api.c38
-rw-r--r--src/plugins/plugin.c65
-rw-r--r--src/plugins/plugin.h5
3 files changed, 106 insertions, 2 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 4844052b2..73148a638 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -293,6 +293,7 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
struct t_gui_filter *ptr_filter;
struct t_gui_window *ptr_window;
struct t_gui_hotlist *ptr_hotlist;
+ struct t_weechat_plugin *ptr_plugin;
/* make C compiler happy */
(void) data;
@@ -492,6 +493,41 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name,
return ptr_infolist;
}
}
+ else if (string_strcasecmp (infolist_name, "plugin") == 0)
+ {
+ /* invalid plugin pointer ? */
+ if (pointer && (!plugin_valid (pointer)))
+ return NULL;
+
+ ptr_infolist = infolist_new ();
+ if (ptr_infolist)
+ {
+ if (pointer)
+ {
+ /* build list with only one plugin */
+ if (!plugin_add_to_infolist (ptr_infolist, pointer))
+ {
+ infolist_free (ptr_infolist);
+ return NULL;
+ }
+ return ptr_infolist;
+ }
+ else
+ {
+ /* build list with all plugins */
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ if (!plugin_add_to_infolist (ptr_infolist, ptr_plugin))
+ {
+ infolist_free (ptr_infolist);
+ return NULL;
+ }
+ }
+ return ptr_infolist;
+ }
+ }
+ }
/* infolist not found */
return NULL;
@@ -678,4 +714,6 @@ plugin_api_init ()
&plugin_api_infolist_get_internal, NULL);
hook_infolist (NULL, "hook", N_("list of hooks"),
&plugin_api_infolist_get_internal, NULL);
+ hook_infolist (NULL, "plugin", N_("list of plugins"),
+ &plugin_api_infolist_get_internal, NULL);
}
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 07df6adee..f433d7fb2 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -63,6 +63,31 @@ char **plugin_argv; /* first time loading plugin) */
/*
+ * plugin_valid: check if a plugin pointer exists
+ * return 1 if plugin exists
+ * 0 if plugin is not found
+ */
+
+int
+plugin_valid (struct t_weechat_plugin *plugin)
+{
+ struct t_weechat_plugin *ptr_plugin;
+
+ if (!plugin)
+ return 0;
+
+ for (ptr_plugin = weechat_plugins; ptr_plugin;
+ ptr_plugin = ptr_plugin->next_plugin)
+ {
+ if (ptr_plugin == plugin)
+ return 1;
+ }
+
+ /* plugin not found */
+ return 0;
+}
+
+/*
* plugin_search: search a plugin by name
*/
@@ -863,6 +888,46 @@ plugin_end ()
}
/*
+ * plugin_add_to_infolist: add a plugin in an infolist
+ * return 1 if ok, 0 if error
+ */
+
+int
+plugin_add_to_infolist (struct t_infolist *infolist,
+ struct t_weechat_plugin *plugin)
+{
+ struct t_infolist_item *ptr_item;
+
+ if (!infolist || !plugin)
+ return 0;
+
+ ptr_item = infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!infolist_new_var_pointer (ptr_item, "pointer", plugin))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "filename", plugin->filename))
+ return 0;
+ if (!infolist_new_var_pointer (ptr_item, "handle", plugin->handle))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "description", plugin->description))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "author", plugin->author))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "version", plugin->version))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "weechat_version", plugin->weechat_version))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "license", plugin->license))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "charset", plugin->charset))
+ return 0;
+
+ return 1;
+}
+
+/*
* plugin_print_log: print plugin infos in log (usually for crash dump)
*/
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index 57b6584ad..875f4288a 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -31,8 +31,7 @@ typedef int (t_weechat_end_func) (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *weechat_plugins;
extern struct t_weechat_plugin *last_weechat_plugin;
-//extern t_plugin_irc_color plugins_irc_colors[GUI_NUM_IRC_COLORS];
-
+extern int plugin_valid (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *plugin_search (const char *name);
extern char *plugin_get_name (struct t_weechat_plugin *plugin);
extern struct t_weechat_plugin *plugin_load (const char *filename);
@@ -44,6 +43,8 @@ extern void plugin_unload_all ();
extern void plugin_reload_name (const char *name);
extern void plugin_init (int auto_load, int argc, char *argv[]);
extern void plugin_end ();
+extern int plugin_add_to_infolist (struct t_infolist *infolist,
+ struct t_weechat_plugin *plugin);
extern void plugin_print_log ();
#endif /* plugin.h */