pidgin: 51d199ba: Add support for receiving handwritten (I...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jul 6 01:30:39 EDT 2009


-----------------------------------------------------------------
Revision: 51d199ba5dd8a81f6276f19421c8f7e0158dcb98
Ancestor: b1475c60325500d6977326c16d129edcdb365e77
Author: qulogic at pidgin.im
Date: 2009-07-06T04:37:06
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/51d199ba5dd8a81f6276f19421c8f7e0158dcb98

Modified files:
        ChangeLog libpurple/protocols/msn/msg.c
        libpurple/protocols/msn/msg.h libpurple/protocols/msn/msn.h
        libpurple/protocols/msn/slpcall.c
        libpurple/protocols/msn/switchboard.c
        libpurple/protocols/msn/switchboard.h

ChangeLog: 

Add support for receiving handwritten (Ink) messages from MSN buddies.
Based on patch from notak and galt, but using imgstore instead of a custom
smiley (like AIM DirectIM), and with better error checking.

References #393.

-------------- next part --------------
============================================================
--- ChangeLog	18df7f2a0d35be1c896f9f3d55eeaf22a73f98d8
+++ ChangeLog	0728d88a37ad36a95a04079b903ae859a63cba90
@@ -24,6 +24,7 @@ version 2.6.0 (??/??/2009):
 	  PURPLE_GNUTLS_DEBUG environment variable, which is an integer between
 	  0 and 9 (higher is more verbose). Higher values may reveal sensitive
 	  information.
+	* Add support for receiving handwritten (ink) messages on MSN.
 
 	Gadu-Gadu:
 	* Accounts can specify a server to which to connect.
============================================================
--- libpurple/protocols/msn/msg.c	7727a9894ac0920e52a895a77d29cf31785aa917
+++ libpurple/protocols/msn/msg.c	c54102f4e702ae77c16f2c6ab84820997f071ab0
@@ -1048,3 +1048,14 @@ msn_invite_msg(MsnCmdProc *cmdproc, MsnM
 	g_hash_table_destroy(body);
 }
 
+/* Only called from chats. Handwritten messages for IMs come as a SLP message */
+void
+msn_handwritten_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
+{
+	const char *body;
+	size_t body_len;
+
+	body = msn_message_get_bin_data(msg, &body_len);
+	msn_switchboard_show_ink(cmdproc->data, msg->remote_user, body);
+}
+
============================================================
--- libpurple/protocols/msn/msg.h	af6d453a733426d2a4e03d7de807a9c69c43c9f6
+++ libpurple/protocols/msn/msg.h	747294e6f8f742838a7961e78f98290ba598e694
@@ -345,4 +345,6 @@ void msn_datacast_msg(MsnCmdProc *cmdpro
 
 void msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg);
 
+void msn_handwritten_msg(MsnCmdProc *cmdproc, MsnMessage *msg);
+
 #endif /* _MSN_MSG_H_ */
============================================================
--- libpurple/protocols/msn/msn.h	3a35c43d1131b199a9f2c886f71cb60bc27c2201
+++ libpurple/protocols/msn/msn.h	6ae6504a3f8fc9aa2d7a090001c7ee5f58b34a44
@@ -138,7 +138,7 @@ typedef enum
 } MsnClientVerId;
 
 #define MSN_CLIENT_ID_VERSION      MSN_CLIENT_VER_7_0
