/pidgin/main: 9f132a6855cd: IRC: fill required command parameter...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Tue Jan 28 10:38:12 EST 2014
Changeset: 9f132a6855cd6b1e702e64b96b4f209bd479bce9
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-01-16 11:28 +0100
Branch: release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/9f132a6855cd
Description:
IRC: fill required command parameter counts (part 1)
diffstat:
libpurple/protocols/irc/msgs.c | 51 ++++++++++++----------------------------
libpurple/protocols/irc/parse.c | 38 +++++++++++++++---------------
2 files changed, 34 insertions(+), 55 deletions(-)
diffs (203 lines):
diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c
--- a/libpurple/protocols/irc/msgs.c
+++ b/libpurple/protocols/irc/msgs.c
@@ -595,13 +595,13 @@ void irc_msg_topic(struct irc_conn *irc,
PurpleConversation *convo;
if (!strcmp(name, "topic")) {
- if (!args[0] || !args[1])
- return;
+ g_return_if_fail(args[0]);
+ g_return_if_fail(args[1]);
chan = args[0];
topic = irc_mirc2txt (args[1]);
} else {
- if (!args[0] || !args[1] || !args[2])
- return;
+ g_return_if_fail(args[1]);
+ g_return_if_fail(args[2]);
chan = args[1];
topic = irc_mirc2txt (args[2]);
}
@@ -908,8 +908,7 @@ void irc_msg_invite(struct irc_conn *irc
GHashTable *components;
gchar *nick;
- if (!args || !args[1] || !gc)
- return;
+ g_return_if_fail(gc);
components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
nick = irc_mask_nick(from);
@@ -982,14 +981,13 @@ void irc_msg_join(struct irc_conn *irc,
PurpleConvChat *chat;
PurpleConvChatBuddy *cb;
- char *nick = irc_mask_nick(from), *userhost, *buf;
+ char *nick, *userhost, *buf;
struct irc_buddy *ib;
static int id = 1;
- if (!gc) {
- g_free(nick);
- return;
- }
+ g_return_if_fail(gc);
+
+ nick = irc_mask_nick(from);
if (!purple_utf8_strcasecmp(nick, purple_connection_get_display_name(gc))) {
/* We are joining a channel for the first time */
@@ -1049,12 +1047,11 @@ void irc_msg_kick(struct irc_conn *irc,
{
PurpleConnection *gc = purple_account_get_connection(irc->account);
PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[0], irc->account);
- char *nick = irc_mask_nick(from), *buf;
+ char *nick, *buf;
- if (!gc) {
- g_free(nick);
- return;
- }
+ g_return_if_fail(gc);
+
+ nick = irc_mask_nick(from);
if (!convo) {
purple_debug(PURPLE_DEBUG_ERROR, "irc", "Received a KICK for unknown channel %s\n", args[0]);
@@ -1238,9 +1235,6 @@ void irc_msg_nickused(struct irc_conn *i
void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args)
{
- if (!args || !args[0] || !args[1])
- return;
-
irc_msg_handle_privmsg(irc, name, from, args[0], args[1], TRUE);
}
@@ -1260,8 +1254,7 @@ void irc_msg_part(struct irc_conn *irc,
PurpleConversation *convo;
char *nick, *msg, *channel;
- if (!args || !args[0] || !gc)
- return;
+ g_return_if_fail(gc);
/* Undernet likes to :-quote the channel name, for no good reason
* that I can see. This catches that. */
@@ -1294,8 +1287,6 @@ void irc_msg_part(struct irc_conn *irc,
void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args)
{
char *buf;
- if (!args || !args[0])
- return;
buf = irc_format(irc, "v:", "PONG", args[0]);
irc_send(irc, buf);
@@ -1309,9 +1300,6 @@ void irc_msg_pong(struct irc_conn *irc,
char **parts, *msg;
time_t oldstamp;
- if (!args || !args[1])
- return;
-
parts = g_strsplit(args[1], " ", 2);
if (!parts[0] || !parts[1]) {
@@ -1345,9 +1333,6 @@ void irc_msg_pong(struct irc_conn *irc,
void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args)
{
- if (!args || !args[0] || !args[1])
- return;
-
irc_msg_handle_privmsg(irc, name, from, args[0], args[1], FALSE);
}
@@ -1424,9 +1409,6 @@ void irc_msg_quit(struct irc_conn *irc,
struct irc_buddy *ib;
char *data[2];
- if (!args || !args[0] || !gc)
- return;
-
data[0] = irc_mask_nick(from);
data[1] = args[0];
/* XXX this should have an API, I shouldn't grab this directly */
@@ -1456,9 +1438,6 @@ void irc_msg_wallops(struct irc_conn *ir
PurpleConnection *gc = purple_account_get_connection(irc->account);
char *nick, *msg;
- if (!args || !args[0] || !gc)
- return;
-
nick = irc_mask_nick(from);
msg = g_strdup_printf (_("Wallops from %s"), nick);
g_free(nick);
@@ -1633,7 +1612,7 @@ irc_msg_cap(struct irc_conn *irc, const
PurpleConnection *gc = purple_account_get_connection(irc->account);
const char *mech_list = NULL;
- if (!args[1] || !args[2] || strncmp(args[2], "sasl ", 6))
+ if (strncmp(args[2], "sasl ", 6))
return;
if (strncmp(args[1], "ACK", 4)) {
const char *tmp = _("SASL authentication failed: Server does not support SASL authentication.");
diff --git a/libpurple/protocols/irc/parse.c b/libpurple/protocols/irc/parse.c
--- a/libpurple/protocols/irc/parse.c
+++ b/libpurple/protocols/irc/parse.c
@@ -72,8 +72,8 @@ static struct _irc_msg {
{ "322", "ncv:", -1, irc_msg_list }, /* List. */
{ "323", ":", -1, irc_msg_list }, /* End of list. */
{ "324", "ncv:", -1, irc_msg_chanmode }, /* Channel modes */
- { "331", "nc:", -1, irc_msg_topic }, /* No channel topic */
- { "332", "nc:", -1, irc_msg_topic }, /* Channel topic */
+ { "331", "nc:", 3, irc_msg_topic }, /* No channel topic */
+ { "332", "nc:", 3, irc_msg_topic }, /* Channel topic */
{ "333", "ncvv", -1, irc_msg_topicinfo }, /* Topic setter stuff */
{ "352", "ncvvvnv:", -1, irc_msg_who }, /* Channel WHO */
{ "353", "nvc:", -1, irc_msg_names }, /* Names list */
@@ -104,26 +104,26 @@ static struct _irc_msg {
{ "506", "nc:", -1, irc_msg_nosend }, /* Must identify to send */
{ "515", "nc:", -1, irc_msg_regonly }, /* Registration required */
#ifdef HAVE_CYRUS_SASL
- { "903", "*", -1, irc_msg_authok}, /* SASL auth successful */
- { "904", "*", -1, irc_msg_authtryagain }, /* SASL auth failed, can recover*/
- { "905", "*", -1, irc_msg_authfail }, /* SASL auth failed */
- { "906", "*", -1, irc_msg_authfail }, /* SASL auth failed */
- { "907", "*", -1, irc_msg_authfail }, /* SASL auth failed */
- { "cap", "vv:", -1, irc_msg_cap }, /* SASL capable */
+ { "903", "*", 0, irc_msg_authok}, /* SASL auth successful */
+ { "904", "*", 0, irc_msg_authtryagain }, /* SASL auth failed, can recover*/
+ { "905", "*", 0, irc_msg_authfail }, /* SASL auth failed */
+ { "906", "*", 0, irc_msg_authfail }, /* SASL auth failed */
+ { "907", "*", 0, irc_msg_authfail }, /* SASL auth failed */
+ { "cap", "vv:", 3, irc_msg_cap }, /* SASL capable */
#endif
- { "invite", "n:", -1, irc_msg_invite }, /* Invited */
- { "join", ":", -1, irc_msg_join }, /* Joined a channel */
+ { "invite", "n:", 2, irc_msg_invite }, /* Invited */
+ { "join", ":", 1, irc_msg_join }, /* Joined a channel */
{ "kick", "cn:", -1, irc_msg_kick }, /* KICK */
- { "mode", "tv:", -1, irc_msg_mode }, /* MODE for channel */
+ { "mode", "tv:", 2, irc_msg_mode }, /* MODE for channel */
{ "nick", ":", -1, irc_msg_nick }, /* Nick change */
- { "notice", "t:", -1, irc_msg_notice }, /* NOTICE recv */
- { "part", "c:", -1, irc_msg_part }, /* Parted a channel */
- { "ping", ":", -1, irc_msg_ping }, /* Received PING from server */
- { "pong", "v:", -1, irc_msg_pong }, /* Received PONG from server */
- { "privmsg", "t:", -1, irc_msg_privmsg }, /* Received private message */
- { "topic", "c:", -1, irc_msg_topic }, /* TOPIC command */
- { "quit", ":", -1, irc_msg_quit }, /* QUIT notice */
- { "wallops", ":", -1, irc_msg_wallops }, /* WALLOPS command */
+ { "notice", "t:", 2, irc_msg_notice }, /* NOTICE recv */
+ { "part", "c:", 1, irc_msg_part }, /* Parted a channel */
+ { "ping", ":", 1, irc_msg_ping }, /* Received PING from server */
+ { "pong", "v:", 2, irc_msg_pong }, /* Received PONG from server */
+ { "privmsg", "t:", 2, irc_msg_privmsg }, /* Received private message */
+ { "topic", "c:", 2, irc_msg_topic }, /* TOPIC command */
+ { "quit", ":", 1, irc_msg_quit }, /* QUIT notice */
+ { "wallops", ":", 1, irc_msg_wallops }, /* WALLOPS command */
{ NULL, NULL, 0, NULL }
};
More information about the Commits
mailing list