Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 382:19469f3ad6d6
mod_muc_log_http: Cleaned up URL parsing.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 02:21:40 +0500 |
parents | f932dc371ce7 |
children | 4099f0837936 |
comparison
equal
deleted
inserted
replaced
381:f932dc371ce7 | 382:19469f3ad6d6 |
---|---|
98 t = ""; | 98 t = ""; |
99 end | 99 end |
100 return t; | 100 return t; |
101 end | 101 end |
102 | 102 |
103 function splitUrl(url) | |
104 local tmp = url:sub(string.len("/muc_log/") + 1); | |
105 local day = nil; | |
106 local room = nil; | |
107 local component = nil; | |
108 local at = nil; | |
109 local slash = nil; | |
110 local slash2 = nil; | |
111 | |
112 slash = tmp:find("/"); | |
113 if slash then | |
114 component = tmp:sub(1, slash - 1); | |
115 if tmp:len() > slash then | |
116 room = tmp:sub(slash + 1); | |
117 slash = room:find("/"); | |
118 if slash then | |
119 tmp = room; | |
120 room = tmp:sub(1, slash - 1); | |
121 if tmp:len() > slash then | |
122 day = tmp:sub(slash + 1); | |
123 slash = day:find("/"); | |
124 if slash then | |
125 day = day:sub(1, slash - 1); | |
126 end | |
127 end | |
128 end | |
129 end | |
130 end | |
131 | |
132 return room, component, day; | |
133 end | |
134 | |
135 local function generateComponentListSiteContent() | 103 local function generateComponentListSiteContent() |
136 local components = ""; | 104 local components = ""; |
137 for component,muc_host in pairs(muc_hosts or {}) do | 105 for component,muc_host in pairs(muc_hosts or {}) do |
138 components = components .. html.components.bit:gsub("###COMPONENT###", component); | 106 components = components .. html.components.bit:gsub("###COMPONENT###", component); |
139 end | 107 end |
691 end | 659 end |
692 end | 660 end |
693 end | 661 end |
694 | 662 |
695 function handle_request(method, body, request) | 663 function handle_request(method, body, request) |
696 local node, host, day = splitUrl(request.url.path); | 664 local host, node, day = request.url.path:match("^/muc_log/([^/]*)/?([^/]*)/?([^/]*)/?$"); |
665 if host == "" then host = nil; end | |
666 if node == "" then node = nil; end | |
667 if day == "" then day = nil; end | |
697 | 668 |
698 node = urldecode(node); | 669 node = urldecode(node); |
699 | 670 |
700 if muc_hosts ~= nil and html.doc ~= nil then | 671 if muc_hosts ~= nil and html.doc ~= nil then |
701 if node ~= nil and host ~= nil then | 672 if node ~= nil and host ~= nil then |