Software / code / prosody
Annotate
plugins/mod_pubsub/mod_pubsub.lua @ 11748:88ba05494d17 0.11
makefile: fix prosody.version target
POSIX is quite explicit regarding the precedence of AND-OR lists [0]:
> The operators "&&" and "||" shall have equal precedence and shall be
> evaluated with left associativity. For example, both of the following
> commands write solely `bar` to standard output:
> false && echo foo || echo bar
> true || echo foo && echo bar
Given that, `prosody.version` target behaves as
((((((test -f prosody.release && cp ...) ||
test -f ...) &&
sed ...) ||
test -f ...) &&
hexdump ...) ||
echo unknown > $@)
In the case of release tarballs, `prosody.release` does exist, so the
first AND pair is executed. Given that it's successful, then the first
`test -f` in the OR pair is ignored, and instead the `sed` in the AND
pair is executed. `sed` success, as `.hg_archival.txt` exists, making
the second `test -f` in the OR pair ignored, and `hexdump` in the AND
pair is executed. Now, given that `.hg` doesn't exist, it fails, so the
last `echo` is run, overwriting `prosody.version` with `unknown`.
This can be worked around placing `()` around the AND pairs. Decided to use
conditionals instead, as I think they better communicate the intention
of the block.
[0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03
| author | Lucas <lucas@sexy.is> |
|---|---|
| date | Sun, 15 Aug 2021 04:10:36 +0000 |
| parent | 11201:4ae1d485a9c6 |
| child | 11202:58492b4b85ea |
| 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"; |
|
8811
f2d35eee69c9
mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents:
8808
diff
changeset
|
5 local new_id = require "util.id".medium; |
|
9828
8e68136cde08
mod_pubsub: Simplify configuration for node data (see #1302)
Kim Alvefur <zash@zash.se>
parents:
9597
diff
changeset
|
6 local storagemanager = require "core.storagemanager"; |
|
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); |
|
7983
879be73c0a58
mod_pubsub: Fix syntax error introduced in 241f02bd66ce
Matthew Wild <mwild1@gmail.com>
parents:
7980
diff
changeset
|
14 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
|
15 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
|
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) |
|
8334
036e46d12b78
mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents:
8328
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 |
|
9108
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
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:
9101
diff
changeset
|
30 -- items(): iterator over (id, item) |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
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:
9101
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:
9101
diff
changeset
|
33 -- clear(): clear all items |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
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:
9101
diff
changeset
|
35 -- tail(): return the latest item |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
diff
changeset
|
36 |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
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:
9101
diff
changeset
|
38 -- set(node_name, node_data) |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
diff
changeset
|
39 -- get(node_name) |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
diff
changeset
|
40 -- users(): iterator over (node_name) |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
diff
changeset
|
41 |
|
86f31a2174b3
mod_pubsub: Add comment to document nodestore/itemstore methods
Matthew Wild <mwild1@gmail.com>
parents:
9101
diff
changeset
|
42 |
|
8504
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8503
diff
changeset
|
43 local node_store = module:open_store(module.name.."_nodes"); |
|
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8503
diff
changeset
|
44 |
|
8503
3b86134c56ea
mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents:
8340
diff
changeset
|
45 local function create_simple_itemstore(node_config, node_name) |
|
9828
8e68136cde08
mod_pubsub: Simplify configuration for node data (see #1302)
Kim Alvefur <zash@zash.se>
parents:
9597
diff
changeset
|
46 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:
9597
diff
changeset
|
47 local archive = driver:open("pubsub_"..node_name, "archive"); |
|
8503
3b86134c56ea
mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents:
8340
diff
changeset
|
48 return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name); |
|
8213
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
49 end |
|
e1272aeef31c
mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8210
diff
changeset
|
50 |
|
8814
07197f29e2b8
mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents:
8811
diff
changeset
|
51 function simple_broadcast(kind, node, jids, item, actor, node_obj) |
|
9181
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
52 if node_obj then |
|
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
53 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:
9179
diff
changeset
|
54 return; |
|
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
55 end |
|
79cf1f74738f
mod_pubsub: Prepare to support turning notifications off for each kind of broadcast
Kim Alvefur <zash@zash.se>
parents:
9179
diff
changeset
|
56 end |
|
9179
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9158
diff
changeset
|
57 if kind == "retract" then |
|
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9158
diff
changeset
|
58 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:
9158
diff
changeset
|
59 end |
|
82fad995a149
util.pubsub: Pass "retract" as the type of such broadcasts
Kim Alvefur <zash@zash.se>
parents:
9158
diff
changeset
|
60 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
61 if item then |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
62 item = st.clone(item); |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
63 item.attr.xmlns = nil; -- Clear the pubsub namespace |
|
9187
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9181
diff
changeset
|
64 if kind == "items" then |
|
9188
ef2616ade453
mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents:
9187
diff
changeset
|
65 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:
9187
diff
changeset
|
66 item:maptags(function () return nil; end); |
|
ef2616ade453
mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents:
9187
diff
changeset
|
67 end |
|
9187
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9181
diff
changeset
|
68 if expose_publisher and actor then |
|
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9181
diff
changeset
|
69 item.attr.publisher = actor |
|
bd452e4f5a13
mod_pubsub: Only attach publisher on normal "item" broadcasts
Kim Alvefur <zash@zash.se>
parents:
9181
diff
changeset
|
70 end |
|
6515
c9a72c64c3e2
mod_pubsub: Add support for including the publisher in item broadcasts
Philipp Hancke <fippo@goodadvice.pages.de>
parents:
6446
diff
changeset
|
71 end |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 end |
|
8811
f2d35eee69c9
mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents:
8808
diff
changeset
|
73 |
|
f2d35eee69c9
mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents:
8808
diff
changeset
|
74 local id = new_id(); |
|
11201
4ae1d485a9c6
mod_pubsub: Fix notification stanza type setting (fixes #1605)
Kim Alvefur <zash@zash.se>
parents:
11199
diff
changeset
|
75 local msg_type = node_obj and node_obj.config.notification_type or "headline"; |
|
8814
07197f29e2b8
mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents:
8811
diff
changeset
|
76 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
|
77 :tag("event", { xmlns = xmlns_pubsub_event }) |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 :tag(kind, { node = node }) |
|
8946
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8815
diff
changeset
|
79 |
|
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8815
diff
changeset
|
80 if item then |
|
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8815
diff
changeset
|
81 message:add_child(item); |
|
3a095233e178
mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
8815
diff
changeset
|
82 end |
|
8814
07197f29e2b8
mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents:
8811
diff
changeset
|
83 |
|
9039
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
84 local summary; |
|
8815
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
85 -- Compose a sensible textual representation of at least Atom payloads |
|
9039
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
86 if item and item.tags[1] then |
|
8815
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
87 local payload = item.tags[1]; |
|
9045
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
88 summary = module:fire_event("pubsub-summary/"..payload.attr.xmlns, { |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
89 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:
9044
diff
changeset
|
90 }); |
|
8815
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
91 end |
|
5974c9da1391
mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents:
8814
diff
changeset
|
92 |
|
9039
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
93 for jid, options in pairs(jids) do |
|
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
94 local new_stanza = st.clone(message); |
|
9044
18cd5102253c
mod_pubsub: Skip checks for adding body if no body generated
Kim Alvefur <zash@zash.se>
parents:
9043
diff
changeset
|
95 if summary and type(options) == "table" and options["pubsub#include_body"] then |
|
9039
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
96 new_stanza:body(summary); |
|
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
97 end |
|
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
98 new_stanza.attr.to = jid; |
|
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
99 module:send(new_stanza); |
|
0124e5ec1556
mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents:
8980
diff
changeset
|
100 end |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
101 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
102 |
|
9100
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
103 local max_max_items = module:get_option_number("pubsub_max_items", 256); |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
104 function check_node_config(node, actor, new_config) -- luacheck: ignore 212/actor 212/node |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
105 if (new_config["max_items"] or 1) > max_max_items then |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
106 return false; |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
107 end |
|
9101
1ff694534e98
mod_pubsub: Restrict access model to 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9100
diff
changeset
|
108 if new_config["access_model"] ~= "whitelist" and new_config["access_model"] ~= "open" then |
|
1ff694534e98
mod_pubsub: Restrict access model to 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9100
diff
changeset
|
109 return false; |
|
1ff694534e98
mod_pubsub: Restrict access model to 'whitelist' and 'open'
Kim Alvefur <zash@zash.se>
parents:
9100
diff
changeset
|
110 end |
|
9100
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
111 return true; |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
112 end |
|
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
113 |
|
8695
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8505
diff
changeset
|
114 function is_item_stanza(item) |
|
10672
657e61531b33
mod_pubsub, mod_pep: Ensure correct number of children of <item/> (fixes #1496)
Kim Alvefur <zash@zash.se>
parents:
9828
diff
changeset
|
115 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; |
|
8695
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8505
diff
changeset
|
116 end |
|
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8505
diff
changeset
|
117 |
|
9045
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
118 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event) |
|
9234
d00e8ec7ece2
mod_pubsub: Fix summary generation for Atom entries to use the correct field
Kim Alvefur <zash@zash.se>
parents:
9188
diff
changeset
|
119 local payload = event.payload; |
|
9045
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
120 local title = payload:get_child_text("title"); |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
121 local summary = payload:get_child_text("summary"); |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
122 if not summary and title then |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
123 local author = payload:find("author/name#"); |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
124 summary = title; |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
125 if author then |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
126 summary = author .. " posted " .. summary; |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
127 end |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
128 end |
|
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
129 return summary; |
|
11199
6c7c50a4de32
mod_pubsub: Lower priority of default <body> generator
Kim Alvefur <zash@zash.se>
parents:
10672
diff
changeset
|
130 end, -1); |
|
9045
4336a2b97aba
mod_pubsub: Make generation of notification body into an event to allow extensibility
Kim Alvefur <zash@zash.se>
parents:
9044
diff
changeset
|
131 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
132 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
|
133 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
|
134 |
|
8505
c9bdb4dfed96
mod_pubsub: Ignore unused parameter [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
8504
diff
changeset
|
135 local function add_disco_features_from_service(service) --luacheck: ignore 431/service |
|
8340
7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8339
diff
changeset
|
136 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:
8339
diff
changeset
|
137 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
|
138 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
140 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
141 module:hook("host-disco-info-node", function (event) |
|
8980
4d2738b99b07
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8957
diff
changeset
|
142 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
|
143 end); |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
145 module:hook("host-disco-items-node", function (event) |
|
8980
4d2738b99b07
mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents:
8957
diff
changeset
|
146 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
|
147 end); |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 return; |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 end |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
156 for node, node_obj in pairs(ret) do |
|
9597
17d43543f9b6
pubsub: Set pubsub#title as name attribute in disco#items (fixes #1226)
Kim Alvefur <zash@zash.se>
parents:
9234
diff
changeset
|
157 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
|
158 end |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
159 end); |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
160 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 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
|
162 local function get_affiliation(jid) |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
163 local bare_jid = jid_bare(jid); |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
164 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
|
165 return admin_aff; |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
166 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
167 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
168 |
|
9118
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9108
diff
changeset
|
169 function get_service() |
|
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9108
diff
changeset
|
170 return service; |
|
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9108
diff
changeset
|
171 end |
|
70f34c663fb3
mod_pubsub: Add a public method for retrieving the service object
Kim Alvefur <zash@zash.se>
parents:
9108
diff
changeset
|
172 |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 function set_service(new_service) |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
174 service = new_service; |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 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
|
176 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
|
177 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
178 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 function module.save() |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 return { service = service }; |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
181 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
182 |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
183 function module.restore(data) |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
184 set_service(data.service); |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
185 end |
|
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
186 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
187 function module.load() |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
188 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
|
189 |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
190 set_service(pubsub.new({ |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
191 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
|
192 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
|
193 |
|
8504
80b8355c8b8b
mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents:
8503
diff
changeset
|
194 nodestore = node_store; |
|
8503
3b86134c56ea
mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents:
8340
diff
changeset
|
195 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
|
196 broadcaster = simple_broadcast; |
|
8695
09e7fd8b16cd
mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents:
8505
diff
changeset
|
197 itemcheck = is_item_stanza; |
|
9100
e01c7d0cbbf4
mod_pubsub: Add configurable maximum on number of items
Kim Alvefur <zash@zash.se>
parents:
9045
diff
changeset
|
198 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
|
199 get_affiliation = get_affiliation; |
|
5626
8416d4619d80
mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 |
|
5690
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
201 normalize_jid = jid_bare; |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
202 })); |
|
630e7224a65f
mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5626
diff
changeset
|
203 end |