pidgin: fa0b8fdb: jabber: Fix setting Google Talk avatar a...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri Jul 31 23:00:49 EDT 2009


-----------------------------------------------------------------
Revision: fa0b8fdbb0ceb27d29b56339657f490eb6a0f4d8
Ancestor: 20e16d28b924016a1310911f9b12376bba9a9859
Author: darkrain42 at pidgin.im
Date: 2009-08-01T01:53:02
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/fa0b8fdbb0ceb27d29b56339657f490eb6a0f4d8

Modified files:
        libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h

ChangeLog: 

jabber: Fix setting Google Talk avatar at login.

Google Talk (at some point) started returning IQ errors when setting
the avatar in the first 10 seconds of login. This was reported by
Bill Lovett to the jdev mailing list and he included the 10-second
"magic number".

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	25c2c2d0966767c9bc198afa9a297a347c7898a8
+++ libpurple/protocols/jabber/buddy.c	cea44f1f631bf38134388d49be6b5c0af910fd35
@@ -463,6 +463,11 @@ void jabber_set_info(PurpleConnection *g
 	if(!js->vcard_fetched)
 		return;
 
+	if (js->vcard_timer) {
+		purple_timeout_remove(js->vcard_timer);
+		js->vcard_timer = 0;
+	}
+
 	g_free(js->avatar_hash);
 	js->avatar_hash = NULL;
 
@@ -854,12 +859,26 @@ static void jabber_buddy_info_remove_id(
 	}
 }
 
+static gboolean
+set_own_vcard_cb(gpointer data)
+{
+	JabberStream *js = data;
+	PurpleAccount *account = purple_connection_get_account(js->gc);
+
+	js->vcard_timer = 0;
+
+	jabber_set_info(js->gc, purple_account_get_user_info(account));
+
+	return FALSE;
+}
+
 static void jabber_vcard_save_mine(JabberStream *js, const char *from,
                                    JabberIqType type, const char *id,
                                    xmlnode *packet, gpointer data)
 {
 	xmlnode *vcard, *photo, *binval;
 	char *txt, *vcard_hash = NULL;
+	PurpleAccount *account;
 
 	if (type == JABBER_IQ_ERROR) {
 		xmlnode *error;
@@ -870,12 +889,13 @@ static void jabber_vcard_save_mine(Jabbe
 			return;
 	}
 
+	account = purple_connection_get_account(js->gc);
+
 	if((vcard = xmlnode_get_child(packet, "vCard")) ||
 			(vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp")))
 	{
 		txt = xmlnode_to_str(vcard, NULL);
-		purple_account_set_user_info(purple_connection_get_account(js->gc), txt);
-
+		purple_account_set_user_info(account, txt);
 		g_free(txt);
 	} else {
 		/* if we have no vCard, then lets not overwrite what we might have locally */
@@ -898,8 +918,17 @@ static void jabber_vcard_save_mine(Jabbe
 
 	/* Republish our vcard if the photo is different than the server's */
 	if (!purple_strequal(vcard_hash, js->initial_avatar_hash)) {
-		PurpleAccount *account = purple_connection_get_account(js->gc);
-		jabber_set_info(js->gc, purple_account_get_user_info(account));
+		/*
+		 * Google Talk has developed the behavior that it will not accept
+		 * a vcard set in the first 10 seconds (or so) of the connection;
+		 * it returns an error (namespaces trimmed):
+		 * <error code="500" type="wait"><internal-server-error/></error>.
+		 */
+		if (js->googletalk)
+			js->vcard_timer = purple_timeout_add_seconds(10, set_own_vcard_cb,
+			                                             js);
+		else
+			jabber_set_info(js->gc, purple_account_get_user_info(account));
 	} else if (js->initial_avatar_hash) {
 		/* Our photo is in the vcard, so advertise vcard-temp updates */
 		js->avatar_hash = g_strdup(js->initial_avatar_hash);
============================================================
--- libpurple/protocols/jabber/jabber.c	d196d8b1ebb9b20da53002692479e3457aa74642
+++ libpurple/protocols/jabber/jabber.c	2b543a314ceb7b86ed1082aca5e103b6aba99dc4
@@ -1542,6 +1542,9 @@ void jabber_close(PurpleConnection *gc)
 	g_free(js->old_track);
 	g_free(js->expected_rspauth);
 
+	if (js->vcard_timer != 0)
+		purple_timeout_remove(js->vcard_timer);
+
 	if (js->keepalive_timeout != 0)
 		purple_timeout_remove(js->keepalive_timeout);
 
============================================================
--- libpurple/protocols/jabber/jabber.h	d16e3384ede5f9248c20add294e58cdba253a6c7
+++ libpurple/protocols/jabber/jabber.h	9564ef082393c764d9942138b860ded2f4076d1b
@@ -214,6 +214,8 @@ struct _JabberStream
 	void *unregistration_user_data;
 
 	gboolean vcard_fetched;
+	/* Timer at login to push updated avatar */
+	guint vcard_timer;
 
 	/* Entity Capabilities hash */
 	char *caps_hash;


More information about the Commits mailing list