pidgin: 1ba8fbd2: Further changes to use UTF-16 instead of...

datallah at pidgin.im datallah at pidgin.im
Tue Mar 11 17:45:48 EDT 2008


-----------------------------------------------------------------
Revision: 1ba8fbd2ac54a6b25df759681a854ccc43e6abff
Ancestor: f606c82f64f5626841bc52a6eb7649064614964e
Author: datallah at pidgin.im
Date: 2008-03-11T21:41:53
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1ba8fbd2ac54a6b25df759681a854ccc43e6abff

Modified files:
        libpurple/ntlm.c pidgin/gtkimhtml.c

ChangeLog: 

Further changes to use UTF-16 instead of UCS-2.  Also, fix #5167 by making sure that the encoding conversion worked before using the result.

-------------- next part --------------
============================================================
--- libpurple/ntlm.c	7b0d79a7fc99288eb355a8c227f14f1fc9b6f7ea
+++ libpurple/ntlm.c	46f675b7f1e52a4a2ee35579770a6be9769533c6
@@ -31,6 +31,7 @@
 #include "util.h"
 #include "ntlm.h"
 #include "cipher.h"
+#include "debug.h"
 #include <string.h>
 
 #define NTLM_NEGOTIATE_NTLM2_KEY 0x00080000
@@ -291,20 +292,32 @@ purple_ntlm_gen_type3(const gchar *usern
 
 	tmp = (char *)tmsg + sizeof(struct type3_message);
 
-	ucs2le = g_convert(domain, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
-	memcpy(tmp, ucs2le, domainlen);
-	g_free(ucs2le);
-	tmp += domainlen;
+	ucs2le = g_convert(domain, -1, "UTF-16LE", "UTF-8", NULL, NULL, NULL);
+	if (ucs2le != NULL) {
+		memcpy(tmp, ucs2le, domainlen);
+		g_free(ucs2le);
+		tmp += domainlen;
+	} else {
+		purple_debug_info("ntlm", "Unable to encode domain in UTF-16LE.\n");
+	}
 
-	ucs2le = g_convert(username, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
-	memcpy(tmp, ucs2le, usernamelen);
-	g_free(ucs2le);
-	tmp += usernamelen;
+	ucs2le = g_convert(username, -1, "UTF-16LE", "UTF-8", NULL, NULL, NULL);
+	if (ucs2le != NULL) {
+		memcpy(tmp, ucs2le, usernamelen);
+		g_free(ucs2le);
+		tmp += usernamelen;
+	} else {
+		purple_debug_info("ntlm", "Unable to encode username in UTF-16LE.\n");
+	}
 
-	ucs2le = g_convert(hostname, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
-	memcpy(tmp, ucs2le, hostnamelen);
-	g_free(ucs2le);
-	tmp += hostnamelen;
+	ucs2le = g_convert(hostname, -1, "UTF-16LE", "UTF-8", NULL, NULL, NULL);
+	if (ucs2le != NULL) {
+		memcpy(tmp, ucs2le, hostnamelen);
+		g_free(ucs2le);
+		tmp += hostnamelen;
+	} else {
+		purple_debug_info("ntlm", "Unable to encode hostname in UTF-16LE.\n");
+	}
 
 	/* LM */
 	if (passwlen > 14)
@@ -327,7 +340,7 @@ purple_ntlm_gen_type3(const gchar *usern
 	tmp += 0x18;
 
 	/* NTLM */
-	/* Convert the password to UCS-2LE */
+	/* Convert the password to UTF-16LE */
 	lennt = strlen(passw);
 	for (idx = 0; idx < lennt; idx++)
 	{
============================================================
--- pidgin/gtkimhtml.c	053c9ffb83e27190c516da0b71028eb6f033c8a4
+++ pidgin/gtkimhtml.c	435f359601c21c5dff292ed9fe4d9649a9ee8a21
@@ -852,15 +852,15 @@ ucs2_order(gboolean swap)
 	be = swap ? be : !be;
 
 	if (be)
-		return "UCS-2BE";
+		return "UTF-16BE";
 	else
-		return "UCS-2LE";
+		return "UTF-16LE";
 
 }
 
-/* Convert from UCS-2 to UTF-8, stripping the BOM if one is present.*/
+/* Convert from UTF-16LE to UTF-8, stripping the BOM if one is present.*/
 static gchar *
-ucs2_to_utf8_with_bom_check(gchar *data, guint len) {
+utf16_to_utf8_with_bom_check(gchar *data, guint len) {
 	char *fromcode = NULL;
 	GError *error = NULL;
 	guint16 c;
@@ -883,7 +883,7 @@ ucs2_to_utf8_with_bom_check(gchar *data,
 		len -= 2;
 		break;
 	default:
-		fromcode = "UCS-2";
+		fromcode = "UTF-16";
 		break;
 	}
 
@@ -927,7 +927,7 @@ static void gtk_imhtml_clipboard_get(Gtk
 		str = g_string_append_unichar(str, 0xfeff);
 		str = g_string_append(str, text);
 		str = g_string_append_unichar(str, 0x0000);
-		selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL);
+		selection = g_convert(str->str, str->len, "UTF-16", "UTF-8", NULL, &len, NULL);
 		gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
 		g_string_free(str, TRUE);
 #else
@@ -1082,12 +1082,12 @@ static void paste_received_cb (GtkClipbo
 
 	if (selection_data->length >= 2 &&
 		(*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
-		/* This is UCS-2 */
-		char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length);
+		/* This is UTF-16 */
+		char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length);
 		g_free(text);
 		text = utf8;
 		if (!text) {
-			purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n");
+			purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n");
 			return;
 		}
 	}
@@ -1784,10 +1784,10 @@ gtk_imhtml_link_drag_rcv_cb(GtkWidget *w
 			 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html
 			 */
 			if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) {
-				utf8 = ucs2_to_utf8_with_bom_check(text, sd->length);
+				utf8 = utf16_to_utf8_with_bom_check(text, sd->length);
 
 				if (!utf8) {
-					purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n");
+					purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n");
 					return;
 				}
 			} else if (!(*text) || !g_utf8_validate(text, -1, NULL)) {


More information about the Commits mailing list