annotate mod_storage_muc_log/mod_storage_muc_log.lua @ 1690:8c0fbc685364

mod_storage_xmlarchive: New stanza archive-only storage module backed by plain text files
author Kim Alvefur <zash@zash.se>
date Sun, 03 May 2015 13:45:42 +0200
parents 711fabfe6604
children 54c8a0cb2996
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local datamanager = require"core.storagemanager".olddm;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local xml_parse = require"util.xml".parse;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local data_load, data_store = datamanager.load, datamanager.store;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local datastore = "muc_log";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local datetime = require"util.datetime"
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local lfs = require"lfs";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local noop = function () end;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local os_date = os.date;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
11 local timef, datef = "!%H:%M:%S", "!%y%m%d";
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local host = module.host;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local driver = {};
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local driver_mt = { __index = driver };
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 -- Sanity check
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 -- Fun fact: 09:00 and 21:00 en_HK are both "09:00:00 UTC"
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local t = os_date("!*t");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 t.hour = 9;
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
22 local am = os_date("!%X", os.time(t));
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 t.hour = 21;
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
24 local pm = os_date("!%X", os.time(t));
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 if am == pm then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 module:log("warn", "Timestamps in AM and PM are identical in your locale, expect timestamps to be wrong");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
1569
711fabfe6604 mod_storage_muc_log: Fix typo
Kim Alvefur <zash@zash.se>
parents: 1568
diff changeset
28 if os_date("!%X", os.time(t)) ~= os_date(timef, os.time(t)) then
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
29 module:log("warn", "Timestamp format differ from what mod_muc_log used, this module may not work correctly");
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
30 end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local function parse_silly(date, time)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local year, month, day = date:match("^(%d%d)(%d%d)(%d%d)");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 year = "20"..year;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 -- year = (year < "70" and "20" or "19") .. year;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 local hour, min, sec = time:match("(%d%d)%D+(%d%d)%D+(%d%d)");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 if hour == "12" and time:find("[Aa][Mm]") then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 hour = "00";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 elseif hour < "12" and time:find("[Pp][Mm]") then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 hour = tostring(tonumber(hour) % 12 + 12);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 return datetime.parse(("%s-%s-%sT%s:%s:%sZ"):format(year, month, day, hour or "00", min or "00", sec or "00"));
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 local function st_with(tag)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local with = tag.attr.type;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 return with and tag.name .. "<" .. with or tag.name;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 function driver:append(node, key, when, with, stanza)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 local today = os_date(datef, when);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 local now = os_date(timef, when);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 local data = data_load(node, host, datastore .. "/" .. today) or {};
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 datamanager.getpath(node, host, datastore, nil, true); -- create the datastore dir
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 local ok, err = data_store(node, host, datastore .. "/" .. today, data);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 if not ok then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 return ok, err;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 return today .. "_" .. #data;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 function driver:find(node, query)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 local path = datamanager.getpath(node, host, datastore):match("(.*)/");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 local ok, iter, state, var = pcall(lfs.dir, path);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 if not ok then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 module:log("warn", iter);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 return nil, iter;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 local dates, i = {}, 1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 for dir in iter, state, var do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 if lfs.attributes(datamanager.getpath(node, host, datastore .. "/" .. dir), "mode") == "file" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 dates[i], i = dir, i+1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 if dates[1] == nil then return noop, 0; end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 table.sort(dates);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 return coroutine.wrap(function ()
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 local query = query;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 local dates = dates;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 local start_date = query and query.start and os_date(datef, query.start) or dates[1];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 local start_time = query and query.start and os_date(timef, query.start) or dates[1];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 local end_time = query and query["end"] and os_date(timef, query["end"]) or dates[#dates];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 local query_with = query and query.with;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 local query_limit = query and query.limit;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 local seek_once = query and query.after;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 local today, time, data, err, item;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 local inner_start, inner_stop, inner_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 local outer_start, outer_stop, outer_step = 1, #dates, 1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 if query and query.reverse then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 outer_start, outer_stop, outer_step = outer_stop, outer_start, -outer_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 seek_once = query.before;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 if seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 end_date = seek_once:match"^(%d+)_%d";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 elseif seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 start_date = seek_once:match"^(%d+)_%d";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 local matches = 0;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 for i = outer_start, outer_stop, outer_step do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 today = dates[i];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 if today >= start_date and today <= end_date then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 data, err = data_load(node, host, datastore .. "/" .. today);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 if data then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 inner_start, inner_stop, inner_step = 1, #data, 1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 if query and query.reverse then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 inner_start, inner_stop, inner_step = inner_stop, inner_start, -inner_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 if seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 inner_start = tonumber(seek_once:match("_(%d+)$"));
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 inner_start = inner_start + (query and query.reverse and -1 or 1);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 seek_once = nil;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 for i = inner_start, inner_stop, inner_step do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 item, err = data[i];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 if item then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 item, err = xml_parse(item);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 if item then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 time = item.attr.time;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 item = item.tags[1];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 if (today >= start_date or time >= start_time) and
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 (today <= end_date or time <= end_time) and
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 (not query_with or query_with == st_with(item)) and
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 item:get_child_text("alreadyJoined") ~= "true" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 matches = matches + 1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 coroutine.yield(today.."_"..i, item, parse_silly(today, time));
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 if query_limit and matches >= query_limit then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 return;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 elseif err then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 module:log("warn", err);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 elseif err then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 module:log("warn", err);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 end);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 function open(_, store, typ)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 if typ ~= "archive" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 return nil, "unsupported-store";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 return setmetatable({ store = store, type = typ }, driver_mt);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 module:provides "storage";