Mercurial > prosody-modules
changeset 2097:4454f124465a
mod_storage_memory: Support for empty username stores
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 16 Mar 2016 12:55:25 +0000 |
parents | b75d29a162cd |
children | 1124758cac7f |
files | mod_storage_memory/mod_storage_memory.lua |
diffstat | 1 files changed, 14 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_storage_memory/mod_storage_memory.lua Wed Mar 16 12:43:17 2016 +0000 +++ b/mod_storage_memory/mod_storage_memory.lua Wed Mar 16 12:55:25 2016 +0000 @@ -7,15 +7,17 @@ end }); +local NULL = {}; + local keyval_store = {}; keyval_store.__index = keyval_store; function keyval_store:get(username) - return self.store[username]; + return self.store[username or NULL]; end function keyval_store:set(username, data) - self.store[username] = data; + self.store[username or NULL] = data; return true; end @@ -23,17 +25,17 @@ map_store.__index = map_store; function map_store:get(username, key) - local userstore = self.store[username]; + local userstore = self.store[username or NULL]; if type(userstore) == "table" then return userstore[key]; end end function map_store:set(username, key, data) - local userstore = self.store[username]; + local userstore = self.store[username or NULL]; if userstore == nil then userstore = {}; - self.store[username] = userstore; + self.store[username or NULL] = userstore; end userstore[key] = data; return true; @@ -46,10 +48,10 @@ if type(when) ~= "number" then when, with, value = value, when, with; end - local a = self.store[username]; + local a = self.store[username or NULL]; if not a then a = {}; - self.store[username] = a; + self.store[username or NULL] = a; end local i = #a+1; local v = { key = key, when = when, with = with, value = value }; @@ -78,7 +80,7 @@ end function archive_store:find(username, query) - local a = self.store[username] or {}; + local a = self.store[username or NULL] or {}; local start, stop, step = 1, #a, 1; local qstart, qend, qwith = -math.huge, math.huge; local limit; @@ -104,16 +106,16 @@ function archive_store:delete(username, query) if not query or next(query) == nil then - self.store[username] = nil; + self.store[username or NULL] = nil; return true; end - local old = self.store[username]; + local old = self.store[username or NULL]; if not old then return true; end local qstart = query.start or -math.huge; local qend = query["end"] or math.huge; local qwith = query.with; local new = {}; - self.store[username] = new; + self.store[username or NULL] = new; local t; for i = 1, #old do i = old[i]; @@ -123,7 +125,7 @@ end end if #new == 0 then - self.store[username] = nil; + self.store[username or NULL] = nil; end return true; end