Annotate

plugins/mod_pubsub/pubsub.lib.lua @ 9038:fd053fcaf9bc

mod_pubsub: Revert disco#info part from previous commit
author Kim Alvefur <zash@zash.se>
date Sat, 14 Jul 2018 18:49:12 +0200
parent 9037:e3c8274427d3
child 9039:0124e5ec1556
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
1 local t_unpack = table.unpack or unpack; -- luacheck: ignore 113
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
8940
365b16109d95 mod_pubsub: Apply normalization to JIDs retrieved from attributes
Kim Alvefur <zash@zash.se>
parents: 8939
diff changeset
4 local jid_prep = require "util.jid".prep;
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
5 local set = require "util.set";
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 local st = require "util.stanza";
8325
9a845e9e9cbf mod_pubsub: Fix typo in import
Kim Alvefur <zash@zash.se>
parents: 8324
diff changeset
7 local it = require "util.iterators";
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8 local uuid_generate = require "util.uuid".generate;
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
9 local dataform = require"util.dataforms".new;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11 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
12 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
13 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
14
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 local _M = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17 local handlers = {};
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 _M.handlers = handlers;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 local pubsub_errors = {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 ["conflict"] = { "cancel", "conflict" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 ["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
23 ["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
24 ["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
25 ["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
26 ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" };
6473
7c8f58d2b331 Merge 0.9->0.10
Matthew Wild <mwild1@gmail.com>
parents: 6448
diff changeset
27 ["forbidden"] = { "auth", "forbidden" };
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
28 ["not-allowed"] = { "cancel", "not-allowed" };
8953
19cbe80df9c8 mod_pubsub: Make pubsub.lib aware of internal-server-error condition
Kim Alvefur <zash@zash.se>
parents: 8940
diff changeset
29 ["internal-server-error"] = { "wait", "internal-server-error" };
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 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
32 local e = pubsub_errors[error];
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
33 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
34 if e[4] then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35 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
36 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
37 return reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 _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
40
9037
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
41 -- util.pubsub is meant to be agnostic to XEP-0060
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
42 local function config_to_xep0060(node_config)
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
43 return {
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
44 ["pubsub#title"] = node_config["title"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
45 ["pubsub#description"] = node_config["description"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
46 ["pubsub#max_items"] = tostring(node_config["max_items"]);
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
47 ["pubsub#persist_items"] = node_config["persist_items"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
48 ["pubsub#notification_type"] = node_config["notification_type"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
49 ["pubsub#include_body"] = node_config["include_body"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
50 }
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
51 end
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
52
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
53 local function config_from_xep0060(config)
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
54 return {
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
55 ["title"] = config["pubsub#title"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
56 ["description"] = config["pubsub#description"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
57 ["max_items"] = tonumber(config["pubsub#max_items"]);
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
58 ["persist_items"] = config["pubsub#persist_items"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
59 ["notification_type"] = config["pubsub#notification_type"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
60 ["include_body"] = config["pubsub#include_body"];
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
61 }
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
62 end
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
63
7358
d0390bc9c5d1 mod_pubsub: Don’t require util.dataforms twice
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6841
diff changeset
64 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
65 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
66 type = "hidden";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
67 name = "FORM_TYPE";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
68 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
69 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
70 {
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
71 type = "text-single";
8979
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
72 name = "pubsub#title";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
73 label = "Title";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
74 };
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
75 {
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
76 type = "text-single";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
77 name = "pubsub#description";
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
78 label = "Description";
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 {
6897b2e18bdf mod_pubsub: Support configurable title and description fields
Kim Alvefur <zash@zash.se>
parents: 8978
diff changeset
81 type = "text-single";
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
82 name = "pubsub#max_items";
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
83 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
84 };
8320
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
85 {
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
86 type = "boolean";
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
87 name = "pubsub#persist_items";
fe5eaf4ed631 mod_pep_plus: Make node persistence configurable via pubsub#persist_items
Kim Alvefur <zash@zash.se>
parents: 8318
diff changeset
88 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
89 };
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
90 {
8815
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
91 type = "boolean";
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
92 name = "pubsub#include_body";
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
93 label = "Receive message body in addition to payload?";
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
94 };
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
95 {
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
96 type = "list-single";
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
97 name = "pubsub#notification_type";
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
98 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
99 options = {
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8400
diff changeset
100 { 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
101 { 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
102 };
8822
4afa77e0d2b0 mod_pubsub: Fix syntax error
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
103 };
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
104 };
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
105
8826
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
106 local options_form = dataform {
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
107 {
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
108 type = "hidden";
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
109 name = "FORM_TYPE";
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
110 value = "http://jabber.org/protocol/pubsub#subscribe_options";
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
111 }
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
112 -- No options yet. File a feature request ;)
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
113 };
d614003a82c1 mod_pubsub: Add support for parsing subscription options form (no options supported yet)
Kim Alvefur <zash@zash.se>
parents: 8825
diff changeset
114
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
115 local node_metadata_form = dataform {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
116 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
117 type = "hidden";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
118 name = "FORM_TYPE";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
119 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
120 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
121 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
122 type = "text-single";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
123 name = "pubsub#title";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
124 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
125 {
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
126 type = "text-single";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
127 name = "pubsub#description";
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
128 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
129 };
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
130
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
131 local service_method_feature_map = {
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
132 add_subscription = { "subscribe" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
133 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
134 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
135 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
136 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
137 node_defaults = { "retrieve-default" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
138 publish = { "publish" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
139 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
140 retract = { "delete-items", "retract-items" };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
141 set_node_config = { "config-node" };
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
142 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
143 };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
144 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
145 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
146 };
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
147
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
148 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
149 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
150
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
151 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
152 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
153 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
154 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
155 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
156 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
157 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
158 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
159 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
160
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
161 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
162 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
163 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
164 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
165 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
166 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
167 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
168 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
169 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
170
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
171 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
172 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
173 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
174 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
175 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
176
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
177 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
178 end
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8338
diff changeset
179
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
180 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
181 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
182 local ok, ret = service:get_nodes(stanza.attr.from);
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
183 local node_obj = ret[node];
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
184 if not ok or not node_obj then
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
185 return;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
186 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
187 event.exists = true;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
188 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
189 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
190 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
191 ["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
192 ["pubsub#description"] = node_obj.config.description;
fd053fcaf9bc mod_pubsub: Revert disco#info part from previous commit
Kim Alvefur <zash@zash.se>
parents: 9037
diff changeset
193 }, "result"));
8981
b6cb0a8f75b1 mod_pubsub: Advertise title and description in disco#info
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
194 end
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
195 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
196
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
197 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
198 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
199 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
200 if not ok then
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
201 return;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
202 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
203
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
204 for _, id in ipairs(ret) do
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
205 reply:tag("item", { jid = module.host, name = id }):up();
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
206 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
207 event.exists = true;
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
208 end
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8979
diff changeset
209
8334
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
210 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
211 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
212 local pubsub_tag = stanza.tags[1];
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
213 local action = pubsub_tag.tags[1];
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
214 if not action then
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
215 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
216 end
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
217 local prefix = "";
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
218 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
219 prefix = "owner_";
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
220 end
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
221 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
222 if handler then
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
223 handler(origin, stanza, action, service);
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
224 return true;
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
225 end
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
226 end
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8333
diff changeset
227
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
228 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
229 local node = items.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
230 local item = items:get_child("item");
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
231 local item_id = item and item.attr.id;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
232
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
233 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
234 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
235 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
236 end
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
237 local ok, results = service:get_items(node, stanza.attr.from, item_id);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
238 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
239 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
240 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
241 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
242
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
243 local data = st.stanza("items", { node = node });
5851
cdcfd93e2f43 mod_pubsub, util.pubsub: Keep track of the order of items
Kim Alvefur <zash@zash.se>
parents: 5626
diff changeset
244 for _, id in ipairs(results) do
cdcfd93e2f43 mod_pubsub, util.pubsub: Keep track of the order of items
Kim Alvefur <zash@zash.se>
parents: 5626
diff changeset
245 data:add_child(results[id]);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
246 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
247 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
248 if data then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
249 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
250 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
251 :add_child(data);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
252 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
253 reply = pubsub_error_reply(stanza, "item-not-found");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
254 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
255 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
256 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
257 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
258
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
259 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
260 local node = subscriptions.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
261 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
262 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
263 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
264 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
265 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
266 local reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
267 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
268 :tag("subscriptions");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
269 for _, sub in ipairs(ret) do
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
270 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
271 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
272 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
273 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
274 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275
9032
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
276 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
277 local node = subscriptions.attr.node;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
278 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
279 if not ok then
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
280 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
281 return true;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
282 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
283 local reply = st.reply(stanza)
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
284 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
285 :tag("subscriptions");
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
286 for _, sub in ipairs(ret) do
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
287 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
288 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
289 origin.send(reply);
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
290 return true;
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
291 end
029e1e18d65c mod_pubsub: Add support for owner subscription retrieval
Kim Alvefur <zash@zash.se>
parents: 9006
diff changeset
292
9033
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
293 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
294 local node = subscriptions.attr.node;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
295 if not node then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
296 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
297 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
298 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
299 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
300 origin.send(pubsub_error_reply(stanza, "forbidden"));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
301 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
302 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
303
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
304 local node_obj = service.nodes[node];
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
305 if not node_obj then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
306 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
307 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
308 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
309
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
310 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
311 if subscription_tag.attr.subscription == 'subscribed' then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
312 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
313 if not ok then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
314 origin.send(pubsub_error_reply(stanza, err));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
315 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
316 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
317 elseif subscription_tag.attr.subscription == 'none' then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
318 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
319 if not ok then
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
320 origin.send(pubsub_error_reply(stanza, err));
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
321 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
322 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
323 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
324 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
325
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
326 local reply = st.reply(stanza);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
327 origin.send(reply);
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
328 return true;
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
329 end
f1b6efd5b379 mod_pubsub: Add support for modifying subscriptions
Kim Alvefur <zash@zash.se>
parents: 9032
diff changeset
330
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
331 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
332 local node = create.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
333 local ok, ret, reply;
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
334 local config;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
335 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
336 if configure then
8338
30d8157391e9 mod_pubsub: Use correct variable name [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8337
diff changeset
337 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
338 if not config_form then
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
339 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
340 return true;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
341 end
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
342 local form_data, err = node_config_form:data(config_form);
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
343 if not form_data then
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
344 origin.send(st.error_reply(stanza, "modify", "bad-request", err));
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
345 return true;
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
346 end
9037
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
347 config = config_from_xep0060(form_data);
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
348 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
349 if node then
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
350 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
351 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
352 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
353 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
354 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
355 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
356 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
357 repeat
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
358 node = uuid_generate();
8337
dc4ea43ac463 mod_pubsub: Add support for Create and Configure
Kim Alvefur <zash@zash.se>
parents: 8336
diff changeset
359 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
360 until ok or ret ~= "conflict";
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
361 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
362 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
363 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
364 :tag("create", { node = node });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
365 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
366 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
367 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
368 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
369 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
370 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
371 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
372
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
373 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
374 local node = delete.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
375
8210
352d605b1178 mod_pubsub: Fix a few warnings [luacheck]
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7358
diff changeset
376 local reply;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
377 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
378 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
379 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
380 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
381 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
382 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
383 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
384 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
385 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
386 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
387 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
388 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
389 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
390
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
391 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
392 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
393 jid = jid_prep(jid);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
394 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
395 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
396 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
397 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
398 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
399 if options_tag then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
400 options = options_form:data(options_tag.tags[1]);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
401 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
402 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
403 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
404 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
405 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
406 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
407 :tag("subscription", {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
408 node = node,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
409 jid = jid,
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
410 subscription = "subscribed"
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
411 }):up();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
412 if options_tag then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
413 reply:add_child(options_tag);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
414 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
415 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
416 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
417 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
418 origin.send(reply);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
419 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
420
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
421 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
422 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
423 jid = jid_prep(jid);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
424 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
425 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
426 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
427 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
428 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
429 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
430 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
431 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
432 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
433 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
434 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
435 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
436 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
437 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
438
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
439 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
440 local node = publish.attr.node;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
441 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
442 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
443 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
444 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
445 local item = publish:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
446 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
447 if not id then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
448 id = uuid_generate();
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
449 if item then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
450 item.attr.id = id;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
451 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
452 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
453 local ok, ret = service:publish(node, stanza.attr.from, id, item);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
454 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
455 if ok then
8400
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
456 if type(ok) == "string" then
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
457 id = ok;
518b56d806bd mod_pubsub: Allow itemstore to override item ids
Kim Alvefur <zash@zash.se>
parents: 8399
diff changeset
458 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
459 reply = st.reply(stanza)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
460 :tag("pubsub", { xmlns = xmlns_pubsub })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
461 :tag("publish", { node = node })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
462 :tag("item", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
463 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
464 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
465 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
466 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
467 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
468 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
469
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
470 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
471 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
472 notify = (notify == "1") or (notify == "true");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
473 local item = retract:get_child("item");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
474 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
475 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
476 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
477 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
478 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
479 local reply, notifier;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
480 if notify then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
481 notifier = st.stanza("retract", { id = id });
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
482 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
483 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
484 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
485 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
486 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
487 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
488 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
489 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
490 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
491 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
492
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
493 function handlers.owner_set_purge(origin, stanza, purge, service)
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
494 local node, notify = purge.attr.node, purge.attr.notify;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
495 notify = (notify == "1") or (notify == "true");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
496 local reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
497 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
498 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
499 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
500 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
501 local ok, ret = service:purge(node, stanza.attr.from, notify);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
502 if ok then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
503 reply = st.reply(stanza);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
504 else
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
505 reply = pubsub_error_reply(stanza, ret);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
506 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
507 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
508 return true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
509 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
510
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
511 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
512 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
513 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
514 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
515 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
516 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
517
6445
f1ad3923368c pubsub.lib: Fix actor in configure
Kim Alvefur <zash@zash.se>
parents: 6441
diff changeset
518 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
519 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
520 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
521 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
522
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
523 local node_obj = service.nodes[node];
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
524 if not node_obj 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
525 origin.send(pubsub_error_reply(stanza, "item-not-found"));
be87ab2d611c plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
Kim Alvefur <zash@zash.se>
parents: 6473
diff changeset
526 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
527 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
528
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8327
diff changeset
529 local node_config = node_obj.config;
9037
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
530 local pubsub_form_data = config_to_xep0060(node_config);
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
531 local reply = st.reply(stanza)
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
532 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
533 :tag("configure", { node = node })
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8327
diff changeset
534 :add_child(node_config_form:form(pubsub_form_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
535 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
536 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
537 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
538
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
539 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
540 local node = config.attr.node;
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
541 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
542 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
543 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
544 end
6446
011ca9b88179 mod_pubsub: Move node config form into pubsub.lib (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 6445
diff changeset
545 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
546 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
547 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
548 end
8317
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
549 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
550 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
551 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
552 return true;
ff57b3cc5a8e mod_pubsub: Make sure that a dataform is given to configure
Kim Alvefur <zash@zash.se>
parents: 8308
diff changeset
553 end
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8327
diff changeset
554 local form_data, err = node_config_form:data(config_form);
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8327
diff changeset
555 if not form_data 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
556 origin.send(st.error_reply(stanza, "modify", "bad-request", 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
557 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
558 end
9037
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
559 local new_config = config_from_xep0060(form_data);
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
560 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
561 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
562 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
563 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
564 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
565 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
566 return true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
567 end
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 5851
diff changeset
568
8336
587305c0ff85 mod_pubsub: Fix namespace conflict with the pubsub#owner namespace
Kim Alvefur <zash@zash.se>
parents: 8334
diff changeset
569 function handlers.owner_get_default(origin, stanza, default, service) -- luacheck: ignore 212/default
9037
e3c8274427d3 mod_pubsub: Refactor translation to/from XEP-0060-specific node configuration format
Kim Alvefur <zash@zash.se>
parents: 9033
diff changeset
570 local pubsub_form_data = config_to_xep0060(service.node_defaults);
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
571 local reply = st.reply(stanza)
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
572 :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
573 :tag("default")
8333
2abbb01cd756 pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
Kim Alvefur <zash@zash.se>
parents: 8327
diff changeset
574 :add_child(node_config_form:form(pubsub_form_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
575 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
576 return true;
6441
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
577 end
bcb1ea9047d3 mod_pubsub: Add support for requesting default node configuration
Kim Alvefur <zash@zash.se>
parents: 6438
diff changeset
578
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
579 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
580 local node = affiliations.attr.node;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
581 if not node then
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
582 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
583 return true;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
584 end
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
585 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
586 origin.send(pubsub_error_reply(stanza, "forbidden"));
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
587 return true;
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
588 end
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
589
8934
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
590 local node_obj = service.nodes[node];
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
591 if not node_obj then
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
592 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
593 return true;
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
594 end
365bcf899093 mod_pubsub: Retrieve the node object
Kim Alvefur <zash@zash.se>
parents: 8933
diff changeset
595
8933
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
596 local reply = st.reply(stanza)
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
597 :tag("pubsub", { xmlns = xmlns_pubsub_owner })
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
598 :tag("affiliations", { node = node });
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
599
8935
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
600 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
601 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
602 end
a825ef6de45a mod_pubsub: Add the list of affiliations to reply
Kim Alvefur <zash@zash.se>
parents: 8934
diff changeset
603
8933
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
604 origin.send(reply);
6d3ecf9e8277 mod_pubsub: Boilerplate checks for affiliation retrieval
Kim Alvefur <zash@zash.se>
parents: 8932
diff changeset
605 return true;
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
606 end
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
607
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
608 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
609 local node = affiliations.attr.node;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
610 if not node then
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
611 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
612 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
613 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
614 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
615 origin.send(pubsub_error_reply(stanza, "forbidden"));
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
616 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
617 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
618
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
619 local node_obj = service.nodes[node];
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
620 if not node_obj then
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
621 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
622 return true;
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
623 end
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
624
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
625 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
626 local jid = affiliation_tag.attr.jid;
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
627 local affiliation = affiliation_tag.attr.affiliation;
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
628
8940
365b16109d95 mod_pubsub: Apply normalization to JIDs retrieved from attributes
Kim Alvefur <zash@zash.se>
parents: 8939
diff changeset
629 jid = jid_prep(jid);
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
630 if affiliation == "none" then affiliation = nil; end
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
631
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
632 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
633 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
634 -- 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
635 -- 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
636 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
637 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
638 end
8938
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
639 end
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
640
384ef9732b81 mod_pubsub: Support for setting affiliations (#622)
Kim Alvefur <zash@zash.se>
parents: 8937
diff changeset
641 local reply = st.reply(stanza);
8937
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
642 origin.send(reply);
0ae46e6ea647 mod_pubsub: Add boilerplate for changing affiliations
Kim Alvefur <zash@zash.se>
parents: 8935
diff changeset
643 return true;
8932
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
644 end
12a9731aef0b mod_pubsub: Add stubs for affiliation handling
Kim Alvefur <zash@zash.se>
parents: 8826
diff changeset
645
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
646 local function create_encapsulating_item(id, payload)
8216
d80233ca006d mod_pubsub: Pass xmlns correctly
Kim Alvefur <zash@zash.se>
parents: 8213
diff changeset
647 local item = st.stanza("item", { id = id, 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
648 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
649 return item;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
650 end
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
651
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
652 local function archive_itemstore(archive, config, user, node)
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
653 module:log("debug", "Creation of itemstore for node %s with config %s", node, config);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
654 local get_set = {};
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
655 local max_items = config["max_items"];
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
656 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
657 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
658 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
659 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
660 });
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
661 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
662 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
663 return true;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
664 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
665 module:log("debug", "Listed items %s", data);
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
666 return it.reverse(function()
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
667 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
668 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
669 return;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
670 end
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
671 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
672 return id, item;
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
673 end);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
674 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
675 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
676 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
677 key = key;
8302
4852def7dc49 mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents: 8301
diff changeset
678 -- 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
679 reverse = true,
4852def7dc49 mod_pubsub: Workaround some storage modules without archive key deduplication
Kim Alvefur <zash@zash.se>
parents: 8301
diff changeset
680 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
681 });
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
682 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
683 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
684 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
685 end
8296
e23328adca25 mod_pubsub: Remove workaround for SQL issue (fixed in becb593ed86d)
Kim Alvefur <zash@zash.se>
parents: 8295
diff changeset
686 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
687 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
688 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
689 return nil;
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
690 end
8327
0b561f8bc790 mod_pubsub: Remove expose_publisher argument since it is handled in broadcaster
Kim Alvefur <zash@zash.se>
parents: 8325
diff changeset
691 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
692 end
8308
ab189d3f55d1 mod_pubsub: Remove use of non-existent fields
Kim Alvefur <zash@zash.se>
parents: 8302
diff changeset
693 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
694 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
695 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
696 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
697 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
698 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
699 else
8300
7759eb130938 mod_pep_plus, mod_pubsub: Store node content in separate archive stores
Kim Alvefur <zash@zash.se>
parents: 8298
diff changeset
700 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
701 end
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
702 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
703 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
704 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
705 end
8217
5f4e0d67b82a util.pubsub: Catch overriden id from storage
Kim Alvefur <zash@zash.se>
parents: 8216
diff changeset
706 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
707 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
708 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
709 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
710 end
8825
7270258fec77 mod_pubsup: Ignore unused 'self' argument [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8822
diff changeset
711 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
712 max_items = size;
8399
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
713 return archive:delete(user, {
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
714 truncate = size;
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
715 });
07443fe9df5b mod_pubsub/archive_itemstore: Support resize operation
Kim Alvefur <zash@zash.se>
parents: 8375
diff changeset
716 end
8375
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
717 function get_set:tail()
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
718 -- This should conveniently return the last item
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
719 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
720 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
721 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
722 end
e2037634cdd9 mod_pubsub: Add a tail method (like util.cache) to archive_itemstore
Kim Alvefur <zash@zash.se>
parents: 8374
diff changeset
723 end
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
724 return setmetatable(get_set, archive);
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
725 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
726 _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
727
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
728 return _M;