Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 384:79983e658bb5
mod_muc_log_http: Cleaned up URL handling.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 02:21:40 +0500 |
parents | 4099f0837936 |
children | fec9bc52aa42 |
comparison
equal
deleted
inserted
replaced
383:4099f0837936 | 384:79983e658bb5 |
---|---|
658 end | 658 end |
659 end | 659 end |
660 end | 660 end |
661 | 661 |
662 function handle_request(method, body, request) | 662 function handle_request(method, body, request) |
663 local host, node, day = request.url.path:match("^/muc_log/([^/]*)/?([^/]*)/?([^/]*)/?$"); | 663 local host, node, day, more = request.url.path:match("^/muc_log/+([^/]*)/*([^/]*)/*([^/]*)/*(.*)$"); |
664 if more ~= "" then return { status = "404 Not found", body = "Unknown URL" }; end | |
664 if host == "" then host = nil; end | 665 if host == "" then host = nil; end |
665 if node == "" then node = nil; end | 666 if node == "" then node = nil; end |
666 if day == "" then day = nil; end | 667 if day == "" then day = nil; end |
667 | 668 |
668 node = urldecode(node); | 669 node = urldecode(node); |
669 | 670 |
670 if muc_hosts ~= nil and html.doc ~= nil then | 671 assert(muc_hosts and html.doc, "MUC hosts or theme not loaded"); |
671 if node ~= nil and host ~= nil then | 672 |
672 local bare = node .. "@" .. host; | 673 if host and not(hosts[host] and hosts[host].modules.muc) then return { status = "404 Not found", body = "No such MUC component" }; end |
673 if prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil then | 674 if host and node and not(muc_hosts[host].modules.muc.rooms[node.."@"..host]) then return { status = "404 Not found", body = "No such MUC room" }; end |
674 if prosody.hosts[host].muc.rooms[bare] ~= nil then | 675 |
675 local room = prosody.hosts[host].muc.rooms[bare]; | 676 if not host then -- main component list |
676 if day == nil then | 677 return createDoc(generateComponentListSiteContent()); |
677 return createDoc(generateDayListSiteContentByRoom(bare)); | 678 elseif not node then -- room list for component |
678 else | 679 return createDoc(generateRoomListSiteContent(host)); |
679 local subject = "" | 680 elseif not day then -- room's listing |
680 if room._data ~= nil and room._data.subject ~= nil then | 681 return createDoc(generateDayListSiteContentByRoom(node.."@"..host)); |
681 subject = room._data.subject; | 682 else |
682 end | 683 local room = muc_hosts[host].modules.muc.rooms[node.."@"..host]; |
683 return createDoc(parseDay(bare, subject, day)); | 684 return createDoc(parseDay(node.."@"..host, room._data.subject or "", day:gsub("%-", ""))); |
684 end | 685 end |
685 else | |
686 return createDoc(generateRoomListSiteContent(host)); | |
687 end | |
688 else | |
689 return createDoc(generateComponentListSiteContent()); | |
690 end | |
691 elseif host ~= nil then | |
692 return createDoc(generateRoomListSiteContent(host)); | |
693 else | |
694 return createDoc(generateComponentListSiteContent()); | |
695 end | |
696 end | |
697 return; | |
698 end | 686 end |
699 | 687 |
700 -- Compatibility: Lua-5.1 | 688 -- Compatibility: Lua-5.1 |
701 function split(str, pat) | 689 function split(str, pat) |
702 local t = {} -- NOTE: use {n = 0} in Lua-5.0 | 690 local t = {} -- NOTE: use {n = 0} in Lua-5.0 |