Annotate

plugins/mod_pubsub/mod_pubsub.lua @ 9044:18cd5102253c

mod_pubsub: Skip checks for adding body if no body generated
author Kim Alvefur <zash@zash.se>
date Sat, 14 Jul 2018 21:26:59 +0200
parent 9043:9d77b6588bdf
child 9045:4336a2b97aba
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";
8811
f2d35eee69c9 mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents: 8808
diff changeset
5 local new_id = require "util.id".medium;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 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
8 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
9 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
10
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11 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
12 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
13 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
14 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
15
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 local service;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 local lib_pubsub = module:require "pubsub";
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)
8334
036e46d12b78 mod_pubsub: Move dispatch function into pubsub.lib
Kim Alvefur <zash@zash.se>
parents: 8328
diff changeset
25 return lib_pubsub.handle_pubsub_iq(event, service);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27
8504
80b8355c8b8b mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents: 8503
diff changeset
28 local node_store = module:open_store(module.name.."_nodes");
80b8355c8b8b mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents: 8503
diff changeset
29
8503
3b86134c56ea mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents: 8340
diff changeset
30 local function create_simple_itemstore(node_config, node_name)
3b86134c56ea mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents: 8340
diff changeset
31 local archive = module:open_store("pubsub_"..node_name, "archive");
3b86134c56ea mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents: 8340
diff changeset
32 return lib_pubsub.archive_itemstore(archive, node_config, nil, node_name);
8213
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
33 end
e1272aeef31c mod_pubsub: Add item persistence using mod_storage_*’s archive store.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8210
diff changeset
34
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8811
diff changeset
35 function simple_broadcast(kind, node, jids, item, actor, node_obj)
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36 if item then
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
37 item = st.clone(item);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 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
39 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
40 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
41 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 end
8811
f2d35eee69c9 mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents: 8808
diff changeset
43
f2d35eee69c9 mod_pubsub: Set an id attribute on outgoing event messages
Kim Alvefur <zash@zash.se>
parents: 8808
diff changeset
44 local id = new_id();
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8811
diff changeset
45 local msg_type = node_obj and node_obj.config.message_type or "headline";
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8811
diff changeset
46 local message = st.message({ from = module.host, type = msg_type, id = id })
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 :tag("event", { xmlns = xmlns_pubsub_event })
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 :tag(kind, { node = node })
8946
3a095233e178 mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
49
3a095233e178 mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
50 if item then
3a095233e178 mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
51 message:add_child(item);
3a095233e178 mod_pubsub: Handle optional item (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents: 8815
diff changeset
52 end
8814
07197f29e2b8 mod_pubsub: Make the 'type' attribute on broadcast messages configurable
Kim Alvefur <zash@zash.se>
parents: 8811
diff changeset
53
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
54 local summary;
8815
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
55 -- Compose a sensible textual representation of at least Atom payloads
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
56 if item and item.tags[1] then
8815
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
57 local payload = item.tags[1];
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
58 if payload.attr.xmlns == "http://www.w3.org/2005/Atom" then
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
59 local title = payload:get_child_text("title");
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
60 summary = payload:get_child_text("summary");
8815
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
61 if not summary and title then
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
62 local author = payload:find("author/name#");
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
63 summary = title;
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
64 if author then
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
65 summary = author .. " posted " .. summary;
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
66 end
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
67 end
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
68 end
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
69 end
5974c9da1391 mod_pubsub: Add support for generation of a plain text <body> from Atom payloads
Kim Alvefur <zash@zash.se>
parents: 8814
diff changeset
70
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
71 for jid, options in pairs(jids) do
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
72 local new_stanza = st.clone(message);
9044
18cd5102253c mod_pubsub: Skip checks for adding body if no body generated
Kim Alvefur <zash@zash.se>
parents: 9043
diff changeset
73 if summary and type(options) == "table" and options["pubsub#include_body"] then
9039
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
74 new_stanza:body(summary);
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
75 end
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
76 new_stanza.attr.to = jid;
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
77 module:send(new_stanza);
0124e5ec1556 mod_pubsub: Move include_body option into subscription options
Kim Alvefur <zash@zash.se>
parents: 8980
diff changeset
78 end
5626
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
8695
09e7fd8b16cd mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents: 8505
diff changeset
81 function is_item_stanza(item)
09e7fd8b16cd mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents: 8505
diff changeset
82 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item";
09e7fd8b16cd mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents: 8505
diff changeset
83 end
09e7fd8b16cd mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents: 8505
diff changeset
84
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 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
86 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
87
8505
c9bdb4dfed96 mod_pubsub: Ignore unused parameter [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 8504
diff changeset
88 local function add_disco_features_from_service(service) --luacheck: ignore 431/service
8340
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8339
diff changeset
89 for feature in lib_pubsub.get_feature_set(service) do
7c1fb8c042dc mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8339
diff changeset
90 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
91 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
94 module:hook("host-disco-info-node", function (event)
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8957
diff changeset
95 return lib_pubsub.handle_disco_info_node(event, service);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96 end);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
98 module:hook("host-disco-items-node", function (event)
8980
4d2738b99b07 mod_pubsub: Move service discovery to pubsub.lib to allow reuse
Kim Alvefur <zash@zash.se>
parents: 8957
diff changeset
99 return lib_pubsub.handle_disco_items_node(event, service);
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
100 end);
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
103 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
104 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
105 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
106 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
107 return;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 end
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
109 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
110 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
111 end
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 end);
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 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
115 local function get_affiliation(jid)
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 local bare_jid = jid_bare(jid);
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 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
118 return admin_aff;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 end
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 function set_service(new_service)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 service = new_service;
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 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
125 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
126 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 function module.save()
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 return { service = service };
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 end
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 function module.restore(data)
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 set_service(data.service);
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
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
136 function module.load()
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
137 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
138
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
139 set_service(pubsub.new({
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
140 capabilities = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
141 none = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
142 create = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
143 publish = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
144 retract = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
145 get_nodes = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
147 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
148 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
149 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
150 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
151 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
152
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
153 subscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
154 unsubscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
155 get_subscription_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
156 get_subscriptions_other = false;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
157
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
158 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
159 be_unsubscribed = 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 set_affiliation = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
162 };
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
163 publisher = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
164 create = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
165 publish = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
166 retract = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
167 get_nodes = 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 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
170 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
171 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
172 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
173 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
174
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
175 subscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
176 unsubscribe_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
177 get_subscription_other = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
178 get_subscriptions_other = false;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
180 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
181 be_unsubscribed = 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 set_affiliation = false;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
184 };
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
185 owner = {
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
186 create = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
187 publish = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
188 retract = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
189 delete = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
190 get_nodes = true;
6438
b1c40054b59d mod_pubsub: Add support for node configuration
Kim Alvefur <zash@zash.se>
parents: 6434
diff changeset
191 configure = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
192
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
193 subscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
194 unsubscribe = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
195 get_subscription = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
196 get_subscriptions = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
197 get_items = true;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
198
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
199
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
200 subscribe_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
201 unsubscribe_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
202 get_subscription_other = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
203 get_subscriptions_other = 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 be_subscribed = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
206 be_unsubscribed = true;
5626
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 set_affiliation = true;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
209 };
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 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
213 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
214
8504
80b8355c8b8b mod_pubsub: Add nodestore to service configuration
Matthew Wild <mwild1@gmail.com>
parents: 8503
diff changeset
215 nodestore = node_store;
8503
3b86134c56ea mod_pubsub: Some variable renames for clarity
Matthew Wild <mwild1@gmail.com>
parents: 8340
diff changeset
216 itemstore = create_simple_itemstore;
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
217 broadcaster = simple_broadcast;
8695
09e7fd8b16cd mod_pubsub: Reject publishing of non-items
Kim Alvefur <zash@zash.se>
parents: 8505
diff changeset
218 itemcheck = is_item_stanza;
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
219 get_affiliation = get_affiliation;
5626
8416d4619d80 mod_pubsub: Split out handlers into a module library
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
220
5690
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
221 normalize_jid = jid_bare;
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
222 }));
630e7224a65f mod_pubsub: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents: 5626
diff changeset
223 end