pidgin: b91b500b: Commit patch #7670: Implement xep-0191 (...

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Dec 22 04:25:34 EST 2008


-----------------------------------------------------------------
Revision: b91b500b28cdf7b1ff8e46c5957519556a7f26db
Ancestor: df6eba32e5b6b34d7483cbfb7e9f2e4c836ac35f
Author: markdoliner at pidgin.im
Date: 2008-12-22T07:51:06
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b91b500b28cdf7b1ff8e46c5957519556a7f26db

Modified files:
        ChangeLog libpurple/protocols/jabber/disco.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/libxmpp.c

ChangeLog: 

Commit patch #7670: Implement xep-0191 (simple blocking) for jabber protocols
from Vijay Raghunathan (a co-worker of mine).  We're testing this at Meebo
and it seems to work ok.  Closes #7670.

-------------- next part --------------
============================================================
--- ChangeLog	15239dc95442ff3c31b689beac8239dff24bd9a3
+++ ChangeLog	e7acef4a64774f391cc3116d54bafe1530b59ded
@@ -7,6 +7,9 @@ version 2.5.4 (??/??/????):
 	* Don't ignore namespace information when parsing XMPP data. (Michal
 	  Witkowski)
 
+	XMPP:
+	* Support for XEP-0191 blocking.  (Vijay Raghunathan)
+
 version 2.5.3 (12/20/2008):
 	libpurple:
 	* The Buddy State Notification plugin no longer prints duplicate
============================================================
--- libpurple/protocols/jabber/disco.c	7f85a8a092ed6670ee147af38b8482042416e2ee
+++ libpurple/protocols/jabber/disco.c	15e05aeaa2b1e64bc8b77794391c734d82691a3e
@@ -355,6 +355,11 @@ jabber_disco_finish_server_info_result_c
 		jabber_adhoc_server_get_list(js);
 	}
 
+	/* If the server supports blocking, request the block list */
+	if (js->server_caps & JABBER_CAP_BLOCKING) {
+		jabber_request_block_list(js);
+	}
+
 	/* If there are manually specified bytestream proxies, query them */
 	ft_proxies = purple_account_get_string(js->gc->account, "ft_proxies", NULL);
 	if (ft_proxies) {
@@ -454,6 +459,8 @@ jabber_disco_server_info_result_cb(Jabbe
 			jabber_google_roster_init(js);
 		} else if (!strcmp("http://jabber.org/protocol/commands", var)) {
 			js->server_caps |= JABBER_CAP_ADHOC;
+		} else if (!strcmp("urn:xmpp:blocking", var)) {
+			js->server_caps |= JABBER_CAP_BLOCKING;
 		}
 	}
 
============================================================
--- libpurple/protocols/jabber/jabber.c	c125aa12f0dbbdf9844fb419d5e9572e235ca373
+++ libpurple/protocols/jabber/jabber.c	851fc11708d9b1cbdea9a9796a0e5fd274d9c9bf
@@ -31,6 +31,7 @@
 #include "message.h"
 #include "notify.h"
 #include "pluginpref.h"
+#include "privacy.h"
 #include "proxy.h"
 #include "prpl.h"
 #include "request.h"
@@ -1454,6 +1455,106 @@ void jabber_idle_set(PurpleConnection *g
 	js->idle = idle ? time(NULL) - idle : idle;
 }
 
