0 Nˆl–ßi~” ji?u @†àq·”Å£�þ[hm,Ùdx ×##Àþ „\qïÁa–Ü4ý( ©¤ýÔ†ÆY¸ÐTÅ£À?÷---------------------------------------------------------------------------- -- CGILua library. -- -- @release $Id: cgilua.lua,v 1.85 2009/06/28 22:42:34 tomas Exp $ ---------------------------------------------------------------------------- local _G = assert(_G) local urlcode = require"cgilua.urlcode" local lp = require"cgilua.lp" local lfs = require"lfs" local debug = require"debug" local assert, error, ipairs, select, tostring, type, unpack, xpcall = assert, error, ipairs, select, tostring, type, unpack, xpcall local pairs = pairs local gsub, format, strfind, strlower, strsub, match = string.gsub, string.format, string.find, string.lower, string.sub, string.match local setmetatable = setmetatable local _open = io.open local tinsert, tremove, concat = table.insert, table.remove, table.concat local date = os.date local os_tmpname = os.tmpname local getenv = os.getenv local remove = os.remove local seeall = package.seeall lp.setoutfunc ("cgilua.put") lp.setcompatmode (true) local M = { _COPYRIGHT = "Copyright (C) 2003-2013 Kepler Project", _DESCRIPTION = "CGILua is a tool for creating dynamic Web pages and manipulating input data from forms", _VERSION = "CGILua 5.2", } -- -- Internal state variables. local SAPI local _default_errorhandler = debug.traceback local _errorhandler = _default_errorhandler local _default_erroroutput = function (msg) if type(msg) ~= "string" and type(msg) ~= "number" then msg = format ("bad argument #1 to 'error' (string expected, got %s)", type(msg)) end -- Logging error SAPI.Response.errorlog (msg) SAPI.Response.errorlog (" ") SAPI.Response.errorlog (SAPI.Request.servervariable"REMOTE_ADDR") SAPI.Response.errorlog (" ") SAPI.Response.errorlog (date()) SAPI.Response.errorlog ("\n") -- Building user message msg = gsub (gsub (msg, "\n", "
\n"), "\t", "  ") SAPI.Response.contenttype ("text/html") SAPI.Response.write ("CGILua Error" .. msg .. "") end local _erroroutput = _default_erroroutput local _default_maxfilesize = 512 * 1024 local _maxfilesize = _default_maxfilesize local _default_maxinput = 1024 * 1024 local _maxinput = _default_maxinput M.script_path = false -- -- Header functions ---------------------------------------------------------------------------- -- Sends a header. -- @name header -- @class function -- @param header String with the header. -- @param value String with the corresponding value. ---------------------------------------------------------------------------- function M.header (...) return SAPI.Response.header (...) end ---------------------------------------------------------------------------- -- Sends a Content-type header. -- @param type String with the type of the header. -- @param subtype String with the subtype of the header. ---------------------------------------------------------------------------- function M.contentheader (type, subtype) SAPI.Response.contenttype (type..'/'..subtype) end ---------------------------------------------------------------------------- -- Sends the HTTP header "text/html". ---------------------------------------------------------------------------- function M.htmlheader() SAPI.Response.contenttype ("text/html") end ---------------------------------------------------------------------------- -- Sends an HTTP header redirecting the browser to another URL -- @param url String with the URL. -- @param args Table with the arguments (optional). ---------------------------------------------------------------------------- function M.redirect (url, args) if strfind(url,"^https?:") then local params="" if args then params = "?"..urlcode.encodetable(args) end return SAPI.Response.redirect(url..params) else return SAPI.Response.redirect(M.mkabsoluteurl(M.mkurlpath(url,args))) end end ---------------------------------------------------------------------------- -- Returns a server variable -- @name servervariable -- @class function -