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
This commit is contained in:
Sébastien Helleu 2021-05-02 11:56:25 +02:00
parent 4c5fcb743b
commit 0f9640a5f3
38 changed files with 1129 additions and 363 deletions

View File

@ -6483,7 +6483,7 @@ COMMAND_CALLBACK(upgrade)
/* execute binary */ /* execute binary */
exec_args[0] = ptr_binary; exec_args[0] = ptr_binary;
exec_args[3] = strdup (weechat_home); exec_args[3] = dir_get_string_home_dirs ();
execvp (exec_args[0], exec_args); execvp (exec_args[0], exec_args);
/* this code should not be reached if execvp is OK */ /* this code should not be reached if execvp is OK */
@ -8332,7 +8332,7 @@ command_init ()
"IMPORTANT: you must restore the session with exactly same " "IMPORTANT: you must restore the session with exactly same "
"configuration (files *.conf).\n" "configuration (files *.conf).\n"
"It is possible to restore WeeChat session on another machine if you " "It is possible to restore WeeChat session on another machine if you "
"copy the content of directory \"~/.weechat\"."), "copy the content of WeeChat home directories (see /debug dirs)."),
"%(filename)|-dummy|-quit", "%(filename)|-dummy|-quit",
&command_upgrade, NULL, NULL); &command_upgrade, NULL, NULL);
hook_command ( hook_command (

View File

@ -573,7 +573,7 @@ completion_list_add_filename_cb (const void *pointer, void *data,
} }
} }
if (!real_prefix) if (!real_prefix)
real_prefix = strdup (weechat_home); real_prefix = strdup (weechat_data_dir);
prefix = strdup (""); prefix = strdup ("");
} }
else else
@ -984,6 +984,7 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
{ {
char *plugin_path, *dir_name, *extra_libdir; char *plugin_path, *dir_name, *extra_libdir;
int length; int length;
struct t_hashtable *options;
/* make C compiler happy */ /* make C compiler happy */
(void) pointer; (void) pointer;
@ -1011,8 +1012,17 @@ completion_list_add_plugins_installed_cb (const void *pointer, void *data,
if (CONFIG_STRING(config_plugin_path) if (CONFIG_STRING(config_plugin_path)
&& CONFIG_STRING(config_plugin_path)[0]) && 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), 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) if (plugin_path)
{ {
dir_exec_on_files (plugin_path, 1, 0, dir_exec_on_files (plugin_path, 1, 0,

View File

@ -2366,13 +2366,13 @@ config_file_write_internal (struct t_config_file *config_file,
return WEECHAT_CONFIG_WRITE_ERROR; return WEECHAT_CONFIG_WRITE_ERROR;
/* build filename */ /* build filename */
filename_length = strlen (weechat_home) + filename_length = strlen (weechat_config_dir) + strlen (DIR_SEPARATOR) +
strlen (config_file->filename) + 2; strlen (config_file->filename) + 1;
filename = malloc (filename_length); filename = malloc (filename_length);
if (!filename) if (!filename)
return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; return WEECHAT_CONFIG_WRITE_MEMORY_ERROR;
snprintf (filename, filename_length, "%s%s%s", snprintf (filename, filename_length, "%s%s%s",
weechat_home, DIR_SEPARATOR, config_file->filename); weechat_config_dir, DIR_SEPARATOR, config_file->filename);
/* /*
* build temporary filename, this temp file will be renamed to filename * build temporary filename, this temp file will be renamed to filename
@ -2561,13 +2561,13 @@ config_file_read_internal (struct t_config_file *config_file, int reload)
return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; return WEECHAT_CONFIG_READ_FILE_NOT_FOUND;
/* build filename */ /* build filename */
filename_length = strlen (weechat_home) + strlen (DIR_SEPARATOR) + filename_length = strlen (weechat_config_dir) + strlen (DIR_SEPARATOR) +
strlen (config_file->filename) + 1; strlen (config_file->filename) + 1;
filename = malloc (filename_length); filename = malloc (filename_length);
if (!filename) if (!filename)
return WEECHAT_CONFIG_READ_MEMORY_ERROR; return WEECHAT_CONFIG_READ_MEMORY_ERROR;
snprintf (filename, filename_length, "%s%s%s", snprintf (filename, filename_length, "%s%s%s",
weechat_home, DIR_SEPARATOR, config_file->filename); weechat_config_dir, DIR_SEPARATOR, config_file->filename);
/* create file with default options if it does not exist */ /* create file with default options if it does not exist */
if (access (filename, F_OK) != 0) if (access (filename, F_OK) != 0)

View File

@ -161,7 +161,7 @@ debug_sigsegv_cb ()
string_fprintf (stderr, string_fprintf (stderr,
"*** Full crash dump was saved to %s/weechat.log file." "*** Full crash dump was saved to %s/weechat.log file."
"\n", "\n",
weechat_home); weechat_data_dir);
} }
string_fprintf ( string_fprintf (
stderr, stderr,
@ -590,19 +590,27 @@ debug_libs_cb (const void *pointer, void *data,
void void
debug_directories () debug_directories ()
{ {
char *extra_libdir; char *extra_libdir, str_temp[1024];
const char *ptr_home = WEECHAT_HOME;
extra_libdir = getenv (WEECHAT_EXTRA_LIBDIR); extra_libdir = getenv (WEECHAT_EXTRA_LIBDIR);
if (weechat_home_temp)
{
snprintf (str_temp, sizeof (str_temp),
" (%s)", _("TEMPORARY, deleted on exit"));
}
else
{
str_temp[0] = '\0';
}
gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "");
gui_chat_printf (NULL, _("Directories:")); gui_chat_printf (NULL, _("Directories:"));
gui_chat_printf (NULL, " home: %s%s%s", gui_chat_printf (NULL, " home:");
weechat_home, gui_chat_printf (NULL, " config: %s%s", weechat_config_dir, str_temp);
(weechat_home_temp) ? " " : "", gui_chat_printf (NULL, " data: %s%s", weechat_data_dir, str_temp);
(weechat_home_temp) ? _("(TEMPORARY, deleted on exit)") : ""); gui_chat_printf (NULL, " cache: %s%s", weechat_cache_dir, str_temp);
gui_chat_printf (NULL, _(" (default: %s)"), gui_chat_printf (NULL, " runtime: %s%s", weechat_runtime_dir, str_temp);
(ptr_home && ptr_home[0]) ? ptr_home : "~/.weechat");
gui_chat_printf (NULL, " lib: %s", WEECHAT_LIBDIR); gui_chat_printf (NULL, " lib: %s", WEECHAT_LIBDIR);
gui_chat_printf (NULL, " lib (extra): %s", gui_chat_printf (NULL, " lib (extra): %s",
(extra_libdir && extra_libdir[0]) ? extra_libdir : "-"); (extra_libdir && extra_libdir[0]) ? extra_libdir : "-");

View File

@ -57,7 +57,7 @@
*/ */
char * char *
dir_get_temp_dir() dir_get_temp_dir ()
{ {
char *tmpdir; char *tmpdir;
struct stat buf; struct stat buf;
@ -101,31 +101,70 @@ dir_get_temp_dir()
int int
dir_mkdir_home (const char *directory, int mode) dir_mkdir_home (const char *directory, int mode)
{ {
char *dir_name; char *dir, *dir1, *dir2, *dir3, *dir4;
int dir_length; int rc, dir_length;
rc = 0;
dir = NULL;
dir1 = NULL;
dir2 = NULL;
dir3 = NULL;
dir4 = NULL;
if (!directory) if (!directory)
return 0; goto end;
/* build directory, adding WeeChat home */ if (strncmp (directory, "${", 2) == 0)
dir_length = strlen (weechat_home) + strlen (directory) + 2;
dir_name = malloc (dir_length);
if (!dir_name)
return 0;
snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory);
if (mkdir (dir_name, mode) < 0)
{ {
if (errno != EEXIST) dir = strdup (directory);
{ }
free (dir_name); else
return 0; {
} /* build directory in data dir by default */
dir_length = strlen (weechat_data_dir) + strlen (directory) + 2;
dir = malloc (dir_length);
if (!dir)
goto end;
snprintf (dir, dir_length, "%s/%s", weechat_data_dir, directory);
} }
free (dir_name); dir1 = string_replace (dir, "${weechat_config_dir}", weechat_config_dir);
return 1; if (!dir1)
goto end;
dir2 = string_replace (dir1, "${weechat_data_dir}", weechat_data_dir);
if (!dir2)
goto end;
dir3 = string_replace (dir2, "${weechat_cache_dir}", weechat_cache_dir);
if (!dir3)
goto end;
dir4 = string_replace (dir3, "${weechat_runtime_dir}", weechat_runtime_dir);
if (!dir4)
goto end;
/* build directory, adding WeeChat home */
if (mkdir (dir4, mode) < 0)
{
if (errno != EEXIST)
goto end;
}
rc = 1;
end:
if (dir)
free (dir);
if (dir1)
free (dir1);
if (dir2)
free (dir2);
if (dir3)
free (dir3);
if (dir4)
free (dir4);
return rc;
} }
/* /*
@ -353,7 +392,7 @@ dir_search_full_lib_name_ext (const char *filename, const char *extension,
} }
/* try WeeChat user's dir */ /* try WeeChat user's dir */
length = strlen (weechat_home) + strlen (name_with_ext) + length = strlen (weechat_data_dir) + strlen (name_with_ext) +
strlen (plugins_dir) + 16; strlen (plugins_dir) + 16;
final_name = malloc (length); final_name = malloc (length);
if (!final_name) if (!final_name)
@ -363,7 +402,7 @@ dir_search_full_lib_name_ext (const char *filename, const char *extension,
} }
snprintf (final_name, length, snprintf (final_name, length,
"%s%s%s%s%s", "%s%s%s%s%s",
weechat_home, weechat_data_dir,
DIR_SEPARATOR, DIR_SEPARATOR,
plugins_dir, plugins_dir,
DIR_SEPARATOR, DIR_SEPARATOR,
@ -514,154 +553,404 @@ error:
} }
/* /*
* Expands and assigns given path to "weechat_home". * Uses one or four different paths for WeeChat home directories.
*
* If 4 paths are given, they must be separated by colons and given in this
* order: config, data, cache, runtime.
*
* Returns:
* 1: OK
* 0: error
*/ */
void int
dir_set_home_path (char *home_path) dir_set_home_path (char *path)
{ {
char *ptr_home; char **paths;
int dir_length; int rc, num_paths;
if (home_path[0] == '~') rc = 0;
paths = NULL;
if (!path)
goto end;
paths = string_split (path, ":", NULL, 0, 0, &num_paths);
if (!paths)
{ {
/* replace leading '~' by $HOME */ string_fprintf (stderr, _("Error: not enough memory\n"));
ptr_home = getenv ("HOME"); goto end;
if (!ptr_home) }
{
string_fprintf (stderr, _("Error: unable to get HOME directory\n")); if (num_paths == 1)
weechat_shutdown (EXIT_FAILURE, 0); {
/* make C static analyzer happy (never executed) */ weechat_config_dir = string_expand_home (paths[0]);
return; weechat_data_dir = string_expand_home (paths[0]);
} weechat_cache_dir = string_expand_home (paths[0]);
dir_length = strlen (ptr_home) + strlen (home_path + 1) + 1; weechat_runtime_dir = string_expand_home (paths[0]);
weechat_home = malloc (dir_length); }
if (weechat_home) else if (num_paths == 4)
{ {
snprintf (weechat_home, dir_length, weechat_config_dir = string_expand_home (paths[0]);
"%s%s", ptr_home, home_path + 1); weechat_data_dir = string_expand_home (paths[1]);
} weechat_cache_dir = string_expand_home (paths[2]);
weechat_runtime_dir = string_expand_home (paths[3]);
} }
else else
{ {
weechat_home = strdup (home_path); string_fprintf (stderr,
_("Error: wrong number of paths for home directories "
"(expected: 1 or 4, received: %d)\n"),
num_paths);
goto end;
} }
if (!weechat_home) rc = 1;
{
string_fprintf (stderr, end:
_("Error: not enough memory for home directory\n")); if (paths)
weechat_shutdown (EXIT_FAILURE, 0); string_free_split (paths);
/* make C static analyzer happy (never executed) */ return rc;
return;
}
} }
/* /*
* Creates WeeChat home directory (by default ~/.weechat). * Creates WeeChat temporary home directory (deleted on exit).
* *
* Any error in this function is fatal: WeeChat can not run without a home * Returns:
* directory. * 1: OK
* 0: error
*/ */
void int
dir_create_home_dir () dir_create_home_temp_dir ()
{ {
char *temp_dir, *temp_home_template, *ptr_weechat_home; char *temp_dir, *temp_home_template, *ptr_weechat_home;
char *config_weechat_home; int rc, length, add_separator;
int length, add_separator;
struct stat statinfo; rc = 0;
temp_dir = NULL;
temp_home_template = NULL;
temp_dir = dir_get_temp_dir ();
if (!temp_dir || !temp_dir[0])
goto memory_error;
length = strlen (temp_dir) + 32 + 1;
temp_home_template = malloc (length);
if (!temp_home_template)
goto memory_error;
add_separator = (temp_dir[strlen (temp_dir) - 1] != DIR_SEPARATOR_CHAR);
snprintf (temp_home_template, length,
"%s%sweechat_temp_XXXXXX",
temp_dir,
add_separator ? DIR_SEPARATOR : "");
ptr_weechat_home = mkdtemp (temp_home_template);
if (!ptr_weechat_home)
{
string_fprintf (stderr,
_("Error: unable to create a temporary "
"home directory (using template: \"%s\")\n"),
temp_home_template);
goto end;
}
weechat_config_dir = strdup (ptr_weechat_home);
weechat_data_dir = strdup (ptr_weechat_home);
weechat_cache_dir = strdup (ptr_weechat_home);
weechat_runtime_dir = strdup (ptr_weechat_home);
weechat_home_delete_on_exit = 1;
rc = 1;
goto end;
memory_error:
string_fprintf (stderr, _("Error: not enough memory\n"));
end:
if (temp_dir)
free (temp_dir);
if (temp_home_template)
free (temp_home_template);
return rc;
}
/*
* Finds XDG directories.
*
* Returns:
* 1: OK
* 0: error
*/
int
dir_find_xdg_dirs (char **config_dir, char **data_dir, char **cache_dir,
char **runtime_dir)
{
char *ptr_home, path[PATH_MAX];
char *xdg_config_home, *xdg_data_home, *xdg_cache_home, *xdg_runtime_dir;
ptr_home = getenv ("HOME");
xdg_config_home = getenv ("XDG_CONFIG_HOME");
xdg_data_home = getenv ("XDG_DATA_HOME");
xdg_cache_home = getenv ("XDG_CACHE_HOME");
xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
/* set config dir: $XDG_CONFIG_HOME/weechat or $HOME/.config/weechat */
if (xdg_config_home && xdg_config_home[0])
{
snprintf (path, sizeof (path),
"%s%s%s",
xdg_config_home, DIR_SEPARATOR, "weechat");
}
else
{
snprintf (path, sizeof (path),
"%s%s%s%s%s",
ptr_home, DIR_SEPARATOR, ".config", DIR_SEPARATOR, "weechat");
}
*config_dir = strdup (path);
if (!*config_dir)
goto error;
/* set data dir: $XDG_DATA_HOME/weechat or $HOME/.local/share/weechat */
if (xdg_data_home && xdg_data_home[0])
{
snprintf (path, sizeof (path),
"%s%s%s",
xdg_data_home, DIR_SEPARATOR, "weechat");
}
else
{
snprintf (path, sizeof (path),
"%s%s%s%s%s%s%s",
ptr_home, DIR_SEPARATOR, ".local", DIR_SEPARATOR, "share",
DIR_SEPARATOR, "weechat");
}
*data_dir = strdup (path);
if (!*data_dir)
goto error;
/* set cache dir: $XDG_CACHE_HOME/weechat or $HOME/.cache/weechat */
if (xdg_cache_home && xdg_cache_home[0])
{
snprintf (path, sizeof (path),
"%s%s%s",
xdg_cache_home, DIR_SEPARATOR, "weechat");
}
else
{
snprintf (path, sizeof (path),
"%s%s%s%s%s",
ptr_home, DIR_SEPARATOR, ".cache", DIR_SEPARATOR, "weechat");
}
*cache_dir = strdup (path);
if (!*cache_dir)
goto error;
/* set runtime dir: $XDG_RUNTIME_DIR/weechat or same as cache dir */
if (xdg_runtime_dir && xdg_runtime_dir[0])
{
snprintf (path, sizeof (path),
"%s%s%s",
xdg_runtime_dir, DIR_SEPARATOR, "weechat");
*runtime_dir = strdup (path);
}
else
{
*runtime_dir = strdup (*cache_dir);
}
if (!*runtime_dir)
goto error;
return 1;
error:
string_fprintf (stderr, _("Error: not enough memory\n"));
return 0;
}
/*
* Finds WeeChat home directories: it can be either XDG directories or the
* same directory for all files (like the legacy directory ~/.weechat).
*
* Returns:
* 1: OK
* 0: error
*/
int
dir_find_home_dirs ()
{
char *ptr_home, *ptr_weechat_home, *config_weechat_home;
char *config_dir, *data_dir, *cache_dir, *runtime_dir;
char path[PATH_MAX];
/* temporary WeeChat home */ /* temporary WeeChat home */
if (weechat_home_temp) if (weechat_home_temp)
{ return dir_create_home_temp_dir ();
temp_dir = dir_get_temp_dir ();
if (!temp_dir || !temp_dir[0]) /* use a forced home with -d/--dir */
{ if (weechat_home_force)
string_fprintf (stderr, return dir_set_home_path (weechat_home_force);
_("Error: not enough memory for home "
"directory\n")); /* use environment variable "WEECHAT_HOME" (if set) */
weechat_shutdown (EXIT_FAILURE, 0); ptr_weechat_home = getenv ("WEECHAT_HOME");
/* make C static analyzer happy (never executed) */ if (ptr_weechat_home && ptr_weechat_home[0])
return; return dir_set_home_path (ptr_weechat_home);
}
length = strlen (temp_dir) + 32 + 1; /* use the home forced at compilation time (if set) */
temp_home_template = malloc (length); config_weechat_home = WEECHAT_HOME;
if (!temp_home_template) if (config_weechat_home[0])
{ return dir_set_home_path (config_weechat_home);
free (temp_dir);
string_fprintf (stderr, if (!dir_find_xdg_dirs (&config_dir, &data_dir, &cache_dir, &runtime_dir))
_("Error: not enough memory for home " return 0;
"directory\n"));
weechat_shutdown (EXIT_FAILURE, 0); /* check if {weechat_config_dir}/weechat.conf exists */
/* make C static analyzer happy (never executed) */ snprintf (path, sizeof (path),
return; "%s%s%s",
} config_dir, DIR_SEPARATOR, "weechat.conf");
add_separator = (temp_dir[strlen (temp_dir) - 1] != DIR_SEPARATOR_CHAR); if (access (path, F_OK) == 0)
snprintf (temp_home_template, length, goto use_xdg;
"%s%sweechat_temp_XXXXXX",
temp_dir,
add_separator ? DIR_SEPARATOR : "");
free (temp_dir);
ptr_weechat_home = mkdtemp (temp_home_template);
if (!ptr_weechat_home)
{
string_fprintf (stderr,
_("Error: unable to create a temporary "
"home directory (using template: \"%s\")\n"),
temp_home_template);
free (temp_home_template);
weechat_shutdown (EXIT_FAILURE, 0);
/* make C static analyzer happy (never executed) */
return;
}
weechat_home = strdup (ptr_weechat_home);
free (temp_home_template);
weechat_home_delete_on_exit = 1;
return;
}
/* /*
* weechat_home is not set yet: look for environment variable * check if $HOME/.weechat/weechat.conf exists
* "WEECHAT_HOME" * (compatibility with old releases not supporting XDG directories)
*/ */
if (!weechat_home) ptr_home = getenv ("HOME");
snprintf (path, sizeof (path),
"%s%s%s%s%s",
ptr_home, DIR_SEPARATOR, ".weechat", DIR_SEPARATOR, "weechat.conf");
if (access (path, F_OK) == 0)
{ {
ptr_weechat_home = getenv ("WEECHAT_HOME"); snprintf (path, sizeof (path),
if (ptr_weechat_home && ptr_weechat_home[0]) "%s%s%s",
dir_set_home_path (ptr_weechat_home); ptr_home, DIR_SEPARATOR, ".weechat");
weechat_config_dir = strdup (path);
weechat_data_dir = strdup (path);
weechat_cache_dir = strdup (path);
weechat_runtime_dir = strdup (path);
free (config_dir);
free (data_dir);
free (cache_dir);
free (runtime_dir);
return 1;
} }
/* weechat_home is still not set: try to use compile time default */ /* use XDG directories */
if (!weechat_home) use_xdg:
{ weechat_config_dir = config_dir;
config_weechat_home = WEECHAT_HOME; weechat_data_dir = data_dir;
dir_set_home_path ( weechat_cache_dir = cache_dir;
(config_weechat_home[0] ? config_weechat_home : "~/.weechat")); weechat_runtime_dir = runtime_dir;
} return 1;
}
/*
* Creates a home directory.
*
* Returns:
* 1: OK
* 0: error
*/
int
dir_create_home_dir (char *path)
{
struct stat statinfo;
/* if home already exists, it has to be a directory */ /* if home already exists, it has to be a directory */
if (stat (weechat_home, &statinfo) == 0) if (stat (path, &statinfo) == 0)
{ {
if (!S_ISDIR (statinfo.st_mode)) if (!S_ISDIR (statinfo.st_mode))
{ {
string_fprintf (stderr, string_fprintf (stderr,
_("Error: home (%s) is not a directory\n"), _("Error: \"%s\" is not a directory\n"),
weechat_home); path);
weechat_shutdown (EXIT_FAILURE, 0); return 0;
/* make C static analyzer happy (never executed) */
return;
} }
} }
/* create home directory; error is fatal */ /* create home directory; error is fatal */
if (!dir_mkdir (weechat_home, 0755)) if (!dir_mkdir_parents (path, 0700))
{ {
string_fprintf (stderr, string_fprintf (stderr,
_("Error: cannot create directory \"%s\"\n"), _("Error: cannot create directory \"%s\"\n"),
weechat_home); path);
weechat_shutdown (EXIT_FAILURE, 0); return 0;
/* make C static analyzer happy (never executed) */
return;
} }
return 1;
}
/*
* Creates WeeChat home directories.
*
* Any error in this function (or a sub function called) is fatal: WeeChat
* can not run at all without the home directories.
*/
void
dir_create_home_dirs ()
{
int rc;
if (!dir_find_home_dirs ())
goto error;
rc = dir_create_home_dir (weechat_config_dir);
if (rc && (strcmp (weechat_config_dir, weechat_data_dir) != 0))
rc = dir_create_home_dir (weechat_data_dir);
if (rc && (strcmp (weechat_config_dir, weechat_cache_dir) != 0))
rc = dir_create_home_dir (weechat_cache_dir);
if (rc && (strcmp (weechat_config_dir, weechat_runtime_dir) != 0))
rc = dir_create_home_dir (weechat_runtime_dir);
if (rc)
return;
error:
weechat_shutdown (EXIT_FAILURE, 0);
}
/*
* Removes WeeChat home directories (called when -t / --temp-dir is given).
*/
void
dir_remove_home_dirs ()
{
dir_rmtree (weechat_config_dir);
if (strcmp (weechat_config_dir, weechat_data_dir) != 0)
dir_rmtree (weechat_data_dir);
if (strcmp (weechat_config_dir, weechat_cache_dir) != 0)
dir_rmtree (weechat_cache_dir);
if (strcmp (weechat_config_dir, weechat_runtime_dir) != 0)
dir_rmtree (weechat_runtime_dir);
}
/*
* Returns a string with home directories separated by colons, in this order:
* config_dir, data_dir, cache_dir, runtime_dir.
*
* Example of value returned:
* /home/user/.config/weechat:/home/user/.local/share/weechat:
* /home/user/.cache/weechat:/run/user/1000/weechat
*
* Note: result must be freed after use.
*/
char *
dir_get_string_home_dirs ()
{
char *dirs[5];
dirs[0] = weechat_config_dir;
dirs[1] = weechat_data_dir;
dirs[2] = weechat_cache_dir;
dirs[3] = weechat_runtime_dir;
dirs[4] = NULL;
return string_build_with_split_string ((const char **)dirs, ":");
} }

View File

@ -33,6 +33,8 @@ extern void dir_exec_on_files (const char *directory, int recurse_subdirs,
extern char *dir_search_full_lib_name (const char *filename, extern char *dir_search_full_lib_name (const char *filename,
const char *sys_directory); const char *sys_directory);
extern char *dir_file_get_content (const char *filename); extern char *dir_file_get_content (const char *filename);
extern void dir_create_home_dir (); extern void dir_create_home_dirs ();
extern void dir_remove_home_dirs ();
extern char *dir_get_string_home_dirs ();
#endif /* WEECHAT_DIR_H */ #endif /* WEECHAT_DIR_H */

View File

@ -1010,32 +1010,34 @@ end:
* Replaces variables, which can be, by order of priority: * Replaces variables, which can be, by order of priority:
* 1. the string itself without evaluation (format: raw:xxx) * 1. the string itself without evaluation (format: raw:xxx)
* 2. an extra variable from hashtable "extra_vars" * 2. an extra variable from hashtable "extra_vars"
* 3. a string to evaluate (format: eval:xxx) * 3. a WeeChat home directory, one of: "weechat_config_dir",
* 4. a condition to evaluate (format: eval_cond:xxx) * "weechat_data_dir", "weechat_cache_dir", "weechat_runtime_dir"
* 5. a string with escaped chars (format: esc:xxx or \xxx) * 4. a string to evaluate (format: eval:xxx)
* 6. a string with chars to hide (format: hide:char,string) * 5. a condition to evaluate (format: eval_cond:xxx)
* 7. a string with max chars (format: cut:max,suffix,string or * 6. a string with escaped chars (format: esc:xxx or \xxx)
* 7. a string with chars to hide (format: hide:char,string)
* 8. a string with max chars (format: cut:max,suffix,string or
* cut:+max,suffix,string) or max chars on screen * cut:+max,suffix,string) or max chars on screen
* (format: cutscr:max,suffix,string or cutscr:+max,suffix,string) * (format: cutscr:max,suffix,string or cutscr:+max,suffix,string)
* 8. a reversed string (format: rev:xxx) or reversed string for screen, * 9. a reversed string (format: rev:xxx) or reversed string for screen,
* color codes are not reversed (format: revscr:xxx) * color codes are not reversed (format: revscr:xxx)
* 9. a repeated string (format: repeat:count,string) * 10. a repeated string (format: repeat:count,string)
* 10. length of a string (format: length:xxx) or length of a string on screen * 11. length of a string (format: length:xxx) or length of a string on screen
* (format: lengthscr:xxx); color codes are ignored * (format: lengthscr:xxx); color codes are ignored
* 11. a regex group captured (format: re:N (0.99) or re:+) * 12. a regex group captured (format: re:N (0.99) or re:+)
* 12. a color (format: color:xxx) * 13. a color (format: color:xxx)
* 13. a modifier (format: modifier:name,data,xxx) * 14. a modifier (format: modifier:name,data,xxx)
* 14. an info (format: info:name,arguments) * 15. an info (format: info:name,arguments)
* 15. a base 16/32/64 encoded/decoded string (format: base_encode:base,xxx * 16. a base 16/32/64 encoded/decoded string (format: base_encode:base,xxx
* or base_decode:base,xxx) * or base_decode:base,xxx)
* 16. current date/time (format: date or date:xxx) * 17. current date/time (format: date or date:xxx)
* 17. an environment variable (format: env:XXX) * 18. an environment variable (format: env:XXX)
* 18. a ternary operator (format: if:condition?value_if_true:value_if_false) * 19. a ternary operator (format: if:condition?value_if_true:value_if_false)
* 19. calculate result of an expression (format: calc:xxx) * 20. calculate result of an expression (format: calc:xxx)
* 20. an option (format: file.section.option) * 21. an option (format: file.section.option)
* 21. a buffer local variable * 22. a buffer local variable
* 22. a pointer name from hashtable "pointers" * 23. a pointer name from hashtable "pointers"
* 23. a hdata variable (format: hdata.var1.var2 or hdata[list].var1.var2 * 24. a hdata variable (format: hdata.var1.var2 or hdata[list].var1.var2
* or hdata[ptr].var1.var2 or hdata[ptr_name].var1.var2) * or hdata[ptr].var1.var2 or hdata[ptr_name].var1.var2)
* *
* See /help in WeeChat for examples. * See /help in WeeChat for examples.
@ -1093,8 +1095,30 @@ eval_replace_vars_cb (void *data, const char *text)
} }
} }
/* 3. WeeChat home directory */
if (strcmp (text, "weechat_config_dir") == 0)
{
value = strdup (weechat_config_dir);
goto end;
}
if (strcmp (text, "weechat_data_dir") == 0)
{
value = strdup (weechat_data_dir);
goto end;
}
if (strcmp (text, "weechat_cache_dir") == 0)
{
value = strdup (weechat_cache_dir);
goto end;
}
if (strcmp (text, "weechat_runtime_dir") == 0)
{
value = strdup (weechat_runtime_dir);
goto end;
}
/* /*
* 3. force evaluation of string (recursive call) * 4. force evaluation of string (recursive call)
* --> use with caution: the text must be safe! * --> use with caution: the text must be safe!
*/ */
if (strncmp (text, "eval:", 5) == 0) if (strncmp (text, "eval:", 5) == 0)
@ -1104,7 +1128,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
/* /*
* 4. force evaluation of condition (recursive call) * 5. force evaluation of condition (recursive call)
* --> use with caution: the text must be safe! * --> use with caution: the text must be safe!
*/ */
if (strncmp (text, "eval_cond:", 10) == 0) if (strncmp (text, "eval_cond:", 10) == 0)
@ -1113,7 +1137,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 5. convert escaped chars */ /* 6. convert escaped chars */
if (strncmp (text, "esc:", 4) == 0) if (strncmp (text, "esc:", 4) == 0)
{ {
value = string_convert_escaped_chars (text + 4); value = string_convert_escaped_chars (text + 4);
@ -1125,7 +1149,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 6. hide chars: replace all chars by a given char/string */ /* 7. hide chars: replace all chars by a given char/string */
if (strncmp (text, "hide:", 5) == 0) if (strncmp (text, "hide:", 5) == 0)
{ {
value = eval_string_hide (text + 5); value = eval_string_hide (text + 5);
@ -1133,7 +1157,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
/* /*
* 7. cut chars: * 8. cut chars:
* cut: max number of chars, and add an optional suffix when the * cut: max number of chars, and add an optional suffix when the
* string is cut * string is cut
* cutscr: max number of chars displayed on screen, and add an optional * cutscr: max number of chars displayed on screen, and add an optional
@ -1150,7 +1174,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 8. reverse string */ /* 9. reverse string */
if (strncmp (text, "rev:", 4) == 0) if (strncmp (text, "rev:", 4) == 0)
{ {
value = string_reverse (text + 4); value = string_reverse (text + 4);
@ -1162,7 +1186,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 9. repeated string */ /* 10. repeated string */
if (strncmp (text, "repeat:", 7) == 0) if (strncmp (text, "repeat:", 7) == 0)
{ {
value = eval_string_repeat (text + 7); value = eval_string_repeat (text + 7);
@ -1170,7 +1194,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
/* /*
* 10. length of string: * 11. length of string:
* length: number of chars * length: number of chars
* lengthscr: number of chars displayed on screen * lengthscr: number of chars displayed on screen
*/ */
@ -1189,35 +1213,35 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 11. regex group captured */ /* 12. regex group captured */
if (strncmp (text, "re:", 3) == 0) if (strncmp (text, "re:", 3) == 0)
{ {
value = eval_string_regex_group (text + 3, eval_context); value = eval_string_regex_group (text + 3, eval_context);
goto end; goto end;
} }
/* 12. color code */ /* 13. color code */
if (strncmp (text, "color:", 6) == 0) if (strncmp (text, "color:", 6) == 0)
{ {
value = eval_string_color (text + 6); value = eval_string_color (text + 6);
goto end; goto end;
} }
/* 13. modifier */ /* 14. modifier */
if (strncmp (text, "modifier:", 9) == 0) if (strncmp (text, "modifier:", 9) == 0)
{ {
value = eval_string_modifier (text + 9); value = eval_string_modifier (text + 9);
goto end; goto end;
} }
/* 14. info */ /* 15. info */
if (strncmp (text, "info:", 5) == 0) if (strncmp (text, "info:", 5) == 0)
{ {
value = eval_string_info (text + 5); value = eval_string_info (text + 5);
goto end; goto end;
} }
/* 15. base_encode/base_decode */ /* 16. base_encode/base_decode */
if (strncmp (text, "base_encode:", 12) == 0) if (strncmp (text, "base_encode:", 12) == 0)
{ {
value = eval_string_base_encode (text + 12); value = eval_string_base_encode (text + 12);
@ -1229,14 +1253,14 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 16. current date/time */ /* 17. current date/time */
if ((strncmp (text, "date", 4) == 0) && (!text[4] || (text[4] == ':'))) if ((strncmp (text, "date", 4) == 0) && (!text[4] || (text[4] == ':')))
{ {
value = eval_string_date (text + 4); value = eval_string_date (text + 4);
goto end; goto end;
} }
/* 17. environment variable */ /* 18. environment variable */
if (strncmp (text, "env:", 4) == 0) if (strncmp (text, "env:", 4) == 0)
{ {
ptr_value = getenv (text + 4); ptr_value = getenv (text + 4);
@ -1244,7 +1268,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 18: ternary operator: if:condition?value_if_true:value_if_false */ /* 19: ternary operator: if:condition?value_if_true:value_if_false */
if (strncmp (text, "if:", 3) == 0) if (strncmp (text, "if:", 3) == 0)
{ {
value = eval_string_if (text + 3, eval_context); value = eval_string_if (text + 3, eval_context);
@ -1252,7 +1276,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
/* /*
* 19. calculate the result of an expression * 20. calculate the result of an expression
* (with number, operators and parentheses) * (with number, operators and parentheses)
*/ */
if (strncmp (text, "calc:", 5) == 0) if (strncmp (text, "calc:", 5) == 0)
@ -1261,7 +1285,7 @@ eval_replace_vars_cb (void *data, const char *text)
goto end; goto end;
} }
/* 20. option: if found, return this value */ /* 21. option: if found, return this value */
if (strncmp (text, "sec.data.", 9) == 0) if (strncmp (text, "sec.data.", 9) == 0)
{ {
ptr_value = hashtable_get (secure_hashtable_data, text + 9); ptr_value = hashtable_get (secure_hashtable_data, text + 9);
@ -1304,7 +1328,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
} }
/* 21. local variable in buffer */ /* 22. local variable in buffer */
ptr_buffer = hashtable_get (eval_context->pointers, "buffer"); ptr_buffer = hashtable_get (eval_context->pointers, "buffer");
if (ptr_buffer) if (ptr_buffer)
{ {
@ -1316,7 +1340,7 @@ eval_replace_vars_cb (void *data, const char *text)
} }
} }
/* 22. hdata */ /* 23. hdata */
value = eval_string_hdata (text, eval_context); value = eval_string_hdata (text, eval_context);
end: end:

View File

@ -45,7 +45,7 @@
#include "../plugins/plugin.h" #include "../plugins/plugin.h"
char *weechat_log_filename = NULL; /* log name (~/.weechat/weechat.log) */ char *weechat_log_filename = NULL; /* WeeChat log filename (weechat.log) */
FILE *weechat_log_file = NULL; /* WeeChat log file */ FILE *weechat_log_file = NULL; /* WeeChat log file */
int weechat_log_use_time = 1; /* 0 to temporary disable time in log, */ int weechat_log_use_time = 1; /* 0 to temporary disable time in log, */
/* for example when dumping data */ /* for example when dumping data */
@ -79,10 +79,10 @@ log_open (const char *filename, const char *mode)
} }
else else
{ {
filename_length = strlen (weechat_home) + 64; filename_length = strlen (weechat_data_dir) + 64;
weechat_log_filename = malloc (filename_length); weechat_log_filename = malloc (filename_length);
snprintf (weechat_log_filename, filename_length, snprintf (weechat_log_filename, filename_length,
"%s/%s", weechat_home, WEECHAT_LOG_NAME); "%s/%s", weechat_data_dir, WEECHAT_LOG_NAME);
weechat_log_file = fopen (weechat_log_filename, mode); weechat_log_file = fopen (weechat_log_filename, mode);
} }
@ -122,10 +122,12 @@ log_init ()
{ {
if (!log_open (NULL, "w")) if (!log_open (NULL, "w"))
{ {
string_fprintf (stderr, string_fprintf (
_("Error: unable to create/append to log file (weechat.log)\n" stderr,
"If another WeeChat process is using this file, try to run WeeChat\n" _("Error: unable to create/append to log file (weechat.log)\n"
"with another home using the \"--dir\" command line option.\n")); "If another WeeChat process is using this file, try to run "
"WeeChat with a specific home directory using the \"--dir\" "
"command line option.\n"));
exit (1); exit (1);
} }
log_printf ("WeeChat %s (%s %s %s)", log_printf ("WeeChat %s (%s %s %s)",
@ -271,7 +273,7 @@ log_crash_rename ()
log_close (); log_close ();
length = strlen (weechat_home) + 128; length = strlen (weechat_data_dir) + 128;
new_name = malloc (length); new_name = malloc (length);
if (new_name) if (new_name)
{ {
@ -279,7 +281,7 @@ log_crash_rename ()
local_time = localtime (&time_now); local_time = localtime (&time_now);
snprintf (new_name, length, snprintf (new_name, length,
"%s/weechat_crash_%04d%02d%02d_%d.log", "%s/weechat_crash_%04d%02d%02d_%d.log",
weechat_home, weechat_data_dir,
local_time->tm_year + 1900, local_time->tm_year + 1900,
local_time->tm_mon + 1, local_time->tm_mon + 1,
local_time->tm_mday, local_time->tm_mday,

View File

@ -57,6 +57,7 @@
#include "weechat.h" #include "weechat.h"
#include "wee-network.h" #include "wee-network.h"
#include "wee-eval.h" #include "wee-eval.h"
#include "wee-hashtable.h"
#include "wee-hook.h" #include "wee-hook.h"
#include "wee-config.h" #include "wee-config.h"
#include "wee-proxy.h" #include "wee-proxy.h"
@ -93,13 +94,24 @@ void
network_set_gnutls_ca_file () network_set_gnutls_ca_file ()
{ {
char *ca_path; char *ca_path;
struct t_hashtable *options;
if (weechat_no_gnutls) if (weechat_no_gnutls)
return; return;
options = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (options)
hashtable_set (options, "directory", "config");
ca_path = string_eval_path_home ( ca_path = string_eval_path_home (
CONFIG_STRING(config_network_gnutls_ca_file), CONFIG_STRING(config_network_gnutls_ca_file),
NULL, NULL, NULL); NULL, NULL, options);
if (options)
hashtable_free (options);
if (ca_path) if (ca_path)
{ {
if (access (ca_path, R_OK) == 0) if (access (ca_path, R_OK) == 0)

View File

@ -774,7 +774,7 @@ string_expand_home (const char *path)
/* /*
* Evaluate a path by replacing (in this order): * Evaluate a path by replacing (in this order):
* 1. "%h" (at beginning of string) by WeeChat home directory. * 1. "%h" (at beginning of string) by WeeChat home directory (deprecated)
* 2. "~" by user home directory (call to string_expand_home) * 2. "~" by user home directory (call to string_expand_home)
* 3. evaluated variables (see /help eval) * 3. evaluated variables (see /help eval)
* *
@ -790,6 +790,7 @@ string_eval_path_home (const char *path,
struct t_hashtable *options) struct t_hashtable *options)
{ {
char *path1, *path2, *path3; char *path1, *path2, *path3;
const char *ptr_option_directory, *ptr_directory;
int length; int length;
if (!path) if (!path)
@ -799,13 +800,29 @@ string_eval_path_home (const char *path,
path2 = NULL; path2 = NULL;
path3 = NULL; path3 = NULL;
/* replace "%h" by WeeChat home */ /*
* replace "%h" by WeeChat home
* (deprecated: "%h" should not be used any more with WeeChat 3.2)
*/
if (strncmp (path, "%h", 2) == 0) if (strncmp (path, "%h", 2) == 0)
{ {
length = strlen (weechat_home) + strlen (path + 2) + 1; ptr_directory = weechat_data_dir;
ptr_option_directory = hashtable_get (options, "directory");
if (ptr_option_directory)
{
if (strcmp (ptr_option_directory, "config") == 0)
ptr_directory = weechat_config_dir;
else if (strcmp (ptr_option_directory, "data") == 0)
ptr_directory = weechat_data_dir;
else if (strcmp (ptr_option_directory, "cache") == 0)
ptr_directory = weechat_cache_dir;
else if (strcmp (ptr_option_directory, "runtime") == 0)
ptr_directory = weechat_runtime_dir;
}
length = strlen (ptr_directory) + strlen (path + 2) + 1;
path1 = malloc (length); path1 = malloc (length);
if (path1) if (path1)
snprintf (path1, length, "%s%s", weechat_home, path + 2); snprintf (path1, length, "%s%s", ptr_directory, path + 2);
} }
else else
path1 = strdup (path); path1 = strdup (path);

View File

@ -203,7 +203,7 @@ upgrade_file_new (const char *filename,
if (new_upgrade_file) if (new_upgrade_file)
{ {
/* build name of file */ /* build name of file */
length = strlen (weechat_home) + 1 + strlen (filename) + 16 + 1; length = strlen (weechat_data_dir) + 1 + strlen (filename) + 16 + 1;
new_upgrade_file->filename = malloc (length); new_upgrade_file->filename = malloc (length);
if (!new_upgrade_file->filename) if (!new_upgrade_file->filename)
{ {
@ -211,7 +211,7 @@ upgrade_file_new (const char *filename,
return NULL; return NULL;
} }
snprintf (new_upgrade_file->filename, length, "%s/%s.upgrade", snprintf (new_upgrade_file->filename, length, "%s/%s.upgrade",
weechat_home, filename); weechat_data_dir, filename);
new_upgrade_file->callback_read = callback_read; new_upgrade_file->callback_read = callback_read;
new_upgrade_file->callback_read_pointer = callback_read_pointer; new_upgrade_file->callback_read_pointer = callback_read_pointer;
new_upgrade_file->callback_read_data = callback_read_data; new_upgrade_file->callback_read_data = callback_read_data;

View File

@ -925,7 +925,7 @@ upgrade_weechat_end ()
long long time_diff; long long time_diff;
/* remove .upgrade files */ /* remove .upgrade files */
dir_exec_on_files (weechat_home, dir_exec_on_files (weechat_data_dir,
0, 0, 0, 0,
&upgrade_weechat_remove_file_cb, NULL); &upgrade_weechat_remove_file_cb, NULL);

View File

@ -106,9 +106,13 @@ volatile sig_atomic_t weechat_quit_signal = 0; /* signal received, */
/* WeeChat must quit */ /* WeeChat must quit */
volatile sig_atomic_t weechat_reload_signal = 0; /* signal received, */ volatile sig_atomic_t weechat_reload_signal = 0; /* signal received, */
/* WeeChat must reload configuration */ /* WeeChat must reload configuration */
char *weechat_home = NULL; /* home dir. (default: ~/.weechat) */ char *weechat_home_force = NULL; /* forced home (with -d/--dir) */
int weechat_home_temp = 0; /* 1 if using a temporary home */ int weechat_home_temp = 0; /* 1 if using a temporary home */
int weechat_home_delete_on_exit = 0; /* 1 if home is deleted on exit */ int weechat_home_delete_on_exit = 0; /* 1 if home is deleted on exit */
char *weechat_config_dir = NULL; /* config directory */
char *weechat_data_dir = NULL; /* data directory */
char *weechat_cache_dir = NULL; /* cache directory */
char *weechat_runtime_dir = NULL; /* runtime directory */
int weechat_locale_ok = 0; /* is locale OK? */ int weechat_locale_ok = 0; /* is locale OK? */
char *weechat_local_charset = NULL; /* example: ISO-8859-1, UTF-8 */ char *weechat_local_charset = NULL; /* example: ISO-8859-1, UTF-8 */
int weechat_server_cmd_line = 0; /* at least 1 server on cmd line */ int weechat_server_cmd_line = 0; /* at least 1 server on cmd line */
@ -164,8 +168,7 @@ weechat_display_usage ()
_(" -a, --no-connect disable auto-connect to servers at " _(" -a, --no-connect disable auto-connect to servers at "
"startup\n" "startup\n"
" -c, --colors display default colors in terminal\n" " -c, --colors display default colors in terminal\n"
" -d, --dir <path> set WeeChat home directory " " -d, --dir <path> force a single WeeChat home directory\n"
"(default: ~/.weechat)\n"
" (environment variable WEECHAT_HOME is " " (environment variable WEECHAT_HOME is "
"read if this option is not given)\n" "read if this option is not given)\n"
" -t, --temp-dir create a temporary WeeChat home" " -t, --temp-dir create a temporary WeeChat home"
@ -255,7 +258,7 @@ weechat_parse_args (int argc, char *argv[])
weechat_argv0 = (argv[0]) ? strdup (argv[0]) : NULL; weechat_argv0 = (argv[0]) ? strdup (argv[0]) : NULL;
weechat_upgrading = 0; weechat_upgrading = 0;
weechat_home = NULL; weechat_home_force = NULL;
weechat_home_temp = 0; weechat_home_temp = 0;
weechat_home_delete_on_exit = 0; weechat_home_delete_on_exit = 0;
weechat_server_cmd_line = 0; weechat_server_cmd_line = 0;
@ -280,16 +283,16 @@ weechat_parse_args (int argc, char *argv[])
break; break;
case 'd': /* -d / --dir */ case 'd': /* -d / --dir */
weechat_home_temp = 0; weechat_home_temp = 0;
if (weechat_home) if (weechat_home_force)
free (weechat_home); free (weechat_home_force);
weechat_home = strdup (optarg); weechat_home_force = strdup (optarg);
break; break;
case 't': /* -t / --temp-dir */ case 't': /* -t / --temp-dir */
weechat_home_temp = 1; weechat_home_temp = 1;
if (weechat_home) if (weechat_home_force)
{ {
free (weechat_home); free (weechat_home_force);
weechat_home = NULL; weechat_home_force = NULL;
} }
break; break;
case 'h': /* -h / --help */ case 'h': /* -h / --help */
@ -545,13 +548,21 @@ weechat_shutdown (int return_code, int crash)
if (!crash && weechat_home_delete_on_exit) if (!crash && weechat_home_delete_on_exit)
{ {
/* remove temporary home (only if not crashing) */ /* remove temporary home (only if not crashing) */
dir_rmtree (weechat_home); dir_remove_home_dirs ();
} }
if (weechat_argv0) if (weechat_argv0)
free (weechat_argv0); free (weechat_argv0);
if (weechat_home) if (weechat_home_force)
free (weechat_home); free (weechat_home_force);
if (weechat_config_dir)
free (weechat_config_dir);
if (weechat_data_dir)
free (weechat_data_dir);
if (weechat_cache_dir)
free (weechat_cache_dir);
if (weechat_runtime_dir)
free (weechat_runtime_dir);
if (weechat_local_charset) if (weechat_local_charset)
free (weechat_local_charset); free (weechat_local_charset);
if (weechat_force_plugin_autoload) if (weechat_force_plugin_autoload)
@ -614,7 +625,7 @@ weechat_init (int argc, char *argv[], void (*gui_init_cb)())
if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */
weechat_shutdown (EXIT_FAILURE, 0); weechat_shutdown (EXIT_FAILURE, 0);
weechat_parse_args (argc, argv); /* parse command line args */ weechat_parse_args (argc, argv); /* parse command line args */
dir_create_home_dir (); /* create WeeChat home directory */ dir_create_home_dirs (); /* create WeeChat home directories */
log_init (); /* init log file */ log_init (); /* init log file */
plugin_api_init (); /* create some hooks (info,hdata,..)*/ plugin_api_init (); /* create some hooks (info,hdata,..)*/
secure_config_read (); /* read secured data options */ secure_config_read (); /* read secured data options */

View File

@ -112,9 +112,13 @@ extern int weechat_upgrade_count;
extern int weechat_quit; extern int weechat_quit;
extern volatile sig_atomic_t weechat_quit_signal; extern volatile sig_atomic_t weechat_quit_signal;
extern volatile sig_atomic_t weechat_reload_signal; extern volatile sig_atomic_t weechat_reload_signal;
extern char *weechat_home; extern char *weechat_home_force;
extern int weechat_home_temp; extern int weechat_home_temp;
extern int weechat_home_delete_on_exit; extern int weechat_home_delete_on_exit;
extern char *weechat_config_dir;
extern char *weechat_data_dir;
extern char *weechat_cache_dir;
extern char *weechat_runtime_dir;
extern char *weechat_local_charset; extern char *weechat_local_charset;
extern int weechat_plugin_no_dlclose; extern int weechat_plugin_no_dlclose;
extern int weechat_no_gnutls; extern int weechat_no_gnutls;

View File

@ -102,7 +102,8 @@ fifo_command_init ()
"\n" "\n"
"FIFO pipe is used as remote control of WeeChat: you can send " "FIFO pipe is used as remote control of WeeChat: you can send "
"commands or text to the FIFO pipe from your shell.\n" "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" "\n"
"The expected format is one of:\n" "The expected format is one of:\n"
" plugin.buffer *text or command here\n" " plugin.buffer *text or command here\n"
@ -110,7 +111,7 @@ fifo_command_init ()
"\n" "\n"
"For example to change your freenode nick:\n" "For example to change your freenode nick:\n"
" echo 'irc.server.freenode */nick newnick' " " echo 'irc.server.freenode */nick newnick' "
">~/.weechat/weechat_fifo\n" ">/run/user/1000/weechat/weechat_fifo\n"
"\n" "\n"
"Please read the user's guide for more info and examples.\n" "Please read the user's guide for more info and examples.\n"
"\n" "\n"

View File

@ -65,16 +65,26 @@ void
fifo_create () fifo_create ()
{ {
struct stat st; struct stat st;
struct t_hashtable *options;
if (!weechat_config_boolean (fifo_config_file_enabled)) if (!weechat_config_boolean (fifo_config_file_enabled))
return; return;
if (!fifo_filename) 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 ( fifo_filename = weechat_string_eval_path_home (
weechat_config_string (fifo_config_file_path), weechat_config_string (fifo_config_file_path),
NULL, NULL, NULL); NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
} }
if (!fifo_filename) if (!fifo_filename)

View File

@ -6570,7 +6570,8 @@ irc_command_init ()
" /dcc send toto /home/foo/bar.txt"), " /dcc send toto /home/foo/bar.txt"),
"chat %(nicks)" "chat %(nicks)"
" || send %(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); &irc_command_dcc, NULL, NULL);
weechat_hook_command ( weechat_hook_command (
"dehalfop", "dehalfop",

View File

@ -95,13 +95,23 @@ char *
irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key) irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
{ {
char *key_path, *content; char *key_path, *content;
struct t_hashtable *options;
if (!sasl_key) if (!sasl_key)
return NULL; return NULL;
content = 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) if (key_path)
content = weechat_file_get_content (key_path); content = weechat_file_get_content (key_path);

View File

@ -4481,6 +4481,7 @@ irc_server_gnutls_callback (const void *pointer, void *data,
char *ssl_password; char *ssl_password;
const char *ptr_cert_path, *ptr_fingerprint; const char *ptr_cert_path, *ptr_fingerprint;
int rc, ret, fingerprint_match, hostname_match, cert_temp_init; int rc, ret, fingerprint_match, hostname_match, cert_temp_init;
struct t_hashtable *options;
#if LIBGNUTLS_VERSION_NUMBER >= 0x010706 /* 1.7.6 */ #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 /* 1.7.6 */
gnutls_datum_t cinfo; gnutls_datum_t cinfo;
int rinfo; int rinfo;
@ -4724,8 +4725,17 @@ irc_server_gnutls_callback (const void *pointer, void *data,
IRC_SERVER_OPTION_SSL_CERT); IRC_SERVER_OPTION_SSL_CERT);
if (ptr_cert_path && ptr_cert_path[0]) 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, 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) if (cert_path)
{ {
cert_str = weechat_file_get_content (cert_path); cert_str = weechat_file_get_content (cert_path);

View File

@ -59,8 +59,7 @@ struct t_hook *logger_hook_print = NULL;
* Gets logger file path option. * Gets logger file path option.
* *
* Special vars are replaced: * Special vars are replaced:
* - "%h" (at beginning of string): WeeChat home * - with call to function string_eval_path_home
* - "~": user home
* - date/time specifiers (see man strftime) * - date/time specifiers (see man strftime)
* *
* Note: result must be freed after use. * Note: result must be freed after use.
@ -73,13 +72,23 @@ logger_get_file_path ()
int length; int length;
time_t seconds; time_t seconds;
struct tm *date_tmp; struct tm *date_tmp;
struct t_hashtable *options;
path = NULL; path = NULL;
path2 = 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 ( 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) if (!path)
goto end; goto end;

View File

@ -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 * char *
plugin_api_info_weechat_dir_cb (const void *pointer, void *data, plugin_api_info_absolute_path (const char *directory)
const char *info_name,
const char *arguments)
{ {
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 */ /* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) info_name; (void) info_name;
(void) arguments; (void) arguments;
if (!realpath (weechat_home, weechat_dir_absolute_path)) return plugin_api_info_absolute_path (weechat_config_dir);
return NULL; }
return strdup ((weechat_dir_absolute_path[0]) ? /*
weechat_dir_absolute_path : weechat_home); * 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 plugin_api_info_absolute_path (weechat_runtime_dir);
} }
/* /*
@ -1802,8 +1866,23 @@ plugin_api_info_init ()
N_("directory separator"), N_("directory separator"),
NULL, &plugin_api_info_dir_separator_cb, NULL, NULL); NULL, &plugin_api_info_dir_separator_cb, NULL, NULL);
hook_info (NULL, "weechat_dir", hook_info (NULL, "weechat_dir",
N_("WeeChat directory"), N_("WeeChat directory "
NULL, &plugin_api_info_weechat_dir_cb, NULL, NULL); "(*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", hook_info (NULL, "weechat_libdir",
N_("WeeChat \"lib\" directory"), N_("WeeChat \"lib\" directory"),
NULL, &plugin_api_info_weechat_libdir_cb, NULL, NULL); NULL, &plugin_api_info_weechat_libdir_cb, NULL, NULL);

View File

@ -431,13 +431,36 @@ plugin_api_modifier_eval_path_home_cb (const void *pointer, void *data,
const char *modifier_data, const char *modifier_data,
const char *string) const char *string)
{ {
struct t_hashtable *options;
const char *ptr_directory;
char *result;
/* make C compiler happy */ /* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) modifier; (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;
} }
/* /*

View File

@ -134,26 +134,22 @@ plugin_script_info_version_cb (const void *pointer, void *data,
} }
/* /*
* Creates directories for plugin in WeeChat home: * Creates directories for plugin in WeeChat data directory:
* - ~/.weechat/XXX/ * - ${weechat_data_dir}/xxx
* - ~/.weechat/XXX/autoload/ * - ${weechat_data_dir}/xxx/autoload
*/ */
void void
plugin_script_create_dirs (struct t_weechat_plugin *weechat_plugin) plugin_script_create_dirs (struct t_weechat_plugin *weechat_plugin)
{ {
char *string; char path[PATH_MAX];
int length;
weechat_mkdir_home (weechat_plugin->name, 0755); snprintf (path, sizeof (path),
length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1; "${weechat_data_dir}/%s", weechat_plugin->name);
string = malloc (length); weechat_mkdir_home (path, 0755);
if (string) snprintf (path, sizeof (path),
{ "${weechat_data_dir}/%s/autoload", weechat_plugin->name);
snprintf (string, length, "%s/autoload", weechat_plugin->name); weechat_mkdir_home (path, 0755);
weechat_mkdir_home (string, 0755);
free (string);
}
} }
/* /*
@ -461,26 +457,26 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
void (*callback)(void *data, void (*callback)(void *data,
const char *filename)) const char *filename))
{ {
char *dir_home, *dir_name; char *weechat_data_dir, *dir_name;
int dir_length; int dir_length;
/* build directory, adding WeeChat home */ /* build directory, adding WeeChat data directory */
dir_home = weechat_info_get ("weechat_dir", ""); weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
if (!dir_home) if (!weechat_data_dir)
return; 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); dir_name = malloc (dir_length);
if (!dir_name) if (!dir_name)
{ {
free (dir_home); free (weechat_data_dir);
return; return;
} }
snprintf (dir_name, dir_length, 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); weechat_exec_on_files (dir_name, 0, 0, callback, NULL);
free (dir_home); free (weechat_data_dir);
free (dir_name); free (dir_name);
} }
@ -542,64 +538,64 @@ char *
plugin_script_search_path (struct t_weechat_plugin *weechat_plugin, plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
const char *filename) const char *filename)
{ {
char *final_name, *dir_home, *dir_system; char *final_name, *weechat_data_dir, *dir_system;
int length; int length;
struct stat st; struct stat st;
if (filename[0] == '~') if (filename[0] == '~')
return weechat_string_expand_home (filename); return weechat_string_expand_home (filename);
dir_home = weechat_info_get ("weechat_dir", ""); weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
if (dir_home) if (weechat_data_dir)
{ {
/* try WeeChat user's autoload 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; strlen (filename) + 16;
final_name = malloc (length); final_name = malloc (length);
if (final_name) if (final_name)
{ {
snprintf (final_name, length, snprintf (final_name, length,
"%s/%s/autoload/%s", "%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)) if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{ {
free (dir_home); free (weechat_data_dir);
return final_name; return final_name;
} }
free (final_name); free (final_name);
} }
/* try WeeChat language user's dir */ /* 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; strlen (filename) + 16;
final_name = malloc (length); final_name = malloc (length);
if (final_name) if (final_name)
{ {
snprintf (final_name, length, 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)) if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{ {
free (dir_home); free (weechat_data_dir);
return final_name; return final_name;
} }
free (final_name); free (final_name);
} }
/* try WeeChat user's dir */ /* try WeeChat user's dir */
length = strlen (dir_home) + strlen (filename) + 16; length = strlen (weechat_data_dir) + strlen (filename) + 16;
final_name = malloc (length); final_name = malloc (length);
if (final_name) if (final_name)
{ {
snprintf (final_name, length, 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)) if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{ {
free (dir_home); free (weechat_data_dir);
return final_name; return final_name;
} }
free (final_name); free (final_name);
} }
free (dir_home); free (weechat_data_dir);
} }
/* try WeeChat system dir */ /* try WeeChat system dir */
@ -1218,7 +1214,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
char **list) char **list)
{ {
char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path; 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; int argc, i, length, rc, autoload, existing_script, script_loaded;
struct t_plugin_script *ptr_script; struct t_plugin_script *ptr_script;
@ -1283,20 +1279,20 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
*quiet, 0); *quiet, 0);
/* move file from install dir to language dir */ /* move file from install dir to language dir */
dir_home = weechat_info_get ("weechat_dir", ""); weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
length = strlen (dir_home) + strlen (weechat_plugin->name) + length = strlen (weechat_data_dir) + strlen (weechat_plugin->name) +
strlen (base_name) + 16; strlen (base_name) + 16;
new_path = malloc (length); new_path = malloc (length);
if (new_path) if (new_path)
{ {
snprintf (new_path, length, "%s/%s/%s", 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) if (rename (name, new_path) == 0)
{ {
/* make link in autoload dir */ /* make link in autoload dir */
if (autoload) if (autoload)
{ {
length = strlen (dir_home) + length = strlen (weechat_data_dir) +
strlen (weechat_plugin->name) + 8 + strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16; strlen (base_name) + 16;
autoload_path = malloc (length); autoload_path = malloc (length);
@ -1304,7 +1300,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
{ {
snprintf (autoload_path, length, snprintf (autoload_path, length,
"%s/%s/autoload/%s", "%s/%s/autoload/%s",
dir_home, weechat_plugin->name, weechat_data_dir, weechat_plugin->name,
base_name); base_name);
dir_separator = weechat_info_get ("dir_separator", ""); dir_separator = weechat_info_get ("dir_separator", "");
length = 2 + strlen (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 (new_path);
} }
free (base_name); free (base_name);
if (dir_home) if (weechat_data_dir)
free (dir_home); free (weechat_data_dir);
} }
free (name); free (name);
} }
@ -1442,7 +1438,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
char **list) char **list)
{ {
char **argv, *name, *ptr_base_name, *base_name, *autoload_path; 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; int argc, i, length, rc, autoload;
if (!*list) if (!*list)
@ -1490,8 +1486,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
base_name = strdup (ptr_base_name); base_name = strdup (ptr_base_name);
if (base_name) if (base_name)
{ {
dir_home = weechat_info_get ("weechat_dir", ""); weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
length = strlen (dir_home) + length = strlen (weechat_data_dir) +
strlen (weechat_plugin->name) + 8 + strlen (weechat_plugin->name) + 8 +
strlen (base_name) + 16; strlen (base_name) + 16;
autoload_path = malloc (length); autoload_path = malloc (length);
@ -1499,7 +1495,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
{ {
snprintf (autoload_path, length, snprintf (autoload_path, length,
"%s/%s/autoload/%s", "%s/%s/autoload/%s",
dir_home, weechat_plugin->name, weechat_data_dir, weechat_plugin->name,
base_name); base_name);
if (autoload) if (autoload)
{ {
@ -1525,8 +1521,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
free (autoload_path); free (autoload_path);
} }
free (base_name); free (base_name);
if (dir_home) if (weechat_data_dir)
free (dir_home); free (weechat_data_dir);
} }
free (name); free (name);
} }

View File

@ -1017,6 +1017,7 @@ plugin_auto_load (char *force_plugin_autoload,
struct t_weechat_plugin *ptr_plugin; struct t_weechat_plugin *ptr_plugin;
struct t_plugin_args plugin_args; struct t_plugin_args plugin_args;
struct t_arraylist *arraylist; struct t_arraylist *arraylist;
struct t_hashtable *options;
int length, i; int length, i;
plugin_args.argc = argc; 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)
&& CONFIG_STRING(config_plugin_path)[0]) && 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), 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) if (plugin_path)
{ {
dir_exec_on_files (plugin_path, 1, 0, dir_exec_on_files (plugin_path, 1, 0,

View File

@ -797,7 +797,7 @@ weechat_python_load (const char *filename, const char *code)
#endif /* PY_MAJOR_VERSION >= 3 */ #endif /* PY_MAJOR_VERSION >= 3 */
FILE *fp; FILE *fp;
PyObject *python_path, *path, *module_main, *globals, *rc; PyObject *python_path, *path, *module_main, *globals, *rc;
char *weechat_sharedir, *weechat_home; char *weechat_sharedir, *weechat_data_dir;
char *str_sharedir, *str_home; char *str_sharedir, *str_home;
int len; int len;
@ -889,15 +889,15 @@ weechat_python_load (const char *filename, const char *code)
free (weechat_sharedir); free (weechat_sharedir);
} }
/* adding $weechat_dir/python in $PYTHONPATH */ /* add {weechat_data_dir}/python in $PYTHONPATH */
weechat_home = weechat_info_get ("weechat_dir", ""); weechat_data_dir = weechat_info_get ("weechat_data_dir", "");
if (weechat_home) 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); str_home = malloc (len);
if (str_home) 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 #if PY_MAJOR_VERSION >= 3
/* python >= 3.x */ /* python >= 3.x */
path = PyUnicode_FromString (str_home); path = PyUnicode_FromString (str_home);
@ -912,7 +912,7 @@ weechat_python_load (const char *filename, const char *code)
} }
free (str_home); free (str_home);
} }
free (weechat_home); free (weechat_data_dir);
} }

View File

@ -49,15 +49,25 @@ relay_network_set_ssl_cert_key (int verbose)
{ {
char *certkey_path; char *certkey_path;
int ret; int ret;
struct t_hashtable *options;
gnutls_certificate_free_credentials (relay_gnutls_x509_cred); gnutls_certificate_free_credentials (relay_gnutls_x509_cred);
gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred); gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred);
relay_network_init_ssl_cert_key_ok = 0; 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 ( certkey_path = weechat_string_eval_path_home (
weechat_config_string (relay_config_network_ssl_cert_key), weechat_config_string (relay_config_network_ssl_cert_key),
NULL, NULL, NULL); NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
if (certkey_path) if (certkey_path)
{ {
ret = gnutls_certificate_set_x509_key_file (relay_gnutls_x509_cred, ret = gnutls_certificate_set_x509_key_file (relay_gnutls_x509_cred,

View File

@ -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) int ipv4, int ipv6, int ssl, int unix_socket)
{ {
struct t_relay_server *new_server, *dup_server; struct t_relay_server *new_server, *dup_server;
struct t_hashtable *options;
if (!protocol_string) if (!protocol_string)
return NULL; return NULL;
@ -823,8 +824,17 @@ relay_server_new (const char *protocol_string, enum t_relay_protocol protocol,
new_server->protocol_args = new_server->protocol_args =
(protocol_args) ? strdup (protocol_args) : NULL; (protocol_args) ? strdup (protocol_args) : NULL;
new_server->port = port; 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, 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->ipv4 = ipv4;
new_server->ipv6 = ipv6; new_server->ipv6 = ipv6;
new_server->ssl = ssl; new_server->ssl = ssl;
@ -862,8 +872,18 @@ void
relay_server_update_path (struct t_relay_server *server, const char *path) relay_server_update_path (struct t_relay_server *server, const char *path)
{ {
char *new_path; char *new_path;
struct t_hashtable *options;
new_path = weechat_string_eval_path_home (path, NULL, NULL, NULL); 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) if (!new_path)
return; return;

View File

@ -1523,7 +1523,7 @@ script_action_schedule (const char *action,
int quiet) int quiet)
{ {
/* create again "script" directory, just in case it has been removed */ /* 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; return;
script_action_add (action); script_action_add (action);

View File

@ -189,7 +189,7 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
struct t_gui_completion *completion) struct t_gui_completion *completion)
{ {
char *weechat_home, *directory; char *weechat_data_dir, *directory;
int length, i; int length, i;
void *pointers[2]; void *pointers[2];
@ -199,9 +199,9 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
(void) completion_item; (void) completion_item;
(void) buffer; (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); directory = malloc (length);
if (directory) if (directory)
{ {
@ -210,16 +210,16 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
pointers[0] = completion; pointers[0] = completion;
pointers[1] = script_extension[i]; pointers[1] = script_extension[i];
/* look for files in "~/.weechat/<language>/" */ /* look for files in <weechat_data_dir>/<language> */
snprintf (directory, length, 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, weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb, &script_completion_exec_file_cb,
pointers); pointers);
/* look for files in "~/.weechat/<language>/autoload/" */ /* look for files in <weechat_data_dir>/<language>/autoload */
snprintf (directory, length, 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, weechat_exec_on_files (directory, 0, 0,
&script_completion_exec_file_cb, &script_completion_exec_file_cb,
pointers); pointers);
@ -227,8 +227,8 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
free (directory); free (directory);
} }
if (weechat_home) if (weechat_data_dir)
free (weechat_home); free (weechat_data_dir);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }

View File

@ -148,8 +148,7 @@ script_config_get_diff_command ()
} }
/* /*
* Gets filename with script * Gets filename with list of scripts.
* (by default "/home/xxx/.weechat/script/plugins.xml.gz").
* *
* Note: result must be freed after use. * Note: result must be freed after use.
*/ */
@ -159,9 +158,19 @@ script_config_get_xml_filename ()
{ {
char *path, *filename; char *path, *filename;
int length; 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 ( 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; length = strlen (path) + 64;
filename = malloc (length); filename = malloc (length);
if (filename) if (filename)
@ -172,11 +181,8 @@ script_config_get_xml_filename ()
/* /*
* Gets filename for a script to download. * Gets filename for a script to download.
*
* If suffix is not NULL, it is added to filename. * If suffix is not NULL, it is added to filename.
* *
* Example: "/home/xxx/.weechat/script/go.py"
*
* Note: result must be freed after use. * 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; char *path, *filename;
int length; 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 ( 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) length = strlen (path) + 1 + strlen (script->name_with_extension)
+ ((suffix) ? strlen (suffix) : 0) + 1; + ((suffix) ? strlen (suffix) : 0) + 1;
filename = malloc (length); filename = malloc (length);

View File

@ -165,28 +165,28 @@ script_repo_search_by_name_ext (const char *name_with_extension)
char * char *
script_repo_get_filename_loaded (struct t_script_repo *script) 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; int length;
struct stat st; struct stat st;
weechat_home = weechat_info_get ("weechat_dir", NULL); weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64; length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length); filename = malloc (length);
if (!filename) if (!filename)
{ {
if (weechat_home) if (weechat_data_dir)
free (weechat_home); free (weechat_data_dir);
return NULL; return NULL;
} }
snprintf (filename, length, "%s/%s/autoload/%s", snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home, weechat_data_dir,
script_language[script->language], script_language[script->language],
script->name_with_extension); script->name_with_extension);
if (stat (filename, &st) != 0) if (stat (filename, &st) != 0)
{ {
snprintf (filename, length, "%s/%s/%s", snprintf (filename, length, "%s/%s/%s",
weechat_home, weechat_data_dir,
script_language[script->language], script_language[script->language],
script->name_with_extension); script->name_with_extension);
if (stat (filename, &st) != 0) if (stat (filename, &st) != 0)
@ -195,8 +195,8 @@ script_repo_get_filename_loaded (struct t_script_repo *script)
} }
} }
if (weechat_home) if (weechat_data_dir)
free (weechat_home); free (weechat_data_dir);
if (!filename[0]) if (!filename[0])
{ {
@ -798,7 +798,7 @@ void
script_repo_update_status (struct t_script_repo *script) script_repo_update_status (struct t_script_repo *script)
{ {
const char *version; const char *version;
char *weechat_home, *filename, *sha512sum; char *weechat_data_dir, *filename, *sha512sum;
struct stat st; struct stat st;
int length; int length;
struct t_script_repo *ptr_script; struct t_script_repo *ptr_script;
@ -807,13 +807,13 @@ script_repo_update_status (struct t_script_repo *script)
sha512sum = NULL; sha512sum = NULL;
/* check if script is installed (file found on disk) */ /* check if script is installed (file found on disk) */
weechat_home = weechat_info_get ("weechat_dir", NULL); weechat_data_dir = weechat_info_get ("weechat_data_dir", NULL);
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64; length = strlen (weechat_data_dir) + strlen (script->name_with_extension) + 64;
filename = malloc (length); filename = malloc (length);
if (filename) if (filename)
{ {
snprintf (filename, length, "%s/%s/autoload/%s", snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home, weechat_data_dir,
script_language[script->language], script_language[script->language],
script->name_with_extension); script->name_with_extension);
if (stat (filename, &st) == 0) if (stat (filename, &st) == 0)
@ -825,7 +825,7 @@ script_repo_update_status (struct t_script_repo *script)
else else
{ {
snprintf (filename, length, "%s/%s/%s", snprintf (filename, length, "%s/%s/%s",
weechat_home, weechat_data_dir,
script_language[script->language], script_language[script->language],
script->name_with_extension); script->name_with_extension);
if (stat (filename, &st) == 0) if (stat (filename, &st) == 0)
@ -837,8 +837,8 @@ script_repo_update_status (struct t_script_repo *script)
free (filename); free (filename);
} }
if (weechat_home) if (weechat_data_dir)
free (weechat_home); free (weechat_data_dir);
/* check if script is held */ /* check if script is held */
if (script_repo_script_is_held (script)) if (script_repo_script_is_held (script))

View File

@ -371,7 +371,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
script_config_read (); script_config_read ();
weechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755); weechat_mkdir_home ("${weechat_cache_dir}/" SCRIPT_PLUGIN_NAME, 0755);
script_command_init (); script_command_init ();
script_completion_init (); script_completion_init ();

View File

@ -195,9 +195,9 @@ spell_warning_aspell_config ()
char *aspell_filename, *spell_filename; char *aspell_filename, *spell_filename;
aspell_filename = weechat_string_eval_path_home ( 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 ( 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.conf is there and not spell.conf, display a warning */
if (aspell_filename && spell_filename if (aspell_filename && spell_filename

View File

@ -210,13 +210,23 @@ void
xfer_file_find_filename (struct t_xfer *xfer) xfer_file_find_filename (struct t_xfer *xfer)
{ {
char *dir_separator, *path; char *dir_separator, *path;
struct t_hashtable *options;
if (!XFER_IS_FILE(xfer->type)) if (!XFER_IS_FILE(xfer->type))
return; 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 ( path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_download_path), weechat_config_string (xfer_config_file_download_path),
NULL, NULL, NULL); NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
if (!path) if (!path)
return; return;

View File

@ -145,11 +145,20 @@ void
xfer_create_directories () xfer_create_directories ()
{ {
char *path; 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 */ /* create download directory */
path = weechat_string_eval_path_home ( path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_download_path), weechat_config_string (xfer_config_file_download_path),
NULL, NULL, NULL); NULL, NULL, options);
if (path) if (path)
{ {
(void) weechat_mkdir_parents (path, 0700); (void) weechat_mkdir_parents (path, 0700);
@ -159,12 +168,15 @@ xfer_create_directories ()
/* create upload directory */ /* create upload directory */
path = weechat_string_eval_path_home ( path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_upload_path), weechat_config_string (xfer_config_file_upload_path),
NULL, NULL, NULL); NULL, NULL, options);
if (path) if (path)
{ {
(void) weechat_mkdir_parents (path, 0700); (void) weechat_mkdir_parents (path, 0700);
free (path); 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; socklen_t length, bind_addr_len;
unsigned long long file_size; unsigned long long file_size;
struct t_xfer *ptr_xfer; struct t_xfer *ptr_xfer;
struct t_hashtable *options;
/* make C compiler happy */ /* make C compiler happy */
(void) pointer; (void) pointer;
@ -1170,9 +1183,18 @@ xfer_add_cb (const void *pointer, void *data,
filename2 = weechat_string_expand_home (filename); filename2 = weechat_string_expand_home (filename);
else 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 ( path = weechat_string_eval_path_home (
weechat_config_string (xfer_config_file_upload_path), weechat_config_string (xfer_config_file_upload_path),
NULL, NULL, NULL); NULL, NULL, options);
if (options)
weechat_hashtable_free (options);
if (!path) if (!path)
{ {
weechat_printf (NULL, weechat_printf (NULL,

View File

@ -160,8 +160,9 @@ TEST(Scripts, API)
test_scripts_dir, test_scripts_dir,
DIR_SEPARATOR, DIR_SEPARATOR,
"testapi.py"); "testapi.py");
path_testapi_output_dir = string_eval_path_home ("%h/testapi", path_testapi_output_dir = string_eval_path_home (
NULL, NULL, NULL); "${weechat_data_dir}/testapi",
NULL, NULL, NULL);
CHECK(path_testapi_output_dir); CHECK(path_testapi_output_dir);
api_tests_ok = 0; api_tests_ok = 0;

View File

@ -35,6 +35,16 @@ TEST_GROUP(CoreDir)
{ {
}; };
/*
* Tests functions:
* dir_get_temp_dir
*/
TEST(CoreDir, GetTempDir)
{
/* TODO: write tests */
}
/* /*
* Tests functions: * Tests functions:
* dir_mkdir_home * dir_mkdir_home
@ -47,6 +57,16 @@ TEST(CoreDir, Mkdir)
/* TODO: write tests */ /* TODO: write tests */
} }
/*
* Tests functions:
* dir_rmtree
*/
TEST(CoreDir, Rmtree)
{
/* TODO: write tests */
}
/* /*
* Tests functions: * Tests functions:
* dir_exec_on_files * dir_exec_on_files
@ -62,7 +82,7 @@ TEST(CoreDir, ExecOnFiles)
* dir_search_full_lib_name * dir_search_full_lib_name
*/ */
TEST(CoreDir, LibName) TEST(CoreDir, SearchFullLibName)
{ {
/* TODO: write tests */ /* TODO: write tests */
} }
@ -84,7 +104,8 @@ TEST(CoreDir, FileGetContent)
POINTERS_EQUAL(NULL, dir_file_get_content ("")); POINTERS_EQUAL(NULL, dir_file_get_content (""));
POINTERS_EQUAL(NULL, dir_file_get_content ("/tmp/does/not/exist.xyz")); POINTERS_EQUAL(NULL, dir_file_get_content ("/tmp/does/not/exist.xyz"));
path = string_eval_path_home ("%h/test_file.txt", NULL, NULL, NULL); path = string_eval_path_home ("${weechat_data_dir}/test_file.txt",
NULL, NULL, NULL);
/* small file */ /* small file */
length = strlen (content_small); length = strlen (content_small);
@ -125,6 +146,37 @@ TEST(CoreDir, FileGetContent)
TEST(CoreDir, SetHomePath) TEST(CoreDir, SetHomePath)
{ {
/* TODO: write tests */
}
/*
* Tests functions:
* dir_create_home_temp_dir
*/
TEST(CoreDir, CreateHomeTempDir)
{
/* TODO: write tests */
}
/*
* Tests functions:
* dir_find_xdg_dirs
*/
TEST(CoreDir, FindXdgDirs)
{
/* TODO: write tests */
}
/*
* Tests functions:
* dir_find_home_dirs
*/
TEST(CoreDir, FindHomeDirs)
{
/* TODO: write tests */
} }
/* /*
@ -134,4 +186,35 @@ TEST(CoreDir, SetHomePath)
TEST(CoreDir, CreateHomeDir) TEST(CoreDir, CreateHomeDir)
{ {
/* TODO: write tests */
}
/*
* Tests functions:
* dir_create_home_dirs
*/
TEST(CoreDir, CreateHomeDirs)
{
/* TODO: write tests */
}
/*
* Tests functions:
* dir_remove_home_dirs
*/
TEST(CoreDir, RemoveHomeDirs)
{
/* TODO: write tests */
}
/*
* Tests functions:
* dir_get_string_home_dirs
*/
TEST(CoreDir, GetStringHomeDirs)
{
/* TODO: write tests */
} }

View File

@ -664,13 +664,17 @@ TEST(CoreString, ExpandHome)
TEST(CoreString, EvalPathHome) TEST(CoreString, EvalPathHome)
{ {
char *home, *result; char *home, *result;
int length_home, length_weechat_home; int length_home, length_weechat_config_dir, length_weechat_data_dir;
struct t_hashtable *extra_vars; int length_weechat_cache_dir, length_weechat_runtime_dir;
struct t_hashtable *extra_vars, *options;
home = getenv ("HOME"); home = getenv ("HOME");
length_home = strlen (home); length_home = strlen (home);
length_weechat_home = strlen (weechat_home); length_weechat_config_dir = strlen (weechat_config_dir);
length_weechat_data_dir = strlen (weechat_data_dir);
length_weechat_cache_dir = strlen (weechat_cache_dir);
length_weechat_runtime_dir = strlen (weechat_runtime_dir);
POINTERS_EQUAL(NULL, string_eval_path_home (NULL, NULL, NULL, NULL)); POINTERS_EQUAL(NULL, string_eval_path_home (NULL, NULL, NULL, NULL));
@ -684,19 +688,91 @@ TEST(CoreString, EvalPathHome)
STRCMP_EQUAL(result + length_home, "/test"); STRCMP_EQUAL(result + length_home, "/test");
free (result); free (result);
/* "%h" is weechat_data_dir by default */
result = string_eval_path_home ("%h/test", NULL, NULL, NULL); result = string_eval_path_home ("%h/test", NULL, NULL, NULL);
CHECK(strncmp (result, weechat_home, length_weechat_home) == 0); CHECK(strncmp (result, weechat_data_dir, length_weechat_data_dir) == 0);
LONGS_EQUAL(length_weechat_home + 5, strlen (result)); LONGS_EQUAL(length_weechat_data_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_home, "/test"); STRCMP_EQUAL(result + length_weechat_data_dir, "/test");
free (result);
options = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
/* "%h" with forced config dir */
hashtable_set (options, "directory", "config");
result = string_eval_path_home ("%h/test", NULL, NULL, options);
CHECK(strncmp (result, weechat_config_dir, length_weechat_config_dir) == 0);
LONGS_EQUAL(length_weechat_config_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_config_dir, "/test");
free (result);
/* "%h" with forced data dir */
hashtable_set (options, "directory", "data");
result = string_eval_path_home ("%h/test", NULL, NULL, options);
CHECK(strncmp (result, weechat_data_dir, length_weechat_data_dir) == 0);
LONGS_EQUAL(length_weechat_data_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_data_dir, "/test");
free (result);
/* "%h" with forced cache dir */
hashtable_set (options, "directory", "cache");
result = string_eval_path_home ("%h/test", NULL, NULL, options);
CHECK(strncmp (result, weechat_cache_dir, length_weechat_cache_dir) == 0);
LONGS_EQUAL(length_weechat_cache_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_cache_dir, "/test");
free (result);
/* "%h" with forced runtime dir */
hashtable_set (options, "directory", "runtime");
result = string_eval_path_home ("%h/test", NULL, NULL, options);
CHECK(strncmp (result, weechat_runtime_dir, length_weechat_runtime_dir) == 0);
LONGS_EQUAL(length_weechat_runtime_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_runtime_dir, "/test");
free (result);
hashtable_free (options);
/* config dir */
result = string_eval_path_home ("${weechat_config_dir}/path",
NULL, NULL, NULL);
CHECK(strncmp (result, weechat_config_dir, length_weechat_config_dir) == 0);
LONGS_EQUAL(length_weechat_config_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_config_dir, "/path");
free (result);
/* data dir */
result = string_eval_path_home ("${weechat_data_dir}/path",
NULL, NULL, NULL);
CHECK(strncmp (result, weechat_data_dir, length_weechat_data_dir) == 0);
LONGS_EQUAL(length_weechat_data_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_data_dir, "/path");
free (result);
/* cache dir */
result = string_eval_path_home ("${weechat_cache_dir}/path",
NULL, NULL, NULL);
CHECK(strncmp (result, weechat_cache_dir, length_weechat_cache_dir) == 0);
LONGS_EQUAL(length_weechat_cache_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_cache_dir, "/path");
free (result);
/* runtime dir */
result = string_eval_path_home ("${weechat_runtime_dir}/path",
NULL, NULL, NULL);
CHECK(strncmp (result, weechat_runtime_dir, length_weechat_runtime_dir) == 0);
LONGS_EQUAL(length_weechat_runtime_dir + 5, strlen (result));
STRCMP_EQUAL(result + length_weechat_runtime_dir, "/path");
free (result); free (result);
setenv ("WEECHAT_TEST_PATH", "path1", 1); setenv ("WEECHAT_TEST_PATH", "path1", 1);
result = string_eval_path_home ("%h/${env:WEECHAT_TEST_PATH}/path2", result = string_eval_path_home ("%h/${env:WEECHAT_TEST_PATH}/path2",
NULL, NULL, NULL); NULL, NULL, NULL);
CHECK(strncmp (result, weechat_home, length_weechat_home) == 0); CHECK(strncmp (result, weechat_data_dir, length_weechat_data_dir) == 0);
LONGS_EQUAL(length_weechat_home + 12, strlen (result)); LONGS_EQUAL(length_weechat_data_dir + 12, strlen (result));
STRCMP_EQUAL(result + length_weechat_home, "/path1/path2"); STRCMP_EQUAL(result + length_weechat_data_dir, "/path1/path2");
free (result); free (result);
extra_vars = hashtable_new (32, extra_vars = hashtable_new (32,
@ -708,9 +784,9 @@ TEST(CoreString, EvalPathHome)
result = string_eval_path_home ("%h/${env:WEECHAT_TEST_PATH}/${path2}", result = string_eval_path_home ("%h/${env:WEECHAT_TEST_PATH}/${path2}",
NULL, extra_vars, NULL); NULL, extra_vars, NULL);
CHECK(strncmp (result, weechat_home, length_weechat_home) == 0); CHECK(strncmp (result, weechat_data_dir, length_weechat_data_dir) == 0);
LONGS_EQUAL(length_weechat_home + 12, strlen (result)); LONGS_EQUAL(length_weechat_data_dir + 12, strlen (result));
STRCMP_EQUAL(result + length_weechat_home, "/path1/value"); STRCMP_EQUAL(result + length_weechat_data_dir, "/path1/value");
free (result); free (result);
hashtable_free (extra_vars); hashtable_free (extra_vars);