IRC: fill required command parameter counts (part 1) release-2.x.y
authorTomasz Wasilczyk <twasilczyk@pidgin.im>
Thu, 16 Jan 2014 11:28:22 +0100
branchrelease-2.x.y
changeset9f132a6855cd pushlog
parent 900c8ac8b4fb
child 5845d9fa7084
IRC: fill required command parameter counts (part 1)
libpurple/protocols/irc/msgs.c
libpurple/protocols/irc/parse.c
     1.1 --- a/libpurple/protocols/irc/msgs.c
     1.2 +++ b/libpurple/protocols/irc/msgs.c
     1.3 @@ -595,13 +595,13 @@
     1.4  	PurpleConversation *convo;
     1.5  
     1.6  	if (!strcmp(name, "topic")) {
     1.7 -		if (!args[0] || !args[1])
     1.8 -			return;
     1.9 +		g_return_if_fail(args[0]);
    1.10 +		g_return_if_fail(args[1]);
    1.11  		chan = args[0];
    1.12  		topic = irc_mirc2txt (args[1]);
    1.13  	} else {
    1.14 -		if (!args[0] || !args[1] || !args[2])
    1.15 -			return;
    1.16 +		g_return_if_fail(args[1]);
    1.17 +		g_return_if_fail(args[2]);
    1.18  		chan = args[1];
    1.19  		topic = irc_mirc2txt (args[2]);
    1.20  	}
    1.21 @@ -908,8 +908,7 @@
    1.22  	GHashTable *components;
    1.23  	gchar *nick;
    1.24  
    1.25 -	if (!args || !args[1] || !gc)
    1.26 -		return;
    1.27 +	g_return_if_fail(gc);
    1.28  
    1.29  	components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
    1.30  	nick = irc_mask_nick(from);
    1.31 @@ -982,14 +981,13 @@
    1.32  	PurpleConvChat *chat;
    1.33  	PurpleConvChatBuddy *cb;
    1.34  
    1.35 -	char *nick = irc_mask_nick(from), *userhost, *buf;
    1.36 +	char *nick, *userhost, *buf;
    1.37  	struct irc_buddy *ib;
    1.38  	static int id = 1;
    1.39  
    1.40 -	if (!gc) {
    1.41 -		g_free(nick);
    1.42 -		return;
    1.43 -	}
    1.44 +	g_return_if_fail(gc);
    1.45 +
    1.46 +	nick = irc_mask_nick(from);
    1.47  
    1.48  	if (!purple_utf8_strcasecmp(nick, purple_connection_get_display_name(gc))) {
    1.49  		/* We are joining a channel for the first time */
    1.50 @@ -1049,12 +1047,11 @@
    1.51  {
    1.52  	PurpleConnection *gc = purple_account_get_connection(irc->account);
    1.53  	PurpleConversation *convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[0], irc->account);
    1.54 -	char *nick = irc_mask_nick(from), *buf;
    1.55 +	char *nick, *buf;
    1.56  
    1.57 -	if (!gc) {
    1.58 -		g_free(nick);
    1.59 -		return;
    1.60 -	}
    1.61 +	g_return_if_fail(gc);
    1.62 +
    1.63 +	nick = irc_mask_nick(from);
    1.64  
    1.65  	if (!convo) {
    1.66  		purple_debug(PURPLE_DEBUG_ERROR, "irc", "Received a KICK for unknown channel %s\n", args[0]);
    1.67 @@ -1238,9 +1235,6 @@
    1.68  
    1.69  void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args)
    1.70  {
    1.71 -	if (!args || !args[0] || !args[1])
    1.72 -		return;
    1.73 -
    1.74  	irc_msg_handle_privmsg(irc, name, from, args[0], args[1], TRUE);
    1.75  }
    1.76  
    1.77 @@ -1260,8 +1254,7 @@
    1.78  	PurpleConversation *convo;
    1.79  	char *nick, *msg, *channel;
    1.80  
    1.81 -	if (!args || !args[0] || !gc)
    1.82 -		return;
    1.83 +	g_return_if_fail(gc);
    1.84  
    1.85  	/* Undernet likes to :-quote the channel name, for no good reason
    1.86  	 * that I can see.  This catches that. */
    1.87 @@ -1294,8 +1287,6 @@
    1.88  void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args)
    1.89  {
    1.90  	char *buf;
    1.91 -	if (!args || !args[0])
    1.92 -		return;
    1.93  
    1.94  	buf = irc_format(irc, "v:", "PONG", args[0]);
    1.95  	irc_send(irc, buf);
    1.96 @@ -1309,9 +1300,6 @@
    1.97  	char **parts, *msg;
    1.98  	time_t oldstamp;
    1.99  
   1.100 -	if (!args || !args[1])
   1.101 -		return;
   1.102 -
   1.103  	parts = g_strsplit(args[1], " ", 2);
   1.104  
   1.105  	if (!parts[0] || !parts[1]) {
   1.106 @@ -1345,9 +1333,6 @@
   1.107  
   1.108  void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args)
   1.109  {
   1.110 -	if (!args || !args[0] || !args[1])
   1.111 -		return;
   1.112 -
   1.113  	irc_msg_handle_privmsg(irc, name, from, args[0], args[1], FALSE);
   1.114  }
   1.115  
   1.116 @@ -1424,9 +1409,6 @@
   1.117  	struct irc_buddy *ib;
   1.118  	char *data[2];
   1.119  
   1.120 -	if (!args || !args[0] || !gc)
   1.121 -		return;
   1.122 -
   1.123  	data[0] = irc_mask_nick(from);
   1.124  	data[1] = args[0];
   1.125  	/* XXX this should have an API, I shouldn't grab this directly */
   1.126 @@ -1456,9 +1438,6 @@
   1.127  	PurpleConnection *gc = purple_account_get_connection(irc->account);
   1.128  	char *nick, *msg;
   1.129  
   1.130 -	if (!args || !args[0] || !gc)
   1.131 -		return;
   1.132 -
   1.133  	nick = irc_mask_nick(from);
   1.134  	msg = g_strdup_printf (_("Wallops from %s"), nick);
   1.135  	g_free(nick);
   1.136 @@ -1633,7 +1612,7 @@
   1.137  	PurpleConnection *gc = purple_account_get_connection(irc->account);
   1.138  	const char *mech_list = NULL;
   1.139  
   1.140 -	if (!args[1] || !args[2] || strncmp(args[2], "sasl ", 6))
   1.141 +	if (strncmp(args[2], "sasl ", 6))
   1.142  		return;
   1.143  	if (strncmp(args[1], "ACK", 4)) {
   1.144  		const char *tmp = _("SASL authentication failed: Server does not support SASL authentication.");
     2.1 --- a/libpurple/protocols/irc/parse.c
     2.2 +++ b/libpurple/protocols/irc/parse.c
     2.3 @@ -72,8 +72,8 @@
     2.4  	{ "322", "ncv:", -1, irc_msg_list },		/* List.			*/
     2.5  	{ "323", ":", -1, irc_msg_list },		/* End of list.			*/
     2.6  	{ "324", "ncv:", -1, irc_msg_chanmode },	/* Channel modes		*/
     2.7 -	{ "331", "nc:", -1,	irc_msg_topic },	/* No channel topic		*/
     2.8 -	{ "332", "nc:", -1, irc_msg_topic },		/* Channel topic		*/
     2.9 +	{ "331", "nc:", 3, irc_msg_topic },		/* No channel topic		*/
    2.10 +	{ "332", "nc:", 3, irc_msg_topic },		/* Channel topic		*/
    2.11  	{ "333", "ncvv", -1, irc_msg_topicinfo },	/* Topic setter stuff		*/
    2.12  	{ "352", "ncvvvnv:", -1, irc_msg_who },		/* Channel WHO			*/
    2.13  	{ "353", "nvc:", -1, irc_msg_names },		/* Names list			*/
    2.14 @@ -104,26 +104,26 @@
    2.15  	{ "506", "nc:", -1, irc_msg_nosend },		/* Must identify to send	*/
    2.16  	{ "515", "nc:", -1, irc_msg_regonly },		/* Registration required	*/
    2.17  #ifdef HAVE_CYRUS_SASL
    2.18 -	{ "903", "*", -1, irc_msg_authok},		/* SASL auth successful		*/
    2.19 -	{ "904", "*", -1, irc_msg_authtryagain },	/* SASL auth failed, can recover*/
    2.20 -	{ "905", "*", -1, irc_msg_authfail },		/* SASL auth failed		*/
    2.21 -	{ "906", "*", -1, irc_msg_authfail },		/* SASL auth failed		*/
    2.22 -	{ "907", "*", -1, irc_msg_authfail },		/* SASL auth failed		*/
    2.23 -	{ "cap", "vv:", -1, irc_msg_cap },		/* SASL capable			*/
    2.24 +	{ "903", "*", 0, irc_msg_authok},		/* SASL auth successful		*/
    2.25 +	{ "904", "*", 0, irc_msg_authtryagain },	/* SASL auth failed, can recover*/
    2.26 +	{ "905", "*", 0, irc_msg_authfail },		/* SASL auth failed		*/
    2.27 +	{ "906", "*", 0, irc_msg_authfail },		/* SASL auth failed		*/
    2.28 +	{ "907", "*", 0, irc_msg_authfail },		/* SASL auth failed		*/
    2.29 +	{ "cap", "vv:", 3, irc_msg_cap },		/* SASL capable			*/
    2.30  #endif
    2.31 -	{ "invite", "n:", -1, irc_msg_invite },		/* Invited			*/
    2.32 -	{ "join", ":", -1, irc_msg_join },		/* Joined a channel		*/
    2.33 +	{ "invite", "n:", 2, irc_msg_invite },		/* Invited			*/
    2.34 +	{ "join", ":", 1, irc_msg_join },		/* Joined a channel		*/
    2.35  	{ "kick", "cn:", -1, irc_msg_kick },		/* KICK				*/
    2.36 -	{ "mode", "tv:", -1, irc_msg_mode },		/* MODE for channel		*/
    2.37 +	{ "mode", "tv:", 2, irc_msg_mode },		/* MODE for channel		*/
    2.38  	{ "nick", ":", -1, irc_msg_nick },		/* Nick change			*/
    2.39 -	{ "notice", "t:", -1, irc_msg_notice },		/* NOTICE recv			*/
    2.40 -	{ "part", "c:", -1, irc_msg_part },		/* Parted a channel		*/
    2.41 -	{ "ping", ":", -1, irc_msg_ping },		/* Received PING from server	*/
    2.42 -	{ "pong", "v:", -1, irc_msg_pong },		/* Received PONG from server	*/
    2.43 -	{ "privmsg", "t:", -1, irc_msg_privmsg },	/* Received private message	*/
    2.44 -	{ "topic", "c:", -1, irc_msg_topic },		/* TOPIC command		*/
    2.45 -	{ "quit", ":", -1, irc_msg_quit },		/* QUIT notice			*/
    2.46 -	{ "wallops", ":", -1, irc_msg_wallops },	/* WALLOPS command		*/
    2.47 +	{ "notice", "t:", 2, irc_msg_notice },		/* NOTICE recv			*/
    2.48 +	{ "part", "c:", 1, irc_msg_part },		/* Parted a channel		*/
    2.49 +	{ "ping", ":", 1, irc_msg_ping },		/* Received PING from server	*/
    2.50 +	{ "pong", "v:", 2, irc_msg_pong },		/* Received PONG from server	*/
    2.51 +	{ "privmsg", "t:", 2, irc_msg_privmsg },	/* Received private message	*/
    2.52 +	{ "topic", "c:", 2, irc_msg_topic },		/* TOPIC command		*/
    2.53 +	{ "quit", ":", 1, irc_msg_quit },		/* QUIT notice			*/
    2.54 +	{ "wallops", ":", 1, irc_msg_wallops },		/* WALLOPS command		*/
    2.55  	{ NULL, NULL, 0, NULL }
    2.56  };
    2.57