mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
script: add option script.scripts.url_force_https (closes #253)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -95,6 +95,43 @@ script_language_search_by_extension (const char *extension)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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).
|
||||
*/
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user