diff options
-rw-r--r-- | app/acf_www-controller.lua | 31 | ||||
-rwxr-xr-x | www/cgi-bin/acf | 2 | ||||
-rwxr-xr-x | www/cgi-bin/mvc.lua | 30 |
3 files changed, 41 insertions, 22 deletions
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index 2a54620..54cab87 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -65,6 +65,8 @@ mvc.on_load = function (self, parent) -- open the log file self.conf.logfile = io.open ("/var/log/acf.log", "a+") + --logevent("acf_www-controller mvc.on_load") + -- Make sure we have some kind of sane defaults for libdir and sessiondir self.conf.libdir = self.conf.libdir or ( self.conf.appdir .. "/lib/" ) self.conf.sessiondir = self.conf.sessiondir or "/tmp/" @@ -124,6 +126,16 @@ mvc.on_load = function (self, parent) end end +mvc.on_unload = function (self) + sessionlib=require ("session") + if sessiondata.id then + sessionlib.save_session(conf.sessiondir, sessiondata) + end + -- Close the logfile + --logevent("acf_www-controller mvc.on_unload") + conf.logfile:close() +end + mvc.check_permission = function(self, controller, action) logevent("Trying " .. (controller or "nil") .. ":" .. (action or "nil")) if nil == self.sessiondata.permissions then return false end @@ -134,16 +146,6 @@ mvc.check_permission = function(self, controller, action) return true end -mvc.post_exec = function (self) - sessionlib=require ("session") - if sessiondata.id then - sessionlib.save_session(conf.sessiondir, sessiondata) - end - -- Close the logfile - conf.logfile:close() -end - - -- look for a template -- ctlr-action-view, then ctlr-view, then action-view, then view @@ -211,7 +213,7 @@ view_resolver = function(self) -- *************************************************** local m,worker_loaded,model_loaded = self:new("alpine-baselayout/hostname") - local alpineversion = self:new("alpine-baselayout/alpineversion") + --local alpineversion = self:new("alpine-baselayout/alpineversion") -- If the worker and model loaded correctly, then -- use the sub-controller @@ -235,6 +237,8 @@ view_resolver = function(self) skin = self.conf.skin or "" } + m:destroy() + return function (viewtable) local template = haserl.loadfile (template) return template ( pageinfo, viewtable, self.sessiondata ) @@ -251,12 +255,9 @@ end exception_handler = function (self, message ) local html = require ("html") - pcall(function() - if sessiondata.id then logevent("Redirecting " .. sessiondata.id) end - mvc.post_exec (self) - end) -- don't want exceptions from this if type(message) == "table" then if message.type == "redir" then + if sessiondata.id then logevent("Redirecting " .. sessiondata.id) end io.write ("Status: 302 Moved\n") io.write ("Location: " .. ENV["SCRIPT_NAME"] .. message.prefix .. message.controller .. diff --git a/www/cgi-bin/acf b/www/cgi-bin/acf index dc5373c..9d6a150 100755 --- a/www/cgi-bin/acf +++ b/www/cgi-bin/acf @@ -16,4 +16,6 @@ APP=FRAMEWORK:new("acf_www") -- Dispatch the application APP:dispatch() +APP:destroy() +FRAMEWORK:destroy() ?> diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua index 1fa88da..c64fa08 100755 --- a/www/cgi-bin/mvc.lua +++ b/www/cgi-bin/mvc.lua @@ -96,9 +96,16 @@ new = function (self, modname) return c, worker_loaded, model_loaded end +destroy = function (self) + if type(rawget(self.worker.mvc, "on_unload")) == "function" then + self.worker.mvc.on_unload(self) + self.worker.mvc.on_unload = nil + end +end + -- This is a sample front controller/dispatch. dispatch = function (self, userprefix, userctlr, useraction) - local controller + local controller = nil local success, err = xpcall ( function () if userprefix == nil then @@ -112,7 +119,6 @@ dispatch = function (self, userprefix, userctlr, useraction) -- Find the proper controller/action combo local origconf = {controller = self.conf.controller, action = self.conf.action} - local controller = nil local action = "" self.conf.default_controller = self.conf.default_controller or "" self.conf.default_prefix = self.conf.default_prefix or "" @@ -161,7 +167,10 @@ dispatch = function (self, userprefix, userctlr, useraction) end if "" ~= action then break end end - controller = nil + if controller then + controller:destroy() + controller = nil + end self.conf.action = "" if self.conf.controller ~= self.conf.default_controller then self.conf.prefix = self.conf.default_prefix @@ -192,15 +201,17 @@ dispatch = function (self, userprefix, userctlr, useraction) -- run the action local viewtable = controller.worker[action](controller) - -- run the post_exec code if type(controller.worker.mvc.post_exec) == "function" then controller.worker.mvc.post_exec ( controller ) end - local viewfunc = controller.worker:view_resolver(viewtable) + -- we're done with the controller, destroy it + controller:destroy() + controller = nil + viewfunc (viewtable) end, self:soft_traceback(message) @@ -210,9 +221,14 @@ dispatch = function (self, userprefix, userctlr, useraction) local handler if controller then handler = controller.worker or controller + if handler then handler:exception_handler(err) end + controller:destroy() + controller = nil + end + if nil == handler then + handler = self.worker or mvc + handler:exception_handler(err) end - handler = handler or self.worker or mvc - handler:exception_handler(err) end end |