annotate mod_storage_memory/mod_storage_memory.lua @ 1268:854a3933cfcd

mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 04 Jan 2014 16:50:57 -0500
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);