Software /
code /
prosody
Annotate
plugins/mod_pubsub/pubsub.lib.lua @ 8334:036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Oct 2017 07:46:44 +0200 |
parent | 8333:2abbb01cd756 |
child | 8336:587305c0ff85 |
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 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 local st = require "util.stanza"; |
8325 | 5 local it = require "util.iterators"; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 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
|
7 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
|
8 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 local _M = {}; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 local handlers = {}; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 _M.handlers = handlers; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 local pubsub_errors = { |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 ["conflict"] = { "cancel", "conflict" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 ["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
|
21 ["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
|
22 ["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
|
23 ["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
|
24 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; |
6473 | 25 ["forbidden"] = { "auth", "forbidden" }; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
26 ["not-allowed"] = { "cancel", "not-allowed" }; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 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
|
29 local e = pubsub_errors[error]; |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
30 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
|
31 if e[4] then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 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
|
33 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 return reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 _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
|
37 |
7358
d0390bc9c5d1
mod_pubsub: Don’t require util.dataforms twice
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6841
diff
changeset
|
38 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
|
39 { |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
40 type = "hidden"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
41 name = "FORM_TYPE"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
42 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
|
43 }; |
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 type = "text-single"; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
46 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
|
47 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
|
48 }; |
8320
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
49 { |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
50 type = "boolean"; |
fe5eaf4ed631
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
51 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
|
52 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
|
53 }; |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
54 }; |
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
55 |
8334
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
56 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
|
57 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
|
58 local pubsub_tag = stanza.tags[1]; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
59 local action = pubsub_tag.tags[1]; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
60 if not action then |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
61 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
|
62 end |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
63 local handler = handlers[stanza.attr.type.."_"..action.name]; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
64 if handler then |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
65 handler(origin, stanza, action, service); |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
66 return true; |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
67 end |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
68 end |
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8333
diff
changeset
|
69 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
70 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
|
71 local node = items.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 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
|
73 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
|
74 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 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
|
76 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
|
77 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 end |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
83 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
84 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
85 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
|
86 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
|
87 data:add_child(results[id]); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
88 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
89 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
90 if data then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
91 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
92 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
93 :add_child(data); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
94 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
99 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
100 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
101 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
|
102 local node = subscriptions.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
108 local reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
109 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
110 :tag("subscriptions"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
111 for _, sub in ipairs(ret) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
116 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
117 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
118 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
|
119 local node = create.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
120 local ok, ret, reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
121 if node then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
122 ok, ret = service:create(node, stanza.attr.from); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
123 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
124 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
125 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
126 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
127 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
128 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
129 repeat |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
130 node = uuid_generate(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
131 ok, ret = service:create(node, stanza.attr.from); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
132 until ok or ret ~= "conflict"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
133 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
134 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
135 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
136 :tag("create", { node = node }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
137 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
140 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
|
141 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
|
142 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
143 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
145 function handlers.set_delete(origin, stanza, delete, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 local node = delete.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7358
diff
changeset
|
148 local reply; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 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
|
150 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
|
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 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
|
154 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
156 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
157 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
158 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
|
159 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
|
160 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
162 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
168 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
169 --[[ |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
170 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
|
171 if options_tag then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
172 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
|
173 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
174 --]] |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 local options_tag, options; -- FIXME |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
176 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
|
177 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
178 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
181 :tag("subscription", { |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
182 node = node, |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
183 jid = jid, |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
184 subscription = "subscribed" |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
185 }):up(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
186 if options_tag then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
187 reply:add_child(options_tag); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
188 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
189 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
190 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
191 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
192 origin.send(reply); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
193 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 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
|
199 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
201 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
|
202 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
203 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
204 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
206 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
207 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
|
208 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
|
209 return true; |
5626
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 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
212 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
|
213 local node = publish.attr.node; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
214 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
|
215 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
|
216 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
217 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
218 local item = publish:get_child("item"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
219 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
|
220 if not id then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
221 id = uuid_generate(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
222 if item then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 item.attr.id = id; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
224 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 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
|
227 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
228 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 reply = st.reply(stanza) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
230 :tag("pubsub", { xmlns = xmlns_pubsub }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
231 :tag("publish", { node = node }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
232 :tag("item", { id = id }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
233 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
234 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
235 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
|
236 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
|
237 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
238 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
239 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 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
|
241 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
|
242 notify = (notify == "1") or (notify == "true"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
243 local item = retract:get_child("item"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
249 local reply, notifier; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
250 if notify then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
251 notifier = st.stanza("retract", { id = id }); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
252 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
253 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
|
254 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
255 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
256 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
257 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
258 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
|
259 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
|
260 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
261 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
262 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
263 function handlers.set_purge(origin, stanza, purge, service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
264 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
|
265 notify = (notify == "1") or (notify == "true"); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
266 local reply; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
267 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
|
268 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
|
269 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
270 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
271 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
|
272 if ok then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
273 reply = st.reply(stanza); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
274 else |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
275 reply = pubsub_error_reply(stanza, ret); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
276 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
|
277 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
|
278 return true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
279 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
280 |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
281 function handlers.get_configure(origin, stanza, config, service) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
282 local node = config.attr.node; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
283 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
|
284 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
|
285 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
286 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
287 |
6445
f1ad3923368c
pubsub.lib: Fix actor in configure
Kim Alvefur <zash@zash.se>
parents:
6441
diff
changeset
|
288 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
|
289 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
|
290 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
291 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
292 |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
293 local node_obj = service.nodes[node]; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
294 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
|
295 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
|
296 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
297 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
298 |
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
|
299 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
|
300 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
|
301 ["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
|
302 ["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
|
303 } |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
304 local reply = st.reply(stanza) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
305 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
306 :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
|
307 :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
|
308 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
|
309 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
310 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
311 |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
312 function handlers.set_configure(origin, stanza, config, service) |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
313 local node = config.attr.node; |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
314 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
|
315 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
|
316 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
317 end |
6446
011ca9b88179
mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6445
diff
changeset
|
318 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
|
319 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
|
320 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
321 end |
8317
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 return true; |
ff57b3cc5a8e
mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents:
8308
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
331 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
|
332 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
|
333 ["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
|
334 ["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
|
335 }; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
340 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
|
341 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
|
342 return true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
343 end |
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
5851
diff
changeset
|
344 |
6441
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
345 function handlers.get_default(origin, stanza, default, service) |
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
|
346 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
|
347 ["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
|
348 ["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
|
349 } |
6441
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
350 local reply = st.reply(stanza) |
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
351 :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
|
352 :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
|
353 :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
|
354 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
|
355 return true; |
6441
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
356 end |
bcb1ea9047d3
mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents:
6438
diff
changeset
|
357 |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
358 local function create_encapsulating_item(id, payload) |
8216
d80233ca006d
mod_pubsub: Pass xmlns correctly
Kim Alvefur <zash@zash.se>
parents:
8213
diff
changeset
|
359 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
|
360 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
|
361 return item; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
362 end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
363 |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
364 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
|
365 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
|
366 local get_set = {}; |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
367 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
|
368 local data, err = archive:find(user, { |
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
|
369 limit = tonumber(config["pubsub#max_items"]); |
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
|
370 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
|
371 }); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
372 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
|
373 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
|
374 return true; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
375 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 return; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
381 end |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
382 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
|
383 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
|
384 end); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
385 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
386 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
|
387 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
|
388 key = key; |
8302
4852def7dc49
mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents:
8301
diff
changeset
|
389 -- 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
|
390 reverse = true, |
4852def7dc49
mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents:
8301
diff
changeset
|
391 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
|
392 }); |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 end |
8296
e23328adca25
mod_pubsub: Remove workaround for SQL issue (fixed in becb593ed86d)
Kim Alvefur <zash@zash.se>
parents:
8295
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 return nil; |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
401 end |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8325
diff
changeset
|
402 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
|
403 end |
8308
ab189d3f55d1
mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents:
8302
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 else |
8300
7759eb130938
mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents:
8298
diff
changeset
|
411 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
|
412 end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 end |
8217
5f4e0d67b82a
util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents:
8216
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 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
|
421 end |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
422 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
|
423 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
|
424 _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
|
425 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
426 return _M; |