changeset 27773:0f3a131d23da

- import nosuke's hash 244 patch and others to yahoo plugin - do not perform any conversion in sanitize_* if _WIN32 defined - suppress warning as much as possible - fix indentation
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 29 Feb 2008 17:56:13 +0000
parents 839cc551cad9
children 5f2dc6845abe
files libpurple/protocols/irc/parse.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/message.c libpurple/protocols/jabber/si.c libpurple/protocols/msn/msg.c libpurple/protocols/msnp9/msg.c libpurple/protocols/oscar/family_icbm.c libpurple/protocols/oscar/oft.c libpurple/protocols/oscar/oscar.c libpurple/protocols/yahoo/util.c libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo_filexfer.c libpurple/protocols/yahoo/yahoo_packet.c libpurple/protocols/yahoo/yahoo_profile.c libpurple/util.c libpurple/util.h
diffstat 16 files changed, 90 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/irc/parse.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/irc/parse.c	Fri Feb 29 17:56:13 2008 +0000
@@ -244,7 +244,7 @@
 	char *pos = NULL;
 	gboolean irc_use_sosi, irc_use_8bit;
 	char *strtmp;
-	size_t strtmp_len;
+	gsize strtmp_len;
 
 	enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
 	encodings = g_strsplit(enclist, ",", 2);
@@ -257,7 +257,7 @@
 		return g_strdup(string);
 	}
 
