author | Kim Alvefur <zash@zash.se> |
Wed, 06 Mar 2024 19:12:11 +0100 | |
changeset 13461 | 3347ed1014b8 |
parent 13460 | e9ab660b9c5f |
permissions | -rw-r--r-- |
12981
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
1 |
local pubsub = require "prosody.util.pubsub"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
2 |
local st = require "prosody.util.stanza"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
3 |
local jid_bare = require "prosody.util.jid".bare; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
4 |
local new_id = require "prosody.util.id".medium; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
5 |
local storagemanager = require "prosody.core.storagemanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12964
diff
changeset
|
6 |
local xtemplate = require "prosody.util.xtemplate"; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 |
local xmlns_pubsub_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
|
10 |
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
|
11 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 |
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
|
13 |
local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); |
7986
879be73c0a58
mod_pubsub: Fix syntax error introduced in 241f02bd66ce
Matthew Wild <mwild1@gmail.com>
parents:
7983
diff
changeset
|
14 |
local pubsub_disco_name = module:get_option_string("name", "Prosody PubSub Service"); |
12964
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
15 |
local service_expose_publisher = module:get_option_boolean("expose_publisher") |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 |
local 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 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
21 |
module:depends("disco"); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 |
function handle_pubsub_iq(event) |
8337
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8331
diff
changeset
|
26 |
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
|
27 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 |
|
9111
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
29 |
-- An itemstore supports the following methods: |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
30 |
-- items(): iterator over (id, item) |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
31 |
-- get(id): return item with id |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
32 |
-- set(id, item): set id to item |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
33 |
-- clear(): clear all items |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
34 |
-- resize(n): set new limit and trim oldest items |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
35 |
-- tail(): return the latest item |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
36 |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
37 |
-- A nodestore supports the following methods: |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
38 |
-- set(node_name, node_data) |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
39 |
-- get(node_name) |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
40 |
-- users(): iterator over (node_name) |
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
41 |
|
13217
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13206
diff
changeset
|
42 |
local max_max_items = module:get_option_integer("pubsub_max_items", 256, 1); |
11635
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
43 |
|
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
44 |
local function tonumber_max_items(n) |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
45 |
if n == "max" then |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
46 |
return max_max_items; |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
47 |
end |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
48 |
return tonumber(n); |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
49 |
end |
9111
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9104
diff
changeset
|
50 |
|
11860
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
51 |
for _, field in ipairs(lib_pubsub.node_config_form) do |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
52 |
if field.var == "pubsub#max_items" then |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
53 |
field.range_max = max_max_items; |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
54 |
break; |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
55 |
end |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
56 |
end |
14a679588b7b
mod_pubsub,mod_pep: Advertise maximum number of items via XEP-0122
Kim Alvefur <zash@zash.se>
parents:
11736
diff
changeset
|
57 |
|
8507
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8506
diff
changeset
|
58 |
local node_store = module:open_store(module.name.."_nodes"); |
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8506
diff
changeset
|
59 |
|
11192
8a29e7206917
mod_pubsub: Comment on itemstore type
Kim Alvefur <zash@zash.se>
parents:
10677
diff
changeset
|
60 |
local function create_simple_itemstore(node_config, node_name) --> util.cache like object |
9832
8e68136cde08
mod_pubsub: Simplify configuration for node data (see #1302)
Kim Alvefur <zash@zash.se>
parents:
9601
diff
changeset
|
61 |
local driver = storagemanager.get_driver(module.host, "pubsub_data"); |
8e68136cde08
mod_pubsub: Simplify configuration for node data (see #1302)
Kim Alvefur <zash@zash.se>
parents:
9601
diff
changeset
|
62 |
local archive = driver:open("pubsub_"..node_name, "archive"); |
11635
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
63 |
local max_items = tonumber_max_items(node_config["max_items"]); |
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
64 |
return lib_pubsub.archive_itemstore(archive, max_items, nil, node_name); |
8216
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8213
diff
changeset
|
65 |
end |
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8213
diff
changeset
|
66 |
|
11729
789da12cf232
mod_pubsub: Silence warning about 'service' as argument [luacheck]
Kim Alvefur <zash@zash.se>
parents:
11724
diff
changeset
|
67 |
function simple_broadcast(kind, node, jids, item, actor, node_obj, service) --luacheck: ignore 431/service |
9184
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9182
diff
changeset
|
68 |
if node_obj then |
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9182
diff
changeset
|
69 |
if node_obj.config["notify_"..kind] == false then |
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9182
diff
changeset
|
70 |
return; |
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9182
diff
changeset
|
71 |
end |
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9182
diff
changeset
|
72 |
end |
9182
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9161
diff
changeset
|
73 |
if kind == "retract" then |
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9161
diff
changeset
|
74 |
kind = "items"; -- XEP-0060 signals retraction in an <items> container |
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9161
diff
changeset
|
75 |
end |
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9161
diff
changeset
|
76 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
77 |
if item then |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 |
item = st.clone(item); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 |
item.attr.xmlns = nil; -- Clear the pubsub namespace |
9190
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9184
diff
changeset
|
80 |
if kind == "items" then |
9191
ef2616ade453
mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents:
9190
diff
changeset
|
81 |
if node_obj and node_obj.config.include_payload == false then |
ef2616ade453
mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents:
9190
diff
changeset
|
82 |
item:maptags(function () return nil; end); |
ef2616ade453
mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents:
9190
diff
changeset
|
83 |
end |
12964
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
84 |
local node_expose_publisher = service_expose_publisher; |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
85 |
if node_expose_publisher == nil and node_obj and node_obj.config.itemreply == "publisher" then |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
86 |
node_expose_publisher = true; |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
87 |
end |
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
88 |
if not node_expose_publisher then |
11722
d79f5431f31b
mod_pubsub: Remove publisher field when not exposing publisher
Kim Alvefur <zash@zash.se>
parents:
11721
diff
changeset
|
89 |
item.attr.publisher = nil; |
12431
018ac691ee22
mod_pubsub: Don't attempt to use server actor as publisher (fixes #1723)
Matthew Wild <mwild1@gmail.com>
parents:
12219
diff
changeset
|
90 |
elseif not item.attr.publisher and actor ~= true then |
11721
605484fc1c62
mod_pubsub: Normalize 'publisher' JID
Kim Alvefur <zash@zash.se>
parents:
11719
diff
changeset
|
91 |
item.attr.publisher = service.config.normalize_jid(actor); |
9190
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9184
diff
changeset
|
92 |
end |
6518
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6449
diff
changeset
|
93 |
end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
94 |
end |
8814
f2d35eee69c9
mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents:
8811
diff
changeset
|
95 |
|
f2d35eee69c9
mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents:
8811
diff
changeset
|
96 |
local id = new_id(); |
11205
4ae1d485a9c6
mod_pubsub: Fix notification stanza type setting (fixes #1605)
Kim Alvefur <zash@zash.se>
parents:
11203
diff
changeset
|
97 |
local msg_type = node_obj and node_obj.config.notification_type or "headline"; |
8817
07197f29e2b8
mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
98 |
local message = st.message({ from = module.host, type = msg_type, id = id }) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
99 |
:tag("event", { xmlns = xmlns_pubsub_event }) |
9724
e7ddf70ae417
mod_pubsub: Add semicolon (code style)
Kim Alvefur <zash@zash.se>
parents:
9601
diff
changeset
|
100 |
:tag(kind, { node = node }); |
8949
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
101 |
|
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
102 |
if item then |
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
103 |
message:add_child(item); |
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
104 |
end |
8817
07197f29e2b8
mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
105 |
|
9042
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
106 |
local summary; |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
107 |
if item and item.tags[1] then |
8818
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8817
diff
changeset
|
108 |
local payload = item.tags[1]; |
12216
bc6fc1cb04ae
mod_pubsub: Use the 'pubsub#type' setting to pick summary generator
Kim Alvefur <zash@zash.se>
parents:
12157
diff
changeset
|
109 |
local payload_type = node_obj and node_obj.config.payload_type or payload.attr.xmlns; |
bc6fc1cb04ae
mod_pubsub: Use the 'pubsub#type' setting to pick summary generator
Kim Alvefur <zash@zash.se>
parents:
12157
diff
changeset
|
110 |
summary = module:fire_event("pubsub-summary/"..payload_type, { |
9048
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9047
diff
changeset
|
111 |
kind = kind, node = node, jids = jids, actor = actor, item = item, payload = payload, |
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9047
diff
changeset
|
112 |
}); |
8818
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8817
diff
changeset
|
113 |
end |
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8817
diff
changeset
|
114 |
|
9042
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
115 |
for jid, options in pairs(jids) do |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
116 |
local new_stanza = st.clone(message); |
9047
18cd5102253c
mod_pubsub: Skip checks for adding body if no body generated
Kim Alvefur <zash@zash.se>
parents:
9046
diff
changeset
|
117 |
if summary and type(options) == "table" and options["pubsub#include_body"] then |
9042
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
118 |
new_stanza:body(summary); |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
119 |
end |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
120 |
new_stanza.attr.to = jid; |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
121 |
module:send(new_stanza); |
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8983
diff
changeset
|
122 |
end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
123 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
124 |
|
9728
8e6a0e1c1876
mod_pubsub: Change order of luacheck directives to match arguments they apply to
Kim Alvefur <zash@zash.se>
parents:
9724
diff
changeset
|
125 |
function check_node_config(node, actor, new_config) -- luacheck: ignore 212/node 212/actor |
11635
6641ca266d94
mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents:
11206
diff
changeset
|
126 |
if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then |
9103
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
127 |
return false; |
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
128 |
end |
9729
8ad689b6d26f
mod_pubsub: Split line in config check to improve readability
Kim Alvefur <zash@zash.se>
parents:
9728
diff
changeset
|
129 |
if new_config["access_model"] ~= "whitelist" |
8ad689b6d26f
mod_pubsub: Split line in config check to improve readability
Kim Alvefur <zash@zash.se>
parents:
9728
diff
changeset
|
130 |
and new_config["access_model"] ~= "open" then |
9104
1ff694534e98
mod_pubsub: Restrict access model to 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9103
diff
changeset
|
131 |
return false; |
1ff694534e98
mod_pubsub: Restrict access model to 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9103
diff
changeset
|
132 |
end |
9103
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
133 |
return true; |
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
134 |
end |
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
135 |
|
8698
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8508
diff
changeset
|
136 |
function is_item_stanza(item) |
10676
657e61531b33
mod_pubsub, mod_pep: Ensure correct number of children of <item/> (fixes #1496)
Kim Alvefur <zash@zash.se>
parents:
9832
diff
changeset
|
137 |
return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; |
8698
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8508
diff
changeset
|
138 |
end |
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8508
diff
changeset
|
139 |
|
10074
d7cae7187943
mod_pubsub: Move a comment to where it makes sense
Kim Alvefur <zash@zash.se>
parents:
9833
diff
changeset
|
140 |
-- Compose a textual representation of Atom payloads |
12219
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
141 |
local summary_templates = module:get_option("pubsub_summary_templates", { |
13343
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
142 |
["http://www.w3.org/2005/Atom"] = "{@pubsub:title|and{*{@pubsub:title}*\n\n}}{summary|or{{author/name|and{{author/name} posted }}{title}}}"; |
12219
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
143 |
}) |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
144 |
|
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
145 |
for pubsub_type, template in pairs(summary_templates) do |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
146 |
module:hook("pubsub-summary/"..pubsub_type, function (event) |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
147 |
local payload = event.payload; |
13343
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
148 |
|
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
149 |
local got_config, node_config = service:get_node_config(event.node, true); |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
150 |
if got_config then |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
151 |
payload = st.clone(payload); |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
152 |
payload.attr["xmlns:pubsub"] = xmlns_pubsub; |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
153 |
payload.attr["pubsub:node"] = event.node; |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
154 |
payload.attr["pubsub:title"] = node_config.title; |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
155 |
payload.attr["pubsub:description"] = node_config.description; |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
156 |
end |
c94989c557cd
mod_pubsub: Provide some node properties in summary template #1809
Kim Alvefur <zash@zash.se>
parents:
13217
diff
changeset
|
157 |
|
12219
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
158 |
return xtemplate.render(template, payload, tostring); |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
159 |
end, -1); |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
160 |
end |
33a93d0a9a45
mod_pubsub: Allow configuring summary templates
Kim Alvefur <zash@zash.se>
parents:
12218
diff
changeset
|
161 |
|
9048
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9047
diff
changeset
|
162 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
|
8508
c9bdb4dfed96
mod_pubsub: Ignore unused parameter [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
8507
diff
changeset
|
166 |
local function add_disco_features_from_service(service) --luacheck: ignore 431/service |
8343
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8342
diff
changeset
|
167 |
for feature in lib_pubsub.get_feature_set(service) do |
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8342
diff
changeset
|
168 |
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
|
169 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
170 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
172 |
module:hook("host-disco-info-node", function (event) |
8983
4d2738b99b07
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8960
diff
changeset
|
173 |
return lib_pubsub.handle_disco_info_node(event, service); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
174 |
end); |
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 |
module:hook("host-disco-items-node", function (event) |
8983
4d2738b99b07
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8960
diff
changeset
|
177 |
return lib_pubsub.handle_disco_items_node(event, service); |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
178 |
end); |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
181 |
module:hook("host-disco-items", function (event) |
8213
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7987
diff
changeset
|
182 |
local stanza, reply = event.stanza, event.reply; |
352d605b1178
mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7987
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
return; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
186 |
end |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
187 |
for node, node_obj in pairs(ret) do |
9601
17d43543f9b6
pubsub: Set pubsub#title as name attribute in disco#items (fixes #1226)
Kim Alvefur <zash@zash.se>
parents:
9237
diff
changeset
|
188 |
reply:tag("item", { jid = module.host, node = node, name = node_obj.config.title }):up(); |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
189 |
end |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
190 |
end); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
191 |
|
13206
173038306750
plugins: Use get_option_enum where appropriate
Kim Alvefur <zash@zash.se>
parents:
12981
diff
changeset
|
192 |
local admin_aff = module:get_option_enum("default_admin_affiliation", "owner", "publisher", "member", "outcast", "none"); |
12646
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12431
diff
changeset
|
193 |
module:default_permission("prosody:admin", ":service-admin"); |
7711
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:
6844
diff
changeset
|
194 |
local function get_affiliation(jid) |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
195 |
local bare_jid = jid_bare(jid); |
12646
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12431
diff
changeset
|
196 |
if bare_jid == module.host or module:may(":service-admin", bare_jid) then |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
197 |
return admin_aff; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
198 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
199 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 |
|
9121
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9111
diff
changeset
|
201 |
function get_service() |
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9111
diff
changeset
|
202 |
return service; |
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9111
diff
changeset
|
203 |
end |
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9111
diff
changeset
|
204 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 |
function set_service(new_service) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
206 |
service = new_service; |
11730
76156c675456
mod_pubsub: Update configuration on reload (fixes #1382)
Kim Alvefur <zash@zash.se>
parents:
11729
diff
changeset
|
207 |
service.config.autocreate_on_publish = autocreate_on_publish; |
76156c675456
mod_pubsub: Update configuration on reload (fixes #1382)
Kim Alvefur <zash@zash.se>
parents:
11729
diff
changeset
|
208 |
service.config.autocreate_on_subscribe = autocreate_on_subscribe; |
12964
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
209 |
service.config.expose_publisher = service_expose_publisher; |
11736
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
210 |
|
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
211 |
service.config.nodestore = node_store; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
212 |
service.config.itemstore = create_simple_itemstore; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
213 |
service.config.broadcaster = simple_broadcast; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
214 |
service.config.itemcheck = is_item_stanza; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
215 |
service.config.check_node_config = check_node_config; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
216 |
service.config.get_affiliation = get_affiliation; |
5735f931f5c4
mod_pubsub: Update callbacks on reload to more completely refresh config
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
217 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
221 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
222 |
function module.save() |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 |
return { service = service }; |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
224 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 |
function module.restore(data) |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
227 |
set_service(data.service); |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
228 |
end |
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
230 |
function module.load() |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
231 |
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
|
232 |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
233 |
set_service(pubsub.new({ |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
234 |
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
|
235 |
autocreate_on_subscribe = autocreate_on_subscribe; |
12964
31b22cc221b5
mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents:
12646
diff
changeset
|
236 |
expose_publisher = service_expose_publisher; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
237 |
|
11724
72512c0858b3
mod_pubsub: Explicitly enable persistence by default to preserve behavior
Kim Alvefur <zash@zash.se>
parents:
11722
diff
changeset
|
238 |
node_defaults = { |
72512c0858b3
mod_pubsub: Explicitly enable persistence by default to preserve behavior
Kim Alvefur <zash@zash.se>
parents:
11722
diff
changeset
|
239 |
["persist_items"] = true; |
72512c0858b3
mod_pubsub: Explicitly enable persistence by default to preserve behavior
Kim Alvefur <zash@zash.se>
parents:
11722
diff
changeset
|
240 |
}; |
12157
26af75c20163
util.pubsub: Fix item store resize to "max"
Kim Alvefur <zash@zash.se>
parents:
12025
diff
changeset
|
241 |
max_items = max_max_items; |
8507
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8506
diff
changeset
|
242 |
nodestore = node_store; |
8506
3b86134c56ea
mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents:
8343
diff
changeset
|
243 |
itemstore = create_simple_itemstore; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
244 |
broadcaster = simple_broadcast; |
8698
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8508
diff
changeset
|
245 |
itemcheck = is_item_stanza; |
9103
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9048
diff
changeset
|
246 |
check_node_config = check_node_config; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
247 |
get_affiliation = get_affiliation; |
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 |
|
12025
376522fb3f52
mod_pubsub: Allow specifying the JID of the pubsub service
Kim Alvefur <zash@zash.se>
parents:
11860
diff
changeset
|
249 |
jid = module.host; |
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
250 |
normalize_jid = jid_bare; |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
251 |
})); |
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
252 |
end |
13460
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
253 |
|
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
254 |
local function get_service(service_jid) |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
255 |
return assert(assert(prosody.hosts[service_jid], "Unknown pubsub service").modules.pubsub, "Not a pubsub service").service; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
256 |
end |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
257 |
|
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
258 |
module:add_item("shell-command", { |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
259 |
section = "pubsub"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
260 |
section_desc = "Manage publish/subscribe nodes"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
261 |
name = "create_node"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
262 |
desc = "Create a node with the specified name"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
263 |
args = { |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
264 |
{ name = "service_jid", type = "string" }; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
265 |
{ name = "node_name", type = "string" }; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
266 |
}; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
267 |
host_selector = "service_jid"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
268 |
|
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
269 |
handler = function (self, service_jid, node_name) --luacheck: ignore 212/self |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
270 |
return get_service(service_jid):create(node_name, true); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
271 |
end; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
272 |
}); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
273 |
|
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
274 |
module:add_item("shell-command", { |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
275 |
section = "pubsub"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
276 |
section_desc = "Manage publish/subscribe nodes"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
277 |
name = "list_nodes"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
278 |
desc = "List nodes on a pubsub service"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
279 |
args = { |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
280 |
{ name = "service_jid", type = "string" }; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
281 |
}; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
282 |
host_selector = "service_jid"; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
283 |
|
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
284 |
handler = function (self, service_jid) --luacheck: ignore 212/self |
13461
3347ed1014b8
mod_pubsub: Ignore shadowed variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
13460
diff
changeset
|
285 |
-- luacheck: ignore 431/service |
13460
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
286 |
local service = get_service(service_jid); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
287 |
local nodes = select(2, assert(service:get_nodes(true))); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
288 |
local count = 0; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
289 |
for node_name in pairs(nodes) do |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
290 |
count = count + 1; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
291 |
self.session.print(node_name); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
292 |
end |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
293 |
return true, ("%d nodes"):format(count); |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
294 |
end; |
e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
Matthew Wild <mwild1@gmail.com>
parents:
13343
diff
changeset
|
295 |
}); |