aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-05-11 23:22:25 +0200
committerKim Alvefur <zash@zash.se>2020-05-11 23:22:25 +0200
commitc9498a4d00f68a4cbb282de99124a4d0922f30e3 (patch)
tree24e59c0b743370ac8d2e1ccebaf4af6a72d5a8b7 /plugins
parent7b3b4efb797c438065ee52aea2ac67a66f5e22cf (diff)
downloadprosody-c9498a4d00f68a4cbb282de99124a4d0922f30e3.tar.gz
prosody-c9498a4d00f68a4cbb282de99124a4d0922f30e3.zip
mod_storage_memory: Add map store methods to archive store
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_memory.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/mod_storage_memory.lua b/plugins/mod_storage_memory.lua
index 8beb8c01..67598416 100644
--- a/plugins/mod_storage_memory.lua
+++ b/plugins/mod_storage_memory.lua
@@ -167,6 +167,37 @@ function archive_store:find(username, query)
end, count;
end
+function archive_store:get(username, wanted_key)
+ local items = self.store[username or NULL];
+ if not items then return nil, "item-not-found"; end
+ local i = items[wanted_key];
+ if not i then return nil, "item-not-found"; end
+ local item = items[i];
+ return item.value(), item.when, item.with;
+end
+
+function archive_store:set(username, wanted_key, new_value, new_when, new_with)
+ local items = self.store[username or NULL];
+ if not items then return nil, "item-not-found"; end
+ local i = items[wanted_key];
+ if not i then return nil, "item-not-found"; end
+ local item = items[i];
+
+ if is_stanza(new_value) then
+ new_value = st.preserialize(new_value);
+ item.value = envload("return xml"..serialize(new_value), "=(stanza)", { xml = st.deserialize })
+ else
+ item.value = envload("return "..serialize(new_value), "=(data)", {});
+ end
+ if new_when then
+ item.when = new_when;
+ end
+ if new_with then
+ item.with = new_when;
+ end
+ return true;
+end
+
function archive_store:summary(username, query)
local iter, err = self:find(username, query)
if not iter then return iter, err; end