summaryrefslogtreecommitdiff
path: root/libpurple/protocols/mxit/markup.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpurple/protocols/mxit/markup.c')
-rw-r--r--libpurple/protocols/mxit/markup.c129
1 files changed, 69 insertions, 60 deletions
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
index 2a417ae71f..9a5fab851b 100644
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -124,10 +124,11 @@ static void hex_dump( const char* buf, int len )
* Adds a link to a message
*
* @param mx The Markup message object
- * @param linkname This is the what will be returned when the link gets clicked
- * @param displayname This is the name for the link which will be displayed in the UI
+ * @param replydata This is the what will be returned when the link gets clicked
+ * @param isStructured Indicates that the reply is a structured reply
+ * @param displaytext This is the text for the link which will be displayed in the UI
*/
-void mxit_add_html_link( struct RXMsgData* mx, const char* linkname, const char* displayname )
+void mxit_add_html_link( struct RXMsgData* mx, const char* replydata, gboolean isStructured, const char* displaytext )
{
#ifdef MXIT_LINK_CLICK
char retstr[256];
@@ -135,15 +136,24 @@ void mxit_add_html_link( struct RXMsgData* mx, const char* linkname, const char*
char link[256];
int len;
- len = g_snprintf( retstr, sizeof( retstr ), "%s|%s|%s|%s|%s", MXIT_LINK_KEY, purple_account_get_username( mx->session->acc ),
- purple_account_get_protocol_id( mx->session->acc ), mx->from, linkname );
+ /*
+ * The link content is encoded as follows:
+ * MXIT_LINK_KEY | ACCOUNT_USER | ACCOUNT_PROTO | REPLY_TO | REPLY_FORMAT | REPLY_DATA
+ */
+ len = g_snprintf( retstr, sizeof( retstr ), "%s|%s|%s|%s|%i|%s",
+ MXIT_LINK_KEY,
+ purple_account_get_username( mx->session->acc ),
+ purple_account_get_protocol_id( mx->session->acc ),
+ mx->from,
+ isStructured ? 1 : 0,
+ replydata );
retstr64 = purple_base64_encode( (const unsigned char*) retstr, len );
g_snprintf( link, sizeof( link ), "%s%s", MXIT_LINK_PREFIX, retstr64 );
g_free( retstr64 );
- g_string_append_printf( mx->msg, "<a href=\"%s\">%s</a>", link, displayname );
+ g_string_append_printf( mx->msg, "<a href=\"%s\">%s</a>", link, displaytext );
#else
- g_string_append_printf( mx->msg, "<b>%s</b>", linkname );
+ g_string_append_printf( mx->msg, "<b>%s</b>", replydata );
#endif
}
@@ -392,7 +402,9 @@ void mxit_show_message( struct RXMsgData* mx )
}
else {
/* insert img tag */
- g_snprintf( tag, sizeof( tag ), "<img id=\"%i\">", *img_id );
+ g_snprintf( tag, sizeof( tag ),
+ "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\">",
+ *img_id );
g_string_insert( mx->msg, start, tag );
}
@@ -619,7 +631,8 @@ static void emoticon_request( struct RXMsgData* mx, const char* id )
/* reference: "libpurple/util.h" */
url = g_strdup_printf( "%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver, MXIT_EMOTICON_SIZE, id, time( NULL ) );
- url_data = purple_util_fetch_url_request( url, TRUE, NULL, TRUE, NULL, FALSE, emoticon_returned, mx );
+ /* FIXME: This should be cancelled somewhere if not needed. */
+ url_data = purple_util_fetch_url( url, TRUE, NULL, TRUE, -1, emoticon_returned, mx );
g_free( url );
}
@@ -736,6 +749,7 @@ void mxit_parse_markup( struct RXMsgData* mx, char* message, int len, short msgt
gboolean tag_bold = FALSE;
gboolean tag_under = FALSE;
gboolean tag_italic = FALSE;
+ int font_size = 0;
#ifdef MXIT_DEBUG_MARKUP
purple_debug_info( MXIT_PLUGIN_ID, "Markup RX (original): '%s'\n", message );
@@ -824,7 +838,7 @@ void mxit_parse_markup( struct RXMsgData* mx, char* message, int len, short msgt
if ( ch ) {
/* end found */
*ch = '\0';
- mxit_add_html_link( mx, &message[i + 1], &message[i + 1] );
+ mxit_add_html_link( mx, &message[i + 1], FALSE, &message[i + 1] );
*ch = '$';
i += ( ch - &message[i + 1] ) + 1;
}
@@ -863,59 +877,54 @@ void mxit_parse_markup( struct RXMsgData* mx, char* message, int len, short msgt
}
break;
case '.' :
- if ( !( msgflags & CP_MSG_EMOTICON ) ) {
- g_string_append_c( mx->msg, message[i] );
- break;
- }
- else if ( i + 1 >= len ) {
+ if ( i + 1 >= len ) {
/* message too short */
g_string_append_c( mx->msg, '.' );
break;
}
- switch ( message[i+1] ) {
- case '+' :
- /* increment text size */
- g_string_append( mx->msg, "<font size=\"+1\">" );
- i++;
- break;
- case '-' :
- /* decrement text size */
- g_string_append( mx->msg, "<font size=\"-1\">" );
- i++;
- break;
- case '{' :
- /* custom emoticon */
- if ( i + 2 >= len ) {
- /* message too short */
- g_string_append_c( mx->msg, '.' );
- break;
- }
-
- parse_emoticon_str( &message[i+2], tmpstr1 );
- if ( tmpstr1[0] != '\0' ) {
- mx->got_img = TRUE;
-
- if ( g_hash_table_lookup( mx->session->iimages, tmpstr1 ) ) {
- /* emoticon found in the cache, so we do not have to request it from the WAPsite */
- }
- else {
- /* request emoticon from the WAPsite */
- mx->img_count++;
- emoticon_request( mx, tmpstr1 );
- }
-
- g_string_append_printf( mx->msg, MXIT_II_TAG"%s>", tmpstr1 );
- i += strlen( tmpstr1 ) + 2;
- }
- else
- g_string_append_c( mx->msg, '.' );
-
- break;
- default :
- g_string_append_c( mx->msg, '.' );
- break;
+ if ( ( msgflags & CP_MSG_EMOTICON ) && ( message[i+1] == '{' ) ) {
+ /* custom emoticon */
+ if ( i + 2 >= len ) {
+ /* message too short */
+ g_string_append_c( mx->msg, '.' );
+ break;
+ }
+
+ parse_emoticon_str( &message[i+2], tmpstr1 );
+ if ( tmpstr1[0] != '\0' ) {
+ mx->got_img = TRUE;
+
+ if ( g_hash_table_lookup( mx->session->iimages, tmpstr1 ) ) {
+ /* emoticon found in the cache, so we do not have to request it from the WAPsite */
+ }
+ else {
+ /* request emoticon from the WAPsite */
+ mx->img_count++;
+ emoticon_request( mx, tmpstr1 );
+ }
+
+ g_string_append_printf( mx->msg, MXIT_II_TAG"%s>", tmpstr1 );
+ i += strlen( tmpstr1 ) + 2;
+ }
+ else
+ g_string_append_c( mx->msg, '.' );
+ }
+ else if ( ( msgflags & CP_MSG_MARKUP ) && ( message[i+1] == '+' ) ) {
+ /* increment text size */
+ font_size++;
+ g_string_append_printf( mx->msg, "<font size=\"%+i\">", font_size );
+ i++;
}
+ else if ( ( msgflags & CP_MSG_MARKUP ) && ( message[i+1] == '-' ) ) {
+ /* decrement text size */
+ font_size--;
+ g_string_append_printf( mx->msg, "<font size=\"%+i\">", font_size );
+ i++;
+ }
+ else
+ g_string_append_c( mx->msg, '.' );
+
break;
case '\\' :
if ( i + 1 >= len ) {
@@ -1060,7 +1069,7 @@ char* mxit_convert_markup_tx( const char* message, int* msgtype )
* Font colour: <font color=#">...</font>
* Links: <a href="">...</a>
* Newline: <br>
- * Inline image: <IMG ID="">
+ * Inline image: <IMG SRC="">
* The following characters are also encoded:
* &amp; &quot; &lt; &gt;
*/
@@ -1127,11 +1136,11 @@ char* mxit_convert_markup_tx( const char* message, int* msgtype )
g_free( tag );
}
}
- else if ( purple_str_has_prefix( &message[i], "<IMG ID=" ) ) {
+ else if ( purple_str_has_prefix( &message[i], "<IMG SRC=" PURPLE_STORED_IMAGE_PROTOCOL) ) {
/* inline image */
int imgid;
- if ( sscanf( &message[i+9], "%i", &imgid ) ) {
+ if ( sscanf( &message[i+sizeof("<IMG SRC=" PURPLE_STORED_IMAGE_PROTOCOL)-1], "%i", &imgid ) ) {
inline_image_add( mx, imgid );
*msgtype = CP_MSGTYPE_COMMAND; /* inline image must be sent as a MXit command */
}