Software /
code /
prosody
Annotate
plugins/mod_pubsub/mod_pubsub.lua @ 8334:036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Oct 2017 07:46:44 +0200 |
parent | 8328:29ef191c7bf9 |
child | 8337:dc4ea43ac463 |
rev | line source |
---|---|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 local pubsub = require "util.pubsub"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 local jid_bare = require "util.jid".bare; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 local usermanager = require "core.usermanager"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 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
|
7 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); |
7983
879be73c0a58
mod_pubsub: Fix syntax error introduced in 241f02bd66ce
Matthew Wild <mwild1@gmail.com>
parents:
7980
diff
changeset
|
12 local pubsub_disco_name = module:get_option_string("name", "Prosody PubSub Service"); |
6515
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
13 local expose_publisher = module:get_option_boolean("expose_publisher", false) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 |
8313
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
15 local enable_persistence = module:get_option_boolean("experimental_pubsub_item_persistence", false); |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
16 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 local service; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 local lib_pubsub = module:require "pubsub"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 local handlers = lib_pubsub.handlers; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
22 module:depends("disco"); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
23 module:add_identity("pubsub", "service", pubsub_disco_name); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
24 module:add_feature("http://jabber.org/protocol/pubsub"); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
25 |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 function handle_pubsub_iq(event) |
8334
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8328
diff
changeset
|
27 return lib_pubsub.handle_pubsub_iq(event, service); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
30 local function simple_itemstore(config, node) |
8311
df8c82d285dc
mod_pubsub: Restore persistence with one archive per node
Kim Alvefur <zash@zash.se>
parents:
8221
diff
changeset
|
31 local archive = module:open_store("pubsub_"..node, "archive"); |
8327
0b561f8bc790
mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents:
8318
diff
changeset
|
32 return lib_pubsub.archive_itemstore(archive, config, nil, node); |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
33 end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
34 |
8313
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
35 if enable_persistence then |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
36 module:log("warn", "Item persistence is an experimental feature. Note that ownership information is lost on restart.") |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
37 else |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
38 simple_itemstore = nil; |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
39 end |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
40 |
21466b778bf1
mod_pubsub: Hide item persistence behind option (at least until affiliations are also persisted)
Kim Alvefur <zash@zash.se>
parents:
8311
diff
changeset
|
41 |
6515
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
42 function simple_broadcast(kind, node, jids, item, actor) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 if item then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
44 item = st.clone(item); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 item.attr.xmlns = nil; -- Clear the pubsub namespace |
6515
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
46 if expose_publisher and actor then |
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
47 item.attr.publisher = actor |
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
48 end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
49 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
50 local message = st.message({ from = module.host, type = "headline" }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
51 :tag("event", { xmlns = xmlns_pubsub_event }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
52 :tag(kind, { node = node }) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
53 :add_child(item); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
54 for jid in pairs(jids) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
55 module:log("debug", "Sending notification to %s", jid); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
56 message.attr.to = jid; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
57 module:send(message); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
58 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
59 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
60 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
61 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
62 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
63 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
64 local feature_map = { |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
65 create = { "create-nodes", "instant-nodes", "item-ids" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
66 retract = { "delete-items", "retract-items" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
67 purge = { "purge-nodes" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
68 publish = { "publish", autocreate_on_publish and "auto-create" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
69 delete = { "delete-nodes" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
70 get_items = { "retrieve-items" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
71 add_subscription = { "subscribe" }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 get_subscriptions = { "retrieve-subscriptions" }; |
8328
29ef191c7bf9
mod_pubsub: Fix feature advertising of config-node and retrieve-default
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
73 set_node_config = { "config-node" }; |
29ef191c7bf9
mod_pubsub: Fix feature advertising of config-node and retrieve-default
Kim Alvefur <zash@zash.se>
parents:
8327
diff
changeset
|
74 node_defaults = { "retrieve-default" }; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
77 local function add_disco_features_from_service(service) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 for method, features in pairs(feature_map) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 if service[method] then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
80 for _, feature in ipairs(features) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
81 if feature then |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
82 module:add_feature(xmlns_pubsub.."#"..feature); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
83 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
84 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
85 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
86 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
87 for affiliation in pairs(service.config.capabilities) do |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
88 if affiliation ~= "none" and affiliation ~= "owner" then |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
89 module:add_feature(xmlns_pubsub.."#"..affiliation.."-affiliation"); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
90 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
91 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
92 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
93 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
94 module:hook("host-disco-info-node", function (event) |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7984
diff
changeset
|
95 local stanza, reply, node = event.stanza, event.reply, event.node; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
96 local ok, ret = service:get_nodes(stanza.attr.from); |
5970
6a2c3293d4d7
mod_pubsub: Don't sent error replies from service disco events, let mod_disco handle that
Kim Alvefur <zash@zash.se>
parents:
5690
diff
changeset
|
97 if not ok or not ret[node] then |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
98 return; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
99 end |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
100 event.exists = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
101 reply:tag("identity", { category = "pubsub", type = "leaf" }); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
102 end); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
103 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
104 module:hook("host-disco-items-node", function (event) |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7984
diff
changeset
|
105 local stanza, reply, node = event.stanza, event.reply, event.node; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
106 local ok, ret = service:get_items(node, stanza.attr.from); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 if not ok then |
5970
6a2c3293d4d7
mod_pubsub: Don't sent error replies from service disco events, let mod_disco handle that
Kim Alvefur <zash@zash.se>
parents:
5690
diff
changeset
|
108 return; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
109 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
110 |
6434
382e03a40dd2
mod_pubsub: Transplant pieces of cdcfd93e2f43 from trunk
Kim Alvefur <zash@zash.se>
parents:
5970
diff
changeset
|
111 for _, id in ipairs(ret) do |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
112 reply:tag("item", { jid = module.host, name = id }):up(); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
113 end |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
114 event.exists = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
115 end); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
116 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
117 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
118 module:hook("host-disco-items", function (event) |
8210
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7984
diff
changeset
|
119 local stanza, reply = event.stanza, event.reply; |
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7984
diff
changeset
|
120 local ok, ret = service:get_nodes(stanza.attr.from); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
121 if not ok then |
5970
6a2c3293d4d7
mod_pubsub: Don't sent error replies from service disco events, let mod_disco handle that
Kim Alvefur <zash@zash.se>
parents:
5690
diff
changeset
|
122 return; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
123 end |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
124 for node, node_obj in pairs(ret) do |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
125 reply:tag("item", { jid = module.host, node = node, name = node_obj.config.name }):up(); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
126 end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
127 end); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
128 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
129 local admin_aff = module:get_option_string("default_admin_affiliation", "owner"); |
7708
c420a38db5ef
Backed out changeset f1af4edd5722, doesn't work as intended (node is the name of the node and always present)
Kim Alvefur <zash@zash.se>
parents:
6841
diff
changeset
|
130 local function get_affiliation(jid) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
131 local bare_jid = jid_bare(jid); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
132 if bare_jid == module.host or usermanager.is_admin(bare_jid, module.host) then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
133 return admin_aff; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
134 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
135 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
136 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
137 function set_service(new_service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 service = new_service; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 module.environment.service = service; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
140 add_disco_features_from_service(service); |
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 module.save() |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 return { service = service }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
145 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 function module.restore(data) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 set_service(data.service); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
150 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
151 function module.load() |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
152 if module.reloading then return; end |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
153 |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
154 set_service(pubsub.new({ |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
155 capabilities = { |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
156 none = { |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
157 create = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
158 publish = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
159 retract = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
160 get_nodes = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
162 subscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
163 unsubscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
164 get_subscription = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
165 get_subscriptions = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
166 get_items = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
167 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
168 subscribe_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
169 unsubscribe_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
170 get_subscription_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
171 get_subscriptions_other = false; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
172 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
173 be_subscribed = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
174 be_unsubscribed = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
176 set_affiliation = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
177 }; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
178 publisher = { |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
179 create = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
180 publish = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
181 retract = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
182 get_nodes = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
183 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
184 subscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
185 unsubscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
186 get_subscription = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
187 get_subscriptions = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
188 get_items = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
189 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
190 subscribe_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
191 unsubscribe_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
192 get_subscription_other = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
193 get_subscriptions_other = false; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
195 be_subscribed = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
196 be_unsubscribed = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
197 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
198 set_affiliation = false; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
199 }; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
200 owner = { |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
201 create = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
202 publish = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
203 retract = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
204 delete = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
205 get_nodes = true; |
6438
b1c40054b59d
mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents:
6434
diff
changeset
|
206 configure = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
207 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
208 subscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
209 unsubscribe = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
210 get_subscription = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
211 get_subscriptions = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
212 get_items = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
213 |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
214 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
215 subscribe_other = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
216 unsubscribe_other = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
217 get_subscription_other = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
218 get_subscriptions_other = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
219 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
220 be_subscribed = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
221 be_unsubscribed = true; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
222 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
223 set_affiliation = true; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
224 }; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
227 autocreate_on_publish = autocreate_on_publish; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
228 autocreate_on_subscribe = autocreate_on_subscribe; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 |
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
230 itemstore = simple_itemstore; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
231 broadcaster = simple_broadcast; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
232 get_affiliation = get_affiliation; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
233 |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
234 normalize_jid = jid_bare; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
235 })); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
236 end |