Software /
code /
prosody
Annotate
plugins/mod_pubsub/pubsub.lib.lua @ 8400:518b56d806bd
mod_pubsub: Allow itemstore to override item ids
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 09 Nov 2017 17:22:47 +0100 |
parent | 8399:07443fe9df5b |
child | 8814:07197f29e2b8 |
rev | line source |
---|---|
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
1 local t_unpack = table.unpack or unpack; -- luacheck: ignore 113 |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
2 local time_now = os.time; |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
3 |
8340
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
4 local set = require "util.set"; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
8325 | 6 local it = require "util.iterators"; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 local uuid_generate = require "util.uuid".generate; |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
8 local dataform = require"util.dataforms".new; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
12 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 local _M = {}; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 local handlers = {}; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 _M.handlers = handlers; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 local pubsub_errors = { |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 ["conflict"] = { "cancel", "conflict" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 ["jid-required"] = { "modify", "bad-request", nil, "jid-required" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 ["item-not-found"] = { "cancel", "item-not-found" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; |
6473 | 26 ["forbidden"] = { "auth", "forbidden" }; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
27 ["not-allowed"] = { "cancel", "not-allowed" }; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 local function pubsub_error_reply(stanza, error) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 local e = pubsub_errors[error]; |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
31 local reply = st.error_reply(stanza, t_unpack(e, 1, 3)); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 if e[4] then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 return reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
37 _M.pubsub_error_reply = pubsub_error_reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
38 |
7358
d0390bc9c5d1
mod_pubsub: Don’t require util.dataforms twice
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6841
diff
changeset
|
39 local node_config_form = dataform { |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
40 { |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
41 type = "hidden"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
42 name = "FORM_TYPE"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
43 value = "http://jabber.org/protocol/pubsub#node_config"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
44 }; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
45 { |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
46 type = "text-single"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
47 name = "pubsub#max_items"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
48 label = "Max # of items to persist"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
49 }; |
8320
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
50 { |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
51 type = "boolean"; |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
52 name = "pubsub#persist_items"; |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
53 label = "Persist items to storage"; |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
54 }; |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
55 }; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
56 |
8340
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
57 local service_method_feature_map = { |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
58 add_subscription = { "subscribe" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
59 create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
60 delete = { "delete-nodes" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
61 get_items = { "retrieve-items" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
62 get_subscriptions = { "retrieve-subscriptions" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
63 node_defaults = { "retrieve-default" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
64 publish = { "publish" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
65 purge = { "purge-nodes" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
66 retract = { "delete-items", "retract-items" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
67 set_node_config = { "config-node" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
68 }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
69 local service_config_feature_map = { |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
70 autocreate_on_publish = { "auto-create" }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
71 }; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
72 |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
73 function _M.get_feature_set(service) |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
74 local supported_features = set.new(); |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
75 |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
76 for method, features in pairs(service_method_feature_map) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
77 if service[method] then |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
78 for _, feature in ipairs(features) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
79 if feature then |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
80 supported_features:add(feature); |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
81 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
82 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
83 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
84 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
85 |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
86 for option, features in pairs(service_config_feature_map) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
87 if service.config[option] then |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
88 for _, feature in ipairs(features) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
89 if feature then |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
90 supported_features:add(feature); |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
91 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
92 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
93 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
94 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
95 |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
96 for affiliation in pairs(service.config.capabilities) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
97 if affiliation ~= "none" and affiliation ~= "owner" then |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
98 supported_features:add(affiliation.."-affiliation"); |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
99 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
100 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
101 |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
102 return supported_features; |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
103 end |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8338
diff
changeset
|
104 |
8334
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
105 function _M.handle_pubsub_iq(event, service) |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
106 local origin, stanza = event.origin, event.stanza; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
107 local pubsub_tag = stanza.tags[1]; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
108 local action = pubsub_tag.tags[1]; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
109 if not action then |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
110 return origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
111 end |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
112 local prefix = ""; |
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
113 if pubsub_tag.attr.xmlns == xmlns_pubsub_owner then |
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
114 prefix = "owner_"; |
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
115 end |
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
116 local handler = handlers[prefix..stanza.attr.type.."_"..action.name]; |
8334
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
117 if handler then |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
118 handler(origin, stanza, action, service); |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
119 return true; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
120 end |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
121 end |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
122 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
123 function handlers.get_items(origin, stanza, items, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
124 local node = items.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
125 local item = items:get_child("item"); |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
126 local item_id = item and item.attr.id; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
127 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
128 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
129 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
130 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
131 end |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
132 local ok, results = service:get_items(node, stanza.attr.from, item_id); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
133 if not ok then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
134 origin.send(pubsub_error_reply(stanza, results)); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
135 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
136 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
137 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 local data = st.stanza("items", { node = node }); |
5851
cdcfd93e2f43
mod_pubsub, util.pubsub: Keep track of the order of items
Kim Alvefur <zash@zash.se>
parents:
5626
diff
changeset
|
139 for _, id in ipairs(results) do |
cdcfd93e2f43
mod_pubsub, util.pubsub: Keep track of the order of items
Kim Alvefur <zash@zash.se>
parents:
5626
diff
changeset
|
140 data:add_child(results[id]); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
141 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
142 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
143 if data then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
145 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 :add_child(data); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 reply = pubsub_error_reply(stanza, "item-not-found"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
150 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
151 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
152 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
153 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
154 function handlers.get_subscriptions(origin, stanza, subscriptions, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 local node = subscriptions.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
156 local ok, ret = service:get_subscriptions(node, stanza.attr.from, stanza.attr.from); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
157 if not ok then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
158 origin.send(pubsub_error_reply(stanza, ret)); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
159 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
160 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 local reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
162 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
163 :tag("subscriptions"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
164 for _, sub in ipairs(ret) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
165 reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
166 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
167 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
168 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
169 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
170 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 function handlers.set_create(origin, stanza, create, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
172 local node = create.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 local ok, ret, reply; |
8337
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
174 local config; |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
175 local configure = stanza.tags[1]:get_child("configure"); |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
176 if configure then |
8338
30d8157391e9
mod_pubsub: Use correct variable name [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8337
diff
changeset
|
177 local config_form = configure:get_child("x", "jabber:x:data"); |
8337
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
178 if not config_form then |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
179 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
180 return true; |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
181 end |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
182 local form_data, err = node_config_form:data(config_form); |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
183 if not form_data then |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
184 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
185 return true; |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
186 end |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
187 config = { |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
188 ["max_items"] = tonumber(form_data["pubsub#max_items"]); |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
189 ["persist_items"] = form_data["pubsub#persist_items"]; |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
190 }; |
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
191 end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
192 if node then |
8337
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
193 ok, ret = service:create(node, stanza.attr.from, config); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
195 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
196 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
197 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
198 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
199 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 repeat |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
201 node = uuid_generate(); |
8337
dc4ea43ac463
mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents:
8336
diff
changeset
|
202 ok, ret = service:create(node, stanza.attr.from, config); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
203 until ok or ret ~= "conflict"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
204 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
206 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
207 :tag("create", { node = node }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
208 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
209 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
210 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
211 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
212 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
213 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
214 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
215 |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
216 function handlers.owner_set_delete(origin, stanza, delete, service) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
217 local node = delete.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
218 |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
219 local reply; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
220 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
221 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
222 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
224 local ok, ret = service:delete(node, stanza.attr.from); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
227 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
228 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
230 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
231 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
232 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
233 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
234 function handlers.set_subscribe(origin, stanza, subscribe, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
235 local node, jid = subscribe.attr.node, subscribe.attr.jid; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
236 if not (node and jid) then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
237 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
238 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
239 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 --[[ |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
241 local options_tag, options = stanza.tags[1]:get_child("options"), nil; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
242 if options_tag then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
243 options = options_form:data(options_tag.tags[1]); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
244 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
245 --]] |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
246 local options_tag, options; -- FIXME |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
247 local ok, ret = service:add_subscription(node, stanza.attr.from, jid, options); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
249 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
250 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
251 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
252 :tag("subscription", { |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
253 node = node, |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
254 jid = jid, |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
255 subscription = "subscribed" |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
256 }):up(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
257 if options_tag then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
258 reply:add_child(options_tag); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
259 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
260 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
261 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
262 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
263 origin.send(reply); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
264 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
265 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
266 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
267 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
268 if not (node and jid) then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
269 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
270 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
271 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
272 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
273 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
274 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
275 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
276 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
277 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
278 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
279 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
280 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
281 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
282 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
283 function handlers.set_publish(origin, stanza, publish, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 local node = publish.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
285 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
286 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
287 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
288 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
289 local item = publish:get_child("item"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
290 local id = (item and item.attr.id); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
291 if not id then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
292 id = uuid_generate(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
293 if item then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 item.attr.id = id; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
296 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
297 local ok, ret = service:publish(node, stanza.attr.from, id, item); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
298 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
299 if ok then |
8400
518b56d806bd
mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents:
8399
diff
changeset
|
300 if type(ok) == "string" then |
518b56d806bd
mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents:
8399
diff
changeset
|
301 id = ok; |
518b56d806bd
mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents:
8399
diff
changeset
|
302 end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
303 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
304 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
305 :tag("publish", { node = node }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
306 :tag("item", { id = id }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
307 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
308 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
309 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
310 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
311 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
312 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
313 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
314 function handlers.set_retract(origin, stanza, retract, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
315 local node, notify = retract.attr.node, retract.attr.notify; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
316 notify = (notify == "1") or (notify == "true"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
317 local item = retract:get_child("item"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
318 local id = item and item.attr.id |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
319 if not (node and id) then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
320 origin.send(pubsub_error_reply(stanza, node and "item-not-found" or "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
321 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
322 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
323 local reply, notifier; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
324 if notify then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
325 notifier = st.stanza("retract", { id = id }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
326 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
327 local ok, ret = service:retract(node, stanza.attr.from, id, notifier); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
328 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
329 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
330 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
331 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
332 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
333 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
334 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
335 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
336 |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
337 function handlers.owner_set_purge(origin, stanza, purge, service) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
338 local node, notify = purge.attr.node, purge.attr.notify; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
339 notify = (notify == "1") or (notify == "true"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
340 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
341 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
342 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
343 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
344 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
345 local ok, ret = service:purge(node, stanza.attr.from, notify); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
346 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
347 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
348 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
349 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
350 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
351 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
352 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
353 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
354 |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
355 function handlers.owner_get_configure(origin, stanza, config, service) |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
356 local node = config.attr.node; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
357 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
358 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
359 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
360 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
361 |
6445
f1ad3923368c
pubsub.lib: Fix actor in configure
Kim Alvefur <zash@zash.se>
parents:
6441
diff
changeset
|
362 if not service:may(node, stanza.attr.from, "configure") then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
363 origin.send(pubsub_error_reply(stanza, "forbidden")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
364 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
365 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
366 |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
367 local node_obj = service.nodes[node]; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
368 if not node_obj then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
369 origin.send(pubsub_error_reply(stanza, "item-not-found")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
370 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
371 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
372 |
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:
8327
diff
changeset
|
373 local node_config = node_obj.config; |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
374 local pubsub_form_data = { |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
375 ["pubsub#max_items"] = tostring(node_config["max_items"]); |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
376 ["pubsub#persist_items"] = node_config["persist_items"] |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
377 } |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
378 local reply = st.reply(stanza) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
379 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
380 :tag("configure", { node = node }) |
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:
8327
diff
changeset
|
381 :add_child(node_config_form:form(pubsub_form_data)); |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
382 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
383 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
384 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
385 |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
386 function handlers.owner_set_configure(origin, stanza, config, service) |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
387 local node = config.attr.node; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
388 if not node then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
389 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
390 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
391 end |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
392 if not service:may(node, stanza.attr.from, "configure") then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
393 origin.send(pubsub_error_reply(stanza, "forbidden")); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
394 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
395 end |
8317
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
396 local config_form = config:get_child("x", "jabber:x:data"); |
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
397 if not config_form then |
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
398 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); |
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
399 return true; |
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
400 end |
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:
8327
diff
changeset
|
401 local form_data, err = node_config_form:data(config_form); |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
402 if not form_data then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
403 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
404 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
405 end |
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:
8327
diff
changeset
|
406 local new_config = { |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
407 ["max_items"] = tonumber(form_data["pubsub#max_items"]); |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
408 ["persist_items"] = form_data["pubsub#persist_items"]; |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
409 }; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
410 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
411 if not ok then |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
412 origin.send(pubsub_error_reply(stanza, err)); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
413 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
414 end |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
415 origin.send(st.reply(stanza)); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
416 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
417 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
418 |
8336
587305c0ff85
mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents:
8334
diff
changeset
|
419 function handlers.owner_get_default(origin, stanza, default, service) -- luacheck: ignore 212/default |
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:
8327
diff
changeset
|
420 local pubsub_form_data = { |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
421 ["pubsub#max_items"] = tostring(service.node_defaults["max_items"]); |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
422 ["pubsub#persist_items"] = service.node_defaults["persist_items"] |
2abbb01cd756
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
423 } |
6441
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
424 local reply = st.reply(stanza) |
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
425 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
6447
8c2dc2ac5a40
mod_pubsub: Fix retreival of node config defaults
Kim Alvefur <zash@zash.se>
parents:
6446
diff
changeset
|
426 :tag("default") |
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:
8327
diff
changeset
|
427 :add_child(node_config_form:form(pubsub_form_data)); |
6841
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
428 origin.send(reply); |
be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents:
6473
diff
changeset
|
429 return true; |
6441
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
430 end |
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
431 |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
432 local function create_encapsulating_item(id, payload) |
8216
d80233ca006d
mod_pubsub: Pass xmlns correctly
Kim Alvefur <zash@zash.se>
parents:
8213
diff
changeset
|
433 local item = st.stanza("item", { id = id, xmlns = xmlns_pubsub }); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
434 item:add_child(payload); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
435 return item; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
436 end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
437 |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
438 local function archive_itemstore(archive, config, user, node) |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
439 module:log("debug", "Creation of itemstore for node %s with config %s", node, config); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
440 local get_set = {}; |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
441 function get_set:items() -- luacheck: ignore 212/self |
8324
58d228da618f
mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents:
8323
diff
changeset
|
442 local data, err = archive:find(user, { |
8374
b52663586243
mod_pubsub: Update node config names (should have been in 2abbb01cd756) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
8340
diff
changeset
|
443 limit = tonumber(config["max_items"]); |
8324
58d228da618f
mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents:
8323
diff
changeset
|
444 reverse = true; |
58d228da618f
mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents:
8323
diff
changeset
|
445 }); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
446 if not data then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
447 module:log("error", "Unable to get items: %s", err); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
448 return true; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
449 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
450 module:log("debug", "Listed items %s", data); |
8324
58d228da618f
mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents:
8323
diff
changeset
|
451 return it.reverse(function() |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
452 local id, payload, when, publisher = data(); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
453 if id == nil then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
454 return; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
455 end |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
456 local item = create_encapsulating_item(id, payload, publisher); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
457 return id, item; |
8324
58d228da618f
mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents:
8323
diff
changeset
|
458 end); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
459 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
460 function get_set:get(key) -- luacheck: ignore 212/self |
8219
2e68ae095645
mod_pubsub: Store data in users store, node in 'with' metadata field
Kim Alvefur <zash@zash.se>
parents:
8218
diff
changeset
|
461 local data, err = archive:find(user, { |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
462 key = key; |
8302
4852def7dc49
mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents:
8301
diff
changeset
|
463 -- Get the last item with that key, if the archive doesn't deduplicate |
4852def7dc49
mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents:
8301
diff
changeset
|
464 reverse = true, |
4852def7dc49
mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents:
8301
diff
changeset
|
465 limit = 1; |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
466 }); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
467 if not data then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
468 module:log("error", "Unable to get item: %s", err); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
469 return nil, err; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
470 end |
8296
e23328adca25
mod_pubsub: Remove workaround for SQL issue (fixed in becb593ed86d)
Kim Alvefur <zash@zash.se>
parents:
8295
diff
changeset
|
471 local id, payload, when, publisher = data(); |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
472 module:log("debug", "Get item %s (published at %s by %s)", id, when, publisher); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
473 if id == nil then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
474 return nil; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
475 end |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
476 return create_encapsulating_item(id, payload, publisher); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
477 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
478 function get_set:set(key, value) -- luacheck: ignore 212/self |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
479 local data, err; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
480 if value ~= nil then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
481 local publisher = value.attr.publisher; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
482 local payload = value.tags[1]; |
8300
7759eb130938
mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents:
8298
diff
changeset
|
483 data, err = archive:append(user, key, payload, time_now(), publisher); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
484 else |
8300
7759eb130938
mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents:
8298
diff
changeset
|
485 data, err = archive:delete(user, { key = key; }); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
486 end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
487 if not data then |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
488 module:log("error", "Unable to set item: %s", err); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
489 return nil, err; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
490 end |
8217
5f4e0d67b82a
util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents:
8216
diff
changeset
|
491 return data; |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
492 end |
8301
e2ab440a3437
mod_pubsub: Ignore unused 'self' since the data used is an upvalue [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8300
diff
changeset
|
493 function get_set:clear() -- luacheck: ignore 212/self |
8300
7759eb130938
mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents:
8298
diff
changeset
|
494 return archive:delete(user); |
8298
dd9fa511494a
mod_pubsub: Add method to clear data from a simple_itemstore
Kim Alvefur <zash@zash.se>
parents:
8296
diff
changeset
|
495 end |
8399
07443fe9df5b
mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents:
8375
diff
changeset
|
496 function get_set:resize(size) |
07443fe9df5b
mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents:
8375
diff
changeset
|
497 return archive:delete(user, { |
07443fe9df5b
mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents:
8375
diff
changeset
|
498 truncate = size; |
07443fe9df5b
mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents:
8375
diff
changeset
|
499 }); |
07443fe9df5b
mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents:
8375
diff
changeset
|
500 end |
8375
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
501 function get_set:tail() |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
502 -- This should conveniently return the last item |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
503 local item = self:get(nil); |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
504 if item then |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
505 return item.attr.id, item; |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
506 end |
e2037634cdd9
mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents:
8374
diff
changeset
|
507 end |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
508 return setmetatable(get_set, archive); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
509 end |
8318
d0a7fc7614de
mod_pubsub, mod_pep_plus: Rename simple_itemstore to reflect that it's based on archive storage
Kim Alvefur <zash@zash.se>
parents:
8317
diff
changeset
|
510 _M.archive_itemstore = archive_itemstore; |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
511 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
512 return _M; |