Comparison

plugins/mod_storage_memory.lua @ 9838:40ed04014b97 0.11

mod_storage_memory: Generate ID using standard util (fixes #1326) The previous method relied on tostring(table) returning the pointer address, which might not be portable.
author Kim Alvefur <zash@zash.se>
date Sat, 02 Mar 2019 22:26:01 +0100
parent 9832:96d9c121547b
child 9839:9007ae90aeb1
child 9881:68faa0c1a99c
comparison
equal deleted inserted replaced
9833:86fe021f16a6 9838:40ed04014b97
1 local serialize = require "util.serialization".serialize; 1 local serialize = require "util.serialization".serialize;
2 local array = require "util.array"; 2 local array = require "util.array";
3 local envload = require "util.envload".envload; 3 local envload = require "util.envload".envload;
4 local st = require "util.stanza"; 4 local st = require "util.stanza";
5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end 5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end
6 local new_id = require "util.id".medium;
6 7
7 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); 8 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false);
8 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {}); 9 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {});
9 10
10 local memory = setmetatable({}, { 11 local memory = setmetatable({}, {
54 a = {}; 55 a = {};
55 self.store[username or NULL] = a; 56 self.store[username or NULL] = a;
56 end 57 end
57 local v = { key = key, when = when, with = with, value = value }; 58 local v = { key = key, when = when, with = with, value = value };
58 if not key then 59 if not key then
59 key = tostring(a):match"%x+$"..tostring(v):match"%x+$"; 60 key = new_id();
60 v.key = key; 61 v.key = key;
61 end 62 end
62 if a[key] then 63 if a[key] then
63 table.remove(a, a[key]); 64 table.remove(a, a[key]);
64 end 65 end