summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-05-02 11:56:25 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-05-11 21:06:34 +0200
commit0f9640a5f33d4d0c76df75cb7a6cb07baac049f0 (patch)
tree7d09fe5119b11d4d38313098e6846e2413ff0a19 /src/plugins
parent4c5fcb743b2e512c407a09ca95d155c9e6edd2bd (diff)
downloadweechat-0f9640a5f33d4d0c76df75cb7a6cb07baac049f0.zip
core: split WeeChat home in 4 directories, use XDG directories by default (issue #1285)
The 4 directories (which can be the same): - config: configuration files, certificates - data: log/upgrade files, local plugins, scripts, xfer files - cache: script repository, scripts downloaded (temporary location) - runtime: FIFO pipe, relay UNIX sockets
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/fifo/fifo-command.c5
-rw-r--r--src/plugins/fifo/fifo.c14
-rw-r--r--src/plugins/irc/irc-command.c3
-rw-r--r--src/plugins/irc/irc-sasl.c12
-rw-r--r--src/plugins/irc/irc-server.c12
-rw-r--r--src/plugins/logger/logger.c17
-rw-r--r--src/plugins/plugin-api-info.c101
-rw-r--r--src/plugins/plugin-api.c27
-rw-r--r--src/plugins/plugin-script.c96
-rw-r--r--src/plugins/plugin.c12
-rw-r--r--src/plugins/python/weechat-python.c14
-rw-r--r--src/plugins/relay/relay-network.c12
-rw-r--r--src/plugins/relay/relay-server.c26
-rw-r--r--src/plugins/script/script-action.c2
-rw-r--r--src/plugins/script/script-completion.c18
-rw-r--r--src/plugins/script/script-config.c34
-rw-r--r--src/plugins/script/script-repo.c32
-rw-r--r--src/plugins/script/script.c2
-rw-r--r--src/plugins/spell/spell.c4
-rw-r--r--src/plugins/xfer/xfer-file.c12
-rw-r--r--src/plugins/xfer/xfer.c28
21 files changed, 355 insertions, 128 deletions
diff --git a/src/plugins/fifo/fifo-command.c b/src/plugins/fifo/fifo-command.c
index 3995fe379..11567d2bf 100644
--- a/src/plugins/fifo/fifo-command.c
+++ b/src/plugins/fifo/fifo-command.c
@@ -102,7 +102,8 @@ fifo_command_init ()
"\n"
"FIFO pipe is used as remote control of WeeChat: you can send "
"commands or text to the FIFO pipe from your shell.\n"
- "By default the FIFO pipe is in ~/.weechat/weechat_fifo\n"
+ "By default the FIFO pipe is called weechat_fifo and saved in the "
+ "WeeChat runtime directory (see /debug dirs).\n"
"\n"
"The expected format is one of:\n"
" plugin.buffer *text or command here\n"
@@ -110,7 +111,7 @@ fifo_command_init ()
"\n"
"For example to change your freenode nick:\n"
" echo 'irc.server.freenode */nick newnick' "
- ">~/.weechat/weechat_fifo\n"
+ ">/run/user/1000/weechat/weechat_fifo\n"
"\n"
"Please read the user's guide for more info and examples.\n"
"\n"
diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c
index a266f7f69..d9d8f3ac7 100644
--- a/src/plugins/fifo/fifo.c
+++ b/src/plugins/fifo/fifo.c
@@ -65,16 +65,26 @@ void
fifo_create ()
{
struct stat st;
+ struct t_hashtable *options;
if (!weechat_config_boolean (fifo_config_file_enabled))
return;
if (!fifo_filename)
{
- /* replace %h and "~", evaluate path */
+ /* evaluate path */
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "runtime");
fifo_filename = weechat_string_eval_path_home (
weechat_config_string (fifo_config_file_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
}
if (!fifo_filename)
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 81ea2156e..48581dfb2 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -6570,7 +6570,8 @@ irc_command_init ()
" /dcc send toto /home/foo/bar.txt"),
"chat %(nicks)"
" || send %(nicks) "
- "%(filename:${modifier:eval_path_home,,${xfer.file.upload_path}})",
+ "%(filename:${modifier:eval_path_home,directory=data,"
+ "${xfer.file.upload_path}})",
&irc_command_dcc, NULL, NULL);
weechat_hook_command (
"dehalfop",
diff --git a/src/plugins/irc/irc-sasl.c b/src/plugins/irc/irc-sasl.c
index 78cc571fe..6a0e42f40 100644
--- a/src/plugins/irc/irc-sasl.c
+++ b/src/plugins/irc/irc-sasl.c
@@ -95,13 +95,23 @@ char *
irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
{
char *key_path, *content;
+ struct t_hashtable *options;
if (!sasl_key)
return NULL;
content = NULL;
- key_path = weechat_string_eval_path_home (sasl_key, NULL, NULL, NULL);
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "config");
+ key_path = weechat_string_eval_path_home (sasl_key, NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (key_path)
content = weechat_file_get_content (key_path);
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index e1cb8ea44..a8fc93ea4 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -4481,6 +4481,7 @@ irc_server_gnutls_callback (const void *pointer, void *data,
char *ssl_password;
const char *ptr_cert_path, *ptr_fingerprint;
int rc, ret, fingerprint_match, hostname_match, cert_temp_init;
+ struct t_hashtable *options;
#if LIBGNUTLS_VERSION_NUMBER >= 0x010706 /* 1.7.6 */
gnutls_datum_t cinfo;
int rinfo;
@@ -4724,8 +4725,17 @@ irc_server_gnutls_callback (const void *pointer, void *data,
IRC_SERVER_OPTION_SSL_CERT);
if (ptr_cert_path && ptr_cert_path[0])
{
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "config");
cert_path = weechat_string_eval_path_home (ptr_cert_path,
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (cert_path)
{
cert_str = weechat_file_get_content (cert_path);
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index 1fd9acc0e..fae9c17b3 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -59,8 +59,7 @@ struct t_hook *logger_hook_print = NULL;
* Gets logger file path option.
*
* Special vars are replaced:
- * - "%h" (at beginning of string): WeeChat home
- * - "~": user home
+ * - with call to function string_eval_path_home
* - date/time specifiers (see man strftime)
*
* Note: result must be freed after use.
@@ -73,13 +72,23 @@ logger_get_file_path ()
int length;
time_t seconds;
struct tm *date_tmp;
+ struct t_hashtable *options;
path = NULL;
path2 = NULL;
- /* replace %h and "~", evaluate path */
+ /* evaluate path */
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "data");
path = weechat_string_eval_path_home (
- weechat_config_string (logger_config_file_path), NULL, NULL, NULL);
+ weechat_config_string (logger_config_file_path), NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (!path)
goto end;
diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c
index 773742581..4dd6e1d47 100644
--- a/src/plugins/plugin-api-info.c
+++ b/src/plugins/plugin-api-info.c
@@ -183,27 +183,91 @@ plugin_api_info_dir_separator_cb (const void *pointer, void *data,
}
/*
- * Returns WeeChat info "weechat_dir".
+ * Returns an absolute path to directory.
+ *
+ * Note: result must be freed after use.
*/
char *
-plugin_api_info_weechat_dir_cb (const void *pointer, void *data,
- const char *info_name,
- const char *arguments)
+plugin_api_info_absolute_path (const char *directory)
{
- char weechat_dir_absolute_path[PATH_MAX];
+ char absolute_path[PATH_MAX];
+
+ if (!realpath (directory, absolute_path))
+ return NULL;
+ return strdup ((absolute_path[0]) ? absolute_path : directory);
+}
+
+/*
+ * Returns WeeChat info "weechat_config_dir".
+ */
+char *
+plugin_api_info_weechat_config_dir_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
(void) arguments;
- if (!realpath (weechat_home, weechat_dir_absolute_path))
- return NULL;
+ return plugin_api_info_absolute_path (weechat_config_dir);
+}
+
+/*
+ * Returns WeeChat info "weechat_data_dir".
+ */
+
+char *
+plugin_api_info_weechat_data_dir_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) info_name;
+ (void) arguments;
+
+ return plugin_api_info_absolute_path (weechat_data_dir);
+}
+
+/*
+ * Returns WeeChat info "weechat_cache_dir".
+ */
+
+char *
+plugin_api_info_weechat_cache_dir_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) info_name;
+ (void) arguments;
+
+ return plugin_api_info_absolute_path (weechat_cache_dir);
+}
+
+/*
+ * Returns WeeChat info "weechat_runtime_dir".
+ */
+
+char *
+plugin_api_info_weechat_runtime_dir_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) info_name;
+ (void) arguments;
- return strdup ((weechat_dir_absolute_path[0]) ?
- weechat_dir_absolute_path : weechat_home);
+ return plugin_api_info_absolute_path (weechat_runtime_dir);
}
/*
@@ -1802,8 +1866,23 @@ plugin_api_info_init ()
N_("directory separator"),
NULL, &plugin_api_info_dir_separator_cb, NULL, NULL);
hook_info (NULL, "weechat_dir",
- N_("WeeChat directory"),
- NULL, &plugin_api_info_weechat_dir_cb, NULL, NULL);
+ N_("WeeChat directory "
+ "(*deprecated* since version 3.2, replaced by "
+ "\"weechat_config_dir\", \"weechat_data_dir\", "
+ "\"weechat_cache_dir\" and \"weechat_runtime_dir\")"),
+ NULL, &plugin_api_info_weechat_data_dir_cb, NULL, NULL);
+ hook_info (NULL, "weechat_config_dir",
+ N_("WeeChat config directory"),
+ NULL, &plugin_api_info_weechat_config_dir_cb, NULL, NULL);
+ hook_info (NULL, "weechat_data_dir",
+ N_("WeeChat data directory"),
+ NULL, &plugin_api_info_weechat_data_dir_cb, NULL, NULL);
+ hook_info (NULL, "weechat_cache_dir",
+ N_("WeeChat cache directory"),
+ NULL, &plugin_api_info_weechat_cache_dir_cb, NULL, NULL);
+ hook_info (NULL, "weechat_runtime_dir",
+ N_("WeeChat runtime directory"),
+ NULL, &plugin_api_info_weechat_runtime_dir_cb, NULL, NULL);
hook_info (NULL, "weechat_libdir",
N_("WeeChat \"lib\" directory"),
NULL, &plugin_api_info_weechat_libdir_cb, NULL, NULL);
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index b22e0be69..95d46bf4c 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -431,13 +431,36 @@ plugin_api_modifier_eval_path_home_cb (const void *pointer, void *data,
const char *modifier_data,
const char *string)
{
+ struct t_hashtable *options;
+ const char *ptr_directory;
+ char *result;
+
/* make C compiler happy */
(void) pointer;
(void) data;
(void) modifier;
- (void) modifier_data;
- return string_eval_path_home (string, NULL, NULL, NULL);
+ options = NULL;
+ ptr_directory = (modifier_data
+ && (strncmp (modifier_data, "directory=", 10) == 0)) ?
+ modifier_data + 10 : NULL;
+ if (ptr_directory)
+ {
+ options = hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ hashtable_set (options, "directory", ptr_directory);
+ }
+
+ result = string_eval_path_home (string, NULL, NULL, options);
+
+ if (options)
+ hashtable_free (options);
+
+ return result;
}
/*
diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c
index d643e4df8..3feb4b44b 100644
--- a/src/plugins/plugin-script.c
+++ b/src/plugins/plugin-script.c
@@ -134,26 +134,22 @@ plugin_script_info_version_cb (const void *pointer, void *data,
}
/*
- * Creates directories for plugin in WeeChat home:
- * - ~/.weechat/XXX/
- * - ~/.weechat/XXX/autoload/
+ * Creates directories for plugin in WeeChat data directory:
+ * - ${weechat_data_dir}/xxx
+ * - ${weechat_data_dir}/xxx/autoload
*/
void
plugin_script_create_dirs (struct t_weechat_plugin *weechat_plugin)
{
- char *string;
- int length;
-
- weechat_mkdir_home (weechat_plugin->name, 0755);
- length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1;
- string = malloc (length);
- if (string)
- {
- snprintf (string, length, "%s/autoload", weechat_plugin->name);
- weechat_mkdir_home (string, 0755);
- free (string);
- }
+ char path[PATH_MAX];
+
+ snprintf (path, sizeof (path),
+ "${weechat_data_dir}/%s", weechat_plugin->name);
+ weechat_mkdir_home (path, 0755);
+ snprintf (path, sizeof (path),
+ "${weechat_data_dir}/%s/autoload", weechat_plugin->name);
+ weechat_mkdir_home (path, 0755);
}
/*
@@ -461,26 +457,26 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
void (*callback)(void *data,
const char *filename))
{
- char *dir_home, *dir_name;
+ char *weechat_data_dir, *dir_name;
int dir_length;
- /* build directory, adding WeeChat home */
- dir_home = weechat_info_get ("weechat_dir", "");
- if (!dir_home)
+ /* build directory, adding WeeChat data directory */
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
+ if (!weechat_data_dir)
return;
- dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
+ dir_length = strlen (weechat_data_dir) + strlen (weechat_plugin->name) + 16;
dir_name = malloc (dir_length);
if (!dir_name)
{
- free (dir_home);
+ free (weechat_data_dir);
return;
}
snprintf (dir_name, dir_length,
- "%s/%s/autoload", dir_home, weechat_plugin->name);
+ "%s/%s/autoload", weechat_data_dir, weechat_plugin->name);
weechat_exec_on_files (dir_name, 0, 0, callback, NULL);
- free (dir_home);
+ free (weechat_data_dir);
free (dir_name);
}
@@ -542,64 +538,64 @@ char *
plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
const char *filename)
{
- char *final_name, *dir_home, *dir_system;
+ char *final_name, *weechat_data_dir, *dir_system;
int length;
struct stat st;
if (filename[0] == '~')
return weechat_string_expand_home (filename);
- dir_home = weechat_info_get ("weechat_dir", "");
- if (dir_home)
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
+ if (weechat_data_dir)
{
/* try WeeChat user's autoload dir */
- length = strlen (dir_home) + strlen (weechat_plugin->name) + 8 +
+ length = strlen (weechat_data_dir) + strlen (weechat_plugin->name) + 8 +
strlen (filename) + 16;
final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
"%s/%s/autoload/%s",
- dir_home, weechat_plugin->name, filename);
+ weechat_data_dir, weechat_plugin->name, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
- free (dir_home);
+ free (weechat_data_dir);
return final_name;
}
free (final_name);
}
/* try WeeChat language user's dir */
- length = strlen (dir_home) + strlen (weechat_plugin->name) +
+ length = strlen (weechat_data_dir) + strlen (weechat_plugin->name) +
strlen (filename) + 16;
final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
- "%s/%s/%s", dir_home, weechat_plugin->name, filename);
+ "%s/%s/%s", weechat_data_dir, weechat_plugin->name, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
- free (dir_home);
+ free (weechat_data_dir);
return final_name;
}
free (final_name);
}
/* try WeeChat user's dir */
- length = strlen (dir_home) + strlen (filename) + 16;
+ length = strlen (weechat_data_dir) + strlen (filename) + 16;
final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
- "%s/%s", dir_home, filename);
+ "%s/%s", weechat_data_dir, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
- free (dir_home);
+ free (weechat_data_dir);
return final_name;
}
free (final_name);
}
- free (dir_home);
+ free (weechat_data_dir);
}
/* try WeeChat system dir */
@@ -1218,7 +1214,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
char **list)
{
char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path;
- char *symlink_path, str_signal[128], *ptr_list, *dir_home, *dir_separator;
+ char *symlink_path, str_signal[128], *ptr_list, *weechat_data_dir, *dir_separator;
int argc, i, length, rc, autoload, existing_script, script_loaded;
struct t_plugin_script *ptr_script;
@@ -1283,20 +1279,20 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
*quiet, 0);
/* move file from install dir to language dir */
- dir_home = weechat_info_get ("weechat_dir", "");
- length = strlen (dir_home) + strlen (weechat_plugin->name) +
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
+ length = strlen (weechat_data_dir) + strlen (weechat_plugin->name) +
strlen (base_name) + 16;
new_path = malloc (length);
if (new_path)
{
snprintf (new_path, length, "%s/%s/%s",
- dir_home, weechat_plugin->name, base_name);
+ weechat_data_dir, weechat_plugin->name, base_name);
if (rename (name, new_path) == 0)
{
/* make link in autoload dir */
if (autoload)
{
- length = strlen (dir_home) +
+ length = strlen (weechat_data_dir) +
strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16;
autoload_path = malloc (length);
@@ -1304,7 +1300,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
{
snprintf (autoload_path, length,
"%s/%s/autoload/%s",
- dir_home, weechat_plugin->name,
+ weechat_data_dir, weechat_plugin->name,
base_name);
dir_separator = weechat_info_get ("dir_separator", "");
length = 2 + strlen (dir_separator) +
@@ -1347,8 +1343,8 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
free (new_path);
}
free (base_name);
- if (dir_home)
- free (dir_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
}
free (name);
}
@@ -1442,7 +1438,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
char **list)
{
char **argv, *name, *ptr_base_name, *base_name, *autoload_path;
- char *symlink_path, *ptr_list, *dir_home, *dir_separator;
+ char *symlink_path, *ptr_list, *weechat_data_dir, *dir_separator;
int argc, i, length, rc, autoload;
if (!*list)
@@ -1490,8 +1486,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
base_name = strdup (ptr_base_name);
if (base_name)
{
- dir_home = weechat_info_get ("weechat_dir", "");
- length = strlen (dir_home) +
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
+ length = strlen (weechat_data_dir) +
strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16;
autoload_path = malloc (length);
@@ -1499,7 +1495,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
{
snprintf (autoload_path, length,
"%s/%s/autoload/%s",
- dir_home, weechat_plugin->name,
+ weechat_data_dir, weechat_plugin->name,
base_name);
if (autoload)
{
@@ -1525,8 +1521,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
free (autoload_path);
}
free (base_name);
- if (dir_home)
- free (dir_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
}
free (name);
}
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 3982e04c5..26cbff783 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -1017,6 +1017,7 @@ plugin_auto_load (char *force_plugin_autoload,
struct t_weechat_plugin *ptr_plugin;
struct t_plugin_args plugin_args;
struct t_arraylist *arraylist;
+ struct t_hashtable *options;
int length, i;
plugin_args.argc = argc;
@@ -1046,8 +1047,17 @@ plugin_auto_load (char *force_plugin_autoload,
&& CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0])
{
+ options = hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ hashtable_set (options, "directory", "data");
plugin_path = string_eval_path_home (CONFIG_STRING(config_plugin_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ hashtable_free (options);
if (plugin_path)
{
dir_exec_on_files (plugin_path, 1, 0,
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c
index 19ad02179..1e84a6cbd 100644
--- a/src/plugins/python/weechat-python.c
+++ b/src/plugins/python/weechat-python.c
@@ -797,7 +797,7 @@ weechat_python_load (const char *filename, const char *code)
#endif /* PY_MAJOR_VERSION >= 3 */
FILE *fp;
PyObject *python_path, *path, *module_main, *globals, *rc;
- char *weechat_sharedir, *weechat_home;
+ char *weechat_sharedir, *weechat_data_dir;
char *str_sharedir, *str_home;
int len;
@@ -889,15 +889,15 @@ weechat_python_load (const char *filename, const char *code)
free (weechat_sharedir);
}
- /* adding $weechat_dir/python in $PYTHONPATH */
- weechat_home = weechat_info_get ("weechat_dir", "");
- if (weechat_home)
+ /* add {weechat_data_dir}/python in $PYTHONPATH */
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
+ if (weechat_data_dir)
{
- len = strlen (weechat_home) + 1 + strlen (PYTHON_PLUGIN_NAME) + 1;
+ len = strlen (weechat_data_dir) + 1 + strlen (PYTHON_PLUGIN_NAME) + 1;
str_home = malloc (len);
if (str_home)
{
- snprintf (str_home, len, "%s/python", weechat_home);
+ snprintf (str_home, len, "%s/python", weechat_data_dir);
#if PY_MAJOR_VERSION >= 3
/* python >= 3.x */
path = PyUnicode_FromString (str_home);
@@ -912,7 +912,7 @@ weechat_python_load (const char *filename, const char *code)
}
free (str_home);
}
- free (weechat_home);
+ free (weechat_data_dir);
}
diff --git a/src/plugins/relay/relay-network.c b/src/plugins/relay/relay-network.c
index cc0cc83b9..53d6f65e1 100644
--- a/src/plugins/relay/relay-network.c
+++ b/src/plugins/relay/relay-network.c
@@ -49,15 +49,25 @@ relay_network_set_ssl_cert_key (int verbose)
{
char *certkey_path;
int ret;
+ struct t_hashtable *options;
gnutls_certificate_free_credentials (relay_gnutls_x509_cred);
gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred);
relay_network_init_ssl_cert_key_ok = 0;
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "config");
certkey_path = weechat_string_eval_path_home (
weechat_config_string (relay_config_network_ssl_cert_key),
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (certkey_path)
{
ret = gnutls_certificate_set_x509_key_file (relay_gnutls_x509_cred,
diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c
index 8c9b74fde..557ff5b17 100644
--- a/src/plugins/relay/relay-server.c
+++ b/src/plugins/relay/relay-server.c
@@ -791,6 +791,7 @@ relay_server_new (const char *protocol_string, enum t_relay_protocol protocol,
int ipv4, int ipv6, int ssl, int unix_socket)
{
struct t_relay_server *new_server, *dup_server;
+ struct t_hashtable *options;
if (!protocol_string)
return NULL;
@@ -823,8 +824,17 @@ relay_server_new (const char *protocol_string, enum t_relay_protocol protocol,
new_server->protocol_args =
(protocol_args) ? strdup (protocol_args) : NULL;
new_server->port = port;
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "runtime");
new_server->path = weechat_string_eval_path_home (path,
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
new_server->ipv4 = ipv4;
new_server->ipv6 = ipv6;
new_server->ssl = ssl;
@@ -862,8 +872,18 @@ void
relay_server_update_path (struct t_relay_server *server, const char *path)
{
char *new_path;
-
- new_path = weechat_string_eval_path_home (path, NULL, NULL, NULL);
+ struct t_hashtable *options;
+
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "runtime");
+ new_path = weechat_string_eval_path_home (path, NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (!new_path)
return;
diff --git a/src/plugins/script/script-action.c b/src/plugins/script/script-action.c
index 6f4f4b8e9..2113de911 100644
--- a/src/plugins/script/script-action.c
+++ b/src/plugins/script/script-action.c
@@ -1523,7 +1523,7 @@ script_action_schedule (const char *action,
int quiet)
{
/* create again "script" directory, just in case it has been removed */
- if (!weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755))
+ if (!weechat_mkdir_home ("${weechat_cache_dir}/" SCRIPT_PLUGIN_NAME, 0755))
return;
script_action_add (action);
diff --git a/src/plugins/script/script-completion.c b/src/plugins/script/script-completion.c
index 5ec3199e9..f0653ea3a 100644
--- a/src/plugins/script/script-completion.c
+++ b/src/plugins/script/script-completion.c
@@ -189,7 +189,7 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
- char *weechat_home, *directory;
+ char *weechat_data_dir, *directory;
int length, i;
void *pointers[2];
@@ -199,9 +199,9 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
(void) completion_item;
(void) buffer;
- weechat_home = weechat_info_get ("weechat_dir", NULL);
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
- length = strlen (weechat_home) + 128 + 1;
+ length = strlen (weechat_data_dir) + 128 + 1;
directory = malloc (length);
if (directory)
{
@@ -210,16 +210,16 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
pointers[0] = completion;
pointers[1] = script_extension[i];
- /* look for files in "~/.weechat/<language>/" */
+ /* look for files in <weechat_data_dir>/<language> */
snprintf (directory, length,
- "%s/%s", weechat_home, script_language[i]);
+ "%s/%s", weechat_data_dir, script_language[i]);
weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
- /* look for files in "~/.weechat/<language>/autoload/" */
+ /* look for files in <weechat_data_dir>/<language>/autoload */
snprintf (directory, length,
- "%s/%s/autoload", weechat_home, script_language[i]);
+ "%s/%s/autoload", weechat_data_dir, script_language[i]);
weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb,
pointers);
@@ -227,8 +227,8 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
free (directory);
}
- if (weechat_home)
- free (weechat_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
return WEECHAT_RC_OK;
}
diff --git a/src/plugins/script/script-config.c b/src/plugins/script/script-config.c
index 79a30ef7a..303857c07 100644
--- a/src/plugins/script/script-config.c
+++ b/src/plugins/script/script-config.c
@@ -148,8 +148,7 @@ script_config_get_diff_command ()
}
/*
- * Gets filename with script
- * (by default "/home/xxx/.weechat/script/plugins.xml.gz").
+ * Gets filename with list of scripts.
*
* Note: result must be freed after use.
*/
@@ -159,9 +158,19 @@ script_config_get_xml_filename ()
{
char *path, *filename;
int length;
-
+ struct t_hashtable *options;
+
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "cache");
path = weechat_string_eval_path_home (
- weechat_config_string (script_config_scripts_path), NULL, NULL, NULL);
+ weechat_config_string (script_config_scripts_path), NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
length = strlen (path) + 64;
filename = malloc (length);
if (filename)
@@ -172,11 +181,8 @@ script_config_get_xml_filename ()
/*
* Gets filename for a script to download.
- *
* If suffix is not NULL, it is added to filename.
*
- * Example: "/home/xxx/.weechat/script/go.py"
- *
* Note: result must be freed after use.
*/
@@ -186,9 +192,19 @@ script_config_get_script_download_filename (struct t_script_repo *script,
{
char *path, *filename;
int length;
-
+ struct t_hashtable *options;
+
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "cache");
path = weechat_string_eval_path_home (
- weechat_config_string (script_config_scripts_path), NULL, NULL, NULL);
+ weechat_config_string (script_config_scripts_path), NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
length = strlen (path) + 1 + strlen (script->name_with_extension)
+ ((suffix) ? strlen (suffix) : 0) + 1;
filename = malloc (length);
diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c
index 3627ad2b9..0d4bdd1c0 100644
--- a/src/plugins/script/script-repo.c
+++ b/src/plugins/script/script-repo.c
@@ -165,28 +165,28 @@ script_repo_search_by_name_ext (const char *name_with_extension)
char *
script_repo_get_filename_loaded (struct t_script_repo *script)
{
- char *weechat_home, *filename, resolved_path[PATH_MAX];
+ char *weechat_data_dir, *filename, resolved_path[PATH_MAX];
int length;
struct stat st;
- weechat_home = weechat_info_get ("weechat_dir", NULL);
- length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
+ length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (!filename)
{
- if (weechat_home)
- free (weechat_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
return NULL;
}
snprintf (filename, length, "%s/%s/autoload/%s",
- weechat_home,
+ weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
{
snprintf (filename, length, "%s/%s/%s",
- weechat_home,
+ weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
@@ -195,8 +195,8 @@ script_repo_get_filename_loaded (struct t_script_repo *script)
}
}
- if (weechat_home)
- free (weechat_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
if (!filename[0])
{
@@ -798,7 +798,7 @@ void
script_repo_update_status (struct t_script_repo *script)
{
const char *version;
- char *weechat_home, *filename, *sha512sum;
+ char *weechat_data_dir, *filename, *sha512sum;
struct stat st;
int length;
struct t_script_repo *ptr_script;
@@ -807,13 +807,13 @@ script_repo_update_status (struct t_script_repo *script)
sha512sum = NULL;
/* check if script is installed (file found on disk) */
- weechat_home = weechat_info_get ("weechat_dir", NULL);
- length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
+ weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
+ length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (filename)
{
snprintf (filename, length, "%s/%s/autoload/%s",
- weechat_home,
+ weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) == 0)
@@ -825,7 +825,7 @@ script_repo_update_status (struct t_script_repo *script)
else
{
snprintf (filename, length, "%s/%s/%s",
- weechat_home,
+ weechat_data_dir,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) == 0)
@@ -837,8 +837,8 @@ script_repo_update_status (struct t_script_repo *script)
free (filename);
}
- if (weechat_home)
- free (weechat_home);
+ if (weechat_data_dir)
+ free (weechat_data_dir);
/* check if script is held */
if (script_repo_script_is_held (script))
diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c
index b8fe7319d..4cb9189ba 100644
--- a/src/plugins/script/script.c
+++ b/src/plugins/script/script.c
@@ -371,7 +371,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_config_read ();
- weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755);
+ weechat_mkdir_home ("${weechat_cache_dir}/" SCRIPT_PLUGIN_NAME, 0755);
script_command_init ();
script_completion_init ();
diff --git a/src/plugins/spell/spell.c b/src/plugins/spell/spell.c
index e47fd6ee8..38e6ef5a8 100644
--- a/src/plugins/spell/spell.c
+++ b/src/plugins/spell/spell.c
@@ -195,9 +195,9 @@ spell_warning_aspell_config ()
char *aspell_filename, *spell_filename;
aspell_filename = weechat_string_eval_path_home (
- "%h/aspell.conf", NULL, NULL, NULL);
+ "${weechat_config_dir}/aspell.conf", NULL, NULL, NULL);
spell_filename = weechat_string_eval_path_home (
- "%h/" SPELL_CONFIG_NAME ".conf", NULL, NULL, NULL);
+ "${weechat_config_dir}/" SPELL_CONFIG_NAME ".conf", NULL, NULL, NULL);
/* if aspell.conf is there and not spell.conf, display a warning */
if (aspell_filename && spell_filename
diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c
index 0ba198eef..8acae7de1 100644
--- a/src/plugins/xfer/xfer-file.c
+++ b/src/plugins/xfer/xfer-file.c
@@ -210,13 +210,23 @@ void
xfer_file_find_filename (struct t_xfer *xfer)
{
char *dir_separator, *path;
+ struct t_hashtable *options;
if (!XFER_IS_FILE(xfer->type))
return;
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "data");
path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_download_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (!path)
return;
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index 5eb203b09..447dbc92c 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -145,11 +145,20 @@ void
xfer_create_directories ()
{
char *path;
+ struct t_hashtable *options;
+
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "data");
/* create download directory */
path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_download_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
if (path)
{
(void) weechat_mkdir_parents (path, 0700);
@@ -159,12 +168,15 @@ xfer_create_directories ()
/* create upload directory */
path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_upload_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
if (path)
{
(void) weechat_mkdir_parents (path, 0700);
free (path);
}
+
+ if (options)
+ weechat_hashtable_free (options);
}
/*
@@ -1072,6 +1084,7 @@ xfer_add_cb (const void *pointer, void *data,
socklen_t length, bind_addr_len;
unsigned long long file_size;
struct t_xfer *ptr_xfer;
+ struct t_hashtable *options;
/* make C compiler happy */
(void) pointer;
@@ -1170,9 +1183,18 @@ xfer_add_cb (const void *pointer, void *data,
filename2 = weechat_string_expand_home (filename);
else
{
+ options = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (options)
+ weechat_hashtable_set (options, "directory", "data");
path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_upload_path),
- NULL, NULL, NULL);
+ NULL, NULL, options);
+ if (options)
+ weechat_hashtable_free (options);
if (!path)
{
weechat_printf (NULL,