+static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data)
+{
+	xmlnode *blocklist, *item;
+	PurpleAccount *account;
+
+	blocklist = xmlnode_get_child_with_namespace(packet,
+			"blocklist", "urn:xmpp:blocking");
+	account = purple_connection_get_account(js->gc);
+
+	if (blocklist == NULL)
+		return;
+
+	item = xmlnode_get_child(blocklist, "item");
+	while (item != NULL) {
+		const char *jid = xmlnode_get_attrib(item, "jid");
+
+		purple_privacy_deny_add(account, jid, TRUE);
+		item = xmlnode_get_next_twin(item);
+	}
+}
+
+void jabber_request_block_list(JabberStream *js)
+{
+	JabberIq *iq;
+	xmlnode *blocklist;
+
+	iq = jabber_iq_new(js, JABBER_IQ_GET);
+
+	blocklist = xmlnode_new_child(iq->node, "blocklist");
+	xmlnode_set_namespace(blocklist, "urn:xmpp:blocking");
+
+	jabber_iq_set_callback(iq, jabber_blocklist_parse, NULL);
+
+	jabber_iq_send(iq);
+}
+
+void jabber_add_deny(PurpleConnection *gc, const char *who)
+{
+	JabberStream *js;
+	JabberIq *iq;
+	xmlnode *block, *item;
+
+	js = gc->proto_data;
+	if (js == NULL)
+		return;
+
+	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
+	{
+		jabber_google_roster_add_deny(gc, who);
+		return;
+	}
+
+	if (!(js->server_caps & JABBER_CAP_BLOCKING))
+	{
+		purple_notify_error(NULL, _("Server doesn't support blocking"),
+							_("Server doesn't support blocking"), NULL);
+		return;
+	}
+
+	iq = jabber_iq_new(js, JABBER_IQ_SET);
+
+	block = xmlnode_new_child(iq->node, "block");
+	xmlnode_set_namespace(block, "urn:xmpp:blocking");
+
+	item = xmlnode_new_child(block, "item");
+	xmlnode_set_attrib(item, "jid", who);
+
+	jabber_iq_send(iq);
+}
+
+void jabber_rem_deny(PurpleConnection *gc, const char *who)
+{
+	JabberStream *js;
+	JabberIq *iq;
+	xmlnode *unblock, *item;
+
+	js = gc->proto_data;
+	if (js == NULL)
+		return;
+
+	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
+	{
+		jabber_google_roster_rem_deny(gc, who);
+		return;
+	}
+
+	if (!(js->server_caps & JABBER_CAP_BLOCKING))
+		return;
+
+	iq = jabber_iq_new(js, JABBER_IQ_SET);
+
+	unblock = xmlnode_new_child(iq->node, "unblock");
+	xmlnode_set_namespace(unblock, "urn:xmpp:blocking");
+
+	item = xmlnode_new_child(unblock, "item");
+	xmlnode_set_attrib(item, "jid", who);
+
+	jabber_iq_send(iq);
+}
+
 void jabber_add_feature(const char *shortname, const char *namespace, JabberFeatureEnabled cb) {
 	JabberFeature *feat;
 
============================================================
--- libpurple/protocols/jabber/jabber.h	278f09ab8a8ec522143d1a89519a628427847ed7
+++ libpurple/protocols/jabber/jabber.h	df574ab651cdebe290c7ce7f0a329167c562919a
@@ -42,7 +42,8 @@ typedef enum {
 
 	JABBER_CAP_PING			  = 1 << 11,
 	JABBER_CAP_ADHOC		  = 1 << 12,
-	
+	JABBER_CAP_BLOCKING       = 1 << 13,
+
 	JABBER_CAP_RETRIEVED      = 1 << 31
 } JabberCapabilities;
 
@@ -294,6 +295,9 @@ void jabber_idle_set(PurpleConnection *g
 void jabber_login(PurpleAccount *account);
 void jabber_close(PurpleConnection *gc);
 void jabber_idle_set(PurpleConnection *gc, int idle);
+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);
 void jabber_keepalive(PurpleConnection *gc);
 void jabber_register_gateway(JabberStream *js, const char *gateway);
 void jabber_register_account(PurpleAccount *account);
============================================================
--- libpurple/protocols/jabber/libxmpp.c	6f56ad50467f427b20c7a81ccab51c0f6f6f50d4
+++ libpurple/protocols/jabber/libxmpp.c	57be32934eb9f7a99243045cadba2059bcc3a4f4
@@ -77,9 +77,9 @@ static PurplePluginProtocolInfo prpl_inf
 	jabber_roster_remove_buddy,		/* remove_buddy */
 	NULL,							/* remove_buddies */
 	NULL,							/* add_permit */
-	jabber_google_roster_add_deny,				/* add_deny */
+	jabber_add_deny,				/* add_deny */
 	NULL,							/* rem_permit */
-	jabber_google_roster_rem_deny,				/* rem_deny */
+	jabber_rem_deny,				/* rem_deny */
 	NULL,							/* set_permit_deny */
 	jabber_chat_join,				/* join_chat */
 	NULL,							/* reject_chat */


More information about the Commits mailing list