/pidgin/main: 7395c02a2960: MXit: Ensure that the presence value...

Andrew Victor andrew.victor at mxit.com
Mon Apr 15 10:49:40 EDT 2013


Changeset: 7395c02a296076345be1a190949ad7548fc2fef1
Author:	 Andrew Victor <andrew.victor at mxit.com>
Date:	 2013-04-15 16:49 +0200
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/7395c02a2960

Description:

MXit: Ensure that the presence value received from the server is valid.

diffstat:

 libpurple/protocols/mxit/protocol.c |  28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diffs (52 lines):

diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -1684,6 +1684,30 @@ static void mxit_parse_cmd_new_sub( stru
 
 
 /*------------------------------------------------------------------------
+ * Parse the received presence value, and ensure that it is supported.
+ *
+ *  @param value		The received presence value.
+ *  @return				A valid presence value.
+ */
+static short mxit_parse_presence( const char* value )
+{
+	short presence = atoi( value );
+
+	/* ensure that the presence value is valid */
+	switch ( presence ) {
+		case MXIT_PRESENCE_OFFLINE :
+		case MXIT_PRESENCE_ONLINE :
+		case MXIT_PRESENCE_AWAY :
+		case MXIT_PRESENCE_DND :
+			return presence;
+
+		default :
+			return MXIT_PRESENCE_ONLINE;
+	}
+}
+
+
+/*------------------------------------------------------------------------
  * Process a received contact update packet.
  *
  *  @param session		The MXit session object
@@ -1714,7 +1738,7 @@ static void mxit_parse_cmd_contact( stru
 		mxit_strip_domain( contact->username );				/* remove dummy domain */
 		g_strlcpy( contact->alias, rec->fields[2]->data, sizeof( contact->alias ) );
 
-		contact->presence = atoi( rec->fields[3]->data );
+		contact->presence = mxit_parse_presence( rec->fields[3]->data );
 		contact->type = atoi( rec->fields[4]->data );
 		contact->mood = atoi( rec->fields[5]->data );
 
@@ -1773,7 +1797,7 @@ static void mxit_parse_cmd_presence( str
 		if ( rec->fcount >= 7 )		/* flags field is included */
 			flags = atoi( rec->fields[6]->data );
 
-		mxit_update_buddy_presence( session, rec->fields[0]->data, atoi( rec->fields[1]->data ), atoi( rec->fields[2]->data ),
+		mxit_update_buddy_presence( session, rec->fields[0]->data, mxit_parse_presence( rec->fields[1]->data ), atoi( rec->fields[2]->data ),
 				rec->fields[3]->data, rec->fields[4]->data, flags );
 		mxit_update_buddy_avatar( session, rec->fields[0]->data, rec->fields[5]->data );
 	}



More information about the Commits mailing list