Mercurial > pidgin
diff libpurple/protocols/jabber/jabber.c @ 24855:0700833f0c5d
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.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 22 Dec 2008 07:51:06 +0000 |
parents | a0b89076a163 |
children | 41e69c65b006 280ffb4d954f |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Sun Dec 21 18:01:37 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Mon Dec 22 07:51:06 2008 +0000 @@ -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 @@ 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;