-#define MSN_CLIENT_ID_CAPABILITIES MSN_CLIENT_CAP_PACKET
+#define MSN_CLIENT_ID_CAPABILITIES (MSN_CLIENT_CAP_PACKET|MSN_CLIENT_CAP_INK_GIF)
 
 #define MSN_CLIENT_ID \
 	((MSN_CLIENT_ID_VERSION    << 24) | \
============================================================
--- libpurple/protocols/msn/slpcall.c	86677b63a56656430882aa0e2ab01ebab1bfa75e
+++ libpurple/protocols/msn/slpcall.c	ab3ce844232f80ec3f8ccd00a1273458d0cbf30d
@@ -210,8 +210,51 @@ msn_slp_process_msg(MsnSlpLink *slplink,
 	{
 		char *body_str;
 
-		body_str = g_strndup((const char *)body, body_len);
-		slpcall = msn_slp_sip_recv(slplink, body_str);
+		if (slpmsg->session_id == 64)
+		{
+			/* This is for handwritten messages (Ink) */
+			GError *error;
+			glong items_read, items_written;
+
+			body_str = g_utf16_to_utf8((gunichar2 *)body, body_len / 2,
+			                           &items_read, &items_written, &error);
+			body_len -= items_read * 2 + 2;
+			body += items_read * 2 + 2;
+			if (body_str == NULL
+			 || body_len <= 0
+			 || strstr(body_str, "image/gif") == NULL)
+			{
+				if (error != NULL)
+					purple_debug_error("msn",
+					                   "Unable to convert Ink header from UTF-16 to UTF-8: %s\n",
+					                   error->message);
+				else
+					purple_debug_error("msn",
+					                   "Received Ink in unknown format\n");
+				g_free(body_str);
+				return NULL;
+			}
+			g_free(body_str);
+
+			body_str = g_utf16_to_utf8((gunichar2 *)body, body_len / 2,
+			                           &items_read, &items_written, &error);
+			if (!body_str)
+			{
+				purple_debug_error("msn",
+				                   "Unable to convert Ink body from UTF-16 to UTF-8: %s\n",
+				                   error->message);
+				return NULL;
+			}
+
+			msn_switchboard_show_ink(slpmsg->slplink->swboard,
+			                         slplink->remote_user,
+			                         body_str);
+		}
+		else
+		{
+			body_str = g_strndup((const char *)body, body_len);
+			slpcall = msn_slp_sip_recv(slplink, body_str);
+		}
 		g_free(body_str);
 	}
 	else if (slpmsg->flags == 0x20 ||
============================================================
--- libpurple/protocols/msn/switchboard.c	995d0025ca4f7e6d1eb4a607d676da5203bff542
+++ libpurple/protocols/msn/switchboard.c	77420c03da4390269d556a13cc9df0904c996eb4
@@ -905,6 +905,47 @@ clientcaps_msg(MsnCmdProc *cmdproc, MsnM
 #endif
 }
 
+void
+msn_switchboard_show_ink(MsnSwitchBoard *swboard, const char *passport,
+                         const char *data)
+{
+	PurpleConnection *gc;
+	guchar *image_data;
+	size_t image_len;
+	int imgid;
+	char *image_msg;
+
+	if (!purple_str_has_prefix(data, "base64:"))
+	{
+		purple_debug_error("msn", "Ignoring Ink not in Base64 format.\n");
+		return;
+	}
+
+	gc = purple_account_get_connection(swboard->session->account);
+
+	data += sizeof("base64:") - 1;
+	image_data = purple_base64_decode(data, &image_len);
+	if (!image_data || !image_len) 
+	{
+		purple_debug_error("msn", "Unable to decode Ink from Base64 format.\n");
+		return;
+	}
+
+	imgid = purple_imgstore_add_with_id(image_data, image_len, NULL);
+	image_msg = g_strdup_printf("<IMG ID=%d/>", imgid);
+
+	if (swboard->current_users > 1 ||
+		((swboard->conv != NULL) &&
+		 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
+		serv_got_chat_in(gc, swboard->chat_id, passport, 0, image_msg,
+						 time(NULL));
+	else
+		serv_got_im(gc, passport, image_msg, 0, time(NULL));
+
+	purple_imgstore_unref_by_id(imgid);
+	g_free(image_msg);
+}
+
 /**************************************************************************
  * Connect stuff
  **************************************************************************/
@@ -1239,6 +1280,8 @@ msn_switchboard_init(void)
 						   msn_datacast_msg);
 	msn_table_add_msg_type(cbs_table, "text/x-msmsgsinvite",
 						   msn_invite_msg);
+	msn_table_add_msg_type(cbs_table, "image/gif",
+						   msn_handwritten_msg);
 }
 
 void
============================================================
--- libpurple/protocols/msn/switchboard.h	b8994e4d60738264aa0368d513a1dac1fa9352a5
+++ libpurple/protocols/msn/switchboard.h	3c7c9cb35758d19bce0b7ea8b859a9dff2640a50
@@ -280,4 +280,14 @@ void msn_invite_msg(MsnCmdProc *cmdproc,
  */
 void msn_invite_msg(MsnCmdProc *cmdproc, MsnMessage *msg);
 
+/**
+ * Shows an ink message from this switchboard.
+ *
+ * @param swboard  The switchboard.
+ * @param passport The user that sent the ink.
+ * @param data     The ink data.
+ */
+void msn_switchboard_show_ink(MsnSwitchBoard *swboard, const char *passport,
+                              const char *data);
+
 #endif /* _MSN_SWITCHBOARD_H_ */


More information about the Commits mailing list