cgiparse: Parse STRING_QUERY environment variable into task parameters

Package: obsutil

Synopsis

CGIPARSE parses the STRING_QUERY environment varabile and sets parameters. The string format is a list of task.param=value pairs which includes the standard QUERY string special characters '&', '+', and '%'. This is intended to parse a query from a CGI script.

Usage

cgiparse

Parameters

There are no parameters. The input is the value of the QUERY_STRING environment variable.

Description

CGIPARSE parses the STRING_QUERY environment varabile and sets parameters. The string format is a list of task.param=value pairs which includes the standard QUERY string special characters '&', '+', and '%'. This is intended to parse a query from a CGI script.

The only input is the STRING_QUERY variable. If it is undefined the task simply does nothing. The string will normally use the standard parameters for this type of string. The data fields are task.param=value strings. As each is parsed the values will be set for the task. This assumes the tasks are defined. Theere is no error checking for undefined tasks or parameters.

Examples

1. A CGI script calls a CL script with the STRING_QUERY string set. The string has "imheader.longheader=yes". CGIPARSE is called and when it completes the parameter value is set.

cl> lpar imhead
cl> lpar imheader
       images =                 image names
      (imlist = "*.imh,*.fits,*.pl,*.qp,*.hhh") default image ...
  (longheader = no)             print header in multi-line format
  (userfields = yes)            print the user fields ...
        (mode = "ql")
cl> cgiparse
cl> lpar imheader
       images =                 image names
      (imlist = "*.imh,*.fits,*.pl,*.qp,*.hhh") default image ...
  (longheader = yes)            print header in multi-line format
  (userfields = yes)            print the user fields ...
        (mode = "ql")

Note that when running this in a "#!cl" script where the "login.cl" is not used that you must be careful to have all tasks referenced by the query string defined.

2. Below is a "#!cl" type script that uses CGIPARSE. It is used for a spectral exposure time calculator based on OBSUTIL.SPTIME though many aspects are fairly generic for this type of application.

#!/iraf/iraf/bin.freebsd/cl.e -f

file    urldir

# The following must be set for different hosts.
# The home directory and the urldir are the same but in different syntax.
# The home directory must have a world writable tmp subdirectory.

set arch = ".freebsd"
set (home = osfn ("/www/htdocs/noao/staff/brooke/gsmt/"))
urldir = "/noao/staff/brooke/gsmt/"

# The uparm is a unique temporary directory.
s1 = mktemp ("uparm") // "/"
set (uparm = "home$/tmp/" // s1)
mkdir uparm$
cd uparm
printf ("!/bin/chmod a+rw %s\n", osfn("uparm$")) | cl

# The URL directory is the same as uparm.
urldir = urldir // "tmp/" // s1

# A private graphcap is required to give an path for sgidispatch.
set graphcap = home$graphcap

# Load packages.
dataio
proto
noao
onedspec
spectime
gsmt

# Parse the CGI string and set parameters.
cgiparse

# Create the output.

# Start HTML.
printf ("Content-Type: text/html\n\n")
printf ("<html><head><title>Test</title></head>\n")
printf ("<body>\n")
if (cl.line == "...")
    printf ("<center><h2>SPECTIME</h2></center>\n", cl.line)
else
    printf ("<center><h2>%s</h2></center>\n", cl.line)
printf ("<pre>\n")

# Execute task(s).
#show QUERY_STRING

setup interactive=no mode=h
printf ("</pre>\n")
printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>")
printf ("<pre>\n")

sptime output="counts,snr" graphics="g-gif" interactive=no mode=h

printf ("</pre>\n")
printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>\n")

printf ("<pre>\n")

# Add any gifs created.  We have to wait for them to be created.

gflush

i = 0; j = 1
while (i != j) {
    sleep 2
    j = i
    files *.gif | count STDIN | scan (i)
}

if (i > 0) {
    printf ("<br><p><em>Note: DN and S/N are per-pixel</em><br>\n")

    files *.gif > gifs
    list = "gifs"
    while (fscan (list, s1) != EOF) {
        if (access (s1))
                printf ("<img src=\"%s%s\">\n", urldir, s1)
    }
    list = ""
    ## delete ("uparm$gifs", verify-)
}

printf ("</pre>\n")

# Finish HTML.

printf ("<A Href='http://www.noao.edu/noao/staff/brooke/gsmt/gsmt.php?stage=1'>Back to form</A>")

printf ("</body></html>\n")

# Clean up.
## delete ("*[^g][^i][^f]", verify-)

logout

See also