[REBOL] RWT: Revoked/renewed CGI code
From: maarten::koopmans::surfnet::nl at: 3-Mar-2003 21:01
All,
I accidentally posted a different copyrighted CGI code script. This was
developed as a quick wrapper for one of my former employers where we did
a small pilot (unsuccesfull). You cannot use this script, I am very sorry.
Below my original version that *is* GPL'ed. Sorry for any incovenience.
Gonna get some sleep ;-)
--Maarten
REBOL
[
Title: {Logic for getting CGI parameters.}
]
cgi: make object!
[
data: copy []
url-encode: func
[
{Replaces characters that are not allowed in URLs by their url-encoded
values.}
val [string!]
/local illegal-chars lval
]
[
lval: copy val
illegal-chars: {+%;/?:@= "<>#{}|\^~[]`}
foreach char illegal-chars
[
replace/all lval char join "%" enbase/base to-string char 16
]
return lval
]
url-decode: func
[
val [string!]
/local illegal-chars lval
]
[
lval: copy val
illegal-chars: {+%;/?:@= "<>#{}|\^~[]`}
foreach char illegal-chars
[
replace/all lval join "%" enbase/base to-string char 16 char
]
return lval
]
init: func
[
{Initializes the CGI object.}
/local x buf parameters
]
[
parameters: either system/options/cgi/request-method = "POST"
[
x: make string! 1000
buf: make string! 1000
while [0 < read-io system/ports/input clear x 1000] [append buf x]
buf
]
[
system/options/cgi/query-string
]
if parameters [ data: decode-cgi parameters ]
]
get-value: func
[
{Reads the value of a named CGI parameter by literal name.}
name [string!]
/local result
]
[
result: select data to-set-word name
either result
[
return trim/lines url-decode result
]
[
return copy {}
]
]
]