pidgin: e703fb01: Factor the per-resource IQs out into the...
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Thu Jul 2 18:06:19 EDT 2009
-----------------------------------------------------------------
Revision: e703fb0151724a6fb97dff8ea67644dfe33fc922
Ancestor: e10b36824b7fe62e7645add5beca9ae060d64706
Author: darkrain42 at pidgin.im
Date: 2009-07-02T21:55:15
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e703fb0151724a6fb97dff8ea67644dfe33fc922
Modified files:
libpurple/protocols/jabber/buddy.c
ChangeLog:
Factor the per-resource IQs out into their own function.
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c f52e0adebb4cc2e7d13fc4ef3c9dbec3d970effb
+++ libpurple/protocols/jabber/buddy.c bf05b5f93ae88a7433e67e1c707db3230bc15cf5
@@ -1660,6 +1660,64 @@ static gboolean _client_is_blacklisted(J
return FALSE;
}
+static void
+dispatch_queries_for_resource(JabberStream *js, JabberBuddyInfo *jbi,
+ gboolean is_bare_jid, const char *jid,
+ JabberBuddyResource *jbr)
+{
+ JabberIq *iq;
+ JabberBuddyInfoResource *jbir;
+ char *full_jid = NULL;
+ const char *to;
+
+ g_return_if_fail(jbr->name != NULL);
+
+ if (is_bare_jid) {
+ full_jid = g_strdup_printf("%s/%s", jid, jbr->name);
+ to = full_jid;
+ } else
+ to = jid;
+
+ jbir = g_new0(JabberBuddyInfoResource, 1);
+ g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir);
+
+ if(!jbr->client.name) {
+ iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version");
+ xmlnode_set_attrib(iq->node, "to", to);
+ jabber_iq_set_callback(iq, jabber_version_parse, jbi);
+ jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
+ jabber_iq_send(iq);
+ }
+
+ /* this is to fix the feeling of irritation I get when trying
+ * to get info on a friend running Trillian, which doesn't
+ * respond (with an error or otherwise) to jabber:iq:last
+ * requests. There are a number of Trillian users in my
+ * office. */
+ if(!_client_is_blacklisted(jbr, "jabber:iq:last")) {
+ iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
+ xmlnode_set_attrib(iq->node, "to", to);
+ jabber_iq_set_callback(iq, jabber_last_parse, jbi);
+ jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
+ jabber_iq_send(iq);
+ }
+
+ if (jbr->tz_off == PURPLE_NO_TZ_OFF &&
+ (!jbr->caps.info ||
+ jabber_resource_has_capability(jbr, "urn:xmpp:time"))) {
+ xmlnode *child;
+ iq = jabber_iq_new(js, JABBER_IQ_GET);
+ xmlnode_set_attrib(iq->node, "to", to);
+ child = xmlnode_new_child(iq->node, "time");
+ xmlnode_set_namespace(child, "urn:xmpp:time");
+ jabber_iq_set_callback(iq, jabber_time_parse, jbi);
+ jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
+ jabber_iq_send(iq);
+ }
+
+ g_free(full_jid);
+}
+
static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *jid)
{
JabberIq *iq;
@@ -1667,6 +1725,7 @@ static void jabber_buddy_get_info_for_ji
GList *resources;
JabberBuddy *jb;
JabberBuddyInfo *jbi;
+ gboolean is_bare_jid;
jb = jabber_buddy_find(js, jid, TRUE);
@@ -1674,6 +1733,8 @@ static void jabber_buddy_get_info_for_ji
if(!jb)
return;
+ is_bare_jid = (strchr(jid, '/') == NULL);
+
jbi = g_new0(JabberBuddyInfo, 1);
jbi->jid = g_strdup(jid);
jbi->js = js;
@@ -1695,59 +1756,10 @@ static void jabber_buddy_get_info_for_ji
for(resources = jb->resources; resources; resources = resources->next)
{
JabberBuddyResource *jbr = resources->data;
- JabberBuddyInfoResource *jbir;
- char *full_jid;
-
- if ((strchr(jid, '/') == NULL) && (jbr->name != NULL)) {
- full_jid = g_strdup_printf("%s/%s", jid, jbr->name);
- } else {
- full_jid = g_strdup(jid);
- }
-
- if (jbr->name != NULL)
- {
- jbir = g_new0(JabberBuddyInfoResource, 1);
- g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir);
- }
-
- if(!jbr->client.name) {
- iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version");
- xmlnode_set_attrib(iq->node, "to", full_jid);
- jabber_iq_set_callback(iq, jabber_version_parse, jbi);
- jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
- jabber_iq_send(iq);
- }
-
- /* this is to fix the feeling of irritation I get when trying
- * to get info on a friend running Trillian, which doesn't
- * respond (with an error or otherwise) to jabber:iq:last
- * requests. There are a number of Trillian users in my
- * office. */
- if(!_client_is_blacklisted(jbr, "jabber:iq:last")) {
- iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
- xmlnode_set_attrib(iq->node, "to", full_jid);
- jabber_iq_set_callback(iq, jabber_last_parse, jbi);
- jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
- jabber_iq_send(iq);
- }
-
- if (jbr->tz_off == PURPLE_NO_TZ_OFF &&
- (!jbr->caps.info ||
- jabber_resource_has_capability(jbr, "urn:xmpp:time"))) {
- xmlnode *child;
- iq = jabber_iq_new(js, JABBER_IQ_GET);
- xmlnode_set_attrib(iq->node, "to", full_jid);
- child = xmlnode_new_child(iq->node, "time");
- xmlnode_set_namespace(child, "urn:xmpp:time");
- jabber_iq_set_callback(iq, jabber_time_parse, jbi);
- jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
- jabber_iq_send(iq);
- }
-
- g_free(full_jid);
+ dispatch_queries_for_resource(js, jbi, is_bare_jid, jid, jbr);
}
- if (!jb->resources && strchr(jid, '/') == NULL) {
+ if (!jb->resources && is_bare_jid) {
/* user is offline, send a jabber:iq:last to find out last time online */
iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
xmlnode_set_attrib(iq->node, "to", jid);
More information about the Commits
mailing list