CGIPARSE(8)                DACS Web Services Manual                CGIPARSE(8)

       cgiparse - CGI argument parsing utility

       cgiparse [mode] [-enc {none | url | mime | dacs}] [-in filename] [-d]
                [-qs query-string] [-copy filename] [[-n name filename]...]

       This program is part of the DACS suite. It is a stand-alone program
       that neither accepts the usual DACS command line options (dacsoptions)
       nor accesses any DACS configuration files.

       This utility is used by web-based scripts (shell scripts in particular)
       to obtain their CGI arguments, which can be obtained from a URI's query
       component or in an encoded entity-body read from the standard input (as
       with the POST method). The form content
       types[1]application/x-www-form-urlencoded and multipart/form-data are
       both understood.

       The program has several different modes of operation, one of which may
       be specified by the first command line argument.

       cgiparse combines query arguments found in the QUERY_STRING environment
       variable with arguments found in the message body it reads from the
       standard input. If an argument name is duplicated the result is

       The mode may be one of the following:

       -arg variable-name
           Emit the value of the CGI argument variable-name, then exit. If
           there is no such argument, the exit status will be 1 instead of 0.

       -targ variable-name
           Test if the CGI argument variable-name exists. If there is no such
           argument, the exit status will be 1, otherwise it will be 0.

           Emit an HTML document that lists the CGI argument names and their

           Emit a listing of the CGI argument values (without the names).

           Emit CGI arguments as a single line in the format:

               variable-name='variable-value'; [...]

           It is an error if any variable-name or variable-value is
           syntactically unsuitable for this format. The returned string can
           be used as the argument to eval to set the CGI arguments as shell

           Like -html except emit text. This is the default. With this mode,
           the program's stdout is usually written to a file. Each line of the
           file has the format:

               variable-name variable-value

           (a space separates the name from the corresponding value). The file
           is typically read by a script to obtain the arguments, or cgiparse
           can be run with the -in flag to retrieve an argument.

       Additionally, cgiparse recognizes these options:

           If writing the parsed CGI arguments (-text), encode the argument
           value using the specified method: url means URL encoding, mime
           means MIME base-64 encoding, and dacs means DACS base-64 encoding.
           For details about these encodings, please see dacs.exprs(5)[2]. The
           default is none, which means that no encoding is performed (use
           this only when you are sure this cannot cause a problem). If
           reading the parsed CGI arguments (-in), decode the argument values
           using the specified method. The default is none, which means that
           no decoding is performed; if the arguments were encoded, they will
           be returned in that encoding, but other than this case the decoding
           method must match the encoding method previously used or an error
           is likely to occur.

       -qs query-string
           Instead of using the environment variable QUERY_STRING to get a
           query component, use query-string.

           With -arg, do not emit a newline after printing an argument value.

           Enable debugging output.

       -copy filename
           Append the input stream to filename. This can be useful for
           debugging purposes.

       -in filename
           Instead of parsing CGI arguments, read variable name/value pairs
           (as produced by the -text flag) from filename. If filename is "-",
           stdin is read.

       -n name filename
           If parsing succeeds, and there is a MIME body part with a name
           exactly matching name, then:

           •   if the content disposition is multipart/form-data, write the
               content as quoted-printable text to filename;

           •   if the content disposition is base64, write the decoded content
               to filename;

           •   otherwise the content is written verbatim to filename.

           If the output file exists it is truncated.

       The following shell script demonstrates one way of using cgiparse.

           #! /bin/sh


           cgiparse > ${tmpfile}
           chmod 0600 ${tmpfile}

           echo "Context-Type: text/plain"
           echo ""

           while [ "${done}x" = x ]
             read a b
             if [ $? = 1 ]
               echo "Arg: ${a}"
               echo "Is: ${b}"
           done < ${tmpfile}

           rm -f ${tmpfile}
           exit 0

       The following code fragment uses cgiparse to save and then look up its
       CGI arguments:

           #! /bin/sh

           trap 'rm -f ${tmpfile}; exit 1' EXIT 1 2 3 13 15

           cgiparse -enc mime > ${tmpfile}
           chmod 0600 ${tmpfile}

           mode=`cgiparse -in ${tmpfile} -enc mime -arg MODE`
           target=`cgiparse -in ${tmpfile} -enc mime -arg TARGET`

       The following script will print "1 2 3" to its standard output:

           #! /bin/sh

           args=`cgiparse -sh -qs "a=1&b=2&c=3"`
           eval "$args"
           echo "$a $b $c"

       The program exits 0 if everything was fine, 1 if an error occurred.

       There do not appear to be any official recommendations concerning how
       to handle apparently "malformed" CGI query strings that do not look
       like a sequence of name=value pairs. The parsing routines that cgiparse
       uses will flag an error if they see strings containing a component like
       "=foo", for example, although "foo=" is fine.

       RFC 3875[3], The WWW Common Gateway Interface, Version 1.2[4], HTML
       4.01 Specification[5], dacs_prenv(8)[6]

       Distributed Systems Software ([7])

       Copyright2003-2012 Distributed Systems Software. See the LICENSE[8]
       file that accompanies the distribution for licensing information.

        1. form content types

        2. dacs.exprs(5)

        3. RFC 3875

        4. The WWW Common Gateway Interface, Version 1.2

        5. HTML 4.01 Specification

        6. dacs_prenv(8)


        8. LICENSE

DACS 1.4.28b                      02/04/2014                       CGIPARSE(8)