summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/script/script-action.c178
-rw-r--r--src/plugins/script/script-action.h5
-rw-r--r--src/plugins/script/script-config.c12
-rw-r--r--src/plugins/script/script-config.h1
-rw-r--r--src/plugins/script/script-repo.c15
-rw-r--r--src/plugins/script/script-repo.h2
-rw-r--r--src/plugins/script/script.c26
-rw-r--r--src/plugins/script/script.h1
8 files changed, 159 insertions, 81 deletions
diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c
index faedbfb84..47794a1b7 100644
--- a/src/plugins/script/script-action.c
+++ b/src/plugins/script/script-action.c
@@ -35,10 +35,10 @@
#include "script-repo.h"
-char *script_actions = NULL;
+char **script_actions = NULL;
-void script_action_install (int quiet);
+void script_action_run_install (int quiet);
/*
@@ -46,7 +46,7 @@ void script_action_install (int quiet);
*/
void
-script_action_list ()
+script_action_run_list ()
{
int i, scripts_loaded;
char hdata_name[128];
@@ -100,7 +100,7 @@ script_action_list ()
*/
void
-script_action_list_input (int send_to_buffer, int translated)
+script_action_run_list_input (int send_to_buffer, int translated)
{
int i, length;
char hdata_name[128], **buf, str_pos[16];
@@ -176,7 +176,7 @@ script_action_list_input (int send_to_buffer, int translated)
*/
void
-script_action_load (const char *name, int quiet)
+script_action_run_load (const char *name, int quiet)
{
char *pos, str_command[1024];
int language;
@@ -219,7 +219,7 @@ script_action_load (const char *name, int quiet)
*/
void
-script_action_unload (const char *name, int quiet)
+script_action_run_unload (const char *name, int quiet)
{
char *pos, hdata_name[128], *filename, *ptr_base_name, str_command[1024];
const char *ptr_filename, *ptr_registered_name;
@@ -324,7 +324,7 @@ script_action_unload (const char *name, int quiet)
*/
void
-script_action_reload (const char *name, int quiet)
+script_action_run_reload (const char *name, int quiet)
{
char *pos, hdata_name[128], *filename, *ptr_base_name, str_command[1024];
const char *ptr_filename, *ptr_registered_name;
@@ -434,7 +434,7 @@ script_action_reload (const char *name, int quiet)
*/
void
-script_action_autoload (const char *name, int quiet, int autoload)
+script_action_run_autoload (const char *name, int quiet, int autoload)
{
struct t_script_repo *ptr_script;
char str_signal[256], *filename;
@@ -509,7 +509,7 @@ script_action_installnext_timer_cb (const void *pointer, void *data,
(void) data;
(void) remaining_calls;
- script_action_install ((pointer) ? 1 : 0);
+ script_action_run_install ((pointer) ? 1 : 0);
return WEECHAT_RC_OK;
}
@@ -630,12 +630,15 @@ script_action_get_next_script_to_install ()
*/
void
-script_action_install (int quiet)
+script_action_run_install (int quiet)
{
struct t_script_repo *ptr_script_to_install;
char *filename, *url;
struct t_hashtable *options;
+ if (!script_download_enabled ())
+ return;
+
while (1)
{
ptr_script_to_install = script_action_get_next_script_to_install ();
@@ -701,7 +704,7 @@ script_action_install (int quiet)
*/
void
-script_action_remove (const char *name, int quiet)
+script_action_run_remove (const char *name, int quiet)
{
struct t_script_repo *ptr_script;
char str_signal[256], *filename;
@@ -783,7 +786,7 @@ script_action_remove (const char *name, int quiet)
*/
int
-script_action_hold (const char *name, int quiet)
+script_action_run_hold (const char *name, int quiet)
{
struct t_script_repo *ptr_script;
@@ -1071,12 +1074,15 @@ script_action_show_source_process_cb (const void *pointer, void *data,
*/
void
-script_action_show (const char *name, int quiet)
+script_action_run_show (const char *name, int quiet)
{
struct t_script_repo *ptr_script;
char *filename, *url;
struct t_hashtable *options;
+ if (!script_download_enabled ())
+ return;
+
if (name)
{
ptr_script = script_repo_search_by_name_ext (name);
@@ -1148,7 +1154,7 @@ script_action_show (const char *name, int quiet)
*/
void
-script_action_showdiff ()
+script_action_run_showdiff ()
{
char str_command[64];
struct t_gui_window *window;
@@ -1181,6 +1187,40 @@ script_action_showdiff ()
}
/*
+ * Adds an action to list of actions.
+ */
+
+void
+script_action_add (const char *action)
+{
+ if (!action)
+ return;
+
+ if (!script_actions)
+ {
+ script_actions = weechat_string_dyn_alloc (256);
+ if (!script_actions)
+ return;
+ }
+
+ if (*script_actions[0])
+ weechat_string_dyn_concat (script_actions, "\n", -1);
+
+ weechat_string_dyn_concat (script_actions, action, -1);
+}
+
+/*
+ * Clears list of actions.
+ */
+
+void
+script_action_clear ()
+{
+ if (script_actions)
+ weechat_string_dyn_copy (script_actions, NULL);
+}
+
+/*
* Runs planned actions.
*
* Returns:
@@ -1189,18 +1229,18 @@ script_action_showdiff ()
*/
int
-script_action_run ()
+script_action_run_all ()
{
char **actions, **argv, **argv_eol, *ptr_action;
int num_actions, argc, i, j, quiet, script_found;
struct t_script_repo *ptr_script;
- if (!script_actions)
+ if (!script_actions || !script_actions[0])
return 0;
script_get_loaded_plugins ();
- actions = weechat_string_split (script_actions, "\n", NULL,
+ actions = weechat_string_split (*script_actions, "\n", NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
@@ -1269,59 +1309,59 @@ script_action_run ()
if (argc > 1)
{
if (weechat_strcasecmp (argv[1], "-i") == 0)
- script_action_list_input (0, 0);
+ script_action_run_list_input (0, 0);
else if (weechat_strcasecmp (argv[1], "-il") == 0)
- script_action_list_input (0, 1);
+ script_action_run_list_input (0, 1);
else if (weechat_strcasecmp (argv[1], "-o") == 0)
- script_action_list_input (1, 0);
+ script_action_run_list_input (1, 0);
else if (weechat_strcasecmp (argv[1], "-ol") == 0)
- script_action_list_input (1, 1);
+ script_action_run_list_input (1, 1);
else
- script_action_list ();
+ script_action_run_list ();
}
else
- script_action_list ();
+ script_action_run_list ();
}
else if (weechat_strcasecmp (argv[0], "load") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_load (argv[j], quiet);
+ script_action_run_load (argv[j], quiet);
}
}
else if (weechat_strcasecmp (argv[0], "unload") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_unload (argv[j], quiet);
+ script_action_run_unload (argv[j], quiet);
}
}
else if (weechat_strcasecmp (argv[0], "reload") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_reload (argv[j], quiet);
+ script_action_run_reload (argv[j], quiet);
}
}
else if (weechat_strcasecmp (argv[0], "autoload") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_autoload (argv[j], quiet, 1);
+ script_action_run_autoload (argv[j], quiet, 1);
}
}
else if (weechat_strcasecmp (argv[0], "noautoload") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_autoload (argv[j], quiet, 0);
+ script_action_run_autoload (argv[j], quiet, 0);
}
}
else if (weechat_strcasecmp (argv[0], "toggleautoload") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_autoload (argv[j], quiet, -1);
+ script_action_run_autoload (argv[j], quiet, -1);
}
}
else if (weechat_strcasecmp (argv[0], "install") == 0)
@@ -1360,13 +1400,13 @@ script_action_run ()
}
}
if (script_found)
- script_action_install (quiet);
+ script_action_run_install (quiet);
}
else if (weechat_strcasecmp (argv[0], "remove") == 0)
{
for (j = 1; j < argc; j++)
{
- script_action_remove (argv[j], quiet);
+ script_action_run_remove (argv[j], quiet);
}
}
else if (weechat_strcasecmp (argv[0], "installremove") == 0)
@@ -1385,7 +1425,7 @@ script_action_run ()
}
else if (ptr_script->status & SCRIPT_STATUS_INSTALLED)
{
- script_action_remove (argv[j], quiet);
+ script_action_run_remove (argv[j], quiet);
}
else
{
@@ -1401,14 +1441,14 @@ script_action_run ()
}
}
if (script_found)
- script_action_install (quiet);
+ script_action_run_install (quiet);
}
else if (weechat_strcasecmp (argv[0], "hold") == 0)
{
script_found = 0;
for (j = 1; j < argc; j++)
{
- if (script_action_hold (argv[j], quiet))
+ if (script_action_run_hold (argv[j], quiet))
script_found = 1;
}
if (script_found)
@@ -1418,13 +1458,13 @@ script_action_run ()
{
if (!script_buffer)
script_buffer_open ();
- script_action_show ((argc >= 2) ? argv[1] : NULL,
- quiet);
+ script_action_run_show ((argc >= 2) ? argv[1] : NULL,
+ quiet);
weechat_buffer_set (script_buffer, "display", "1");
}
else if (weechat_strcasecmp (argv[0], "showdiff") == 0)
{
- script_action_showdiff ();
+ script_action_run_showdiff ();
}
else if (weechat_strcasecmp (argv[0], "upgrade") == 0)
{
@@ -1445,7 +1485,7 @@ script_action_run ()
}
}
if (script_found)
- script_action_install (quiet);
+ script_action_run_install (quiet);
else
{
weechat_printf (NULL,
@@ -1462,41 +1502,11 @@ script_action_run ()
weechat_string_free_split (actions);
}
- free (script_actions);
- script_actions = NULL;
+ script_action_clear ();
return 1;
}
-
-/*
- * Adds an action to list of actions.
- */
-
-void
-script_action_add (const char *action)
-{
- char *new_actions;
-
- if (!action)
- return;
-
- if (script_actions)
- {
- new_actions = realloc (script_actions,
- strlen (script_actions) + 1 + strlen (action) + 1);
- if (!new_actions)
- return;
- script_actions = new_actions;
- strcat (script_actions, "\n");
- strcat (script_actions, action);
- }
- else
- {
- script_actions = strdup (action);
- }
-}
-
/*
* Schedules an action.
*
@@ -1507,10 +1517,11 @@ script_action_add (const char *action)
void
script_action_schedule (const char *action, int need_repository, int quiet)
{
- script_action_add (action);
-
/* create again "script" directory, just in case it has been removed */
- weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755);
+ if (!weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755))
+ return;
+
+ script_action_add (action);
if (need_repository)
{
@@ -1518,11 +1529,28 @@ script_action_schedule (const char *action, int need_repository, int quiet)
{
if (!scripts_repo)
script_repo_file_read (quiet);
- script_action_run ();
+ script_action_run_all ();
}
else
- script_repo_file_update (quiet);
+ {
+ if (!script_repo_file_update (quiet))
+ script_action_clear ();
+ }
}
else
- script_action_run ();
+ script_action_run_all ();
+}
+
+/*
+ * Ends script action.
+ */
+
+void
+script_action_end ()
+{
+ if (script_actions)
+ {
+ weechat_string_dyn_free (script_actions, 1);
+ script_actions = NULL;
+ }
}
diff --git a/src/plugins/script/script-action.h b/src/plugins/script/script-action.h
index 2b48aac82..05738e449 100644
--- a/src/plugins/script/script-action.h
+++ b/src/plugins/script/script-action.h
@@ -20,10 +20,11 @@
#ifndef WEECHAT_PLUGIN_SCRIPT_ACTION_H
#define WEECHAT_PLUGIN_SCRIPT_ACTION_H
-extern char *script_actions;
+extern char **script_actions;
-extern int script_action_run ();
+extern int script_action_run_all ();
extern void script_action_schedule (const char *action, int need_repository,
int quiet);
+extern void script_action_end ();
#endif /* WEECHAT_PLUGIN_SCRIPT_ACTION_H */
diff --git a/src/plugins/script/script-config.c b/src/plugins/script/script-config.c
index c8ae790af..ea5f0276c 100644
--- a/src/plugins/script/script-config.c
+++ b/src/plugins/script/script-config.c
@@ -79,6 +79,7 @@ struct t_config_option *script_config_color_text_version_selected;
struct t_config_option *script_config_scripts_autoload;
struct t_config_option *script_config_scripts_cache_expire;
+struct t_config_option *script_config_scripts_download_enabled;
struct t_config_option *script_config_scripts_download_timeout;
struct t_config_option *script_config_scripts_hold;
struct t_config_option *script_config_scripts_path;
@@ -753,6 +754,17 @@ script_config_init ()
"0 = always expire)"),
NULL, -1, 525600, "1440", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ script_config_scripts_download_enabled = weechat_config_new_option (
+ script_config_file, ptr_section,
+ "download_enabled", "boolean",
+ N_("enable download of files from the scripts repository when the "
+ "/script command is used (list of scripts and scripts themselves); "
+ "the list of scripts is downloaded from the URL specified in the "
+ "option script.scripts.url; WeeChat will sometimes download again "
+ "the list of scripts when you use the /script command, even if "
+ "you don't install a script"),
+ NULL, 0, 0, "off", NULL, 0,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
script_config_scripts_download_timeout = weechat_config_new_option (
script_config_file, ptr_section,
"download_timeout", "integer",
diff --git a/src/plugins/script/script-config.h b/src/plugins/script/script-config.h
index 230d2a043..6c6281ecb 100644
--- a/src/plugins/script/script-config.h
+++ b/src/plugins/script/script-config.h
@@ -62,6 +62,7 @@ extern struct t_config_option *script_config_color_text_version_selected;
extern struct t_config_option *script_config_scripts_autoload;
extern struct t_config_option *script_config_scripts_cache_expire;
+extern struct t_config_option *script_config_scripts_download_enabled;
extern struct t_config_option *script_config_scripts_download_timeout;
extern struct t_config_option *script_config_scripts_hold;
extern struct t_config_option *script_config_scripts_path;
diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c
index fb0407263..a218bc9d9 100644
--- a/src/plugins/script/script-repo.c
+++ b/src/plugins/script/script-repo.c
@@ -1478,7 +1478,7 @@ script_repo_file_update_process_cb (const void *pointer, void *data,
{
if (script_buffer)
script_buffer_refresh (1);
- if (!script_action_run ())
+ if (!script_action_run_all ())
script_buffer_refresh (1);
}
else
@@ -1490,19 +1490,26 @@ script_repo_file_update_process_cb (const void *pointer, void *data,
/*
* Updates repository file and reads it.
+ *
+ * Returns:
+ * 0: error
+ * 1: OK
*/
-void
+int
script_repo_file_update (int quiet)
{
char *filename, *url;
struct t_hashtable *options;
+ if (!script_download_enabled ())
+ return 0;
+
script_repo_remove_all ();
filename = script_config_get_xml_filename ();
if (!filename)
- return;
+ return 0;
options = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -1534,6 +1541,8 @@ script_repo_file_update (int quiet)
}
free (filename);
+
+ return 1;
}
/*
diff --git a/src/plugins/script/script-repo.h b/src/plugins/script/script-repo.h
index 4408ff5b4..5630be93b 100644
--- a/src/plugins/script/script-repo.h
+++ b/src/plugins/script/script-repo.h
@@ -80,7 +80,7 @@ extern void script_repo_filter_scripts (const char *search);
extern int script_repo_file_exists ();
extern int script_repo_file_is_uptodate ();
extern int script_repo_file_read (int quiet);
-extern void script_repo_file_update (int quiet);
+extern int script_repo_file_update (int quiet);
extern struct t_hdata *script_repo_hdata_script_cb (const void *pointer,
void *data,
const char *hdata_name);
diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c
index eab823421..9d67ea5f7 100644
--- a/src/plugins/script/script.c
+++ b/src/plugins/script/script.c
@@ -27,6 +27,7 @@
#include "../weechat-plugin.h"
#include "script.h"
+#include "script-action.h"
#include "script-buffer.h"
#include "script-command.h"
#include "script-completion.h"
@@ -98,6 +99,29 @@ script_language_search_by_extension (const char *extension)
}
/*
+ * Checks if download of scripts is enabled.
+ *
+ * Returns:
+ * 0: download NOT enabled (an error is displayed)
+ * 1: download enabled
+ */
+
+int
+script_download_enabled ()
+{
+ if (weechat_config_boolean (script_config_scripts_download_enabled))
+ return 1;
+
+ /* download not enabled: display an error */
+ weechat_printf (NULL,
+ _("%s%s: download of scripts is disabled by default; "
+ "see /help script.scripts.download_enabled"),
+ weechat_prefix ("error"),
+ SCRIPT_PLUGIN_NAME);
+ return 0;
+}
+
+/*
* Builds download URL (to use with hook_process or hook_process_hashtable).
*
* Note: result must be freed after use.
@@ -394,5 +418,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
script_config_free ();
+ script_action_end ();
+
return WEECHAT_RC_OK;
}
diff --git a/src/plugins/script/script.h b/src/plugins/script/script.h
index 802af0465..11106e350 100644
--- a/src/plugins/script/script.h
+++ b/src/plugins/script/script.h
@@ -34,6 +34,7 @@ extern struct t_hashtable *script_loaded;
extern int script_language_search (const char *language);
extern int script_language_search_by_extension (const char *extension);
+extern int script_download_enabled ();
extern char *script_build_download_url (const char *url);
extern void script_get_loaded_plugins ();
extern void script_get_scripts ();