/pidgin/main: 6b0e0566af20: IRC: fill required command parameter...

Tomasz Wasilczyk twasilczyk at pidgin.im
Tue Jan 28 10:38:12 EST 2014


Changeset: 6b0e0566af20742c2c4f0e94354598bea2bdbbce
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-01-16 12:11 +0100
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/6b0e0566af20

Description:

IRC: fill required command parameter counts (part 3)

diffstat:

 libpurple/protocols/irc/msgs.c  |  34 +-------------------------
 libpurple/protocols/irc/parse.c |  54 +++++++++++++++++++++-------------------
 2 files changed, 29 insertions(+), 59 deletions(-)

diffs (174 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
@@ -203,9 +203,6 @@ void irc_msg_features(struct irc_conn *i
 	gchar **features;
 	int i;
 
-	if (!args || !args[0] || !args[1])
-		return;
-
 	features = g_strsplit(args[1], " ", -1);
 	for (i = 0; features[i]; i++) {
 		char *val;
@@ -220,9 +217,6 @@ void irc_msg_features(struct irc_conn *i
 
 void irc_msg_luser(struct irc_conn *irc, const char *name, const char *from, char **args)
 {
-	if (!args || !args[0])
-		return;
-
 	if (!strcmp(name, "251")) {
 		/* 251 is required, so we pluck our nick from here and
 		 * finalize connection */
@@ -238,9 +232,6 @@ void irc_msg_away(struct irc_conn *irc, 
 	PurpleConnection *gc;
 	char *msg;
 
-	if (!args || !args[1])
-		return;
-
 	if (irc->whois.nick && !purple_utf8_strcasecmp(irc->whois.nick, args[1])) {
 		/* We're doing a whois, show this in the whois dialog */
 		irc_msg_whois(irc, name, from, args);
@@ -266,17 +257,13 @@ void irc_msg_ban(struct irc_conn *irc, c
 {
 	PurpleConversation *convo;
 
-	if (!args || !args[0] || !args[1])
-		return;
-
 	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
 						      args[1], irc->account);
 
 	if (!strcmp(name, "367")) {
 		char *msg = NULL;
 		/* Ban list entry */
-		if (!args[2])
-			return;
+		g_return_if_fail(args[2]);
 		if (args[3] && args[4]) {
 			/* This is an extended syntax, not in RFC 1459 */
 			int t1 = atoi(args[4]);
@@ -340,9 +327,6 @@ void irc_msg_chanmode(struct irc_conn *i
 	PurpleConversation *convo;
 	char *buf, *escaped;
 
-	if (!args || !args[1] || !args[2])
-		return;
-
 	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);
 	if (!convo)	/* XXX punt on channels we are not in for now */
 		return;
@@ -480,13 +464,6 @@ void irc_msg_who(struct irc_conn *irc, c
 		PurpleConvChatBuddyFlags flags;
 		GList *keys = NULL, *values = NULL;
 
-		if (!args || !args[0] || !args[1] || !args[2] || !args[3]
-		    || !args[4] || !args[5] || !args[6] || !args[7]) {
-			purple_debug(PURPLE_DEBUG_ERROR, "irc",
-				     "Got a WHO response with not enough arguments\n");
-			return;
-		}
-
 		conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);
 		if (!conv) {
 			purple_debug(PURPLE_DEBUG_ERROR, "irc","Got a WHO response for %s, which doesn't exist\n", args[1]);
@@ -562,9 +539,6 @@ void irc_msg_list(struct irc_conn *irc, 
 		PurpleRoomlistRoom *room;
 		char *topic;
 
-		if (!args[0] || !args[1] || !args[2] || !args[3])
-			return;
-
 		if (!purple_roomlist_get_in_progress(irc->roomlist)) {
 			purple_debug_warning("irc", "Buggy server didn't send RPL_LISTSTART.\n");
 			purple_roomlist_set_in_progress(irc->roomlist, TRUE);
@@ -643,9 +617,6 @@ void irc_msg_topicinfo(struct irc_conn *
 	struct tm *tm;
 	time_t t;
 	char *msg, *timestamp, *datestamp;
-	
-	if (!args || !args[1] || !args[2] || !args[3])
-		return;
 
 	convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);
 	if (!convo) {
@@ -910,9 +881,6 @@ void irc_msg_ison(struct irc_conn *irc, 
 	struct irc_buddy *ib;
 	int i;
 
-	if (!args || !args[1])
-		return;
-
 	nicks = g_strsplit(args[1], " ", -1);
 	for (i = 0; nicks[i]; i++) {
 		if ((ib = g_hash_table_lookup(irc->buddies, (gconstpointer)nicks[i])) == NULL) {
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
@@ -50,36 +50,38 @@ extern PurplePlugin *_irc_plugin;
 static struct _irc_msg {
 	char *name;
 	char *format;
-	int req_cnt;
+	/* The required parameters count, based on values we use, not protocol
+	 * specification. */
+	int req_cnt; 
 	void (*cb)(struct irc_conn *irc, const char *name, const char *from, char **args);
 } _irc_msgs[] = {
-	{ "005", "n*", -1, irc_msg_features },		/* Feature list			*/
-	{ "251", "n:", -1, irc_msg_luser },		/* Client & Server count	*/
-	{ "255", "n:", -1, irc_msg_luser },		/* Client & Server count Mk. II	*/
-	{ "301", "nn:", -1, irc_msg_away },		/* User is away			*/
-	{ "303", "n:", -1, irc_msg_ison },		/* ISON reply			*/
-	{ "311", "nnvvv:", -1, irc_msg_whois },		/* Whois user			*/
-	{ "312", "nnv:", -1, irc_msg_whois },		/* Whois server			*/
-	{ "313", "nn:", -1, irc_msg_whois },		/* Whois ircop			*/
-	{ "317", "nnvv", -1, irc_msg_whois },		/* Whois idle			*/
-	{ "318", "nt:", -1, irc_msg_endwhois },		/* End of WHOIS			*/
-	{ "319", "nn:", -1, irc_msg_whois },		/* Whois channels		*/
-	{ "320", "nn:", -1, irc_msg_whois },		/* Whois (fn ident)		*/
-	{ "314", "nnnvv:", -1, irc_msg_whois },		/* Whowas user			*/
-	{ "315", "nt:", -1, irc_msg_who },		/* end of WHO channel		*/
-	{ "369", "nt:", -1, irc_msg_endwhois },		/* End of WHOWAS		*/
-	{ "321", "*", -1, irc_msg_list },		/* Start of list		*/
-	{ "322", "ncv:", -1, irc_msg_list },		/* List.			*/
-	{ "323", ":", -1, irc_msg_list },		/* End of list.			*/
-	{ "324", "ncv:", -1, irc_msg_chanmode },	/* Channel modes		*/
+	{ "005", "n*", 2, irc_msg_features },		/* Feature list			*/
+	{ "251", "n:", 1, irc_msg_luser },		/* Client & Server count	*/
+	{ "255", "n:", 1, irc_msg_luser },		/* Client & Server count Mk. II	*/
+	{ "301", "nn:", 3, irc_msg_away },		/* User is away			*/
+	{ "303", "n:", 2, irc_msg_ison },		/* ISON reply			*/
+	{ "311", "nnvvv:", 6, irc_msg_whois },		/* Whois user			*/
+	{ "312", "nnv:", 4, irc_msg_whois },		/* Whois server			*/
+	{ "313", "nn:", 2, irc_msg_whois },		/* Whois ircop			*/
+	{ "317", "nnvv", 4, irc_msg_whois },		/* Whois idle			*/
+	{ "318", "nt:", 2, irc_msg_endwhois },		/* End of WHOIS			*/
+	{ "319", "nn:", 3, irc_msg_whois },		/* Whois channels		*/
+	{ "320", "nn:", 2, irc_msg_whois },		/* Whois (fn ident)		*/
+	{ "314", "nnnvv:", 6, irc_msg_whois },		/* Whowas user			*/
+	{ "315", "nt:", 0, irc_msg_who },		/* end of WHO channel		*/
+	{ "369", "nt:", 2, irc_msg_endwhois },		/* End of WHOWAS		*/
+	{ "321", "*", 0, irc_msg_list },		/* Start of list		*/
+	{ "322", "ncv:", 4, irc_msg_list },		/* List.			*/
+	{ "323", ":", 0, irc_msg_list },		/* End of list.			*/
+	{ "324", "ncv:", 3, irc_msg_chanmode },		/* Channel modes		*/
 	{ "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			*/
-	{ "366", "nc:", -1, irc_msg_names },		/* End of names			*/
-	{ "367", "ncnnv", -1, irc_msg_ban },		/* Ban list			*/
-	{ "368", "nc:", -1, irc_msg_ban },		/* End of ban list		*/
+	{ "333", "ncvv", 4, irc_msg_topicinfo },	/* Topic setter stuff		*/
+	{ "352", "ncvvvnv:", 8, irc_msg_who },		/* Channel WHO			*/
+	{ "353", "nvc:", 4, irc_msg_names },		/* Names list			*/
+	{ "366", "nc:", 2, irc_msg_names },		/* End of names			*/
+	{ "367", "ncnnv", 3, irc_msg_ban },		/* Ban list			*/
+	{ "368", "nc:", 2, irc_msg_ban },		/* End of ban list		*/
 	{ "372", "n:", 1, irc_msg_motd },		/* MOTD				*/
 	{ "375", "n:", 1, irc_msg_motd },		/* Start MOTD			*/
 	{ "376", "n:", 1, irc_msg_motd },		/* End of MOTD			*/



More information about the Commits mailing list