diff --git a/docs/signals.txt b/docs/signals.txt index 6128084b..da72ef57 100644 --- a/docs/signals.txt +++ b/docs/signals.txt @@ -151,7 +151,7 @@ irc.c: "whois default event", SERVER_REC, char *args, char *sender_nick, char *sender_address "server incoming", SERVER_REC, char *data - "server outgoing modify", SERVER_REC, GString *data + "server outgoing modify", SERVER_REC, GString *data, int crlf (for perl parser..) "redir ", SERVER_REC, char *args, char *sender_nick, char *sender_address diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 664ca9a4..82989534 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -718,6 +718,7 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now) GString *str; long usecs; char *cmd; + int crlf; if (!IS_IRC_SERVER(server)) return 0; @@ -741,15 +742,29 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now) /* send command */ str = g_string_new(cmd); - signal_emit("server outgoing modify", 2, server, str); + + if (str->len > 2 && str->str[str->len - 2] == '\r') + crlf = 2; + else if (str->len > 1 && str->str[str->len - 1] == '\n') + crlf = 1; + else + crlf = 0; + + if (crlf) + g_string_truncate(str, str->len - crlf); + + signal_emit("server outgoing modify", 3, server, str, crlf); if (str->len) { + if (crlf == 2) + g_string_append(str, "\r\n"); + else if (crlf == 1) + g_string_append(str, "\n"); + irc_server_send_data(server, str->str, str->len); /* add to rawlog without [CR+]LF */ - if (str->len > 2 && str->str[str->len - 2] == '\r') - str->str[str->len - 2] = '\0'; - else if (str->str[str->len - 1] == '\n') - str->str[str->len - 1] = '\0'; + if (crlf) + g_string_truncate(str, str->len - crlf); rawlog_output(server->rawlog, str->str); server_redirect_command(server, str->str, redirect); } diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index c17e2470..62bc0bc8 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -115,20 +115,34 @@ void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd, int irc_send_whe if (!raw) { /* Add CR+LF to command */ - g_string_append_c(str, 13); - g_string_append_c(str, 10); + g_string_append(str, "\r\n"); } if (irc_send_when == IRC_SEND_NOW) { - signal_emit("server outgoing modify", 2, server, str); + int crlf; + + if (str->len > 2 && str->str[str->len - 2] == '\r') + crlf = 2; + else if (str->len > 1 && str->str[str->len - 1] == '\n') + crlf = 1; + else + crlf = 0; + + if (crlf) + g_string_truncate(str, str->len - crlf); + + signal_emit("server outgoing modify", 3, server, str, crlf); if (str->len) { + if (crlf == 2) + g_string_append(str, "\r\n"); + else if (crlf == 1) + g_string_append(str, "\n"); + irc_server_send_data(server, str->str, str->len); /* add to rawlog without [CR+]LF */ - if (str->len > 2 && str->str[str->len - 2] == '\r') - str->str[str->len - 2] = '\0'; - else if (str->str[str->len - 1] == '\n') - str->str[str->len - 1] = '\0'; + if (crlf) + g_string_truncate(str, str->len - crlf); rawlog_output(server->rawlog, str->str); server_redirect_command(server, str->str, server->redirect_next); }