changeset 27791:ab1185e87ca5

- more normalization for window title - apply botch_utf() to outgoing alias name in msn14 protocol - now botch_utf() and sanitize_utf() accept -1 and NULL as the length of source string and the pointer to length of converted string respectively. - now botch_ucs() and botch_utf() skip conversion if _WIN32 is defined.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 13 Mar 2008 14:50:21 +0000
parents 1aab44eab011
children 79aa23cdf393
files libpurple/protocols/msn/msn.c libpurple/server.c libpurple/util.c
diffstat 3 files changed, 55 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Wed Mar 12 19:31:01 2008 +0000
+++ b/libpurple/protocols/msn/msn.c	Thu Mar 13 14:50:21 2008 +0000
@@ -154,13 +154,18 @@
 	MsnSession *session;
 	PurpleAccount *account;
 	const char *alias;
+	gchar *tmp;
+	gsize dummy;
 
 	session = gc->proto_data;
 	cmdproc = session->notification->cmdproc;
 	account = purple_connection_get_account(gc);
 
-	if(entry && strlen(entry))
-		alias = purple_url_encode(entry);
+	if(entry && strlen(entry)) {
+		tmp = botch_utf(entry, strlen(entry), &dummy);
+		alias = purple_url_encode(tmp);
+		g_free(tmp);
+	}
 	else
 		alias = "";
 
--- a/libpurple/server.c	Wed Mar 12 19:31:01 2008 +0000
+++ b/libpurple/server.c	Thu Mar 13 14:50:21 2008 +0000
@@ -236,12 +236,14 @@
 }
 
 void
-serv_got_alias(PurpleConnection *gc, const char *who, const char *alias)
+serv_got_alias(PurpleConnection *gc, const char *who, const char *alias_src)
 {
 	PurpleAccount *account;
 	GSList *buddies;
 	PurpleBuddy *b;
 	PurpleConversation *conv;
+	gsize dummy;
+	gchar *alias = sanitize_utf(alias_src, strlen(alias_src), &dummy);
 
 	account = purple_connection_get_account(gc);
 	buddies = purple_find_buddies(account, who);
@@ -272,14 +274,17 @@
 			g_free(tmp);
 		}
 	}
+	g_free(alias);
 }
 
 void
-purple_serv_got_private_alias(PurpleConnection *gc, const char *who, const char *alias)
+purple_serv_got_private_alias(PurpleConnection *gc, const char *who, const char *alias_src)
 {
 	PurpleAccount *account = NULL;
 	GSList *buddies = NULL;
 	PurpleBuddy *b = NULL;
+	gsize dummy;
+	gchar *alias = sanitize_utf(alias_src, strlen(alias_src), &dummy);
 
 	account = purple_connection_get_account(gc);
 	buddies = purple_find_buddies(account, who);
@@ -294,6 +299,7 @@
 
 		purple_blist_alias_buddy(b, alias);
 	}
+	g_free(alias);
 }
 
 
--- a/libpurple/util.c	Wed Mar 12 19:31:01 2008 +0000
+++ b/libpurple/util.c	Thu Mar 13 14:50:21 2008 +0000
@@ -4709,6 +4709,13 @@
 	return g_string_free(string, FALSE);
 }
 
+
+#ifdef _WIN32
+void botch_ucs(gchar *ucs_src, gsize len)
+{
+	/* no operation */
+}
+#else
 void botch_ucs(gchar *ucs_src, gsize len)
 {
 	gint i;
@@ -4757,6 +4764,7 @@
  	}
 
 }
+#endif
 
 #ifdef _WIN32
 void sanitize_ucs(gchar *ucs, gsize len)
@@ -4815,9 +4823,12 @@
 gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen)
 {
 	g_return_val_if_fail(msg != NULL, NULL);
+	if(len == -1)
+		len = strlen(msg);
 	g_return_val_if_fail(len > 0, NULL);
 
-	*newlen = len;
+	if(newlen)
+		*newlen = len;
 
 	return g_strndup(msg, len);
 }
@@ -4829,6 +4840,8 @@
 	guchar *utf;
 
 	g_return_val_if_fail(msg != NULL, NULL);
+	if(len == -1)
+		len = strlen(msg);
 	g_return_val_if_fail(len > 0, NULL);
 
 	utf = (guchar *)g_strndup(msg, len);
@@ -4864,25 +4877,25 @@
 				break;
 			case 0xbf:
 				switch(*(utf+i+2)){
-			       case 0xa0:// ¢
+			       case 0xa0:	// ¢
 				       *(utf+i) = 0xc2;
 				       *(utf+i+1) = 0xa2;
 				       memmove(utf+i+2, utf+i+3,
-					       len-i-3); //1byte詰める
+					       len-i-3); //shorten by 1byte
 				       bytes--;
 				       break;
 			       case 0xa1:	// £
 				       *(utf+i) = 0xc2;
 				       *(utf+i+1) = 0xa3;
 				       memmove(utf+i+2, utf+i+3,
-					       len-i-3); //1byte詰める
+					       len-i-3); //shorten by 1byte
 				       bytes--;
 				       break;
 			       case 0xa2:	// ¬
 				       *(utf+i) = 0xc2;
 				       *(utf+i+1) = 0xac;
 				       memmove(utf+i+2, utf+i+3,
-					       len-i-3); //1byte詰める
+					       len-i-3); //shorten by 1byte
 				       bytes--;
 				       break;
 			       }
@@ -4892,20 +4905,36 @@
 		}
 	}
 	*(utf+bytes)= 0x00; //terminate
-	*newlen = bytes;
+	if(newlen)
+		*newlen = bytes;
 	return (gchar *)utf;
 }
 #endif
 
-
+#ifdef _WIN32
+gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen)
+{
+	g_return_val_if_fail(msg != NULL, NULL);
+	if(len == -1)
+		len = strlen(msg);
+	g_return_val_if_fail(len > 0, NULL);
+
+	if(newlen)
+		*newlen = len;
+
+	return g_strndup(msg, len);
+}
+#else
 gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen)
 {
  	int i,bytes;
 	unsigned char *utf;
 
 	g_return_val_if_fail(msg != NULL, NULL);
+	if(len == -1)
+		len = strlen(msg);
 	g_return_val_if_fail(len > 0, NULL);
-
+	
 	bytes = len;
 
 	utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */
@@ -4968,6 +4997,8 @@
  		} //switch
  	}
 	*(utf+bytes) = 0x00; //terminate
-	*newlen = bytes;
+	if(newlen)
+		*newlen = bytes;
 	return (gchar *)utf;
 }
+#endif