pidgin/pidgin

IRC: fill required command parameter counts (part 1)
release-2.x.y
2014-01-16, Tomasz Wasilczyk
9f132a6855cd
Parents 900c8ac8b4fb
Children 5845d9fa7084
IRC: fill required command parameter counts (part 1)
--- a/libpurple/protocols/irc/msgs.c Wed Jan 15 20:43:52 2014 -0800
+++ b/libpurple/protocols/irc/msgs.c Thu Jan 16 11:28:22 2014 +0100
@@ -595,13 +595,13 @@
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 @@
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 @@
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 @@
{
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_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 @@
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_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 @@
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_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 @@
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 @@
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 @@
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.");
--- a/libpurple/protocols/irc/parse.c Wed Jan 15 20:43:52 2014 -0800
+++ b/libpurple/protocols/irc/parse.c Thu Jan 16 11:28:22 2014 +0100
@@ -72,8 +72,8 @@
{ "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 @@
{ "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 }
};