more cleanup in classpath; http renamed to cgi
authorTimm S. Mueller <tmueller@neoscientists.org>
Sun, 20 May 2007 21:16:54 +0200
changeset 189efb1bd425c56
parent 188 77f536d09f08
child 190 fec8f9cad093
more cleanup in classpath; http renamed to cgi
cgi-bin/Makefile
cgi-bin/tek/app/loona.lua
cgi-bin/tek/class/cgi.lua
cgi-bin/tek/class/cgi/request.lua
cgi-bin/tek/class/http.lua
cgi-bin/tek/class/http/header.lua
cgi-bin/tek/class/http/request.lua
cgi-bin/tek/class/loona.lua
cgi-bin/tek/class/loona/markup.lua
cgi-bin/tek/class/loona/util.lua
extensions/checkaccept.lua
extensions/search.lua
     1.1 --- a/cgi-bin/Makefile	Sun May 20 18:28:42 2007 +0200
     1.2 +++ b/cgi-bin/Makefile	Sun May 20 21:16:54 2007 +0200
     1.3 @@ -27,14 +27,13 @@
     1.4  
     1.5  install: tek/lib/luahtml.so tek/os/posix.so
     1.6  	-install -d $(INSTPATH)/tek/app $(INSTPATH)/tek/lib $(INSTPATH)/tek/os
     1.7 -	-install -d $(INSTPATH)/tek/class/http $(INSTPATH)/tek/class/loona
     1.8 +	-install -d $(INSTPATH)/tek/class/cgi $(INSTPATH)/tek/class/loona
     1.9  	-install -s tek/lib/*.so $(INSTPATH)/tek/lib
    1.10  	-install -s tek/os/*.so $(INSTPATH)/tek/os
    1.11  	-luac -s -o $(INSTPATH)/tek/lib.lua tek/lib.lua
    1.12  	-luac -s -o $(INSTPATH)/tek/app/loona.lua tek/app/loona.lua
    1.13 -	-luac -s -o $(INSTPATH)/tek/class/http.lua tek/class/http.lua
    1.14 -	-luac -s -o $(INSTPATH)/tek/class/http/header.lua tek/class/http/header.lua
    1.15 -	-luac -s -o $(INSTPATH)/tek/class/http/request.lua tek/class/http/request.lua
    1.16 +	-luac -s -o $(INSTPATH)/tek/class/cgi.lua tek/class/cgi.lua
    1.17 +	-luac -s -o $(INSTPATH)/tek/class/cgi/request.lua tek/class/cgi/request.lua
    1.18  	-luac -s -o $(INSTPATH)/tek/class/loona.lua tek/class/loona.lua
    1.19  	-luac -s -o $(INSTPATH)/tek/class/loona/buffer.lua tek/class/loona/buffer.lua
    1.20  	-luac -s -o $(INSTPATH)/tek/class/loona/markup.lua tek/class/loona/markup.lua
     2.1 --- a/cgi-bin/tek/app/loona.lua	Sun May 20 18:28:42 2007 +0200
     2.2 +++ b/cgi-bin/tek/app/loona.lua	Sun May 20 21:16:54 2007 +0200
     2.3 @@ -6,17 +6,17 @@
     2.4  --
     2.5  
     2.6  local lib = require "tek.lib"
     2.7 -local http = require "tek.class.http"
     2.8 -local Request = require "tek.class.http.request"
     2.9 +local Request = require "tek.class.cgi.request"
    2.10 +local Loona = require "tek.class.loona"
    2.11  local Buffer = require "tek.class.loona.buffer"
    2.12 -local require = require
    2.13 +local util = require "tek.class.loona.util"
    2.14  
    2.15  
    2.16  module "tek.app.loona"
    2.17  
    2.18  
    2.19  _VERSION = 1
    2.20 -_REVISION = 0
    2.21 +_REVISION = 1
    2.22  
    2.23  
    2.24  function main()
    2.25 @@ -26,7 +26,6 @@
    2.26  	if document.Handler then
    2.27  		local loona, detail, trace
    2.28  		res, msg, detail, trace = lib.catch(function()
    2.29 -			local Loona = require "tek.class.loona"
    2.30  			loona = Loona:new { buf = buf }
    2.31  			loona:run()
    2.32  		end)
    2.33 @@ -43,14 +42,14 @@
    2.34  </head>
    2.35  <body>
    2.36  	<h2>Error ]] .. (res or "").. [[</h2>
    2.37 -	<pre>]] .. http.encodeform(msg) .. [[</pre>
    2.38 +	<pre>]] .. util.encodeform(msg) .. [[</pre>
    2.39  ]])
    2.40 --- 			if loona and (loona.authuser or loona.config.debug) then
    2.41 + 			if loona and (loona.authuser or loona.config.debug) then
    2.42  				buf:out([[
    2.43 -	<pre>]] .. http.encodeform(detail) .. [[</pre>
    2.44 -	<pre>]] .. http.encodeform(trace) .. [[</pre>
    2.45 +	<pre>]] .. util.encodeform(detail) .. [[</pre>
    2.46 +	<pre>]] .. util.encodeform(trace) .. [[</pre>
    2.47  ]])
    2.48 --- 			end
    2.49 + 			end
    2.50  			buf:out([[
    2.51  </body>
    2.52  </html>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/cgi-bin/tek/class/cgi.lua	Sun May 20 21:16:54 2007 +0200
     3.3 @@ -0,0 +1,44 @@
     3.4 +
     3.5 +--
     3.6 +--	tek.class.cgi
     3.7 +--	Written by Timm S. Mueller <tmueller at neoscientists.org>
     3.8 +--	See copyright notice in COPYRIGHT
     3.9 +--
    3.10 +
    3.11 +local type, tonumber = type, tonumber
    3.12 +local insert, concat, char = table.insert, table.concat, string.char
    3.13 +
    3.14 +
    3.15 +module "tek.class.cgi"
    3.16 +
    3.17 +
    3.18 +_VERSION = 1
    3.19 +_REVISION = 0
    3.20 +
    3.21 +
    3.22 +function encodeurl(s, keep)
    3.23 +	local matchset = "$&+,/:;=?@" -- reserved chars with special meaning
    3.24 +	if keep then 
    3.25 +		if type(keep) == "string" then -- delete specified from set:
    3.26 +			matchset = matchset:gsub("[" .. keep:gsub(".", "%%%1") .. "]", "")
    3.27 +		elseif keep == true then -- delete whole set:
    3.28 +			matchset = "" 
    3.29 +		end
    3.30 +	end
    3.31 +	-- always substitute unsafe chars:
    3.32 +	matchset = matchset .. '"<>#%{}|\\^~[]`]'
    3.33 +	matchset = "[%z\001-\032\127-\255" .. matchset:gsub(".", "%%%1") .. "]"
    3.34 +	s = s:gsub(matchset, function(c)
    3.35 +		return ("%%%02x"):format(c:byte())
    3.36 +	end)
    3.37 +	return s
    3.38 +end
    3.39 +
    3.40 +
    3.41 +function decodeurl(s)
    3.42 +	s = s:gsub("+", " ")
    3.43 +	return s:gsub("%%(%x%x)", function(h)
    3.44 +		return char(tonumber(h, 16))
    3.45 +	end)
    3.46 +end
    3.47 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/cgi-bin/tek/class/cgi/request.lua	Sun May 20 21:16:54 2007 +0200
     4.3 @@ -0,0 +1,153 @@
     4.4 +
     4.5 +--
     4.6 +--	tek.class.cgi.request - Request variables
     4.7 +--	Written by Timm S. Mueller <tmueller at neoscientists.org>
     4.8 +--	See copyright notice in COPYRIGHT
     4.9 +--
    4.10 +--	TODO: args can be instantiated only once, because POST data
    4.11 +--	is read from a stream
    4.12 +--
    4.13 +
    4.14 +require "cgilua.post"
    4.15 +local cgi = require "tek.class.cgi"
    4.16 +
    4.17 +local getfenv, setmetatable = getfenv, setmetatable
    4.18 +local getenv, tonumber = os.getenv, tonumber
    4.19 +local parsedata, read = cgilua.post.parsedata, io.read
    4.20 +local open = io.open
    4.21 +
    4.22 +
    4.23 +module "tek.class.cgi.request"
    4.24 +
    4.25 +
    4.26 +_VERSION = 5
    4.27 +_REVISION = 0
    4.28 +
    4.29 +
    4.30 +local Request = getfenv()
    4.31 +
    4.32 +
    4.33 +function Request:new(o)
    4.34 +	o = o or { }
    4.35 +	o.maxinput = o.maxinput or 1048575
    4.36 +	o.maxfilesize = o.maxfilesize or 524288
    4.37 + 	setmetatable(o, self)
    4.38 + 	self.__index = self
    4.39 +	o.Protocol = getenv("SERVER_PROTOCOL")
    4.40 +	o.Port = tonumber(getenv("SERVER_PORT"))
    4.41 +	o.Method = getenv("REQUEST_METHOD")
    4.42 +	o.PathInfo = getenv("PATH_INFO")
    4.43 +	o.PathTranslated = getenv("PATH_TRANSLATED")
    4.44 +	o.ScriptName = getenv("SCRIPT_NAME")
    4.45 +	o.QueryString = getenv("QUERY_STRING")
    4.46 +	o.RemoteHost = getenv("REMOTE_HOST")
    4.47 +	o.RemoteAddr = getenv("REMOTE_ADDR")
    4.48 +	o.AuthType = getenv("AUTH_TYPE")
    4.49 +	o.RemoteUser = getenv("REMOTE_USER")
    4.50 +	o.RemoteIdent = getenv("REMOTE_IDENT")
    4.51 +	o.ContentType = getenv("CONTENT_TYPE")
    4.52 +	o.ContentLength = getenv("CONTENT_LENGTH")
    4.53 +	o.DocumentName = getenv("DOCUMENT_NAME")
    4.54 +	o.UniqueID = getenv("UNIQUE_ID")
    4.55 +	return o
    4.56 +end
    4.57 +
    4.58 +
    4.59 +function Request:getargs(maxinput, maxfilesize)
    4.60 +	if not self.args then
    4.61 +		self.args = { }
    4.62 +		if self.Method == "GET" then
    4.63 +			self.QueryString:gsub("([^&=]+)=([^&=]+)", function(key, value)
    4.64 +				self.args[key] = cgi.decodeurl(value)
    4.65 +			end)
    4.66 +		elseif self.Method == "POST" then
    4.67 +			parsedata {
    4.68 +				read = read,
    4.69 +				discardinput = nil,
    4.70 +				content_type = self.ContentType,
    4.71 +				content_length = self.ContentLength,
    4.72 +				maxinput = maxinput or self.maxinput,
    4.73 +				maxfilesize = maxfilesize or self.maxfilesize,
    4.74 +				args = self.args
    4.75 +			}
    4.76 +		end
    4.77 +	end
    4.78 +	return self.args
    4.79 +end
    4.80 +
    4.81 +
    4.82 +function Request:getdocument()
    4.83 +
    4.84 +	if not self.document and self.PathTranslated then
    4.85 +	
    4.86 +		self.document = { }
    4.87 +		
    4.88 +		--	Gather document information "Name" and "Path", additionally
    4.89 +		--	provide a "VirtualPath" that is past the end of the script path.
    4.90 +		--	"Handler" denotes the script in the path.
    4.91 +		
    4.92 +		local pt, vp, f = self.PathTranslated
    4.93 +		
    4.94 +		repeat
    4.95 +			f = open(pt)
    4.96 +			if f then
    4.97 +				f:close()
    4.98 +				-- now matches a filesystem object - the rest is 'virtual'
    4.99 +				break
   4.100 +			end
   4.101 +			pt = pt:gsub("^(.*)(/.-)$", function(a, b)
   4.102 +				vp = b .. (vp or "")
   4.103 +				return a
   4.104 +			end)
   4.105 +		until not pt
   4.106 +		
   4.107 +		self.document.Handler = pt
   4.108 +		
   4.109 +		local name = self.PathInfo
   4.110 +		if vp then
   4.111 +			-- isolate document name by matching virtual path at end:
   4.112 +			if name:sub(-vp:len()) == vp then
   4.113 +				name = name:sub(1, name:len() - vp:len())
   4.114 +			end
   4.115 +			self.document.VirtualPath = vp:gsub("^/?(.*)$", "%1")
   4.116 +		end
   4.117 +		self.document.Name = name
   4.118 +		self.document.Path = pt:gsub("^(.*/).-$", "%1")
   4.119 +	end
   4.120 +	
   4.121 +	return self.document
   4.122 +end
   4.123 +
   4.124 +
   4.125 +function Request:getheader()
   4.126 +	if not self.header then
   4.127 +		self.header = {
   4.128 +			Accept = getenv("HTTP_ACCEPT"),
   4.129 +			UserAgent = getenv("HTTP_USER_AGENT"),
   4.130 +			Referer = getenv("HTTP_REFERER"),
   4.131 +			Host = getenv("HTTP_HOST"),
   4.132 +			CookieString = getenv("HTTP_COOKIE"),
   4.133 +		}
   4.134 +	end
   4.135 +	return self.header
   4.136 +end
   4.137 +
   4.138 +
   4.139 +function Request:getcookies()
   4.140 +	if not self.cookies then
   4.141 +		local header = self:getheader()
   4.142 +		if header.CookieString then
   4.143 +			self.cookies = { }
   4.144 +			local pos, name, id = 0
   4.145 +			while true do
   4.146 +				_, pos, name, id = header.CookieString:find(
   4.147 +					"[%s]*([%w_]+)=([%w%.%-%+%%_]+)[;%s]*", pos + 1)
   4.148 +				if not pos then
   4.149 +					break
   4.150 +				end
   4.151 +				self.cookies[name] = id
   4.152 +			end
   4.153 +		end
   4.154 +	end
   4.155 +	return self.cookies
   4.156 +end
     5.1 --- a/cgi-bin/tek/class/http.lua	Sun May 20 18:28:42 2007 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,71 +0,0 @@
     5.4 -
     5.5 ---
     5.6 ---	tek.class.http - HTTP baseclass
     5.7 ---	Written by Timm S. Mueller <tmueller at neoscientists.org>
     5.8 ---	See copyright notice in COPYRIGHT
     5.9 ---
    5.10 -
    5.11 -local lib = require "tek.lib"
    5.12 -local type, tonumber, utf8values = type, tonumber, lib.utf8values
    5.13 -local insert, concat, char = table.insert, table.concat, string.char
    5.14 -
    5.15 -
    5.16 -module "tek.class.http"
    5.17 -
    5.18 -
    5.19 -_VERSION = 2
    5.20 -_REVISION = 0
    5.21 -
    5.22 -
    5.23 ---	Encode for forms (display '<', '>', '&', '"' literally)
    5.24 -
    5.25 -function encodeform(s)
    5.26 -	local tab = { }
    5.27 -	if s then
    5.28 -		for c in utf8values(s) do
    5.29 -			if c == 34 then
    5.30 -				insert(tab, "&quot;")
    5.31 -			elseif c == 38 then
    5.32 -				insert(tab, "&amp;")
    5.33 -			elseif c == 60 then
    5.34 -				insert(tab, "&lt;")
    5.35 -			elseif c == 62 then
    5.36 -				insert(tab, "&gt;")
    5.37 -			elseif c == 91 or c == 93 or c > 126 then
    5.38 -				insert(tab, ("&#%03d;"):format(c))
    5.39 -			else
    5.40 -				insert(tab, char(c))
    5.41 -			end
    5.42 -		end
    5.43 -	end
    5.44 -	return concat(tab)
    5.45 -end
    5.46 -
    5.47 -
    5.48 ---	URL encode/decode
    5.49 -
    5.50 -function encodeurl(s, keep)
    5.51 -	local matchset = "$&+,/:;=?@" -- reserved chars with special meaning
    5.52 -	if keep then 
    5.53 -		if type(keep) == "string" then -- delete specified from set:
    5.54 -			matchset = matchset:gsub("[" .. keep:gsub(".", "%%%1") .. "]", "")
    5.55 -		elseif keep == true then -- delete whole set:
    5.56 -			matchset = "" 
    5.57 -		end
    5.58 -	end
    5.59 -	-- always substitute unsafe chars:
    5.60 -	matchset = matchset .. '"<>#%{}|\\^~[]`]'
    5.61 -	matchset = "[%z\001-\032\127-\255" .. matchset:gsub(".", "%%%1") .. "]"
    5.62 -	s = s:gsub(matchset, function(c)
    5.63 -		return ("%%%02x"):format(c:byte())
    5.64 -	end)
    5.65 -	return s
    5.66 -end
    5.67 -
    5.68 -
    5.69 -function decodeurl(s)
    5.70 -	s = s:gsub("+", " ")
    5.71 -	return s:gsub("%%(%x%x)", function(h)
    5.72 -		return char(tonumber(h, 16))
    5.73 -	end)
    5.74 -end
     6.1 --- a/cgi-bin/tek/class/http/header.lua	Sun May 20 18:28:42 2007 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,48 +0,0 @@
     6.4 -
     6.5 ---
     6.6 ---	tek.cgi.header - Collect header variables
     6.7 ---	Written by Timm S. Mueller <tmueller at neoscientists.org>
     6.8 ---	See copyright notice in COPYRIGHT
     6.9 ---
    6.10 -
    6.11 -local getenv = os.getenv
    6.12 -
    6.13 -
    6.14 -module "tek.cgi.header"
    6.15 -
    6.16 -
    6.17 -_VERSION = 2
    6.18 -_REVISION = 0
    6.19 -
    6.20 -
    6.21 -local Header = getfenv()
    6.22 -
    6.23 -
    6.24 -function Header:new(o)
    6.25 -	o = o or { }
    6.26 - 	setmetatable(o, self)
    6.27 - 	self.__index = self
    6.28 -	o.Accept = getenv("HTTP_ACCEPT")
    6.29 -	o.UserAgent = getenv("HTTP_USER_AGENT")
    6.30 -	o.Referer = getenv("HTTP_REFERER")
    6.31 -	o.Host = getenv("HTTP_HOST")
    6.32 -	o.CookieString = getenv("HTTP_COOKIE")
    6.33 -	return o
    6.34 -end
    6.35 -
    6.36 -
    6.37 -function Header:getcookies()
    6.38 -	if not self.cookies and self.CookieString then
    6.39 -		self.cookies = { }
    6.40 -		local pos, name, id = 0
    6.41 -		while true do
    6.42 -			_, pos, name, id = self.CookieString:find(
    6.43 -				"[%s]*([%w_]+)=([%w%.%-%+%%_]+)[;%s]*", pos + 1)
    6.44 -			if not pos then
    6.45 -				break
    6.46 -			end
    6.47 -			self.cookies[name] = id
    6.48 -		end
    6.49 -	end
    6.50 -	return self.cookies
    6.51 -end
     7.1 --- a/cgi-bin/tek/class/http/request.lua	Sun May 20 18:28:42 2007 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,153 +0,0 @@
     7.4 -
     7.5 ---
     7.6 ---	tek.cgi.request - Collect request variables
     7.7 ---	Written by Timm S. Mueller <tmueller at neoscientists.org>
     7.8 ---	See copyright notice in COPYRIGHT
     7.9 ---
    7.10 ---	TODO: args can be instantiated only once, because POST data
    7.11 ---	is read from a stream
    7.12 ---
    7.13 -
    7.14 -require "cgilua.post"
    7.15 -local http = require "tek.class.http"
    7.16 -
    7.17 -local getfenv, setmetatable = getfenv, setmetatable
    7.18 -local getenv, tonumber = os.getenv, tonumber
    7.19 -local parsedata, read = cgilua.post.parsedata, io.read
    7.20 -local open = io.open
    7.21 -
    7.22 -
    7.23 -module "tek.class.http.request"
    7.24 -
    7.25 -
    7.26 -_VERSION = 4
    7.27 -_REVISION = 0
    7.28 -
    7.29 -
    7.30 -local Request = getfenv()
    7.31 -
    7.32 -
    7.33 -function Request:new(o)
    7.34 -	o = o or { }
    7.35 -	o.maxinput = o.maxinput or 1048575
    7.36 -	o.maxfilesize = o.maxfilesize or 524288
    7.37 - 	setmetatable(o, self)
    7.38 - 	self.__index = self
    7.39 -	o.Protocol = getenv("SERVER_PROTOCOL")
    7.40 -	o.Port = tonumber(getenv("SERVER_PORT"))
    7.41 -	o.Method = getenv("REQUEST_METHOD")
    7.42 -	o.PathInfo = getenv("PATH_INFO")
    7.43 -	o.PathTranslated = getenv("PATH_TRANSLATED")
    7.44 -	o.ScriptName = getenv("SCRIPT_NAME")
    7.45 -	o.QueryString = getenv("QUERY_STRING")
    7.46 -	o.RemoteHost = getenv("REMOTE_HOST")
    7.47 -	o.RemoteAddr = getenv("REMOTE_ADDR")
    7.48 -	o.AuthType = getenv("AUTH_TYPE")
    7.49 -	o.RemoteUser = getenv("REMOTE_USER")
    7.50 -	o.RemoteIdent = getenv("REMOTE_IDENT")
    7.51 -	o.ContentType = getenv("CONTENT_TYPE")
    7.52 -	o.ContentLength = getenv("CONTENT_LENGTH")
    7.53 -	o.DocumentName = getenv("DOCUMENT_NAME")
    7.54 -	o.UniqueID = getenv("UNIQUE_ID")
    7.55 -	return o
    7.56 -end
    7.57 -
    7.58 -
    7.59 -function Request:getargs(maxinput, maxfilesize)
    7.60 -	if not self.args then
    7.61 -		self.args = { }
    7.62 -		if self.Method == "GET" then
    7.63 -			self.QueryString:gsub("([^&=]+)=([^&=]+)", function(key, value)
    7.64 -				self.args[key] = http.decodeurl(value)
    7.65 -			end)
    7.66 -		elseif self.Method == "POST" then
    7.67 -			parsedata {
    7.68 -				read = read,
    7.69 -				discardinput = nil,
    7.70 -				content_type = self.ContentType,
    7.71 -				content_length = self.ContentLength,
    7.72 -				maxinput = maxinput or self.maxinput,
    7.73 -				maxfilesize = maxfilesize or self.maxfilesize,
    7.74 -				args = self.args
    7.75 -			}
    7.76 -		end
    7.77 -	end
    7.78 -	return self.args
    7.79 -end
    7.80 -
    7.81 -
    7.82 -function Request:getdocument()
    7.83 -
    7.84 -	if not self.document and self.PathTranslated then
    7.85 -	
    7.86 -		self.document = { }
    7.87 -		
    7.88 -		--	Gather document information "Name" and "Path", additionally
    7.89 -		--	provide a "VirtualPath" that is past the end of the script path.
    7.90 -		--	"Handler" denotes the script in the path.
    7.91 -		
    7.92 -		local pt, vp, f = self.PathTranslated
    7.93 -		
    7.94 -		repeat
    7.95 -			f = open(pt)
    7.96 -			if f then
    7.97 -				f:close()
    7.98 -				-- now matches a filesystem object - the rest is 'virtual'
    7.99 -				break
   7.100 -			end
   7.101 -			pt = pt:gsub("^(.*)(/.-)$", function(a, b)
   7.102 -				vp = b .. (vp or "")
   7.103 -				return a
   7.104 -			end)
   7.105 -		until not pt
   7.106 -		
   7.107 -		self.document.Handler = pt
   7.108 -		
   7.109 -		local name = self.PathInfo
   7.110 -		if vp then
   7.111 -			-- isolate document name by matching virtual path at end:
   7.112 -			if name:sub(-vp:len()) == vp then
   7.113 -				name = name:sub(1, name:len() - vp:len())
   7.114 -			end
   7.115 -			self.document.VirtualPath = vp:gsub("^/?(.*)$", "%1")
   7.116 -		end
   7.117 -		self.document.Name = name
   7.118 -		self.document.Path = pt:gsub("^(.*/).-$", "%1")
   7.119 -	end
   7.120 -	
   7.121 -	return self.document
   7.122 -end
   7.123 -
   7.124 -
   7.125 -function Request:getheader()
   7.126 -	if not self.header then
   7.127 -		self.header = {
   7.128 -			Accept = getenv("HTTP_ACCEPT"),
   7.129 -			UserAgent = getenv("HTTP_USER_AGENT"),
   7.130 -			Referer = getenv("HTTP_REFERER"),
   7.131 -			Host = getenv("HTTP_HOST"),
   7.132 -			CookieString = getenv("HTTP_COOKIE"),
   7.133 -		}
   7.134 -	end
   7.135 -	return self.header
   7.136 -end
   7.137 -
   7.138 -
   7.139 -function Request:getcookies()
   7.140 -	if not self.cookies then
   7.141 -		local header = self:getheader()
   7.142 -		if header.CookieString then
   7.143 -			self.cookies = { }
   7.144 -			local pos, name, id = 0
   7.145 -			while true do
   7.146 -				_, pos, name, id = header.CookieString:find(
   7.147 -					"[%s]*([%w_]+)=([%w%.%-%+%%_]+)[;%s]*", pos + 1)
   7.148 -				if not pos then
   7.149 -					break
   7.150 -				end
   7.151 -				self.cookies[name] = id
   7.152 -			end
   7.153 -		end
   7.154 -	end
   7.155 -	return self.cookies
   7.156 -end
     8.1 --- a/cgi-bin/tek/class/loona.lua	Sun May 20 18:28:42 2007 +0200
     8.2 +++ b/cgi-bin/tek/class/loona.lua	Sun May 20 21:16:54 2007 +0200
     8.3 @@ -8,8 +8,8 @@
     8.4  local lib = require "tek.lib"
     8.5  local luahtml = require "tek.lib.luahtml"
     8.6  local posix = require "tek.os.posix"
     8.7 -local http = require "tek.class.http"
     8.8 -local Request = require "tek.class.http.request"
     8.9 +local cgi = require "tek.class.cgi"
    8.10 +local Request = require "tek.class.cgi.request"
    8.11  local util = require "tek.class.loona.util"
    8.12  local markup = require "tek.class.loona.markup"
    8.13  
    8.14 @@ -36,7 +36,7 @@
    8.15  
    8.16  
    8.17  _VERSION = 4
    8.18 -_REVISION = 1
    8.19 +_REVISION = 2
    8.20  
    8.21  
    8.22  -- Session
    8.23 @@ -508,7 +508,7 @@
    8.24  		else
    8.25  			table.insert(href, "?")
    8.26  		end
    8.27 -		table.insert(href, arg.name .. "=" .. http.encodeurl(arg.value))
    8.28 +		table.insert(href, arg.name .. "=" .. cgi.encodeurl(arg.value))
    8.29  	end
    8.30  	if anch then
    8.31  		insert(href, anch)
    8.32 @@ -1482,7 +1482,7 @@
    8.33  
    8.34  
    8.35  function Loona:encodeform(s)
    8.36 -	return http.encodeform(s)
    8.37 +	return util.encodeform(s)
    8.38  end
    8.39  
    8.40  
     9.1 --- a/cgi-bin/tek/class/loona/markup.lua	Sun May 20 18:28:42 2007 +0200
     9.2 +++ b/cgi-bin/tek/class/loona/markup.lua	Sun May 20 21:16:54 2007 +0200
     9.3 @@ -5,7 +5,8 @@
     9.4  --	See copyright notice in COPYRIGHT
     9.5  --
     9.6  
     9.7 -local http = require "tek.class.http"
     9.8 +local cgi = require "tek.class.cgi"
     9.9 +local util = require "tek.class.loona.util"
    9.10  
    9.11  local unpack, min, ipairs = unpack, math.min, ipairs
    9.12  local remove, insert, concat, foreachi =
    9.13 @@ -130,15 +131,15 @@
    9.14  	end,
    9.15  
    9.16  	gettext = function(state, line, id)
    9.17 -		return http.encodeform(gettextml(state, line, id))
    9.18 +		return util.encodeform(gettextml(state, line, id))
    9.19  	end,
    9.20  
    9.21  	getpre = function(state, line)
    9.22 -		return http.encodeform(line), '\n'
    9.23 +		return util.encodeform(line), '\n'
    9.24  	end,
    9.25  
    9.26  	getcode = function(state, line)
    9.27 -		return http.encodeform(line)
    9.28 +		return util.encodeform(line)
    9.29  	end,
    9.30  
    9.31  	head = function(state, level, text)
    9.32 @@ -205,9 +206,9 @@
    9.33  	link = function(state, link, isurl)
    9.34  		link = link:lower()
    9.35  		if isurl then
    9.36 -			return '<%=loona:elink("' .. http.encodeurl(link, true) .. '", [[', ']])%>'
    9.37 +			return '<%=loona:elink("' .. cgi.encodeurl(link, true) .. '", [[', ']])%>'
    9.38  		else
    9.39 -			return '<%=loona:link("' .. http.encodeurl(link, true) .. '", [[', ']])%>'
    9.40 +			return '<%=loona:link("' .. cgi.encodeurl(link, true) .. '", [[', ']])%>'
    9.41  		end
    9.42  	end,
    9.43  
    9.44 @@ -226,7 +227,7 @@
    9.45  	end,
    9.46  
    9.47  	image = function(state, link)
    9.48 -		return '<img src="' .. http.encodeurl(link, true) .. '" />'
    9.49 +		return '<img src="' .. cgi.encodeurl(link, true) .. '" />'
    9.50  	end,
    9.51  }
    9.52  
    10.1 --- a/cgi-bin/tek/class/loona/util.lua	Sun May 20 18:28:42 2007 +0200
    10.2 +++ b/cgi-bin/tek/class/loona/util.lua	Sun May 20 21:16:54 2007 +0200
    10.3 @@ -1,19 +1,21 @@
    10.4  
    10.5  --
    10.6 ---	tek.class.loona.util - LOona class utilities
    10.7 +--	tek.class.loona.util - LOona utilities
    10.8  --	Written by Timm S. Mueller <tmueller at neoscientists.org>
    10.9  --	See copyright notice in COPYRIGHT
   10.10  --
   10.11  
   10.12 +local lib = require "tek.lib"
   10.13  local posix = require "tek.os.posix"
   10.14  
   10.15 -local assert, time, remove = assert, os.time, os.remove
   10.16 +local assert, os_time, os_remove = assert, os.time, os.remove
   10.17 +local insert, concat, char = table.insert, table.concat, string.char
   10.18  
   10.19  
   10.20  module "tek.class.loona.util"
   10.21  
   10.22  
   10.23 -_VERSION = 3
   10.24 +_VERSION = 4
   10.25  _REVISION = 0
   10.26  
   10.27  
   10.28 @@ -41,7 +43,7 @@
   10.29  	assert(pat, "No pattern")
   10.30  	assert(maxtime, "No maxtime")
   10.31  	if posix.stat(dir, "mode") == "directory" then
   10.32 -		local nowtime = time()
   10.33 +		local nowtime = os_time()
   10.34  		for e in readdir(dir) do
   10.35  			if not pat or e:match(pat) then
   10.36  				local fname = dir .. "/" .. e
   10.37 @@ -49,7 +51,7 @@
   10.38  				-- (in which case stat() returns nil), it can be deleted anyway
   10.39  				local atime = posix.stat(fname, "access")
   10.40  				if not atime or (nowtime - atime > maxtime) then
   10.41 - 					local res, msg = remove(fname)
   10.42 + 					local res, msg = os_remove(fname)
   10.43   					assert(res, msg and "Failed to delete item : " .. msg)
   10.44  				end
   10.45   			end
   10.46 @@ -57,3 +59,28 @@
   10.47   		return true
   10.48  	end
   10.49  end
   10.50 +
   10.51 +
   10.52 +--	Encode for forms (display '<', '>', '&', '"' literally)
   10.53 +
   10.54 +function encodeform(s)
   10.55 +	local tab = { }
   10.56 +	if s then
   10.57 +		for c in lib.utf8values(s) do
   10.58 +			if c == 34 then
   10.59 +				insert(tab, "&quot;")
   10.60 +			elseif c == 38 then
   10.61 +				insert(tab, "&amp;")
   10.62 +			elseif c == 60 then
   10.63 +				insert(tab, "&lt;")
   10.64 +			elseif c == 62 then
   10.65 +				insert(tab, "&gt;")
   10.66 +			elseif c == 91 or c == 93 or c > 126 then
   10.67 +				insert(tab, ("&#%03d;"):format(c))
   10.68 +			else
   10.69 +				insert(tab, char(c))
   10.70 +			end
   10.71 +		end
   10.72 +	end
   10.73 +	return concat(tab)
   10.74 +end
    11.1 --- a/extensions/checkaccept.lua	Sun May 20 18:28:42 2007 +0200
    11.2 +++ b/extensions/checkaccept.lua	Sun May 20 21:16:54 2007 +0200
    11.3 @@ -1,8 +1,8 @@
    11.4  <%
    11.5  
    11.6  os = require "os"
    11.7 -http = require "tek.class.http"
    11.8 -cookies = require "tek.class.http.request":new():getcookies()
    11.9 +cgi = require "tek.class.cgi"
   11.10 +cookies = require "tek.class.cgi.request":new():getcookies()
   11.11  
   11.12  local cookiename = arg[1]
   11.13  local introtext = arg[2] -- diclaimer
   11.14 @@ -12,7 +12,7 @@
   11.15  
   11.16  
   11.17  if cookies and cookies[cookiename] then
   11.18 -	local cdata = http.decodeurl(cookies[cookiename])
   11.19 +	local cdata = cgi.decodeurl(cookies[cookiename])
   11.20  	accept = accept or cdata:match("(.+)")
   11.21  end
   11.22  
   11.23 @@ -21,7 +21,7 @@
   11.24  		"(%w+)%s(%w+)%s(.+)%s(%d+):(%d+):(%d+)%s(%d+)", function(wdy,mon,d,h,m,s,y)
   11.25  			return wdy..", "..d.."-"..mon.."-"..(y+1).." "..h..":"..m..":"..s.." GMT"
   11.26  		end)
   11.27 -	cdata = http.encodeurl(accept)
   11.28 +	cdata = cgi.encodeurl(accept)
   11.29  	loona:setheader("Set-cookie: "..cookiename.."="..cdata.."; expires="..expdate.."; path=/;\n")
   11.30  end
   11.31  
    12.1 --- a/extensions/search.lua	Sun May 20 18:28:42 2007 +0200
    12.2 +++ b/extensions/search.lua	Sun May 20 21:16:54 2007 +0200
    12.3 @@ -3,10 +3,9 @@
    12.4  io = require "io"
    12.5  lib = require "tek.lib"
    12.6  util = require "tek.class.loona.util"
    12.7 -http = require "tek.class.http"
    12.8  args = loona.args
    12.9  
   12.10 -local searchtext = http.encodeform(args.searchtext or "")
   12.11 +local searchtext = util.encodeform(args.searchtext or "")
   12.12  
   12.13  
   12.14  --