annotate mod_blocking/mod_blocking.lua @ 164:0b238b2b0801

mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
author Matthew Wild <mwild1@gmail.com>
date Thu, 03 Jun 2010 11:20:26 +0100
parents 9fe6d314fd07
children 4f58ddade1db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 module:add_feature("urn:xmpp:blocking");
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Add JID to default privacy list
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 function add_blocked_jid(username, host, jid)
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local privacy_lists = datamanager.load(username, host, "privacy") or {};
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local default_list_name = privacy_lists.default;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 if not default_list_name then
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 default_list_name = "blocklist";
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 privacy_lists.default = default_list_name;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local default_list = privacy_lists.list[default_list_name];
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if not default_list then
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 default_list = { name = default_list_name, items = {} };
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 privacy_lists.lists[default_list_name] = default_list;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local items = default_list.items;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local order = items[1].order; -- Must come first
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 for i=1,#items do -- order must be unique
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 items[i].order = items[i].order + 1;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 table.insert(items, 1, { type = "jid"
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 , action = "deny"
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 , value = jid
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 , message = false
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 , ["presence-out"] = false
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 , ["presence-in"] = false
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 , iq = false
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 , order = order
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 };
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 datamanager.store(username, host, "privacy", privacy_lists);
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 -- Remove JID from default privacy list
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 function remove_blocked_jid(username, host, jid)
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local privacy_lists = datamanager.load(username, host, "privacy") or {};
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local default_list_name = privacy_lists.default;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 if not default_list_name then return; end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local default_list = privacy_lists.list[default_list_name];
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 if not default_list then return; end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local items = default_list.items;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local item;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 for i=1,#items do -- order must be unique
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 item = items[i];
163
9fe6d314fd07 mod_blocking: Only count rules with action == "deny" as blocked JIDs
Matthew Wild <mwild1@gmail.com>
parents: 161
diff changeset
44 if item.type == "jid" and item.action == "deny" and item.value == jid then
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 table.remove(items, i);
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 return true;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
164
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
49 datamanager.store(username, host, "privacy", privacy_lists);
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
50 end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
51
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
52 function remove_all_blocked_jids(username, host)
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
53 local privacy_lists = datamanager.load(username, host, "privacy") or {};
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
54 local default_list_name = privacy_lists.default;
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
55 if not default_list_name then return; end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
56 local default_list = privacy_lists.list[default_list_name];
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
57 if not default_list then return; end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
58 local items = default_list.items;
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
59 local item;
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
60 for i=#items,1 do -- order must be unique
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
61 item = items[i];
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
62 if item.type == "jid" and item.action == "deny" then
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
63 table.remove(items, i);
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
64 end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
65 end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
66 datamanager.store(username, host, "privacy", privacy_lists);
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 function get_blocked_jids(username, host)
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 -- Return array of blocked JIDs in default privacy list
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 local privacy_lists = datamanager.load(username, host, "privacy") or {};
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 local default_list_name = privacy_lists.default;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 if not default_list_name then return {}; end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 local default_list = privacy_lists.list[default_list_name];
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 if not default_list then return {}; end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 local items = default_list.items;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 local item;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 local jid_list = {};
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 for i=1,#items do -- order must be unique
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 item = items[i];
163
9fe6d314fd07 mod_blocking: Only count rules with action == "deny" as blocked JIDs
Matthew Wild <mwild1@gmail.com>
parents: 161
diff changeset
81 if item.type == "jid" and item.action == "deny" then
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 jid_list[#jid_list+1] = item.value;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 return jid_list;
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 function handle_blocking_command(session, stanza)
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 local username, host = jid_split(stanza.attr.from);
164
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
90 if stanza.attr.type == "set" then
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
91 if stanza.tags[1].name == "block" then
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
92 local block = stanza.tags[1]:get_child("block");
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
93 local block_jid_list = {};
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
94 for item in block:childtags() do
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
95 block_jid_list[#block_jid_list+1] = item.attr.jid;
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
164
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
97 if #block_jid_list == 0 then
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
98 --FIXME: Reply bad-request
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
99 else
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
100 for _, jid in ipairs(block_jid_list) do
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
101 add_blocked_jid(username, host, jid);
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
102 end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
103 session.send(st.reply(stanza));
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
104 end
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
105 elseif stanza.tags[1].name == "unblock" then
0b238b2b0801 mod_blocking: Support for the "unblock all JIDs" case, and fix saving of rules after removing a JID
Matthew Wild <mwild1@gmail.com>
parents: 163
diff changeset
106 remove_all_blocked_jids(username, host);
161
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 session.send(st.reply(stanza));
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 elseif stanza.attr.type == "get" and stanza.tags[1].name == "blocklist" then
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 local reply = st.reply(stanza):tag("blocklist", { xmlns = xmlns_block });
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 local blocked_jids = get_blocked_jids(username, host);
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 for _, jid in ipairs(blocked_jids) do
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 reply:tag("item", { jid = jid }):up();
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 session.send(reply);
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 else
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 --FIXME: Need to respond with service-unavailable
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 end
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120
fda7faee7677 mod_blocking: XEP-0191 Simple Communications Blocking, should work, but not tested. Requires mod_privacy be loaded.
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 module:add_iq_handler("c2s", xmlns_blocking, handle_blocking_command);