comparison libpurple/protocols/mxit/markup.c @ 32332:92ab45c1758a

Correctly process messages received from MXit that include font-change markup.
author andrew.victor@mxit.com
date Mon, 20 Jun 2011 21:25:52 +0000
parents 516435ac46a7
children 9ad5fcde4af4
comparison
equal deleted inserted replaced
32133:835ea8811734 32332:92ab45c1758a
733 733
734 /* tags */ 734 /* tags */
735 gboolean tag_bold = FALSE; 735 gboolean tag_bold = FALSE;
736 gboolean tag_under = FALSE; 736 gboolean tag_under = FALSE;
737 gboolean tag_italic = FALSE; 737 gboolean tag_italic = FALSE;
738 int font_size = 0;
738 739
739 #ifdef MXIT_DEBUG_MARKUP 740 #ifdef MXIT_DEBUG_MARKUP
740 purple_debug_info( MXIT_PLUGIN_ID, "Markup RX (original): '%s'\n", message ); 741 purple_debug_info( MXIT_PLUGIN_ID, "Markup RX (original): '%s'\n", message );
741 #endif 742 #endif
742 743
860 /* not valid colour markup */ 861 /* not valid colour markup */
861 g_string_append_c( mx->msg, '#' ); 862 g_string_append_c( mx->msg, '#' );
862 } 863 }
863 break; 864 break;
864 case '.' : 865 case '.' :
865 if ( !( msgflags & CP_MSG_EMOTICON ) ) { 866 if ( i + 1 >= len ) {
866 g_string_append_c( mx->msg, message[i] );
867 break;
868 }
869 else if ( i + 1 >= len ) {
870 /* message too short */ 867 /* message too short */
871 g_string_append_c( mx->msg, '.' ); 868 g_string_append_c( mx->msg, '.' );
872 break; 869 break;
873 } 870 }
874 871
875 switch ( message[i+1] ) { 872 if ( ( msgflags & CP_MSG_EMOTICON ) && ( message[i+1] == '{' ) ) {
876 case '+' : 873 /* custom emoticon */
877 /* increment text size */ 874 if ( i + 2 >= len ) {
878 g_string_append( mx->msg, "<font size=\"+1\">" ); 875 /* message too short */
879 i++; 876 g_string_append_c( mx->msg, '.' );
880 break; 877 break;
881 case '-' : 878 }
882 /* decrement text size */ 879
883 g_string_append( mx->msg, "<font size=\"-1\">" ); 880 parse_emoticon_str( &message[i+2], tmpstr1 );
884 i++; 881 if ( tmpstr1[0] != '\0' ) {
885 break; 882 mx->got_img = TRUE;
886 case '{' : 883
887 /* custom emoticon */ 884 if ( g_hash_table_lookup( mx->session->iimages, tmpstr1 ) ) {
888 if ( i + 2 >= len ) { 885 /* emoticon found in the cache, so we do not have to request it from the WAPsite */
889 /* message too short */ 886 }
890 g_string_append_c( mx->msg, '.' ); 887 else {
891 break; 888 /* request emoticon from the WAPsite */
892 } 889 mx->img_count++;
893 890 emoticon_request( mx, tmpstr1 );
894 parse_emoticon_str( &message[i+2], tmpstr1 ); 891 }
895 if ( tmpstr1[0] != '\0' ) { 892
896 mx->got_img = TRUE; 893 g_string_append_printf( mx->msg, MXIT_II_TAG"%s>", tmpstr1 );
897 894 i += strlen( tmpstr1 ) + 2;
898 if ( g_hash_table_lookup( mx->session->iimages, tmpstr1 ) ) { 895 }
899 /* emoticon found in the cache, so we do not have to request it from the WAPsite */ 896 else
900 } 897 g_string_append_c( mx->msg, '.' );
901 else { 898 }
902 /* request emoticon from the WAPsite */ 899 else if ( ( msgflags & CP_MSG_MARKUP ) && ( message[i+1] == '+' ) ) {
903 mx->img_count++; 900 /* increment text size */
904 emoticon_request( mx, tmpstr1 ); 901 font_size++;
905 } 902 g_string_append_printf( mx->msg, "<font size=\"%+i\">", font_size );
906 903 i++;
907 g_string_append_printf( mx->msg, MXIT_II_TAG"%s>", tmpstr1 ); 904 }
908 i += strlen( tmpstr1 ) + 2; 905 else if ( ( msgflags & CP_MSG_MARKUP ) && ( message[i+1] == '-' ) ) {
909 } 906 /* decrement text size */
910 else 907 font_size--;
911 g_string_append_c( mx->msg, '.' ); 908 g_string_append_printf( mx->msg, "<font size=\"%+i\">", font_size );
912 909 i++;
913 break; 910 }
914 default : 911 else
915 g_string_append_c( mx->msg, '.' ); 912 g_string_append_c( mx->msg, '.' );
916 break; 913
917 }
918 break; 914 break;
919 case '\\' : 915 case '\\' :
920 if ( i + 1 >= len ) { 916 if ( i + 1 >= len ) {
921 /* message too short for an escaped character */ 917 /* message too short for an escaped character */
922 g_string_append_c( mx->msg, '\\' ); 918 g_string_append_c( mx->msg, '\\' );