Mercurial > pidgin.yaz
changeset 22447:9b154f484d64
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.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 11 Mar 2008 21:41:53 +0000 |
parents | 2ebc7c497382 |
children | 4baa8b7ad5b4 |
files | libpurple/ntlm.c pidgin/gtkimhtml.c |
diffstat | 2 files changed, 37 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/ntlm.c Tue Mar 11 16:20:54 2008 +0000 +++ b/libpurple/ntlm.c Tue Mar 11 21:41:53 2008 +0000 @@ -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 @@ 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 @@ tmp += 0x18; /* NTLM */ - /* Convert the password to UCS-2LE */ + /* Convert the password to UTF-16LE */ lennt = strlen(passw); for (idx = 0; idx < lennt; idx++) {
--- a/pidgin/gtkimhtml.c Tue Mar 11 16:20:54 2008 +0000 +++ b/pidgin/gtkimhtml.c Tue Mar 11 21:41:53 2008 +0000 @@ -852,15 +852,15 @@ 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 @@ len -= 2; break; default: - fromcode = "UCS-2"; + fromcode = "UTF-16"; break; } @@ -927,7 +927,7 @@ 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 @@ 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 @@ * 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)) {