mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
Add function "string_expand_home" in plugin API, fix bug with replacement of home in paths
This commit is contained in:
@@ -2572,8 +2572,8 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session,
|
||||
weechat_dir = weechat_info_get ("weechat_dir", "");
|
||||
cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir);
|
||||
cert_path2 = (cert_path1) ?
|
||||
weechat_string_replace (cert_path1, "~", getenv ("HOME")) : NULL;
|
||||
|
||||
weechat_string_expand_home (cert_path1) : NULL;
|
||||
|
||||
if (cert_path2)
|
||||
{
|
||||
cert_str = weechat_file_get_content (cert_path2);
|
||||
|
||||
@@ -82,8 +82,7 @@ logger_get_file_path ()
|
||||
goto end;
|
||||
|
||||
/* replace "~" with user home */
|
||||
file_path = weechat_string_replace (weechat_config_string (logger_config_file_path),
|
||||
"~", getenv ("HOME"));
|
||||
file_path = weechat_string_expand_home (weechat_config_string (logger_config_file_path));
|
||||
if (!file_path)
|
||||
goto end;
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ plugin_find_pos (struct t_weechat_plugin *plugin)
|
||||
struct t_weechat_plugin *
|
||||
plugin_load (const char *filename)
|
||||
{
|
||||
char *ptr_home, *full_name, *full_name2;
|
||||
char *full_name, *full_name2;
|
||||
void *handle;
|
||||
char *name, *api_version, *author, *description, *version;
|
||||
char *license, *charset;
|
||||
@@ -260,9 +260,7 @@ plugin_load (const char *filename)
|
||||
if (plugin_autoload_array && !plugin_check_autoload (full_name))
|
||||
return NULL;
|
||||
|
||||
ptr_home = getenv ("HOME");
|
||||
full_name2 = string_replace (full_name, "~", ptr_home);
|
||||
|
||||
full_name2 = string_expand_home (full_name);
|
||||
if (full_name2)
|
||||
{
|
||||
free (full_name);
|
||||
@@ -462,6 +460,7 @@ plugin_load (const char *filename)
|
||||
new_plugin->strcasestr = &string_strcasestr;
|
||||
new_plugin->string_match = &string_match;
|
||||
new_plugin->string_replace = &string_replace;
|
||||
new_plugin->string_expand_home = &string_expand_home;
|
||||
new_plugin->string_remove_quotes = &string_remove_quotes;
|
||||
new_plugin->string_strip = &string_strip;
|
||||
new_plugin->string_has_highlight = &string_has_highlight;
|
||||
@@ -780,7 +779,7 @@ plugin_auto_load_file (void *plugin, const char *filename)
|
||||
void
|
||||
plugin_auto_load ()
|
||||
{
|
||||
char *ptr_home, *dir_name, *plugin_path, *plugin_path2;
|
||||
char *dir_name, *plugin_path, *plugin_path2;
|
||||
|
||||
plugin_autoload_array = NULL;
|
||||
plugin_autoload_count = 0;
|
||||
@@ -797,9 +796,7 @@ plugin_auto_load ()
|
||||
if (CONFIG_STRING(config_plugin_path)
|
||||
&& CONFIG_STRING(config_plugin_path)[0])
|
||||
{
|
||||
ptr_home = getenv ("HOME");
|
||||
plugin_path = string_replace (CONFIG_STRING(config_plugin_path),
|
||||
"~", ptr_home);
|
||||
plugin_path = string_expand_home (CONFIG_STRING(config_plugin_path));
|
||||
plugin_path2 = string_replace ((plugin_path) ?
|
||||
plugin_path : CONFIG_STRING(config_plugin_path),
|
||||
"%h", weechat_home);
|
||||
|
||||
@@ -482,19 +482,7 @@ script_search_path (struct t_weechat_plugin *weechat_plugin,
|
||||
struct stat st;
|
||||
|
||||
if (filename[0] == '~')
|
||||
{
|
||||
dir_home = getenv ("HOME");
|
||||
if (!dir_home)
|
||||
return NULL;
|
||||
length = strlen (dir_home) + strlen (filename + 1) + 1;
|
||||
final_name = malloc (length);
|
||||
if (final_name)
|
||||
{
|
||||
snprintf (final_name, length, "%s%s", dir_home, filename + 1);
|
||||
return final_name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return weechat_string_expand_home (filename);
|
||||
|
||||
dir_home = weechat_info_get ("weechat_dir", "");
|
||||
if (dir_home)
|
||||
|
||||
@@ -39,7 +39,7 @@ struct timeval;
|
||||
*/
|
||||
|
||||
/* API version (used to check that plugin has same API and can be loaded) */
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20100302-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20100502-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -134,7 +134,11 @@ struct t_weechat_plugin
|
||||
struct t_weechat_plugin *prev_plugin; /* link to previous plugin */
|
||||
struct t_weechat_plugin *next_plugin; /* link to next plugin */
|
||||
|
||||
/* plugin functions (API) */
|
||||
/*
|
||||
* plugin functions (API)
|
||||
* WeeChat developers: if you add functions in API, update value of
|
||||
* constant WEECHAT_PLUGIN_API_VERSION
|
||||
*/
|
||||
|
||||
/* plugins */
|
||||
const char *(*plugin_get_name) (struct t_weechat_plugin *plugin);
|
||||
@@ -157,6 +161,7 @@ struct t_weechat_plugin
|
||||
int case_sensitive);
|
||||
char *(*string_replace) (const char *string, const char *search,
|
||||
const char *replace);
|
||||
char *(*string_expand_home) (const char *path);
|
||||
char *(*string_remove_quotes) (const char *string, const char *quotes);
|
||||
char *(*string_strip) (const char *string, int left, int right,
|
||||
const char *chars);
|
||||
@@ -644,8 +649,6 @@ struct t_weechat_plugin
|
||||
struct t_infolist *infolist),
|
||||
void *callback_read_data);
|
||||
void (*upgrade_close) (struct t_upgrade_file *upgrade_file);
|
||||
|
||||
/* WeeChat developers: ALWAYS add new functions at the end */
|
||||
};
|
||||
|
||||
extern int weechat_plugin_init (struct t_weechat_plugin *plugin,
|
||||
@@ -697,6 +700,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->string_match(__string, __mask, __case_sensitive)
|
||||
#define weechat_string_replace(__string, __search, __replace) \
|
||||
weechat_plugin->string_replace(__string, __search, __replace)
|
||||
#define weechat_string_expand_home(__path) \
|
||||
weechat_plugin->string_expand_home(__path)
|
||||
#define weechat_string_remove_quotes(__string, __quotes) \
|
||||
weechat_plugin->string_remove_quotes(__string, __quotes)
|
||||
#define weechat_string_strip(__string, __left, __right, __chars) \
|
||||
|
||||
@@ -84,9 +84,7 @@ xfer_file_find_filename (struct t_xfer *xfer)
|
||||
if (!XFER_IS_FILE(xfer->type))
|
||||
return;
|
||||
|
||||
dir1 = weechat_string_replace (weechat_config_string (xfer_config_file_download_path),
|
||||
"~",
|
||||
getenv ("HOME"));
|
||||
dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_download_path));
|
||||
if (!dir1)
|
||||
return;
|
||||
|
||||
|
||||
@@ -134,8 +134,7 @@ xfer_create_directories ()
|
||||
weechat_dir = weechat_info_get ("weechat_dir", "");
|
||||
if (weechat_dir)
|
||||
{
|
||||
dir1 = weechat_string_replace (weechat_config_string (xfer_config_file_download_path),
|
||||
"~", getenv ("HOME"));
|
||||
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);
|
||||
@@ -817,12 +816,10 @@ xfer_add_cb (void *data, const char *signal, const char *type_data,
|
||||
if (filename[0] == '/')
|
||||
filename2 = strdup (filename);
|
||||
else if (filename[0] == '~')
|
||||
filename2 = weechat_string_replace (filename, "~", getenv ("HOME"));
|
||||
filename2 = weechat_string_expand_home (filename);
|
||||
else
|
||||
{
|
||||
dir1 = weechat_string_replace (weechat_config_string (xfer_config_file_upload_path),
|
||||
"~",
|
||||
getenv ("HOME"));
|
||||
dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_upload_path));
|
||||
if (!dir1)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
|
||||
Reference in New Issue
Block a user