summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-11-15 18:28:34 +0100
committerSébastien Helleu <flashcode@flashtux.org>2014-11-15 18:28:34 +0100
commit786999b4a30c9e83bef21e94f30a8439c2fe646f (patch)
tree9863d7e219fd2825f4fe5f4ce4d25f3455c012e0 /src
parentbc3c81ee4f467ba4a3feb7884dae112b0f23532e (diff)
downloadweechat-786999b4a30c9e83bef21e94f30a8439c2fe646f.zip
script: add option script.scripts.url_force_https (closes #253)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/script/script-action.c12
-rw-r--r--src/plugins/script/script-config.c9
-rw-r--r--src/plugins/script/script-config.h1
-rw-r--r--src/plugins/script/script-repo.c8
-rw-r--r--src/plugins/script/script.c37
-rw-r--r--src/plugins/script/script.h2
6 files changed, 52 insertions, 17 deletions
diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c
index 3f2423a70..0683bfd8b 100644
--- a/src/plugins/script/script-action.c
+++ b/src/plugins/script/script-action.c
@@ -600,7 +600,6 @@ script_action_install (int quiet)
{
struct t_script_repo *ptr_script_to_install;
char *filename, *url;
- int length;
struct t_hashtable *options;
while (1)
@@ -638,8 +637,7 @@ script_action_install (int quiet)
NULL);
if (options)
{
- length = 4 + strlen (ptr_script_to_install->url) + 1;
- url = malloc (length);
+ url = script_build_download_url (ptr_script_to_install->url);
if (url)
{
if (!weechat_config_boolean (script_config_look_quiet_actions))
@@ -649,9 +647,6 @@ script_action_install (int quiet)
SCRIPT_PLUGIN_NAME,
ptr_script_to_install->name_with_extension);
}
-
- snprintf (url, length, "url:%s",
- ptr_script_to_install->url);
weechat_hashtable_set (options, "file_out", filename);
weechat_hook_process_hashtable (url, options, 30000,
&script_action_install_process_cb,
@@ -1031,7 +1026,6 @@ script_action_show (const char *name, int quiet)
{
struct t_script_repo *ptr_script;
char *filename, *url;
- int length;
struct t_hashtable *options;
if (name)
@@ -1069,11 +1063,9 @@ script_action_show (const char *name, int quiet)
NULL);
if (options)
{
- length = 4 + strlen (ptr_script->url) + 1;
- url = malloc (length);
+ url = script_build_download_url (ptr_script->url);
if (url)
{
- snprintf (url, length, "url:%s", ptr_script->url);
weechat_hashtable_set (options, "file_out", filename);
weechat_hook_process_hashtable (url, options, 30000,
&script_action_show_source_process_cb,
diff --git a/src/plugins/script/script-config.c b/src/plugins/script/script-config.c
index 04a380215..7dbe04234 100644
--- a/src/plugins/script/script-config.c
+++ b/src/plugins/script/script-config.c
@@ -85,6 +85,7 @@ struct t_config_option *script_config_scripts_cache_expire;
struct t_config_option *script_config_scripts_dir;
struct t_config_option *script_config_scripts_hold;
struct t_config_option *script_config_scripts_url;
+struct t_config_option *script_config_scripts_url_force_https;
/*
@@ -705,6 +706,14 @@ script_config_init ()
N_("URL for file with list of scripts"),
NULL, 0, 0, "http://weechat.org/files/plugins.xml.gz", NULL, 0, NULL, NULL,
NULL, NULL, NULL, NULL);
+ script_config_scripts_url_force_https = weechat_config_new_option (
+ script_config_file, ptr_section,
+ "url_force_https", "boolean",
+ N_("force use of HTTPS for downloads (index and scripts); "
+ "you should disable this option only if you have problems with "
+ "the downloads"),
+ NULL, 0, 0, "on", NULL, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL);
return 1;
}
diff --git a/src/plugins/script/script-config.h b/src/plugins/script/script-config.h
index 8a45a0070..4b5a22097 100644
--- a/src/plugins/script/script-config.h
+++ b/src/plugins/script/script-config.h
@@ -65,6 +65,7 @@ extern struct t_config_option *script_config_scripts_cache_expire;
extern struct t_config_option *script_config_scripts_dir;
extern struct t_config_option *script_config_scripts_hold;
extern struct t_config_option *script_config_scripts_url;
+extern struct t_config_option *script_config_scripts_url_force_https;
extern const char *script_config_get_diff_command ();
extern char *script_config_get_dir ();
diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c
index b0f9155ef..a7288b005 100644
--- a/src/plugins/script/script-repo.c
+++ b/src/plugins/script/script-repo.c
@@ -1445,7 +1445,6 @@ void
script_repo_file_update (int quiet)
{
char *filename, *url;
- int length;
struct t_hashtable *options;
script_repo_remove_all ();
@@ -1461,8 +1460,8 @@ script_repo_file_update (int quiet)
NULL);
if (options)
{
- length = 4 + strlen (weechat_config_string (script_config_scripts_url)) + 1;
- url = malloc (length);
+ url = script_build_download_url (
+ weechat_config_string (script_config_scripts_url));
if (url)
{
if (!quiet)
@@ -1471,9 +1470,6 @@ script_repo_file_update (int quiet)
_("%s: downloading list of scripts..."),
SCRIPT_PLUGIN_NAME);
}
-
- snprintf (url, length, "url:%s",
- weechat_config_string (script_config_scripts_url));
weechat_hashtable_set (options, "file_out", filename);
weechat_hook_process_hashtable (url, options, 30000,
&script_repo_file_update_process_cb,
diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c
index 4b8ffae58..805922915 100644
--- a/src/plugins/script/script.c
+++ b/src/plugins/script/script.c
@@ -96,6 +96,43 @@ script_language_search_by_extension (const char *extension)
}
/*
+ * Builds download URL (to use with hook_process or hook_process_hashtable).
+ *
+ * If the option script.scripts.url_force_https is enabled, the protocol is
+ * forced to HTTPS (if URL starts with "http://").
+ *
+ * Note: result must be freed after use.
+ */
+
+char *
+script_build_download_url (const char *url)
+{
+ char *result;
+ int length;
+
+ if (!url || !url[0])
+ return NULL;
+
+ /* length of url + "url:" + 1 (for httpS) */
+ length = 4 + 1 + strlen (url) + 1;
+ result = malloc (length);
+ if (!result)
+ return NULL;
+
+ if (weechat_config_boolean (script_config_scripts_url_force_https)
+ && (weechat_strncasecmp (url, "http://", 7) == 0))
+ {
+ snprintf (result, length, "url:https://%s", url + 7);
+ }
+ else
+ {
+ snprintf (result, length, "url:%s", url);
+ }
+
+ return result;
+}
+
+/*
* Gets loaded plugins (in array of integers) and scripts (in hashtable).
*/
diff --git a/src/plugins/script/script.h b/src/plugins/script/script.h
index 6ca557003..686f7a7d7 100644
--- a/src/plugins/script/script.h
+++ b/src/plugins/script/script.h
@@ -34,7 +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 void script_actions_add (const char *action);
+extern char *script_build_download_url (const char *url);
extern void script_get_loaded_plugins_and_scripts ();
#endif /* WEECHAT_SCRIPT_H */