changeset 30304:fe072dddc42c

If a chatroom user's nickname contains MXit markup characters, they are escaped by the chatroom service before being sent. When the client extracts the nickname field we need to perform un-escaping (ie, "\X" -> "X" ) to restore the original nickname.
author andrew.victor@mxit.com
date Wed, 21 Jul 2010 08:23:42 +0000
parents bcc196eb47c2
children d3e13deb64a5
files libpurple/protocols/mxit/markup.c
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/mxit/markup.c	Tue Jul 20 13:44:56 2010 +0000
+++ b/libpurple/protocols/mxit/markup.c	Wed Jul 21 08:23:42 2010 +0000
@@ -662,7 +662,7 @@
  *  @param message			The message text
  *  @return					The length of the message to skip
  */
-static int mxit_extract_chatroom_nick( struct RXMsgData* mx, char* message, int len )
+static int mxit_extract_chatroom_nick( struct RXMsgData* mx, char* message, int len, int msgflags )
 {
 	int		i;
 
@@ -673,7 +673,6 @@
 		 * Search for it....
 		 */
 		gboolean	found	= FALSE;
-		gchar*		nickname;
 
 		for ( i = 1; i < len; i++ ) {
 			if ( ( message[i] == '\n' ) && ( message[i-1] == '>' ) ) {
@@ -685,12 +684,30 @@
 		}
 
 		if ( found ) {
+			gchar*		nickname;
+
 			/*
 			 * The message definitely had an embedded nickname - generate a marked-up
 			 * message to be displayed.
 			 */
 			nickname = g_markup_escape_text( &message[1], -1 );
 
+			/* Remove any MXit escaping from nickname ("\X" --> "X") */
+			if ( msgflags & CP_MSG_MARKUP ) {
+				int	nicklen = strlen( nickname );
+				int	j, k;
+
+				for ( j = 0, k = 0; j < nicklen; j++ ) {
+					if ( nickname[j] == '\\' )
+						j++;
+
+					nickname[k] = nickname[j];
+					k++;
+				}
+
+				nickname[k] = '\0';		/* terminate string */
+			}
+
 			/* add nickname within some BOLD markup to the new converted message */
 			g_string_append_printf( mx->msg, "<b>%s:</b> ", nickname );
 
@@ -747,7 +764,7 @@
 	if ( is_mxit_chatroom_contact( mx->session, mx->from ) ) {
 		/* chatroom message, so we need to extract and skip the sender's nickname
 		 * which is embedded inside the message */
-		i = mxit_extract_chatroom_nick( mx, message, len );
+		i = mxit_extract_chatroom_nick( mx, message, len, msgflags );
 	}
 
 	/* run through the message and check for custom emoticons and markup */