[REBOL] From "C" to Rebol: - decode-cgi-special/Object Methods
From: tim::johnsons-web::com at: 3-Aug-2001 9:15
Hi Anton: I will check out your code later.
In the meantime, have a look at what I have below. Implementation - wise,
these are "methods" for a large object .... they are evaluated
by a "constructor"
On Fri, Aug 03, 2001 at 02:30:29PM +1000, Anton wrote:
> I suggest modifying the decode-cgi function.
> I changed the 'equate rule to look like the
> 'value rule just below it.
> Of course, you won't be able to make an object
> out of it, since some of the names might have
> spaces in them, but for that you can still use
> decode-cgi.
> See code below, which I haven't tried.
>
; "helper" functions:
no-data?: func[arg][either any[none? arg arg = false empty? arg][return true][return
false]]
has-data?: func[arg][either any[none? arg arg = false empty? arg][return false][return
true]]
; data "fetch" method:
; ============================================================================================
read-data: func[/local tmp stdin dstr] [
either system/options/cgi/request-method = "POST"[
either (tmp: to-integer
load any[system/options/cgi/content-length "0"])> 0[
stdin: make string! tmp ; allocate storage space
read-io system/ports/input stdin tmp
return stdin
][none] ; data string empty
][;OR
dstr: system/options/cgi/query-string
either has-data? dstr[dstr][none]
]; end either
]; end read-data --------------------
; parses data string into a block in which names and values alternate:
; A value can then be retrieved by a name string, or by a numeric reference
; ============================================================================================
decode-data: func[/local cgi-form data-string][
either data-string: read-data[
data-string: dehex replace/all data-string "+" " "
pairs: (length? pair-list: parse/all data-string "&=") / 2
][none]
]; end decode-data
;=== I've rewritten the code above from some much "sloppier" implementations.
;=== I have tested this above and seems to work...
Thanks for the contribution, I will test Anton's code soon.
regards
tim
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com