mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #45 from ailin-nemui/server-outgoing
simplify duplicate code in outgoing modify
This commit is contained in:
commit
f5d74bd81b
@ -6,7 +6,7 @@
|
||||
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
||||
|
||||
#define IRSSI_ABI_VERSION 41
|
||||
#define IRSSI_ABI_VERSION 42
|
||||
|
||||
#define DEFAULT_SERVER_ADD_PORT 6667
|
||||
#define DEFAULT_SERVER_ADD_TLS_PORT 6697
|
||||
|
@ -711,37 +711,12 @@ void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len)
|
||||
}
|
||||
}
|
||||
|
||||
static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now)
|
||||
void irc_server_send_and_redirect(IRC_SERVER_REC *server, GString *str, REDIRECT_REC *redirect)
|
||||
{
|
||||
REDIRECT_REC *redirect;
|
||||
GSList *link;
|
||||
GString *str;
|
||||
long usecs;
|
||||
char *cmd;
|
||||
int crlf;
|
||||
|
||||
if (!IS_IRC_SERVER(server))
|
||||
return 0;
|
||||
|
||||
if (server->cmdcount == 0 && server->cmdqueue == NULL)
|
||||
return 0;
|
||||
|
||||
if (now < server->wait_cmd)
|
||||
return 1;
|
||||
|
||||
usecs = (now - server->last_cmd) / G_TIME_SPAN_MILLISECOND;
|
||||
if (usecs < server->cmd_queue_speed)
|
||||
return 1;
|
||||
|
||||
server->cmdcount--;
|
||||
if (server->cmdqueue == NULL) return 1;
|
||||
|
||||
/* get command */
|
||||
cmd = server->cmdqueue->data;
|
||||
redirect = server->cmdqueue->next->data;
|
||||
|
||||
/* send command */
|
||||
str = g_string_new(cmd);
|
||||
g_return_if_fail(server != NULL);
|
||||
g_return_if_fail(str != NULL);
|
||||
|
||||
if (str->len > 2 && str->str[str->len - 2] == '\r')
|
||||
crlf = 2;
|
||||
@ -768,6 +743,40 @@ static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now)
|
||||
rawlog_output(server->rawlog, str->str);
|
||||
server_redirect_command(server, str->str, redirect);
|
||||
}
|
||||
}
|
||||
|
||||
static int server_cmd_timeout(IRC_SERVER_REC *server, gint64 now)
|
||||
{
|
||||
REDIRECT_REC *redirect;
|
||||
GSList *link;
|
||||
GString *str;
|
||||
long usecs;
|
||||
char *cmd;
|
||||
|
||||
if (!IS_IRC_SERVER(server))
|
||||
return 0;
|
||||
|
||||
if (server->cmdcount == 0 && server->cmdqueue == NULL)
|
||||
return 0;
|
||||
|
||||
if (now < server->wait_cmd)
|
||||
return 1;
|
||||
|
||||
usecs = (now - server->last_cmd) / G_TIME_SPAN_MILLISECOND;
|
||||
if (usecs < server->cmd_queue_speed)
|
||||
return 1;
|
||||
|
||||
server->cmdcount--;
|
||||
if (server->cmdqueue == NULL)
|
||||
return 1;
|
||||
|
||||
/* get command */
|
||||
cmd = server->cmdqueue->data;
|
||||
redirect = server->cmdqueue->next->data;
|
||||
|
||||
/* send command */
|
||||
str = g_string_new(cmd);
|
||||
irc_server_send_and_redirect(server, str, redirect);
|
||||
g_string_free(str, TRUE);
|
||||
|
||||
/* remove from queue */
|
||||
|
@ -176,6 +176,7 @@ char **irc_server_split_action(IRC_SERVER_REC *server, const char *target,
|
||||
const char *data);
|
||||
void irc_server_send_away(IRC_SERVER_REC *server, const char *reason);
|
||||
void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len);
|
||||
void irc_server_send_and_redirect(IRC_SERVER_REC *server, GString *str, REDIRECT_REC *redirect);
|
||||
void irc_server_init_isupport(IRC_SERVER_REC *server);
|
||||
|
||||
void irc_servers_start_cmd_timeout(void);
|
||||
|
@ -119,33 +119,7 @@ void irc_send_cmd_full(IRC_SERVER_REC *server, const char *cmd, int irc_send_whe
|
||||
}
|
||||
|
||||
if (irc_send_when == IRC_SEND_NOW) {
|
||||
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 (crlf)
|
||||
g_string_truncate(str, str->len - crlf);
|
||||
rawlog_output(server->rawlog, str->str);
|
||||
server_redirect_command(server, str->str, server->redirect_next);
|
||||
}
|
||||
irc_server_send_and_redirect(server, str, server->redirect_next);
|
||||
g_string_free(str, TRUE);
|
||||
} else if (irc_send_when == IRC_SEND_NEXT) {
|
||||
/* add to queue */
|
||||
|
Loading…
Reference in New Issue
Block a user