/pidgin/main: 0ff850475a1d: Change the last param of yahoo_strin...

Mark Doliner mark at kingant.net
Tue Jan 28 10:38:14 EST 2014


Changeset: 0ff850475a1d21b0cd4c031a24cdaecebcb688bf
Author:	 Mark Doliner <mark at kingant.net>
Date:	 2014-01-20 00:26 -0800
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/0ff850475a1d

Description:

Change the last param of yahoo_string_encode from gboolean* to gboolean.

There was no reason for it to be a pointer. Maybe someone wanted to
optionally set utf-8 to true if we needed it or something? But that's
not the current behavior. It's better for the code to be simpler now,
and it can be changed back to a pointer if we need it for some reason.

diffstat:

 libpurple/protocols/yahoo/libymsg.c   |  40 +++++++++++++++-------------------
 libpurple/protocols/yahoo/libymsg.h   |  12 ++++------
 libpurple/protocols/yahoo/util.c      |  16 +------------
 libpurple/protocols/yahoo/yahoochat.c |  28 ++++++++---------------
 libpurple/protocols/yahoo/ycht.c      |   2 +-
 5 files changed, 36 insertions(+), 62 deletions(-)

diffs (truncated from 347 to 300 lines):

diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -1320,7 +1320,7 @@ yahoo_buddy_add_deny_cb(const char *msg,
 	const char *who = add_req->who;
 
 	if (msg && *msg)
-		encoded_msg = yahoo_string_encode(add_req->gc, msg, NULL);
+		encoded_msg = yahoo_string_encode(add_req->gc, msg, FALSE);
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH_REQ_15,
 			YAHOO_STATUS_AVAILABLE, yd->session_id);
@@ -1333,7 +1333,7 @@ yahoo_buddy_add_deny_cb(const char *msg,
 						  241, add_req->fed,
 						  13, 2,
 						  334, 0,
-						  97, 1,
+						  97, 1, /* UTF-8 */
 						  14, encoded_msg ? encoded_msg : "");
 	}
 	else {
@@ -1342,7 +1342,7 @@ yahoo_buddy_add_deny_cb(const char *msg,
 						  5, who,
 						  13, 2,
 						  334, 0,
-						  97, 1,
+						  97, 1, /* UTF-8 */
 						  14, encoded_msg ? encoded_msg : "");
 	}
 
