Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

RWT: CGI logic

 [1/4] from: maarten:koopmans:surfnet:nl at: 3-Mar-2003 19:43


REBOL [ Title: {Logic for getting (Fast)CGI parameters.} Author: {Ernie van der Meer} Copyright: "2002, ING The Netherlands" ] 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 ] two-binary: func [ {Converts a string representation of a binary (eg. EFAB2E) back to its binary representation (#{EFAB2E}).} val [string!] /local bval ] [ either error? try [ val: do rejoin [ "#{" val "}" ] ] [ return none ] [ return val ] ] two-string: func [ {Converts a binary value (eg #{EFAB2E}) to its string representation (EFAB2E).} val [binary!] /local bval ] [ either parse (mold val) [ thru "{" copy bval to "}" to end ] [ return trim/all bval ] [ return none ] ] 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!] /loose {Returns an empty string instead of an error message if the CGI parameter cannot be found.} /local result ] [ result: select data to-set-word name either result [ return trim/lines url-decode result ] [ either loose [ return copy {} ] [ make error! rejoin [ {Unknown CGI parameter: } name ] ] ] ] ]

 [2/4] from: petr:krenzelok:trz:cz at: 4-Mar-2003 17:31


Maarten Koopmans wrote: as far as goes for logic, I have two objections and one general comment/suggestion?: Unless you have some all-included-modules initialisation sequence, I: 1) I find it a bit unnecessary to call cookies/init, if it can be done by get-cookie function itself - in such case though, it is imo unnecessary scattering of functionality into more functions than needed 2) cgi/init imo should not return decoded-cgi value - as it does so, I assume you don't do any global inicialisation, as what would you do with decoded cgi strin in such initial phase? :-) Imo the value should be stored into cgi/data word ... you seem to do so, but maybe it would be good to return true or false for your module initialisation? :-) "if cgi/init .... " .... anyway - easy fix .... btw what do you think of putting POST method gathered data into system/options/cgi/query-string so later on ppl could use their possible system/options/cgi inspection functions? 3) possible suggestion - could not be e.g. "system/words/advertise: func ..." replaced by "set advertise: func ..." as it imo has identical effect of setting inside-object functions into global context ... PS: just don't feel offended, those are merely suggestion :-) Cheers, -pekr-

 [3/4] from: andreas:bolka:gmx at: 4-Mar-2003 17:25


Tuesday, March 4, 2003, 4:31:35 PM, Petr wrote:
> btw what do you think of putting POST method gathered data into > system/options/cgi/query-string so later on ppl could use their > possible system/options/cgi inspection functions?
as post-data can be of any type (text, xml, ... lots of other possible mime types :), this would not make that much sense. -- Best regards, Andreas mailto:[andreas--bolka--gmx--net]

 [4/4] from: petr::krenzelok::trz::cz at: 4-Mar-2003 20:22


Andreas Bolka wrote:
>Tuesday, March 4, 2003, 4:31:35 PM, Petr wrote: >>btw what do you think of putting POST method gathered data into
<<quoted lines omitted: 4>>
>as post-data can be of any type (text, xml, ... lots of other possible >mime types :), this would not make that much sense.
yes, but Maarten and Ernie use decode-cgi for both anyway ;-) -pekr-

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted