/pidgin/main: df92c3d93904: From now on, prpls must specify imag...

Elliott Sales de Andrade qulogic at pidgin.im
Fri Jun 15 03:12:26 EDT 2012


Changeset: df92c3d93904d2bd301169af5a1b263d71f9fb46
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2012-06-15 00:59 -0400
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/df92c3d93904

Description:

>From now on, prpls must specify images using SRC instead of ID.

This only fixes libpurple, the UI side doesn't follow this change
just yet.

diffstat:

 libpurple/ft.c                            |   3 ++-
 libpurple/imgstore.h                      |   2 ++
 libpurple/protocols/jabber/buddy.c        |   3 ++-
 libpurple/protocols/msn/switchboard.c     |   3 ++-
 libpurple/protocols/mxit/formcmds.c       |   6 +++---
 libpurple/protocols/mxit/markup.c         |  10 ++++++----
 libpurple/protocols/mxit/profile.c        |   3 ++-
 libpurple/protocols/mxit/splashscreen.c   |   3 ++-
 libpurple/protocols/oscar/odc.c           |   4 +++-
 libpurple/protocols/oscar/oscar.c         |   6 ++++--
 libpurple/protocols/sametime/sametime.c   |   2 +-
 libpurple/protocols/silc/ops.c            |   4 +++-
 libpurple/protocols/yahoo/yahoo_profile.c |   3 ++-
 13 files changed, 34 insertions(+), 18 deletions(-)

diffs (208 lines):

diff --git a/libpurple/ft.c b/libpurple/ft.c
--- a/libpurple/ft.c
+++ b/libpurple/ft.c
@@ -306,7 +306,8 @@
 		int id = purple_imgstore_add_with_id(data, size, NULL);
 
 		message_with_img =
-			g_strdup_printf("<img id='%d'> %s", id, escaped);
+			g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'> %s",
+			                id, escaped);
 		purple_conversation_write(conv, NULL, message_with_img, flags,
 			time(NULL));
 		purple_imgstore_unref_by_id(id);
diff --git a/libpurple/imgstore.h b/libpurple/imgstore.h
--- a/libpurple/imgstore.h
+++ b/libpurple/imgstore.h
@@ -29,6 +29,8 @@
 
 #include <glib.h>
 
+#define PURPLE_STORED_IMAGE_PROTOCOL "purple-image:"
+
 /** A reference-counted immutable wrapper around an image's data and its
  *  filename.
  */
diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -1204,7 +1204,8 @@
 						char *hash;
 
 						jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add_with_id(g_memdup(data, size), size, "logo.png")));
-						img_text = g_strdup_printf("<img id='%d'>", GPOINTER_TO_INT(jbi->vcard_imgids->data));
+						img_text = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
+						                           GPOINTER_TO_INT(jbi->vcard_imgids->data));
 
 						purple_notify_user_info_add_pair_html(user_info, (photo ? _("Photo") : _("Logo")), img_text);
 
diff --git a/libpurple/protocols/msn/switchboard.c b/libpurple/protocols/msn/switchboard.c
--- a/libpurple/protocols/msn/switchboard.c
+++ b/libpurple/protocols/msn/switchboard.c
@@ -828,7 +828,8 @@
 	}
 
 	imgid = purple_imgstore_add_with_id(image_data, image_len, NULL);
-	image_msg = g_strdup_printf("<IMG ID='%d'>", imgid);
+	image_msg = g_strdup_printf("<IMG SRC='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
+	                            imgid);
 
 	if (swboard->current_users > 1 ||
 		((swboard->conv != NULL) &&
diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -327,7 +327,6 @@
 	const char*	img;
 	const char*	reply;
 	guchar*		rawimg;
-	char		link[256];
 	gsize		rawimglen;
 	int			imgid;
 
@@ -336,8 +335,9 @@
 		rawimg = purple_base64_decode(img, &rawimglen);
 		//purple_util_write_data_to_file_absolute("/tmp/mxitinline.png", (char*) rawimg, rawimglen);
 		imgid = purple_imgstore_add_with_id(rawimg, rawimglen, NULL);
-		g_snprintf(link, sizeof(link), "<img id=\"%i\">", imgid);
-		g_string_append_printf(msg, "%s", link);
+		g_string_append_printf(msg,
+		                       "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\">",
+		                       imgid);
 		mx->flags |= PURPLE_MESSAGE_IMAGES;
 	}
 	else {
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -403,7 +403,9 @@
 			}
 			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 );
 			}
 		}
@@ -1066,7 +1068,7 @@
 	 *   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:
 	 *   &  "  <  >
 	 */
@@ -1133,11 +1135,11 @@
 						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 */
 					}
diff --git a/libpurple/protocols/mxit/profile.c b/libpurple/protocols/mxit/profile.c
--- a/libpurple/protocols/mxit/profile.c
+++ b/libpurple/protocols/mxit/profile.c
@@ -233,7 +233,8 @@
 			if ( contact->imgid ) {
 				/* this invite has a avatar */
 				char* img_text;
-				img_text = g_strdup_printf( "<img id='%d'>", contact->imgid );
+				img_text = g_strdup_printf( "<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
+				                            contact->imgid );
 				purple_notify_user_info_add_pair_html( info, _( "Photo" ), img_text );
 				g_free(img_text);
 			}
diff --git a/libpurple/protocols/mxit/splashscreen.c b/libpurple/protocols/mxit/splashscreen.c
--- a/libpurple/protocols/mxit/splashscreen.c
+++ b/libpurple/protocols/mxit/splashscreen.c
@@ -187,7 +187,8 @@
 		imgid = purple_imgstore_add_with_id(g_memdup(imgdata, imglen), imglen, NULL);
 
 		/* Generate and display message */
-		g_snprintf(buf, sizeof(buf), "<img id=\"%d\">", imgid);
+		g_snprintf(buf, sizeof(buf),
+		           "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\">", imgid);
 
 		/* Open a request-type popup to display the image */
 		{
diff --git a/libpurple/protocols/oscar/odc.c b/libpurple/protocols/oscar/odc.c
--- a/libpurple/protocols/oscar/odc.c
+++ b/libpurple/protocols/oscar/odc.c
@@ -376,7 +376,9 @@
 		if (imgid != 0)
 		{
 			/* Write the new image tag */
-			g_string_append_printf(newmsg, "<IMG ID=\"%d\">", imgid);
+			g_string_append_printf(newmsg,
+			                       "<IMG SRC=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\">",
+			                       imgid);
 		}
 
 		/* Continue from the end of the tag */
diff --git a/libpurple/protocols/oscar/oscar.c b/libpurple/protocols/oscar/oscar.c
--- a/libpurple/protocols/oscar/oscar.c
+++ b/libpurple/protocols/oscar/oscar.c
@@ -3186,10 +3186,12 @@
 			g_string_append_len(msg, last, start - last);
 		}
 
-		id = g_datalist_get_data(&attribs, "id");
+		id = g_datalist_get_data(&attribs, "src");
 
 		/* ... if it refers to a valid purple image ... */
-		if (id && (image = purple_imgstore_find_by_id(atoi(id)))) {
+		if (id
+		 && strlen(id) > (sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1)
+		 && (image = purple_imgstore_find_by_id(atoi(id + sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1)))) {
 			/* ... append the message from start to the tag ... */
 			unsigned long size = purple_imgstore_get_size(image);
 			const char *filename = purple_imgstore_get_filename(image);
diff --git a/libpurple/protocols/sametime/sametime.c b/libpurple/protocols/sametime/sametime.c
--- a/libpurple/protocols/sametime/sametime.c
+++ b/libpurple/protocols/sametime/sametime.c
@@ -2833,7 +2833,7 @@
 	if(align) g_string_append_printf(atstr, " align=\"%s\"", align);
 	if(border) g_string_append_printf(atstr, " border=\"%s\"", border);
 
-	mov = g_snprintf(start, len, "<img%s id=\"%i\"", atstr->str, img);
+	mov = g_snprintf(start, len, "<img%s src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\"", atstr->str, img);
 	while(mov < len) start[mov++] = ' ';
 
 	g_string_free(atstr, TRUE);
diff --git a/libpurple/protocols/silc/ops.c b/libpurple/protocols/silc/ops.c
--- a/libpurple/protocols/silc/ops.c
+++ b/libpurple/protocols/silc/ops.c
@@ -210,7 +210,9 @@
 		imgid = purple_imgstore_add_with_id(g_memdup(data, data_len), data_len, "");
 		if (imgid) {
 			cflags |= PURPLE_MESSAGE_IMAGES | PURPLE_MESSAGE_RECV;
-			g_snprintf(tmp, sizeof(tmp), "<IMG ID=\"%d\">", imgid);
+			g_snprintf(tmp, sizeof(tmp),
+			           "<IMG SRC=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\">",
+			           imgid);
 
 			if (channel)
 				serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)),
diff --git a/libpurple/protocols/yahoo/yahoo_profile.c b/libpurple/protocols/yahoo/yahoo_profile.c
--- a/libpurple/protocols/yahoo/yahoo_profile.c
+++ b/libpurple/protocols/yahoo/yahoo_profile.c
@@ -1047,7 +1047,8 @@
 					" bytes\n", photo_url_text, len);
 			id = purple_imgstore_add_with_id(g_memdup(url_text, len), len, NULL);
 
-			tmp = g_strdup_printf("<img id=\"%d\"><br>", id);
+			tmp = g_strdup_printf("<img id=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\"><br>",
+			                      id);
 			purple_notify_user_info_add_pair_html(user_info, NULL, tmp);
 			g_free(tmp);
 		}



More information about the Commits mailing list