diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-12-28 10:32:40 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-12-28 10:32:40 +0000 |
commit | 2678d43e1f155b2b692c729bb0470967072a8d58 (patch) | |
tree | 3eb10f930770897e028bac3079d7eb46e5a481c8 /app | |
parent | bd7a0266eb07cb8859fa7518f0000ef0240923d6 (diff) | |
download | acf-core-2678d43e1f155b2b692c729bb0470967072a8d58.tar.bz2 acf-core-2678d43e1f155b2b692c729bb0470967072a8d58.tar.xz |
Removed redundant/buggy basename and dirname functions. Added parse_redir_string to www controller.
Removed basename and dirname from mvc and fs, use posix functions instead.
parse_path_info was buggy and used 2 ways, rewrote and created parse_redir_string for backwards parsing.
Diffstat (limited to 'app')
-rw-r--r-- | app/acf-util/logon-controller.lua | 4 | ||||
-rw-r--r-- | app/acf_www-controller.lua | 35 |
2 files changed, 30 insertions, 9 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua index f1fa93d..165bedb 100644 --- a/app/acf-util/logon-controller.lua +++ b/app/acf-util/logon-controller.lua @@ -34,8 +34,8 @@ logon = function(self) if logon.value then -- only copy the logonredirect if redirecting to that page if logonredirect and cmdresult.value.redir.value then - local prefix, controller, action = self.parse_path_info("/"..cmdresult.value.redir.value) - if logonredirect.action == action and logonredirect.controller == controller then + local prefix, controller, action = self.parse_redir_string(cmdresult.value.redir.value) + if logonredirect.action == action and logonredirect.controller == controller and logonredirect.prefix == prefix then self.sessiondata.logonredirect = logonredirect end end diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index ee7f344..2913f1e 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -66,7 +66,7 @@ local check_permission = function(self, prefix, controller, action) end local check_permission_string = function (self, str) - local prefix, controller, action = self.parse_path_info("/" .. (str or "")) + local prefix, controller, action = parse_redir_string(str) if prefix == "/" then prefix = self.conf.prefix end if controller == "" then controller = self.conf.controller end @@ -98,10 +98,10 @@ find_template = function ( appdir, prefix, controller, action, viewtype ) end end -- not found, so try one level higher - if prefix == "" then -- already at the top level - fail + if prefix == "." then -- already at the top level - fail return nil end - prefix = dirname (prefix) + prefix = posix.dirname (prefix) return find_template ( appdir, prefix, controller, action, viewtype ) end @@ -145,7 +145,7 @@ local dispatch_component = function(self, str, clientdata, suppress_view) self.clientdata = clientdata or {} self.clientdata.sessionid = tempclientdata.sessionid - local prefix, controller, action = self.parse_path_info("/" .. str) + local prefix, controller, action = parse_redir_string(str) if prefix == "/" then prefix = self.conf.prefix end if controller == "" then controller = self.conf.controller end local viewtable = self.dispatch(self, prefix, controller, action) @@ -332,6 +332,7 @@ exception_handler = function (self, message ) parent_exception_handler(self, message) end else + logevent("Exception: "..message) viewtable = {message = message} self.conf.prefix = "/" self.conf.controller = "exception" @@ -373,7 +374,8 @@ dispatch = function (self, userprefix, userctlr, useraction) end -- This is for get / post data saved for after logon - if self.sessiondata.logonredirect and self.conf.controller == self.sessiondata.logonredirect.controller + if self.sessiondata.logonredirect and self.conf.prefix == self.sessiondata.logonredirect.prefix + and self.conf.controller == self.sessiondata.logonredirect.controller and self.conf.action == self.sessiondata.logonredirect.action then ENV.HTTP_REFERER = self.sessiondata.logonredirect.referrer or ENV.HTTP_REFERER self.clientdata = self.sessiondata.logonredirect.clientdata @@ -481,7 +483,7 @@ redirect = function (self, str, result) if result then self.sessiondata[self.conf.action.."result"] = result end - local prefix, controller, action = self.parse_path_info("/" .. (str or "")) + local prefix, controller, action = parse_redir_string(str) if prefix ~= "/" then self.conf.prefix = prefix end if controller ~= "" then self.conf.controller = controller end @@ -506,7 +508,7 @@ redirect_to_referrer = function(self, result) end else local prefix, controller, action = self.parse_path_info(ENV.HTTP_REFERER:gsub("%?.*", "")) - if controller ~= self.conf.controller or action ~= self.conf.action then + if prefix ~= self.conf.prefix or controller ~= self.conf.controller or action ~= self.conf.action then self.sessiondata[self.conf.action.."result"] = result error({type="redir_to_referrer"}) end @@ -520,6 +522,25 @@ redirect_to_referrer = function(self, result) return result end +-- parse a "URI" like string into a prefix, controller and action +-- this is the same as URI string, but opposite preference +-- if only one is defined, it's assumed to be the action +parse_redir_string = function( str ) + str = str or "" + str = string.gsub(str, "/+$", "") + local action = string.match(str, "[^/]+$") or "" + str = string.gsub(str, "/*[^/]*$", "") + local controller = string.match(str, "[^/]+$") or "" + str = string.gsub(str, "/*[^/]*$", "") + local prefix = string.match(str, "[^/]+$") or "" + if prefix == "" then + prefix = "/" + else + prefix = "/"..prefix.."/" + end + return prefix, controller, action +end + -- FIXME - need to think more about this.. logevent = function ( message ) conf.logfile:write (string.format("%s: %s\n", os.date(), message or "")) |