diff options
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/irc-commands.c | 12 | ||||
-rw-r--r-- | src/irc/core/irc.c | 37 | ||||
-rw-r--r-- | src/irc/core/irc.h | 5 |
3 files changed, 38 insertions, 16 deletions
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index e8afab93..c2e7e47c 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -571,6 +571,16 @@ static void cmd_quote(const char *data, IRC_SERVER_REC *server) irc_send_cmd(server, data); } +/* SYNTAX: RAWQUOTE <data> */ +static void cmd_rawquote(const char *data, IRC_SERVER_REC *server) +{ + g_return_if_fail(data != NULL); + if (server == NULL || !IS_IRC_SERVER(server)) + cmd_return_error(CMDERR_NOT_CONNECTED); + + irc_send_cmd_full(server, data, FALSE, FALSE, TRUE); +} + static void cmd_wall_hash(gpointer key, NICK_REC *nick, GSList **nicks) { if (nick->op) *nicks = g_slist_append(*nicks, nick); @@ -1045,6 +1055,7 @@ void irc_commands_init(void) /* SYNTAX: USERHOST <nicks> */ command_bind("userhost", NULL, (SIGNAL_FUNC) command_self); command_bind("quote", NULL, (SIGNAL_FUNC) cmd_quote); + command_bind("rawquote", NULL, (SIGNAL_FUNC) cmd_rawquote); command_bind("wall", NULL, (SIGNAL_FUNC) cmd_wall); command_bind("wait", NULL, (SIGNAL_FUNC) cmd_wait); /* SYNTAX: WALLOPS <message> */ @@ -1118,6 +1129,7 @@ void irc_commands_deinit(void) command_unbind("uping", (SIGNAL_FUNC) command_self); command_unbind("userhost", (SIGNAL_FUNC) command_self); command_unbind("quote", (SIGNAL_FUNC) cmd_quote); + command_unbind("rawquote", (SIGNAL_FUNC) cmd_rawquote); command_unbind("wall", (SIGNAL_FUNC) cmd_wall); command_unbind("wait", (SIGNAL_FUNC) cmd_wait); command_unbind("wallops", (SIGNAL_FUNC) command_1self); diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index c894adc5..7af48fe2 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -42,25 +42,32 @@ static int signal_server_incoming; # define MAX_SOCKET_READS 5 #endif -static void cmd_send(IRC_SERVER_REC *server, const char *cmd, int send_now, int immediate) +/* The core of the irc_send_cmd* functions. If `raw' is TRUE, the `cmd' + won't be checked at all if it's 512 bytes or not, or if it contains + line feeds or not. Use with extreme caution! */ +void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd, + int send_now, int immediate, int raw) { - char str[513], *ptr; + char str[513]; int len; + len = strlen(cmd); server->cmdcount++; if (send_now) rawlog_output(server->rawlog, cmd); - /* just check that we don't send any longer commands than 512 bytes.. */ - strncpy(str, cmd, 510); - len = strlen(cmd); - if (len > 510) len = 510; - str[len++] = 13; str[len++] = 10; str[len] = '\0'; + if (!raw) { + /* check that we don't send any longer commands + than 512 bytes. also add the line feed. */ + strncpy(str, cmd, 510); + if (len > 510) len = 510; + str[len++] = 13; str[len++] = 10; str[len] = '\0'; + cmd = str; + } - ptr = str; if (send_now) { - if (net_sendbuffer_send(server->handle, str, len) == -1) { + if (net_sendbuffer_send(server->handle, cmd, len) == -1) { /* something bad happened */ server->connection_lost = TRUE; server_disconnect(SERVER(server)); @@ -72,11 +79,9 @@ static void cmd_send(IRC_SERVER_REC *server, const char *cmd, int send_now, int } /* add to queue */ - ptr = g_strdup(ptr); - if (!immediate) - server->cmdqueue = g_slist_append(server->cmdqueue, ptr); - else - server->cmdqueue = g_slist_prepend(server->cmdqueue, ptr); + server->cmdqueue = immediate ? + g_slist_prepend(server->cmdqueue, g_strdup(cmd)) : + g_slist_append(server->cmdqueue, g_strdup(cmd)); } /* Send command to IRC server */ @@ -93,7 +98,7 @@ void irc_send_cmd(IRC_SERVER_REC *server, const char *cmd) (server->cmdcount < server->max_cmds_at_once || server->cmd_queue_speed <= 0); - cmd_send(server, cmd, send_now, FALSE); + irc_send_cmd_full(server, cmd, send_now, FALSE, FALSE); } /* Send command to IRC server */ @@ -118,7 +123,7 @@ void irc_send_cmd_now(IRC_SERVER_REC *server, const char *cmd) g_return_if_fail(cmd != NULL); if (server == NULL) return; - cmd_send(server, cmd, TRUE, TRUE); + irc_send_cmd_full(server, cmd, TRUE, TRUE, FALSE); } static char *split_nicks(const char *cmd, char **pre, char **nicks, char **post, int arg) diff --git a/src/irc/core/irc.h b/src/irc/core/irc.h index 7eacca7a..c4e4ed10 100644 --- a/src/irc/core/irc.h +++ b/src/irc/core/irc.h @@ -44,6 +44,11 @@ void irc_send_cmd_split(IRC_SERVER_REC *server, const char *cmd, /* Send command to server immediately bypassing all flood protections and queues. */ void irc_send_cmd_now(IRC_SERVER_REC *server, const char *cmd); +/* The core of the irc_send_cmd* functions. If `raw' is TRUE, the `cmd' + won't be checked at all if it's 512 bytes or not, or if it contains + line feeds or not. Use with extreme caution! */ +void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd, + int send_now, int immediate, int raw); #include "commands.h" /* contains the generic PARAM_FLAG_xxx defines */ |