int xfer_command_me (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_xfer *ptr_xfer; /* make C compiler happy */ (void) data; (void) argc; (void) argv; ptr_xfer = xfer_search_by_buffer (buffer); if (!ptr_xfer) { dogechat_printf (NULL, _("%s%s: can't find xfer for buffer \"%s\""), dogechat_prefix ("error"), XFER_PLUGIN_NAME, dogechat_buffer_get_string (buffer, "name")); return DOGECHAT_RC_OK; } if (!XFER_HAS_ENDED(ptr_xfer->status)) { xfer_chat_sendf (ptr_xfer, "\01ACTION %s\01\r\n", (argv_eol[1]) ? argv_eol[1] : ""); dogechat_printf_tags (buffer, "no_highlight", "%s%s%s %s%s", dogechat_prefix ("action"), dogechat_color ("chat_nick_self"), ptr_xfer->local_nick, dogechat_color ("chat"), (argv_eol[1]) ? argv_eol[1] : ""); } return DOGECHAT_RC_OK; }
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 = dogechat_hashtable_new (32, DOGECHAT_HASHTABLE_STRING, DOGECHAT_HASHTABLE_STRING, NULL, NULL); if (hashtable) { dogechat_hashtable_set (hashtable, "command", exec_cmd->command); snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); dogechat_hashtable_set (hashtable, "number", str_number); dogechat_hashtable_set (hashtable, "name", exec_cmd->name); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDOUT]); dogechat_hashtable_set (hashtable, "out", output); if (output) free (output); output = exec_decode_color (exec_cmd, exec_cmd->output[EXEC_STDERR]); dogechat_hashtable_set (hashtable, "err", output); if (output) free (output); snprintf (str_number, sizeof (str_number), "%d", return_code); dogechat_hashtable_set (hashtable, "rc", str_number); dogechat_hook_hsignal_send (exec_cmd->hsignal, hashtable); dogechat_hashtable_free (hashtable); } } else { ptr_buffer = dogechat_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 = dogechat_buffer_get_integer (ptr_buffer, "type"); if (return_code >= 0) { if (buffer_type == 1) { dogechat_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 { dogechat_printf_tags (ptr_buffer, "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) { dogechat_printf_y (ptr_buffer, -1, _("%s: unexpected end of command %d " "(\"%s\")"), EXEC_PLUGIN_NAME, exec_cmd->number, exec_cmd->command); } else { dogechat_printf_tags (ptr_buffer, "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 (dogechat_config_integer (exec_config_command_purge_delay) >= 0) { dogechat_hook_timer (1 + (1000 * dogechat_config_integer (exec_config_command_purge_delay)), 0, 1, &exec_timer_delete_cb, exec_cmd); } }
void irc_input_user_message_display (struct t_gui_buffer *buffer, int action, const char *text) { struct t_irc_nick *ptr_nick; char *pos, *text2, *text_decoded, str_tags[256], *str_color; const char *ptr_text; /* if message is an action, force "action" to 1 and extract message */ if (strncmp (text, "\01ACTION ", 8) == 0) { action = 1; pos = strrchr (text + 8, '\01'); if (pos) text2 = dogechat_strndup (text + 8, pos - text - 8); else text2 = strdup (text + 8); } else text2 = strdup (text); text_decoded = irc_color_decode ( (text2) ? text2 : text, dogechat_config_boolean (irc_config_network_colors_send)); IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (ptr_channel) { ptr_nick = NULL; if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) { ptr_nick = irc_nick_search (ptr_server, ptr_channel, ptr_server->nick); } if (action) { snprintf (str_tags, sizeof (str_tags), "irc_action,notify_none,no_highlight"); } else { str_color = irc_color_for_tags ( dogechat_config_color ( dogechat_config_get ("dogechat.color.chat_nick_self"))); snprintf (str_tags, sizeof (str_tags), "notify_none,no_highlight,prefix_nick_%s", (str_color) ? str_color : "default"); if (str_color) free (str_color); } ptr_text = (text_decoded) ? text_decoded : ((text2) ? text2 : text); if (action) { dogechat_printf_tags ( buffer, irc_protocol_tags ( "privmsg", str_tags, (ptr_nick) ? ptr_nick->name : ptr_server->nick, NULL), "%s%s%s%s%s %s", dogechat_prefix ("action"), irc_nick_mode_for_display (ptr_server, ptr_nick, 0), IRC_COLOR_CHAT_NICK_SELF, ptr_server->nick, IRC_COLOR_RESET, ptr_text); } else { dogechat_printf_tags ( buffer, irc_protocol_tags ( "privmsg", str_tags, (ptr_nick) ? ptr_nick->name : ptr_server->nick, NULL), "%s%s", irc_nick_as_prefix ( ptr_server, (ptr_nick) ? ptr_nick : NULL, (ptr_nick) ? NULL : ptr_server->nick, IRC_COLOR_CHAT_NICK_SELF), ptr_text); } } if (text2) free (text2); if (text_decoded) free (text_decoded); }
void exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *line) { char *line_color, *line2, str_number[32], str_tags[1024]; int length; if (!exec_cmd || !line) return; /* * if output is sent to the buffer, the buffer must exist * (we don't send output by default to core buffer) */ if (exec_cmd->output_to_buffer && !exec_cmd->pipe_command && !buffer) return; /* decode colors */ line_color = exec_decode_color (exec_cmd, line); if (!line_color) return; exec_cmd->output_line_nb++; if (exec_cmd->pipe_command) { if (strstr (exec_cmd->pipe_command, "$line")) { /* replace $line by line content */ line2 = dogechat_string_replace (exec_cmd->pipe_command, "$line", line_color); if (line2) { dogechat_command (buffer, line2); free (line2); } } else { /* add line at the end of command, after a space */ length = strlen (exec_cmd->pipe_command) + 1 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%s %s", exec_cmd->pipe_command, line_color); dogechat_command (buffer, line2); free (line2); } } } else if (exec_cmd->output_to_buffer) { if (exec_cmd->line_numbers) { length = 32 + strlen (line_color) + 1; line2 = malloc (length); if (line2) { snprintf (line2, length, "%d. %s", exec_cmd->output_line_nb, line_color); dogechat_command (buffer, line2); free (line2); } } else dogechat_command (buffer, (line_color[0]) ? line_color : " "); } else { snprintf (str_number, sizeof (str_number), "%d", exec_cmd->number); snprintf (str_tags, sizeof (str_tags), "exec_%s,exec_cmd_%s", (out == EXEC_STDOUT) ? "stdout" : "stderr", (exec_cmd->name) ? exec_cmd->name : str_number); if (dogechat_buffer_get_integer (buffer, "type") == 1) { snprintf (str_number, sizeof (str_number), "%d. ", exec_cmd->output_line_nb); dogechat_printf_y (buffer, -1, "%s%s", (exec_cmd->line_numbers) ? str_number : " ", line_color); } else { snprintf (str_number, sizeof (str_number), "%d\t", exec_cmd->output_line_nb); dogechat_printf_tags (buffer, str_tags, "%s%s", (exec_cmd->line_numbers) ? str_number : " \t", line_color); } } }