Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 975:08628703456a
mod_muc_log_http: do some more cleanup of the code.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Mon, 08 Apr 2013 00:52:16 +0200 |
parents | 224e3745c1b3 |
children | f178318c9aeb |
comparison
equal
deleted
inserted
replaced
974:224e3745c1b3 | 975:08628703456a |
---|---|
25 local lom = require "lxp.lom"; | 25 local lom = require "lxp.lom"; |
26 local lfs = require "lfs"; | 26 local lfs = require "lfs"; |
27 local html = {}; | 27 local html = {}; |
28 local theme; | 28 local theme; |
29 | 29 |
30 -- encoding function | 30 -- Helper Functions |
31 | |
31 local p_encode = datamanager.path_encode; | 32 local p_encode = datamanager.path_encode; |
32 | 33 local function store_exists(node, host, today) |
33 local function checkDatastorePathExists(node, host, today, create) | 34 if lfs.attributes(data_getpath(node, host, datastore .. "/" .. today), "mode") then return true; else return false; end |
34 create = create or false; | 35 end |
35 local path = data_getpath(node, host, datastore, "dat", true); | 36 |
36 path = path:gsub("/[^/]*$", ""); | 37 -- Module Definitions |
37 | |
38 -- check existance | |
39 local attributes, err = lfs.attributes(path); | |
40 if attributes == nil or attributes.mode ~= "directory" then | |
41 module:log("warn", "muc_log folder isn't a folder: %s", path); | |
42 return false; | |
43 end | |
44 | |
45 attributes, err = lfs.attributes(path .. "/" .. today); | |
46 if attributes == nil then | |
47 if create then | |
48 return lfs.mkdir(path .. "/" .. today); | |
49 else | |
50 return false; | |
51 end | |
52 elseif attributes.mode == "directory" then | |
53 return true; | |
54 end | |
55 return false; | |
56 end | |
57 | 38 |
58 local function htmlEscape(t) | 39 local function htmlEscape(t) |
59 if t then | 40 if t then |
60 t = t:gsub("<", "<"); | 41 t = t:gsub("<", "<"); |
61 t = t:gsub(">", ">"); | 42 t = t:gsub(">", ">"); |
463 local node, host, resource = splitJid(bareRoomJid); | 444 local node, host, resource = splitJid(bareRoomJid); |
464 local day = incrementDay(bare_day); | 445 local day = incrementDay(bare_day); |
465 local max_trys = 7; | 446 local max_trys = 7; |
466 | 447 |
467 module:log("debug", day); | 448 module:log("debug", day); |
468 while(not checkDatastorePathExists(node, host, day, false)) do | 449 while(not store_exists(node, host, day)) do |
469 max_trys = max_trys - 1; | 450 max_trys = max_trys - 1; |
470 if max_trys == 0 then | 451 if max_trys == 0 then |
471 break; | 452 break; |
472 end | 453 end |
473 day = incrementDay(day); | 454 day = incrementDay(day); |
520 local function findPreviousDay(bareRoomJid, bare_day) | 501 local function findPreviousDay(bareRoomJid, bare_day) |
521 local node, host, resource = splitJid(bareRoomJid); | 502 local node, host, resource = splitJid(bareRoomJid); |
522 local day = decrementDay(bare_day); | 503 local day = decrementDay(bare_day); |
523 local max_trys = 7; | 504 local max_trys = 7; |
524 module:log("debug", day); | 505 module:log("debug", day); |
525 while(not checkDatastorePathExists(node, host, day, false)) do | 506 while(not store_exists(node, host, day)) do |
526 max_trys = max_trys - 1; | 507 max_trys = max_trys - 1; |
527 if max_trys == 0 then | 508 if max_trys == 0 then |
528 break; | 509 break; |
529 end | 510 end |
530 day = decrementDay(day); | 511 day = decrementDay(day); |