diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-06-23 15:58:56 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-06-23 15:58:56 +0100 |
commit | f00a5d70b30b132b763b2e20c68accb8ce52789d (patch) | |
tree | 0741204836fedee0caea15f4607bd996d7e5fdab /util/datamanager.lua | |
parent | 3f141a44c2b4564e5d88748f76f53f5fec6c1a33 (diff) | |
parent | 54bbd9c98aa6e40463982ec2a92fa9a444704b43 (diff) | |
download | prosody-f00a5d70b30b132b763b2e20c68accb8ce52789d.tar.gz prosody-f00a5d70b30b132b763b2e20c68accb8ce52789d.zip |
Automated merge with http://waqas.ath.cx:8000/
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r-- | util/datamanager.lua | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index 41d09f06..54cf1959 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -50,7 +50,7 @@ local function mkdir(path) end local data_path = "data"; -local callback; +local callbacks = {}; ------- API ------------- @@ -58,8 +58,32 @@ function set_data_path(path) log("debug", "Setting data path to: %s", path); data_path = path; end -function set_callback(func) - callback = func; + +local function callback(username, host, datastore, data) + for _, f in ipairs(callbacks) do + username, host, datastore, data = f(username, host, datastore, data); + if not username then break; end + end + + return username, host, datastore, data; +end +function add_callback(func) + if not callbacks[func] then -- Would you really want to set the same callback more than once? + callbacks[func] = true; + callbacks[#callbacks+1] = func; + return true; + end +end +function remove_callback(func) + if callbacks[func] then + for i, f in ipairs(callbacks) do + if f == func then + callbacks[i] = nil; + callbacks[f] = nil; + return true; + end + end + end end function getpath(username, host, datastore, ext, create) @@ -97,7 +121,12 @@ function store(username, host, datastore, data) if not data then data = {}; end - if callback and callback(username, host, datastore) then return true; end + + username, host, datastore, data = callback(username, host, datastore, data); + if not username then + return true; -- Don't save this data at all + end + -- save the datastore local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); if not f then |