Software /
code /
prosody
Annotate
util/pubsub.lua @ 7198:48d167f652ad
util.termcolours: Silence luacheck warning
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Feb 2016 22:33:40 +0100 |
parent | 6777:5de6b93d0190 |
child | 6791:e813e8cf6046 |
child | 7695:56ce32cfd6d9 |
rev | line source |
---|---|
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
1 local events = require "util.events"; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
2 local t_remove = table.remove; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
3 |
3619 | 4 local service = {}; |
5 local service_mt = { __index = service }; | |
6 | |
6436
31ca87ea8d46
util.pubsub: One less table allocated per pubsub object created
Kim Alvefur <zash@zash.se>
parents:
6435
diff
changeset
|
7 local default_config = { __index = { |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
8 broadcaster = function () end; |
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
9 get_affiliation = function () end; |
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
10 capabilities = {}; |
6436
31ca87ea8d46
util.pubsub: One less table allocated per pubsub object created
Kim Alvefur <zash@zash.se>
parents:
6435
diff
changeset
|
11 } }; |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
12 local default_node_config = { __index = { |
6439
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
13 ["pubsub#max_items"] = "20"; |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
14 } }; |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
15 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6515
diff
changeset
|
16 local function new(config) |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
17 config = config or {}; |
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
18 return setmetatable({ |
6436
31ca87ea8d46
util.pubsub: One less table allocated per pubsub object created
Kim Alvefur <zash@zash.se>
parents:
6435
diff
changeset
|
19 config = setmetatable(config, default_config); |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
20 node_defaults = setmetatable(config.node_defaults or {}, default_node_config); |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
21 affiliations = {}; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
22 subscriptions = {}; |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
23 nodes = {}; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
24 data = {}; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
25 events = events.new(); |
3909
c2dc7f7eed94
util.pubsub: Modify new() to take a config, and add a default config via a metatable
Matthew Wild <mwild1@gmail.com>
parents:
3759
diff
changeset
|
26 }, service_mt); |
3619 | 27 end |
28 | |
3934
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
29 function service:jids_equal(jid1, jid2) |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
30 local normalize = self.config.normalize_jid; |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
31 return normalize(jid1) == normalize(jid2); |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
32 end |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
33 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
34 function service:may(node, actor, action) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
35 if actor == true then return true; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
36 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
37 local node_obj = self.nodes[node]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
38 local node_aff = node_obj and node_obj.affiliations[actor]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
39 local service_aff = self.affiliations[actor] |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
40 or self.config.get_affiliation(actor, node, action) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
41 or "none"; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
42 |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
43 -- Check if node allows/forbids it |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
44 local node_capabilities = node_obj and node_obj.capabilities; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
45 if node_capabilities then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
46 local caps = node_capabilities[node_aff or service_aff]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
47 if caps then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
48 local can = caps[action]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
49 if can ~= nil then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
50 return can; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
51 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
52 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
53 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
54 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
55 -- Check service-wide capabilities instead |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
56 local service_capabilities = self.config.capabilities; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
57 local caps = service_capabilities[node_aff or service_aff]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
58 if caps then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
59 local can = caps[action]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
60 if can ~= nil then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
61 return can; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
62 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
63 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
64 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
65 return false; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
66 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
67 |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
68 function service:set_affiliation(node, actor, jid, affiliation) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
69 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
70 if not self:may(node, actor, "set_affiliation") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
71 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
72 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
73 -- |
3619 | 74 local node_obj = self.nodes[node]; |
75 if not node_obj then | |
76 return false, "item-not-found"; | |
77 end | |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
78 node_obj.affiliations[jid] = affiliation; |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
79 local _, jid_sub = self:get_subscription(node, true, jid); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
80 if not jid_sub and not self:may(node, jid, "be_unsubscribed") then |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
81 local ok, err = self:add_subscription(node, true, jid); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
82 if not ok then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
83 return ok, err; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
84 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
85 elseif jid_sub and not self:may(node, jid, "be_subscribed") then |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
86 local ok, err = self:add_subscription(node, true, jid); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
87 if not ok then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
88 return ok, err; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
89 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
90 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
91 return true; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
92 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
93 |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
94 function service:add_subscription(node, actor, jid, options) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
95 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
96 local cap; |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
97 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
98 cap = "subscribe"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
99 else |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
100 cap = "subscribe_other"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
101 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
102 if not self:may(node, actor, cap) then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
103 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
104 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
105 if not self:may(node, jid, "be_subscribed") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
106 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
107 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
108 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
109 local node_obj = self.nodes[node]; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
110 if not node_obj then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
111 if not self.config.autocreate_on_subscribe then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
112 return false, "item-not-found"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
113 else |
4364
af40cf682eba
util.pubsub: Use built-in actor for auto-creating nodes on publish and subscribe (so they never fail due to permissions)
Matthew Wild <mwild1@gmail.com>
parents:
4100
diff
changeset
|
114 local ok, err = self:create(node, true); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
115 if not ok then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
116 return ok, err; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
117 end |
3936
61f12f8a8539
util.pubsub: Fix traceback when using autocreate-on-subscribe
Matthew Wild <mwild1@gmail.com>
parents:
3934
diff
changeset
|
118 node_obj = self.nodes[node]; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
119 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
120 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
121 node_obj.subscribers[jid] = options or true; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
122 local normal_jid = self.config.normalize_jid(jid); |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
123 local subs = self.subscriptions[normal_jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
124 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
125 if not subs[jid] then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
126 subs[jid] = { [node] = true }; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
127 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
128 subs[jid][node] = true; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
129 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
130 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
131 self.subscriptions[normal_jid] = { [jid] = { [node] = true } }; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
132 end |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
133 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
3619 | 134 return true; |
135 end | |
136 | |
137 function service:remove_subscription(node, actor, jid) | |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
138 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
139 local cap; |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
140 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
141 cap = "unsubscribe"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
142 else |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
143 cap = "unsubscribe_other"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
144 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
145 if not self:may(node, actor, cap) then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
146 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
147 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
148 if not self:may(node, jid, "be_unsubscribed") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
149 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
150 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
151 -- |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
152 local node_obj = self.nodes[node]; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
153 if not node_obj then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
154 return false, "item-not-found"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
155 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
156 if not node_obj.subscribers[jid] then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
157 return false, "not-subscribed"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
158 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
159 node_obj.subscribers[jid] = nil; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
160 local normal_jid = self.config.normalize_jid(jid); |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
161 local subs = self.subscriptions[normal_jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
162 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
163 local jid_subs = subs[jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
164 if jid_subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
165 jid_subs[node] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
166 if next(jid_subs) == nil then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
167 subs[jid] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
168 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
169 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
170 if next(subs) == nil then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
171 self.subscriptions[normal_jid] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
172 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
173 end |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
174 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); |
3619 | 175 return true; |
176 end | |
177 | |
4366
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
178 function service:remove_all_subscriptions(actor, jid) |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
179 local normal_jid = self.config.normalize_jid(jid); |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
180 local subs = self.subscriptions[normal_jid] |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
181 subs = subs and subs[jid]; |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
182 if subs then |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
183 for node in pairs(subs) do |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
184 self:remove_subscription(node, true, jid); |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
185 end |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
186 end |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
187 return true; |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
188 end |
b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
4365
diff
changeset
|
189 |
3626
444f965baed8
util.pubsub: Add :get_subscription() to return the current subscription for a JID, if any
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
190 function service:get_subscription(node, actor, jid) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
191 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
192 local cap; |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
193 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
194 cap = "get_subscription"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
195 else |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
196 cap = "get_subscription_other"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
197 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
198 if not self:may(node, actor, cap) then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
199 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
200 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
201 -- |
3626
444f965baed8
util.pubsub: Add :get_subscription() to return the current subscription for a JID, if any
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
202 local node_obj = self.nodes[node]; |
3937
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
203 if not node_obj then |
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
204 return false, "item-not-found"; |
3626
444f965baed8
util.pubsub: Add :get_subscription() to return the current subscription for a JID, if any
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
205 end |
3937
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
206 return true, node_obj.subscribers[jid]; |
3626
444f965baed8
util.pubsub: Add :get_subscription() to return the current subscription for a JID, if any
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
207 end |
444f965baed8
util.pubsub: Add :get_subscription() to return the current subscription for a JID, if any
Matthew Wild <mwild1@gmail.com>
parents:
3619
diff
changeset
|
208 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
209 function service:create(node, actor, options) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
210 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
211 if not self:may(node, actor, "create") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
212 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
213 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
214 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
215 if self.nodes[node] then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
216 return false, "conflict"; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
217 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
218 |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
219 self.data[node] = {}; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
220 self.nodes[node] = { |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
221 name = node; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
222 subscribers = {}; |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
223 config = setmetatable(options or {}, {__index=self.node_defaults}); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
224 affiliations = {}; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
225 }; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
226 setmetatable(self.nodes[node], { __index = { data = self.data[node] } }); -- COMPAT |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
227 self.events.fire_event("node-created", { node = node, actor = actor }); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
228 local ok, err = self:set_affiliation(node, true, actor, "owner"); |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
229 if not ok then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
230 self.nodes[node] = nil; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
231 self.data[node] = nil; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
232 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
233 return ok, err; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
234 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
235 |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
236 function service:delete(node, actor) |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
237 -- Access checking |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
238 if not self:may(node, actor, "delete") then |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
239 return false, "forbidden"; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
240 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
241 -- |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
242 local node_obj = self.nodes[node]; |
5675
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
243 if not node_obj then |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
244 return false, "item-not-found"; |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
245 end |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
246 self.nodes[node] = nil; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
247 self.data[node] = nil; |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
248 self.events.fire_event("node-deleted", { node = node, actor = actor }); |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
249 self.config.broadcaster("delete", node, node_obj.subscribers); |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
250 return true; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
251 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
252 |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
253 local function remove_item_by_id(data, id) |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
254 if not data[id] then return end |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
255 data[id] = nil; |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
256 for i, _id in ipairs(data) do |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
257 if id == _id then |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
258 t_remove(data, i); |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
259 return i; |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
260 end |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
261 end |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
262 end |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
263 |
6439
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
264 local function trim_items(data, max) |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
265 max = tonumber(max); |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
266 if not max or #data <= max then return end |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
267 repeat |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
268 data[t_remove(data, 1)] = nil; |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
269 until #data <= max |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
270 end |
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
271 |
3619 | 272 function service:publish(node, actor, id, item) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
273 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
274 if not self:may(node, actor, "publish") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
275 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
276 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
277 -- |
3619 | 278 local node_obj = self.nodes[node]; |
279 if not node_obj then | |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
280 if not self.config.autocreate_on_publish then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
281 return false, "item-not-found"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
282 end |
4364
af40cf682eba
util.pubsub: Use built-in actor for auto-creating nodes on publish and subscribe (so they never fail due to permissions)
Matthew Wild <mwild1@gmail.com>
parents:
4100
diff
changeset
|
283 local ok, err = self:create(node, true); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
284 if not ok then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
285 return ok, err; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
286 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
287 node_obj = self.nodes[node]; |
3619 | 288 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
289 local node_data = self.data[node]; |
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
290 remove_item_by_id(node_data, id); |
6435 | 291 node_data[#node_data + 1] = id; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
292 node_data[id] = item; |
6439
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
293 trim_items(node_data, node_obj.config["pubsub#max_items"]); |
5181
1e9508ae44cc
util.pubsub: Add item-published event
Matthew Wild <mwild1@gmail.com>
parents:
4367
diff
changeset
|
294 self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); |
6515
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6439
diff
changeset
|
295 self.config.broadcaster("items", node, node_obj.subscribers, item, actor); |
3619 | 296 return true; |
297 end | |
298 | |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
299 function service:retract(node, actor, id, retract) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
300 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
301 if not self:may(node, actor, "retract") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
302 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
303 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
304 -- |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
305 local node_obj = self.nodes[node]; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
306 if (not node_obj) or (not self.data[node][id]) then |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
307 return false, "item-not-found"; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
308 end |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
309 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id }); |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
310 remove_item_by_id(self.data[node], id); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
311 if retract then |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
312 self.config.broadcaster("items", node, node_obj.subscribers, retract); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
313 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
314 return true |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
315 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
316 |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
317 function service:purge(node, actor, notify) |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
318 -- Access checking |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
319 if not self:may(node, actor, "retract") then |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
320 return false, "forbidden"; |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
321 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
322 -- |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
323 local node_obj = self.nodes[node]; |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
324 if not node_obj then |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
325 return false, "item-not-found"; |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
326 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
327 self.data[node] = {}; -- Purge |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
328 self.events.fire_event("node-purged", { node = node, actor = actor }); |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
329 if notify then |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
330 self.config.broadcaster("purge", node, node_obj.subscribers); |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
331 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
332 return true |
5305
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
333 end |
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
334 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
335 function service:get_items(node, actor, id) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
336 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
337 if not self:may(node, actor, "get_items") then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
338 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
339 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
340 -- |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
341 local node_obj = self.nodes[node]; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
342 if not node_obj then |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
343 return false, "item-not-found"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
344 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
345 if id then -- Restrict results to a single specific item |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
346 return true, { id, [id] = self.data[node][id] }; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
347 else |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
348 return true, self.data[node]; |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
349 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
350 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
351 |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
352 function service:get_nodes(actor) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
353 -- Access checking |
3917
263a133bdf5a
util.pubsub: Fix nil global access in get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3910
diff
changeset
|
354 if not self:may(nil, actor, "get_nodes") then |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
355 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
356 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
357 -- |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
358 return true, self.nodes; |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
359 end |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
360 |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
361 function service:get_subscriptions(node, actor, jid) |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
362 -- Access checking |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
363 local cap; |
4100
69e3f1e7111e
util.pubsub: Pass true instead of nil as the actor in a bunch of places, and fix a bunch of methods to not traceback on this (those with *_other capability checking).
Matthew Wild <mwild1@gmail.com>
parents:
4099
diff
changeset
|
364 if actor == true or jid == actor or self:jids_equal(actor, jid) then |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
365 cap = "get_subscriptions"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
366 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
367 cap = "get_subscriptions_other"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
368 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
369 if not self:may(node, actor, cap) then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
370 return false, "forbidden"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
371 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
372 -- |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
373 local node_obj; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
374 if node then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
375 node_obj = self.nodes[node]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
376 if not node_obj then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
377 return false, "item-not-found"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
378 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
379 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
380 local normal_jid = self.config.normalize_jid(jid); |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
381 local subs = self.subscriptions[normal_jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
382 -- We return the subscription object from the node to save |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
383 -- a get_subscription() call for each node. |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
384 local ret = {}; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
385 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
386 for jid, subscribed_nodes in pairs(subs) do |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
387 if node then -- Return only subscriptions to this node |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
388 if subscribed_nodes[node] then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
389 ret[#ret+1] = { |
5628
ba5c2f6b799e
util.pubsub: Fix get_subscriptions to not pass a boolean as node name (thanks jonas)
Kim Alvefur <zash@zash.se>
parents:
5320
diff
changeset
|
390 node = node; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
391 jid = jid; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
392 subscription = node_obj.subscribers[jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
393 }; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
394 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
395 else -- Return subscriptions to all nodes |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
396 local nodes = self.nodes; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
397 for subscribed_node in pairs(subscribed_nodes) do |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
398 ret[#ret+1] = { |
3942
0323beb7183c
util.pubsub: Use correct node name when returning a list of multiple nodes in a subscriptions response
Matthew Wild <mwild1@gmail.com>
parents:
3938
diff
changeset
|
399 node = subscribed_node; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
400 jid = jid; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
401 subscription = nodes[subscribed_node].subscribers[jid]; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
402 }; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
403 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
404 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
405 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
406 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
407 return true, ret; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
408 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
409 |
3928
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
410 -- Access models only affect 'none' affiliation caps, service/default access level... |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
411 function service:set_node_capabilities(node, actor, capabilities) |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
412 -- Access checking |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
413 if not self:may(node, actor, "configure") then |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
414 return false, "forbidden"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
415 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
416 -- |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
417 local node_obj = self.nodes[node]; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
418 if not node_obj then |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
419 return false, "item-not-found"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
420 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
421 node_obj.capabilities = capabilities; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
422 return true; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
423 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
424 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
425 function service:set_node_config(node, actor, new_config) |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
426 if not self:may(node, actor, "configure") then |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
427 return false, "forbidden"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
428 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
429 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
430 local node_obj = self.nodes[node]; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
431 if not node_obj then |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
432 return false, "item-not-found"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
433 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
434 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
435 for k,v in pairs(new_config) do |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
436 node_obj.config[k] = v; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
437 end |
6439
d58ad8bd244b
util.pubsub: Add support for limiting the number of item in a node (default to 20)
Kim Alvefur <zash@zash.se>
parents:
6437
diff
changeset
|
438 trim_items(self.data[node], node_obj.config["pubsub#max_items"]); |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
439 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
440 return true; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
441 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
442 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6515
diff
changeset
|
443 return { |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6515
diff
changeset
|
444 new = new; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6515
diff
changeset
|
445 }; |