From a167322d8b572948a0c2cf74139c8e6c1e1dc45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 19 Feb 2024 18:29:21 +0100 Subject: api: add info "plugin_loaded" --- src/plugins/plugin-api-info.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index f59aa004c..f22515847 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -1179,6 +1179,39 @@ error: return NULL; } +/* + * Returns WeeChat info "plugin_loaded". + */ + +char * +plugin_api_info_plugin_loaded_cb (const void *pointer, void *data, + const char *info_name, + const char *arguments) +{ + struct t_weechat_plugin *ptr_plugin; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) info_name; + + if (!arguments || !arguments[0]) + return NULL; + + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + if (strcmp (ptr_plugin->name, arguments) == 0) + { + /* plugin loaded */ + return strdup ("1"); + } + } + + /* plugin not loaded */ + return NULL; +} + /* * Returns secured data hashtable. */ @@ -2234,6 +2267,10 @@ plugin_api_info_init () "timestamp (optional, current time by default), number of " "passwords before/after to test (optional, 0 by default)"), &plugin_api_info_totp_validate_cb, NULL, NULL); + hook_info (NULL, "plugin_loaded", + N_("1 if plugin is loaded"), + N_("plugin name"), + &plugin_api_info_plugin_loaded_cb, NULL, NULL); /* WeeChat core info_hashtable hooks */ hook_info_hashtable (NULL, -- cgit v1.2.3