pidgin: 303af74a: Woo boy this function is a little crazy....

markdoliner at pidgin.im markdoliner at pidgin.im
Thu Mar 5 18:55:32 EST 2009


-----------------------------------------------------------------
Revision: 303af74a38e7b313d4fb0be4d4054a16cb13d819
Ancestor: ccb8d092a7dafef1f0bd31ddff1d73dbf0bfe1a3
Author: markdoliner at pidgin.im
Date: 2009-03-05T23:54:50
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/303af74a38e7b313d4fb0be4d4054a16cb13d819

Modified files:
        libpurple/protocols/oscar/oscar.c

ChangeLog: 

Woo boy this function is a little crazy.  I shuffled some things around:
1. We now call aim_srv_setextrainfo() after aim_locate_setprofile()  This
   fixes the bug where, if you set an available message, then set an
   away message, then change your state to available but leave the same
   away message up, the AIM servers would use your old available message.
   I'm not really sure why it happens... maybe some sort of race condition
   in how the server parses our requests.  In any case, this fixes it, and
   it's what the official clients seem to do (or AIM Lite at least)
2. Combine the code for stripping HTML and truncating the available
   message.  It was happening in two places before (one for available
   messages and another for ICQ away messages)
3. Put our away message in the field we've been calling an "available"
   message.  This seems to be what the official clients do.  Or AIM Lite
   at least.  I'm not sure if there will be other side effects.

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c	a89878800e75c7bba6f7de98966ef919876c687c
+++ libpurple/protocols/oscar/oscar.c	0d45664f454a1e315f72c9317ff2bf7536651066
@@ -4738,16 +4738,17 @@ oscar_set_info_and_status(PurpleAccount 
 	PurpleStatusType *status_type;
 	PurpleStatusPrimitive primitive;
 
-	char *htmlinfo;
 	char *info_encoding = NULL;
 	char *info = NULL;
 	gsize infolen = 0;
 
-	const char *htmlaway;
 	char *away_encoding = NULL;
 	char *away = NULL;
 	gsize awaylen = 0;
 
+	char *status_text = NULL;
+	const char *itmsurl = NULL;
+
 	status_type = purple_status_get_type(status);
 	primitive = purple_status_type_get_primitive(status_type);
 
@@ -4765,7 +4766,7 @@ oscar_set_info_and_status(PurpleAccount 
 	}
 	else if (rawinfo != NULL)
 	{
-		htmlinfo = purple_strdup_withhtml(rawinfo);
+		char *htmlinfo = purple_strdup_withhtml(rawinfo);
 		info = purple_prpl_oscar_convert_to_infotext(htmlinfo, &infolen, &info_encoding);
 		g_free(htmlinfo);
 
@@ -4782,85 +4783,71 @@ oscar_set_info_and_status(PurpleAccount 
 		}
 	}
 
-	if (!setstatus)
+	if (setstatus)
 	{
-		/* Do nothing! */
-	}
-	else if (primitive == PURPLE_STATUS_AVAILABLE || primitive == PURPLE_STATUS_INVISIBLE)
-	{
-		const char *status_html, *itmsurl;
-		char *status_text = NULL;
+		const char *status_html;
 
 		status_html = purple_status_get_attr_string(status, "message");
-		if (status_html != NULL)
+
+		if (primitive == PURPLE_STATUS_AVAILABLE || primitive == PURPLE_STATUS_INVISIBLE)
 		{
-			status_text = purple_markup_strip_html(status_html);
-			/* If the status_text is longer than 251 characters then truncate it */
-			if (strlen(status_text) > MAXAVAILMSGLEN)
+			/* This is needed for us to un-set any previous away message. */
+			away = g_strdup("");
+		}
+		else
+		{
+			gchar *linkified;
+
+			/* We do this for icq too so that they work for old third party clients */
+			linkified = purple_markup_linkify(status_html);
+			away = purple_prpl_oscar_convert_to_infotext(linkified, &awaylen, &away_encoding);
+			g_free(linkified);
+
+			if (awaylen > od->rights.maxawaymsglen)
 			{
-				char *tmp = g_utf8_find_prev_char(status_text, &status_text[MAXAVAILMSGLEN - 2]);
-				strcpy(tmp, "...");
+				gchar *errstr;
+
+				errstr = g_strdup_printf(dngettext(PACKAGE, "The maximum away message length of %d byte "
+										 "has been exceeded.  It has been truncated for you.",
+										 "The maximum away message length of %d bytes "
+										 "has been exceeded.  It has been truncated for you.",
+										 od->rights.maxawaymsglen), od->rights.maxawaymsglen);
+				purple_notify_warning(gc, NULL, _("Away message too long."), errstr);
+				g_free(errstr);
 			}
 		}
-		itmsurl = purple_status_get_attr_string(status, "itmsurl");
+	}
 
-		aim_srv_setextrainfo(od, FALSE, 0, TRUE, status_text, itmsurl);
-		g_free(status_text);
+	aim_locate_setprofile(od,
+			info_encoding, info, MIN(infolen, od->rights.maxsiglen),
+			away_encoding, away, MIN(awaylen, od->rights.maxawaymsglen));
+	g_free(info);
+	g_free(away);
 
-		/* This is needed for us to un-set any previous away message. */
-		away = g_strdup("");
-	}
-	else
+	if (setstatus)
 	{
-		gchar *linkified;
+		const char *status_html;
 
-		htmlaway = purple_status_get_attr_string(status, "message");
-		if ((htmlaway == NULL) || (*htmlaway == '\0'))
-			htmlaway = purple_status_type_get_name(status_type);
-
-		/* ICQ 6.x seems to use an available message for all statuses so set one */
-		if (od->icq)
+		status_html = purple_status_get_attr_string(status, "message");
+		if (od->icq && (status_html == NULL || status_html[0] == '\0'))
+			status_html = purple_status_type_get_name(status_type);
+		if (status_html != NULL)
 		{
-			char *status_text;
-
-			status_text = purple_markup_strip_html(htmlaway);
-
+			status_text = purple_markup_strip_html(status_html);
 			/* If the status_text is longer than 251 characters then truncate it */
 			if (strlen(status_text) > MAXAVAILMSGLEN)
 			{
 				char *tmp = g_utf8_find_prev_char(status_text, &status_text[MAXAVAILMSGLEN - 2]);
 				strcpy(tmp, "...");
 			}
-			aim_srv_setextrainfo(od, FALSE, 0, TRUE, status_text, NULL);
-			g_free(status_text);
 		}
 
-		/* Set a proper away message for icq too so that they work for old third party clients */
-		linkified = purple_markup_linkify(htmlaway);
-		away = purple_prpl_oscar_convert_to_infotext(linkified, &awaylen, &away_encoding);
-		g_free(linkified);
+		itmsurl = purple_status_get_attr_string(status, "itmsurl");
 
-		if (awaylen > od->rights.maxawaymsglen)
-		{
-			gchar *errstr;
-
-			errstr = g_strdup_printf(dngettext(PACKAGE, "The maximum away message length of %d byte "
-									 "has been exceeded.  It has been truncated for you.",
-									 "The maximum away message length of %d bytes "
-									 "has been exceeded.  It has been truncated for you.",
-									 od->rights.maxawaymsglen), od->rights.maxawaymsglen);
-			purple_notify_warning(gc, NULL, _("Away message too long."), errstr);
-			g_free(errstr);
-		}
-	}
-
-	if (setstatus)
+		/* TODO: Combine these two calls! */
+		aim_srv_setextrainfo(od, FALSE, 0, TRUE, status_text, itmsurl);
 		oscar_set_extendedstatus(gc);
-
-	aim_locate_setprofile(od, info_encoding, info, MIN(infolen, od->rights.maxsiglen),
-									away_encoding, away, MIN(awaylen, od->rights.maxawaymsglen));
-	g_free(info);
-	g_free(away);
+	}
 }
 
 static void


More information about the Commits mailing list