diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-03-28 22:07:25 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-03-28 22:07:25 +0100 |
commit | da43e95c758d8b5a51ac41f6ea503beebda48796 (patch) | |
tree | ad82953a4001e1844907ba60ea1888567d779d7a /src/plugins | |
parent | 4e9e5f265235b405bb7787eb4460364e7c930d38 (diff) | |
download | weechat-da43e95c758d8b5a51ac41f6ea503beebda48796.zip |
relay: use option "delay" in call to command_options (closes #1327)
This fixes a crash when sending "/plugin reload relay" from a relay client.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-protocol.c | 120 |
1 files changed, 37 insertions, 83 deletions
diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c index 184024927..26509bc38 100644 --- a/src/plugins/relay/weechat/relay-weechat-protocol.c +++ b/src/plugins/relay/weechat/relay-weechat-protocol.c @@ -393,71 +393,6 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(nicklist) } /* - * Timer callback for input command. - */ - -int -relay_weechat_protocol_input_timer_cb (const void *pointer, - void *data, - int remaining_calls) -{ - char **timer_args; - const char *ptr_weechat_commands; - int i; - struct t_gui_buffer *ptr_buffer; - struct t_hashtable *options; - - /* make C compiler happy */ - (void) data; - (void) remaining_calls; - - timer_args = (char **)pointer; - - if (!timer_args) - return WEECHAT_RC_ERROR; - - if (timer_args[0] && timer_args[1]) - { - ptr_buffer = weechat_buffer_search ("==", timer_args[0]); - if (ptr_buffer) - { - ptr_weechat_commands = weechat_config_string ( - relay_config_weechat_commands); - if (ptr_weechat_commands && ptr_weechat_commands[0]) - { - options = weechat_hashtable_new (8, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, NULL); - if (options) - { - weechat_hashtable_set ( - options, - "commands", - weechat_config_string (relay_config_weechat_commands)); - weechat_command_options (ptr_buffer, timer_args[1], - options); - weechat_hashtable_free (options); - } - } - else - { - weechat_command (ptr_buffer, timer_args[1]); - } - } - } - - for (i = 0; i < 2; i++) - { - if (timer_args[i]) - free (timer_args[i]); - } - free (timer_args); - - return WEECHAT_RC_OK; -} - -/* * Callback for command "input" (from client). * * Message looks like: @@ -469,7 +404,9 @@ relay_weechat_protocol_input_timer_cb (const void *pointer, RELAY_WEECHAT_PROTOCOL_CALLBACK(input) { struct t_gui_buffer *ptr_buffer; - char *pos, **timer_args; + struct t_hashtable *options; + const char *ptr_weechat_commands; + char *pos; RELAY_WEECHAT_PROTOCOL_MIN_ARGS(1); @@ -489,25 +426,42 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(input) } pos = strchr (argv_eol[0], ' '); - if (pos) + if (!pos) + return WEECHAT_RC_OK; + + pos++; + options = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + if (!options) { - /* - * use a timer to execute the command after we go back in the - * WeeChat main loop (some commands like /upgrade executed now can - * cause a crash) - */ - timer_args = malloc (2 * sizeof (*timer_args)); - if (timer_args) - { - timer_args[0] = strdup (weechat_buffer_get_string (ptr_buffer, - "full_name")); - timer_args[1] = strdup (pos + 1); - weechat_hook_timer (1, 0, 1, - &relay_weechat_protocol_input_timer_cb, - timer_args, - NULL); - } + weechat_printf (NULL, + _("%s%s: not enough memory"), + weechat_prefix ("error"), RELAY_PLUGIN_NAME); + return WEECHAT_RC_OK; + } + + ptr_weechat_commands = weechat_config_string ( + relay_config_weechat_commands); + if (ptr_weechat_commands && ptr_weechat_commands[0]) + { + weechat_hashtable_set ( + options, + "commands", + weechat_config_string (relay_config_weechat_commands)); } + /* + * delay the execution of command after we go back in the WeeChat + * main loop (some commands like /upgrade executed now can cause + * a crash) + */ + weechat_hashtable_set (options, "delay", "1"); + + /* execute the command, with the delay */ + weechat_command_options (ptr_buffer, pos, options); + + weechat_hashtable_free (options); return WEECHAT_RC_OK; } |