mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 02:03:13 +02:00
Add infolist "plugin", with list of plugins
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,31 @@ int plugin_argc; /* command line arguments (used only */
|
||||
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
|
||||
*/
|
||||
@@ -862,6 +887,46 @@ plugin_end ()
|
||||
plugin_config_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)
|
||||
*/
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user