Changeset

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 381:f932dc371ce7
children 383:4099f0837936
files mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
diffstat 1 files changed, 4 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Mon Jul 25 02:21:40 2011 +0500
+++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Mon Jul 25 02:21:40 2011 +0500
@@ -100,38 +100,6 @@
 	return t;
 end
 
-function splitUrl(url)
-	local tmp = url:sub(string.len("/muc_log/") + 1);
-	local day = nil;
-	local room = nil;
-	local component = nil;
-	local at = nil;
-	local slash = nil;
-	local slash2 = nil;
-
-	slash = tmp:find("/");
-	if slash then
-		component = tmp:sub(1, slash - 1);
-		if tmp:len() > slash then
-			room = tmp:sub(slash + 1);
-			slash = room:find("/");
-			if slash then
-				tmp = room;
-				room = tmp:sub(1, slash - 1);
-				if tmp:len() > slash then
-					day = tmp:sub(slash + 1);
-					slash = day:find("/");
-					if slash then
-						day = day:sub(1, slash - 1);
-					end
-				end
-			end
-		end
-	end
-
-	return room, component, day;
-end
-
 local function generateComponentListSiteContent()
 	local components = "";
 	for component,muc_host in pairs(muc_hosts or {}) do
@@ -693,7 +661,10 @@
 end
 
 function handle_request(method, body, request)
-	local node, host, day = splitUrl(request.url.path);
+	local host, node, day = request.url.path:match("^/muc_log/([^/]*)/?([^/]*)/?([^/]*)/?$");
+	if host == "" then host = nil; end
+	if node == "" then node = nil; end
+	if day  == "" then day  = nil; end
 
 	node = urldecode(node);