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