Annotate

plugins/mod_pubsub/mod_pubsub.lua @ 8210:352d605b1178

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