diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-03-14 16:05:22 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-03-14 16:05:22 +0000 |
commit | bcd9d386bf3d145872796dd6bb183a34bf64b2f8 (patch) | |
tree | 3191e9e9af444ce237f12aa322c891fea9aefc17 /core | |
parent | 94692c20efb3c0edc09710f509c0c310e5c9d0c1 (diff) | |
parent | d2ebe25dc579fb0ab21e411518c50eee1fae0f99 (diff) | |
download | prosody-bcd9d386bf3d145872796dd6bb183a34bf64b2f8.tar.gz prosody-bcd9d386bf3d145872796dd6bb183a34bf64b2f8.zip |
Merge
Diffstat (limited to 'core')
-rw-r--r-- | core/objectmanager.lua | 60 | ||||
-rw-r--r-- | core/usermanager.lua | 15 |
2 files changed, 75 insertions, 0 deletions
diff --git a/core/objectmanager.lua b/core/objectmanager.lua new file mode 100644 index 00000000..b8e5eb3f --- /dev/null +++ b/core/objectmanager.lua @@ -0,0 +1,60 @@ +
+local new_multitable = require "util.multitable".new;
+local t_insert = table.insert;
+local t_concat = table.concat;
+local tostring = tostring;
+local unpack = unpack;
+local pairs = pairs;
+local error = error;
+local type = type;
+local _G = _G;
+
+local data = new_multitable();
+
+module "objectmanager"
+
+function set(...)
+ return data:set(...);
+end
+function remove(...)
+ return data:remove(...);
+end
+function get(...)
+ return data:get(...);
+end
+
+local function get_path(path)
+ if type(path) == "table" then return path; end
+ local s = {};
+ for part in tostring(path):gmatch("[%w_]+") do
+ t_insert(s, part);
+ end
+ return s;
+end
+
+function get_object(path)
+ path = get_path(path)
+ return data:get(unpack(path)), path;
+end
+function set_object(path, object)
+ path = get_path(path);
+ data:set(unpack(path), object);
+end
+
+data:set("ls", function(_dir)
+ local obj, dir = get_object(_dir);
+ if not obj then error("object not found: " .. t_concat(dir, '/')); end
+ local r = {};
+ if type(obj) == "table" then
+ for key, val in pairs(obj) do
+ r[key] = type(val);
+ end
+ end
+ return r;
+end);
+data:set("get", get_object);
+data:set("set", set_object);
+data:set("echo", function(...) return {...}; end);
+data:set("_G", _G);
+
+return _M;
diff --git a/core/usermanager.lua b/core/usermanager.lua index fd8fe739..bee1502e 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -11,8 +11,12 @@ require "util.datamanager" local datamanager = datamanager; local log = require "util.logger".init("usermanager"); +local type = type; local error = error; +local ipairs = ipairs; local hashes = require "util.hashes"; +local jid_bare = require "util.jid".bare; +local config = require "core.configmanager"; module "usermanager" @@ -59,4 +63,15 @@ function get_supported_methods(host) return methods; end +function is_admin(jid) + local admins = config.get("*", "core", "admins") or {}; + if type(admins) == "table" then + jid = jid_bare(jid); + for _,admin in ipairs(admins) do + if admin == jid then return true; end + end + else log("debug", "Option core.admins is not a table"); end + return nil; +end + return _M; |