# HG changeset patch # User Thilo Cestonaro # Date 1255961208 -7200 # Node ID d9749ed44f6e5152b788aa29d07681b7943c6636 # Parent f15108153710ce3f37c8a734a935db370764fdc7 mod_muc_log: make it recognize s2s messages/presences diff -r f15108153710 -r d9749ed44f6e mod_muc_log/mod_muc_log.lua --- a/mod_muc_log/mod_muc_log.lua Sun Oct 18 23:26:15 2009 +0100 +++ b/mod_muc_log/mod_muc_log.lua Mon Oct 19 16:06:48 2009 +0200 @@ -20,7 +20,6 @@ local lom = require "lxp.lom"; function validateLogFolder() - module:log("debug", "validateLogFolder; Folder: %s", tostring(config.folder)); if config.folder == nil then module:log("warn", "muc_log folder isn't configured. configure it please!"); return false; @@ -36,7 +35,6 @@ return false; end --TODO: check for write rights! - module:log("debug", "Folder is validated and correct.") return true; end @@ -46,43 +44,40 @@ return; end - if (stanza.name == "presence") or - (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") + if (stanza.name == "presence") or + (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") then local node, host, resource = splitJid(stanza.attr.to); if node ~= nil and host ~= nil then local bare = node .. "@" .. host; if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then local room = prosody.hosts[host].muc.rooms[bare] - local logging = config_get(host, "core", "logging"); - if logging == true then - local today = os.date("%y%m%d"); - local now = os.date("%X") - local fn = config.folder .. "/" .. today .. "_" .. bare .. ".log"; - local mucFrom = nil; - - if stanza.name == "presence" and stanza.attr.type == nil then - mucFrom = stanza.attr.to; - else - for jid, nick in pairs(room._jid_nick) do - if jid == stanza.attr.from then - mucFrom = nick; - end + local today = os.date("%y%m%d"); + local now = os.date("%X") + local fn = config.folder .. "/" .. today .. "_" .. bare .. ".log"; + local mucFrom = nil; + + if stanza.name == "presence" and stanza.attr.type == nil then + mucFrom = stanza.attr.to; + else + for jid, nick in pairs(room._jid_nick) do + if jid == stanza.attr.from then + mucFrom = nick; end end + end - if mucFrom ~= nil then - module:log("debug", "try to open room log: %s", fn); - local f = assert(io.open(fn, "a")); - local realFrom = stanza.attr.from; - local realTo = stanza.attr.to; - stanza.attr.from = mucFrom; - stanza.attr.to = nil; - f:write("" .. tostring(stanza) .. "\n"); - stanza.attr.from = realFrom; - stanza.attr.to = realTo; - f:close() - end + if mucFrom ~= nil then + module:log("debug", "try to open room log: %s", fn); + local f = assert(io.open(fn, "a")); + local realFrom = stanza.attr.from; + local realTo = stanza.attr.to; + stanza.attr.from = mucFrom; + stanza.attr.to = nil; + f:write("" .. tostring(stanza) .. "\n"); + stanza.attr.from = realFrom; + stanza.attr.to = realTo; + f:close() end end end @@ -149,13 +144,8 @@ local ret = "

Rooms hosted on this server:


"; for host, config in pairs(prosody.hosts) do if prosody.hosts[host].muc ~= nil then - local logging = config_get(host, "core", "logging"); - if logging then - for jid, room in pairs(prosody.hosts[host].muc.rooms) do - ret = ret .. "" .. jid .."
\n"; - end - else - module:log("debug", "logging not enabled for muc component: %s", tostring(host)); + for jid, room in pairs(prosody.hosts[host].muc.rooms) do + ret = ret .. "" .. jid .."
\n"; end end end @@ -167,7 +157,6 @@ for file in lfs.dir(config.folder) do local year, month, day = file:match("^(%d%d)(%d%d)(%d%d)_" .. bareRoomJid .. ".log"); - module:log("debug", "year: %s, month: %s, day: %s", year, month, day); if year ~= nil and month ~= nil and day ~= nil and year ~= "" and month ~= "" and day ~= "" then @@ -209,9 +198,8 @@ local parsed = lom.parse("" .. content .. ""); if parsed ~= nil then for _,stanza in ipairs(parsed) do - -- module:log("debug", "dump of stanza: \n%s", dump(stanza)) if stanza.attr ~= nil and stanza.attr.time ~= nil then - ret = ret .. "[" .. stanza.attr.time .. "] "; + local tmp = "[" .. stanza.attr.time .. "] "; if stanza[1] ~= nil then local nick; if stanza[1].attr.from ~= nil then @@ -219,11 +207,11 @@ end if stanza[1].tag == "presence" and nick ~= nil then if stanza[1].attr.type == nil then - ret = ret .. " *** " .. nick .. " joins the room
\n"; + ret = ret .. tmp .. " *** " .. nick .. " joins the room
\n"; elseif stanza[1].attr.type ~= nil and stanza[1].attr.type == "unavailable" then - ret = ret .. " *** " .. nick .. " leaves the room
\n"; + ret = ret .. tmp .. " *** " .. nick .. " leaves the room
\n"; else - ret = ret .. " *** " .. nick .. " changed his/her status to: " .. stanza[1].attr.type .. "
\n"; + ret = ret .. tmp .. " *** " .. nick .. " changed his/her status to: " .. stanza[1].attr.type .. "
\n"; end elseif stanza[1].tag == "message" then local body; @@ -241,7 +229,7 @@ end end if nick ~= nil and body ~= nil then - ret = ret .. "<" .. nick .. "> " .. body .. "
\n"; + ret = ret .. tmp .. "<" .. nick .. "> " .. body .. "
\n"; end else module:log("info", "unknown stanza subtag in log found. room: %s; day: %s", bareRoomJid, year .. "/" .. month .. "/" .. day); @@ -263,8 +251,6 @@ end function handle_request(method, body, request) - module:log("debug", "method: %s, body: %s, request: %s", tostring(method), tostring(body), tostring(request)); - -- module:log("debug", "dump of request:\n%s\n", dump(request)); local query = splitQuery(request.url.query); local node, host = grepRoomJid(request.url.path); @@ -283,18 +269,13 @@ local bare = node .. "@" .. host; if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then local room = prosody.hosts[host].muc.rooms[bare]; - local logging = config_get(host, "core", "logging"); - if logging == true then - if request.url.query == nil then - return createDoc(generateDayListSiteContentByRoom(bare)); - else - return createDoc(parseDay(bare, query)); - end + if request.url.query == nil then + return createDoc(generateDayListSiteContentByRoom(bare)); else - module:log("debug", "logging not enabled for this room: %s", bare); + return createDoc(parseDay(bare, query)); end else - module:log("debug", "room instance not found. bare room jid: %s", tostring(bare)); + module:log("warn", "room instance not found. bare room jid: %s", tostring(bare)); end else return createDoc(generateRoomListSiteContent()); @@ -302,13 +283,11 @@ return; end -function module.load() - config = config_get("*", "core", "muc_log"); - -- module:log("debug", "muc_log config: \n%s", dump(config)); - - httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" }); - return validateLogFolder(); -end +config = config_get(module:get_host(), "core", "muc_log"); + +httpserver.new_from_config({ config.http_port or true }, handle_request, { base = "muc_log" }); +module:hook("message/bare", logIfNeeded, 500); module:hook("pre-message/bare", logIfNeeded, 500); +module:hook("presence/full", logIfNeeded, 500); module:hook("pre-presence/full", logIfNeeded, 500);