aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-03-11 16:29:57 +0000
committerMatthew Wild <mwild1@gmail.com>2020-03-11 16:29:57 +0000
commit335ce1bf2ad08c54bc0ad41a535c0a7f8b60b4b1 (patch)
tree7730ad7cccd994ed8c798b9efb66cd997347078e /core
parente15b284dc80c208bdec60a2bb2ad8939822418fc (diff)
downloadprosody-335ce1bf2ad08c54bc0ad41a535c0a7f8b60b4b1.tar.gz
prosody-335ce1bf2ad08c54bc0ad41a535c0a7f8b60b4b1.zip
storagemanager: Add support for :find_key() and :delete_key() to map store shim
Diffstat (limited to 'core')
-rw-r--r--core/storagemanager.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/storagemanager.lua b/core/storagemanager.lua
index dea71733..14de1314 100644
--- a/core/storagemanager.lua
+++ b/core/storagemanager.lua
@@ -167,6 +167,39 @@ local map_shim_mt = {
return self.keyval_store:set(username, current);
end;
remove = {};
+ find_key = function (self, key)
+ if type(key) ~= "string" or key == "" then
+ return nil, "find_key only supports non-empty string keys";
+ end
+ local ret;
+ for username in self.keyval_store:users() do
+ local key_data = self:get(username, key);
+ if key_data then
+ if not ret then
+ ret = {};
+ end
+ ret[username] = key_data;
+ end
+ end
+ return ret;
+ end;
+ delete_key = function (self, key)
+ if type(key) ~= "string" or key == "" then
+ return nil, "delete_key only supports non-empty string keys";
+ end
+ local data = { [key] = self.remove };
+ local last_err;
+ for username in self.keyval_store:users() do
+ local ok, err = self:set_keys(username, data);
+ if not ok then
+ last_err = err;
+ end
+ end
+ if last_err then
+ return nil, last_err;
+ end
+ return true;
+ end;
};
}