Software /
code /
prosody
Annotate
util/pubsub.lua @ 8500:9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 01 Feb 2018 15:09:04 +0000 |
parent | 8401:f1923a79c93d |
child | 8501:8d9e2c2095dd |
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"; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
2 local cache = require "util.cache"; |
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 | |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
7 local default_config = { |
8333
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8326
diff
changeset
|
8 itemstore = function (config, _) return cache.new(config["max_items"]) end; |
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
|
9 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
|
10 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
|
11 capabilities = {}; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
12 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
13 local default_config_mt = { __index = default_config }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
14 |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
15 local default_node_config = { |
8333
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8326
diff
changeset
|
16 ["persist_items"] = false; |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8326
diff
changeset
|
17 ["max_items"] = 20; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
18 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
19 local default_node_config_mt = { __index = 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
|
20 |
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
|
21 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
|
22 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
|
23 return setmetatable({ |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
24 config = setmetatable(config, default_config_mt); |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
25 node_defaults = setmetatable(config.node_defaults or {}, default_node_config_mt); |
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 affiliations = {}; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
27 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
|
28 nodes = {}; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
29 data = {}; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
30 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
|
31 }, service_mt); |
3619 | 32 end |
33 | |
3934
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 end |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
38 |
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
|
39 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
|
40 if actor == true then return true; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
41 |
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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 or "none"; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
47 |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
48 -- 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
59 |
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
|
60 -- Check service-wide capabilities instead |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
69 |
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
|
70 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
|
71 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
|
72 |
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 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
|
74 -- 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
|
75 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
|
76 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
|
77 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
|
78 -- |
3619 | 79 local node_obj = self.nodes[node]; |
80 if not node_obj then | |
81 return false, "item-not-found"; | |
82 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
|
83 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
|
84 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
|
85 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
|
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 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 |
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 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
|
100 -- 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 -- |
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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 end |
3936
61f12f8a8539
util.pubsub: Fix traceback when using autocreate-on-subscribe
Matthew Wild <mwild1@gmail.com>
parents:
3934
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
130 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
|
131 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
|
132 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
133 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
|
134 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
135 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
136 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
|
137 end |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
138 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
3619 | 139 return true; |
140 end | |
141 | |
142 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
|
143 -- 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 -- |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
157 local node_obj = self.nodes[node]; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
158 if not node_obj then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
159 return false, "item-not-found"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
160 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
161 if not node_obj.subscribers[jid] then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
162 return false, "not-subscribed"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
163 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 subs[jid] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
173 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
174 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
175 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
|
176 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
|
177 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
178 end |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
179 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); |
3619 | 180 return true; |
181 end | |
182 | |
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
|
183 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
|
184 -- 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 -- |
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
|
195 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
|
196 if not node_obj then |
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
197 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
|
198 end |
3937
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
199 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
|
200 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
|
201 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
202 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
|
203 -- 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
|
204 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
|
205 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
|
206 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
|
207 -- |
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
|
208 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
|
209 return false, "conflict"; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
210 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
211 |
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
|
212 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
|
213 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
|
214 subscribers = {}; |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
215 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
|
216 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
|
217 }; |
8211
5cbbe825d9d1
util.pubsub: Add a node parameter to itemstore().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7727
diff
changeset
|
218 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 self.nodes[node] = nil; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
223 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
|
224 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
|
225 return ok, err; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
226 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
227 |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
228 function service:delete(node, actor) |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
229 -- Access checking |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
230 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
|
231 return false, "forbidden"; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
232 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
233 -- |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
234 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
|
235 if not node_obj then |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
236 return false, "item-not-found"; |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
237 end |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
238 self.nodes[node] = nil; |
8312
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
239 if self.data[node] and self.data[node].clear then |
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
240 self.data[node]:clear(); |
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
241 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
242 self.data[node] = nil; |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
243 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
|
244 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
|
245 return true; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
246 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
247 |
3619 | 248 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
|
249 -- 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
|
250 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
|
251 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
|
252 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
|
253 -- |
3619 | 254 local node_obj = self.nodes[node]; |
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 node_obj = self.nodes[node]; |
3619 | 264 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
265 local node_data = self.data[node]; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
266 local ok = node_data:set(id, item); |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
267 if not ok then |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
268 return nil, "internal-server-error"; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
269 end |
8217
5f4e0d67b82a
util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents:
8212
diff
changeset
|
270 if type(ok) == "string" then id = ok; end |
5181
1e9508ae44cc
util.pubsub: Add item-published event
Matthew Wild <mwild1@gmail.com>
parents:
4367
diff
changeset
|
271 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
|
272 self.config.broadcaster("items", node, node_obj.subscribers, item, actor); |
3619 | 273 return true; |
274 end | |
275 | |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
276 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
|
277 -- 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
|
278 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
|
279 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
|
280 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
|
281 -- |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
282 local node_obj = self.nodes[node]; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
283 if (not node_obj) or (not self.data[node]:get(id)) then |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
284 return false, "item-not-found"; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
285 end |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
286 local ok = self.data[node]:set(id, nil); |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
287 if not ok then |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
288 return nil, "internal-server-error"; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
289 end |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
290 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id }); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
291 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
|
292 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
|
293 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
294 return true |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
295 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
296 |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
297 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
|
298 -- 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
|
299 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
|
300 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
|
301 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
302 -- |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 end |
8297
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
307 if self.data[node] and self.data[node].clear then |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
308 self.data[node]:clear() |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
309 else |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
310 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
311 end |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
316 return true |
5305
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
317 end |
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
318 |
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
|
319 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
|
320 -- 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
|
321 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
|
322 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
|
323 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
|
324 -- |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 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
|
329 if id then -- Restrict results to a single specific item |
8316
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
330 local with_id = self.data[node]:get(id); |
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
331 if not with_id then |
8343
5df2f240173b
util.pubsub: Return an empty list if specific item asked for does not exist (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
332 return true, { }; |
8316
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
333 end |
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
334 return true, { id, [id] = with_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
|
335 else |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
336 local data = {} |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
337 for key, value in self.data[node]:items() do |
7726
29c20eefa306
util.pubsub: Fix item retrieval by including the item order as it was before using util.cache (thanks walduhu)
Kim Alvefur <zash@zash.se>
parents:
7703
diff
changeset
|
338 data[#data+1] = key; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
339 data[key] = value; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
340 end |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
341 return true, data; |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
342 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
343 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
344 |
8376
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
345 function service:get_last_item(node, actor) |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
346 -- Access checking |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
347 if not self:may(node, actor, "get_items") then |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
348 return false, "forbidden"; |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
349 end |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
350 -- |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
351 return true, self.data[node]:tail(); |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
352 end |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
353 |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
354 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
|
355 -- Access checking |
3917
263a133bdf5a
util.pubsub: Fix nil global access in get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3910
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 -- |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
360 return true, self.nodes; |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
361 end |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
362 |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
363 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
|
364 -- Access checking |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
365 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
|
366 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
|
367 cap = "get_subscriptions"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
368 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
369 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
|
370 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
371 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
|
372 return false, "forbidden"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
373 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
374 -- |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
375 local node_obj; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
376 if node then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
381 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
382 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
|
383 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
|
384 -- 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
|
385 -- 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
|
386 local ret = {}; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
387 if subs then |
7703
74e755674e0f
util.pubsub: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7696
diff
changeset
|
388 for subscribed_jid, subscribed_nodes in pairs(subs) do |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 node = node; |
7703
74e755674e0f
util.pubsub: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7696
diff
changeset
|
393 jid = subscribed_jid; |
74e755674e0f
util.pubsub: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7696
diff
changeset
|
394 subscription = node_obj.subscribers[subscribed_jid]; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
395 }; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
396 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 node = subscribed_node; |
7703
74e755674e0f
util.pubsub: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7696
diff
changeset
|
402 jid = subscribed_jid; |
74e755674e0f
util.pubsub: Rename loop variable to avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7696
diff
changeset
|
403 subscription = nodes[subscribed_node].subscribers[subscribed_jid]; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
404 }; |
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 end |
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 return true, ret; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
410 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
411 |
3928
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
412 -- 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
|
413 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
|
414 -- Access checking |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
415 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
|
416 return false, "forbidden"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
417 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
418 -- |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
419 local node_obj = self.nodes[node]; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
420 if not node_obj then |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
421 return false, "item-not-found"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
422 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
423 node_obj.capabilities = capabilities; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
424 return true; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
425 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
426 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
427 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
|
428 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
|
429 return false, "forbidden"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
430 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
431 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
432 local node_obj = self.nodes[node]; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
433 if not node_obj then |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
434 return false, "item-not-found"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
435 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
436 |
8401
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
437 if new_config["persist_items"] ~= node_obj.config["persist_items"] then |
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
438 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
439 elseif new_config["max_items"] ~= node_obj.config["max_items"] then |
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
440 self.data[node]:resize(new_config["max_items"]); |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
441 end |
8401
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
442 |
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
443 node_obj.config = setmetatable(new_config, {__index=self.node_defaults}); |
f1923a79c93d
util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
Kim Alvefur <zash@zash.se>
parents:
8382
diff
changeset
|
444 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
445 return true; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
446 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
447 |
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
|
448 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
|
449 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
|
450 }; |