changeset 18163:703872bf33c6

server-side jabber vcards now take precedence over local vcards, so we no longer overwrite things we shouldn't (fixes #1013)
author Nathan Walp <nwalp@pidgin.im>
date Sun, 17 Jun 2007 15:27:35 +0000
parents 2b8460b599ea
children 1100b05e9fb7
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/buddy.h libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h
diffstat 5 files changed, 51 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Sun Jun 17 15:09:05 2007 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sun Jun 17 15:27:35 2007 +0000
@@ -385,6 +385,11 @@
 	xmlnode *vc_node;
 	struct tag_attr *tag_attr;
 
+	/* if we have't grabbed the remote vcard yet, we can't
+	 * assume that what we have here is correct */
+	if(!js->vcard_fetched)
+		return;
+
 	g_free(js->avatar_hash);
 	js->avatar_hash = NULL;
 
@@ -734,6 +739,40 @@
 	}
 }
 
+static void jabber_vcard_save_mine(JabberStream *js, xmlnode *packet, gpointer data)
+{
+	xmlnode *vcard;
+	char *txt;
+	PurpleStoredImage *img;
+
+	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);
+
+		g_free(txt);
+	} else {
+		/* if we have no vCard, then lets not overwrite what we might have locally */
+	}
+
+	js->vcard_fetched = TRUE;
+
+	if(NULL != (img = purple_buddy_icons_find_account_icon(js->gc->account))) {
+		jabber_set_buddy_icon(js->gc, img);
+		purple_imgstore_unref(img);
+	}
+}
+
+void jabber_vcard_fetch_mine(JabberStream *js)
+{
+	JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, "vcard-temp");
+
+	jabber_iq_set_callback(iq, jabber_vcard_save_mine, NULL);
+
+	jabber_iq_send(iq);
+}
+
 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data)
 {
 	const char *id, *from;
--- a/libpurple/protocols/jabber/buddy.h	Sun Jun 17 15:09:05 2007 +0000
+++ b/libpurple/protocols/jabber/buddy.h	Sun Jun 17 15:27:35 2007 +0000
@@ -103,4 +103,6 @@
 
 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js);
 
+void jabber_vcard_fetch_mine(JabberStream *js);
+
 #endif /* _PURPLE_JABBER_BUDDY_H_ */
--- a/libpurple/protocols/jabber/disco.c	Sun Jun 17 15:09:05 2007 +0000
+++ b/libpurple/protocols/jabber/disco.c	Sun Jun 17 15:27:35 2007 +0000
@@ -218,6 +218,9 @@
 static void
 jabber_disco_finish_server_info_result_cb(JabberStream *js)
 {
+
+	jabber_vcard_fetch_mine(js);
+
 	if (!(js->server_caps & JABBER_CAP_GOOGLE_ROSTER)) {
 		/* If the server supports JABBER_CAP_GOOGLE_ROSTER; we will have already requested it */
 		jabber_roster_request(js);
--- a/libpurple/protocols/jabber/jabber.c	Sun Jun 17 15:09:05 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sun Jun 17 15:27:35 2007 +0000
@@ -1038,8 +1038,6 @@
 
 void jabber_stream_set_state(JabberStream *js, JabberStreamState state)
 {
-	PurpleStoredImage *img;
-
 	js->state = state;
 	switch(state) {
 		case JABBER_STREAM_OFFLINE:
@@ -1071,14 +1069,6 @@
 
 			break;
 		case JABBER_STREAM_CONNECTED:
-			/* lets make sure our buddy icon is up to date
-			 * before we go letting people know we're here */
-			img = purple_buddy_icons_find_account_icon(js->gc->account);
-			if(NULL != img) {
-				jabber_set_buddy_icon(js->gc, img);
-				purple_imgstore_unref(img);
-			}
-
 			/* now we can alert the core that we're ready to send status */
 			purple_connection_set_state(js->gc, PURPLE_CONNECTED);
 			jabber_disco_items_server(js);
--- a/libpurple/protocols/jabber/jabber.h	Sun Jun 17 15:09:05 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sun Jun 17 15:27:35 2007 +0000
@@ -142,11 +142,17 @@
 #ifdef HAVE_CYRUS_SASL
 	sasl_conn_t *sasl;
 	sasl_callback_t *sasl_cb;
+#else /* keep the struct the same size */
+	void *sasl;
+	void *sasl_cb;
+#endif
+
 	int sasl_state;
 	int sasl_maxbuf;
 	GString *sasl_mechs;
 	char *serverFQDN;
-#endif
+
+	gboolean vcard_fetched;
 
 } JabberStream;