Comparison

mod_archive_muc/mod_archive_muc.lua @ 240:ef0b580f434d

mod_archive_muc: clean up '\n ' in preference stanza
author shinysky<shinysky1986(AT)gmail.com>
date Wed, 11 Aug 2010 07:59:26 +0800
parent 238:5343b3ebaffb
child 243:6202ce4d12d6
comparison
equal deleted inserted replaced
239:2659ee3e8d56 240:ef0b580f434d
21 module:add_feature("urn:xmpp:archive#management"); 21 module:add_feature("urn:xmpp:archive#management");
22 22
23 ------------------------------------------------------------ 23 ------------------------------------------------------------
24 -- Utils 24 -- Utils
25 ------------------------------------------------------------ 25 ------------------------------------------------------------
26 local function trim(s)
27 return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
28 end
29
30 local function clean_up(t)
31 for i = #t, 1, -1 do
32 if type(t[i]) == 'table' then
33 clean_up(t[i]);
34 elseif type(t[i]) == 'string' and trim(t[i]) == '' then
35 table.remove(t, i);
36 end
37 end
38 end
39
26 local function load_prefs(node, host) 40 local function load_prefs(node, host)
27 return st.deserialize(dm.load(node, host, PREFS_DIR)); 41 return st.deserialize(dm.load(node, host, PREFS_DIR));
28 end 42 end
29 43
30 local function store_prefs(data, node, host) 44 local function store_prefs(data, node, host)
45 clean_up(data);
31 dm.store(node, host, PREFS_DIR, st.preserialize(data)); 46 dm.store(node, host, PREFS_DIR, st.preserialize(data));
32 end 47 end
33 48
34 local date_time = datetime.datetime; 49 local date_time = datetime.datetime;
35 50