changeset 30827:ed520e6e972b

Renames and cleanups.
author ivan.komarov@soc.pidgin.im
date Sat, 31 Jul 2010 20:00:39 +0000
parents bbb27d65681f
children 1b7152eeea31
files libpurple/protocols/oscar/bstream.c libpurple/protocols/oscar/encoding.c libpurple/protocols/oscar/encoding.h libpurple/protocols/oscar/oscar.c
diffstat 4 files changed, 25 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/bstream.c	Wed Jul 28 23:53:25 2010 +0000
+++ b/libpurple/protocols/oscar/bstream.c	Sat Jul 31 20:00:39 2010 +0000
@@ -78,7 +78,8 @@
  */
 int byte_stream_advance(ByteStream *bs, int n)
 {
-	g_return_val_if_fail((byte_stream_curpos(bs) + n >= 0) && (n <= byte_stream_bytes_left(bs)), 0);
+	g_return_val_if_fail(byte_stream_curpos(bs) + n >= 0, 0);
+	g_return_val_if_fail(n <= byte_stream_bytes_left(bs), 0);
 
 	bs->offset += n;
 	return n;
--- a/libpurple/protocols/oscar/encoding.c	Wed Jul 28 23:53:25 2010 +0000
+++ b/libpurple/protocols/oscar/encoding.c	Sat Jul 31 20:00:39 2010 +0000
@@ -20,19 +20,6 @@
 
 #include "encoding.h"
 
-guint16
-oscar_charset_check(const char *utf8)
-{
-	while (*utf8++)
-	{
-		if ((unsigned char)(*utf8) > 0x7f) {
-			/* not ASCII! */
-			return AIM_CHARSET_UNICODE;
-		}
-	}
-	return AIM_CHARSET_ASCII;
-}
-
 static gchar *
 encoding_extract(const char *encoding)
 {
@@ -214,10 +201,23 @@
 	return ret;
 }
 
+static guint16
+get_simplest_charset(const char *utf8)
+{
+	while (*utf8++)
+	{
+		if ((unsigned char)(*utf8) > 0x7f) {
+			/* not ASCII! */
+			return AIM_CHARSET_UNICODE;
+		}
+	}
+	return AIM_CHARSET_ASCII;
+}
+
 gchar *
-oscar_convert_to_best_encoding(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr)
+oscar_encode_im(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr)
 {
-	guint16 msg_charset = oscar_charset_check(msg);
+	guint16 msg_charset = get_simplest_charset(msg);
 	if (charset != NULL) {
 		*charset = msg_charset;
 	}
--- a/libpurple/protocols/oscar/encoding.h	Wed Jul 28 23:53:25 2010 +0000
+++ b/libpurple/protocols/oscar/encoding.h	Sat Jul 31 20:00:39 2010 +0000
@@ -24,11 +24,6 @@
 #include "oscar.h"
 #include "oscarcommon.h"
 
-/**
- * Determine the simplest encoding we can send this message in.
- */
-guint16 oscar_charset_check(const char *utf8);
-
 gchar * oscar_encoding_to_utf8(const char *encoding, const char *text, int textlen);
 gchar * oscar_utf8_try_convert(PurpleAccount *account, OscarData *od, const gchar *msg);
 
@@ -46,6 +41,6 @@
 /**
  * Figure out what encoding to use when sending a given outgoing message.
  */
-gchar * oscar_convert_to_best_encoding(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr);
+gchar * oscar_encode_im(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr);
 
 #endif
\ No newline at end of file
--- a/libpurple/protocols/oscar/oscar.c	Wed Jul 28 23:53:25 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Sat Jul 31 20:00:39 2010 +0000
@@ -3107,7 +3107,7 @@
 	g_string_append(msg, "</BODY></HTML>");
 
 	/* Convert the message to a good encoding */
-	tmp = oscar_convert_to_best_encoding(msg->str, &tmplen, &charset, NULL);
+	tmp = oscar_encode_im(msg->str, &tmplen, &charset, NULL);
 	g_string_free(msg, TRUE);
 	msg = g_string_new_len(tmp, tmplen);
 	g_free(tmp);
@@ -3256,7 +3256,7 @@
 		g_free(tmp1);
 		tmp1 = tmp2;
 
-		args.msg = oscar_convert_to_best_encoding(tmp1, &args.msglen, &args.charset, NULL);
+		args.msg = oscar_encode_im(tmp1, &args.msglen, &args.charset, NULL);
 		if (is_html && (args.msglen > MAXMSGLEN)) {
 			/* If the length was too long, try stripping the HTML and then running it back through
 			* purple_strdup_withhtml() and the encoding process. The result may be shorter. */
@@ -3273,7 +3273,7 @@
 			g_free(tmp1);
 			tmp1 = tmp2;
 
-			args.msg = oscar_convert_to_best_encoding(tmp1, &args.msglen, &args.charset, NULL);
+			args.msg = oscar_encode_im(tmp1, &args.msglen, &args.charset, NULL);
 			purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
 								  message, (char *)args.msg);
 		}
@@ -3413,7 +3413,7 @@
 	else if (rawinfo != NULL)
 	{
 		char *htmlinfo = purple_strdup_withhtml(rawinfo);
-		info = oscar_convert_to_best_encoding(htmlinfo, &infolen, NULL, &info_encoding);
+		info = oscar_encode_im(htmlinfo, &infolen, NULL, &info_encoding);
 		g_free(htmlinfo);
 
 		if (infolen > od->rights.maxsiglen)
@@ -3446,7 +3446,7 @@
 
 			/* We do this for icq too so that they work for old third party clients */
 			linkified = purple_markup_linkify(status_html);
-			away = oscar_convert_to_best_encoding(linkified, &awaylen, NULL, &away_encoding);
+			away = oscar_encode_im(linkified, &awaylen, NULL, &away_encoding);
 			g_free(linkified);
 
 			if (awaylen > od->rights.maxawaymsglen)
@@ -4429,7 +4429,7 @@
 			  "You cannot send IM Images in AIM chats."),
 			PURPLE_MESSAGE_ERROR, time(NULL));
 
-	buf2 = oscar_convert_to_best_encoding(buf, &len, &charset, &charsetstr);
+	buf2 = oscar_encode_im(buf, &len, &charset, &charsetstr);
 	/*
 	 * Evan S. suggested that maxvis really does mean "number of
 	 * visible characters" and not "number of bytes"
@@ -4445,7 +4445,7 @@
 		buf = purple_strdup_withhtml(buf3);
 		g_free(buf3);
 
-		buf2 = oscar_convert_to_best_encoding(buf, &len, &charset, &charsetstr);
+		buf2 = oscar_encode_im(buf, &len, &charset, &charsetstr);
 
 		if ((len > c->maxlen) || (len > c->maxvis)) {
 			purple_debug_warning("oscar",