annotate mod_pep_plus/util_pubsub.lib.lua @ 2848:232da6b1d2c1

mod_adhoc_groups: Allow users to create and join roster groups
author Kim Alvefur <zash@zash.se>
date Tue, 21 Nov 2017 16:58:50 +0100
parents cb2342cf3f3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2801
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local events = require "util.events";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local cache = require "util.cache";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local service = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local service_mt = { __index = service };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local default_config = { __index = {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 itemstore = function (config, _) return cache.new(config["max_items"]) end;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 broadcaster = function () end;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 get_affiliation = function () end;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 capabilities = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 } };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local default_node_config = { __index = {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 ["persist_items"] = false;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 ["max_items"] = 20;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 } };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local function new(config)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 config = config or {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 return setmetatable({
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 config = setmetatable(config, default_config);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 node_defaults = setmetatable(config.node_defaults or {}, default_node_config);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 affiliations = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 subscriptions = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 nodes = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 data = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 events = events.new();
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 }, service_mt);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 function service:jids_equal(jid1, jid2)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 local normalize = self.config.normalize_jid;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 return normalize(jid1) == normalize(jid2);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 function service:may(node, actor, action)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 if actor == true then return true; end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 local node_aff = node_obj and node_obj.affiliations[actor];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local service_aff = self.affiliations[actor]
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 or self.config.get_affiliation(actor, node, action)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 or "none";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 -- Check if node allows/forbids it
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 local node_capabilities = node_obj and node_obj.capabilities;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 if node_capabilities then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 local caps = node_capabilities[node_aff or service_aff];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 if caps then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local can = caps[action];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 if can ~= nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 return can;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 -- Check service-wide capabilities instead
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 local service_capabilities = self.config.capabilities;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 local caps = service_capabilities[node_aff or service_aff];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 if caps then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 local can = caps[action];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 if can ~= nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 return can;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 return false;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 function service:set_affiliation(node, actor, jid, affiliation)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 if not self:may(node, actor, "set_affiliation") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 node_obj.affiliations[jid] = affiliation;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 local _, jid_sub = self:get_subscription(node, true, jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 if not jid_sub and not self:may(node, jid, "be_unsubscribed") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 local ok, err = self:add_subscription(node, true, jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 return ok, err;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 elseif jid_sub and not self:may(node, jid, "be_subscribed") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 local ok, err = self:add_subscription(node, true, jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 return ok, err;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 function service:add_subscription(node, actor, jid, options)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local cap;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 if actor == true or jid == actor or self:jids_equal(actor, jid) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 cap = "subscribe";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 cap = "subscribe_other";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 if not self:may(node, actor, cap) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 if not self:may(node, jid, "be_subscribed") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 if not self.config.autocreate_on_subscribe then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 local ok, err = self:create(node, true);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 return ok, err;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 node_obj.subscribers[jid] = options or true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 local normal_jid = self.config.normalize_jid(jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 local subs = self.subscriptions[normal_jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 if subs then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 if not subs[jid] then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 subs[jid] = { [node] = true };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 subs[jid][node] = true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 self.subscriptions[normal_jid] = { [jid] = { [node] = true } };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 function service:remove_subscription(node, actor, jid)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 local cap;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 if actor == true or jid == actor or self:jids_equal(actor, jid) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 cap = "unsubscribe";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 cap = "unsubscribe_other";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 if not self:may(node, actor, cap) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 if not self:may(node, jid, "be_unsubscribed") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 if not node_obj.subscribers[jid] then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 return false, "not-subscribed";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 node_obj.subscribers[jid] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 local normal_jid = self.config.normalize_jid(jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 local subs = self.subscriptions[normal_jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 if subs then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 local jid_subs = subs[jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 if jid_subs then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 jid_subs[node] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 if next(jid_subs) == nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169 subs[jid] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 if next(subs) == nil then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 self.subscriptions[normal_jid] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 function service:remove_all_subscriptions(actor, jid)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 local normal_jid = self.config.normalize_jid(jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 local subs = self.subscriptions[normal_jid]
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 subs = subs and subs[jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 if subs then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 for node in pairs(subs) do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 self:remove_subscription(node, true, jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192 function service:get_subscription(node, actor, jid)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 local cap;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 if actor == true or jid == actor or self:jids_equal(actor, jid) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196 cap = "get_subscription";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 cap = "get_subscription_other";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 if not self:may(node, actor, cap) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 return true, node_obj.subscribers[jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211 function service:create(node, actor, options)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 if not self:may(node, actor, "create") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217 if self.nodes[node] then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218 return false, "conflict";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221 self.nodes[node] = {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 name = node;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223 subscribers = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 config = setmetatable(options or {}, {__index=self.node_defaults});
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 affiliations = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226 };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 self.data[node] = self.config.itemstore(self.nodes[node].config, node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 self.events.fire_event("node-created", { node = node, actor = actor });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 local ok, err = self:set_affiliation(node, true, actor, "owner");
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 self.nodes[node] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 self.data[node] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 return ok, err;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 function service:delete(node, actor)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 if not self:may(node, actor, "delete") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 self.nodes[node] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248 if self.data[node] and self.data[node].clear then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249 self.data[node]:clear();
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 self.data[node] = nil;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 self.events.fire_event("node-deleted", { node = node, actor = actor });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 self.config.broadcaster("delete", node, node_obj.subscribers);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257 function service:publish(node, actor, id, item)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 if not self:may(node, actor, "publish") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 if not self.config.autocreate_on_publish then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 local ok, err = self:create(node, true);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 return ok, err;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 local node_data = self.data[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 local ok = node_data:set(id, item);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 return nil, "internal-server-error";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 if type(ok) == "string" then id = ok; end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 self.config.broadcaster("items", node, node_obj.subscribers, item, actor);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 function service:retract(node, actor, id, retract)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 if not self:may(node, actor, "retract") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 if (not node_obj) or (not self.data[node]:get(id)) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 local ok = self.data[node]:set(id, nil);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 if not ok then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 return nil, "internal-server-error";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 if retract then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 self.config.broadcaster("items", node, node_obj.subscribers, retract);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 return true
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
306 function service:purge(node, actor, notify)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
308 if not self:may(node, actor, "retract") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
309 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
310 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
314 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
315 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
316 if self.data[node] and self.data[node].clear then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
317 self.data[node]:clear()
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
318 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
319 self.data[node] = self.config.itemstore(self.nodes[node].config, node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
320 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
321 self.events.fire_event("node-purged", { node = node, actor = actor });
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
322 if notify then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
323 self.config.broadcaster("purge", node, node_obj.subscribers);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
324 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
325 return true
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
326 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
327
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
328 function service:get_items(node, actor, id)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
329 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
330 if not self:may(node, actor, "get_items") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
331 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
332 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
333 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
334 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
335 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
336 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
337 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
338 if id then -- Restrict results to a single specific item
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
339 local with_id = self.data[node]:get(id);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
340 if not with_id then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
341 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
342 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
343 return true, { id, [id] = with_id };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
344 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
345 local data = {}
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
346 for key, value in self.data[node]:items() do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
347 data[#data+1] = key;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
348 data[key] = value;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
349 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
350 return true, data;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
351 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
352 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
353
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
354 function service:get_nodes(actor)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
355 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
356 if not self:may(nil, actor, "get_nodes") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
357 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
358 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
359 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
360 return true, self.nodes;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
361 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
362
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
363 function service:get_subscriptions(node, actor, jid)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
364 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
365 local cap;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
366 if actor == true or jid == actor or self:jids_equal(actor, jid) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
367 cap = "get_subscriptions";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
368 else
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
369 cap = "get_subscriptions_other";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
370 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
371 if not self:may(node, actor, cap) then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
372 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
373 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
374 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
375 local node_obj;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
376 if node then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
377 node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
378 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
379 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
380 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
381 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
382 local normal_jid = self.config.normalize_jid(jid);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
383 local subs = self.subscriptions[normal_jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
384 -- We return the subscription object from the node to save
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
385 -- a get_subscription() call for each node.
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
386 local ret = {};
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
387 if subs then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
388 for subscribed_jid, subscribed_nodes in pairs(subs) do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
389 if node then -- Return only subscriptions to this node
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
390 if subscribed_nodes[node] then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
391 ret[#ret+1] = {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
392 node = node;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
393 jid = subscribed_jid;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
394 subscription = node_obj.subscribers[subscribed_jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
395 };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
396 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
397 else -- Return subscriptions to all nodes
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
398 local nodes = self.nodes;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
399 for subscribed_node in pairs(subscribed_nodes) do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
400 ret[#ret+1] = {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
401 node = subscribed_node;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
402 jid = subscribed_jid;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
403 subscription = nodes[subscribed_node].subscribers[subscribed_jid];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
404 };
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
405 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
406 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
407 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
408 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
409 return true, ret;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
410 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
411
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
412 -- Access models only affect 'none' affiliation caps, service/default access level...
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
413 function service:set_node_capabilities(node, actor, capabilities)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
414 -- Access checking
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
415 if not self:may(node, actor, "configure") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
416 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
417 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
418 --
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
419 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
420 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
421 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
422 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
423 node_obj.capabilities = capabilities;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
424 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
425 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
426
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
427 function service:set_node_config(node, actor, new_config)
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
428 if not self:may(node, actor, "configure") then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
429 return false, "forbidden";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
430 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
431
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
432 local node_obj = self.nodes[node];
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
433 if not node_obj then
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 return false, "item-not-found";
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
436
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
437 for k,v in pairs(new_config) do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
438 node_obj.config[k] = v;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
439 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
440 local new_data = self.config.itemstore(self.nodes[node].config, node);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 for key, value in self.data[node]:items() do
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
442 new_data:set(key, value);
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
443 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
444 self.data[node] = new_data;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
445 return true;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
446 end
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
447
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
448 return {
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
449 new = new;
cb2342cf3f3c mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff changeset
450 };