Mercurial > pidgin
comparison libpurple/protocols/jabber/buddy.c @ 27251:c408e4dc3101
Factor the per-resource IQs out into their own function.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Thu, 02 Jul 2009 21:55:15 +0000 |
parents | 291724375feb |
children | ea9df9bfa921 |
comparison
equal
deleted
inserted
replaced
27250:19a1e7d9a039 | 27251:c408e4dc3101 |
---|---|
1658 } | 1658 } |
1659 | 1659 |
1660 return FALSE; | 1660 return FALSE; |
1661 } | 1661 } |
1662 | 1662 |
1663 static void | |
1664 dispatch_queries_for_resource(JabberStream *js, JabberBuddyInfo *jbi, | |
1665 gboolean is_bare_jid, const char *jid, | |
1666 JabberBuddyResource *jbr) | |
1667 { | |
1668 JabberIq *iq; | |
1669 JabberBuddyInfoResource *jbir; | |
1670 char *full_jid = NULL; | |
1671 const char *to; | |
1672 | |
1673 g_return_if_fail(jbr->name != NULL); | |
1674 | |
1675 if (is_bare_jid) { | |
1676 full_jid = g_strdup_printf("%s/%s", jid, jbr->name); | |
1677 to = full_jid; | |
1678 } else | |
1679 to = jid; | |
1680 | |
1681 jbir = g_new0(JabberBuddyInfoResource, 1); | |
1682 g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir); | |
1683 | |
1684 if(!jbr->client.name) { | |
1685 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version"); | |
1686 xmlnode_set_attrib(iq->node, "to", to); | |
1687 jabber_iq_set_callback(iq, jabber_version_parse, jbi); | |
1688 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1689 jabber_iq_send(iq); | |
1690 } | |
1691 | |
1692 /* this is to fix the feeling of irritation I get when trying | |
1693 * to get info on a friend running Trillian, which doesn't | |
1694 * respond (with an error or otherwise) to jabber:iq:last | |
1695 * requests. There are a number of Trillian users in my | |
1696 * office. */ | |
1697 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { | |
1698 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); | |
1699 xmlnode_set_attrib(iq->node, "to", to); | |
1700 jabber_iq_set_callback(iq, jabber_last_parse, jbi); | |
1701 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1702 jabber_iq_send(iq); | |
1703 } | |
1704 | |
1705 if (jbr->tz_off == PURPLE_NO_TZ_OFF && | |
1706 (!jbr->caps.info || | |
1707 jabber_resource_has_capability(jbr, "urn:xmpp:time"))) { | |
1708 xmlnode *child; | |
1709 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
1710 xmlnode_set_attrib(iq->node, "to", to); | |
1711 child = xmlnode_new_child(iq->node, "time"); | |
1712 xmlnode_set_namespace(child, "urn:xmpp:time"); | |
1713 jabber_iq_set_callback(iq, jabber_time_parse, jbi); | |
1714 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1715 jabber_iq_send(iq); | |
1716 } | |
1717 | |
1718 g_free(full_jid); | |
1719 } | |
1720 | |
1663 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *jid) | 1721 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *jid) |
1664 { | 1722 { |
1665 JabberIq *iq; | 1723 JabberIq *iq; |
1666 xmlnode *vcard; | 1724 xmlnode *vcard; |
1667 GList *resources; | 1725 GList *resources; |
1668 JabberBuddy *jb; | 1726 JabberBuddy *jb; |
1669 JabberBuddyInfo *jbi; | 1727 JabberBuddyInfo *jbi; |
1728 gboolean is_bare_jid; | |
1670 | 1729 |
1671 jb = jabber_buddy_find(js, jid, TRUE); | 1730 jb = jabber_buddy_find(js, jid, TRUE); |
1672 | 1731 |
1673 /* invalid JID */ | 1732 /* invalid JID */ |
1674 if(!jb) | 1733 if(!jb) |
1675 return; | 1734 return; |
1735 | |
1736 is_bare_jid = (strchr(jid, '/') == NULL); | |
1676 | 1737 |
1677 jbi = g_new0(JabberBuddyInfo, 1); | 1738 jbi = g_new0(JabberBuddyInfo, 1); |
1678 jbi->jid = g_strdup(jid); | 1739 jbi->jid = g_strdup(jid); |
1679 jbi->js = js; | 1740 jbi->js = js; |
1680 jbi->jb = jb; | 1741 jbi->jb = jb; |
1693 jabber_iq_send(iq); | 1754 jabber_iq_send(iq); |
1694 | 1755 |
1695 for(resources = jb->resources; resources; resources = resources->next) | 1756 for(resources = jb->resources; resources; resources = resources->next) |
1696 { | 1757 { |
1697 JabberBuddyResource *jbr = resources->data; | 1758 JabberBuddyResource *jbr = resources->data; |
1698 JabberBuddyInfoResource *jbir; | 1759 dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr); |
1699 char *full_jid; | 1760 } |
1700 | 1761 |
1701 if ((strchr(jid, '/') == NULL) && (jbr->name != NULL)) { | 1762 if (!jb->resources && is_bare_jid) { |
1702 full_jid = g_strdup_printf("%s/%s", jid, jbr->name); | |
1703 } else { | |
1704 full_jid = g_strdup(jid); | |
1705 } | |
1706 | |
1707 if (jbr->name != NULL) | |
1708 { | |
1709 jbir = g_new0(JabberBuddyInfoResource, 1); | |
1710 g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir); | |
1711 } | |
1712 | |
1713 if(!jbr->client.name) { | |
1714 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version"); | |
1715 xmlnode_set_attrib(iq->node, "to", full_jid); | |
1716 jabber_iq_set_callback(iq, jabber_version_parse, jbi); | |
1717 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1718 jabber_iq_send(iq); | |
1719 } | |
1720 | |
1721 /* this is to fix the feeling of irritation I get when trying | |
1722 * to get info on a friend running Trillian, which doesn't | |
1723 * respond (with an error or otherwise) to jabber:iq:last | |
1724 * requests. There are a number of Trillian users in my | |
1725 * office. */ | |
1726 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { | |
1727 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); | |
1728 xmlnode_set_attrib(iq->node, "to", full_jid); | |
1729 jabber_iq_set_callback(iq, jabber_last_parse, jbi); | |
1730 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1731 jabber_iq_send(iq); | |
1732 } | |
1733 | |
1734 if (jbr->tz_off == PURPLE_NO_TZ_OFF && | |
1735 (!jbr->caps.info || | |
1736 jabber_resource_has_capability(jbr, "urn:xmpp:time"))) { | |
1737 xmlnode *child; | |
1738 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
1739 xmlnode_set_attrib(iq->node, "to", full_jid); | |
1740 child = xmlnode_new_child(iq->node, "time"); | |
1741 xmlnode_set_namespace(child, "urn:xmpp:time"); | |
1742 jabber_iq_set_callback(iq, jabber_time_parse, jbi); | |
1743 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
1744 jabber_iq_send(iq); | |
1745 } | |
1746 | |
1747 g_free(full_jid); | |
1748 } | |
1749 | |
1750 if (!jb->resources && strchr(jid, '/') == NULL) { | |
1751 /* user is offline, send a jabber:iq:last to find out last time online */ | 1763 /* user is offline, send a jabber:iq:last to find out last time online */ |
1752 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); | 1764 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); |
1753 xmlnode_set_attrib(iq->node, "to", jid); | 1765 xmlnode_set_attrib(iq->node, "to", jid); |
1754 jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi); | 1766 jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi); |
1755 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | 1767 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); |