Annotate

plugins/mod_pubsub/pubsub.lib.lua @ 13201:65fb0d7a2312

moduleapi: Add enum config option method For when a setting has a few fixed values it can take
author Kim Alvefur <zash@zash.se>
date Sat, 16 Jan 2021 20:40:14 +0100
parent 13179:1b1ed555f307
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12589
39ae08180c81 compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents: 12021
diff changeset
1 local t_unpack = table.unpack;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
2 local time_now = os.time;
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
3
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
4 local jid_prep = require "prosody.util.jid".prep;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
5 local set = require "prosody.util.set";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
6 local st = require "prosody.util.stanza";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
7 local it = require "prosody.util.iterators";
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
8 local uuid_generate = require "prosody.util.uuid".generate;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
9 local dataform = require"prosody.util.dataforms".new;
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12961
diff changeset
10 local errors = require "prosody.util.error";
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 local 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
13 local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors";
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
14 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 local _M = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 local handlers = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 _M.handlers = handlers;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 local pubsub_errors = {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 ["conflict"] = { "cancel", "conflict" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 ["jid-required"] = { "modify", "bad-request", nil, "jid-required" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 ["item-not-found"] = { "cancel", "item-not-found" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
9041
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
28 ["invalid-options"] = { "modify", "bad-request", nil, "invalid-options" };
6473
7c8f58d2b331 Merge 0.9->0.10
Matthew Wild <mwild1@gmail.com>
parents: 6448
diff changeset
29 ["forbidden"] = { "auth", "forbidden" };
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
30 ["not-allowed"] = { "cancel", "not-allowed" };
9076
00d89430d77e pubsub.lib: Support for not-acceptable error
Matthew Wild <mwild1@gmail.com>
parents: 9072
diff changeset
31 ["not-acceptable"] = { "modify", "not-acceptable" };
8953
19cbe80df9c8 mod_pubsub: Make pubsub.lib aware of internal-server-error condition
Kim Alvefur <zash@zash.se>
parents: 8940
diff changeset
32 ["internal-server-error"] = { "wait", "internal-server-error" };
9110
3dbecb399dfb pubsub.lib: Add support for precondition-not-met error
Matthew Wild <mwild1@gmail.com>
parents: 9109
diff changeset
33 ["precondition-not-met"] = { "cancel", "conflict", nil, "precondition-not-met" };
9207
76d593b35958 util.pubsub, pubsub.lib: Improve error on attempt to publish invalid item
Matthew Wild <mwild1@gmail.com>
parents: 9206
diff changeset
34 ["invalid-item"] = { "modify", "bad-request", "invalid item" };
11723
3ead0967e04d util.pubsub: Signal that 'persistent-items' is unsupported when disabled
Kim Alvefur <zash@zash.se>
parents: 11715
diff changeset
35 ["persistent-items-unsupported"] = { "cancel", "feature-not-implemented", nil, "persistent-items" };
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36 };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
37 local function pubsub_error_reply(stanza, error)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 local e = pubsub_errors[error];
10356
0a2d7efca039 util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents: 10276
diff changeset
39 if not e and errors.is_err(error) then
0a2d7efca039 util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents: 10276
diff changeset
40 e = { error.type, error.condition, error.text, error.pubsub_condition };
0a2d7efca039 util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455)
Matthew Wild <mwild1@gmail.com>
parents: 10276
diff changeset
41 end
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
42 local reply = st.error_reply(stanza, t_unpack(e, 1, 3));
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 if e[4] then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 return reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 _M.pubsub_error_reply = pubsub_error_reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
50 local function dataform_error_message(err) -- ({ string : string }) -> string?
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
51 local out = {};
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
52 for field, errmsg in pairs(err) do
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
53 table.insert(out, ("%s: %s"):format(field, errmsg))
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
54 end
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
55 return table.concat(out, "; ");
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
56 end
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
57
9115
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
58 -- Note: If any config options are added that are of complex types,
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
59 -- (not simply strings/numbers) then the publish-options code will
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
60 -- need to be revisited
7358
d0390bc9c5d1 mod_pubsub: Don’t require util.dataforms twice
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6841
diff changeset
61 local node_config_form = dataform {
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
62 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
63 type = "hidden";
9274
1712e366b081 mod_pubsub: Exclude value of FORM_TYPE from stored data
Kim Alvefur <zash@zash.se>
parents: 9247
diff changeset
64 var = "FORM_TYPE";
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
65 value = "http://jabber.org/protocol/pubsub#node_config";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
66 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
67 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
68 type = "text-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
69 name = "title";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
70 var = "pubsub#title";
8979
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
71 label = "Title";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
72 };
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
73 {
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
74 type = "text-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
75 name = "description";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
76 var = "pubsub#description";
8979
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
77 label = "Description";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
78 };
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
79 {
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
80 type = "text-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
81 name = "payload_type";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
82 var = "pubsub#type";
9180
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
83 label = "The type of node data, usually specified by the namespace of the payload (if any)";
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
84 };
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
85 {
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
86 type = "text-single";
11631
6641ca266d94 mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents: 11429
diff changeset
87 datatype = "pubsub:integer-or-max";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
88 name = "max_items";
11855
8890eaa69446 mod_pubsub: Prevent max_items from being set to zero
Kim Alvefur <zash@zash.se>
parents: 11854
diff changeset
89 range_min = 1;
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
90 var = "pubsub#max_items";
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
91 label = "Max # of items to persist";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
92 };
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
93 {
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
94 type = "boolean";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
95 name = "persist_items";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
96 var = "pubsub#persist_items";
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
97 label = "Persist items to storage";
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
98 };
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
99 {
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
100 type = "list-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
101 name = "access_model";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
102 var = "pubsub#access_model";
9096
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
103 label = "Specify the subscriber model";
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
104 options = {
9135
c68d62ae9cb7 pubsub.lib: correctly emit data form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9124
diff changeset
105 "authorize",
c68d62ae9cb7 pubsub.lib: correctly emit data form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9124
diff changeset
106 "open",
c68d62ae9cb7 pubsub.lib: correctly emit data form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9124
diff changeset
107 "presence",
c68d62ae9cb7 pubsub.lib: correctly emit data form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9124
diff changeset
108 "roster",
c68d62ae9cb7 pubsub.lib: correctly emit data form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9124
diff changeset
109 "whitelist",
9096
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
110 };
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
111 };
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
112 {
7de4eec02ece mod_pubsub: Add access model to configuration form
Kim Alvefur <zash@zash.se>
parents: 9076
diff changeset
113 type = "list-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
114 name = "publish_model";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
115 var = "pubsub#publish_model";
9130
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
116 label = "Specify the publisher model";
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
117 options = {
9137
4803d2feeecb pubsub.lib: fix more form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9136
diff changeset
118 "publishers";
4803d2feeecb pubsub.lib: fix more form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9136
diff changeset
119 "subscribers";
4803d2feeecb pubsub.lib: fix more form fields
Jonas Wielicki <jonas@wielicki.name>
parents: 9136
diff changeset
120 "open";
9130
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
121 };
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
122 };
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
123 {
11854
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
124 type = "list-single";
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
125 var = "pubsub#send_last_published_item";
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
126 name = "send_last_published_item";
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
127 options = { "never"; "on_sub"; "on_sub_and_presence" };
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
128 };
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
129 {
9182
ec48c02ded0c mod_pubsub: Add support for "quiet nodes" (disabling notifications)
Kim Alvefur <zash@zash.se>
parents: 9180
diff changeset
130 type = "boolean";
9211
a476d80761cd mod_pubsub: Fix boolean value in form
Kim Alvefur <zash@zash.se>
parents: 9210
diff changeset
131 value = true;
9186
9f33a13eb011 mod_pubsub: Use the correct form field
Kim Alvefur <zash@zash.se>
parents: 9185
diff changeset
132 label = "Whether to deliver event notifications";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
133 name = "notify_items";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
134 var = "pubsub#deliver_notifications";
9182
ec48c02ded0c mod_pubsub: Add support for "quiet nodes" (disabling notifications)
Kim Alvefur <zash@zash.se>
parents: 9180
diff changeset
135 };
ec48c02ded0c mod_pubsub: Add support for "quiet nodes" (disabling notifications)
Kim Alvefur <zash@zash.se>
parents: 9180
diff changeset
136 {
9188
ef2616ade453 mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents: 9186
diff changeset
137 type = "boolean";
9212
127af0795e93 mod_pubsub: Add missing default value for deliver_payloads
Kim Alvefur <zash@zash.se>
parents: 9211
diff changeset
138 value = true;
9188
ef2616ade453 mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents: 9186
diff changeset
139 label = "Whether to deliver payloads with event notifications";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
140 name = "include_payload";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
141 var = "pubsub#deliver_payloads";
9188
ef2616ade453 mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents: 9186
diff changeset
142 };
ef2616ade453 mod_pubsub: Add support for thin notifications (without the full payload)
Kim Alvefur <zash@zash.se>
parents: 9186
diff changeset
143 {
9130
74525b8104d5 pubsub.lib: Add support for pubsub#publish_model
Matthew Wild <mwild1@gmail.com>
parents: 9128
diff changeset
144 type = "list-single";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
145 name = "notification_type";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
146 var = "pubsub#notification_type";
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
147 label = "Specify the delivery style for notifications";
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
148 options = {
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
149 { label = "Messages of type normal", value = "normal" },
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
150 { label = "Messages of type headline", value = "headline", default = true },
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
151 };
8822
4afa77e0d2b0 mod_pubsub: Fix syntax error
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
152 };
9183
8239f24e38df mod_pubsub: Make notification of node deletion configurable
Kim Alvefur <zash@zash.se>
parents: 9182
diff changeset
153 {
8239f24e38df mod_pubsub: Make notification of node deletion configurable
Kim Alvefur <zash@zash.se>
parents: 9182
diff changeset
154 type = "boolean";
8239f24e38df mod_pubsub: Make notification of node deletion configurable
Kim Alvefur <zash@zash.se>
parents: 9182
diff changeset
155 label = "Whether to notify subscribers when the node is deleted";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
156 name = "notify_delete";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
157 var = "pubsub#notify_delete";
9185
60f163e7a7a7 mod_pubsub: Specify defaults for notification settings
Kim Alvefur <zash@zash.se>
parents: 9184
diff changeset
158 value = true;
9183
8239f24e38df mod_pubsub: Make notification of node deletion configurable
Kim Alvefur <zash@zash.se>
parents: 9182
diff changeset
159 };
9184
9fbddb80803b mod_pubsub: Make notification of item retraction configurable
Kim Alvefur <zash@zash.se>
parents: 9183
diff changeset
160 {
9fbddb80803b mod_pubsub: Make notification of item retraction configurable
Kim Alvefur <zash@zash.se>
parents: 9183
diff changeset
161 type = "boolean";
9fbddb80803b mod_pubsub: Make notification of item retraction configurable
Kim Alvefur <zash@zash.se>
parents: 9183
diff changeset
162 label = "Whether to notify subscribers when items are removed from the node";
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
163 name = "notify_retract";
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
164 var = "pubsub#notify_retract";
9185
60f163e7a7a7 mod_pubsub: Specify defaults for notification settings
Kim Alvefur <zash@zash.se>
parents: 9184
diff changeset
165 value = true;
9184
9fbddb80803b mod_pubsub: Make notification of item retraction configurable
Kim Alvefur <zash@zash.se>
parents: 9183
diff changeset
166 };
12960
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
167 {
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
168 type = "list-single";
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
169 label = "Specify whose JID to include as the publisher of items";
12961
1cbfa843f8c3 mod_pubsub/pubsub.lib: Fix accidental name/var swap (thanks scansion)
Matthew Wild <mwild1@gmail.com>
parents: 12960
diff changeset
170 name = "itemreply";
1cbfa843f8c3 mod_pubsub/pubsub.lib: Fix accidental name/var swap (thanks scansion)
Matthew Wild <mwild1@gmail.com>
parents: 12960
diff changeset
171 var = "pubsub#itemreply";
12960
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
172 options = {
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
173 { label = "Include the node owner's JID", value = "owner" };
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
174 { label = "Include the item publisher's JID", value = "publisher" };
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
175 { label = "Don't include any JID with items", value = "none", default = true };
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
176 };
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
177 };
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
178 };
11785
b1381e302cab mod_pubsub/pubsub.lib: Export config forms for use by other modules
Matthew Wild <mwild1@gmail.com>
parents: 11769
diff changeset
179 _M.node_config_form = node_config_form;
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
180
9116
9f36f5c14545 mod_pubsub: Rename variable subscription options form to improve readability
Kim Alvefur <zash@zash.se>
parents: 9115
diff changeset
181 local subscribe_options_form = dataform {
8826
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
182 {
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
183 type = "hidden";
9274
1712e366b081 mod_pubsub: Exclude value of FORM_TYPE from stored data
Kim Alvefur <zash@zash.se>
parents: 9247
diff changeset
184 var = "FORM_TYPE";
8826
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
185 value = "http://jabber.org/protocol/pubsub#subscribe_options";
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
186 };
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
187 {
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
188 type = "boolean";
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
189 name = "pubsub#include_body";
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
190 label = "Receive message body in addition to payload?";
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 9038
diff changeset
191 };
8826
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
192 };
11785
b1381e302cab mod_pubsub/pubsub.lib: Export config forms for use by other modules
Matthew Wild <mwild1@gmail.com>
parents: 11769
diff changeset
193 _M.subscribe_options_form = subscribe_options_form;
8826
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
194
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
195 local node_metadata_form = dataform {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
196 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
197 type = "hidden";
9274
1712e366b081 mod_pubsub: Exclude value of FORM_TYPE from stored data
Kim Alvefur <zash@zash.se>
parents: 9247
diff changeset
198 var = "FORM_TYPE";
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
199 value = "http://jabber.org/protocol/pubsub#meta-data";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
200 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
201 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
202 type = "text-single";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
203 name = "pubsub#title";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
204 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
205 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
206 type = "text-single";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
207 name = "pubsub#description";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
208 };
9180
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
209 {
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
210 type = "text-single";
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
211 name = "pubsub#type";
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
212 };
10062
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
213 {
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
214 type = "text-single";
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
215 name = "pubsub#access_model";
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
216 };
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
217 {
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
218 type = "text-single";
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
219 name = "pubsub#publish_model";
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
220 };
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
221 };
11785
b1381e302cab mod_pubsub/pubsub.lib: Export config forms for use by other modules
Matthew Wild <mwild1@gmail.com>
parents: 11769
diff changeset
222 _M.node_metadata_form = node_metadata_form;
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
223
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
224 local service_method_feature_map = {
9199
596d0d82a113 mod_pubsub: Advertise support for subscription-options
Kim Alvefur <zash@zash.se>
parents: 9198
diff changeset
225 add_subscription = { "subscribe", "subscription-options" };
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
226 create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
227 delete = { "delete-nodes" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
228 get_items = { "retrieve-items" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
229 get_subscriptions = { "retrieve-subscriptions" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
230 node_defaults = { "retrieve-default" };
9131
d0d676b86013 pubsub.lib: Enable publish-options unconditionally
Matthew Wild <mwild1@gmail.com>
parents: 9130
diff changeset
231 publish = { "publish", "multi-items", "publish-options" };
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
232 purge = { "purge-nodes" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
233 retract = { "delete-items", "retract-items" };
9198
2ce27be5fdd1 mod_pubsub: Advertise support for node meta-data
Kim Alvefur <zash@zash.se>
parents: 9188
diff changeset
234 set_node_config = { "config-node", "meta-data" };
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
235 set_affiliation = { "modify-affiliations" };
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
236 };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
237 local service_config_feature_map = {
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
238 autocreate_on_publish = { "auto-create" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
239 };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
240
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
241 function _M.get_feature_set(service)
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
242 local supported_features = set.new();
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
243
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
244 for method, features in pairs(service_method_feature_map) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
245 if service[method] then
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
246 for _, feature in ipairs(features) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
247 if feature then
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
248 supported_features:add(feature);
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
249 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
250 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
251 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
252 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
253
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
254 for option, features in pairs(service_config_feature_map) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
255 if service.config[option] then
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
256 for _, feature in ipairs(features) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
257 if feature then
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
258 supported_features:add(feature);
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
259 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
260 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
261 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
262 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
263
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
264 for affiliation in pairs(service.config.capabilities) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
265 if affiliation ~= "none" and affiliation ~= "owner" then
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
266 supported_features:add(affiliation.."-affiliation");
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
267 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
268 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
269
9102
f3a1ecc46f20 mod_pubsub: Advertise default access model in disco
Kim Alvefur <zash@zash.se>
parents: 9096
diff changeset
270 if service.node_defaults.access_model then
f3a1ecc46f20 mod_pubsub: Advertise default access model in disco
Kim Alvefur <zash@zash.se>
parents: 9096
diff changeset
271 supported_features:add("access-"..service.node_defaults.access_model);
f3a1ecc46f20 mod_pubsub: Advertise default access model in disco
Kim Alvefur <zash@zash.se>
parents: 9096
diff changeset
272 end
f3a1ecc46f20 mod_pubsub: Advertise default access model in disco
Kim Alvefur <zash@zash.se>
parents: 9096
diff changeset
273
11854
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
274 if service.node_defaults.send_last_published_item ~= "never" then
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
275 supported_features:add("last-published");
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
276 end
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
277
9109
31bf4b3abc7f pubsub.lib: Advertise peristent-items feature when nodes and items are persisted
Matthew Wild <mwild1@gmail.com>
parents: 9102
diff changeset
278 if rawget(service.config, "itemstore") and rawget(service.config, "nodestore") then
31bf4b3abc7f pubsub.lib: Advertise peristent-items feature when nodes and items are persisted
Matthew Wild <mwild1@gmail.com>
parents: 9102
diff changeset
279 supported_features:add("persistent-items");
31bf4b3abc7f pubsub.lib: Advertise peristent-items feature when nodes and items are persisted
Matthew Wild <mwild1@gmail.com>
parents: 9102
diff changeset
280 end
31bf4b3abc7f pubsub.lib: Advertise peristent-items feature when nodes and items are persisted
Matthew Wild <mwild1@gmail.com>
parents: 9102
diff changeset
281
11803
024b44ad5651 mod_pubsub: Advertise support for 'max' as value for max_items
Kim Alvefur <zash@zash.se>
parents: 11785
diff changeset
282 if true --[[ node_metadata_form[max_items].datatype == "pubsub:integer-or-max" ]] then
024b44ad5651 mod_pubsub: Advertise support for 'max' as value for max_items
Kim Alvefur <zash@zash.se>
parents: 11785
diff changeset
283 supported_features:add("config-node-max");
024b44ad5651 mod_pubsub: Advertise support for 'max' as value for max_items
Kim Alvefur <zash@zash.se>
parents: 11785
diff changeset
284 end
024b44ad5651 mod_pubsub: Advertise support for 'max' as value for max_items
Kim Alvefur <zash@zash.se>
parents: 11785
diff changeset
285
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
286 return supported_features;
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
287 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
288
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
289 function _M.handle_disco_info_node(event, service)
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
290 local stanza, reply, node = event.stanza, event.reply, event.node;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
291 local ok, ret = service:get_nodes(stanza.attr.from);
11904
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
292 if not ok then
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
293 event.origin.send(pubsub_error_reply(stanza, ret));
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
294 return true;
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
295 end
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
296 local node_obj = ret[node];
11904
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
297 if not node_obj then
313d01cc4258 mod_pubsub: Fix traceback in disco of non-existent node (thanks Martin)
Kim Alvefur <zash@zash.se>
parents: 11882
diff changeset
298 event.origin.send(pubsub_error_reply(stanza, "item-not-found"));
11882
c3bd71227e17 mod_pubsub: Return proper errors for disco queries on nodes
Kim Alvefur <zash@zash.se>
parents: 11855
diff changeset
299 return true;
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
300 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
301 event.exists = true;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
302 reply:tag("identity", { category = "pubsub", type = "leaf" }):up();
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
303 if node_obj.config then
9038
fd053fcaf9bc mod_pubsub: Revert disco#info part from previous commit
Kim Alvefur <zash@zash.se>
parents: 9037
diff changeset
304 reply:add_child(node_metadata_form:form({
fd053fcaf9bc mod_pubsub: Revert disco#info part from previous commit
Kim Alvefur <zash@zash.se>
parents: 9037
diff changeset
305 ["pubsub#title"] = node_obj.config.title;
fd053fcaf9bc mod_pubsub: Revert disco#info part from previous commit
Kim Alvefur <zash@zash.se>
parents: 9037
diff changeset
306 ["pubsub#description"] = node_obj.config.description;
9180
cc68cb03f85e mod_pubsub: Add payload type metadata field
Kim Alvefur <zash@zash.se>
parents: 9137
diff changeset
307 ["pubsub#type"] = node_obj.config.payload_type;
10062
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
308 ["pubsub#access_model"] = node_obj.config.access_model;
6ffed67356e9 mod_pubsub: Expose pubsub#access_model and pubsub#publish_model (fixes #1387)
Kim Alvefur <zash@zash.se>
parents: 9817
diff changeset
309 ["pubsub#publish_model"] = node_obj.config.publish_model;
9038
fd053fcaf9bc mod_pubsub: Revert disco#info part from previous commit
Kim Alvefur <zash@zash.se>
parents: 9037
diff changeset
310 }, "result"));
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
311 end
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
312 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
313
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
314 function _M.handle_disco_items_node(event, service)
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
315 local stanza, reply, node = event.stanza, event.reply, event.node;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
316 local ok, ret = service:get_items(node, stanza.attr.from);
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
317 if not ok then
11882
c3bd71227e17 mod_pubsub: Return proper errors for disco queries on nodes
Kim Alvefur <zash@zash.se>
parents: 11855
diff changeset
318 event.origin.send(pubsub_error_reply(stanza, ret));
c3bd71227e17 mod_pubsub: Return proper errors for disco queries on nodes
Kim Alvefur <zash@zash.se>
parents: 11855
diff changeset
319 return true;
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
320 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
321
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
322 for _, id in ipairs(ret) do
13177
6f64542a1336 mod_pubsub: Send correct jid attribute in disco#items
Kim Alvefur <zash@zash.se>
parents: 12021
diff changeset
323 reply:tag("item", { jid = service.config.jid or module.host, name = id }):up();
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
324 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
325 event.exists = true;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
326 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
327
8334
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
328 function _M.handle_pubsub_iq(event, service)
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
329 local origin, stanza = event.origin, event.stanza;
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
330 local pubsub_tag = stanza.tags[1];
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
331 local action = pubsub_tag.tags[1];
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
332 if not action then
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
333 return origin.send(st.error_reply(stanza, "cancel", "bad-request"));
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
334 end
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
335 local prefix = "";
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
336 if pubsub_tag.attr.xmlns == xmlns_pubsub_owner then
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
337 prefix = "owner_";
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
338 end
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
339 local handler = handlers[prefix..stanza.attr.type.."_"..action.name];
8334
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
340 if handler then
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
341 handler(origin, stanza, action, service);
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
342 return true;
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
343 end
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
344 end
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
345
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
346 function handlers.get_items(origin, stanza, items, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
347 local node = items.attr.node;
9817
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
348
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
349 local requested_items = {};
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
350 for item in items:childtags("item") do
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
351 table.insert(requested_items, item.attr.id);
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
352 end
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
353 if requested_items[1] == nil then
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
354 requested_items = nil;
7aad9eb7f050 mod_pubsub: Support requests for multiple items (fixes #1305)
Kim Alvefur <zash@zash.se>
parents: 9274
diff changeset
355 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
356
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
357 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
358 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
359 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
360 end
12960
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
361
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
362 local node_obj = service.nodes[node];
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
363 if not node_obj then
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
364 origin.send(pubsub_error_reply(stanza, "item-not-found"));
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
365 return true;
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
366 end
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
367
11768
aa6ab07544c2 mod_pubsub: Add support for limiting result size #1608
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
368 local resultspec; -- TODO rsm.get()
aa6ab07544c2 mod_pubsub: Add support for limiting result size #1608
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
369 if items.attr.max_items then
aa6ab07544c2 mod_pubsub: Add support for limiting result size #1608
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
370 resultspec = { max = tonumber(items.attr.max_items) };
aa6ab07544c2 mod_pubsub: Add support for limiting result size #1608
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
371 end
aa6ab07544c2 mod_pubsub: Add support for limiting result size #1608
Kim Alvefur <zash@zash.se>
parents: 11723
diff changeset
372 local ok, results = service:get_items(node, stanza.attr.from, requested_items, resultspec);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
373 if not ok then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
374 origin.send(pubsub_error_reply(stanza, results));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
375 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
376 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
377
11715
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
378 local expose_publisher = service.config.expose_publisher;
12960
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
379 if expose_publisher == nil 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: 12636
diff changeset
380 expose_publisher = true;
31b22cc221b5 mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher
Matthew Wild <mwild1@gmail.com>
parents: 12636
diff changeset
381 end
11715
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
382
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
383 local data = st.stanza("items", { node = node });
11769
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
384 local iter, v, i = ipairs(results);
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
385 if not requested_items then
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
386 -- XXX Hack to preserve order of explicitly requested items.
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
387 iter, v, i = it.reverse(iter, v, i);
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
388 end
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
389
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
390 for _, id in iter, v, i do
11715
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
391 local item = results[id];
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
392 if not expose_publisher then
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
393 item = st.clone(item);
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
394 item.attr.publisher = nil;
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
395 end
ddd6e21e58bf mod_pubsub: Respect 'expose publisher' setting in item retrieval
Kim Alvefur <zash@zash.se>
parents: 11714
diff changeset
396 data:add_child(item);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
397 end
10090
cdcf26331b9f mod_pubsub: Eliminate dead code
Kim Alvefur <zash@zash.se>
parents: 10062
diff changeset
398 local reply = st.reply(stanza)
cdcf26331b9f mod_pubsub: Eliminate dead code
Kim Alvefur <zash@zash.se>
parents: 10062
diff changeset
399 :tag("pubsub", { xmlns = xmlns_pubsub })
cdcf26331b9f mod_pubsub: Eliminate dead code
Kim Alvefur <zash@zash.se>
parents: 10062
diff changeset
400 :add_child(data);
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
401 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
402 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
403 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
404
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
405 function handlers.get_subscriptions(origin, stanza, subscriptions, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
406 local node = subscriptions.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
407 local ok, ret = service:get_subscriptions(node, stanza.attr.from, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
408 if not ok then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
409 origin.send(pubsub_error_reply(stanza, ret));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
410 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
411 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
412 local reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
413 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
414 :tag("subscriptions");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
415 for _, sub in ipairs(ret) do
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
416 reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
417 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
418 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
419 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
420 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
421
9032
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
422 function handlers.owner_get_subscriptions(origin, stanza, subscriptions, service)
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
423 local node = subscriptions.attr.node;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
424 local ok, ret = service:get_subscriptions(node, stanza.attr.from);
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
425 if not ok then
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
426 origin.send(pubsub_error_reply(stanza, ret));
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
427 return true;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
428 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
429 local reply = st.reply(stanza)
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
430 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
431 :tag("subscriptions");
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
432 for _, sub in ipairs(ret) do
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
433 reply:tag("subscription", { node = sub.node, jid = sub.jid, subscription = 'subscribed' }):up();
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
434 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
435 origin.send(reply);
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
436 return true;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
437 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
438
9033
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
439 function handlers.owner_set_subscriptions(origin, stanza, subscriptions, service)
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
440 local node = subscriptions.attr.node;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
441 if not node then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
442 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
443 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
444 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
445 if not service:may(node, stanza.attr.from, "subscribe_other") then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
446 origin.send(pubsub_error_reply(stanza, "forbidden"));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
447 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
448 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
449
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
450 local node_obj = service.nodes[node];
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
451 if not node_obj then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
452 origin.send(pubsub_error_reply(stanza, "item-not-found"));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
453 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
454 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
455
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
456 for subscription_tag in subscriptions:childtags("subscription") do
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
457 if subscription_tag.attr.subscription == 'subscribed' then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
458 local ok, err = service:add_subscription(node, stanza.attr.from, subscription_tag.attr.jid);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
459 if not ok then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
460 origin.send(pubsub_error_reply(stanza, err));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
461 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
462 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
463 elseif subscription_tag.attr.subscription == 'none' then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
464 local ok, err = service:remove_subscription(node, stanza.attr.from, subscription_tag.attr.jid);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
465 if not ok then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
466 origin.send(pubsub_error_reply(stanza, err));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
467 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
468 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
469 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
470 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
471
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
472 local reply = st.reply(stanza);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
473 origin.send(reply);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
474 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
475 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
476
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
477 function handlers.set_create(origin, stanza, create, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
478 local node = create.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
479 local ok, ret, reply;
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
480 local config;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
481 local configure = stanza.tags[1]:get_child("configure");
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
482 if configure then
8338
30d8157391e9 mod_pubsub: Use correct variable name [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8337
diff changeset
483 local config_form = configure:get_child("x", "jabber:x:data");
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
484 if not config_form then
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
485 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform"));
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
486 return true;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
487 end
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
488 local form_data, err = node_config_form:data(config_form);
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
489 if err then
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
490 origin.send(st.error_reply(stanza, "modify", "bad-request", dataform_error_message(err)));
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
491 return true;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
492 end
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
493 config = form_data;
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
494 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
495 if node then
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
496 ok, ret = service:create(node, stanza.attr.from, config);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
497 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
498 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
499 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
500 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
501 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
502 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
503 repeat
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
504 node = uuid_generate();
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
505 ok, ret = service:create(node, stanza.attr.from, config);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
506 until ok or ret ~= "conflict";
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
507 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
508 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
509 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
510 :tag("create", { node = node });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
511 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
512 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
513 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
514 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
515 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
516 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
517 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
518
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
519 function handlers.owner_set_delete(origin, stanza, delete, service)
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
520 local node = delete.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
521
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
522 local reply;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
523 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
524 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
525 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
526 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
527 local ok, ret = service:delete(node, stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
528 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
529 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
530 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
531 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
532 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
533 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
534 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
535 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
536
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
537 function handlers.set_subscribe(origin, stanza, subscribe, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
538 local node, jid = subscribe.attr.node, subscribe.attr.jid;
8940
365b16109d95 mod_pubsub: Apply normalization to JIDs retrieved from attributes
Kim Alvefur <zash@zash.se>
parents: 8939
diff changeset
539 jid = jid_prep(jid);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
540 if not (node and jid) then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
541 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
542 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
543 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
544 local options_tag, options = stanza.tags[1]:get_child("options"), nil;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
545 if options_tag then
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
546 -- FIXME form parsing errors ignored here, why?
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
547 local err
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
548 options, err = subscribe_options_form:data(options_tag.tags[1]);
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
549 if err then
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
550 origin.send(st.error_reply(stanza, "modify", "bad-request", dataform_error_message(err)));
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
551 return true
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
552 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
553 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
554 local ok, ret = service:add_subscription(node, stanza.attr.from, jid, options);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
555 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
556 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
557 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
558 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
559 :tag("subscription", {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
560 node = node,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
561 jid = jid,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
562 subscription = "subscribed"
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
563 }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
564 if options_tag then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
565 reply:add_child(options_tag);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
566 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
567 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
568 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
569 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
570 origin.send(reply);
11854
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
571 local ok, config = service:get_node_config(node, true);
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
572 if ok and config.send_last_published_item ~= "never" then
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
573 local ok, id, item = service:get_last_item(node, jid);
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
574 if not (ok and id) then return; end
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
575 service.config.broadcaster("items", node, { [jid] = true }, item);
b605cbd5f13b mod_pubsub,mod_pep: Implement 'send_last_published_item' option #1436
Kim Alvefur <zash@zash.se>
parents: 11803
diff changeset
576 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
577 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
578
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
579 function handlers.set_unsubscribe(origin, stanza, unsubscribe, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
580 local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid;
8940
365b16109d95 mod_pubsub: Apply normalization to JIDs retrieved from attributes
Kim Alvefur <zash@zash.se>
parents: 8939
diff changeset
581 jid = jid_prep(jid);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
582 if not (node and jid) then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
583 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
584 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
585 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
586 local ok, ret = service:remove_subscription(node, stanza.attr.from, jid);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
587 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
588 if ok then
11429
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
589 reply = st.reply(stanza)
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
590 :tag("pubsub", { xmlns = xmlns_pubsub })
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
591 :tag("subscription", {
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
592 node = node,
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
593 jid = jid,
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
594 subscription = "none"
ef623d719894 mod_pubsub: Include <pubsub> with unsubscribe reply
Kim Alvefur <zash@zash.se>
parents: 11187
diff changeset
595 }):up();
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
596 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
597 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
598 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
599 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
600 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
601 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
602
9040
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
603 function handlers.get_options(origin, stanza, options, service)
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
604 local node, jid = options.attr.node, options.attr.jid;
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
605 jid = jid_prep(jid);
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
606 if not (node and jid) then
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
607 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
608 return true;
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
609 end
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
610 local ok, ret = service:get_subscription(node, stanza.attr.from, jid);
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
611 if not ok then
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
612 origin.send(pubsub_error_reply(stanza, "not-subscribed"));
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
613 return true;
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
614 end
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
615 if ret == true then ret = {} end
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
616 origin.send(st.reply(stanza)
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
617 :tag("pubsub", { xmlns = xmlns_pubsub })
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
618 :tag("options", { node = node, jid = jid })
9116
9f36f5c14545 mod_pubsub: Rename variable subscription options form to improve readability
Kim Alvefur <zash@zash.se>
parents: 9115
diff changeset
619 :add_child(subscribe_options_form:form(ret)));
9040
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
620 return true;
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
621 end
e993fad0cc62 mod_pubsub: Add support for retrieving subscription options
Kim Alvefur <zash@zash.se>
parents: 9039
diff changeset
622
9041
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
623 function handlers.set_options(origin, stanza, options, service)
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
624 local node, jid = options.attr.node, options.attr.jid;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
625 jid = jid_prep(jid);
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
626 if not (node and jid) then
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
627 origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid"));
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
628 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
629 end
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
630 local ok, ret = service:get_subscription(node, stanza.attr.from, jid);
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
631 if not ok then
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
632 origin.send(pubsub_error_reply(stanza, ret));
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
633 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
634 elseif not ret then
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
635 origin.send(pubsub_error_reply(stanza, "not-subscribed"));
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
636 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
637 end
9235
7fbcabee6df1 mod_pubsub: Preserve current subscription options if given a partial form
Kim Alvefur <zash@zash.se>
parents: 9212
diff changeset
638 local old_subopts = ret;
7fbcabee6df1 mod_pubsub: Preserve current subscription options if given a partial form
Kim Alvefur <zash@zash.se>
parents: 9212
diff changeset
639 local new_subopts, err = subscribe_options_form:data(options.tags[1], old_subopts);
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
640 if err then
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
641 origin.send(st.error_reply(stanza, "modify", "bad-request", dataform_error_message(err)));
9041
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
642 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
643 end
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
644 local ok, err = service:add_subscription(node, stanza.attr.from, jid, new_subopts);
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
645 if not ok then
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
646 origin.send(pubsub_error_reply(stanza, err));
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
647 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
648 end
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
649 origin.send(st.reply(stanza));
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
650 return true;
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
651 end
b3bc742ee188 mod_pubsub: Add support for changing subscription options
Kim Alvefur <zash@zash.se>
parents: 9040
diff changeset
652
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
653 function handlers.set_publish(origin, stanza, publish, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
654 local node = publish.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
655 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
656 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
657 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
658 end
9200
249d90ff992e pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents: 9199
diff changeset
659 local required_config = nil;
9115
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
660 local publish_options = stanza.tags[1]:get_child("publish-options");
9131
d0d676b86013 pubsub.lib: Enable publish-options unconditionally
Matthew Wild <mwild1@gmail.com>
parents: 9130
diff changeset
661 if publish_options then
9115
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
662 -- Ensure that the node configuration matches the values in publish-options
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
663 local publish_options_form = publish_options:get_child("x", "jabber:x:data");
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
664 local err;
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
665 required_config, err = node_config_form:data(publish_options_form);
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
666 if err then
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
667 origin.send(st.error_reply(stanza, "modify", "bad-request", dataform_error_message(err)));
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
668 return true
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
669 end
9115
fddebfaae7d9 pubsub.lib: Support for publish-options behind a feature flag, 'enable_publish_options'
Matthew Wild <mwild1@gmail.com>
parents: 9110
diff changeset
670 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
671 local item = publish:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
672 local id = (item and item.attr.id);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
673 if not id then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
674 id = uuid_generate();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
675 if item then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
676 item.attr.id = id;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
677 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
678 end
11714
d783716103c1 mod_pubsub: Fix inclusion of publisher (fixes #1399)
Kim Alvefur <zash@zash.se>
parents: 11631
diff changeset
679 if item then
d783716103c1 mod_pubsub: Fix inclusion of publisher (fixes #1399)
Kim Alvefur <zash@zash.se>
parents: 11631
diff changeset
680 item.attr.publisher = service.config.normalize_jid(stanza.attr.from);
d783716103c1 mod_pubsub: Fix inclusion of publisher (fixes #1399)
Kim Alvefur <zash@zash.se>
parents: 11631
diff changeset
681 end
9200
249d90ff992e pubsub.lib, util.pubsub: Move precondition checks to util.pubsub
Matthew Wild <mwild1@gmail.com>
parents: 9199
diff changeset
682 local ok, ret = service:publish(node, stanza.attr.from, id, item, required_config);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
683 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
684 if ok then
8400
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
685 if type(ok) == "string" then
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
686 id = ok;
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
687 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
688 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
689 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
690 :tag("publish", { node = node })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
691 :tag("item", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
692 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
693 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
694 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
695 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
696 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
697 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
698
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
699 function handlers.set_retract(origin, stanza, retract, service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
700 local node, notify = retract.attr.node, retract.attr.notify;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
701 notify = (notify == "1") or (notify == "true");
12636
e8934ce6ea0f util.stanza: Add method for extracting a single attribute value
Kim Alvefur <zash@zash.se>
parents: 12589
diff changeset
702 local id = retract:get_child_attr("item", nil, "id");
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
703 if not (node and id) then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
704 origin.send(pubsub_error_reply(stanza, node and "item-not-found" or "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
705 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
706 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
707 local reply, notifier;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
708 if notify then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
709 notifier = st.stanza("retract", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
710 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
711 local ok, ret = service:retract(node, stanza.attr.from, id, notifier);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
712 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
713 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
714 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
715 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
716 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
717 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
718 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
719 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
720
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
721 function handlers.owner_set_purge(origin, stanza, purge, service)
10276
4e4ce7400b39 mod_pubsub: Remove the unwanted check for @notify on <purge/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10090
diff changeset
722 local node = purge.attr.node;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
723 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
724 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
725 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
726 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
727 end
10276
4e4ce7400b39 mod_pubsub: Remove the unwanted check for @notify on <purge/>.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10090
diff changeset
728 local ok, ret = service:purge(node, stanza.attr.from, true);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
729 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
730 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
731 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
732 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
733 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
734 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
735 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
736 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
737
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
738 function handlers.owner_get_configure(origin, stanza, config, service)
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
739 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
740 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
741 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
742 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
743 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
744
9120
01fc8ba0a7fa mod_pubsub: Use util.pubsub API for retrieving node config instead
Kim Alvefur <zash@zash.se>
parents: 9116
diff changeset
745 local ok, node_config = service:get_node_config(node, stanza.attr.from);
01fc8ba0a7fa mod_pubsub: Use util.pubsub API for retrieving node config instead
Kim Alvefur <zash@zash.se>
parents: 9116
diff changeset
746 if not ok then
01fc8ba0a7fa mod_pubsub: Use util.pubsub API for retrieving node config instead
Kim Alvefur <zash@zash.se>
parents: 9116
diff changeset
747 origin.send(pubsub_error_reply(stanza, node_config));
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
748 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
749 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
750
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
751 local reply = st.reply(stanza)
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
752 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
753 :tag("configure", { node = node })
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
754 :add_child(node_config_form:form(node_config));
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
755 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
756 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
757 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
758
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
759 function handlers.owner_set_configure(origin, stanza, config, service)
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
760 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
761 if not node then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
762 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
763 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
764 end
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
765 if not service:may(node, stanza.attr.from, "configure") then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
766 origin.send(pubsub_error_reply(stanza, "forbidden"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
767 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
768 end
8317
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
769 local config_form = config:get_child("x", "jabber:x:data");
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
770 if not config_form then
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
771 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform"));
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
772 return true;
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
773 end
9122
a69dc9c729ec mod_pubsub: Pass the current values to dataforms
Kim Alvefur <zash@zash.se>
parents: 9120
diff changeset
774 local ok, old_config = service:get_node_config(node, stanza.attr.from);
a69dc9c729ec mod_pubsub: Pass the current values to dataforms
Kim Alvefur <zash@zash.se>
parents: 9120
diff changeset
775 if not ok then
a69dc9c729ec mod_pubsub: Pass the current values to dataforms
Kim Alvefur <zash@zash.se>
parents: 9120
diff changeset
776 origin.send(pubsub_error_reply(stanza, old_config));
a69dc9c729ec mod_pubsub: Pass the current values to dataforms
Kim Alvefur <zash@zash.se>
parents: 9120
diff changeset
777 return true;
a69dc9c729ec mod_pubsub: Pass the current values to dataforms
Kim Alvefur <zash@zash.se>
parents: 9120
diff changeset
778 end
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
779 local new_config, err = node_config_form:data(config_form, old_config);
9247
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
780 if err then
26854d7a4947 mod_pubsub: Fix dataforms error handling
Kim Alvefur <zash@zash.se>
parents: 9245
diff changeset
781 origin.send(st.error_reply(stanza, "modify", "bad-request", dataform_error_message(err)));
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
782 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
783 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
784 local ok, err = service:set_node_config(node, stanza.attr.from, new_config);
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
785 if not ok then
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
786 origin.send(pubsub_error_reply(stanza, err));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
787 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
788 end
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
789 origin.send(st.reply(stanza));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
790 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
791 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
792
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
793 function handlers.owner_get_default(origin, stanza, default, service) -- luacheck: ignore 212/default
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
794 local reply = st.reply(stanza)
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
795 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
6447
8c2dc2ac5a40 mod_pubsub: Fix retreival of node config defaults
Kim Alvefur <zash@zash.se>
parents: 6446
diff changeset
796 :tag("default")
9244
b3b156bd9914 mod_pubsub: Use field mapping in util.dataforms
Kim Alvefur <zash@zash.se>
parents: 9235
diff changeset
797 :add_child(node_config_form:form(service.node_defaults));
6841
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
798 origin.send(reply);
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
799 return true;
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
800 end
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
801
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
802 function handlers.owner_get_affiliations(origin, stanza, affiliations, service)
8933
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
803 local node = affiliations.attr.node;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
804 if not node then
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
805 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
806 return true;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
807 end
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
808 if not service:may(node, stanza.attr.from, "set_affiliation") then
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
809 origin.send(pubsub_error_reply(stanza, "forbidden"));
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
810 return true;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
811 end
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
812
8934
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
813 local node_obj = service.nodes[node];
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
814 if not node_obj then
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
815 origin.send(pubsub_error_reply(stanza, "item-not-found"));
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
816 return true;
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
817 end
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
818
8933
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
819 local reply = st.reply(stanza)
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
820 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
821 :tag("affiliations", { node = node });
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
822
8935
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
823 for jid, affiliation in pairs(node_obj.affiliations) do
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
824 reply:tag("affiliation", { jid = jid, affiliation = affiliation }):up();
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
825 end
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
826
8933
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
827 origin.send(reply);
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
828 return true;
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
829 end
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
830
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
831 function handlers.owner_set_affiliations(origin, stanza, affiliations, service)
8937
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
832 local node = affiliations.attr.node;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
833 if not node then
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
834 origin.send(pubsub_error_reply(stanza, "nodeid-required"));
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
835 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
836 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
837 if not service:may(node, stanza.attr.from, "set_affiliation") then
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
838 origin.send(pubsub_error_reply(stanza, "forbidden"));
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
839 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
840 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
841
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
842 local node_obj = service.nodes[node];
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
843 if not node_obj then
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
844 origin.send(pubsub_error_reply(stanza, "item-not-found"));
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
845 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
846 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
847
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
848 for affiliation_tag in affiliations:childtags("affiliation") do
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
849 local jid = affiliation_tag.attr.jid;
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
850 local affiliation = affiliation_tag.attr.affiliation;
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
851
8940
365b16109d95 mod_pubsub: Apply normalization to JIDs retrieved from attributes
Kim Alvefur <zash@zash.se>
parents: 8939
diff changeset
852 jid = jid_prep(jid);
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
853 if affiliation == "none" then affiliation = nil; end
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
854
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
855 local ok, err = service:set_affiliation(node, stanza.attr.from, jid, affiliation);
8939
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
856 if not ok then
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
857 -- FIXME Incomplete error handling,
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
858 -- see XEP 60 8.9.2.4 Multiple Simultaneous Modifications
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
859 origin.send(pubsub_error_reply(stanza, err));
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
860 return true;
849c4683eaa0 mod_pubsub: Handle :set_affiliation errors (not completely in line with the XEP)
Kim Alvefur <zash@zash.se>
parents: 8938
diff changeset
861 end
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
862 end
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
863
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
864 local reply = st.reply(stanza);
8937
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
865 origin.send(reply);
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
866 return true;
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
867 end
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
868
11714
d783716103c1 mod_pubsub: Fix inclusion of publisher (fixes #1399)
Kim Alvefur <zash@zash.se>
parents: 11631
diff changeset
869 local function create_encapsulating_item(id, payload, publisher)
d783716103c1 mod_pubsub: Fix inclusion of publisher (fixes #1399)
Kim Alvefur <zash@zash.se>
parents: 11631
diff changeset
870 local item = st.stanza("item", { id = id, publisher = publisher, xmlns = xmlns_pubsub });
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
871 item:add_child(payload);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
872 return item;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
873 end
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
874
11631
6641ca266d94 mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents: 11429
diff changeset
875 local function archive_itemstore(archive, max_items, user, node)
6641ca266d94 mod_pubsub,mod_pep: Support "max" as 'pubsub#max_items'
Kim Alvefur <zash@zash.se>
parents: 11429
diff changeset
876 module:log("debug", "Creation of archive itemstore for node %s with limit %d", node, max_items);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
877 local get_set = {};
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
878 function get_set:items() -- luacheck: ignore 212/self
8324
58d228da618f mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents: 8323
diff changeset
879 local data, err = archive:find(user, {
9005
7203a1b65d1b mod_pubsub: Cache only max_items to avoid holding reference to possibly outdated config
Kim Alvefur <zash@zash.se>
parents: 8981
diff changeset
880 limit = tonumber(max_items);
8324
58d228da618f mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents: 8323
diff changeset
881 reverse = true;
58d228da618f mod_pubsub: Limit number of items to fetch from archive storage to pubsub#max_items to prevent unbounded query (thanks Martin and lovetox)
Kim Alvefur <zash@zash.se>
parents: 8323
diff changeset
882 });
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
883 if not data then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
884 module:log("error", "Unable to get items: %s", err);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
885 return true;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
886 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
887 module:log("debug", "Listed items %s", data);
11769
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
888 return function()
10554
e1de29c41259 mod_pubsub: Ignore an unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10356
diff changeset
889 -- luacheck: ignore 211/when
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
890 local id, payload, when, publisher = data();
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
891 if id == nil then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
892 return;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
893 end
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
894 local item = create_encapsulating_item(id, payload, publisher);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
895 return id, item;
11769
071715a18394 mod_pubsub: Move reversal of item order in <items>
Kim Alvefur <zash@zash.se>
parents: 11768
diff changeset
896 end;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
897 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
898 function get_set:get(key) -- luacheck: ignore 212/self
8219
2e68ae095645 mod_pubsub: Store data in users store, node in 'with' metadata field
Kim Alvefur <zash@zash.se>
parents: 8218
diff changeset
899 local data, err = archive:find(user, {
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
900 key = key;
8302
4852def7dc49 mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents: 8301
diff changeset
901 -- Get the last item with that key, if the archive doesn't deduplicate
4852def7dc49 mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents: 8301
diff changeset
902 reverse = true,
4852def7dc49 mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents: 8301
diff changeset
903 limit = 1;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
904 });
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
905 if not data then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
906 module:log("error", "Unable to get item: %s", err);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
907 return nil, err;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
908 end
8296
e23328adca25 mod_pubsub: Remove workaround for SQL issue (fixed in becb593ed86d)
Kim Alvefur <zash@zash.se>
parents: 8295
diff changeset
909 local id, payload, when, publisher = data();
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
910 module:log("debug", "Get item %s (published at %s by %s)", id, when, publisher);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
911 if id == nil then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
912 return nil;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
913 end
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
914 return create_encapsulating_item(id, payload, publisher);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
915 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
916 function get_set:set(key, value) -- luacheck: ignore 212/self
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
917 local data, err;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
918 if value ~= nil then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
919 local publisher = value.attr.publisher;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
920 local payload = value.tags[1];
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8298
diff changeset
921 data, err = archive:append(user, key, payload, time_now(), publisher);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
922 else
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8298
diff changeset
923 data, err = archive:delete(user, { key = key; });
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
924 end
9072
9603a6a1ec85 mod_pubsub: Enforce max_items on insertion
Kim Alvefur <zash@zash.se>
parents: 9041
diff changeset
925 -- TODO archive support for maintaining maximum items
9603a6a1ec85 mod_pubsub: Enforce max_items on insertion
Kim Alvefur <zash@zash.se>
parents: 9041
diff changeset
926 archive:delete(user, {
9603a6a1ec85 mod_pubsub: Enforce max_items on insertion
Kim Alvefur <zash@zash.se>
parents: 9041
diff changeset
927 truncate = max_items;
9603a6a1ec85 mod_pubsub: Enforce max_items on insertion
Kim Alvefur <zash@zash.se>
parents: 9041
diff changeset
928 });
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
929 if not data then
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
930 module:log("error", "Unable to set item: %s", err);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
931 return nil, err;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
932 end
8217
5f4e0d67b82a util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents: 8216
diff changeset
933 return data;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
934 end
8301
e2ab440a3437 mod_pubsub: Ignore unused 'self' since the data used is an upvalue [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8300
diff changeset
935 function get_set:clear() -- luacheck: ignore 212/self
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8298
diff changeset
936 return archive:delete(user);
8298
dd9fa511494a mod_pubsub: Add method to clear data from a simple_itemstore
Kim Alvefur <zash@zash.se>
parents: 8296
diff changeset
937 end
8825
7270258fec77 mod_pubsup: Ignore unused 'self' argument [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8822
diff changeset
938 function get_set:resize(size) -- luacheck: ignore 212/self
9006
935e5ca43792 mod_pubsub: Update max_items on resize (fixes #1082)
Kim Alvefur <zash@zash.se>
parents: 9005
diff changeset
939 max_items = size;
8399
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
940 return archive:delete(user, {
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
941 truncate = size;
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
942 });
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
943 end
9206
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9200
diff changeset
944 function get_set:head()
33ee40dc3e25 Pubsub: Add tests for :get_last_item() and fix for non-persistent nodes
Matthew Wild <mwild1@gmail.com>
parents: 9200
diff changeset
945 -- This should conveniently return the most recent item
8375
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
946 local item = self:get(nil);
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
947 if item then
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
948 return item.attr.id, item;
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
949 end
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
950 end
11186
15fe9f0bb483 mod_pubsub: Don't set store as metatable
Kim Alvefur <zash@zash.se>
parents: 10554
diff changeset
951 return get_set;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
952 end
8318
d0a7fc7614de mod_pubsub, mod_pep_plus: Rename simple_itemstore to reflect that it's based on archive storage
Kim Alvefur <zash@zash.se>
parents: 8317
diff changeset
953 _M.archive_itemstore = archive_itemstore;
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
954
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
955 return _M;