summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2015-06-27 08:11:28 +0200
committerSébastien Helleu <flashcode@flashtux.org>2015-06-27 08:11:28 +0200
commitfdd9c03e5a5670d6ecfa4d389df4e76d22fd3aad (patch)
treecd8a24be6787b03f91398e3222b6c2f6c6a84c53 /src
parent9e56308a4d3f051eccefe029eb1c17074ab63d84 (diff)
downloadweechat-fdd9c03e5a5670d6ecfa4d389df4e76d22fd3aad.zip
xfer: evaluate content of options xfer.file.download_path and xfer.file.upload_path (issue #388)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xfer/xfer-config.c12
-rw-r--r--src/plugins/xfer/xfer-file.c35
-rw-r--r--src/plugins/xfer/xfer.c60
3 files changed, 46 insertions, 61 deletions
diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c
index dec6db897..e2aba74a6 100644
--- a/src/plugins/xfer/xfer-config.c
+++ b/src/plugins/xfer/xfer-config.c
@@ -312,15 +312,17 @@ xfer_config_init ()
xfer_config_file_download_path = weechat_config_new_option (
xfer_config_file, ptr_section,
"download_path", "string",
- N_("path for writing incoming files (\"%h\" will be replaced by "
- "WeeChat home, \"~/.weechat\" by default)"),
+ N_("path for writing incoming files: \"%h\" at beginning of string is "
+ "replaced by WeeChat home (\"~/.weechat\" by default) "
+ "(note: content is evaluated, see /help eval)"),
NULL, 0, 0, "%h/xfer", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
xfer_config_file_upload_path = weechat_config_new_option (
xfer_config_file, ptr_section,
"upload_path", "string",
- N_("path for reading files when sending (when no path is "
- "specified by user) (\"%h\" will be replaced by "
- "WeeChat home, \"~/.weechat\" by default)"),
+ N_("path for reading files when sending (when no path is specified "
+ "by user): \"%h\" at beginning of string is replaced by WeeChat "
+ "home (\"~/.weechat\" by default) "
+ "(note: content is evaluated, see /help eval)"),
NULL, 0, 0, "~", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
xfer_config_file_use_nick_in_filename = weechat_config_new_option (
xfer_config_file, ptr_section,
diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c
index 63dc9e275..65f2cd42c 100644
--- a/src/plugins/xfer/xfer-file.c
+++ b/src/plugins/xfer/xfer-file.c
@@ -80,37 +80,29 @@ xfer_file_resume (struct t_xfer *xfer, const char *filename)
void
xfer_file_find_filename (struct t_xfer *xfer)
{
- const char *weechat_home, *dir_separator;
- char *dir1, *dir2, *filename2;
+ const char *dir_separator;
+ char *path, *filename2;
int length;
if (!XFER_IS_FILE(xfer->type))
return;
- dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_download_path));
- if (!dir1)
+ path = weechat_string_eval_path_home (
+ weechat_config_string (xfer_config_file_download_path),
+ NULL, NULL, NULL);
+ if (!path)
return;
- weechat_home = weechat_info_get ("weechat_dir", "");
- if (!weechat_home)
- {
- free (dir1);
- return;
- }
- dir2 = weechat_string_replace (dir1, "%h", weechat_home);
- if (!dir2)
- {
- free (dir1);
- return;
- }
-
- xfer->local_filename = malloc (strlen (dir2) +
+ xfer->local_filename = malloc (strlen (path) +
strlen (xfer->remote_nick) +
strlen (xfer->filename) + 4);
if (!xfer->local_filename)
+ {
+ free (path);
return;
+ }
- strcpy (xfer->local_filename, dir2);
+ strcpy (xfer->local_filename, path);
dir_separator = weechat_info_get("dir_separator", "");
if (dir_separator
&& (xfer->local_filename[strlen (xfer->local_filename) - 1] != dir_separator[0]))
@@ -122,10 +114,7 @@ xfer_file_find_filename (struct t_xfer *xfer)
}
strcat (xfer->local_filename, xfer->filename);
- if (dir1)
- free (dir1);
- if (dir2 )
- free (dir2);
+ free (path);
/* file already exists? */
if (access (xfer->local_filename, F_OK) == 0)
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index 02e73ec6d..84d43aade 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -140,21 +140,26 @@ xfer_signal_upgrade_cb (void *data, const char *signal, const char *type_data,
void
xfer_create_directories ()
{
- const char *weechat_dir;
- char *dir1, *dir2;
+ char *path;
/* create download directory */
- weechat_dir = weechat_info_get ("weechat_dir", "");
- if (weechat_dir)
+ path = weechat_string_eval_path_home (
+ weechat_config_string (xfer_config_file_download_path),
+ NULL, NULL, NULL);
+ if (path)
{
- dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_download_path));
- dir2 = weechat_string_replace (dir1, "%h", weechat_dir);
- if (dir2)
- (void) weechat_mkdir (dir2, 0700);
- if (dir1)
- free (dir1);
- if (dir2)
- free (dir2);
+ (void) weechat_mkdir_parents (path, 0700);
+ free (path);
+ }
+
+ /* create upload directory */
+ path = weechat_string_eval_path_home (
+ weechat_config_string (xfer_config_file_upload_path),
+ NULL, NULL, NULL);
+ if (path)
+ {
+ (void) weechat_mkdir_parents (path, 0700);
+ free (path);
}
}
@@ -998,9 +1003,9 @@ xfer_add_cb (void *data, const char *signal, const char *type_data,
struct t_infolist *infolist;
const char *plugin_name, *plugin_id, *str_type, *str_protocol;
const char *remote_nick, *local_nick, *charset_modifier, *filename, *proxy;
- const char *weechat_dir, *str_address, *str_port;
+ const char *str_address, *str_port;
int type, protocol, args, port_start, port_end, sock, port;
- char *dir1, *dir2, *filename2, *short_filename, *pos, str_port_temp[16];
+ char *path, *filename2, *short_filename, *pos, str_port_temp[16];
struct stat st;
struct sockaddr_storage addr, own_ip_addr, bind_addr;
struct sockaddr *out_addr = (struct sockaddr*)&addr;
@@ -1104,41 +1109,30 @@ xfer_add_cb (void *data, const char *signal, const char *type_data,
filename2 = weechat_string_expand_home (filename);
else
{
- dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_upload_path));
- if (!dir1)
- {
- weechat_printf (NULL,
- _("%s%s: not enough memory"),
- weechat_prefix ("error"), XFER_PLUGIN_NAME);
- goto error;
- }
-
- weechat_dir = weechat_info_get ("weechat_dir", "");
- dir2 = weechat_string_replace (dir1, "%h", weechat_dir);
- if (!dir2)
+ path = weechat_string_eval_path_home (
+ weechat_config_string (xfer_config_file_upload_path),
+ NULL, NULL, NULL);
+ if (!path)
{
weechat_printf (NULL,
_("%s%s: not enough memory"),
weechat_prefix ("error"), XFER_PLUGIN_NAME);
- free (dir1);
goto error;
}
- filename2 = malloc (strlen (dir2) + strlen (filename) + 4);
+ filename2 = malloc (strlen (path) + strlen (filename) + 4);
if (!filename2)
{
weechat_printf (NULL,
_("%s%s: not enough memory"),
weechat_prefix ("error"), XFER_PLUGIN_NAME);
- free (dir1);
- free (dir2);
+ free (path);
goto error;
}
- strcpy (filename2, dir2);
+ strcpy (filename2, path);
if (filename2[strlen (filename2) - 1] != DIR_SEPARATOR_CHAR)
strcat (filename2, DIR_SEPARATOR);
strcat (filename2, filename);
- free (dir1);
- free (dir2);
+ free (path);
}
#endif /* _WIN32 */
/* check if file exists */