annotate mod_storage_memory/mod_storage_memory.lua @ 1468:cf32265eb4c7

mod_onions: Actually define the variable "stanza" to contain "event.stanza", fixing problems of stanzas being dropped for outgoing connections.
author Thijs Alkemade <me@thijsalkema.de>
date Fri, 04 Jul 2014 14:47:14 +0200
parents fa7e402fcdc1
children 8b997d9cf09e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1259
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local memory = setmetatable({}, {
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 __index = function(t, k)
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 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
5 t[k] = store;
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 return store;
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 end
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
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local keyval_store = {};
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 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
12
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 function keyval_store:get(username)
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 return self.store[username];
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 function keyval_store:set(username, data)
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 self.store[username] = data;
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 return true;
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 end
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local stores = {
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 keyval = keyval_store;
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 }
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local driver = {};
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 function driver:open(store, typ)
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 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
30 if store_mt then
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 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
32 end
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 return nil, "unsupported-store";
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
fa7e402fcdc1 mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 module:provides("storage", driver);