Mercurial > pidgin
comparison libpurple/protocols/jabber/buddy.c @ 29045:4e7fd81a39c6
jabber: Fix getting info on your own JID, under some circumstances.
Prosody doesn't stamp a 'from' on responses from one's own bare JID (and
the spec does not require it), so neither of these functions can rely on
'from' being non-NULL. Of course, we shouldn't be sending an NS_LAST_ACTIVITY
to our own bare JID, but that's another issue.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 14 Feb 2010 23:56:00 +0000 |
parents | b8d47ed6ceb1 |
children | f2949cd7db0a |
comparison
equal
deleted
inserted
replaced
29044:89858e3a0464 | 29045:4e7fd81a39c6 |
---|---|
978 { | 978 { |
979 char *bare_jid; | 979 char *bare_jid; |
980 char *text; | 980 char *text; |
981 char *serverside_alias = NULL; | 981 char *serverside_alias = NULL; |
982 xmlnode *vcard; | 982 xmlnode *vcard; |
983 PurpleBuddy *b; | 983 PurpleAccount *account; |
984 JabberBuddyInfo *jbi = data; | 984 JabberBuddyInfo *jbi = data; |
985 PurpleNotifyUserInfo *user_info; | 985 PurpleNotifyUserInfo *user_info; |
986 | 986 |
987 if(!jbi) | 987 g_return_if_fail(jbi != NULL); |
988 | |
989 jabber_buddy_info_remove_id(jbi, id); | |
990 | |
991 if (type == JABBER_IQ_ERROR) { | |
992 purple_debug_info("jabber", "Got error response for vCard\n"); | |
993 jabber_buddy_info_show_if_ready(jbi); | |
988 return; | 994 return; |
989 | 995 } |
990 jabber_buddy_info_remove_id(jbi, id); | |
991 | |
992 if(!from) | |
993 return; | |
994 | |
995 if(!jabber_buddy_find(js, from, FALSE)) | |
996 return; | |
997 | |
998 /* XXX: handle the error case */ | |
999 | 996 |
1000 user_info = jbi->user_info; | 997 user_info = jbi->user_info; |
1001 bare_jid = jabber_get_bare_jid(from); | 998 account = purple_connection_get_account(js->gc); |
1002 | 999 bare_jid = jabber_get_bare_jid(from ? from : purple_account_get_username(account)); |
1003 b = purple_find_buddy(js->gc->account, bare_jid); | 1000 |
1004 | 1001 /* TODO: Is the query xmlns='vcard-temp' version of this still necessary? */ |
1005 if((vcard = xmlnode_get_child(packet, "vCard")) || | 1002 if((vcard = xmlnode_get_child(packet, "vCard")) || |
1006 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | 1003 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { |
1007 xmlnode *child; | 1004 xmlnode *child; |
1008 for(child = vcard->child; child; child = child->next) | 1005 for(child = vcard->child; child; child = child->next) |
1009 { | 1006 { |
1181 img_text = g_strdup_printf("<img id='%d'>", GPOINTER_TO_INT(jbi->vcard_imgids->data)); | 1178 img_text = g_strdup_printf("<img id='%d'>", GPOINTER_TO_INT(jbi->vcard_imgids->data)); |
1182 | 1179 |
1183 purple_notify_user_info_add_pair(user_info, (photo ? _("Photo") : _("Logo")), img_text); | 1180 purple_notify_user_info_add_pair(user_info, (photo ? _("Photo") : _("Logo")), img_text); |
1184 | 1181 |
1185 hash = jabber_calculate_data_sha1sum(data, size); | 1182 hash = jabber_calculate_data_sha1sum(data, size); |
1186 purple_buddy_icons_set_for_user(js->gc->account, bare_jid, | 1183 purple_buddy_icons_set_for_user(account, bare_jid, data, size, hash); |
1187 data, size, hash); | |
1188 g_free(hash); | 1184 g_free(hash); |
1189 g_free(img_text); | 1185 g_free(img_text); |
1190 } | 1186 } |
1191 g_free(bintext); | 1187 g_free(bintext); |
1192 } | 1188 } |
1194 g_free(text); | 1190 g_free(text); |
1195 } | 1191 } |
1196 } | 1192 } |
1197 | 1193 |
1198 if (serverside_alias) { | 1194 if (serverside_alias) { |
1195 PurpleBuddy *b; | |
1199 /* If we found a serverside alias, set it and tell the core */ | 1196 /* If we found a serverside alias, set it and tell the core */ |
1200 serv_got_alias(js->gc, from, serverside_alias); | 1197 serv_got_alias(js->gc, bare_jid, serverside_alias); |
1198 b = purple_find_buddy(account, bare_jid); | |
1201 if (b) { | 1199 if (b) { |
1202 purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", serverside_alias); | 1200 purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", serverside_alias); |
1203 } | 1201 } |
1204 | 1202 |
1205 g_free(serverside_alias); | 1203 g_free(serverside_alias); |
1361 | 1359 |
1362 g_return_if_fail(jbi != NULL); | 1360 g_return_if_fail(jbi != NULL); |
1363 | 1361 |
1364 jabber_buddy_info_remove_id(jbi, id); | 1362 jabber_buddy_info_remove_id(jbi, id); |
1365 | 1363 |
1366 if(!from) | |
1367 return; | |
1368 | |
1369 if (type == JABBER_IQ_RESULT) { | 1364 if (type == JABBER_IQ_RESULT) { |
1370 if((query = xmlnode_get_child(packet, "query"))) { | 1365 if((query = xmlnode_get_child(packet, "query"))) { |
1371 seconds = xmlnode_get_attrib(query, "seconds"); | 1366 seconds = xmlnode_get_attrib(query, "seconds"); |
1372 if(seconds) { | 1367 if(seconds) { |
1373 char *end = NULL; | 1368 char *end = NULL; |
1585 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | 1580 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); |
1586 | 1581 |
1587 jabber_iq_send(iq); | 1582 jabber_iq_send(iq); |
1588 | 1583 |
1589 if (is_bare_jid) { | 1584 if (is_bare_jid) { |
1590 for(resources = jb->resources; resources; resources = resources->next) { | 1585 if (jb->resources) { |
1591 JabberBuddyResource *jbr = resources->data; | 1586 for(resources = jb->resources; resources; resources = resources->next) { |
1592 dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr); | 1587 JabberBuddyResource *jbr = resources->data; |
1588 dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr); | |
1589 } | |
1590 } else { | |
1591 /* user is offline, send a jabber:iq:last to find out last time online */ | |
1592 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_LAST_ACTIVITY); | |
1593 xmlnode_set_attrib(iq->node, "to", jid); | |
1594 jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi); | |
1595 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1596 jabber_iq_send(iq); | |
1593 } | 1597 } |
1594 } else { | 1598 } else { |
1595 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, slash + 1); | 1599 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, slash + 1); |
1596 if (jbr) | 1600 if (jbr) |
1597 dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr); | 1601 dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr); |
1598 else | 1602 else |
1599 purple_debug_warning("jabber", "jabber_buddy_get_info_for_jid() " | 1603 purple_debug_warning("jabber", "jabber_buddy_get_info_for_jid() " |
1600 "was passed JID %s, but there is no corresponding " | 1604 "was passed JID %s, but there is no corresponding " |
1601 "JabberBuddyResource!\n", jid); | 1605 "JabberBuddyResource!\n", jid); |
1602 } | |
1603 | |
1604 if (!jb->resources && is_bare_jid) { | |
1605 /* user is offline, send a jabber:iq:last to find out last time online */ | |
1606 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_LAST_ACTIVITY); | |
1607 xmlnode_set_attrib(iq->node, "to", jid); | |
1608 jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi); | |
1609 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1610 jabber_iq_send(iq); | |
1611 } | 1606 } |
1612 | 1607 |
1613 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi); | 1608 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi); |
1614 jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi); | 1609 jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi); |
1615 } | 1610 } |