void irc_redirect_stop (struct t_irc_redirect *redirect, const char *error) { struct t_hashtable *hashtable; char signal_name[1024], str_int[64]; redirect->current_count++; if (error || (redirect->current_count > redirect->count)) { /* * error or max count reached, then we run callback and remove * redirect */ hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (hashtable) { /* set error and output (main fields) */ weechat_hashtable_set (hashtable, "error", (error) ? (char *)error : ""); weechat_hashtable_set (hashtable, "output", (redirect->output) ? redirect->output : ""); snprintf (str_int, sizeof (str_int), "%d", redirect->output_size); weechat_hashtable_set (hashtable, "output_size", str_int); /* set some other fields with values from redirect */ weechat_hashtable_set (hashtable, "server", redirect->server->name); weechat_hashtable_set (hashtable, "pattern", redirect->pattern); weechat_hashtable_set (hashtable, "signal", redirect->signal); weechat_hashtable_set (hashtable, "command", redirect->command); } snprintf (signal_name, sizeof (signal_name), "irc_redirection_%s_%s", redirect->signal, redirect->pattern); (void) weechat_hook_hsignal_send (signal_name, hashtable); if (hashtable) weechat_hashtable_free (hashtable); irc_redirect_free (redirect); } else { /* * max count not yet reached, then we prepare redirect to continue * redirection */ redirect->cmd_start_received = 0; redirect->cmd_stop_received = 0; } }
void exec_end_command (struct t_exec_cmd *exec_cmd, int return_code) { struct t_gui_buffer *ptr_buffer; struct t_hashtable *hashtable; char str_number[32], *output; int i, buffer_type; if (exec_cmd->hsignal) { hashtable = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (hashtable) { weechat_hashtable_set (hashtable, "command", exec_cmd->command); snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); weechat_hashtable_set (hashtable, "number", str_number); weechat_hashtable_set (hashtable, "name", exec_cmd->name); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]); weechat_hashtable_set (hashtable, "out", output); if (output) free (output); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]); weechat_hashtable_set (hashtable, "err", output); if (output) free (output); snprintf (str_number, sizeof (str_number), "%d", return_code); weechat_hashtable_set (hashtable, "rc", str_number); weechat_hook_hsignal_send (exec_cmd->hsignal, hashtable); weechat_hashtable_free (hashtable); } } else { ptr_buffer = weechat_buffer_search ("==", exec_cmd->buffer_full_name); /* display the last line of output (if not ending with '\n') */ exec_display_line (exec_cmd, ptr_buffer, EXEC_STDOUT, exec_cmd->output[EXEC_STDOUT]); exec_display_line (exec_cmd, ptr_buffer, EXEC_STDERR, exec_cmd->output[EXEC_STDERR]); /* * display return code (only if command is not detached, if output is * NOT sent to buffer, and if command is not piped) */ if (exec_cmd->display_rc && !exec_cmd->detached && !exec_cmd->output_to_buffer && !exec_cmd->pipe_command) { buffer_type = weechat_buffer_get_integer (ptr_buffer, "type"); if (return_code >= 0) { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, ("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: end of command %d (\"%s\"), " "return code: %d"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command, return_code); } } else { if (buffer_type == 1) { weechat_printf_y (ptr_buffer, -1, _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } else { weechat_printf_date_tags ( ptr_buffer, 0, "exec_rc", _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } } } } /* (re)set some variables after the end of command */ exec_cmd->hook = NULL; exec_cmd->pid = 0; exec_cmd->end_time = time (NULL); exec_cmd->return_code = return_code; for (i = 0; i < 2; i++) { if (exec_cmd->output[i]) { free (exec_cmd->output[i]); exec_cmd->output[i] = NULL; } exec_cmd->output_size[i] = 0; } /* schedule a timer to remove the executed command */ if (weechat_config_integer (exec_config_command_purge_delay) >= 0) { weechat_hook_timer (1 + (1000 * weechat_config_integer (exec_config_command_purge_delay)), 0, 1, &exec_timer_delete_cb, exec_cmd, NULL); } }