pidgin.vv.msn.webcam: f58d536d: Using g_utf8_to_utf16 (or the reverse) i...

qulogic at pidgin.im qulogic at pidgin.im
Sat Feb 6 01:28:54 EST 2010


-----------------------------------------------------------------
Revision: f58d536d352f197d779da5a6ce4d253f9275c17e
Ancestor: 5ffb89b013fe991e546bd88bfa764717416bb4cd
Author: qulogic at pidgin.im
Date: 2010-01-30T21:38:53
Branch: im.pidgin.pidgin.vv.msn.webcam
URL: http://d.pidgin.im/viewmtn/revision/info/f58d536d352f197d779da5a6ce4d253f9275c17e

Modified files:
        libpurple/protocols/msn/webcam.c

ChangeLog: 

Using g_utf8_to_utf16 (or the reverse) is not big-endian safe.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/webcam.c	ce5a585a3998500ffd8859bcbb4f847fafed7faf
+++ libpurple/protocols/msn/webcam.c	a616f0a741c06d3601155b72b3e8304a40279d7d
@@ -115,9 +115,9 @@ msn_webcam_candidates_prepared_cb(Purple
 	MsnSlpCall *slpcall;
 	GList *candidates;
 	const gchar *context = "{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8}";
-	gunichar2 *utf16_context;
+	gchar *utf16_context;
 	gchar *base64_context;
-	glong written;
+	gsize written;
 
 	purple_debug_info("msn", "candidates prepared - sid: %s name: %s\n", sid, name);
 
@@ -155,9 +155,9 @@ msn_webcam_candidates_prepared_cb(Purple
 	}
 	g_list_free(candidates);
 
-	utf16_context = g_utf8_to_utf16(context, -1, NULL, &written, NULL);
-	base64_context = purple_base64_encode((guchar*)utf16_context,
-			written*sizeof(gunichar2));
+	utf16_context = g_convert(context, -1, "UTF-16LE", "UTF-8",
+	                          NULL, &written, NULL);
+	base64_context = purple_base64_encode((guchar *)utf16_context, written + 2);
 	g_free(utf16_context);
 	if (purple_media_get_session_type(media, sid) == PURPLE_MEDIA_SEND_VIDEO)
 		msn_slpcall_invite(slpcall, MSN_CAM_GUID, 4, base64_context);
@@ -242,10 +242,10 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	xmlnode *node, *child, *tcp;
 	gchar *session_id = NULL, *rid = NULL, *port = NULL, *xml;
 	const gchar *public_ip = NULL;
-	gunichar2 *xmlutf;
+	gchar *xmlutf;
 	guint count = 1;
 
-	glong written;
+	gsize written;
 	gchar *body;
 	guint32 *len;
 	gboolean is_producer = FALSE;
@@ -326,14 +326,15 @@ msn_webcam_send_xml(MsnSlpLink *slplink,
 	g_free(port);
 	g_free(rid);
 
-	xmlutf = g_utf8_to_utf16(xml, strlen(xml) + 1, NULL, &written, NULL);
+	xmlutf = g_convert(xml, -1, "UTF-16LE", "UTF-8",
+	                   NULL, &written, NULL);
 	g_free(xml);
-	written *= sizeof(gunichar2);
+	written += 2;
 
 	body = g_malloc(written + 10);
 	memcpy(body, "\x80\x00\x00\x00\x08\x00", 6);
 	len = (guint32*)(body+6);
-	*len = GUINT32_TO_LE((guint32)written);
+	*len = GUINT32_TO_LE(written);
 	memcpy(body + 10, xmlutf, written);
 	g_free(xmlutf);
 
@@ -349,9 +350,10 @@ msn_webcam_recv_xml(MsnSlpLink *slplink,
 msn_webcam_recv_xml(MsnSlpLink *slplink, MsnSlpMessage *slpmsg, const guchar *body, gsize body_len)
 {
 	MsnSlpMessage *slpmsg2;
-	glong bytes_written;
-	gchar *xml = g_utf16_to_utf8((const gunichar2*)body + 5,
-			body_len - 5, NULL, &bytes_written, NULL);
+	gsize bytes_written;
+	gchar *xml = g_convert((const gchar *)body + 5, body_len - 5,
+	                       "UTF-8", "UTF-16LE",
+	                       NULL, &bytes_written, NULL);
 	gchar *body_str;
 	gboolean is_producer = FALSE;
 


More information about the Commits mailing list