Annotate

plugins/blocking.lua @ 396:b0afde43b3e5

Add util.ip, dependency of net.dns since Prosody 0.9.9
author Kim Alvefur <zash@zash.se>
date Sat, 09 Jan 2016 01:36:03 +0100
parent 250:a5ac643a7fd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 80
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 80
diff changeset
2
80
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local xmlns_blocking = "urn:xmpp:blocking";
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 function verse.plugins.blocking(stream)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- FIXME: Disco
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 stream.blocking = {};
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 function stream.blocking:block_jid(jid, callback)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 stream:send_iq(verse.iq{type="set"}
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 :tag("block", { xmlns = xmlns_blocking })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 :tag("item", { jid = jid })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 , function () return callback and callback(true); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 , function () return callback and callback(false); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 );
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 function stream.blocking:unblock_jid(jid, callback)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 stream:send_iq(verse.iq{type="set"}
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 :tag("unblock", { xmlns = xmlns_blocking })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 :tag("item", { jid = jid })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 , function () return callback and callback(true); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 , function () return callback and callback(false); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 );
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 function stream.blocking:unblock_all_jids(callback)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 stream:send_iq(verse.iq{type="set"}
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 :tag("unblock", { xmlns = xmlns_blocking })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 , function () return callback and callback(true); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 , function () return callback and callback(false); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 );
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 function stream.blocking:get_blocked_jids(callback)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 stream:send_iq(verse.iq{type="get"}
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 :tag("blocklist", { xmlns = xmlns_blocking })
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 , function (result)
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local list = result:get_child("blocklist", xmlns_blocking);
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 if not list then return callback and callback(false); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 local jids = {};
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 for item in list:childtags() do
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 jids[#jids+1] = item.attr.jid;
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 return callback and callback(jids);
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 , function (result) return callback and callback(false); end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 );
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
336864e83991 verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end