[BusyBox] How to get parameter httpd.?

Martijn de Gouw MDG at Prodrive.nl
Wed May 11 06:59:26 UTC 2005



> -----Original Message-----
> From: busybox-bounces at mail.busybox.net [mailto:busybox-
> bounces at mail.busybox.net] On Behalf Of Ralph Siemsen
> Sent: dinsdag 10 mei 2005 21:14
> To: HS8JCV
> Cc: busybox at mail.busybox.net
> Subject: Re: [BusyBox] How to get parameter httpd.?
> 
> HS8JCV wrote:
> > Hi all
> > I will get parameter from get method on web page form.
> > Example: test.cgi?a1=value1&a2=value2
> > How to get value of a1 and a2 in cgi file.
> 
> The entire string "a1=value1&a2=value2" is passed in environment
> variable (GET method) or on stdin (POST method).  You can read in in the
> CGI script as appropriate, depending which language you use to write
> your CGI.
> 
> For decoding the strings, you can use ready-made libraries for this, for
> example, CGI.pm for perl, or libcgi for C language.  You can even do it
> with bash shell.  If your requirements are not very complicated you can
> write your own decoder routine fairly easily (but it is tricky to handle
> all the possible cases securely, so you are best to use existing code).
> 
> Note that busybox httpd includes the ability to encode and decode the
> URL encoding of the string... that is the hardest part.  See the
> comments at the beginning of busybox/networking/httpd.c
> 
> -R

For bash I do it like this:

function ParseQueryString {
  if [ -n "$1" ]; then
    for args in `echo "$1" | tr "&" " "`
    do
      param=`echo "$args" | cut -d "=" -f 1`
      value=`echo "$args" | cut -d "=" -f 2`
      eval "export FORM_${param}=${value}"
    done
  fi
}

if [ -n "$REQUEST_METHOD" ]; then
  case "$REQUEST_METHOD" in
    (GET)
      ParseQueryString "$QUERY_STRING"
      ;;
    (POST)
      ;;
    (*)
      ;;
  esac
fi

I doesn't catch up all the possible cases, and doesn't handle hex codes. But
this is the first version I ever made.

Martijn






More information about the busybox mailing list