changeset 27033:10c91922bc1e

Support pushed notifications about XEP-0191 Blocks/Unblocks. Closes #8045. Recompiling jabberd2 from scratch magically made the pushes work, so I was able to test this and it works, except for causing a crash in jabberd2 that Mark already fixed. :)
author Paul Aurich <paul@darkrain42.org>
date Tue, 26 May 2009 23:44:55 +0000
parents d9f2a7f18759
children 1dcee141997d
files libpurple/protocols/jabber/iq.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h
diffstat 3 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/iq.c	Mon May 25 20:13:01 2009 +0000
+++ b/libpurple/protocols/jabber/iq.c	Tue May 26 23:44:55 2009 +0000
@@ -495,6 +495,8 @@
 	jabber_iq_register_handler("session", "http://www.google.com/session",
 		jabber_google_session_parse);
 #endif
+	jabber_iq_register_handler("block", "urn:xmpp:blocking", jabber_blocklist_parse_push);
+	jabber_iq_register_handler("unblock", "urn:xmpp:blocking", jabber_blocklist_parse_push);
 	jabber_iq_register_handler("time", "urn:xmpp:time", jabber_iq_time_parse);
 
 }
--- a/libpurple/protocols/jabber/jabber.c	Mon May 25 20:13:01 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue May 26 23:44:55 2009 +0000
@@ -1652,6 +1652,59 @@
 	jabber_presence_send(js, FALSE);
 }
 
+void jabber_blocklist_parse_push(JabberStream *js, const char *from,
+                                 JabberIqType type, const char *id,
+                                 xmlnode *child)
+{
+	JabberIq *result;
+	xmlnode *item;
+	PurpleAccount *account;
+	gboolean is_block;
+
+	if (!jabber_is_own_account(js, from)) {
+		xmlnode *error, *x;
+		result = jabber_iq_new(js, JABBER_IQ_ERROR);
+		xmlnode_set_attrib(result->node, "id", id);
+		xmlnode_set_attrib(result->node, "to", from);
+
+		error = xmlnode_new_child(result->node, "error");
+		xmlnode_set_attrib(error, "type", "cancel");
+		x = xmlnode_new_child(error, "not-allowed");
+		xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas");
+
+		jabber_iq_send(result);
+		return;
+	}
+
+	account = purple_connection_get_account(js->gc);
+	is_block = g_str_equal(child->name, "block");
+
+	item = xmlnode_get_child(child, "item");
+	if (!is_block && item == NULL) {
+		/* Unblock everyone */
+		purple_debug_info("jabber", "Received unblock push. Unblocking everyone.\n");
+
+		while (account->deny != NULL) {
+			purple_privacy_deny_remove(account, account->deny->data, TRUE);
+		}
+	} else {
+		for ( ; item; item = xmlnode_get_next_twin(item)) {
+			const char *jid = xmlnode_get_attrib(item, "jid");
+			if (jid == NULL || *jid == '\0')
+				continue;
+
+			if (is_block)
+				purple_privacy_deny_add(account, jid, TRUE);
+			else
+				purple_privacy_deny_remove(account, jid, TRUE);
+		}
+	}
+
+	result = jabber_iq_new(js, JABBER_IQ_RESULT);
+	xmlnode_set_attrib(result->node, "id", id);
+	jabber_iq_send(result);
+}
+
 static void jabber_blocklist_parse(JabberStream *js, const char *from,
                                    JabberIqType type, const char *id,
                                    xmlnode *packet, gpointer data)
@@ -1666,6 +1719,14 @@
 	if (blocklist == NULL)
 		return;
 
+	/* This is the only privacy method supported by XEP-0191 */
+	if (account->perm_deny != PUPRLE_PRIVACY_DENY_USERS)
+		account->perm_deny = PURPLE_PRIVACY_DENY_USERS;
+
+	/*
+	 * FIXME: We should probably completely override the local list with
+	 * the contents of the server list instead of merging them.
+	 */
 	item = xmlnode_get_child(blocklist, "item");
 	while (item != NULL) {
 		const char *jid = xmlnode_get_attrib(item, "jid");
--- a/libpurple/protocols/jabber/jabber.h	Mon May 25 20:13:01 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Tue May 26 23:44:55 2009 +0000
@@ -347,6 +347,9 @@
 void jabber_login(PurpleAccount *account);
 void jabber_close(PurpleConnection *gc);
 void jabber_idle_set(PurpleConnection *gc, int idle);
+void jabber_blocklist_parse_push(JabberStream *js, const char *from,
+                                 JabberIqType type, const char *id,
+                                 xmlnode *child);
 void jabber_request_block_list(JabberStream *js);
 void jabber_add_deny(PurpleConnection *gc, const char *who);
 void jabber_rem_deny(PurpleConnection *gc, const char *who);