Mercurial > prosody-modules
annotate mod_pep_plus/pubsub.lib.lua @ 2812:fd4a5ba12fa2
mod_migrate: Catch failure to use user listing API and suggest the alternative
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Nov 2017 22:12:09 +0100 |
parents | cb2342cf3f3c |
children |
rev | line source |
---|---|
2801
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local t_unpack = table.unpack or unpack; -- luacheck: ignore 113 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local time_now = os.time; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local set = require "util.set"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local it = require "util.iterators"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local uuid_generate = require "util.uuid".generate; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local dataform = require"util.dataforms".new; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local _M = {}; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local handlers = {}; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 _M.handlers = handlers; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local pubsub_errors = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 ["conflict"] = { "cancel", "conflict" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 ["jid-required"] = { "modify", "bad-request", nil, "jid-required" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 ["item-not-found"] = { "cancel", "item-not-found" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 ["forbidden"] = { "auth", "forbidden" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 ["not-allowed"] = { "cancel", "not-allowed" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local function pubsub_error_reply(stanza, error) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local e = pubsub_errors[error]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local reply = st.error_reply(stanza, t_unpack(e, 1, 3)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 if e[4] then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 return reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 _M.pubsub_error_reply = pubsub_error_reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 local node_config_form = dataform { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 type = "hidden"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 name = "FORM_TYPE"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 value = "http://jabber.org/protocol/pubsub#node_config"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 type = "text-single"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 name = "pubsub#max_items"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 label = "Max # of items to persist"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 type = "boolean"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 name = "pubsub#persist_items"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 label = "Persist items to storage"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 local service_method_feature_map = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 add_subscription = { "subscribe" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 delete = { "delete-nodes" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 get_items = { "retrieve-items" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 get_subscriptions = { "retrieve-subscriptions" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 node_defaults = { "retrieve-default" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 publish = { "publish" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 purge = { "purge-nodes" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 retract = { "delete-items", "retract-items" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 set_node_config = { "config-node" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 local service_config_feature_map = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 autocreate_on_publish = { "auto-create" }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 function _M.get_feature_set(service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 local supported_features = set.new(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 for method, features in pairs(service_method_feature_map) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 if service[method] then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 for _, feature in ipairs(features) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 if feature then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 supported_features:add(feature); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 for option, features in pairs(service_config_feature_map) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 if service.config[option] then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 for _, feature in ipairs(features) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 if feature then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 supported_features:add(feature); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 for affiliation in pairs(service.config.capabilities) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 if affiliation ~= "none" and affiliation ~= "owner" then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 supported_features:add(affiliation.."-affiliation"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 return supported_features; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 function _M.handle_pubsub_iq(event, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 local origin, stanza = event.origin, event.stanza; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 local pubsub_tag = stanza.tags[1]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 local action = pubsub_tag.tags[1]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 if not action then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 return origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 local prefix = ""; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 if pubsub_tag.attr.xmlns == xmlns_pubsub_owner then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 prefix = "owner_"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 local handler = handlers[prefix..stanza.attr.type.."_"..action.name]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 if handler then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 handler(origin, stanza, action, service); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 function handlers.get_items(origin, stanza, items, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 local node = items.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 local item = items:get_child("item"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 local item_id = item and item.attr.id; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 local ok, results = service:get_items(node, stanza.attr.from, item_id); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 if not ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 origin.send(pubsub_error_reply(stanza, results)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 local data = st.stanza("items", { node = node }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 for _, id in ipairs(results) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 data:add_child(results[id]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 if data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 :tag("pubsub", { xmlns = xmlns_pubsub }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 :add_child(data); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 reply = pubsub_error_reply(stanza, "item-not-found"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 function handlers.get_subscriptions(origin, stanza, subscriptions, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 local node = subscriptions.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 local ok, ret = service:get_subscriptions(node, stanza.attr.from, stanza.attr.from); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 if not ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 origin.send(pubsub_error_reply(stanza, ret)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 local reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 :tag("pubsub", { xmlns = xmlns_pubsub }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 :tag("subscriptions"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 for _, sub in ipairs(ret) do |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 function handlers.set_create(origin, stanza, create, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
172 local node = create.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 local ok, ret, reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 local config; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 local configure = stanza.tags[1]:get_child("configure"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
176 if configure then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 local config_form = configure:get_child("x", "jabber:x:data"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 if not config_form then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
179 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
180 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
181 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
182 local form_data, err = node_config_form:data(config_form); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
183 if not form_data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
184 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
185 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
186 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
187 config = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
188 ["max_items"] = tonumber(form_data["pubsub#max_items"]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 ["persist_items"] = form_data["pubsub#persist_items"]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 if node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
193 ok, ret = service:create(node, stanza.attr.from, config); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
194 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
195 reply = st.reply(stanza); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
196 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 repeat |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 node = uuid_generate(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
202 ok, ret = service:create(node, stanza.attr.from, config); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
203 until ok or ret ~= "conflict"; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
204 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
205 reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
206 :tag("pubsub", { xmlns = xmlns_pubsub }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 :tag("create", { node = node }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
209 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
210 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
211 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
212 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
213 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
214 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
215 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
216 function handlers.owner_set_delete(origin, stanza, delete, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
217 local node = delete.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
218 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
219 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
220 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
221 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
222 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
223 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
224 local ok, ret = service:delete(node, stanza.attr.from); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
225 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
226 reply = st.reply(stanza); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
227 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
228 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
229 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
230 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
231 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
232 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
233 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
234 function handlers.set_subscribe(origin, stanza, subscribe, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
235 local node, jid = subscribe.attr.node, subscribe.attr.jid; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
236 if not (node and jid) then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
237 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
238 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
239 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
240 --[[ |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
241 local options_tag, options = stanza.tags[1]:get_child("options"), nil; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
242 if options_tag then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
243 options = options_form:data(options_tag.tags[1]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
244 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
245 --]] |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
246 local options_tag, options; -- FIXME |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
247 local ok, ret = service:add_subscription(node, stanza.attr.from, jid, options); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
248 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
249 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
250 reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
251 :tag("pubsub", { xmlns = xmlns_pubsub }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
252 :tag("subscription", { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
253 node = node, |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
254 jid = jid, |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
255 subscription = "subscribed" |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
256 }):up(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
257 if options_tag then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
258 reply:add_child(options_tag); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
259 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
260 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
261 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
262 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
263 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
264 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
265 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
266 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
267 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
268 if not (node and jid) then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
269 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
270 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
271 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
272 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
273 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
274 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
275 reply = st.reply(stanza); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
276 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
277 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
278 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
279 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
280 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
281 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
282 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
283 function handlers.set_publish(origin, stanza, publish, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
284 local node = publish.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
285 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
286 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
287 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
288 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
289 local item = publish:get_child("item"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
290 local id = (item and item.attr.id); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
291 if not id then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
292 id = uuid_generate(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
293 if item then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
294 item.attr.id = id; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
295 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
296 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
297 local ok, ret = service:publish(node, stanza.attr.from, id, item); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
298 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
299 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
300 reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
301 :tag("pubsub", { xmlns = xmlns_pubsub }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
302 :tag("publish", { node = node }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
303 :tag("item", { id = id }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
304 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
305 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
306 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
307 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
308 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
309 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
310 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
311 function handlers.set_retract(origin, stanza, retract, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
312 local node, notify = retract.attr.node, retract.attr.notify; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
313 notify = (notify == "1") or (notify == "true"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
314 local item = retract:get_child("item"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
315 local id = item and item.attr.id |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
316 if not (node and id) then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
317 origin.send(pubsub_error_reply(stanza, node and "item-not-found" or "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
318 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
319 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
320 local reply, notifier; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
321 if notify then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
322 notifier = st.stanza("retract", { id = id }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
323 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
324 local ok, ret = service:retract(node, stanza.attr.from, id, notifier); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
325 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
326 reply = st.reply(stanza); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
327 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
328 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
329 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
330 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
331 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
332 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
333 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
334 function handlers.owner_set_purge(origin, stanza, purge, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
335 local node, notify = purge.attr.node, purge.attr.notify; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
336 notify = (notify == "1") or (notify == "true"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
337 local reply; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
338 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
339 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
340 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
341 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
342 local ok, ret = service:purge(node, stanza.attr.from, notify); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
343 if ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
344 reply = st.reply(stanza); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
345 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
346 reply = pubsub_error_reply(stanza, ret); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
347 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
348 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
349 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
350 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
351 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
352 function handlers.owner_get_configure(origin, stanza, config, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
353 local node = config.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
354 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
355 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
356 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
357 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
358 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
359 if not service:may(node, stanza.attr.from, "configure") then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
360 origin.send(pubsub_error_reply(stanza, "forbidden")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
361 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
362 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
363 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
364 local node_obj = service.nodes[node]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
365 if not node_obj then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
366 origin.send(pubsub_error_reply(stanza, "item-not-found")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
367 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
368 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
369 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
370 local node_config = node_obj.config; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
371 local pubsub_form_data = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
372 ["pubsub#max_items"] = tostring(node_config["max_items"]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
373 ["pubsub#persist_items"] = node_config["persist_items"] |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
374 } |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
375 local reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
376 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
377 :tag("configure", { node = node }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
378 :add_child(node_config_form:form(pubsub_form_data)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
379 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
380 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
381 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
382 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
383 function handlers.owner_set_configure(origin, stanza, config, service) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
384 local node = config.attr.node; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
385 if not node then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
386 origin.send(pubsub_error_reply(stanza, "nodeid-required")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
387 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
388 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
389 if not service:may(node, stanza.attr.from, "configure") then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
390 origin.send(pubsub_error_reply(stanza, "forbidden")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
391 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
392 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
393 local config_form = config:get_child("x", "jabber:x:data"); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
394 if not config_form then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
395 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
396 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
397 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
398 local form_data, err = node_config_form:data(config_form); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
399 if not form_data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
400 origin.send(st.error_reply(stanza, "modify", "bad-request", err)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
401 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
402 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
403 local new_config = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
404 ["max_items"] = tonumber(form_data["pubsub#max_items"]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
405 ["persist_items"] = form_data["pubsub#persist_items"]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
406 }; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
407 local ok, err = service:set_node_config(node, stanza.attr.from, new_config); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
408 if not ok then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
409 origin.send(pubsub_error_reply(stanza, err)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
410 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
411 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
412 origin.send(st.reply(stanza)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
413 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
414 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
415 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
416 function handlers.owner_get_default(origin, stanza, default, service) -- luacheck: ignore 212/default |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
417 local pubsub_form_data = { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
418 ["pubsub#max_items"] = tostring(service.node_defaults["max_items"]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
419 ["pubsub#persist_items"] = service.node_defaults["persist_items"] |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
420 } |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
421 local reply = st.reply(stanza) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
422 :tag("pubsub", { xmlns = xmlns_pubsub_owner }) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
423 :tag("default") |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
424 :add_child(node_config_form:form(pubsub_form_data)); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
425 origin.send(reply); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
426 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
427 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
428 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
429 local function create_encapsulating_item(id, payload) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
430 local item = st.stanza("item", { id = id, xmlns = xmlns_pubsub }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
431 item:add_child(payload); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
432 return item; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
433 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
434 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
435 local function archive_itemstore(archive, config, user, node) |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
436 module:log("debug", "Creation of itemstore for node %s with config %s", node, config); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
437 local get_set = {}; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
438 function get_set:items() -- luacheck: ignore 212/self |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
439 local data, err = archive:find(user, { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
440 limit = tonumber(config["pubsub#max_items"]); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
441 reverse = true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
442 }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
443 if not data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
444 module:log("error", "Unable to get items: %s", err); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
445 return true; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
446 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
447 module:log("debug", "Listed items %s", data); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
448 return it.reverse(function() |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
449 local id, payload, when, publisher = data(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
450 if id == nil then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
451 return; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
452 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
453 local item = create_encapsulating_item(id, payload, publisher); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
454 return id, item; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
455 end); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
456 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
457 function get_set:get(key) -- luacheck: ignore 212/self |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
458 local data, err = archive:find(user, { |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
459 key = key; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
460 -- Get the last item with that key, if the archive doesn't deduplicate |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
461 reverse = true, |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
462 limit = 1; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
463 }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
464 if not data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
465 module:log("error", "Unable to get item: %s", err); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
466 return nil, err; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
467 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
468 local id, payload, when, publisher = data(); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
469 module:log("debug", "Get item %s (published at %s by %s)", id, when, publisher); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
470 if id == nil then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
471 return nil; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
472 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
473 return create_encapsulating_item(id, payload, publisher); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
474 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
475 function get_set:set(key, value) -- luacheck: ignore 212/self |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
476 local data, err; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
477 if value ~= nil then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
478 local publisher = value.attr.publisher; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
479 local payload = value.tags[1]; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
480 data, err = archive:append(user, key, payload, time_now(), publisher); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
481 else |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
482 data, err = archive:delete(user, { key = key; }); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
483 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
484 if not data then |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
485 module:log("error", "Unable to set item: %s", err); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
486 return nil, err; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
487 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
488 return data; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
489 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
490 function get_set:clear() -- luacheck: ignore 212/self |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
491 return archive:delete(user); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
492 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
493 return setmetatable(get_set, archive); |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
494 end |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
495 _M.archive_itemstore = archive_itemstore; |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
496 |
cb2342cf3f3c
mod_pep_plus: Snapshot from Prosody trunk 910d3c3f60a6 including dependencies
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
497 return _M; |