aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-09-28 01:45:59 +0200
committerKim Alvefur <zash@zash.se>2014-09-28 01:45:59 +0200
commit4f74defed4aa265350c0465c63b4698eaab9814c (patch)
tree450a30981494c9345ce33e1c0df9f9b7604944b4
parent2d58001a25c924d5e77e568c9984981443aee5ad (diff)
downloadprosody-4f74defed4aa265350c0465c63b4698eaab9814c.tar.gz
prosody-4f74defed4aa265350c0465c63b4698eaab9814c.zip
util.pubsub: Add support for node configuration
-rw-r--r--util/pubsub.lua24
1 files changed, 22 insertions, 2 deletions
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;