Software /
code /
prosody
Annotate
util/pubsub.lua @ 9172:822e9c5ff4a4
util.pubsub: Allow outcasts to get their subscription status
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Aug 2018 11:33:22 +0100 |
parent | 9161:da154ced7de4 |
child | 9179:82fad995a149 |
rev | line source |
---|---|
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
1 local events = require "util.events"; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
2 local cache = require "util.cache"; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
3 |
8501
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
4 local service_mt = {}; |
3619 | 5 |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
6 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
|
7 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
|
8 broadcaster = function () end; |
8694
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
9 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
|
10 get_affiliation = function () end; |
8810
9f8a746f99c1
util.pubsub: Add a default/fallback JID normalization function
Kim Alvefur <zash@zash.se>
parents:
8809
diff
changeset
|
11 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
|
12 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
|
13 outcast = { |
9172
822e9c5ff4a4
util.pubsub: Allow outcasts to get their subscription status
Matthew Wild <mwild1@gmail.com>
parents:
9161
diff
changeset
|
14 get_subscription = true; |
822e9c5ff4a4
util.pubsub: Allow outcasts to get their subscription status
Matthew Wild <mwild1@gmail.com>
parents:
9161
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 }; |
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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 |
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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 |
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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 |
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
|
36 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
|
37 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
|
38 |
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
|
39 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
|
40 }; |
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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 |
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 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 |
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
|
58 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
|
59 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
|
60 |
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
|
61 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
|
62 }; |
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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 |
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 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
|
71 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
|
72 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
|
73 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
|
74 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
|
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 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
|
77 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
|
78 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
|
79 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
|
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 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
|
82 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
|
83 |
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 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
|
85 }; |
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 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 |
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 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 |
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 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
|
103 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
|
104 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
|
105 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
|
106 |
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 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
|
108 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
|
109 |
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 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
|
111 }; |
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 }; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
113 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
114 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
|
115 |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
116 local default_node_config = { |
8333
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8326
diff
changeset
|
117 ["persist_items"] = false; |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8326
diff
changeset
|
118 ["max_items"] = 20; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
119 ["access_model"] = "open"; |
9129
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
120 ["publish_model"] = "publishers"; |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
121 }; |
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
122 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
|
123 |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
124 -- 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
|
125 |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 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
|
130 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
131 |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 }); |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
139 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
140 |
8952
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
141 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
|
142 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
|
143 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
144 |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
145 -- 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
|
146 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
|
147 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
|
148 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
149 local service = setmetatable({ |
8500
9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
Matthew Wild <mwild1@gmail.com>
parents:
8401
diff
changeset
|
150 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
|
151 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
|
152 affiliations = {}; |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
153 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
|
154 nodes = {}; |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
155 data = {}; |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
156 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
|
157 }, 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
|
158 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
159 -- 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
|
160 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
|
161 for node_name in config.nodestore:users() do |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
162 service.nodes[node_name] = load_node_from_store(service, 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
|
163 service.data[node_name] = config.itemstore(service.nodes[node_name].config, 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
|
164 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
165 end |
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 return service; |
3619 | 168 end |
169 | |
8501
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
170 --- Service methods |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
171 |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
172 local service = {}; |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
173 service_mt.__index = service; |
8d9e2c2095dd
util.pubsub: Move service methods object creation (just code reorganisation)
Matthew Wild <mwild1@gmail.com>
parents:
8500
diff
changeset
|
174 |
3934
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
175 function service:jids_equal(jid1, jid2) |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
176 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
|
177 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
|
178 end |
4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
Matthew Wild <mwild1@gmail.com>
parents:
3931
diff
changeset
|
179 |
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
|
180 function service:may(node, actor, action) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
181 if actor == true then return true; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
182 |
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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
190 -- 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
|
191 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
|
192 if node_capabilities then |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
201 |
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
|
202 -- Check service-wide capabilities instead |
4099
5c0b7947f0ef
util.pubsub: Some tidying/optimisation to service:may()
Matthew Wild <mwild1@gmail.com>
parents:
3945
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
211 |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
212 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
|
213 end |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
214 |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
215 function service:get_default_affiliation(node, actor, action) -- luacheck: ignore 212 |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
220 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
|
221 return "member"; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
222 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
|
223 return "outcast"; |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
224 end |
9098
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
225 |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 return aff; |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
232 end |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
233 end |
d5bc306e93aa
util.pubsub: Look for a configured callback for more complicated access models
Kim Alvefur <zash@zash.se>
parents:
9095
diff
changeset
|
234 end |
9095
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
diff
changeset
|
235 end |
5639dc1a3f85
util.pubsub: Add initial support for configurable access models
Kim Alvefur <zash@zash.se>
parents:
9075
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 function service:set_affiliation(node, actor, jid, affiliation) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
238 -- 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
|
239 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
|
240 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
|
241 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
|
242 -- |
3619 | 243 local node_obj = self.nodes[node]; |
244 if not node_obj then | |
245 return false, "item-not-found"; | |
246 end | |
8941 | 247 jid = self.config.normalize_jid(jid); |
8954
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
248 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
|
249 node_obj.affiliations[jid] = affiliation; |
8954
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
250 |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
251 if self.config.nodestore then |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
252 local ok, err = save_node_to_store(self, node_obj); |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
253 if not ok then |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
254 node_obj.affiliations[jid] = old_affiliation; |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
255 return ok, "internal-server-error"; |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
256 end |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
257 end |
3b6095686498
util.pubsub: Persistence on affiliation change
Kim Alvefur <zash@zash.se>
parents:
8952
diff
changeset
|
258 |
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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return 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 function service:add_subscription(node, actor, jid, options) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
275 -- 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 end |
3936
61f12f8a8539
util.pubsub: Fix traceback when using autocreate-on-subscribe
Matthew Wild <mwild1@gmail.com>
parents:
3934
diff
changeset
|
298 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
|
299 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
|
300 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 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
|
305 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
306 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
|
307 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
|
308 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
309 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
|
310 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
311 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
312 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
|
313 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
314 |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
315 if self.config.nodestore then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
316 local ok, err = save_node_to_store(self, node_obj); |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
317 if not ok then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
318 node_obj.subscribers[jid] = old_subscription; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
319 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
|
320 return ok, "internal-server-error"; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
321 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
322 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
323 |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
324 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
3619 | 325 return true; |
326 end | |
327 | |
328 function service:remove_subscription(node, actor, jid) | |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
329 -- 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
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 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 -- |
3698
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
343 local node_obj = self.nodes[node]; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
344 if not node_obj then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
345 return false, "item-not-found"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
346 end |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
347 if not node_obj.subscribers[jid] then |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
348 return false, "not-subscribed"; |
77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
Florian Zeitz <florob@babelmonkeys.de>
parents:
3672
diff
changeset
|
349 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 if subs then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 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
|
359 subs[jid] = nil; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
360 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
361 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
362 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
|
363 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
|
364 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
365 end |
8955
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
366 |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
367 if self.config.nodestore then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
368 local ok, err = save_node_to_store(self, node_obj); |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
369 if not ok then |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
370 node_obj.subscribers[jid] = old_subscription; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
371 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
|
372 return ok, "internal-server-error"; |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
373 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
374 end |
ca6a09cf2829
util.pubsub: Store subscription changes
Kim Alvefur <zash@zash.se>
parents:
8954
diff
changeset
|
375 |
4365
6704b3cd032e
util.pubsub: Support for events (currently subscription-added and subscription-removed)
Matthew Wild <mwild1@gmail.com>
parents:
4364
diff
changeset
|
376 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); |
3619 | 377 return true; |
378 end | |
379 | |
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
|
380 function service:get_subscription(node, actor, jid) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
381 -- 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 -- |
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
|
392 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
|
393 if not node_obj then |
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
394 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
|
395 end |
3937
843ee23cc91a
util.pubsub: Small code tidying for :get_subscription()
Matthew Wild <mwild1@gmail.com>
parents:
3936
diff
changeset
|
396 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
|
397 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
|
398 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
399 function service:create(node, actor, options) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
400 -- 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
|
401 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
|
402 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
|
403 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
|
404 -- |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
405 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
|
406 return false, "conflict"; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
407 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5675
diff
changeset
|
408 |
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
|
409 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
|
410 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
|
411 subscribers = {}; |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
412 config = setmetatable(options or {}, {__index=self.node_defaults}); |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
413 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
|
414 }; |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
415 |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
416 if self.config.nodestore then |
8950
03ba5b4f131a
util.pubsub: Fix applying per service node defaults when loading from nodestore
Kim Alvefur <zash@zash.se>
parents:
8941
diff
changeset
|
417 local ok, err = save_node_to_store(self, self.nodes[node]); |
8502
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
422 end |
6c2c2fc4b8dd
util.pubsub: Support a 'nodestore' for persisting nodes (same API as kv stores)
Matthew Wild <mwild1@gmail.com>
parents:
8501
diff
changeset
|
423 |
8211
5cbbe825d9d1
util.pubsub: Add a node parameter to itemstore().
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7727
diff
changeset
|
424 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
425 self.events.fire_event("node-created", { 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 return ok, err; |
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
432 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
|
433 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
|
434 |
8809
6cba2df3817c
util.pubsub: Don't record the superuser as owner on creation
Kim Alvefur <zash@zash.se>
parents:
8694
diff
changeset
|
435 return true; |
3672
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
436 end |
b24db47995ac
mod_pubsub, util.pubsub: Support node creation
Florian Zeitz <florob@babelmonkeys.de>
parents:
3641
diff
changeset
|
437 |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
438 function service:delete(node, actor) |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
439 -- Access checking |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
440 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
|
441 return false, "forbidden"; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
442 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
443 -- |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
444 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
|
445 if not node_obj then |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
446 return false, "item-not-found"; |
e29ece65e3b0
util.pubsub: Check whether node exists, when deleting
Florian Zeitz <florob@babelmonkeys.de>
parents:
5628
diff
changeset
|
447 end |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
448 self.nodes[node] = nil; |
8312
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
449 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
|
450 self.data[node]:clear(); |
6fd36e73082b
util.pubsub: Clear data on node deletion
Kim Alvefur <zash@zash.se>
parents:
8297
diff
changeset
|
451 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
452 self.data[node] = nil; |
8952
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
453 |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
454 if self.config.nodestore then |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
455 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
|
456 if not ok then |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
457 self.nodes[node] = nil; |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
458 return ok, err; |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
459 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
460 end |
15bb54f96dd1
util.pubsub: Remove node from persistent storage on deletion
Kim Alvefur <zash@zash.se>
parents:
8951
diff
changeset
|
461 |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
462 self.events.fire_event("node-deleted", { node = node, actor = actor }); |
8813
2c55fccb0c0c
util.pubsub: Pass node and service objects to broadcaster to allow eg config access
Kim Alvefur <zash@zash.se>
parents:
8810
diff
changeset
|
463 self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self); |
5320
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
464 return true; |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
465 end |
518d864b2ab8
mod_pubsub, util.pubsub: Add delete action
Kim Alvefur <zash@zash.se>
parents:
5315
diff
changeset
|
466 |
3619 | 467 function service:publish(node, actor, id, item) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
468 -- Access checking |
9129
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
469 local may_publish = false; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
470 |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
471 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
|
472 may_publish = true; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
473 else |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
474 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
|
475 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
|
476 if publish_model == "open" |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
477 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
|
478 may_publish = true; |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
479 end |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
480 end |
7721794e9e93
util.pubsub: Add support for publish_model config option
Matthew Wild <mwild1@gmail.com>
parents:
9117
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 -- |
3619 | 485 local node_obj = self.nodes[node]; |
486 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
|
487 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
|
488 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
|
489 end |
4364
af40cf682eba
util.pubsub: Use built-in actor for auto-creating nodes on publish and subscribe (so they never fail due to permissions)
Matthew Wild <mwild1@gmail.com>
parents:
4100
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 node_obj = self.nodes[node]; |
3619 | 495 end |
8694
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
496 if not self.config.itemcheck(item) then |
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
497 return nil, "internal-server-error"; |
059183e5571e
util.pubsub: Allow setting a callback for validating items to be published
Kim Alvefur <zash@zash.se>
parents:
8502
diff
changeset
|
498 end |
5972
f365d3c8fd2c
util.pubsub: Separate data from node configuration
Kim Alvefur <zash@zash.se>
parents:
5971
diff
changeset
|
499 local node_data = self.data[node]; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
500 local ok = node_data:set(id, item); |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
501 if not ok then |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
502 return nil, "internal-server-error"; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
503 end |
8217
5f4e0d67b82a
util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents:
8212
diff
changeset
|
504 if type(ok) == "string" then id = ok; end |
5181
1e9508ae44cc
util.pubsub: Add item-published event
Matthew Wild <mwild1@gmail.com>
parents:
4367
diff
changeset
|
505 self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); |
8813
2c55fccb0c0c
util.pubsub: Pass node and service objects to broadcaster to allow eg config access
Kim Alvefur <zash@zash.se>
parents:
8810
diff
changeset
|
506 self.config.broadcaster("items", node, node_obj.subscribers, item, actor, node_obj, self); |
3619 | 507 return true; |
508 end | |
509 | |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
510 function service:retract(node, actor, id, retract) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
511 -- 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
|
512 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
|
513 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
|
514 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
|
515 -- |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
516 local node_obj = self.nodes[node]; |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
517 if (not node_obj) or (not self.data[node]:get(id)) then |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
518 return false, "item-not-found"; |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
519 end |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
520 local ok = self.data[node]:set(id, nil); |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
521 if not ok then |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
522 return nil, "internal-server-error"; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
523 end |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
524 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id }); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
525 if retract then |
8813
2c55fccb0c0c
util.pubsub: Pass node and service objects to broadcaster to allow eg config access
Kim Alvefur <zash@zash.se>
parents:
8810
diff
changeset
|
526 self.config.broadcaster("items", node, node_obj.subscribers, retract, actor, node_obj, self); |
3699
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
527 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
528 return true |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
529 end |
150e58d69e60
mod_pubsub: Support item retraction
Florian Zeitz <florob@babelmonkeys.de>
parents:
3698
diff
changeset
|
530 |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
531 function service:purge(node, actor, notify) |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
532 -- 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
|
533 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
|
534 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
|
535 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
536 -- |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 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
|
541 if self.data[node] and self.data[node].clear then |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
542 self.data[node]:clear() |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
543 else |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
544 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
ac5c90230c2c
util.pubsub: Clear data store if it supports being cleared, otherwise fall back to creating a new one
Kim Alvefur <zash@zash.se>
parents:
8220
diff
changeset
|
545 end |
5971
637731f0b9a3
util.pubsub: Fire events on more actions
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
546 self.events.fire_event("node-purged", { node = node, actor = actor }); |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
547 if notify then |
8813
2c55fccb0c0c
util.pubsub: Pass node and service objects to broadcaster to allow eg config access
Kim Alvefur <zash@zash.se>
parents:
8810
diff
changeset
|
548 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self); |
5312
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
549 end |
fdcd2ac7c22d
mod_pubsub, util.pubsub: Don't send purge notifications in an <items/> element
Florian Zeitz <florob@babelmonkeys.de>
parents:
5305
diff
changeset
|
550 return true |
5305
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
551 end |
391b72fede9f
mod_pubsub, util.pubsub: Implement the purge action
Kim Alvefur <zash@zash.se>
parents:
5181
diff
changeset
|
552 |
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
|
553 function service:get_items(node, actor, id) |
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
554 -- 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
|
555 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
|
556 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
|
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 -- |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 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
|
563 if id then -- Restrict results to a single specific item |
8316
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
564 local with_id = self.data[node]:get(id); |
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
565 if not with_id then |
8343
5df2f240173b
util.pubsub: Return an empty list if specific item asked for does not exist (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
566 return true, { }; |
8316
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
567 end |
8648cb171213
util.pubsub: Return item-not-found if a single item is requested, and not there
Kim Alvefur <zash@zash.se>
parents:
8312
diff
changeset
|
568 return true, { id, [id] = with_id }; |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
569 else |
7695
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
570 local data = {} |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
571 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
|
572 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
|
573 data[key] = value; |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
574 end |
56ce32cfd6d9
util.pubsub: Switch to use util.cache for item data
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
575 return true, data; |
3641
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
576 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
577 end |
3603aeb325de
mod_pubsub, util.pubsub: Support for fetching items
Florian Zeitz <florob@babelmonkeys.de>
parents:
3626
diff
changeset
|
578 |
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
|
579 function service:get_last_item(node, actor) |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
580 -- 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
|
581 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
|
582 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
|
583 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
|
584 -- |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
585 return true, self.data[node]:tail(); |
eb6a9c314c86
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
Kim Alvefur <zash@zash.se>
parents:
8343
diff
changeset
|
586 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
|
587 |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
588 function service:get_nodes(actor) |
3910
80fe910f912a
util.pubsub: Too many changes to list or split sensibly. Added access control to all methods, with capabilities support. Renamed get() -> get_items() and changed it to return true, result on success. Support for autocreate_on_subscribe and autocreate_on_publish config options.
Matthew Wild <mwild1@gmail.com>
parents:
3909
diff
changeset
|
589 -- Access checking |
3917
263a133bdf5a
util.pubsub: Fix nil global access in get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3910
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 -- |
3759
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
594 return true, self.nodes; |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
595 end |
1f7305784e12
util.pubsub: Add service:get_nodes()
Matthew Wild <mwild1@gmail.com>
parents:
3699
diff
changeset
|
596 |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 if subscribed_nodes[node] then |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
601 ret[#ret+1] = { |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
602 node = node; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
603 jid = subscribed_jid; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
604 subscription = node_obj.subscribers[subscribed_jid]; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
605 }; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
606 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
607 else -- Return subscriptions to all nodes |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
608 local nodes = serv.nodes; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
609 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
|
610 ret[#ret+1] = { |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
611 node = subscribed_node; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
612 jid = subscribed_jid; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
613 subscription = nodes[subscribed_node].subscribers[subscribed_jid]; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
614 }; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
615 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
616 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
617 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
618 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
619 |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
620 function service:get_subscriptions(node, actor, jid) |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
621 -- Access checking |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
622 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
|
623 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
|
624 cap = "get_subscriptions"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
625 else |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
626 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
|
627 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
628 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
|
629 return false, "forbidden"; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
630 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
631 -- |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
632 local node_obj; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
633 if node then |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
638 end |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
639 local ret = {}; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
640 if jid == nil then |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
641 for _, subs in pairs(self.subscriptions) do |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
642 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
|
643 end |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
644 return true, ret; |
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
645 end |
3938
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
646 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
|
647 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
|
648 -- 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
|
649 -- 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
|
650 if subs then |
9031
d1a4b1b78695
util.pubsub: Support for returning *all* subscriptions
Kim Alvefur <zash@zash.se>
parents:
8956
diff
changeset
|
651 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
|
652 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
653 return true, ret; |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
654 end |
a3ecaf46bd82
util.pubsub: Add service-wide subscription tracking, and add :get_subscriptions()
Matthew Wild <mwild1@gmail.com>
parents:
3937
diff
changeset
|
655 |
3928
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
656 -- Access models only affect 'none' affiliation caps, service/default access level... |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
657 function service:set_node_capabilities(node, actor, capabilities) |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
658 -- Access checking |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
659 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
|
660 return false, "forbidden"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
661 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
662 -- |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
663 local node_obj = self.nodes[node]; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
664 if not node_obj then |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
665 return false, "item-not-found"; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
666 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
667 node_obj.capabilities = capabilities; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
668 return true; |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
669 end |
4dfb345e33ec
util.pubsub: Add service:set_node_capabilities()
Matthew Wild <mwild1@gmail.com>
parents:
3917
diff
changeset
|
670 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
671 function service:set_node_config(node, actor, new_config) |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
672 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
|
673 return false, "forbidden"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
674 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
675 |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
676 local node_obj = self.nodes[node]; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
677 if not node_obj then |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
678 return false, "item-not-found"; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
679 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
680 |
9117
a19fdc6e4f09
util.pubsub: Apply defaults metatable before config check (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9107
diff
changeset
|
681 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
|
682 |
9075
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
683 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
|
684 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
|
685 if not ok then |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
686 return false, "not-acceptable"; |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
687 end |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
688 end |
46d4322f7eed
util.pubsub: Add support for a config validation function
Matthew Wild <mwild1@gmail.com>
parents:
9031
diff
changeset
|
689 |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
690 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
|
691 node_obj.config = new_config; |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
692 |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
693 if self.config.nodestore then |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
694 local ok, err = save_node_to_store(self, node_obj); |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
695 if not ok then |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
696 node_obj.config = old_config; |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
697 return ok, "internal-server-error"; |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
698 end |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
699 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
|
700 |
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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 |
8951
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
713 if old_config["persist_items"] ~= node_obj.config["persist_items"] then |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
714 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
715 elseif old_config["max_items"] ~= node_obj.config["max_items"] then |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
716 self.data[node]:resize(self.nodes[node].config["max_items"]); |
9baac001fccb
util.pubsub: Persist nodes on configuration change
Kim Alvefur <zash@zash.se>
parents:
8950
diff
changeset
|
717 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
|
718 |
6437
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
719 return true; |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
720 end |
3f1f11dfdf10
util.pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6436
diff
changeset
|
721 |
9107
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
722 function service:get_node_config(node, actor) |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
723 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
|
724 return false, "forbidden"; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
725 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
726 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
727 local node_obj = self.nodes[node]; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
728 if not node_obj then |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
729 return false, "item-not-found"; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
730 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
731 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
732 local config_table = {}; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
733 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
|
734 config_table[k] = v; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
735 end |
9144
b40efef8ec99
util.pubsub: Include node defaults from current service object
Kim Alvefur <zash@zash.se>
parents:
9138
diff
changeset
|
736 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
|
737 config_table[k] = v; |
b40efef8ec99
util.pubsub: Include node defaults from current service object
Kim Alvefur <zash@zash.se>
parents:
9138
diff
changeset
|
738 end |
9107
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
739 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
|
740 config_table[k] = v; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
741 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
742 |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
743 return true, config_table; |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
744 end |
6e42ef9c805c
util.pubsub: Add method to retrieve node configuration
Matthew Wild <mwild1@gmail.com>
parents:
9106
diff
changeset
|
745 |
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
|
746 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
|
747 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
|
748 }; |