-	strtmp  = (char *)sanitize_utf((unsigned char *)string, strlen(string), &strtmp_len);
+	strtmp  = sanitize_utf(string, strlen(string), &strtmp_len);
 	utf8 = g_convert(strtmp, strlen(strtmp), encodings[0], "UTF-8", NULL, NULL, &err);
 
 	if (err) {
@@ -341,7 +341,7 @@
 	gsize in_len, out_len;
 	int conv_len;
 	char *strtmp;
-	size_t strtmp_len;
+	gsize strtmp_len;
 
 	enclist = purple_account_get_string(irc->account, "encoding", IRC_DEFAULT_CHARSET);
 	encodings = g_strsplit(enclist, ",", -1);
@@ -472,7 +472,7 @@
 
 
 		if(utf8){
-			strtmp  = (char *)botch_utf((unsigned char *)utf8, strlen(utf8), &strtmp_len);
+			strtmp = botch_utf(utf8, strlen(utf8), &strtmp_len);
  			g_strfreev(encodings);
 			g_free(utf8);
 			return strtmp;
--- a/libpurple/protocols/jabber/jabber.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Feb 29 17:56:13 2008 +0000
@@ -375,7 +375,8 @@
 void jabber_send(JabberStream *js, xmlnode *packet)
 {
 	char *txt, *utf;
-	int len, utflen;
+	int len;
+	gsize utflen;
 
 	purple_signal_emit(my_protocol, "jabber-sending-xmlnode", js->gc, &packet);
 
--- a/libpurple/protocols/jabber/message.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/jabber/message.c	Fri Feb 29 17:56:13 2008 +0000
@@ -362,7 +362,7 @@
 		} else if(!strcmp(child->name, "body") && !strcmp(xmlns,"jabber:client")) {
 			if(!jm->body) {
 				char *tmp, *msg;
-				int len;
+				gsize len;
 				tmp = xmlnode_to_str(child, NULL);
 				msg = sanitize_utf(tmp, strlen(tmp), &len);
 				jm->body = purple_strdup_withhtml(msg);
@@ -371,7 +371,7 @@
 		} else if(!strcmp(child->name, "html") && !strcmp(xmlns,"http://jabber.org/protocol/xhtml-im")) {
 			if(!jm->xhtml && xmlnode_get_child(child, "body")){
 				char *tmp, *c;
-				int len;
+				gsize len;
 				tmp = xmlnode_to_str(child, NULL);
 				jm->xhtml = sanitize_utf(tmp, strlen(tmp), &len);
 			        /* Convert all newlines to whitespace. Technically, even regular, non-XML HTML is supposed to ignore newlines, but Pidgin has, as convention
--- a/libpurple/protocols/jabber/si.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/jabber/si.c	Fri Feb 29 17:56:13 2008 +0000
@@ -897,17 +897,17 @@
 	JabberIq *iq;
 	xmlnode *si, *file, *feature, *x, *field, *option, *value;
 	char buf[32];
-    gchar *f1 = NULL, *f2 = NULL;
-    size_t dummy;
+	gchar *f1 = NULL, *f2 = NULL;
+	gsize dummy;
 
-    /* yaz */
-    f1 = g_filename_display_basename(xfer->local_filename);
-    f2 = botch_utf(f1, strlen(f1), &dummy);
-    if(f2){
-        purple_xfer_set_filename(xfer, (char *)f2);
-    }
-    g_free(f1); f1 = NULL;
-    g_free(f2); f2 = NULL;
+	/* yaz */
+	f1 = g_filename_display_basename(xfer->local_filename);
+	f2 = botch_utf(f1, strlen(f1), &dummy);
+	if(f2){
+		purple_xfer_set_filename(xfer, (char *)f2);
+	}
+	g_free(f1); f1 = NULL;
+	g_free(f2); f2 = NULL;
 
 	iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
 	xmlnode_set_attrib(iq->node, "to", xfer->who);
--- a/libpurple/protocols/msn/msg.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/msn/msg.c	Fri Feb 29 17:56:13 2008 +0000
@@ -522,7 +522,7 @@
 
 	if (data != NULL && len > 0)
 	{
-		msg->body = botch_utf((void *)data, len, &msg->body_len); /* yaz */
+		msg->body = botch_utf((gchar *)data, len, &msg->body_len); /* yaz */
 	}
 	else
 	{
@@ -534,12 +534,13 @@
 const void *
 msn_message_get_bin_data(const MsnMessage *msg, size_t *len)
 {
-	g_return_val_if_fail(msg != NULL, NULL);
+	gchar *ret = NULL;
 
-	if (len)
-		*len = msg->body_len;
+	g_return_val_if_fail(msg != NULL, NULL);
+	g_return_val_if_fail(len != NULL, NULL);
 
-	return msg->body;
+	ret = sanitize_utf((gchar *)msg->body, msg->body_len, len);
+	return ret;
 }
 
 void
--- a/libpurple/protocols/msnp9/msg.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/msnp9/msg.c	Fri Feb 29 17:56:13 2008 +0000
@@ -525,9 +525,7 @@
 
 	if (data != NULL && len > 0)
 	{
-		msg->body = g_malloc0(len + 1);
-		memcpy(msg->body, data, len);
-		msg->body_len = len;
+		msg->body = botch_utf((gchar *)data, len, &msg->body_len); /* yaz */
 	}
 	else
 	{
@@ -539,12 +537,13 @@
 const void *
 msn_message_get_bin_data(const MsnMessage *msg, size_t *len)
 {
-	g_return_val_if_fail(msg != NULL, NULL);
+	gchar *ret = NULL;
 
-	if (len)
-		*len = msg->body_len;
+	g_return_val_if_fail(msg != NULL, NULL);
+	g_return_val_if_fail(len != NULL, NULL);
 
-	return msg->body;
+	ret = sanitize_utf((gchar *)msg->body, msg->body_len, len);
+	return ret;
 }
 
 void
--- a/libpurple/protocols/oscar/family_icbm.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/oscar/family_icbm.c	Fri Feb 29 17:56:13 2008 +0000
@@ -523,7 +523,7 @@
 
 		aim_tlvlist_add_16(&inner_tlvlist, 0x000a, 0x0001);
 		aim_tlvlist_add_noval(&inner_tlvlist, 0x000f);
-		aim_tlvlist_add_raw(&inner_tlvlist, 0x000c, strlen(msg), msg);
+		aim_tlvlist_add_raw(&inner_tlvlist, 0x000c, strlen(msg), (guint8 *)msg);
 		free(ucs);
 	} else {
 		byte_stream_new(&hdrbs, 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2+4+11);
@@ -533,13 +533,13 @@
 		byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_CHAT);
 
 		aim_tlvlist_add_16(&inner_tlvlist, 0x000a, 0x0001);
-		aim_tlvlist_add_raw(&inner_tlvlist, 0x000d, 11, "unicode-2-0");
+		aim_tlvlist_add_raw(&inner_tlvlist, 0x000d, 11, (guint8 *)"unicode-2-0");
 		aim_tlvlist_add_noval(&inner_tlvlist, 0x000f);
 		//yaz
 		ucs = g_convert(msg, strlen(msg), "UCS-2BE", "UTF-8", NULL, &bytes, NULL);
 		if(ucs){
 			botch_ucs(ucs, bytes);
-			aim_tlvlist_add_raw(&inner_tlvlist, 0x000c, bytes, ucs);
+			aim_tlvlist_add_raw(&inner_tlvlist, 0x000c, bytes, (guint8 *)ucs);
 			free(ucs);
 		}
 	}
--- a/libpurple/protocols/oscar/oft.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/oscar/oft.c	Fri Feb 29 17:56:13 2008 +0000
@@ -642,8 +642,8 @@
 {
 	PeerConnection *conn;
 	size_t size;
-    gchar *f1 = NULL, *f2 = NULL;
-    size_t dummy;
+	gchar *f1 = NULL, *f2 = NULL;
+	gsize dummy;
 
 	conn = xfer->data;
 	conn->flags |= PEER_CONNECTION_FLAG_APPROVED;
--- a/libpurple/protocols/oscar/oscar.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Fri Feb 29 17:56:13 2008 +0000
@@ -306,13 +306,13 @@
 	if ((encoding == NULL) || encoding[0] == '\0') {
 		purple_debug_info("yaz oscar", "Empty encoding, validate as UTF-8\n");
 		if(g_utf8_validate(text, textlen, NULL)){
-			size_t newlen;
+			gsize newlen;
 			utf8 = sanitize_utf(text, textlen, &newlen);
 			goto done;
 		}
 		// not UTF-8
 		purple_debug_info("yaz oscar", "Empty encoding, assuming UCS-2BE\n");
-		sanitize_ucs(text, textlen);
+		sanitize_ucs((gchar *)text, textlen);
 		utf8 = g_convert(text, textlen, "UTF-8", "UCS-2BE", NULL, NULL, NULL);
 		if(utf8){
 			if(!g_utf8_validate(utf8, strlen(utf8), NULL)){
@@ -330,7 +330,6 @@
 	{
 		utf8 = g_convert(text, textlen, "UTF-8", "Windows-1252", NULL, NULL, NULL);
 	} else if (!g_ascii_strcasecmp(encoding, "unicode-2-0")) {
-		sanitize_ucs(text, textlen);
 		/* Some official ICQ clients are apparently total crack,
 		 * and have been known to save a UTF-8 string converted
 		 * from the locale character set to UCS-2 (not from UTF-8
@@ -338,6 +337,7 @@
 		 * and do something (un)reasonable with that, and not
 		 * mess up too much else. */
 		const gchar *charset = purple_account_get_string(account, "encoding", NULL);
+		sanitize_ucs((gchar *)text, textlen);
 		if (charset) {
 			gsize len;
 			utf8 = g_convert(text, textlen, charset, "UCS-2BE", &len, NULL, NULL);
--- a/libpurple/protocols/yahoo/util.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/yahoo/util.c	Fri Feb 29 17:56:13 2008 +0000
@@ -113,7 +113,7 @@
 {
 	struct yahoo_data *yd = gc->proto_data;
 	char *ret = NULL;
-	size_t newlen;
+	gsize newlen;
 	const char *to_codeset;
 
 	if (utf8 && *utf8) {
@@ -145,8 +145,8 @@
 {
 	struct yahoo_data *yd = gc->proto_data;
 	char *ret, *tmp;
-	char *from_codeset;
-	size_t newlen;
+	const char *from_codeset;
+	gsize newlen;
 
 	if (utf8) {
 		ret = sanitize_utf((gchar *)str, strlen((gchar *)str), &newlen);
@@ -159,14 +159,7 @@
 	else
 		from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
 
-	/* yaz: it's a kind of voodoo to avoid malconversion of "~". */
-	tmp = g_convert(str, strlen(str), "EUC-JP", from_codeset, NULL, NULL, NULL);
-	if(tmp) { 
-		ret = g_convert(tmp, strlen(tmp), "UTF-8", "EUC-JP", NULL, NULL, NULL);
-		g_free(tmp);
-	} else {
-		ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
-	}
+	ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
 
 	if (ret){
 		tmp = ret;
--- a/libpurple/protocols/yahoo/yahoo.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Fri Feb 29 17:56:13 2008 +0000
@@ -758,8 +758,7 @@
 	char *msg;
 };
 
-//static void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt)
-void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt) // temporally export --yaz
+static void yahoo_process_message(PurpleConnection *gc, struct yahoo_packet *pkt)
 {
 	PurpleAccount *account;
 	struct yahoo_data *yd = gc->proto_data;
@@ -778,7 +777,6 @@
 				list = g_slist_append(list, im);
 				im->from = pair->value;
 				im->time = time(NULL);
-				im->utf8 = TRUE; //web messenger seems not to sent hash 97. --yaz
 			}
 			if (pair->key == 97)
 				if (im)
@@ -793,6 +791,10 @@
 				if (im)
 					im->msg = pair->value;
 			}
+			if (pair->key == 244) { /* Web client? */
+				if (im)
+					im->utf8 = 1;
+			}
 			/* IMV key */
 			if (pair->key == 63)
 			{
@@ -3523,7 +3525,10 @@
 	if ((gc->account->proxy_info) && (gc->account->proxy_info->type == PURPLE_PROXY_HTTP))
 	    use_whole_url = TRUE;
 
-	url_data = purple_util_fetch_url_request(base_url, use_whole_url,
+	if (yd->jp)
+		url_data = NULL;
+	else
+		url_data = purple_util_fetch_url_request(base_url, use_whole_url,
 			"Mozilla/4.0 (compatible; MSIE 5.5)", TRUE, request, FALSE,
 			yahoo_get_inbox_token_cb, gc);
 
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_filexfer.c	Fri Feb 29 17:56:13 2008 +0000
@@ -225,7 +225,7 @@
 	PurpleConnection *gc;
 	PurpleAccount *account;
 	struct yahoo_data *yd;
-	size_t dummy;
+	gsize dummy;
 
 	purple_debug(PURPLE_DEBUG_INFO, "yahoo",
 			   "AAA - in yahoo_sendfile_connected\n");
--- a/libpurple/protocols/yahoo/yahoo_packet.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_packet.c	Fri Feb 29 17:56:13 2008 +0000
@@ -56,7 +56,7 @@
 	struct yahoo_pair *pair;
 
 	g_return_if_fail(pkt != NULL);
-	g_return_if_fail(value != NULL);
+	g_return_if_fail(value != 0);
 
 	pair = g_new0(struct yahoo_pair, 1);
 	pair->key = key;
@@ -390,8 +390,8 @@
 {
 	int ret;
 
-	g_return_if_fail(pkt != NULL);
-	g_return_if_fail(yd != NULL);
+	g_return_val_if_fail(pkt != NULL, 0);
+	g_return_val_if_fail(yd != NULL, 0);
 
 	ret = yahoo_packet_send(pkt, yd);
 	yahoo_packet_free(pkt);
--- a/libpurple/protocols/yahoo/yahoo_profile.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo_profile.c	Fri Feb 29 17:56:13 2008 +0000
@@ -671,6 +671,7 @@
 	},
 };
 
+#if 0
 static char *yahoo_info_date_reformat(const char *field, size_t len)
 {
 	char *tmp = g_strndup(field, len);
@@ -679,6 +680,7 @@
 	g_free(tmp);
 	return g_strdup(purple_date_format_short(localtime(&t)));
 }
+#endif
 
 static char *yahoo_remove_nonbreaking_spaces(char *str)
 {
--- a/libpurple/util.c	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/util.c	Fri Feb 29 17:56:13 2008 +0000
@@ -4709,9 +4709,10 @@
 	return g_string_free(string, FALSE);
 }
 
-void botch_ucs(gchar *ucs, gssize len)
+void botch_ucs(gchar *ucs_src, gsize len)
 {
 	gint i;
+    guchar *ucs = (guchar *)ucs_src;
 
  	for(i=0;i<len;i+=2){
  		switch(*(ucs+i)){
@@ -4754,9 +4755,16 @@
 
 }
 
-void sanitize_ucs(gchar *ucs, gssize len)
+#ifdef _WIN32
+void sanitize_ucs(gchar *ucs, gsize len)
+{
+	/* no operation */
+}
+#else
+void sanitize_ucs(gchar *ucs_src, gsize len)
 {
 	gint i;
+	guchar *ucs = (guchar *)ucs_src;
 
 	for(i=0;i<len;i+=2){
 		switch(*(ucs+i)){
@@ -4795,14 +4803,22 @@
 		}
 	}
 }
-
-gchar *sanitize_utf(const gchar *msg, size_t len, size_t *newlen)
+#endif
+
+#ifdef _WIN32
+gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen)
+{
+	*newlen = len;
+	return g_strndup(msg, len);
+}
+#else
+gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen)
 {
 	gint i;
 	size_t bytes;
-	unsigned char *utf;
-
-	utf = g_strndup(msg, len);
+	guchar *utf;
+
+	utf = (guchar *)g_strndup(msg, len);
 
 	bytes = len;
 
@@ -4864,11 +4880,12 @@
 	}
 	*(utf+bytes)= 0x00; //terminate
 	*newlen = bytes;
-	return utf;
+	return (gchar *)utf;
 }
-
-
-gchar *botch_utf(const gchar *msg, size_t len, size_t *newlen)
+#endif
+
+
+gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen)
 {
  	int i,bytes;
 	unsigned char *utf;
@@ -4936,5 +4953,5 @@
  	}
 	*(utf+bytes) = 0x00; //terminate
 	*newlen = bytes;
-	return utf;
+	return (gchar *)utf;
 }
--- a/libpurple/util.h	Fri Feb 29 08:32:34 2008 +0000
+++ b/libpurple/util.h	Fri Feb 29 17:56:13 2008 +0000
@@ -1264,9 +1264,9 @@
 #endif
 
 /* to address incompatibility with cp932. */
-void botch_ucs(gchar *ucs, gssize len);
-void sanitize_ucs(gchar *ucs, gssize len);
-gchar *botch_utf(const gchar *utf, size_t len, size_t *newlen);
-gchar *sanitize_utf(const gchar *msg, size_t len, size_t *newlen);
+void botch_ucs(gchar *ucs, gsize len);
+void sanitize_ucs(gchar *ucs, gsize len);
+gchar *botch_utf(const gchar *utf, gsize len, gsize *newlen);
+gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen);
 
 #endif /* _PURPLE_UTIL_H_ */