libpurple/protocols/mxit/protocol.c

changeset 33933
bd00e2d2b32e
parent 33852
368feedc80cf
parent 33893
7395c02a2960
child 34219
eee308def583
--- a/libpurple/protocols/mxit/protocol.c	Thu May 09 23:11:52 2013 +0200
+++ b/libpurple/protocols/mxit/protocol.c	Sat May 11 18:02:21 2013 -0400
@@ -1685,6 +1685,30 @@
 
 
 /*------------------------------------------------------------------------
+ * 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
@@ -1715,7 +1739,7 @@
 		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 );
 
@@ -1774,7 +1798,7 @@
 		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 );
 	}

mercurial