Mercurial > prosody-modules
annotate mod_storage_memory/mod_storage_memory.lua @ 2985:7467509abdbb
mod_post_msg/README: Update Introduction text
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 04 Apr 2018 15:50:13 +0200 |
parents | 9db18f909b84 |
children | 8e5da12205b5 |
rev | line source |
---|---|
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
1 local serialize = require "util.serialization".serialize; |
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
2 local envload = require "util.envload".envload; |
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
3 local st = require "util.stanza"; |
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
4 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end |
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
5 |
2620
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
6 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
7 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {}); |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local memory = setmetatable({}, { |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 __index = function(t, k) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local store = module:shared(k) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 t[k] = store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 return store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 }); |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
17 local function NULL() return nil end |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
18 |
2619
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
19 local function _purge_store(self, username) |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
20 self.store[username or NULL] = nil; |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
21 return true; |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
22 end |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
23 |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local keyval_store = {}; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 keyval_store.__index = keyval_store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 function keyval_store:get(username) |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
28 return (self.store[username or NULL] or NULL)(); |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 function keyval_store:set(username, data) |
2673
2e1a4740adee
mod_storage_memory: Include missing return statement (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
2661
diff
changeset
|
32 self.store[username or NULL] = envload("return "..serialize(data), "@data", {}); |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return true; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
2619
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
36 keyval_store.purge = _purge_store; |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
37 |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
38 local archive_store = {}; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
39 archive_store.__index = archive_store; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
40 |
1753
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1608
diff
changeset
|
41 function archive_store:append(username, key, value, when, with) |
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1608
diff
changeset
|
42 if type(when) ~= "number" then |
1760
e72f9eac51c8
mod_storage_(various): Order swapping in 54c8a0cb2996 was backwards
Kim Alvefur <zash@zash.se>
parents:
1753
diff
changeset
|
43 when, with, value = value, when, with; |
1753
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1608
diff
changeset
|
44 end |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
45 if is_stanza(value) then |
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
46 value = st.preserialize(value); |
2802
0d5d1ff96600
mod_storage_memory: Serialize stanzas on save (was delayed until query)
Kim Alvefur <zash@zash.se>
parents:
2673
diff
changeset
|
47 value = envload("return xml"..serialize(value), "@stanza", { xml = st.deserialize }) |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
48 else |
2673
2e1a4740adee
mod_storage_memory: Include missing return statement (thanks jonasw)
Kim Alvefur <zash@zash.se>
parents:
2661
diff
changeset
|
49 value = envload("return "..serialize(value), "@data", {}); |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
50 end |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
51 local a = self.store[username or NULL]; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
52 if not a then |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
53 a = {}; |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
54 self.store[username or NULL] = a; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
55 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
56 local i = #a+1; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
57 local v = { key = key, when = when, with = with, value = value }; |
2803
9db18f909b84
mod_storage_memory: Allow archive items to be overwritten by id
Kim Alvefur <zash@zash.se>
parents:
2802
diff
changeset
|
58 if not key then |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
59 key = tostring(a):match"%x+$"..tostring(v):match"%x+$"; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
60 v.key = key; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
61 end |
2803
9db18f909b84
mod_storage_memory: Allow archive items to be overwritten by id
Kim Alvefur <zash@zash.se>
parents:
2802
diff
changeset
|
62 if a[key] then |
9db18f909b84
mod_storage_memory: Allow archive items to be overwritten by id
Kim Alvefur <zash@zash.se>
parents:
2802
diff
changeset
|
63 table.remove(a, a[key]); |
9db18f909b84
mod_storage_memory: Allow archive items to be overwritten by id
Kim Alvefur <zash@zash.se>
parents:
2802
diff
changeset
|
64 end |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
65 a[i] = v; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
66 a[key] = i; |
2654
9e5015555fff
mod_storage_memory: Fix to make archive:append() return the archive id as it should
Kim Alvefur <zash@zash.se>
parents:
2620
diff
changeset
|
67 return key; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
68 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
69 |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
70 local function archive_iter (a, start, stop, step, limit, when_start, when_end, match_with) |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
71 local item, when, with; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
72 local count = 0; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
73 coroutine.yield(true); -- Ready |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
74 for i = start, stop, step do |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
75 item = a[i]; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
76 when, with = item.when, item.with; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
77 if when >= when_start and when_end >= when and (not match_with or match_with == with) then |
2656
83fb61fa476e
mod_storage_memory: Serialize data functions that return the data (prevents mutation of stored data)
Kim Alvefur <zash@zash.se>
parents:
2655
diff
changeset
|
78 coroutine.yield(item.key, item.value(), when, with); |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
79 count = count + 1; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
80 if limit and count >= limit then return end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
81 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
82 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
83 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
84 |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
85 function archive_store:find(username, query) |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
86 local a = self.store[username or NULL] or {}; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
87 local start, stop, step = 1, #a, 1; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
88 local qstart, qend, qwith = -math.huge, math.huge; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
89 local limit; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
90 if query then |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
91 module:log("debug", "query included") |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
92 if query.reverse then |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
93 start, stop, step = stop, start, -1; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
94 if query.before then |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
95 start = a[query.before]; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
96 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
97 elseif query.after then |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
98 start = a[query.after]; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
99 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
100 limit = query.limit; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
101 qstart = query.start or qstart; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
102 qend = query["end"] or qend; |
2660
796ace2c8f9d
mod_storage_memory: Inclued 'with' in search [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2659
diff
changeset
|
103 qwith = query.with; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
104 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
105 if not start then return nil, "invalid-key"; end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
106 local iter = coroutine.wrap(archive_iter); |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
107 iter(a, start, stop, step, limit, qstart, qend, qwith); |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
108 return iter; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
109 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
110 |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
111 function archive_store:delete(username, query) |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
112 if not query or next(query) == nil then |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
113 self.store[username or NULL] = nil; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
114 return true; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
115 end |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
116 local old = self.store[username or NULL]; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
117 if not old then return true; end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
118 local qstart = query.start or -math.huge; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
119 local qend = query["end"] or math.huge; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
120 local qwith = query.with; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
121 local new = {}; |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
122 self.store[username or NULL] = new; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
123 local t; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
124 for i = 1, #old do |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
125 i = old[i]; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
126 t = i.when; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
127 if not(qstart >= t and qend <= t and (not qwith or i.with == qwith)) then |
1753
54c8a0cb2996
mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents:
1608
diff
changeset
|
128 self:append(username, i.key, i.value, t, i.with); |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
129 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
130 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
131 if #new == 0 then |
2097
4454f124465a
mod_storage_memory: Support for empty username stores
Matthew Wild <mwild1@gmail.com>
parents:
1760
diff
changeset
|
132 self.store[username or NULL] = nil; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
133 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
134 return true; |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
135 end |
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
136 |
2619
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
137 archive_store.purge = _purge_store; |
1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
Matthew Wild <mwild1@gmail.com>
parents:
2172
diff
changeset
|
138 |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 local stores = { |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 keyval = keyval_store; |
1608
59fdf4f12343
mod_storage_memory: Add support for archive stores
Kim Alvefur <zash@zash.se>
parents:
1607
diff
changeset
|
141 archive = archive_store; |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 } |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 local driver = {}; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 |
2661
1d734acabd46
mod_storage_memory: Ignore unused 'self' [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2660
diff
changeset
|
146 function driver:open(store, typ) -- luacheck: ignore 212/self |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 local store_mt = stores[typ or "keyval"]; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 if store_mt then |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 return setmetatable({ store = memory[store] }, store_mt); |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 return nil, "unsupported-store"; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 |
2620
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
154 if auto_purge_enabled then |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
155 module:hook("resource-unbind", function (event) |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
156 local user_bare_jid = event.session.username.."@"..event.session.host; |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
157 if not prosody.bare_sessions[user_bare_jid] then -- User went offline |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
158 module:log("debug", "Clearing store for offline user %s", user_bare_jid); |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
159 local f, s, v; |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
160 if auto_purge_stores:empty() then |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
161 f, s, v = pairs(memory); |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
162 else |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
163 f, s, v = auto_purge_stores:items(); |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
164 end |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
165 |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
166 for store_name in f, s, v do |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
167 if memory[store_name] then |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
168 memory[store_name][event.session.username] = nil; |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
169 end |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
170 end |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
171 end |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
172 end); |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
173 end |
8b8cab2eb7fc
mod_storage_memory: Add support for clearing a user's data when they log out
Matthew Wild <mwild1@gmail.com>
parents:
2619
diff
changeset
|
174 |
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 module:provides("storage", driver); |