aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-01-14 16:57:19 +0000
committerMatthew Wild <mwild1@gmail.com>2022-01-14 16:57:19 +0000
commit843e4ad49db8c913b42db411547c654b6af2c3e9 (patch)
treee7fa639e09ec647b9a3d89eecc0d8b5ea3b52073 /plugins
parent2d0db1b0a3a9887f9c94b6a8e4e14836bd2747b9 (diff)
downloadprosody-843e4ad49db8c913b42db411547c654b6af2c3e9.tar.gz
prosody-843e4ad49db8c913b42db411547c654b6af2c3e9.zip
mod_storage_xep0227: Add API to iterate all stores of a user
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_xep0227.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/plugins/mod_storage_xep0227.lua b/plugins/mod_storage_xep0227.lua
index 45cfaa77..7b039f81 100644
--- a/plugins/mod_storage_xep0227.lua
+++ b/plugins/mod_storage_xep0227.lua
@@ -688,6 +688,18 @@ function driver:open_xep0227(datastore, typ, options)
return instance;
end
+local function get_store_names_from_xml(self, user_xml)
+ local stores = set.new();
+ for handler_name, handler_funcs in pairs(handlers) do
+ if handler_funcs._stores then
+ stores:include(handler_funcs._stores(self, user_xml));
+ else
+ stores:include(handler_name);
+ end
+ end
+ return stores;
+end
+
local function get_store_names(self, path)
local stores = set.new();
local f, err = io_open(paths.join(prosody.paths.data, path));
@@ -698,13 +710,8 @@ local function get_store_names(self, path)
module:log("info", "Loaded %s", path);
local s = f:read("*a");
f:close();
- local xml = parse_xml_real(s);
- for _, handler_funcs in pairs(handlers) do
- if handler_funcs._stores then
- stores:include(handler_funcs._stores(self, xml));
- end
- end
- return stores;
+ local user_xml = parse_xml_real(s);
+ return get_store_names_from_xml(self, user_xml);
end
function driver:stores(username)
@@ -733,4 +740,13 @@ function driver:stores(username)
return store_names:items();
end
+function driver:xep0227_user_stores(username, host)
+ local user_xml = self:_get_user_xml(username, host);
+ if not user_xml then
+ return nil;
+ end
+ local store_names = get_store_names_from_xml(username, host);
+ return store_names:items();
+end
+
module:provides("storage", driver);