aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-18 09:38:45 +0200
committerKim Alvefur <zash@zash.se>2017-10-18 09:38:45 +0200
commit389f85aabfed739952c0973b806728fb0d1c1a9b (patch)
treee16075aec996b681147e0aa0ecf4c17dd1f26c8e
parent876c849635dc5c24b039e7fdd0d68e6661f491e5 (diff)
downloadprosody-im-server-389f85aabfed739952c0973b806728fb0d1c1a9b.tar
prosody-im-server-389f85aabfed739952c0973b806728fb0d1c1a9b.zip
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua28
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua49
2 files changed, 51 insertions, 26 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 6ebbe765..0e00c427 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -60,33 +60,9 @@ end
module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
-local feature_map = {
- create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" };
- retract = { "delete-items", "retract-items" };
- purge = { "purge-nodes" };
- publish = { "publish", autocreate_on_publish and "auto-create" };
- delete = { "delete-nodes" };
- get_items = { "retrieve-items" };
- add_subscription = { "subscribe" };
- get_subscriptions = { "retrieve-subscriptions" };
- set_node_config = { "config-node" };
- node_defaults = { "retrieve-default" };
-};
-
local function add_disco_features_from_service(service)
- for method, features in pairs(feature_map) do
- if service[method] then
- for _, feature in ipairs(features) do
- if feature then
- module:add_feature(xmlns_pubsub.."#"..feature);
- end
- end
- end
- end
- for affiliation in pairs(service.config.capabilities) do
- if affiliation ~= "none" and affiliation ~= "owner" then
- module:add_feature(xmlns_pubsub.."#"..affiliation.."-affiliation");
- end
+ for feature in lib_pubsub.get_feature_set(service) do
+ module:add_feature(xmlns_pubsub.."#"..feature);
end
end
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index ca9f7c9a..b9a7a8c1 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -1,6 +1,7 @@
local t_unpack = table.unpack or unpack; -- luacheck: ignore 113
local time_now = os.time;
+local set = require "util.set";
local st = require "util.stanza";
local it = require "util.iterators";
local uuid_generate = require "util.uuid".generate;
@@ -53,6 +54,54 @@ local node_config_form = dataform {
};
};
+local service_method_feature_map = {
+ add_subscription = { "subscribe" };
+ create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" };
+ delete = { "delete-nodes" };
+ get_items = { "retrieve-items" };
+ get_subscriptions = { "retrieve-subscriptions" };
+ node_defaults = { "retrieve-default" };
+ publish = { "publish" };
+ purge = { "purge-nodes" };
+ retract = { "delete-items", "retract-items" };
+ set_node_config = { "config-node" };
+};
+local service_config_feature_map = {
+ autocreate_on_publish = { "auto-create" };
+};
+
+function _M.get_feature_set(service)
+ local supported_features = set.new();
+
+ for method, features in pairs(service_method_feature_map) do
+ if service[method] then
+ for _, feature in ipairs(features) do
+ if feature then
+ supported_features:add(feature);
+ end
+ end
+ end
+ end
+
+ for option, features in pairs(service_config_feature_map) do
+ if service.config[option] then
+ for _, feature in ipairs(features) do
+ if feature then
+ supported_features:add(feature);
+ end
+ end
+ end
+ end
+
+ for affiliation in pairs(service.config.capabilities) do
+ if affiliation ~= "none" and affiliation ~= "owner" then
+ supported_features:add(affiliation.."-affiliation");
+ end
+ end
+
+ return supported_features;
+end
+
function _M.handle_pubsub_iq(event, service)
local origin, stanza = event.origin, event.stanza;
local pubsub_tag = stanza.tags[1];