changeset 29149:9ab75ab032b4

jabber: The google roster request code was so lonely, so let's just drop-kick it and add the little custom logic to roster.c
author Paul Aurich <paul@darkrain42.org>
date Sun, 06 Dec 2009 22:44:20 +0000
parents 4e9a36bdda0f
children 4cb8d0fcfd2f
files libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/google.c libpurple/protocols/jabber/google.h libpurple/protocols/jabber/namespaces.h libpurple/protocols/jabber/roster.c
diffstat 5 files changed, 15 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/disco.c	Sun Dec 06 19:26:52 2009 +0000
+++ b/libpurple/protocols/jabber/disco.c	Sun Dec 06 22:44:20 2009 +0000
@@ -370,10 +370,8 @@
 	if (js->pep)
 		jabber_avatar_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);
-	}
+	/* Yes, please! */
+	jabber_roster_request(js);
 
 	if (js->server_caps & JABBER_CAP_ADHOC) {
 		/* The server supports ad-hoc commands, so let's request the list */
@@ -555,9 +553,8 @@
 		if (!strcmp(NS_GOOGLE_MAIL_NOTIFY, var)) {
 			js->server_caps |= JABBER_CAP_GMAIL_NOTIFY;
 			jabber_gmail_init(js);
-		} else if (!strcmp("google:roster", var)) {
+		} else if (!strcmp(NS_GOOGLE_ROSTER, var)) {
 			js->server_caps |= JABBER_CAP_GOOGLE_ROSTER;
-			jabber_google_roster_init(js);
 		} else if (!strcmp("http://jabber.org/protocol/commands", var)) {
 			js->server_caps |= JABBER_CAP_ADHOC;
 		} else if (!strcmp(NS_SIMPLE_BLOCKING, var)) {
--- a/libpurple/protocols/jabber/google.c	Sun Dec 06 19:26:52 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Sun Dec 06 22:44:20 2009 +0000
@@ -950,33 +950,6 @@
 	jabber_iq_send(iq);
 }
 
-static void
-roster_init_cb(JabberStream *js, const char *from, JabberIqType type,
-               const char *id, xmlnode *packet, gpointer data)
-{
-	xmlnode *query = xmlnode_get_child(packet, "query");
-
-	if (type == JABBER_IQ_RESULT && query)
-		jabber_roster_parse(js, from, type, id, query);
-
-	jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
-}
-
-void jabber_google_roster_init(JabberStream *js)
-{
-	JabberIq *iq;
-	xmlnode *query;
-
-	iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster");
-	query = xmlnode_get_child(iq->node, "query");
-
-	xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
-	xmlnode_set_attrib(query, "gr:ext", "2");
-
-	jabber_iq_set_callback(iq, roster_init_cb, NULL);
-	jabber_iq_send(iq);
-}
-
 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item)
 {
 	PurpleAccount *account = purple_connection_get_account(js->gc);
@@ -986,7 +959,7 @@
 
 	while (list) {
 		if (!strcmp(jid_norm, (char*)list->data)) {
-			xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
+			xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
 			xmlnode_set_attrib(query, "gr:ext", "2");
 			xmlnode_set_attrib(item, "gr:t", "B");
 			return;
@@ -1003,7 +976,7 @@
 
 	char *jid_norm;
 
-	const char *grt = xmlnode_get_attrib_with_namespace(item, "t", "google:roster");
+	const char *grt = xmlnode_get_attrib_with_namespace(item, "t", NS_GOOGLE_ROSTER);
 	const char *subscription = xmlnode_get_attrib(item, "subscription");
 	const char *ask = xmlnode_get_attrib(item, "ask");
 
@@ -1088,7 +1061,7 @@
 	xmlnode_set_attrib(item, "jid", who);
 	xmlnode_set_attrib(item, "name", balias ? balias : "");
 	xmlnode_set_attrib(item, "gr:t", "B");
-	xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
+	xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
 	xmlnode_set_attrib(query, "gr:ext", "2");
 
 	jabber_iq_send(iq);
@@ -1147,7 +1120,7 @@
 	balias = purple_buddy_get_local_buddy_alias(b);
 	xmlnode_set_attrib(item, "jid", who);
 	xmlnode_set_attrib(item, "name", balias ? balias : "");
-	xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
+	xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
 	xmlnode_set_attrib(query, "gr:ext", "2");
 
 	jabber_iq_send(iq);
--- a/libpurple/protocols/jabber/google.h	Sun Dec 06 19:26:52 2009 +0000
+++ b/libpurple/protocols/jabber/google.h	Sun Dec 06 22:44:20 2009 +0000
@@ -32,7 +32,6 @@
 void jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
                        const char *id, xmlnode *new_mail);
 
-void jabber_google_roster_init(JabberStream *js);
 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item);
 
 /* Returns FALSE if this should short-circuit processing of this roster item, or TRUE
--- a/libpurple/protocols/jabber/namespaces.h	Sun Dec 06 19:26:52 2009 +0000
+++ b/libpurple/protocols/jabber/namespaces.h	Sun Dec 06 22:44:20 2009 +0000
@@ -95,6 +95,7 @@
 #define NS_GOOGLE_JINGLE_INFO "google:jingleinfo"
 
 #define NS_GOOGLE_MAIL_NOTIFY "google:mail:notify"
+#define NS_GOOGLE_ROSTER "google:roster"
 
 #define NS_GOOGLE_PROTOCOL_SESSION "http://www.google.com/xmpp/protocol/session"
 #define NS_GOOGLE_SESSION "http://www.google.com/session"
--- a/libpurple/protocols/jabber/roster.c	Sun Dec 06 19:26:52 2009 +0000
+++ b/libpurple/protocols/jabber/roster.c	Sun Dec 06 22:44:20 2009 +0000
@@ -87,8 +87,13 @@
 	iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster");
 	query = xmlnode_get_child(iq->node, "query");
 	xmlnode_set_attrib(query, "ver", ver);
+
+	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) {
+		xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
+		xmlnode_set_attrib(query, "gr:ext", "2");
+	}
+
 	jabber_iq_set_callback(iq, roster_request_cb, NULL);
-
 	jabber_iq_send(iq);
 }
 
@@ -334,7 +339,7 @@
 
 	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) {
 		jabber_google_roster_outgoing(js, query, item);
-		xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
+		xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
 		xmlnode_set_attrib(query, "gr:ext", "2");
 	}
 	jabber_iq_send(iq);