From 54252eecb4fb38317f51087c591aa878ad19df71 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Sep 2014 01:45:59 +0200 Subject: util.pubsub: Add support for node configuration --- util/pubsub.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'util/pubsub.lua') diff --git a/util/pubsub.lua b/util/pubsub.lua index 3c67be90..424a48c6 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -11,11 +11,14 @@ local default_config = { __index = { get_affiliation = function () end; capabilities = {}; } }; +local default_node_config = { __index = { +} }; function new(config) config = config or {}; return setmetatable({ config = setmetatable(config, default_config); + node_defaults = setmetatable(config.node_defaults or {}, default_node_config); affiliations = {}; subscriptions = {}; nodes = {}; @@ -204,7 +207,7 @@ function service:get_subscription(node, actor, jid) return true, node_obj.subscribers[jid]; end -function service:create(node, actor) +function service:create(node, actor, options) -- Access checking if not self:may(node, actor, "create") then return false, "forbidden"; @@ -218,7 +221,7 @@ function service:create(node, actor) self.nodes[node] = { name = node; subscribers = {}; - config = {}; + config = setmetatable(options or {}, {__index=self.node_defaults}); affiliations = {}; }; setmetatable(self.nodes[node], { __index = { data = self.data[node] } }); -- COMPAT @@ -411,4 +414,21 @@ function service:set_node_capabilities(node, actor, capabilities) return true; end +function service:set_node_config(node, actor, new_config) + if not self:may(node, actor, "configure") then + return false, "forbidden"; + end + + local node_obj = self.nodes[node]; + if not node_obj then + return false, "item-not-found"; + end + + for k,v in pairs(new_config) do + node_obj.config[k] = v; + end + + return true; +end + return _M; -- cgit v1.2.3