@verb #80:"parse_cgi" this none this rxdo #60 @program #80:"parse_cgi" this none this ":parse_cgi(string[, find])" "Breaks up the CGI arguments from a URL into components. Optional argument will locate the data coresponding with the requested component and return it if it exists, otherwise E_PROPNF is returned." "?name=Raptor&action=audit => {{'name', 'Raptor'}, {'action', 'audit'}}" "?name=Raptor&action=audit , action => 'audit'" "Multi line inputs are broked up: {'description', {'line 1', 'line 2'}}" "Multiple selections are likewise grouped together in a list." {input, ?find = 0} = args input = length(input) >= 2 && input[1..2] == "/?" ? input[3..$] | input input = input && input[1] == "?" ? input[2..$] | input if (length(input) > 5 && input[$ - 5..$] == "~0D~0A") "POST is binary, and leaves a CRLF at the end." input[$ - 5..$] = "" endif lf = index(input, "%0A", 1) cr = index(input, "%0D", 1) "Make sure that all line breaks are just %0D" if (lf && cr) input = strsub(input, lf < cr ? "%0A%0D" | "%0D%0A", "%0D") elseif (lf) input = strsub(input, "%0A", "%0D") endif if (find) find = $string_utils:substitute(find, $www.desubst) "The next three strsubs are to escape special chars for match()" find = strsub(find, "%", "%%") find = strsub(find, ".", "%.") find = strsub(find, "*", "%*") if (x = match(input, "%(^%|&%)" + find + "=")) y = index(input[x[2]..$], "&") text = input[x[2] + 1..y ? y + x[2] - 2 | length(input)] text = $string_utils:explode_all(text, "%0D") for z in [1..length(text)] text[z] = $string_utils:substitute_suspended(text[z], $www.subst) endfor return length(text) == 1 ? text[1] | (text ? text | "") else return E_PROPNF endif endif codes = {} while (index(input, "=")) x = index(input, "=") y = index(input, "&") y = y ? y - 1 | length(input) text = input[x + 1..y] text = $string_utils:explode_all(text, "%0D") for z in [1..length(text)] text[z] = $string_utils:substitute_suspended(text[z], $www.subst) endfor key = $string_utils:substitute(input[1..x - 1], $www.subst) text = length(text) == 1 ? text[1] | (text ? text | "") if (x = listiassoc(key, codes)) codes[x][2] = {@codes[x][2], @text} else codes = {@codes, {key, text}} endif input = input[y + 2..$] endwhile return codes "Last modified by Dax (#789) on Tue Jul 21 14:23:39 1998 EDT." .