buflist: remove recursive evaluation of extra variables (closes #1060)

v2.8-utf8proc
Sébastien Helleu 2017-09-02 14:00:20 +02:00
parent 24418b30a0
commit 8c046d9be9
5 changed files with 102 additions and 30 deletions

View File

@ -38,6 +38,7 @@ Bug fixes::
* core: call the config hook when options are renamed or removed
* api: change type of arguments status/gnutls_rc/sock in hook_connect() callback from string to integer (in scripts)
* api: change type of argument fd in hook_fd() callback from string to integer (in scripts)
* buflist: remove recursive evaluation of extra variables (issue #1060)
* buflist: fix crash in auto-scroll of bar when the buflist item is not the first item in the bar
* irc: fix CTCP PING reply when the option irc.ctcp.ping is set to non-empty value
* relay: fix send of "PART" command in backlog (irc protocol)

View File

@ -20,6 +20,21 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
[[v2.0]]
== Version 2.0 (under dev)
[[v2.0_buflist_eval]]
=== Evaluation in buflist
The evaluation of expressions in buflist options is not recursive any more,
to prevent too many evaluations, for example in buffer variables
(see issue #1060 for more information). +
If you are using custom variables/options containing evaluated expressions,
like `${some.config.option}`, and if this option contains evaluated strings (`${...}`),
you must evaluate them with: `${eval:${some.config.option}}`.
[NOTE]
The default buflist formats (`${format_buffer}`, `${format_name}`,
`${format_hotlist}`, ...) are automatically evaluated in options _buflist.format.buffer_,
_buflist.format.buffer_current_ and _buflist.format.hotlist_.
[[v2.0_hook_connect]]
=== Function hook_connect
@ -43,8 +58,8 @@ No release note.
[[v1.8]]
== Version 1.8 (2017-05-13)
[[v1.8_options]]
=== Options
The option _script.scripts.url_force_https_ has been removed because now the

View File

@ -32,7 +32,6 @@
struct t_gui_bar_item *buflist_bar_item_buflist = NULL;
struct t_hashtable *buflist_hashtable_pointers = NULL;
struct t_hashtable *buflist_hashtable_extra_vars = NULL;
struct t_hashtable *buflist_hashtable_options = NULL;
struct t_hashtable *buflist_hashtable_options_conditions = NULL;
struct t_arraylist *buflist_list_buffers = NULL;
@ -257,8 +256,8 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
buflist = weechat_string_dyn_alloc (256);
ptr_format = weechat_config_string (buflist_config_format_buffer);
ptr_format_current = weechat_config_string (buflist_config_format_buffer_current);
ptr_format = buflist_config_format_buffer_eval;
ptr_format_current = buflist_config_format_buffer_current_eval;
ptr_current_buffer = weechat_current_buffer ();
@ -434,8 +433,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
/* set extra variables */
weechat_hashtable_set (buflist_hashtable_extra_vars,
"format_buffer",
weechat_config_string (
buflist_config_format_buffer));
buflist_config_format_buffer_eval);
weechat_hashtable_set (buflist_hashtable_extra_vars,
"number", str_number);
weechat_hashtable_set (buflist_hashtable_extra_vars,
@ -508,7 +506,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
weechat_hashtable_set (
buflist_hashtable_extra_vars,
"format_hotlist",
(str_hotlist) ? weechat_config_string (buflist_config_format_hotlist) : "");
(str_hotlist) ? buflist_config_format_hotlist_eval : "");
weechat_hashtable_set (buflist_hashtable_extra_vars,
"hotlist",
(str_hotlist) ? str_hotlist : "");
@ -535,7 +533,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
(current_buffer) ? ptr_format_current : ptr_format,
buflist_hashtable_pointers,
buflist_hashtable_extra_vars,
buflist_hashtable_options);
NULL);
/* concatenate string */
rc = weechat_string_dyn_concat (buflist, line);
@ -600,20 +598,6 @@ buflist_bar_item_init ()
return 0;
}
buflist_hashtable_options = weechat_hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (!buflist_hashtable_options)
{
weechat_hashtable_free (buflist_hashtable_pointers);
weechat_hashtable_free (buflist_hashtable_extra_vars);
return 0;
}
weechat_hashtable_set (buflist_hashtable_options, "extra", "eval");
buflist_hashtable_options_conditions = weechat_hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
@ -623,7 +607,6 @@ buflist_bar_item_init ()
{
weechat_hashtable_free (buflist_hashtable_pointers);
weechat_hashtable_free (buflist_hashtable_extra_vars);
weechat_hashtable_free (buflist_hashtable_options);
return 0;
}
weechat_hashtable_set (buflist_hashtable_options_conditions,
@ -652,9 +635,6 @@ buflist_bar_item_end ()
weechat_hashtable_free (buflist_hashtable_extra_vars);
buflist_hashtable_extra_vars = NULL;
weechat_hashtable_free (buflist_hashtable_options);
buflist_hashtable_options = NULL;
weechat_hashtable_free (buflist_hashtable_options_conditions);
buflist_hashtable_options_conditions = NULL;

View File

@ -20,6 +20,7 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
@ -62,6 +63,9 @@ struct t_hook **buflist_config_signals_refresh = NULL;
int buflist_config_num_signals_refresh = 0;
char **buflist_config_sort_fields = NULL;
int buflist_config_sort_fields_count = 0;
char *buflist_config_format_buffer_eval = NULL;
char *buflist_config_format_buffer_current_eval = NULL;
char *buflist_config_format_hotlist_eval = NULL;
/*
@ -292,7 +296,7 @@ buflist_config_change_nick_prefix (const void *pointer, void *data,
}
/*
* Callback for changes on format options.
* Callback for changes on options needing bar item refresh.
*/
void
@ -307,6 +311,67 @@ buflist_config_change_buflist (const void *pointer, void *data,
buflist_bar_item_update ();
}
/*
* Replace formats like ${format_xxx} by evaluated form: ${eval:${format_xxx}}.
*
* Note: result must be freed after use.
*/
char *
buflist_config_add_eval_for_formats (const char *string)
{
char *formats[] = { "format_buffer", "format_number", "indent",
"format_nick_prefix", "format_name",
"format_hotlist", "hotlist", "format_lag",
"color_hotlist", NULL };
char *result, *tmp, format[512], format_eval[512];
int i;
result = strdup (string);
for (i = 0; formats[i]; i++)
{
snprintf (format, sizeof (format),
"${%s}", formats[i]);
snprintf (format_eval, sizeof (format_eval),
"${eval:${%s}}", formats[i]);
tmp = weechat_string_replace (result, format, format_eval);
free (result);
result = tmp;
}
return result;
}
/*
* Callback for changes on some format options.
*/
void
buflist_config_change_format (const void *pointer, void *data,
struct t_config_option *option)
{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
if (buflist_config_format_buffer_eval)
free (buflist_config_format_buffer_eval);
buflist_config_format_buffer_eval = buflist_config_add_eval_for_formats (
weechat_config_string (buflist_config_format_buffer));
if (buflist_config_format_buffer_current_eval)
free (buflist_config_format_buffer_current_eval);
buflist_config_format_buffer_current_eval = buflist_config_add_eval_for_formats (
weechat_config_string (buflist_config_format_buffer_current));
if (buflist_config_format_hotlist_eval)
free (buflist_config_format_hotlist_eval);
buflist_config_format_hotlist_eval = buflist_config_add_eval_for_formats (
weechat_config_string (buflist_config_format_hotlist));
buflist_bar_item_update ();
}
/*
* Initializes buflist configuration file.
*
@ -480,7 +545,7 @@ buflist_config_init ()
"${format_name}",
NULL, 0,
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
&buflist_config_change_format, NULL, NULL,
NULL, NULL, NULL);
buflist_config_format_buffer_current = weechat_config_new_option (
buflist_config_file, ptr_section,
@ -489,7 +554,7 @@ buflist_config_init ()
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0, "${color:,blue}${format_buffer}", NULL, 0,
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
&buflist_config_change_format, NULL, NULL,
NULL, NULL, NULL);
buflist_config_format_hotlist = weechat_config_new_option (
buflist_config_file, ptr_section,
@ -500,7 +565,7 @@ buflist_config_init ()
" ${color:green}(${hotlist}${color:green})",
NULL, 0,
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
&buflist_config_change_format, NULL, NULL,
NULL, NULL, NULL);
buflist_config_format_hotlist_level[0] = weechat_config_new_option (
buflist_config_file, ptr_section,
@ -624,6 +689,7 @@ buflist_config_read ()
{
buflist_config_change_sort (NULL, NULL, NULL);
buflist_config_change_signals_refresh (NULL, NULL, NULL);
buflist_config_change_format (NULL, NULL, NULL);
}
return rc;
@ -657,4 +723,11 @@ buflist_config_free ()
buflist_config_sort_fields = NULL;
buflist_config_sort_fields_count = 0;
}
if (buflist_config_format_buffer_eval)
free (buflist_config_format_buffer_eval);
if (buflist_config_format_buffer_current_eval)
free (buflist_config_format_buffer_current_eval);
if (buflist_config_format_hotlist_eval)
free (buflist_config_format_hotlist_eval);
}

View File

@ -58,6 +58,9 @@ extern struct t_config_option *buflist_config_format_number;
extern char **buflist_config_sort_fields;
extern int buflist_config_sort_fields_count;
extern char *buflist_config_format_buffer_eval;
extern char *buflist_config_format_buffer_current_eval;
extern char *buflist_config_format_hotlist_eval;
extern int buflist_config_init ();
extern int buflist_config_read ();