cpw.ivan: e4e0a801: Escape status messages properly (Fixes #...

ivan.komarov at soc.pidgin.im ivan.komarov at soc.pidgin.im
Tue Sep 21 14:02:26 EDT 2010


----------------------------------------------------------------------
Revision: e4e0a8019c2a8da23c47db0095c8485f18ba6caa
Parent:   7b998c02b684a694f1089bee715e4a3952bbcf08
Author:   ivan.komarov at soc.pidgin.im
Date:     09/21/10 13:53:09
Branch:   im.pidgin.cpw.ivan
URL: http://d.pidgin.im/viewmtn/revision/info/e4e0a8019c2a8da23c47db0095c8485f18ba6caa

Changelog: 

Escape status messages properly (Fixes #11964).

We now never strip HTML tags from status messages (this behaviour converted the
"<-- hat jetzt ein Macbook" status from the bug to the empty string).
Instead, we just escape HTML where needed.

Also, the x-status message is now not written to the "message" status attribute
of PurpleStatus, because it can be different from the available message
for some clients (Miranda) and we don't want the x-status message to
overwrite the available message.

Changes against parent 7b998c02b684a694f1089bee715e4a3952bbcf08

  patched  libpurple/protocols/oscar/family_icbm.c
  patched  libpurple/protocols/oscar/oscar.c
  patched  libpurple/protocols/oscar/oscar.h
  patched  libpurple/protocols/oscar/userinfo.c

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c	e8c1ff08db1d603ba878a7bbfdac077b6abb35e5
+++ libpurple/protocols/oscar/oscar.c	1a9dec6716433c8ab250bc0a0223d874916538a1
@@ -1301,8 +1301,6 @@ static int purple_parse_oncoming(OscarDa
 	aim_userinfo_t *info;
 	char *message = NULL;
 	char *itmsurl = NULL;
-	char *tmp;
-	const char *tmp2;
 
 	gc = od->gc;
 	account = purple_connection_get_account(gc);
@@ -1377,41 +1375,22 @@ static int purple_parse_oncoming(OscarDa
 			status_id = OSCAR_STATUS_ID_AVAILABLE;
 	}
 
-	if (info->flags & AIM_FLAG_WIRELESS)
-	{
+	if (info->flags & AIM_FLAG_WIRELESS) {
 		purple_prpl_got_user_status(account, info->bn, OSCAR_STATUS_ID_MOBILE, NULL);
 	} else {
 		purple_prpl_got_user_status_deactive(account, info->bn, OSCAR_STATUS_ID_MOBILE);
 	}
 
-	if (info->status != NULL && info->status[0] != '\0') {
-		/* Grab the available message */
+	if (info->status != NULL) {
 		message = oscar_encoding_to_utf8(info->status_encoding, info->status, info->status_len);
+		purple_prpl_got_user_status(account, info->bn, status_id, "message", message, NULL);
 	}
 
-	tmp2 = tmp = (message ? purple_markup_escape_text(message, -1) : NULL);
-
-	if (strcmp(status_id, OSCAR_STATUS_ID_AVAILABLE) == 0) {
-		if (info->itmsurl_encoding && info->itmsurl && info->itmsurl_len) {
-			/* Grab the iTunes Music Store URL */
-			itmsurl = oscar_encoding_to_utf8(info->itmsurl_encoding, info->itmsurl, info->itmsurl_len);
-		}
-
-		if (tmp2 == NULL && itmsurl != NULL)
-			/*
-			 * The message can't be NULL because NULL means it was the
-			 * last attribute, so the itmsurl would get ignored below.
-			 */
-			tmp2 = "";
-
-		purple_prpl_got_user_status(account, info->bn, status_id,
-									"message", tmp2, "itmsurl", itmsurl, NULL);
+	if (info->itmsurl != NULL) {
+		itmsurl = oscar_encoding_to_utf8(info->itmsurl_encoding, info->itmsurl, info->itmsurl_len);
+		purple_prpl_got_user_status(account, info->bn, status_id, "itmsurl", itmsurl, NULL);
 	}
-	else
-		purple_prpl_got_user_status(account, info->bn, status_id, "message", tmp2, NULL);
 
-	g_free(tmp);
-
 	g_free(message);
 	g_free(itmsurl);
 
@@ -4569,7 +4548,7 @@ void oscar_tooltip_text(PurpleBuddy *b, 
 	od = purple_connection_get_protocol_data(gc);
 	userinfo = aim_locate_finduserinfo(od, purple_buddy_get_name(b));
 
-	oscar_user_info_append_status(gc, user_info, b, userinfo, /* strip_html_tags */ TRUE);
+	oscar_user_info_append_status(gc, user_info, b, userinfo, /* use_html_status */ FALSE);
 
 	if (full)
 		oscar_user_info_append_extra_info(gc, user_info, b, userinfo);
@@ -4607,13 +4586,9 @@ char *oscar_status_text(PurpleBuddy *b)
 		message = purple_status_get_attr_string(status, "message");
 		if (message != NULL)
 		{
-			gchar *tmp1, *tmp2;
-			tmp1 = purple_markup_strip_html(message);
-			purple_util_chrreplace(tmp1, '\n', ' ');
-			tmp2 = g_markup_escape_text(tmp1, -1);
-			ret = oscar_util_format_string(tmp2, purple_account_get_username(account));
-			g_free(tmp1);
-			g_free(tmp2);
+			gchar *tmp = oscar_util_format_string(message, purple_account_get_username(account));
+			ret = purple_markup_escape_text(tmp, -1);
+			g_free(tmp);
 		}
 		else if (purple_status_is_available(status))
 		{
============================================================
--- libpurple/protocols/oscar/family_icbm.c	d47c7af073b498694d71876b40166191a9984946
+++ libpurple/protocols/oscar/family_icbm.c	fc14f7b0d74cabc7a6a499dd2fd5ac90dc481826
@@ -1720,9 +1720,9 @@ static int clientautoresp(OscarData *od,
 						buddy = purple_find_buddy(account, bn);
 						presence = purple_buddy_get_presence(buddy);
 						status = purple_presence_get_active_status(presence);
-						purple_prpl_got_user_status(account, bn,
+						/* purple_prpl_got_user_status(account, bn,
 								purple_status_get_id(status),
-								"message", xstatus->str, NULL);
+								"message", xstatus->str, NULL); */
 					}
 					g_string_free(xstatus, TRUE);
 				} else {
============================================================
--- libpurple/protocols/oscar/oscar.h	1d89ef59b02cf5d9827df8b375fee765ac121887
+++ libpurple/protocols/oscar/oscar.h	d6e887f2bc0553a3f5073447e4b27ec3adf887b4
@@ -1304,7 +1304,7 @@ void flap_connection_destroy_chat(OscarD
 
 /* userinfo.c - displaying user information */
 
-void oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean strip_html_tags);
+void oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean use_html_status);
 void oscar_user_info_append_extra_info(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo);
 void oscar_user_info_display_error(OscarData *od, guint16 error_reason, char *buddy);
 void oscar_user_info_display_icq(OscarData *od, struct aim_icq_info *info);
============================================================
--- libpurple/protocols/oscar/userinfo.c	697f7f7995580aefe593685b29e5a078d827a8d8
+++ libpurple/protocols/oscar/userinfo.c	1fb9c439c7f6140aade72c0df698e741df26a59f
@@ -173,17 +173,17 @@ oscar_user_info_convert_and_add_hyperlin
  * @param user_info A PurpleNotifyUserInfo object to which status information will be added
  * @param b The PurpleBuddy whose status is desired. This or the aim_userinfo_t (or both) must be passed to oscar_user_info_append_status().
  * @param userinfo The aim_userinfo_t of the buddy whose status is desired. This or the PurpleBuddy (or both) must be passed to oscar_user_info_append_status().
- * @param strip_html_tags If strip_html_tags is TRUE, tags embedded in the status message will be stripped, returning a non-formatted string. The string will still be HTML escaped.
+ * @param use_html_status If TRUE, prefer HTML-formatted away message over plaintext available message.
  */
 void
-oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean strip_html_tags)
+oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean use_html_status)
 {
 	PurpleAccount *account = purple_connection_get_account(gc);
 	OscarData *od;
 	PurplePresence *presence = NULL;
 	PurpleStatus *status = NULL;
 	gchar *message = NULL, *itmsurl = NULL, *tmp;
-	gboolean is_away;
+	gboolean escaping_needed = TRUE;
 
 	od = purple_connection_get_protocol_data(gc);
 
@@ -205,9 +205,10 @@ oscar_user_info_append_status(PurpleConn
 	   the "message" attribute of the status contains only the plaintext
 	   message. */
 	if (userinfo) {
-		if ((userinfo->flags & AIM_FLAG_AWAY) && userinfo->away_len > 0 && userinfo->away != NULL && userinfo->away_encoding != NULL) {
+		if ((userinfo->flags & AIM_FLAG_AWAY) && use_html_status && userinfo->away_len > 0 && userinfo->away != NULL && userinfo->away_encoding != NULL) {
 			/* Away message */
 			message = oscar_encoding_to_utf8(userinfo->away_encoding, userinfo->away, userinfo->away_len);
+			escaping_needed = FALSE;
 		} else {
 			/*
 			 * Available message or non-HTML away message (because that's
@@ -227,44 +228,26 @@ oscar_user_info_append_status(PurpleConn
 		itmsurl = g_strdup(purple_status_get_attr_string(status, "itmsurl"));
 	}
 
-	is_away = ((status && !purple_status_is_available(status)) ||
-			   (userinfo && (userinfo->flags & AIM_FLAG_AWAY)));
-
-	if (strip_html_tags) {
-		/* Away messages are HTML, but available messages were originally plain text.
-		 * We therefore need to strip away messages but not available messages if we're asked to remove HTML tags.
-		 */
-		/*
-		 * It seems like the above comment no longer applies.  All messages need
-		 * to be escaped.
-		 */
-		if (message) {
-			gchar *tmp2;
-			tmp = purple_markup_strip_html(message);
+	if (message) {
+		tmp = oscar_util_format_string(message, purple_account_get_username(account));
+		g_free(message);
+		message = tmp;
+		if (escaping_needed) {
+			tmp = purple_markup_escape_text(message, -1);
 			g_free(message);
-			tmp2 = g_markup_escape_text(tmp, -1);
-			g_free(tmp);
-			message = tmp2;
-		}
-
-	} else {
-		if (itmsurl) {
-			tmp = g_strdup_printf("<a href=\"%s\">%s</a>",
-								  itmsurl, message);
-			g_free(message);
 			message = tmp;
 		}
 	}
-	g_free(itmsurl);
 
-	if (message) {
-		tmp = oscar_util_format_string(message, purple_account_get_username(account));
+	if (use_html_status && itmsurl) {
+		tmp = g_strdup_printf("<a href=\"%s\">%s</a>", itmsurl, message);
 		g_free(message);
 		message = tmp;
 	}
 
 	if (b) {
 		if (purple_presence_is_online(presence)) {
+			gboolean is_away = ((status && !purple_status_is_available(status)) || (userinfo && (userinfo->flags & AIM_FLAG_AWAY)));
 			if (oscar_util_valid_name_icq(purple_buddy_get_name(b)) || is_away || !message || !(*message)) {
 				/* Append the status name for online ICQ statuses, away AIM statuses, and for all buddies with no message.
 				 * If the status name and the message are the same, only show one. */
@@ -458,7 +441,7 @@ oscar_user_info_display_icq(OscarData *o
 	}
 	oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Personal Web Page"), info->email, "");
 	if (buddy != NULL)
-		oscar_user_info_append_status(gc, user_info, buddy, /* aim_userinfo_t */ NULL, /* strip_html_tags */ FALSE);
+		oscar_user_info_append_status(gc, user_info, buddy, /* aim_userinfo_t */ NULL, /* use_html_status */ TRUE);
 
 	oscar_user_info_convert_and_add(account, od, user_info, _("Additional Information"), info->info);
 	purple_notify_user_info_add_section_break(user_info);
@@ -504,7 +487,7 @@ oscar_user_info_display_aim(OscarData *o
 	PurpleNotifyUserInfo *user_info = purple_notify_user_info_new();
 	gchar *tmp = NULL, *info_utf8 = NULL, *base_profile_url = NULL;
 
-	oscar_user_info_append_status(gc, user_info, /* PurpleBuddy */ NULL, userinfo, /* strip_html_tags */ FALSE);
+	oscar_user_info_append_status(gc, user_info, /* PurpleBuddy */ NULL, userinfo, /* use_html_status */ TRUE);
 
 	if ((userinfo->present & AIM_USERINFO_PRESENT_IDLE) && userinfo->idletime != 0) {
 		tmp = purple_str_seconds_to_string(userinfo->idletime*60);


More information about the Commits mailing list