Mercurial > prosody-modules
annotate mod_storage_muc_log/mod_storage_muc_log.lua @ 2249:d3e697c141e4
mod_cloud_notify/README: Let's call it Beta
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Jul 2016 11:49:49 +0200 |
parents | e72f9eac51c8 |
children | 49a01b78b45f |
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 | 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 |
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:
1569
diff
changeset
|
51 function driver:append(node, key, stanza, 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:
1569
diff
changeset
|
52 if type(when) ~= "number" then |
1760
e72f9eac51c8
mod_storage_(various): Order swapping in 54c8a0cb2996 was backwards
Kim Alvefur <zash@zash.se>
parents:
1759
diff
changeset
|
53 when, with, stanza = stanza, 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:
1569
diff
changeset
|
54 end |
1566
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 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
|
65 end |
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 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
|
68 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
|
69 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 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
|
83 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
|
84 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
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 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
|
106 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
|
107 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 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
|
124 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
|
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 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
|
127 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 (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
|
133 (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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 return; |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 end |
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 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
|
142 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
|
143 end |
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 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
|
146 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
|
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 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 end); |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 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
|
158 end |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 |
9158882dd9a1
mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 module:provides "storage"; |