summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-10-10 21:53:33 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-10-17 21:28:31 +0200
commita2a733fc36de9403080fa265027cae92e87a068a (patch)
treef51ac3fdb1fd62fa0fd16611ec5ff293013e5466 /src
parent56edeba7fc8a9e7725bf8cfa904f6116ea3f1e71 (diff)
downloadweechat-a2a733fc36de9403080fa265027cae92e87a068a.zip
irc: use parsed command parameters in "chghost" command callback
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-protocol.c21
-rw-r--r--src/plugins/irc/irc-protocol.h22
2 files changed, 32 insertions, 11 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index b3cdd7aae..6fbf415de 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -1138,28 +1138,27 @@ IRC_PROTOCOL_CALLBACK(cap)
* https://ircv3.net/specs/extensions/chghost-3.2.html
*
* Command looks like:
- * :nick!user@host CHGHOST user new.host.goes.here
- * :nick!user@host CHGHOST newuser host
- * :nick!user@host CHGHOST newuser new.host.goes.here
- * :nick!user@host CHGHOST newuser :new.host.goes.here
+ * CHGHOST user new.host.goes.here
+ * CHGHOST newuser host
+ * CHGHOST newuser new.host.goes.here
+ * CHGHOST newuser :new.host.goes.here
*/
IRC_PROTOCOL_CALLBACK(chghost)
{
int length, local_chghost, smart_filter;
- char *str_host, *pos_new_host;
+ char *str_host;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
struct t_irc_channel_speaking *ptr_nick_speaking;
- IRC_PROTOCOL_MIN_ARGS(4);
- IRC_PROTOCOL_CHECK_HOST;
+ IRC_PROTOCOL_MIN_PARAMS(2);
+ IRC_PROTOCOL_CHECK_NICK;
+ IRC_PROTOCOL_CHECK_ADDRESS;
local_chghost = (irc_server_strcasecmp (server, nick, server->nick) == 0);
- pos_new_host = (argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3];
-
- length = strlen (argv[2]) + 1 + strlen (pos_new_host) + 1;
+ length = strlen (params[0]) + 1 + strlen (params[1]) + 1;
str_host = malloc (length);
if (!str_host)
{
@@ -1169,7 +1168,7 @@ IRC_PROTOCOL_CALLBACK(chghost)
weechat_prefix ("error"), IRC_PLUGIN_NAME, "chghost");
return WEECHAT_RC_OK;
}
- snprintf (str_host, length, "%s@%s", argv[2], pos_new_host);
+ snprintf (str_host, length, "%s@%s", params[0], params[1]);
if (local_chghost)
irc_server_set_host (server, str_host);
diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h
index e239d3c3a..b7327dfa1 100644
--- a/src/plugins/irc/irc-protocol.h
+++ b/src/plugins/irc/irc-protocol.h
@@ -103,6 +103,28 @@
return WEECHAT_RC_ERROR; \
}
+#define IRC_PROTOCOL_CHECK_NICK \
+ if (!nick) \
+ { \
+ weechat_printf (server->buffer, \
+ _("%s%s: \"%s\" command received without " \
+ "nick"), \
+ weechat_prefix ("error"), IRC_PLUGIN_NAME, \
+ command); \
+ return WEECHAT_RC_ERROR; \
+ }
+
+#define IRC_PROTOCOL_CHECK_ADDRESS \
+ if (!address) \
+ { \
+ weechat_printf (server->buffer, \
+ _("%s%s: \"%s\" command received without " \
+ "address"), \
+ weechat_prefix ("error"), IRC_PLUGIN_NAME, \
+ command); \
+ return WEECHAT_RC_ERROR; \
+ }
+
struct t_irc_server;
typedef int (t_irc_recv_func)(struct t_irc_server *server,