Mercurial > prosody-modules
comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 1742:ec50cecc9318
mod_storage_xmlarchive: Store timestamps in text form, I don't trust numeric timestamps in Lua
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 18 May 2015 02:46:41 +0200 |
| parents | 07ceaf5f6f0d |
| children | 3f3689a16133 |
comparison
equal
deleted
inserted
replaced
| 1741:07ceaf5f6f0d | 1742:ec50cecc9318 |
|---|---|
| 48 ok, err = fallocate(f, offset, #data); if not ok then return nil, err; end | 48 ok, err = fallocate(f, offset, #data); if not ok then return nil, err; end |
| 49 ok, err = f:write(data); if not ok then return nil, err; end | 49 ok, err = f:write(data); if not ok then return nil, err; end |
| 50 ok, err = f:close(); if not ok then return nil, err; end | 50 ok, err = f:close(); if not ok then return nil, err; end |
| 51 | 51 |
| 52 local id = day .. "-" .. hmac_sha256(username.."@"..day.."+"..offset, data, true):sub(-16); | 52 local id = day .. "-" .. hmac_sha256(username.."@"..day.."+"..offset, data, true):sub(-16); |
| 53 ok, err = dm.list_append(username.."@"..day, module.host, self.store, { id = id, when = when, with = with, offset = offset, length = #data }); | 53 ok, err = dm.list_append(username.."@"..day, module.host, self.store, { id = id, when = dt.datetime(when), with = with, offset = offset, length = #data }); |
| 54 if not ok then return nil, err; end | 54 if not ok then return nil, err; end |
| 55 return id; | 55 return id; |
| 56 end | 56 end |
| 57 | 57 |
| 58 function archive:find(username, query) | 58 function archive:find(username, query) |
| 131 | 131 |
| 132 local q_with, q_start, q_end = query.with, query.start, query["end"]; | 132 local q_with, q_start, q_end = query.with, query.start, query["end"]; |
| 133 for i = first_item, last_item, step do | 133 for i = first_item, last_item, step do |
| 134 local item = items[i]; | 134 local item = items[i]; |
| 135 local i_when, i_with = item.when, item.with; | 135 local i_when, i_with = item.when, item.with; |
| 136 if type(i_when) == "string" then | |
| 137 i_when = dt.parse(i_when); | |
| 138 end | |
| 139 if type(i_when) ~= "number" then | |
| 140 module:log("warn", "data[%q][%d].when is invalid", dates[d], i); | |
| 141 break; | |
| 142 end | |
| 136 if not item then | 143 if not item then |
| 137 module:log("warn", "data[%q][%d] is nil", dates[d], i); | 144 module:log("warn", "data[%q][%d] is nil", dates[d], i); |
| 138 break; | 145 break; |
| 139 end | 146 end |
| 140 if xmlfile and in_range | 147 if xmlfile and in_range |
