| 1 |
|
| 2 |
#everything needed for typical web form handling |
| 3 |
|
| 4 |
procedure cgiparms() #returns a table, mapping names to lists of values |
| 5 |
local GET_data, POST_data, data, i, pname, pvalue, s |
| 6 |
static result |
| 7 |
initial { |
| 8 |
result := table() |
| 9 |
GET_data := trim(getenv("QUERY_STRING"))|"" |
| 10 |
if *GET_data = 0 then GET_data := &null |
| 11 |
POST_data := reads(&input, getenv("CONTENT_LENGTH")) |
| 12 |
if \GET_data & \POST_data then |
| 13 |
data := GET_data || "&" || POST_data |
| 14 |
else |
| 15 |
data := \GET_data | \POST_data |
| 16 |
if /data then return result |
| 17 |
data ? every i := upto('&')|0 do { |
| 18 |
tab(i) ? { |
| 19 |
pname := _urldecode( tab(upto('=')) ) |
| 20 |
move(1) |
| 21 |
pvalue := _urldecode( tab(0) ) |
| 22 |
/result[pname] := [] |
| 23 |
put( result[pname], pvalue ) |
| 24 |
} |
| 25 |
if pos(0) then break |
| 26 |
move(1) |
| 27 |
} |
| 28 |
} |
| 29 |
return result |
| 30 |
end |
| 31 |
|
| 32 |
procedure _urldecode(url) |
| 33 |
local s |
| 34 |
s := "" |
| 35 |
url ? repeat { |
| 36 |
s ||:= tab(upto('%+')|0) |
| 37 |
if pos(0) then return s |
| 38 |
case move(1) of { |
| 39 |
"%" : s ||:= char("16r" || map(move(2)) ) |
| 40 |
"+" : s ||:= " " |
| 41 |
} |
| 42 |
} |
| 43 |
end |