Software /
code /
prosody
Annotate
util/pubsub.lua @ 11772:e2155e2703dd
mod_s2s: Factor out procedure for newly encrypted sessions
Goal is to call this if the connection is using Direct TLS, either via
multiplexing or a future Direct TLS S2S port.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 10 Aug 2021 20:51:31 +0200 |
parent | 11767:5610f7c5b261 |
child | 11854:b605cbd5f13b |
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"; |
10356
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
3 local errors = require "util.error"; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
4 |
8501
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
5 local service_mt = {}; |
3619 | 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; |
10519
641e3b7a6a39
util.pubsub: Pass subscribers trough a filter callback
Kim Alvefur <zash@zash.se>
parents:
10518
diff
changeset
|
10 subscriber_filter = function (subs) return subs end; |
8694
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
11 itemcheck = function () return true; 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
|
12 get_affiliation = function () end; |
8810
9f8a746f99c1
util.pubsub: Add a default/fallback JID normalization function
Kim Alvefur <zash@zash.se>
parents:
8809
diff
changeset
|
13 normalize_jid = function (jid) return jid; end; |
9158
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
14 capabilities = { |
9160
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
15 outcast = { |
9233
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
16 create = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
17 publish = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
18 retract = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
19 get_nodes = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
20 |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
21 subscribe = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
22 unsubscribe = false; |
9172
822e9c5ff4a4
util.pubsub: Allow outcasts to get their subscription status
Matthew Wild <mwild1@gmail.com>
parents:
9161
diff
changeset
|
23 get_subscription = true; |
822e9c5ff4a4
util.pubsub: Allow outcasts to get their subscription status
Matthew Wild <mwild1@gmail.com>
parents:
9161
diff
changeset
|
24 get_subscriptions = true; |
9233
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
25 get_items = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
26 |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
27 subscribe_other = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
28 unsubscribe_other = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
29 get_subscription_other = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
30 get_subscriptions_other = false; |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
31 |
9158
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
32 be_subscribed = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
33 be_unsubscribed = true; |
9233
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
34 |
885dd6845e62
util.pubsub: Explicitly add all capabilities to the 'outcast' affiliation for completeness
Kim Alvefur <zash@zash.se>
parents:
9232
diff
changeset
|
35 set_affiliation = false; |
9158
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
36 }; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
37 none = { |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
38 create = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
39 publish = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
40 retract = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
41 get_nodes = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
42 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
43 subscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
44 unsubscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
45 get_subscription = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
46 get_subscriptions = true; |
9160
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
47 get_items = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
48 |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
49 subscribe_other = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
50 unsubscribe_other = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
51 get_subscription_other = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
52 get_subscriptions_other = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
53 |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
54 be_subscribed = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
55 be_unsubscribed = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
56 |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
57 set_affiliation = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
58 }; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
59 member = { |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
60 create = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
61 publish = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
62 retract = false; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
63 get_nodes = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
64 |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
65 subscribe = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
66 unsubscribe = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
67 get_subscription = true; |
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
68 get_subscriptions = true; |
9158
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
69 get_items = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
70 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
71 subscribe_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
72 unsubscribe_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
73 get_subscription_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
74 get_subscriptions_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
75 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
76 be_subscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
77 be_unsubscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
78 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
79 set_affiliation = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
80 }; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
81 publisher = { |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
82 create = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
83 publish = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
84 retract = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
85 get_nodes = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
86 get_configuration = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
87 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
88 subscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
89 unsubscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
90 get_subscription = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
91 get_subscriptions = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
92 get_items = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
93 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
94 subscribe_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
95 unsubscribe_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
96 get_subscription_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
97 get_subscriptions_other = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
98 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
99 be_subscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
100 be_unsubscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
101 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
102 set_affiliation = false; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
103 }; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
104 owner = { |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
105 create = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
106 publish = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
107 retract = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
108 delete = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
109 get_nodes = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
110 configure = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
111 get_configuration = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
112 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
113 subscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
114 unsubscribe = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
115 get_subscription = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
116 get_subscriptions = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
117 get_items = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
118 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
119 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
120 subscribe_other = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
121 unsubscribe_other = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
122 get_subscription_other = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
123 get_subscriptions_other = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
124 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
125 be_subscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
126 be_unsubscribed = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
127 |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
128 set_affiliation = true; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
129 }; |
37e814a680ab
mod_pubsub, mod_pep, util.pubsub: Move capability definitions into util.pubsub to avoid duplication
Matthew Wild <mwild1@gmail.com>
parents:
9144
diff
changeset
|
130 }; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
131 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
132 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
|
133 |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
134 local default_node_config = { |
11720
72512c0858b3
mod_pubsub: Explicitly enable persistence by default to preserve behavior
Kim Alvefur <zash@zash.se>
parents:
11719
diff
changeset
|
135 ["persist_items"] = true; |
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
|
136 ["max_items"] = 20; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
137 ["access_model"] = "open"; |
9129
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
138 ["publish_model"] = "publishers"; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
139 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
140 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
|
141 |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
142 -- Storage helper functions |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
143 |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
144 local function load_node_from_store(service, node_name) |
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
145 local node = service.config.nodestore:get(node_name); |
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
146 node.config = setmetatable(node.config or {}, {__index=service.node_defaults}); |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
147 return node; |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
148 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
149 |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
150 local function save_node_to_store(service, node) |
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
151 return service.config.nodestore:set(node.name, { |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
152 name = node.name; |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
153 config = node.config; |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
154 subscribers = node.subscribers; |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
155 affiliations = node.affiliations; |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
156 }); |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
157 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
158 |
8952
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
159 local function delete_node_in_store(service, node_name) |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
160 return service.config.nodestore:set(node_name, nil); |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
161 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
162 |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
163 -- Create and return a new service object |
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
|
164 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
|
165 config = config or {}; |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
166 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
167 local service = setmetatable({ |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
168 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
|
169 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
|
170 affiliations = {}; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
171 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
|
172 nodes = {}; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
173 data = {}; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
174 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
|
175 }, service_mt); |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
176 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
177 -- Load nodes from storage, if we have a store and it supports iterating over stored items |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
178 if config.nodestore and config.nodestore.users then |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
179 for node_name in config.nodestore:users() do |
11721
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
180 local node = load_node_from_store(service, node_name); |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
181 service.nodes[node_name] = node; |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
182 if node.config.persist_items then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
183 service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name); |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
184 end |
9742
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
185 |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
186 for jid in pairs(service.nodes[node_name].subscribers) do |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
187 local normal_jid = service.config.normalize_jid(jid); |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
188 local subs = service.subscriptions[normal_jid]; |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
189 if subs then |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
190 if not subs[jid] then |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
191 subs[jid] = { [node_name] = true }; |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
192 else |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
193 subs[jid][node_name] = true; |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
194 end |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
195 else |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
196 service.subscriptions[normal_jid] = { [jid] = { [node_name] = true } }; |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
197 end |
18eca6afb367
util.pubsub: Restore subscription index from stored data (fixes #1281)
Kim Alvefur <zash@zash.se>
parents:
9539
diff
changeset
|
198 end |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
199 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
200 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
201 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
202 return service; |
3619 | 203 end |
204 | |
8501
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
205 --- Service methods |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
206 |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
207 local service = {}; |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
208 service_mt.__index = service; |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
209 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
210 function service:jids_equal(jid1, jid2) --> boolean |
3934
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
211 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
|
212 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
|
213 end |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
214 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
215 function service:may(node, actor, action) --> boolean |
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 if actor == true then return true; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
217 |
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
|
218 local node_obj = self.nodes[node]; |
8816
0f9d5cfa84f9
util.pubsub: Also check for affiliation set on bare JID
Kim Alvefur <zash@zash.se>
parents:
8813
diff
changeset
|
219 local node_aff = node_obj and (node_obj.affiliations[actor] |
0f9d5cfa84f9
util.pubsub: Also check for affiliation set on bare JID
Kim Alvefur <zash@zash.se>
parents:
8813
diff
changeset
|
220 or node_obj.affiliations[self.config.normalize_jid(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
|
221 local service_aff = self.affiliations[actor] |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
222 or self.config.get_affiliation(actor, node, action); |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
223 local default_aff = self:get_default_affiliation(node, actor) or "none"; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
224 |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
225 -- 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
|
226 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
|
227 if node_capabilities then |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
228 local caps = node_capabilities[node_aff or service_aff or default_aff]; |
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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
236 |
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
|
237 -- Check service-wide capabilities instead |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
238 local service_capabilities = self.config.capabilities; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
239 local caps = service_capabilities[node_aff or service_aff or default_aff]; |
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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
246 |
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
|
247 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
|
248 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
|
249 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
250 function service:get_default_affiliation(node, actor) --> affiliation |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
251 local node_obj = self.nodes[node]; |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
252 local access_model = node_obj and node_obj.config.access_model |
9106
e70b9e8bc443
util.pubsub: Use service.node_defaults in case config.node_defaults was not provided (thanks jonasw)
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
253 or self.node_defaults.access_model; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
254 |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
255 if access_model == "open" then |
9161
da154ced7de4
util.pubsub: For open nodes, default affiliation is "member"
Matthew Wild <mwild1@gmail.com>
parents:
9160
diff
changeset
|
256 return "member"; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
257 elseif access_model == "whitelist" then |
9160
e13a1a0b0107
mod_pep, util.pubsub: Rename restricted->outcast, none->member and add new 'none' affiliation to better match XEP-0060
Matthew Wild <mwild1@gmail.com>
parents:
9158
diff
changeset
|
258 return "outcast"; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
259 end |
9098
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
260 |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
261 if self.config.access_models then |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
262 local check = self.config.access_models[access_model]; |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
263 if check then |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
264 local aff = check(actor); |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
265 if aff then |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
266 return aff; |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
267 end |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
268 end |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
269 end |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
270 end |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
271 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
272 function service:set_affiliation(node, actor, jid, affiliation) --> ok, err |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
273 -- Access checking |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
274 if not self:may(node, actor, "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
|
275 return false, "forbidden"; |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
276 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
277 -- |
3619 | 278 local node_obj = self.nodes[node]; |
279 if not node_obj then | |
280 return false, "item-not-found"; | |
281 end | |
8941 | 282 jid = self.config.normalize_jid(jid); |
8954
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
283 local old_affiliation = node_obj.affiliations[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
|
284 node_obj.affiliations[jid] = affiliation; |
8954
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
285 |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
286 if self.config.nodestore then |
10537
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
287 -- TODO pass the error from storage to caller eg wrapped in an util.error |
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
288 local ok, err = save_node_to_store(self, node_obj); -- luacheck: ignore 211/err |
8954
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
289 if not ok then |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
290 node_obj.affiliations[jid] = old_affiliation; |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
291 return ok, "internal-server-error"; |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
292 end |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
293 end |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
294 |
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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
310 function service:add_subscription(node, actor, jid, options) --> ok, err |
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
|
311 -- 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
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 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
325 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
|
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 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 end |
3936
61f12f8a8539
util.pubsub: Fix traceback when using autocreate-on-subscribe
Matthew Wild <mwild1@gmail.com>
parents:
3934
diff
changeset
|
334 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
|
335 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
|
336 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
337 local old_subscription = node_obj.subscribers[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
|
338 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
|
339 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
|
340 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
|
341 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
342 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
|
343 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
|
344 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
345 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
|
346 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
347 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
348 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
|
349 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
350 |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
351 if self.config.nodestore then |
10537
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
352 -- TODO pass the error from storage to caller eg wrapped in an util.error |
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
353 local ok, err = save_node_to_store(self, node_obj); -- luacheck: ignore 211/err |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
354 if not ok then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
355 node_obj.subscribers[jid] = old_subscription; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
356 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
357 return ok, "internal-server-error"; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
358 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
359 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
360 |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
361 self.events.fire_event("subscription-added", { service = self, node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
3619 | 362 return true; |
363 end | |
364 | |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
365 function service:remove_subscription(node, actor, jid) --> ok, err |
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
|
366 -- 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 -- |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
380 local node_obj = self.nodes[node]; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
381 if not node_obj then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
382 return false, "item-not-found"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
383 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
384 if not node_obj.subscribers[jid] then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
385 return false, "not-subscribed"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
386 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
387 local old_subscription = node_obj.subscribers[jid]; |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 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
|
396 subs[jid] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
397 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
398 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
399 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
|
400 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
|
401 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
402 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
403 |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
404 if self.config.nodestore then |
10537
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
405 -- TODO pass the error from storage to caller eg wrapped in an util.error |
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
406 local ok, err = save_node_to_store(self, node_obj); -- luacheck: ignore 211/err |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
407 if not ok then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
408 node_obj.subscribers[jid] = old_subscription; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
409 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
410 return ok, "internal-server-error"; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
411 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
412 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
413 |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
414 self.events.fire_event("subscription-removed", { service = self, node = node, jid = jid, normalized_jid = normal_jid }); |
3619 | 415 return true; |
416 end | |
417 | |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
418 function service:get_subscription(node, actor, jid) --> (true, subscription) or (false, err) |
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
|
419 -- 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 -- |
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
|
430 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
|
431 if not node_obj then |
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
432 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
|
433 end |
3937
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
434 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
|
435 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
|
436 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
437 function service:create(node, actor, options) --> ok, err |
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
|
438 -- 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
|
439 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
|
440 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
|
441 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
|
442 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
443 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
|
444 return false, "conflict"; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
445 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
446 |
9840
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
447 local config = setmetatable(options or {}, {__index=self.node_defaults}); |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
448 |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
449 if self.config.check_node_config then |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
450 local ok = self.config.check_node_config(node, actor, config); |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
451 if not ok then |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
452 return false, "not-acceptable"; |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
453 end |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
454 end |
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
455 |
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
|
456 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
|
457 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
|
458 subscribers = {}; |
9840
ec353524b739
util.pubsub: Validate node configuration on node creation (fixes #1328)
Kim Alvefur <zash@zash.se>
parents:
9816
diff
changeset
|
459 config = config; |
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
|
460 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
|
461 }; |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
462 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
463 if self.config.nodestore then |
10537
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
464 -- TODO pass the error from storage to caller eg wrapped in an util.error |
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
465 local ok, err = save_node_to_store(self, self.nodes[node]); -- luacheck: ignore 211/err |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
466 if not ok then |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
467 self.nodes[node] = nil; |
8956
82f92af4b0f3
util.pubsub: Return error code known by pubsub.lib if persistent creation fails
Kim Alvefur <zash@zash.se>
parents:
8955
diff
changeset
|
468 return ok, "internal-server-error"; |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
469 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
470 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
471 |
11721
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
472 if config.persist_items then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
473 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
474 end |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
475 |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
476 self.events.fire_event("node-created", { service = self, node = node, actor = actor }); |
8809
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
477 if actor ~= true then |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
478 local ok, err = self:set_affiliation(node, true, actor, "owner"); |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
479 if not ok then |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
480 self.nodes[node] = nil; |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
481 self.data[node] = nil; |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
482 return ok, err; |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
483 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
|
484 end |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
485 |
8809
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
486 return true; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
487 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
488 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
489 function service:delete(node, actor) --> ok, err |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
490 -- Access checking |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
491 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
|
492 return false, "forbidden"; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
493 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
494 -- |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
495 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
|
496 if not node_obj then |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
497 return false, "item-not-found"; |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
498 end |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
499 self.nodes[node] = nil; |
8312
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
500 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
|
501 self.data[node]:clear(); |
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
502 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
503 self.data[node] = nil; |
8952
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
504 |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
505 if self.config.nodestore then |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
506 local ok, err = delete_node_in_store(self, node); |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
507 if not ok then |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
508 self.nodes[node] = nil; |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
509 return ok, err; |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
510 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
511 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
512 |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
513 self.events.fire_event("node-deleted", { service = self, node = node, actor = actor }); |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
514 self:broadcast("delete", node, node_obj.subscribers, nil, actor, node_obj); |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
515 return true; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
516 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
517 |
9200
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
518 -- Used to check that the config of a node is as expected (i.e. 'publish-options') |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
519 local function check_preconditions(node_config, required_config) |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
520 if not (node_config and required_config) then |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
521 return false; |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
522 end |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
523 for config_field, value in pairs(required_config) do |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
524 if node_config[config_field] ~= value then |
10356
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
525 return false, config_field; |
9200
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
526 end |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
527 end |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
528 return true; |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
529 end |
249d90ff992e
pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents:
9195
diff
changeset
|
530 |
9516
038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents:
9236
diff
changeset
|
531 function service:publish(node, actor, id, item, requested_config) --> ok, err |
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
|
532 -- Access checking |
9129
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
533 local may_publish = false; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
534 |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
535 if self:may(node, actor, "publish") then |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
536 may_publish = true; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
537 else |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
538 local node_obj = self.nodes[node]; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
539 local publish_model = node_obj and node_obj.config.publish_model; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
540 if publish_model == "open" |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
541 or (publish_model == "subscribers" and node_obj.subscribers[actor]) then |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
542 may_publish = true; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
543 end |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
544 end |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
545 if not may_publish 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
|
546 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
|
547 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
|
548 -- |
3619 | 549 local node_obj = self.nodes[node]; |
550 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
|
551 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
|
552 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
|
553 end |
9516
038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents:
9236
diff
changeset
|
554 local ok, err = self:create(node, true, requested_config); |
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
|
555 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
|
556 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
|
557 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
|
558 node_obj = self.nodes[node]; |
9516
038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents:
9236
diff
changeset
|
559 elseif requested_config and not requested_config._defaults_only then |
038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents:
9236
diff
changeset
|
560 -- Check that node has the requested config before we publish |
10356
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
561 local ok, field = check_preconditions(node_obj.config, requested_config); |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
562 if not ok then |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
563 local err = errors.new({ |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
564 type = "cancel", condition = "conflict", text = "Field does not match: "..field; |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
565 }); |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
566 err.pubsub_condition = "precondition-not-met"; |
0a2d7efca039
util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents:
9840
diff
changeset
|
567 return false, err; |
9516
038446c50630
util.pubsub: Allow publishing with a config that should be used as defaults only
Matthew Wild <mwild1@gmail.com>
parents:
9236
diff
changeset
|
568 end |
3619 | 569 end |
8694
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
570 if not self.config.itemcheck(item) then |
9207
76d593b35958
util.pubsub, pubsub.lib: Improve error on attempt to publish invalid item
Matthew Wild <mwild1@gmail.com>
parents:
9206
diff
changeset
|
571 return nil, "invalid-item"; |
8694
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
572 end |
11721
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
573 if node_obj.config.persist_items then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
574 if not self.data[node] then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
575 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
576 end |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
577 local ok = self.data[node]:set(id, item); |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
578 if not ok then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
579 return nil, "internal-server-error"; |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
580 end |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
581 if type(ok) == "string" then id = ok; end |
11565
087b275a9aee
util.pubsub: Fix traceback if node data not initialized
Kim Alvefur <zash@zash.se>
parents:
10519
diff
changeset
|
582 end |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
583 local event_data = { service = self, node = node, actor = actor, id = id, item = item }; |
9218
7e27dc4d100b
util.pubsub: Fire item-published/<node> to allow for easier handling of per-node items
Matthew Wild <mwild1@gmail.com>
parents:
9207
diff
changeset
|
584 self.events.fire_event("item-published/"..node, event_data); |
7e27dc4d100b
util.pubsub: Fire item-published/<node> to allow for easier handling of per-node items
Matthew Wild <mwild1@gmail.com>
parents:
9207
diff
changeset
|
585 self.events.fire_event("item-published", event_data); |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
586 self:broadcast("items", node, node_obj.subscribers, item, actor, node_obj); |
3619 | 587 return true; |
588 end | |
589 | |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
590 function service:broadcast(event, node, subscribers, item, actor, node_obj) |
10519
641e3b7a6a39
util.pubsub: Pass subscribers trough a filter callback
Kim Alvefur <zash@zash.se>
parents:
10518
diff
changeset
|
591 subscribers = self.config.subscriber_filter(subscribers, node, event); |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
592 return self.config.broadcaster(event, node, subscribers, item, actor, node_obj, self); |
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
593 end |
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
594 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
595 function service:retract(node, actor, id, retract) --> ok, err |
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
|
596 -- 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
|
597 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
|
598 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
|
599 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
|
600 -- |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
601 local node_obj = self.nodes[node]; |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
602 if not node_obj then |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
603 return false, "item-not-found"; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
604 end |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
605 if self.data[node] then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
606 if not self.data[node]:get(id) then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
607 return false, "item-not-found"; |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
608 end |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
609 local ok = self.data[node]:set(id, nil); |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
610 if not ok then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
611 return nil, "internal-server-error"; |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
612 end |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
613 end |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
614 self.events.fire_event("item-retracted", { service = self, node = node, actor = actor, id = id }); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
615 if retract then |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
616 self:broadcast("retract", node, node_obj.subscribers, retract, actor, node_obj); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
617 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
618 return true |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
619 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
620 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
621 function service:purge(node, actor, notify) --> ok, err |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
622 -- 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
|
623 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
|
624 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
|
625 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
626 -- |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
627 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
|
628 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
|
629 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
|
630 end |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
631 if self.data[node] then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
632 if self.data[node].clear then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
633 self.data[node]:clear() |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
634 else |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
635 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
636 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
|
637 end |
9230
711fea229e48
util.pubsub: Add 'service' field to all events
Matthew Wild <mwild1@gmail.com>
parents:
9220
diff
changeset
|
638 self.events.fire_event("node-purged", { service = self, 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
|
639 if notify then |
10518
9f50489c2033
util.pubsub: Factor out calling of broadcaster
Kim Alvefur <zash@zash.se>
parents:
9840
diff
changeset
|
640 self:broadcast("purge", node, node_obj.subscribers, nil, actor, node_obj); |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
641 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
642 return true |
5305
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
643 end |
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
644 |
11767
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
645 function service:get_items(node, actor, ids, resultspec) --> (true, { id, [id] = node }) or (false, err) |
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
|
646 -- 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
|
647 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
|
648 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
|
649 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
|
650 -- |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 end |
11723
3ead0967e04d
util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents:
11721
diff
changeset
|
655 if not self.data[node] then |
3ead0967e04d
util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents:
11721
diff
changeset
|
656 -- Disabled rather than unsupported, but close enough. |
3ead0967e04d
util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents:
11721
diff
changeset
|
657 return false, "persistent-items-unsupported"; |
3ead0967e04d
util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents:
11721
diff
changeset
|
658 end |
9816
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
659 if type(ids) == "string" then -- COMPAT see #1305 |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
660 ids = { ids }; |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
661 end |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
662 local data = {}; |
11767
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
663 local limit = resultspec and resultspec.max; |
9816
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
664 if ids then |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
665 for _, key in ipairs(ids) do |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
666 local value = self.data[node]:get(key); |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
667 if value then |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
668 data[#data+1] = key; |
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
669 data[key] = value; |
11767
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
670 -- Limits and ids seem like a problematic combination. |
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
671 if limit and #data >= limit then break end |
9816
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
672 end |
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
|
673 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
|
674 else |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
675 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
|
676 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
|
677 data[key] = value; |
11767
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
678 if limit and #data >= limit then break |
5610f7c5b261
util.pubsub: Add support for limiting number of items to retrieve
Kim Alvefur <zash@zash.se>
parents:
11723
diff
changeset
|
679 end |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
680 end |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
681 end |
9816
7f84d7f77a00
util.pubsub: Add support for requesting multiple specific items (needed for #1305)
Kim Alvefur <zash@zash.se>
parents:
9742
diff
changeset
|
682 return true, data; |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
683 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
684 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
685 function service:get_last_item(node, actor) --> (true, id, node) or (false, err) |
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
|
686 -- 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
|
687 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
|
688 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
|
689 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
|
690 -- |
9201
1555ea0d6f61
util.pubsub: get_last_item(): Return error if node does not exist
Matthew Wild <mwild1@gmail.com>
parents:
9200
diff
changeset
|
691 |
9203
c65bfddd3cc5
Backed out changeset 27d800ddc3b0 (see below)
Matthew Wild <mwild1@gmail.com>
parents:
9202
diff
changeset
|
692 -- Check node exists |
c65bfddd3cc5
Backed out changeset 27d800ddc3b0 (see below)
Matthew Wild <mwild1@gmail.com>
parents:
9202
diff
changeset
|
693 if not self.nodes[node] then |
9201
1555ea0d6f61
util.pubsub: get_last_item(): Return error if node does not exist
Matthew Wild <mwild1@gmail.com>
parents:
9200
diff
changeset
|
694 return false, "item-not-found"; |
1555ea0d6f61
util.pubsub: get_last_item(): Return error if node does not exist
Matthew Wild <mwild1@gmail.com>
parents:
9200
diff
changeset
|
695 end |
9204
c5a81acc1fc3
util.pubsub: Fix whitespace [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
9203
diff
changeset
|
696 |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
697 if not self.data[node] then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
698 -- FIXME Should this be a success or failure? |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
699 return true, nil; |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
700 end |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
701 |
9195
b6ffd4f951b9
util.pubsub: Add comment to clarify return values
Matthew Wild <mwild1@gmail.com>
parents:
9179
diff
changeset
|
702 -- Returns success, id, item |
9206
33ee40dc3e25
Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents:
9204
diff
changeset
|
703 return true, self.data[node]:head(); |
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
|
704 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
|
705 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
706 function service:get_nodes(actor) --> (true, map) or (false, err) |
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
|
707 -- Access checking |
3917
263a133bdf5a
util.pubsub: Fix nil global access in get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3910
diff
changeset
|
708 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
|
709 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
|
710 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
|
711 -- |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
712 return true, self.nodes; |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
713 end |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
714 |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
715 local function flatten_subscriptions(ret, serv, subs, node, node_obj) |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
716 for subscribed_jid, subscribed_nodes in pairs(subs) do |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
717 if node then -- Return only subscriptions to this node |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
718 if subscribed_nodes[node] then |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
719 ret[#ret+1] = { |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
720 node = node; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
721 jid = subscribed_jid; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
722 subscription = node_obj.subscribers[subscribed_jid]; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
723 }; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
724 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
725 else -- Return subscriptions to all nodes |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
726 local nodes = serv.nodes; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
727 for subscribed_node in pairs(subscribed_nodes) do |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
728 ret[#ret+1] = { |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
729 node = subscribed_node; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
730 jid = subscribed_jid; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
731 subscription = nodes[subscribed_node].subscribers[subscribed_jid]; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
732 }; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
733 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
734 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
735 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
736 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
737 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
738 function service:get_subscriptions(node, actor, jid) --> (true, array) or (false, err) |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
739 -- Access checking |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
740 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
|
741 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
|
742 cap = "get_subscriptions"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
743 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
744 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
|
745 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
746 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
|
747 return false, "forbidden"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
748 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
749 -- |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
750 local node_obj; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
751 if node then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
752 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
|
753 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
|
754 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
|
755 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
756 end |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
757 local ret = {}; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
758 if jid == nil then |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
759 for _, subs in pairs(self.subscriptions) do |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
760 flatten_subscriptions(ret, self, subs, node, node_obj) |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
761 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
762 return true, ret; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
763 end |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
764 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
|
765 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
|
766 -- 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
|
767 -- 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
|
768 if subs then |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
769 flatten_subscriptions(ret, self, subs, node, node_obj) |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
770 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
771 return true, ret; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
772 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
773 |
3928
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
774 -- Access models only affect 'none' affiliation caps, service/default access level... |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
775 function service:set_node_capabilities(node, actor, capabilities) --> ok, err |
3928
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
776 -- Access checking |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
777 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
|
778 return false, "forbidden"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
779 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
780 -- |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
781 local node_obj = self.nodes[node]; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
782 if not node_obj then |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
783 return false, "item-not-found"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
784 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
785 node_obj.capabilities = capabilities; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
786 return true; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
787 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
788 |
9232
65c83bfcf2ee
util.pubsub: Comments describing the return values of methods
Kim Alvefur <zash@zash.se>
parents:
9230
diff
changeset
|
789 function service:set_node_config(node, actor, new_config) --> ok, err |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
790 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
|
791 return false, "forbidden"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
792 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
793 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
794 local node_obj = self.nodes[node]; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
795 if not node_obj then |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
796 return false, "item-not-found"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
797 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
798 |
9117
a19fdc6e4f09
util.pubsub: Apply defaults metatable before config check (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9107
diff
changeset
|
799 setmetatable(new_config, {__index=self.node_defaults}) |
a19fdc6e4f09
util.pubsub: Apply defaults metatable before config check (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9107
diff
changeset
|
800 |
9075
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
801 if self.config.check_node_config then |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
802 local ok = self.config.check_node_config(node, actor, new_config); |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
803 if not ok then |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
804 return false, "not-acceptable"; |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
805 end |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
806 end |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
807 |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
808 local old_config = node_obj.config; |
9117
a19fdc6e4f09
util.pubsub: Apply defaults metatable before config check (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9107
diff
changeset
|
809 node_obj.config = new_config; |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
810 |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
811 if self.config.nodestore then |
10537
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
812 -- TODO pass the error from storage to caller eg wrapped in an util.error |
c5558138ce33
util.pubsub: Silence luacheck warnings, leaving notes on future proper fix
Kim Alvefur <zash@zash.se>
parents:
10521
diff
changeset
|
813 local ok, err = save_node_to_store(self, node_obj); -- luacheck: ignore 211/err |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
814 if not ok then |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
815 node_obj.config = old_config; |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
816 return ok, "internal-server-error"; |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
817 end |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
818 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
|
819 |
9138
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
820 if old_config["access_model"] ~= node_obj.config["access_model"] then |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
821 for subscriber in pairs(node_obj.subscribers) do |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
822 if not self:may(node, subscriber, "be_subscribed") then |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
823 local ok, err = self:remove_subscription(node, true, subscriber); |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
824 if not ok then |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
825 node_obj.config = old_config; |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
826 return ok, err; |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
827 end |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
828 end |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
829 end |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
830 end |
db47db788295
util.pubsub: Re-check all subscriptions on access_model change, unsubscribing those no longer allowed
Kim Alvefur <zash@zash.se>
parents:
9129
diff
changeset
|
831 |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
832 if old_config["persist_items"] ~= node_obj.config["persist_items"] then |
11721
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
833 if node_obj.config["persist_items"] then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
834 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
835 elseif self.data[node] then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
836 if self.data[node].clear then |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
837 self.data[node]:clear() |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
838 end |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
839 self.data[node] = nil; |
7a77f0c05382
util.pubsub: Fix behavior of persist_items disabled
Kim Alvefur <zash@zash.se>
parents:
11720
diff
changeset
|
840 end |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
841 elseif old_config["max_items"] ~= node_obj.config["max_items"] then |
11719
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
842 if self.data[node] then |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
843 self.data[node]:resize(self.nodes[node].config["max_items"]); |
3986b5a0c3fc
util.pubsub: Handle absence of node data interface
Kim Alvefur <zash@zash.se>
parents:
11567
diff
changeset
|
844 end |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
845 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
|
846 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
847 return true; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
848 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
849 |
9539
b30455212f89
util.pubsub: Clarify comment about return value
Kim Alvefur <zash@zash.se>
parents:
9516
diff
changeset
|
850 function service:get_node_config(node, actor) --> (true, config) or (false, err) |
9107
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
851 if not self:may(node, actor, "get_configuration") then |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
852 return false, "forbidden"; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
853 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
854 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
855 local node_obj = self.nodes[node]; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
856 if not node_obj then |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
857 return false, "item-not-found"; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
858 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
859 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
860 local config_table = {}; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
861 for k, v in pairs(default_node_config) do |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
862 config_table[k] = v; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
863 end |
9144
b40efef8ec99
util.pubsub: Include node defaults from current service object
Kim Alvefur <zash@zash.se>
parents:
9138
diff
changeset
|
864 for k, v in pairs(self.node_defaults) do |
b40efef8ec99
util.pubsub: Include node defaults from current service object
Kim Alvefur <zash@zash.se>
parents:
9138
diff
changeset
|
865 config_table[k] = v; |
b40efef8ec99
util.pubsub: Include node defaults from current service object
Kim Alvefur <zash@zash.se>
parents:
9138
diff
changeset
|
866 end |
9107
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
867 for k, v in pairs(node_obj.config) do |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
868 config_table[k] = v; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
869 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
870 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
871 return true, config_table; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
872 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
873 |
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
|
874 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
|
875 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
|
876 }; |