Annotate

plugins/mod_pubsub/mod_pubsub.lua @ 6438:b1c40054b59d

mod_pubsub: Add support for node configuration
author Kim Alvefur <zash@zash.se>
date Sun, 28 Sep 2014 01:46:17 +0200
parent 6434:382e03a40dd2
child 6440:9619809bf50b
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);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 local pubsub_disco_name = module:get_option("name");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 if type(pubsub_disco_name) ~= "string" then pubsub_disco_name = "Prosody PubSub Service"; end
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 local pubsub_error_reply = lib_pubsub.pubsub_error_reply;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
21 module:depends("disco");
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
22 module:add_identity("pubsub", "service", pubsub_disco_name);
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
23 module:add_feature("http://jabber.org/protocol/pubsub");
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
24
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 function handle_pubsub_iq(event)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 local origin, stanza = event.origin, event.stanza;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 local pubsub = stanza.tags[1];
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 local action = pubsub.tags[1];
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 if not action then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 return origin.send(st.error_reply(stanza, "cancel", "bad-request"));
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
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 function simple_broadcast(kind, node, jids, item)
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
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 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
45 :tag("event", { xmlns = xmlns_pubsub_event })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 :tag(kind, { node = node })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 :add_child(item);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 for jid in pairs(jids) do
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 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
50 message.attr.to = jid;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 module:send(message);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
55 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
56 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
57
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 local feature_map = {
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59 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
60 retract = { "delete-items", "retract-items" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
61 purge = { "purge-nodes" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 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
63 delete = { "delete-nodes" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 get_items = { "retrieve-items" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65 add_subscription = { "subscribe" };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 get_subscriptions = { "retrieve-subscriptions" };
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
67 set_configure = { "config-node" };
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
68 };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
70 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
71 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
72 if service[method] then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 for _, feature in ipairs(features) do
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74 if feature then
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
75 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
76 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
77 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 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
81 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
82 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
83 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
87 module:hook("host-disco-info-node", function (event)
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
88 local stanza, origin, reply, node = event.stanza, event.origin, event.reply, event.node;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
89 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
90 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
91 return;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 end
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
93 event.exists = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
94 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
95 end);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
97 module:hook("host-disco-items-node", function (event)
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
98 local stanza, origin, reply, node = event.stanza, event.origin, event.reply, event.node;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 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
100 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
101 return;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103
6434
382e03a40dd2 mod_pubsub: Transplant pieces of cdcfd93e2f43 from trunk
Kim Alvefur <zash@zash.se>
parents: 5970
diff changeset
104 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
105 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
106 end
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
107 event.exists = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
108 end);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
111 module:hook("host-disco-items", function (event)
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
112 local stanza, origin, reply = event.stanza, event.origin, event.reply;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 local ok, ret = service:get_nodes(event.stanza.attr.from);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 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
115 return;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 end
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
117 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
118 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
119 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 end);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 local admin_aff = module:get_option_string("default_admin_affiliation", "owner");
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 local function get_affiliation(jid)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 local bare_jid = jid_bare(jid);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 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
126 return admin_aff;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 function set_service(new_service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 service = new_service;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 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
133 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
134 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136 function module.save()
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 return { service = service };
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.restore(data)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 set_service(data.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
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
144 function module.load()
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
145 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
146
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
147 set_service(pubsub.new({
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
148 capabilities = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
149 none = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
150 create = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
151 publish = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
152 retract = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
153 get_nodes = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
154
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
155 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
156 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
157 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
158 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
159 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
161 subscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
162 unsubscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
163 get_subscription_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
164 get_subscriptions_other = false;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
165
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
166 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
167 be_unsubscribed = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
168
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
169 set_affiliation = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
170 };
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
171 publisher = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
172 create = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
173 publish = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
174 retract = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
175 get_nodes = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
176
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
177 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
178 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
179 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
180 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
181 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
182
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
183 subscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
184 unsubscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
185 get_subscription_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
186 get_subscriptions_other = false;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
188 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
189 be_unsubscribed = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
190
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
191 set_affiliation = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
192 };
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
193 owner = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
194 create = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
195 publish = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
196 retract = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
197 delete = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
198 get_nodes = true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
199 configure = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
200
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
201 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
202 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
203 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
204 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
205 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
206
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
207
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
208 subscribe_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
209 unsubscribe_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
210 get_subscription_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
211 get_subscriptions_other = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
212
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
213 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
214 be_unsubscribed = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
215
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
216 set_affiliation = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
217 };
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
218 };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
219
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
220 node_config_form = require"util.dataforms".new {
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
221 {
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
222 type = "hidden";
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
223 name = "FORM_TYPE";
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
224 value = "http://jabber.org/protocol/pubsub#node_config";
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
225 };
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
226 };
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
227
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
228 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
229 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
230
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
231 broadcaster = simple_broadcast;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
232 get_affiliation = get_affiliation;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
233
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
234 normalize_jid = jid_bare;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
235 }));
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
236 end