Software /
code /
prosody
Changeset
6437:3f1f11dfdf10
util.pubsub: Add support for node configuration
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Sep 2014 01:45:59 +0200 |
parents | 6436:31ca87ea8d46 |
children | 6438:b1c40054b59d |
files | util/pubsub.lua |
diffstat | 1 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/util/pubsub.lua Sun Sep 28 00:05:21 2014 +0200 +++ b/util/pubsub.lua Sun Sep 28 01:45:59 2014 +0200 @@ -11,11 +11,14 @@ 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 @@ 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 @@ 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 @@ 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;