1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 04:46:37 +02:00

Improve plugins autoload (option weechat.plugin.autoload): allow to use "*" as joker and "!" to prevent a plugin from being autoloaded (task #6361)

Some examples for option weechat.plugin.autoload:
- load all plugins (default): "*"
- load only alias, charset, irc and logger: "alias,charset,irc,logger"
- load all plugins but not lua and tcl: "*,!lua,!tcl"
- load all plugins but not perl and python: "*,!p*" (not recommended because new future plugins may begin with "p")
- do not load any plugin (weechat core alone is not really useful eheh): "!*"
This commit is contained in:
Sebastien Helleu
2010-03-31 22:39:09 +02:00
parent 253ff07009
commit 848cce2c8a
15 changed files with 193 additions and 95 deletions
+4 -1
View File
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
FlashCode <flashcode@flashtux.org>
v0.3.2-dev, 2010-03-30
v0.3.2-dev, 2010-03-31
Version 0.3.2 (under dev!)
@@ -11,6 +11,9 @@ Version 0.3.2 (under dev!)
* core: add new command /mute
* core: add command line option "-s" (or "--no-script") to start WeeChat
without loading any script
* core: improve plugins autoload (option weechat.plugin.autoload): allow to
use "*" as joker and "!" to prevent a plugin from being autoloaded
(task #6361)
* core: remove unneeded space after time on each line if option
weechat.look.buffer_time_format is set to empty value (bug #28751)
* core: add option "switch_active_buffer_previous" for command /input
+1 -1
View File
@@ -574,7 +574,7 @@
** values: any string (default value: "%h/ssl/CAs.pem")
* *weechat.plugin.autoload*
** description: comma separated list of plugins to load automatically at startup, "*" means all plugins found (names may be partial, for example "perl" is ok for "perl.so")
** description: comma separated list of plugins to load automatically at startup, "*" means all plugins found, a name beginning with "!" is a negative value to prevent a plugin from being loaded, names can start or end with "*" to match several plugins (examples: "*", "*,!lua,!tcl")
** type: string
** values: any string (default value: "*")
+1 -1
View File
@@ -574,7 +574,7 @@
** valeurs: toute chaîne (valeur par défaut: "%h/ssl/CAs.pem")
* *weechat.plugin.autoload*
** description: liste des extensions à charger automatiquement au démarrage, "*" signifie toutes (séparées par des virgules, les noms peuvent être partiels, par exemple "perl" est ok pour "perl.so")
** description: liste des extensions à charger automatiquement au démarrage (séparées par des virgules), "*" signifie toutes les extensions trouvées, un nom commençant par "!" est une valeur négative pour empêcher une extension d'être chargée, les noms peuvent commencer ou se terminer par "*" pour indiquer plusieurs extensions (exemples: "*", "*,!lua,!tcl")
** type: chaîne
** valeurs: toute chaîne (valeur par défaut: "*")
+1 -1
View File
@@ -574,7 +574,7 @@
** valori: qualsiasi stringa (valore predefinito: "%h/ssl/CAs.pem")
* *weechat.plugin.autoload*
** descrizione: elenco separato da virgole di plugin da caricare automaticamente all'avvio, "*" per tutti i plugin trovati (nomi possono essere parziali, per esempio "perl" va bene per "perl.so")
** descrizione: comma separated list of plugins to load automatically at startup, "*" means all plugins found, a name beginning with "!" is a negative value to prevent a plugin from being loaded, names can start or end with "*" to match several plugins (examples: "*", "*,!lua,!tcl")
** tipo: stringa
** valori: qualsiasi stringa (valore predefinito: "*")
+5 -3
View File
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-23 10:19+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -2065,10 +2065,12 @@ msgstr ""
msgid "file containing the certificate authorities"
msgstr "soubor obsahuje certifikační autority"
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"čárkou rozdělený seznam pluginů pro automatické načtení při spuštění \"*\" "
"znamená všechny nalezené pluginy (jména mohou být částečná, například \"perl"
+5 -3
View File
@@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-29 22:38+0200\n"
"Last-Translator: Nils G <weechatter@arcor.de>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -2176,10 +2176,12 @@ msgstr ""
msgid "file containing the certificate authorities"
msgstr "Datei enthält die Zertifizierungsstellen."
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"Durch Kommata getrennte Liste der Erweiterungen, die beim Start automatisch "
"geladen werden sollen, \"*\" lädt alle gefundenen Erweiterungen (es können "
+5 -3
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-23 10:20+0100\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -2074,10 +2074,12 @@ msgstr ""
msgid "file containing the certificate authorities"
msgstr "archivo que contiene las autoridades de certificación"
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"lista de plugins separados por comas para cargar automáticamente al iniciar, "
"\"*\" significa todos los plugins encontrados (los nombres pueden ser "
+10 -7
View File
@@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"PO-Revision-Date: 2010-03-29 18:16+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-31 19:57+0200\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@@ -2145,12 +2145,15 @@ msgstr "fichier contenant les autorités de certification"
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"liste des extensions à charger automatiquement au démarrage, \"*\" signifie "
"toutes (séparées par des virgules, les noms peuvent être partiels, par "
"exemple \"perl\" est ok pour \"perl.so\")"
"liste des extensions à charger automatiquement au démarrage (séparées par "
"des virgules), \"*\" signifie toutes les extensions trouvées, un nom "
"commençant par \"!\" est une valeur négative pour empêcher une extension "
"d'être chargée, les noms peuvent commencer ou se terminer par \"*\" pour "
"indiquer plusieurs extensions (exemples: \"*\", \"*,!lua,!tcl\")"
msgid ""
"enable debug messages by default in all plugins (option disabled by default, "
+4 -3
View File
@@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-23 10:20+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1953,8 +1953,9 @@ msgstr ""
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"automatikusan betöltendő modulok vesszővel elválasztott listája, \"*\" "
"esetén az összes fellelt modul (az elnevezés lehet részleges, például a "
+5 -3
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Weechat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-24 14:20+0100\n"
"Last-Translator: Marco Paolone <marcopaolone@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -2117,10 +2117,12 @@ msgstr ""
msgid "file containing the certificate authorities"
msgstr "file contenente le autorità dei certificati"
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"elenco separato da virgole di plugin da caricare automaticamente all'avvio, "
"\"*\" per tutti i plugin trovati (nomi possono essere parziali, per esempio "
+5 -3
View File
@@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-23 10:20+0100\n"
"Last-Translator: Krzysztof Koroscik <soltys@szluug.org>\n"
"Language-Team: Polish\n"
@@ -2092,10 +2092,12 @@ msgstr ""
msgid "file containing the certificate authorities"
msgstr "plik zawierający dane centrum uwieżytelniającego (CA)"
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"oddzielona przecinkami lista wtyczek do automatycznego załadowania podczas "
"startu, \"*\" oznacza wszystkie znalezione wtyczki (nazwy mogą być "
+4 -3
View File
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.2-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: 2010-03-23 10:20+0100\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1960,8 +1960,9 @@ msgstr ""
#, fuzzy
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
"разделённый запятыми список автоматически загружаемых при запуске plug-"
"in'ов , \"*\" означает все найденные plug-in'ы (имена могут быть не полными, "
+4 -3
View File
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2010-03-29 18:13+0200\n"
"POT-Creation-Date: 2010-03-31 19:56+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1664,8 +1664,9 @@ msgstr ""
msgid ""
"comma separated list of plugins to load automatically at startup, \"*\" "
"means all plugins found (names may be partial, for example \"perl\" is ok "
"for \"perl.so\")"
"means all plugins found, a name beginning with \"!\" is a negative value to "
"prevent a plugin from being loaded, names can start or end with \"*\" to "
"match several plugins (examples: \"*\", \"*,!lua,!tcl\")"
msgstr ""
msgid ""
+4 -3
View File
@@ -1992,9 +1992,10 @@ config_weechat_init_options ()
weechat_config_file, ptr_section,
"autoload", "string",
N_("comma separated list of plugins to load automatically "
"at startup, \"*\" means all plugins found (names may "
"be partial, for example \"perl\" is ok for "
"\"perl.so\")"),
"at startup, \"*\" means all plugins found, a name beginning with "
"\"!\" is a negative value to prevent a plugin from being loaded, "
"names can start or end with \"*\" to match several plugins "
"(examples: \"*\", \"*,!lua,!tcl\")"),
NULL, 0, 0, "*", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_plugin_debug = config_file_new_option (
weechat_config_file, ptr_section,
+135 -57
View File
@@ -26,6 +26,7 @@
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
@@ -63,6 +64,10 @@ struct t_weechat_plugin *last_weechat_plugin = NULL;
int plugin_argc; /* command line arguments (used only */
char **plugin_argv; /* first time loading plugin) */
int plugin_autoload_count = 0; /* number of items in autoload_array */
char **plugin_autoload_array = NULL; /* autoload array, this is split of */
/* option "weechat.plugin.autoload" */
void plugin_remove (struct t_weechat_plugin *plugin);
@@ -127,6 +132,80 @@ plugin_get_name (struct t_weechat_plugin *plugin)
return (plugin) ? plugin->name : plugin_core;
}
/*
* plugin_check_autoload: check if a plugin can be autoloaded or not
* return 1 if plugin can be autoloaded
* 0 if plugin can NOT be autoloaded
* list of autoloaded plugins is set in option
* "weechat.plugin.autoload"
*/
int
plugin_check_autoload (char *plugin_full_name)
{
int i, plugin_authorized, plugin_blacklisted;
char *ptr_base_name, *base_name, *plugin_name, *pos;
/* by default we can auto load all plugins */
if (!plugin_autoload_array)
return 1;
/* get short name of plugin (filename without extension) */
plugin_name = NULL;
ptr_base_name = basename (plugin_full_name);
if (!ptr_base_name)
return 1;
base_name = strdup (ptr_base_name);
if (!base_name)
return 1;
if (CONFIG_STRING(config_plugin_extension)
&& CONFIG_STRING(config_plugin_extension)[0])
{
pos = strstr (base_name,
CONFIG_STRING(config_plugin_extension));
plugin_name = (pos) ?
string_strndup (base_name, pos - base_name) :
strdup (base_name);
}
else
plugin_name = strdup (base_name);
free (base_name);
if (!plugin_name)
return 1;
/* browse array and check if plugin is "authorized" or "blacklisted" */
plugin_authorized = 0;
plugin_blacklisted = 0;
for (i = 0; i < plugin_autoload_count; i++)
{
if (plugin_autoload_array[i][0] == '!')
{
/*
* negative value: it is used to "blacklist" a plugin
* for example with "*,!perl", all plugins are loaded, but not perl
*/
if (string_match (plugin_name, plugin_autoload_array[i] + 1, 0))
plugin_blacklisted = 1;
}
else
{
if (string_match (plugin_name, plugin_autoload_array[i], 0))
plugin_authorized = 1;
}
}
free (plugin_name);
if (plugin_blacklisted)
return 0;
return plugin_authorized;
}
/*
* plugin_find_pos: find position for a plugin (for sorting plugins list)
*/
@@ -171,6 +250,14 @@ plugin_load (const char *filename)
if (!full_name)
return NULL;
/*
* if plugin must not be autoloaded, then return immediately
* Note: the "plugin_autoload_array" variable is set only during auto-load,
* ie when WeeChat is starting or when doing /plugin autoload
*/
if (plugin_autoload_array && !plugin_check_autoload (full_name))
return NULL;
ptr_home = getenv ("HOME");
full_name2 = string_replace (full_name, "~", ptr_home);
@@ -684,74 +771,65 @@ plugin_auto_load_file (void *plugin, const char *filename)
}
/*
* plugin_auto_load: auto-load WeeChat plugins
* plugin_auto_load: auto-load WeeChat plugins, from user and system
* directories
*/
void
plugin_auto_load ()
{
char *ptr_home, *dir_name, *plugin_path, *plugin_path2;
char *list_plugins, *pos, *pos2;
plugin_autoload_array = NULL;
plugin_autoload_count = 0;
if (CONFIG_STRING(config_plugin_autoload)
&& CONFIG_STRING(config_plugin_autoload)[0])
{
if (string_strcasecmp (CONFIG_STRING(config_plugin_autoload),
"*") == 0)
{
/* auto-load plugins in WeeChat home dir */
if (CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0])
{
ptr_home = getenv ("HOME");
plugin_path = string_replace (CONFIG_STRING(config_plugin_path),
"~", ptr_home);
plugin_path2 = string_replace ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path),
"%h", weechat_home);
util_exec_on_files ((plugin_path2) ?
plugin_path2 : ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path)),
0,
NULL,
&plugin_auto_load_file);
if (plugin_path)
free (plugin_path);
if (plugin_path2)
free (plugin_path2);
}
/* auto-load plugins in WeeChat global lib dir */
dir_name = malloc (strlen (WEECHAT_LIBDIR) + 16);
if (dir_name)
{
snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
"%s/plugins", WEECHAT_LIBDIR);
util_exec_on_files (dir_name, 0, NULL, &plugin_auto_load_file);
free (dir_name);
}
}
else
{
list_plugins = strdup (CONFIG_STRING(config_plugin_autoload));
if (list_plugins)
{
pos = list_plugins;
while (pos && pos[0])
{
pos2 = strchr (pos, ',');
if (pos2)
pos2[0] = '\0';
plugin_load (pos);
if (pos2)
pos = pos2 + 1;
else
pos = NULL;
}
free (list_plugins);
}
}
plugin_autoload_array = string_split (CONFIG_STRING(config_plugin_autoload),
",", 0, 0,
&plugin_autoload_count);
}
/* auto-load plugins in WeeChat home dir */
if (CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0])
{
ptr_home = getenv ("HOME");
plugin_path = string_replace (CONFIG_STRING(config_plugin_path),
"~", ptr_home);
plugin_path2 = string_replace ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path),
"%h", weechat_home);
util_exec_on_files ((plugin_path2) ?
plugin_path2 : ((plugin_path) ?
plugin_path : CONFIG_STRING(config_plugin_path)),
0,
NULL,
&plugin_auto_load_file);
if (plugin_path)
free (plugin_path);
if (plugin_path2)
free (plugin_path2);
}
/* auto-load plugins in WeeChat global lib dir */
dir_name = malloc (strlen (WEECHAT_LIBDIR) + 16);
if (dir_name)
{
snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
"%s/plugins", WEECHAT_LIBDIR);
util_exec_on_files (dir_name, 0, NULL, &plugin_auto_load_file);
free (dir_name);
}
/* free autoload array */
if (plugin_autoload_array)
{
string_free_split (plugin_autoload_array);
plugin_autoload_array = NULL;
}
plugin_autoload_count = 0;
}
/*