# HG changeset patch # User ivan.komarov@soc.pidgin.im # Date 1280606439 0 # Node ID ed520e6e972b13cf645e30219a1084cdae16d22d # Parent bbb27d65681fdfcef749f9e5db42ce3677854c82 Renames and cleanups. diff -r bbb27d65681f -r ed520e6e972b libpurple/protocols/oscar/bstream.c --- 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; diff -r bbb27d65681f -r ed520e6e972b libpurple/protocols/oscar/encoding.c --- 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; } diff -r bbb27d65681f -r ed520e6e972b libpurple/protocols/oscar/encoding.h --- 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 diff -r bbb27d65681f -r ed520e6e972b libpurple/protocols/oscar/oscar.c --- 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, ""); /* 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",