irc: case-insensitive comparison on incoming CTCP command, force upper case on CTCP replies (closes #1439)
parent
4f42f407c1
commit
4f9c4fecd3
|
@ -28,6 +28,7 @@ New features::
|
||||||
Bug fixes::
|
Bug fixes::
|
||||||
|
|
||||||
* core: fix evaluation of condition with nested "if" (issue #1434)
|
* core: fix evaluation of condition with nested "if" (issue #1434)
|
||||||
|
* irc: case-insensitive comparison on incoming CTCP command, force upper case on CTCP replies (issue #1439)
|
||||||
* irc: fix memory leak when the channel topic is changed
|
* irc: fix memory leak when the channel topic is changed
|
||||||
* xfer: send signal "xfer_ended" after the received file has been renamed (issue #1438)
|
* xfer: send signal "xfer_ended" after the received file has been renamed (issue #1438)
|
||||||
|
|
||||||
|
|
|
@ -150,19 +150,25 @@ irc_ctcp_display_request (struct t_irc_server *server,
|
||||||
void
|
void
|
||||||
irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||||
const char *command, const char *nick,
|
const char *command, const char *nick,
|
||||||
const char *address, char *arguments)
|
const char *address, const char *arguments)
|
||||||
{
|
{
|
||||||
char *pos_end, *pos_space, *pos_args, *pos_usec;
|
char *dup_arguments, *ptr_args, *pos_end, *pos_space, *pos_args, *pos_usec;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
long sec1, usec1, sec2, usec2, difftime;
|
long sec1, usec1, sec2, usec2, difftime;
|
||||||
|
|
||||||
while (arguments && arguments[0])
|
dup_arguments = strdup (arguments);
|
||||||
|
if (!dup_arguments)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ptr_args = dup_arguments;
|
||||||
|
|
||||||
|
while (ptr_args && ptr_args[0])
|
||||||
{
|
{
|
||||||
pos_end = strrchr (arguments + 1, '\01');
|
pos_end = strrchr (ptr_args + 1, '\01');
|
||||||
if (pos_end)
|
if (pos_end)
|
||||||
pos_end[0] = '\0';
|
pos_end[0] = '\0';
|
||||||
|
|
||||||
pos_space = strchr (arguments + 1, ' ');
|
pos_space = strchr (ptr_args + 1, ' ');
|
||||||
if (pos_space)
|
if (pos_space)
|
||||||
{
|
{
|
||||||
pos_space[0] = '\0';
|
pos_space[0] = '\0';
|
||||||
|
@ -171,7 +177,7 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||||
{
|
{
|
||||||
pos_args++;
|
pos_args++;
|
||||||
}
|
}
|
||||||
if (strcmp (arguments + 1, "PING") == 0)
|
if (weechat_strcasecmp (ptr_args + 1, "PING") == 0)
|
||||||
{
|
{
|
||||||
pos_usec = strchr (pos_args, ' ');
|
pos_usec = strchr (pos_args, ' ');
|
||||||
if (pos_usec)
|
if (pos_usec)
|
||||||
|
@ -198,11 +204,9 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||||
nick,
|
nick,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
IRC_COLOR_CHAT_CHANNEL,
|
IRC_COLOR_CHAT_CHANNEL,
|
||||||
arguments + 1,
|
ptr_args + 1,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
(float)difftime / 1000000.0);
|
(float)difftime / 1000000.0);
|
||||||
|
|
||||||
pos_usec[0] = ' ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -218,12 +222,11 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||||
nick,
|
nick,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
IRC_COLOR_CHAT_CHANNEL,
|
IRC_COLOR_CHAT_CHANNEL,
|
||||||
arguments + 1,
|
ptr_args + 1,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
" ",
|
" ",
|
||||||
pos_args);
|
pos_args);
|
||||||
}
|
}
|
||||||
pos_space[0] = ' ';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -238,17 +241,16 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
|
||||||
nick,
|
nick,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
IRC_COLOR_CHAT_CHANNEL,
|
IRC_COLOR_CHAT_CHANNEL,
|
||||||
arguments + 1,
|
ptr_args + 1,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos_end)
|
ptr_args = (pos_end) ? pos_end + 1 : NULL;
|
||||||
pos_end[0] = '\01';
|
|
||||||
|
|
||||||
arguments = (pos_end) ? pos_end + 1 : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free (dup_arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -266,14 +268,21 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
|
||||||
int number;
|
int number;
|
||||||
char hash_key[32];
|
char hash_key[32];
|
||||||
const char *str_args;
|
const char *str_args;
|
||||||
char *str_args_color;
|
char *str_args_color, *ctcp_upper;
|
||||||
|
|
||||||
|
ctcp_upper = strdup (ctcp);
|
||||||
|
if (!ctcp_upper)
|
||||||
|
return;
|
||||||
|
|
||||||
|
weechat_string_toupper (ctcp_upper);
|
||||||
|
|
||||||
hashtable = irc_server_sendf (
|
hashtable = irc_server_sendf (
|
||||||
server,
|
server,
|
||||||
IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE,
|
IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE,
|
||||||
NULL,
|
NULL,
|
||||||
"NOTICE %s :\01%s%s%s\01",
|
"NOTICE %s :\01%s%s%s\01",
|
||||||
nick, ctcp,
|
nick,
|
||||||
|
ctcp_upper,
|
||||||
(arguments) ? " " : "",
|
(arguments) ? " " : "",
|
||||||
(arguments) ? arguments : "");
|
(arguments) ? arguments : "");
|
||||||
|
|
||||||
|
@ -307,7 +316,7 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
|
||||||
nick,
|
nick,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
IRC_COLOR_CHAT_CHANNEL,
|
IRC_COLOR_CHAT_CHANNEL,
|
||||||
ctcp,
|
ctcp_upper,
|
||||||
(str_args_color[0]) ? IRC_COLOR_RESET : "",
|
(str_args_color[0]) ? IRC_COLOR_RESET : "",
|
||||||
(str_args_color[0]) ? " " : "",
|
(str_args_color[0]) ? " " : "",
|
||||||
str_args_color);
|
str_args_color);
|
||||||
|
@ -317,6 +326,8 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
|
||||||
}
|
}
|
||||||
weechat_hashtable_free (hashtable);
|
weechat_hashtable_free (hashtable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free (ctcp_upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -541,7 +552,7 @@ irc_ctcp_dcc_filename_without_quotes (const char *filename)
|
||||||
|
|
||||||
void
|
void
|
||||||
irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
const char *arguments, char *message)
|
const char *arguments, const char *message)
|
||||||
{
|
{
|
||||||
char *dcc_args, *pos, *pos_file, *pos_addr, *pos_port, *pos_size;
|
char *dcc_args, *pos, *pos_file, *pos_addr, *pos_port, *pos_size;
|
||||||
char *pos_start_resume, *filename;
|
char *pos_start_resume, *filename;
|
||||||
|
@ -669,7 +680,7 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
|
|
||||||
(void) weechat_hook_signal_send ("irc_dcc",
|
(void) weechat_hook_signal_send ("irc_dcc",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
free (filename);
|
free (filename);
|
||||||
|
@ -765,7 +776,7 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
|
|
||||||
(void) weechat_hook_signal_send ("irc_dcc",
|
(void) weechat_hook_signal_send ("irc_dcc",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
free (filename);
|
free (filename);
|
||||||
|
@ -861,7 +872,7 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
|
|
||||||
(void) weechat_hook_signal_send ("irc_dcc",
|
(void) weechat_hook_signal_send ("irc_dcc",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
free (filename);
|
free (filename);
|
||||||
|
@ -972,7 +983,7 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
|
|
||||||
(void) weechat_hook_signal_send ("irc_dcc",
|
(void) weechat_hook_signal_send ("irc_dcc",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
|
|
||||||
free (dcc_args);
|
free (dcc_args);
|
||||||
}
|
}
|
||||||
|
@ -985,24 +996,30 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
|
||||||
void
|
void
|
||||||
irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
struct t_irc_channel *channel, const char *address,
|
struct t_irc_channel *channel, const char *address,
|
||||||
const char *nick, const char *remote_nick, char *arguments,
|
const char *nick, const char *remote_nick,
|
||||||
char *message)
|
const char *arguments, const char *message)
|
||||||
{
|
{
|
||||||
char *pos_end, *pos_space, *pos_args, *nick_color;
|
char *dup_arguments, *ptr_args, *pos_end, *pos_space, *pos_args;
|
||||||
|
char *nick_color, *decoded_reply;
|
||||||
const char *reply;
|
const char *reply;
|
||||||
char *decoded_reply;
|
|
||||||
struct t_irc_channel *ptr_channel;
|
struct t_irc_channel *ptr_channel;
|
||||||
struct t_irc_nick *ptr_nick;
|
struct t_irc_nick *ptr_nick;
|
||||||
int nick_is_me;
|
int nick_is_me;
|
||||||
|
|
||||||
while (arguments && arguments[0])
|
dup_arguments = strdup (arguments);
|
||||||
|
if (!dup_arguments)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ptr_args = dup_arguments;
|
||||||
|
|
||||||
|
while (ptr_args && ptr_args[0])
|
||||||
{
|
{
|
||||||
pos_end = strrchr (arguments + 1, '\01');
|
pos_end = strrchr (ptr_args + 1, '\01');
|
||||||
if (pos_end)
|
if (pos_end)
|
||||||
pos_end[0] = '\0';
|
pos_end[0] = '\0';
|
||||||
|
|
||||||
pos_args = NULL;
|
pos_args = NULL;
|
||||||
pos_space = strchr (arguments + 1, ' ');
|
pos_space = strchr (ptr_args + 1, ' ');
|
||||||
if (pos_space)
|
if (pos_space)
|
||||||
{
|
{
|
||||||
pos_space[0] = '\0';
|
pos_space[0] = '\0';
|
||||||
|
@ -1014,7 +1031,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CTCP ACTION */
|
/* CTCP ACTION */
|
||||||
if (strcmp (arguments + 1, "ACTION") == 0)
|
if (weechat_strcasecmp (ptr_args + 1, "ACTION") == 0)
|
||||||
{
|
{
|
||||||
nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0);
|
nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0);
|
||||||
if (channel)
|
if (channel)
|
||||||
|
@ -1095,16 +1112,16 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
(pos_args) ? pos_args : "");
|
(pos_args) ? pos_args : "");
|
||||||
(void) weechat_hook_signal_send ("irc_pv",
|
(void) weechat_hook_signal_send ("irc_pv",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* CTCP PING */
|
/* CTCP PING */
|
||||||
else if (strcmp (arguments + 1, "PING") == 0)
|
else if (weechat_strcasecmp (ptr_args + 1, "PING") == 0)
|
||||||
{
|
{
|
||||||
reply = irc_ctcp_get_reply (server, arguments + 1);
|
reply = irc_ctcp_get_reply (server, ptr_args + 1);
|
||||||
irc_ctcp_display_request (server, date, command, channel, nick,
|
irc_ctcp_display_request (server, date, command, channel, nick,
|
||||||
address, arguments + 1, pos_args, reply);
|
address, ptr_args + 1, pos_args, reply);
|
||||||
if (!reply || reply[0])
|
if (!reply || reply[0])
|
||||||
{
|
{
|
||||||
if (reply)
|
if (reply)
|
||||||
|
@ -1113,30 +1130,30 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
if (decoded_reply)
|
if (decoded_reply)
|
||||||
{
|
{
|
||||||
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
||||||
arguments + 1, decoded_reply);
|
ptr_args + 1, decoded_reply);
|
||||||
free (decoded_reply);
|
free (decoded_reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
||||||
arguments + 1, pos_args);
|
ptr_args + 1, pos_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* CTCP DCC */
|
/* CTCP DCC */
|
||||||
else if (strcmp (arguments + 1, "DCC") == 0)
|
else if (weechat_strcasecmp (ptr_args + 1, "DCC") == 0)
|
||||||
{
|
{
|
||||||
irc_ctcp_recv_dcc (server, nick, pos_args, message);
|
irc_ctcp_recv_dcc (server, nick, pos_args, message);
|
||||||
}
|
}
|
||||||
/* other CTCP */
|
/* other CTCP */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reply = irc_ctcp_get_reply (server, arguments + 1);
|
reply = irc_ctcp_get_reply (server, ptr_args + 1);
|
||||||
if (reply)
|
if (reply)
|
||||||
{
|
{
|
||||||
irc_ctcp_display_request (server, date, command, channel, nick,
|
irc_ctcp_display_request (server, date, command, channel, nick,
|
||||||
address, arguments + 1, pos_args,
|
address, ptr_args + 1, pos_args,
|
||||||
reply);
|
reply);
|
||||||
|
|
||||||
if (reply[0])
|
if (reply[0])
|
||||||
|
@ -1145,7 +1162,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
if (decoded_reply)
|
if (decoded_reply)
|
||||||
{
|
{
|
||||||
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
irc_ctcp_reply_to_nick (server, command, channel, nick,
|
||||||
arguments + 1, decoded_reply);
|
ptr_args + 1, decoded_reply);
|
||||||
free (decoded_reply);
|
free (decoded_reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1166,7 +1183,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
nick,
|
nick,
|
||||||
IRC_COLOR_RESET,
|
IRC_COLOR_RESET,
|
||||||
IRC_COLOR_CHAT_CHANNEL,
|
IRC_COLOR_CHAT_CHANNEL,
|
||||||
arguments + 1,
|
ptr_args + 1,
|
||||||
(pos_args) ? IRC_COLOR_RESET : "",
|
(pos_args) ? IRC_COLOR_RESET : "",
|
||||||
(pos_args) ? " " : "",
|
(pos_args) ? " " : "",
|
||||||
(pos_args) ? pos_args : "");
|
(pos_args) ? pos_args : "");
|
||||||
|
@ -1176,14 +1193,10 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
|
||||||
|
|
||||||
(void) weechat_hook_signal_send ("irc_ctcp",
|
(void) weechat_hook_signal_send ("irc_ctcp",
|
||||||
WEECHAT_HOOK_SIGNAL_STRING,
|
WEECHAT_HOOK_SIGNAL_STRING,
|
||||||
message);
|
(void *)message);
|
||||||
|
|
||||||
if (pos_space)
|
ptr_args = (pos_end) ? pos_end + 1 : NULL;
|
||||||
pos_space[0] = ' ';
|
|
||||||
|
|
||||||
if (pos_end)
|
|
||||||
pos_end[0] = '\01';
|
|
||||||
|
|
||||||
arguments = (pos_end) ? pos_end + 1 : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free (dup_arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ extern void irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
|
||||||
const char *command,
|
const char *command,
|
||||||
const char *nick,
|
const char *nick,
|
||||||
const char *address,
|
const char *address,
|
||||||
char *arguments);
|
const char *arguments);
|
||||||
extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
||||||
const char *command, struct t_irc_channel *channel,
|
const char *command, struct t_irc_channel *channel,
|
||||||
const char *address, const char *nick,
|
const char *address, const char *nick,
|
||||||
const char *remote_nick, char *arguments,
|
const char *remote_nick, const char *arguments,
|
||||||
char *message);
|
const char *message);
|
||||||
|
|
||||||
#endif /* WEECHAT_PLUGIN_IRC_CTCP_H */
|
#endif /* WEECHAT_PLUGIN_IRC_CTCP_H */
|
||||||
|
|
Loading…
Reference in New Issue