changeset 4458:a46c57f2d58b

[gaim-migrate @ 4733] (20:45:09) Trogdor: http://web.ics.purdue.edu/~eblanton/gaim/gaim-cvs-oscar-ssi-conv.diff (20:45:12) Trogdor: commit please (20:45:22) LSchiere: commit log? (20:45:48) Trogdor: Adds best-effort charset conversion to Oscar SSI aliases and group names. (20:45:55) Trogdor: oh (20:46:19) Trogdor: Also adds a gaim global function gaim_try_conv_to_utf8 () for attempting several logical encodings on a given string. (20:46:43) Trogdor: (which replaces the aptly named whatever_to_utf8) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 29 Jan 2003 01:46:44 +0000
parents 16e0c6826f23
children 23ff3690d291
files src/gaim.h src/list.c src/protocols/oscar/oscar.c src/util.c
diffstat 4 files changed, 40 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/gaim.h	Wed Jan 29 01:20:20 2003 +0000
+++ b/src/gaim.h	Wed Jan 29 01:46:44 2003 +0000
@@ -472,8 +472,11 @@
 extern void strip_linefeed(char *);
 extern time_t get_time(int, int, int, int, int, int) G_GNUC_CONST;
 extern FILE *gaim_mkstemp(gchar **);
-extern char *convert_string(char *, const char *, const char *);
 extern const char *handle_uri(char *);
+/* This guy does its best to convert a string to UTF-8 from an unknown
+ * encoding by checking the locale and trying some sane defaults ...
+ * if everything fails it returns NULL. */
+char *gaim_try_conv_to_utf8(const char *str);
 
 /* Functions in log.h */
 extern FILE *open_log_file (const char *, int);
--- a/src/list.c	Wed Jan 29 01:20:20 2003 +0000
+++ b/src/list.c	Wed Jan 29 01:46:44 2003 +0000
@@ -41,11 +41,6 @@
 
 #define PATHSIZE 1024
 
-/* This guy does its best to convert a string to UTF-8 from an unknown
- * encoding by checking the locale and trying some sane defaults ...
- * if everything fails it returns NULL. */
-static char *whatever_to_utf8(const char *str);
-
 void remove_buddy(struct buddy *rem_b)
 {
 	if(rem_b->user->gc) {
@@ -263,7 +258,7 @@
 				break;
 			if (*c == 'g') {
 				char *utf8 = NULL;
-				utf8 = whatever_to_utf8(c + 2);
+				utf8 = gaim_try_conv_to_utf8(c + 2);
 				if (utf8 == NULL) {
 					g_strlcpy(current, _("Invalid Groupname"), sizeof(current));
 				} else {
@@ -282,7 +277,7 @@
 
 				g_strlcpy(nm, c + 2, sizeof(nm));
 				if (a) {
-					utf8 = whatever_to_utf8(a);
+					utf8 = gaim_try_conv_to_utf8(a);
 					if (utf8 == NULL) {
 						debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm);
 					}
@@ -1210,29 +1205,3 @@
 		return NULL;
 	return g_strdup(g_hash_table_lookup(b->settings, key));
 }
-
-static char *whatever_to_utf8(const char *str)
-{
-	int converted;
-	char *utf8;
-
-	if (g_utf8_validate(str, -1, NULL)) {
-		return g_strdup(str);
-	}
-
-	utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
-	if (utf8 && converted == strlen (str)) {
-		return(utf8);
-	} else if (utf8) {
-		g_free(utf8);
-	}
-
-	utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
-	if (utf8 && converted == strlen (str)) {
-		return(utf8);
-	} else if (utf8) {
-		g_free(utf8);
-	}
-
-	return(NULL);
-}
--- a/src/protocols/oscar/oscar.c	Wed Jan 29 01:20:20 2003 +0000
+++ b/src/protocols/oscar/oscar.c	Wed Jan 29 01:46:44 2003 +0000
@@ -4147,18 +4147,23 @@
 			case 0x0000: { /* Buddy */
 				if (curitem->name) {
 					char *gname = aim_ssi_itemlist_findparentname(sess->ssi.local, curitem->name);
+					char *gname_utf8 = gaim_try_conv_to_utf8(gname);
 					char *alias = aim_ssi_getalias(sess->ssi.local, gname, curitem->name);
+					char *alias_utf8 = gaim_try_conv_to_utf8(alias);
 					struct buddy *buddy = find_buddy(gc->user, curitem->name);
+					/* Should gname be freed here? -- elb */
+					free(alias);
 					if (buddy) {
 						/* Get server stored alias */
-						if (alias)
-							strcpy(buddy->alias, alias);
+						if (alias_utf8)
+							strcpy(buddy->alias, alias_utf8);
 					} else {
 						debug_printf("ssi: adding buddy %s to group %s to local list\n", curitem->name, gname);
-						add_buddy(gc->user, (gname ? gname : "orphans"), curitem->name, alias);
+						add_buddy(gc->user, (gname_utf8 ? gname_utf8 : "orphans"), curitem->name, alias_utf8);
 						tmp++;
 					}
-					free(alias);
+					free(gname_utf8);
+					free(alias_utf8);
 				}
 			} break;
 
--- a/src/util.c	Wed Jan 29 01:20:20 2003 +0000
+++ b/src/util.c	Wed Jan 29 01:46:44 2003 +0000
@@ -1279,7 +1279,32 @@
 	return menuitem;
 }
 
+char *gaim_try_conv_to_utf8(const char *str)
+{
+	int converted;
+	char *utf8;
 
+	if (str == NULL) {
+		return NULL;
+	}
+
+	if (g_utf8_validate(str, -1, NULL)) {
+		return g_strdup(str);
+	}
 
+	utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
+	if (utf8 && converted == strlen (str)) {
+		return(utf8);
+	} else if (utf8) {
+		g_free(utf8);
+	}
 
+	utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
+	if (utf8 && converted == strlen (str)) {
+		return(utf8);
+	} else if (utf8) {
+		g_free(utf8);
+	}
 
+	return(NULL);
+}