summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c61
-rw-r--r--src/core/wee-input.c70
-rw-r--r--src/core/wee-input.h6
-rw-r--r--src/gui/gui-input.c2
-rw-r--r--src/gui/gui-key.c4
-rw-r--r--src/plugins/plugin-api.c33
6 files changed, 101 insertions, 75 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index ea3832952..a8ed5c72d 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -1413,7 +1413,7 @@ COMMAND_CALLBACK(color)
if (string_strcasecmp (argv[1], "-o") == 0)
{
gui_color_info_term_colors (str_color, sizeof (str_color));
- (void) input_data (buffer, str_color);
+ (void) input_data (buffer, str_color, NULL);
return WEECHAT_RC_OK;
}
@@ -1472,7 +1472,7 @@ COMMAND_CALLBACK(color)
"/set weechat.palette.%d \"%s\"",
(int)number,
(str_color[0]) ? str_color + 1 : "");
- (void) input_exec_command (buffer, 1, NULL, str_command);
+ (void) input_exec_command (buffer, 1, NULL, str_command, NULL);
return WEECHAT_RC_OK;
}
@@ -1519,7 +1519,7 @@ COMMAND_CALLBACK(color)
snprintf (str_command, sizeof (str_command),
"/unset weechat.palette.%d",
(int)number);
- (void) input_exec_command (buffer, 1, NULL, str_command);
+ (void) input_exec_command (buffer, 1, NULL, str_command, NULL);
return WEECHAT_RC_OK;
}
@@ -1628,7 +1628,7 @@ COMMAND_CALLBACK(command)
if (string_is_command_char (argv_eol[index_args + 1]))
{
(void) input_exec_command (ptr_buffer, any_plugin, ptr_plugin,
- argv_eol[index_args + 1]);
+ argv_eol[index_args + 1], NULL);
}
else
{
@@ -1638,7 +1638,7 @@ COMMAND_CALLBACK(command)
{
snprintf (command, length, "/%s", argv_eol[index_args + 1]);
(void) input_exec_command (ptr_buffer, any_plugin, ptr_plugin,
- command);
+ command, NULL);
free (command);
}
}
@@ -1920,7 +1920,7 @@ COMMAND_CALLBACK(debug)
{
COMMAND_MIN_ARGS(3, "time");
gettimeofday (&time_start, NULL);
- (void) input_data (buffer, argv_eol[2]);
+ (void) input_data (buffer, argv_eol[2], NULL);
gettimeofday (&time_end, NULL);
debug_display_time_elapsed (&time_start, &time_end, argv_eol[2], 1);
return WEECHAT_RC_OK;
@@ -2043,7 +2043,7 @@ COMMAND_CALLBACK(eval)
options);
if (result)
{
- (void) input_data (buffer, result);
+ (void) input_data (buffer, result, NULL);
free (result);
}
else
@@ -2059,7 +2059,7 @@ COMMAND_CALLBACK(eval)
result = eval_expression (ptr_args, pointers, NULL, options);
if (result)
{
- (void) input_data (buffer, result);
+ (void) input_data (buffer, result, NULL);
free (result);
}
else
@@ -3130,7 +3130,7 @@ COMMAND_CALLBACK(input)
gui_input_jump_smart (buffer);
/* not used any more in WeeChat >= 1.0 (replaced by "/buffer ++") */
else if (string_strcasecmp (argv[1], "jump_last_buffer") == 0)
- (void) input_data (buffer, "/buffer +");
+ (void) input_data (buffer, "/buffer +", NULL);
else if (string_strcasecmp (argv[1], "jump_last_buffer_displayed") == 0)
gui_input_jump_last_buffer_displayed (buffer);
else if (string_strcasecmp (argv[1], "jump_previously_visited_buffer") == 0)
@@ -3163,7 +3163,7 @@ COMMAND_CALLBACK(input)
gui_input_insert (buffer, argv_eol[2]);
}
else if (string_strcasecmp (argv[1], "send") == 0)
- (void) input_data (buffer, argv_eol[2]);
+ (void) input_data (buffer, argv_eol[2], NULL);
else if (string_strcasecmp (argv[1], "undo") == 0)
gui_input_undo (buffer);
else if (string_strcasecmp (argv[1], "redo") == 0)
@@ -4197,7 +4197,7 @@ COMMAND_CALLBACK(mute)
if (string_is_command_char (ptr_command))
{
- (void) input_exec_command (buffer, 1, NULL, ptr_command);
+ (void) input_exec_command (buffer, 1, NULL, ptr_command, NULL);
}
else
{
@@ -4206,7 +4206,7 @@ COMMAND_CALLBACK(mute)
if (command)
{
snprintf (command, length, "/%s", ptr_command);
- (void) input_exec_command (buffer, 1, NULL, command);
+ (void) input_exec_command (buffer, 1, NULL, command, NULL);
free (command);
}
}
@@ -5228,12 +5228,13 @@ command_repeat_timer_cb (const void *pointer, void *data, int remaining_calls)
/* execute command */
if (ptr_buffer)
- (void) input_exec_command (ptr_buffer, 1, NULL, repeat_args[1]);
+ (void) input_exec_command (ptr_buffer, 1, NULL, repeat_args[1],
+ repeat_args[2]);
}
if (remaining_calls == 0)
{
- for (i = 0; i < 2; i++)
+ for (i = 0; i < 3; i++)
{
if (repeat_args[i])
free (repeat_args[i]);
@@ -5294,20 +5295,20 @@ COMMAND_CALLBACK(repeat)
if (command)
{
- (void) input_exec_command (buffer, 1, NULL, command);
+ (void) input_exec_command (buffer, 1, NULL, command, NULL);
if (count > 1)
{
if (interval == 0)
{
for (i = 0; i < count - 1; i++)
{
- (void) input_exec_command (buffer, 1, NULL, command);
+ (void) input_exec_command (buffer, 1, NULL, command, NULL);
}
free (command);
}
else
{
- repeat_args = malloc (2 * sizeof (*repeat_args));
+ repeat_args = malloc (3 * sizeof (*repeat_args));
if (!repeat_args)
{
gui_chat_printf (NULL,
@@ -5318,6 +5319,9 @@ COMMAND_CALLBACK(repeat)
}
repeat_args[0] = strdup (buffer->full_name);
repeat_args[1] = command;
+ repeat_args[2] = (input_commands_allowed) ?
+ string_build_with_split_string (
+ (const char **)input_commands_allowed, ",") : NULL;
hook_timer (NULL, interval, 0, count - 1,
&command_repeat_timer_cb, repeat_args, NULL);
}
@@ -6366,7 +6370,7 @@ COMMAND_CALLBACK(uptime)
minutes,
seconds,
str_first_start);
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
}
else if ((argc >= 2) && (string_strcasecmp (argv[1], "-ol") == 0))
{
@@ -6379,7 +6383,7 @@ COMMAND_CALLBACK(uptime)
minutes,
seconds,
util_get_time_string (&weechat_first_start_time));
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
}
else
{
@@ -6458,7 +6462,7 @@ command_version_display (struct t_gui_buffer *buffer,
_("compiled on"),
version_get_compilation_date (),
version_get_compilation_time ());
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
if (weechat_upgrade_count > 0)
{
snprintf (string, sizeof (string),
@@ -6468,7 +6472,7 @@ command_version_display (struct t_gui_buffer *buffer,
NG_("time", "times", weechat_upgrade_count),
str_first_start,
str_last_start);
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
}
}
else
@@ -6479,7 +6483,7 @@ command_version_display (struct t_gui_buffer *buffer,
"compiled on",
version_get_compilation_date (),
version_get_compilation_time ());
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
if (weechat_upgrade_count > 0)
{
snprintf (string, sizeof (string),
@@ -6488,7 +6492,7 @@ command_version_display (struct t_gui_buffer *buffer,
(weechat_upgrade_count > 1) ? "times" : "time",
str_first_start,
str_last_start);
- (void) input_data (buffer, string);
+ (void) input_data (buffer, string, NULL);
}
}
}
@@ -6578,10 +6582,10 @@ command_wait_timer_cb (const void *pointer, void *data, int remaining_calls)
/* execute command */
if (ptr_buffer)
- (void) input_data (ptr_buffer, timer_args[1]);
+ (void) input_data (ptr_buffer, timer_args[1], timer_args[2]);
}
- for (i = 0; i < 2; i++)
+ for (i = 0; i < 3; i++)
{
if (timer_args[i])
free (timer_args[i]);
@@ -6648,7 +6652,7 @@ COMMAND_CALLBACK(wait)
delay = number * factor;
/* build arguments for timer callback */
- timer_args = malloc (2 * sizeof (*timer_args));
+ timer_args = malloc (3 * sizeof (*timer_args));
if (!timer_args)
{
gui_chat_printf (NULL,
@@ -6659,6 +6663,9 @@ COMMAND_CALLBACK(wait)
}
timer_args[0] = strdup (buffer->full_name);
timer_args[1] = strdup (argv_eol[2]);
+ timer_args[2] = (input_commands_allowed) ?
+ string_build_with_split_string (
+ (const char **)input_commands_allowed, ",") : NULL;
/* schedule command, execute it after "delay" milliseconds */
hook_timer (NULL, delay, 0, 1,
@@ -8385,7 +8392,7 @@ command_exec_list (const char *command_list)
weechat_buffer = gui_buffer_search_main ();
for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++)
{
- (void) input_data (weechat_buffer, *ptr_cmd);
+ (void) input_data (weechat_buffer, *ptr_cmd, NULL);
}
string_free_split_command (commands);
}
diff --git a/src/core/wee-input.c b/src/core/wee-input.c
index 0ab2357ee..5ba90d005 100644
--- a/src/core/wee-input.c
+++ b/src/core/wee-input.c
@@ -75,17 +75,43 @@ int
input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
- const char *string)
+ const char *string,
+ const char *commands_allowed)
{
char *command, *command_name, *pos;
+ char **old_commands_allowed, **new_commands_allowed;
int rc;
if ((!string) || (!string[0]))
return WEECHAT_RC_ERROR;
+ rc = WEECHAT_RC_OK;
+
+ command = NULL;
+ command_name = NULL;
+
+ old_commands_allowed = input_commands_allowed;
+ new_commands_allowed = NULL;
+
command = strdup (string);
if (!command)
- return WEECHAT_RC_ERROR;
+ {
+ rc = WEECHAT_RC_ERROR;
+ goto end;
+ }
+
+ if (commands_allowed)
+ {
+ new_commands_allowed = string_split (
+ commands_allowed,
+ ",",
+ WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
+ 0,
+ NULL);
+ input_commands_allowed = new_commands_allowed;
+ }
/* ignore spaces at the end of command */
pos = &command[strlen (command) - 1];
@@ -102,12 +128,10 @@ input_exec_command (struct t_gui_buffer *buffer,
string_strndup (command, pos - command) : strdup (command);
if (!command_name)
{
- free (command);
- return WEECHAT_RC_ERROR;
+ rc = WEECHAT_RC_ERROR;
+ goto end;
}
- rc = WEECHAT_RC_OK;
-
/* check if command is allowed */
if (input_commands_allowed
&& !string_match_list (command_name + 1,
@@ -195,8 +219,14 @@ input_exec_command (struct t_gui_buffer *buffer,
}
end:
- free (command);
- free (command_name);
+ if (command)
+ free (command);
+ if (command_name)
+ free (command_name);
+
+ if (new_commands_allowed)
+ string_free_split (new_commands_allowed);
+ input_commands_allowed = old_commands_allowed;
return rc;
}
@@ -210,22 +240,27 @@ end:
*/
int
-input_data (struct t_gui_buffer *buffer, const char *data)
+input_data (struct t_gui_buffer *buffer, const char *data,
+ const char *commands_allowed)
{
char *pos, *buf, str_buffer[128], *new_data, *buffer_full_name;
const char *ptr_data, *ptr_data_for_buffer;
int length, char_size, first_command, rc;
- rc = WEECHAT_RC_OK;
-
if (!buffer || !gui_buffer_valid (buffer) || !data)
- {
return WEECHAT_RC_ERROR;
- }
+
+ rc = WEECHAT_RC_OK;
+
+ buffer_full_name = NULL;
+ new_data = NULL;
buffer_full_name = strdup (buffer->full_name);
if (!buffer_full_name)
- return WEECHAT_RC_ERROR;
+ {
+ rc = WEECHAT_RC_ERROR;
+ goto end;
+ }
/* execute modifier "input_text_for_buffer" */
snprintf (str_buffer, sizeof (str_buffer),
@@ -291,7 +326,8 @@ input_data (struct t_gui_buffer *buffer, const char *data)
else
{
/* input string is a command */
- rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data);
+ rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data,
+ commands_allowed);
}
if (pos)
@@ -306,10 +342,10 @@ input_data (struct t_gui_buffer *buffer, const char *data)
}
end:
- if (new_data)
- free (new_data);
if (buffer_full_name)
free (buffer_full_name);
+ if (new_data)
+ free (new_data);
return rc;
}
diff --git a/src/core/wee-input.h b/src/core/wee-input.h
index d6c6b3dac..faaf1b490 100644
--- a/src/core/wee-input.h
+++ b/src/core/wee-input.h
@@ -28,7 +28,9 @@ extern char **input_commands_allowed;
extern int input_exec_command (struct t_gui_buffer *buffer,
int any_plugin,
struct t_weechat_plugin *plugin,
- const char *string);
-extern int input_data (struct t_gui_buffer *buffer, const char *data);
+ const char *string,
+ const char *commands_allowed);
+extern int input_data (struct t_gui_buffer *buffer, const char *data,
+ const char *commands_allowed);
#endif /* WEECHAT_INPUT_H */
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index fdbd11e97..4cac88339 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -432,7 +432,7 @@ gui_input_return (struct t_gui_buffer *buffer)
gui_input_text_changed_modifier_and_signal (buffer,
0, /* save undo */
1); /* stop completion */
- (void) input_data (buffer, command);
+ (void) input_data (buffer, command, NULL);
free (command);
}
}
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index 2d53554c1..7127a5269 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -1159,7 +1159,7 @@ gui_key_focus_command (const char *key, int context,
command,
ptr_buffer->full_name);
}
- (void) input_data (ptr_buffer, command);
+ (void) input_data (ptr_buffer, command, NULL);
free (command);
}
}
@@ -1388,7 +1388,7 @@ gui_key_pressed (const char *key_str)
for (i = 0; commands[i]; i++)
{
(void) input_data (gui_current_window->buffer,
- commands[i]);
+ commands[i], NULL);
}
string_free_split (commands);
}
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 16b232dd7..cd5c736ef 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -303,44 +303,25 @@ plugin_api_command_options (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer, const char *command,
struct t_hashtable *options)
{
- char *command2, **old_commands_allowed, **new_commands_allowed;
- const char *ptr_commands;
+ char *command2;
+ const char *ptr_commands_allowed;
int rc;
if (!plugin || !command)
return WEECHAT_RC_ERROR;
- old_commands_allowed = input_commands_allowed;
- new_commands_allowed = NULL;
-
- if (options)
- {
- ptr_commands = hashtable_get (options, "commands");
- if (ptr_commands)
- {
- new_commands_allowed = string_split (
- ptr_commands,
- ",",
- WEECHAT_STRING_SPLIT_STRIP_LEFT
- | WEECHAT_STRING_SPLIT_STRIP_RIGHT
- | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
- 0,
- NULL);
- input_commands_allowed = new_commands_allowed;
- }
- }
+ ptr_commands_allowed = (options) ?
+ hashtable_get (options, "commands") : NULL;
command2 = string_iconv_to_internal (plugin->charset, command);
if (!buffer)
buffer = gui_current_window->buffer;
- rc = input_data (buffer, (command2) ? command2 : command);
+ rc = input_data (buffer,
+ (command2) ? command2 : command,
+ ptr_commands_allowed);
if (command2)
free (command2);
- if (new_commands_allowed)
- string_free_split (new_commands_allowed);
- input_commands_allowed = old_commands_allowed;
-
return rc;
}