@@ -4563,7 +4563,6 @@ int yahoo_send_im(PurpleConnection *gc, 
 	struct yahoo_packet *pkt = NULL;
 	char *msg = yahoo_html_to_codes(what);
 	char *msg2;
-	gboolean utf8 = TRUE;
 	PurpleWhiteboard *wb;
 	int ret = 1;
 	const char *fed_who;
@@ -4571,7 +4570,7 @@ int yahoo_send_im(PurpleConnection *gc, 
 	glong lenc = 0;
 	struct yahoo_p2p_data *p2p_data;
 	YahooFederation fed = YAHOO_FEDERATION_NONE;
-	msg2 = yahoo_string_encode(gc, msg, &utf8);
+	msg2 = yahoo_string_encode(gc, msg, TRUE);
 
 	if(msg2) {
 		lenb = strlen(msg2);
@@ -4654,8 +4653,7 @@ int yahoo_send_im(PurpleConnection *gc, 
 	if (fed)
 		yahoo_packet_hash_int(pkt, 241, fed);
 
-	if (utf8)
-		yahoo_packet_hash_str(pkt, 97, "1");
+	yahoo_packet_hash_str(pkt, 97, "1"); /* UTF-8 */
 	yahoo_packet_hash_str(pkt, 14, msg2);
 
 	/*
@@ -4780,7 +4778,6 @@ void yahoo_set_status(PurpleAccount *acc
 	const char *msg = NULL;
 	char *tmp = NULL;
 	char *conv_msg = NULL;
-	gboolean utf8 = TRUE;
 
 	if (!purple_status_is_active(status))
 		return;
@@ -4797,13 +4794,13 @@ void yahoo_set_status(PurpleAccount *acc
 		msg = purple_status_get_attr_string(status, "message");
 
 		if (purple_status_is_available(status)) {
-			tmp = yahoo_string_encode(gc, msg, &utf8);
+			tmp = yahoo_string_encode(gc, msg, TRUE);
 			conv_msg = purple_markup_strip_html(tmp);
 			g_free(tmp);
 		} else {
 			if ((msg == NULL) || (*msg == '\0'))
 				msg = _("Away");
-			tmp = yahoo_string_encode(gc, msg, &utf8);
+			tmp = yahoo_string_encode(gc, msg, TRUE);
 			conv_msg = purple_markup_strip_html(tmp);
 			g_free(tmp);
 		}
@@ -4821,7 +4818,7 @@ void yahoo_set_status(PurpleAccount *acc
 	yahoo_packet_hash_int(pkt, 10, yd->current_status);
 
 	if (yd->current_status == YAHOO_STATUS_CUSTOM) {
-		yahoo_packet_hash_str(pkt, 97, utf8 ? "1" : 0);
+		yahoo_packet_hash_str(pkt, 97, "1"); /* UTF-8 */
 		yahoo_packet_hash_str(pkt, 19, conv_msg);
 	} else {
 		yahoo_packet_hash_str(pkt, 19, "");
@@ -4881,10 +4878,9 @@ void yahoo_set_idle(PurpleConnection *gc
 			status = purple_presence_get_active_status(purple_account_get_presence(purple_connection_get_account(gc)));
 		tmp = purple_status_get_attr_string(status, "message");
 		if (tmp != NULL) {
-			gboolean utf8 = TRUE;
-			msg = yahoo_string_encode(gc, tmp, &utf8);
+			msg = yahoo_string_encode(gc, tmp, TRUE);
 			msg2 = purple_markup_strip_html(msg);
-			yahoo_packet_hash_str(pkt, 97, utf8 ? "1" : 0);
+			yahoo_packet_hash_str(pkt, 97, "1"); /* UTF-8 */
 			yahoo_packet_hash_str(pkt, 19, msg2);
 		} else {
 			/* get_yahoo_status_from_purple_status() returns YAHOO_STATUS_CUSTOM for
@@ -5030,13 +5026,13 @@ void yahoo_add_buddy(PurpleConnection *g
 	else
 		group = "Buddies";
 
-	group2 = yahoo_string_encode(gc, group, NULL);
+	group2 = yahoo_string_encode(gc, group, FALSE);
 	pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id);
 	if (fed) {
 		yahoo_packet_hash(pkt, "sssssssisss",
 						  14, "",
 						  65, group2,
-						  97, "1",
+						  97, "1", /* UTF-8 */
 						  1, purple_connection_get_display_name(gc),
 						  302, "319",
 						  300, "319",
@@ -5051,7 +5047,7 @@ void yahoo_add_buddy(PurpleConnection *g
 		yahoo_packet_hash(pkt, "ssssssssss",
 						  14, "",
 						  65, group2,
-						  97, "1",
+						  97, "1", /* UTF-8 */
 						  1, purple_connection_get_display_name(gc),
 						  302, "319",
 						  300, "319",
@@ -5101,7 +5097,7 @@ void yahoo_remove_buddy(PurpleConnection
 		f = NULL; /* f no longer valid - Just making it clear */
 	}
 
-	cg = yahoo_string_encode(gc, gname, NULL);
+	cg = yahoo_string_encode(gc, gname, FALSE);
 	pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, yd->session_id);
 
 	switch (fed) {
@@ -5216,8 +5212,8 @@ void yahoo_change_buddys_group(PurpleCon
 	 * end up deleting the buddy, which would be bad.
 	 * This might happen because of the charset conversation.
 	 */
-	gpn = yahoo_string_encode(gc, new_group, NULL);
-	gpo = yahoo_string_encode(gc, old_group, NULL);
+	gpn = yahoo_string_encode(gc, new_group, FALSE);
+	gpo = yahoo_string_encode(gc, old_group, FALSE);
 	if (!strcmp(gpn, gpo)) {
 		g_free(gpn);
 		g_free(gpo);
@@ -5246,8 +5242,8 @@ void yahoo_rename_group(PurpleConnection
 	struct yahoo_packet *pkt;
 	char *gpn, *gpo;
 
-	gpn = yahoo_string_encode(gc, purple_group_get_name(group), NULL);
-	gpo = yahoo_string_encode(gc, old_name, NULL);
+	gpn = yahoo_string_encode(gc, purple_group_get_name(group), FALSE);
+	gpo = yahoo_string_encode(gc, old_name, FALSE);
 	if (!strcmp(gpn, gpo)) {
 		g_free(gpn);
 		g_free(gpo);
diff --git a/libpurple/protocols/yahoo/libymsg.h b/libpurple/protocols/yahoo/libymsg.h
--- a/libpurple/protocols/yahoo/libymsg.h
+++ b/libpurple/protocols/yahoo/libymsg.h
@@ -330,14 +330,12 @@ yahoo_account_use_http_proxy(PurpleConne
  *
  * @param gc The connection handle.
  * @param str The null terminated utf8 string to encode.
- * @param utf8 If not @c NULL, whether utf8 is okay or not.
- *             Even if it is okay, we may not use it. If we
- *             used it, we set this to @c TRUE, else to
- *             @c FALSE. If @c NULL, false is assumed, and
- *             it is not dereferenced.
- * @return The g_malloced string in the appropriate encoding.
+ * @param utf8 Whether to return a UTF-8 string.
+ * @return A g_malloc'ed string in the appropriate encoding. If jd->jp or
+ *         utf8 is true then the string is copied verbatim. Otherwise the
+ *         encoding from account settings is used.
  */
-char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8);
+gchar *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean utf8);
 
 /**
  * Decode some text received from the server.
diff --git a/libpurple/protocols/yahoo/util.c b/libpurple/protocols/yahoo/util.c
--- a/libpurple/protocols/yahoo/util.c
+++ b/libpurple/protocols/yahoo/util.c
@@ -116,19 +116,7 @@ gchar* yahoo_get_cookies(PurpleConnectio
 	return ans;
 }
 
-/**
- * Encode some text to send to the yahoo server.
- *
- * @param gc The connection handle.
- * @param str The null terminated utf8 string to encode.
- * @param utf8 If not @c NULL, whether utf8 is okay or not.
- *             Even if it is okay, we may not use it. If we
- *             used it, we set this to @c TRUE, else to
- *             @c FALSE. If @c NULL, false is assumed, and
- *             it is not dereferenced.
- * @return The g_malloced string in the appropriate encoding.
- */
-char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
+char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean utf8)
 {
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 	char *ret;
@@ -138,7 +126,7 @@ char *yahoo_string_encode(PurpleConnecti
 	if (yd->jp)
 		return g_strdup(str);
 
-	if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
+	if (utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
 		return g_strdup(str);
 
 	to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset",  "ISO-8859-1");
diff --git a/libpurple/protocols/yahoo/yahoochat.c b/libpurple/protocols/yahoo/yahoochat.c
--- a/libpurple/protocols/yahoo/yahoochat.c
+++ b/libpurple/protocols/yahoo/yahoochat.c
@@ -406,7 +406,6 @@ static void yahoo_chat_join(PurpleConnec
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 	struct yahoo_packet *pkt;
 	char *room2;
-	gboolean utf8 = TRUE;
 
 	if (yd->wm) {
 		g_return_if_fail(yd->ycht != NULL);
@@ -416,7 +415,7 @@ static void yahoo_chat_join(PurpleConnec
 
 	/* apparently room names are always utf8, or else always not utf8,
 	 * so we don't have to actually pass the flag in the packet. Or something. */
-	room2 = yahoo_string_encode(gc, room, &utf8);
+	room2 = yahoo_string_encode(gc, room, TRUE);
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, yd->session_id);
 	yahoo_packet_hash(pkt, "ssss",
@@ -853,10 +852,9 @@ static int yahoo_conf_send(PurpleConnect
 	struct yahoo_packet *pkt;
 	GList *who;
 	char *msg, *msg2;
-	int utf8 = 1;
 
 	msg = yahoo_html_to_codes(what);
-	msg2 = yahoo_string_encode(gc, msg, &utf8);
+	msg2 = yahoo_string_encode(gc, msg, TRUE);
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, yd->session_id);
 
@@ -866,8 +864,7 @@ static int yahoo_conf_send(PurpleConnect
 		yahoo_packet_hash_str(pkt, 53, name);
 	}
 	yahoo_packet_hash(pkt, "ss", 57, room, 14, msg2);
-	if (utf8)
-		yahoo_packet_hash_str(pkt, 97, "1"); /* utf-8 */
+	yahoo_packet_hash_str(pkt, 97, "1"); /* UTF-8 */
 
 	yahoo_packet_send_and_free(pkt, yd);
 	g_free(msg);
@@ -912,7 +909,7 @@ static void yahoo_conf_invite(PurpleConn
 	char *msg2 = NULL;
 
 	if (msg)
-		msg2 = yahoo_string_encode(gc, msg, NULL);
+		msg2 = yahoo_string_encode(gc, msg, FALSE);
 
 	members = purple_chat_conversation_get_users(c);
 
@@ -938,9 +935,7 @@ static void yahoo_chat_leave(PurpleConne
 {
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 	struct yahoo_packet *pkt;
-
 	char *eroom;
-	gboolean utf8 = 1;
 
 	if (yd->wm) {
 		g_return_if_fail(yd->ycht != NULL);
@@ -949,7 +944,7 @@ static void yahoo_chat_leave(PurpleConne
 		return;
 	}
 
-	eroom = yahoo_string_encode(gc, room, &utf8);
+	eroom = yahoo_string_encode(gc, room, TRUE);
 
 	pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, yd->session_id);
 	yahoo_packet_hash(pkt, "sss", 104, eroom, 109, dn, 108, "1");
@@ -991,7 +986,6 @@ static int yahoo_chat_send(PurpleConnect
 	struct yahoo_packet *pkt;
 	int me = 0;
 	char *msg1, *msg2, *room2;
-	gboolean utf8 = TRUE;
 
 	if (yd->wm) {
 		g_return_val_if_fail(yd->ycht != NULL, 1);
@@ -1006,9 +1000,9 @@ static int yahoo_chat_send(PurpleConnect
 
 	msg2 = yahoo_html_to_codes(msg1);
 	g_free(msg1);
-	msg1 = yahoo_string_encode(gc, msg2, &utf8);
+	msg1 = yahoo_string_encode(gc, msg2, TRUE);
 	g_free(msg2);



More information about the Commits mailing list