<COMMENT>(--------------------------------------------------------------------)

<CHAPTER>(CGI\chapter_scripting_cgi)

<P> The information in this chapter merely outlines the WASD implementation
details, which are in general very much vanilla CGI and NCSA CGI (Common
Gateway Interface) compliant, originally based the INTERNET-DRAFT authored by
D.Robinson (drtr@ast.cam.ac.uk), 8 January 1996, and confirmed against the
latest INTERNET-DRAFT authored by Ken A.L.Coar (drtr@etrade.co.uk), 12 June
1999.

<HEAD1>(CGI Environment Variables\head_cgi_env_variables)

<P> With the standard CGI environment variables are provided to the script via
DCL global symbols. Each CGI variable symbol name is prefixed with
<QUOTE>(WWW_) (by default, although this can be changed using the
<QUOTE>(/CGI_PREFIX) qualifier and the SET CGIPREFIX mapping rule, see
<QUOTE>(Technical Overview), this is not recommended if the WASD VMS scripts
are to be used, as they expect CGI variable symbols to be prefixed in this
manner).

<P> In line with other CGI implementations, additional, non-compliant variables
are provided to ease CGI interfacing.  These provide the various components of
the query string.  A <EMPHASIS>(keyword) query string and a <EMPHASIS>(form)
query string are parsed into separated variables, named

<CODE_EXAMPLE>
  WWW_KEY_<EMPHASIS>(number)
  WWW_KEY_COUNT
  WWW_FORM_<EMPHASIS>(form-element-name)
<ENDCODE_EXAMPLE>

<P> plus a number of non-<QUOTE>(standard) CGI variables to assist in tailoring
scripts for the WASD environment.  Do not make your scripts dependent on any of
these if portability is a goal.  See the table below.

<HEAD>(VMS Apache Compliance\head_cgi_apache)

<P> WASD v7.0 had it's CGI environment tailored slightly to ease portability
between VMS Apache and WASD.  This included the provision of an APACHE$INPUT:
stream and several Apache-specific CGI variables (see the table below). The
CGILIB C function library (see <REFERENCE>(head_cgilib)) has also been made
CSWS V1.0-1 (Apache 1.3.12) compliant.

<HEAD>(VMS Limits\head_cgi_limits)

<P> CGI variable values are limited to approximately 980 characters (regardless
of the version of VMS in use).  This should be sufficient for most
circumstances (if not consider using CGIplus or ISAPI, extensions to CGI
programming which remove this limitation).  Why such an odd number and why a
little rubbery?  A DCL command line is limited to 255 characters so the symbols
for larger variables are built up over successive DCL commands.  The limit of
980 characters is set by <EMPHASIS>(what can actually be achieved) this way
(still, it's much more useful than a limit of 255 or less!).

<P> The total length of all CGI variable names and values is determined by the
value of [BufferSizeDclCommand] configuration directive, which determines the
total buffer space of a mailbox providing the script's SYS$COMMAND.  The
default value of 4096 bytes will be ample for the typical CGI script request,
however if it contains an extraordinary number of form fields, etc., it may be
possible to exhaust this buffer space.

<HEAD>(CGI Variables\head_cgi_variables)

<P> Remember, all variables are prefixed by <QUOTE>(WWW_), and not all
variables will be present for all requests.

<P>
<TABLE>
<TABLE_SETUP>(3\20\30)
<TABLE_HEADS>(Name\Description\<QUOTE>(Standard))
<TABLE_ROW>(AUTH_ACCESS\<QUOTE>(READ) or <QUOTE>(READ+WRITE)\WASD)
<TABLE_ROW>(AUTH_AGENT\only present to and used by authorization agent\WASD)
<TABLE_ROW>(AUTH_GROUP\authentication group\WASD)
<TABLE_ROW>(AUTH_PASSWORD\plain-text password, only if EXTERNAL realm\WASD)
<TABLE_ROW>(AUTH_REALM\authentication realm\WASD)
<TABLE_ROW>(AUTH_REALM_DESCRIPTION\browser displayed string\WASD)
<TABLE_ROW>(AUTH_TYPE\authentication type (BASIC or DIGEST)\yes)
<TABLE_ROW>(AUTH_USER\details of authenticated user\WASD)
<TABLE_ROW>(CONTENT_LENGTH\<QUOTE>(Content-Length:) from request header\yes)
<TABLE_ROW>(CONTENT_TYPE\<QUOTE>(Content-Type:) from request header\yes)
<TABLE_ROW>(DOCUMENT_ROOT\always empty for WASD\Apache)
<TABLE_ROW>(FORM_field\query string <QUOTE>(&) separated form elements\no)
<TABLE_ROW>(GATEWAY_BG\device name <QUOTE>(BG<EMPHASIS>(nnnn):) of raw client
socket\WASD)
<TABLE_ROW>(GATEWAY_INTERFACE\<QUOTE>(CGI/1.1)\yes)
<TABLE_ROW>(GATEWAY_MRS\maximum record size of script SYS$OUTPUT\WASD)
<TABLE_ROW>(HTTP_ACCEPT\any list of browser-accepted content types\optional)
<TABLE_ROW>(HTTP_ACCEPT_CHARSET\any list of browser-accepted character sets\optional)
<TABLE_ROW>(HTTP_ACCEPT_LANGUAGE\any list of browser-accepted languages\optional)
<TABLE_ROW>(HTTP_AUTHORIZATION\any from request header\optional)
<TABLE_ROW>(HTTP_COOKIE\any cookie sent by the client\optional)
<TABLE_ROW>(HTTP_FORWARDED\any proxy/gateway hosts that forwarded the request\optional)
<TABLE_ROW>(HTTP_HOST\host and port request was sent to\optional)
<TABLE_ROW>(HTTP_IF_MODIFIED_SINCE\any last modified GMT time string\optional)
<TABLE_ROW>(HTTP_PRAGMA\any pragma directive of request header\optional)
<TABLE_ROW>(HTTP_REFERER\any source document URL for this request\optional)
<TABLE_ROW>(HTTP_USER_AGENT\client/browser identification string\optional)
<TABLE_ROW>(KEY_n\query string <QUOTE>(+) separated elements\no)
<TABLE_ROW>(KEY_COUNT\number of <QUOTE>(+) separated elements\no)
<TABLE_ROW>(PATH_INFO\virtual path of data requested in URL\yes)
<TABLE_ROW>(PATH_TRANSLATED\VMS file path of data requested in URL\yes)
<TABLE_ROW>(QUERY_STRING\un-URL-decoded string following <QUOTE>(?) in URL\yes)
<TABLE_ROW>(REMOTE_ADDR\IP host address of HTTP client\yes)
<TABLE_ROW>(REMOTE_HOST\IP host name of HTTP client\yes)
<TABLE_ROW>(REMOTE_USER\authenticated remote user name (or empty)\yes)
<TABLE_ROW>(REQUEST_CHARSET\any server-determined request character set\WASD)
<TABLE_ROW>(REQUEST_METHOD\<QUOTE>(GET), <QUOTE>(PUT), etc.\yes)
<TABLE_ROW>(REQUEST_SCHEME\<QUOTE>(http:) or <QUOTE>(https:)\WASD)
<TABLE_ROW>(REQUEST_TIME_GMT\GMT time request received\WASD)
<TABLE_ROW>(REQUEST_TIME_LOCAL\Local time request received\WASD)
<TABLE_ROW>(REQUEST_URI\full, unescaped request string\Apache)
<TABLE_ROW>(SCRIPT_FILENAME\script file name
(e.g. <QUOTE>(CGI-BIN:[000000]QUERY.COM))\Apache)
<TABLE_ROW>(SCRIPT_NAME\script being executed (e.g. <QUOTE>(/query))\yes)
<TABLE_ROW>(SERVER_ADDR\IP host name of server system\WASD)
<TABLE_ROW>(SERVER_ADMIN\email address for server administration\Apache)
<TABLE_ROW>(SERVER_CHARSET\server default character set\WASD)
<TABLE_ROW>(SERVER_GMT\offset from GMT (e.g. <QUOTE>(+09:30))\WASD)
<TABLE_ROW>(SERVER_NAME\IP host name of server\yes)
<TABLE_ROW>(SERVER_PROTOCOL\HTTP protocol version (always <QUOTE>(HTTP/1.0))\yes)
<TABLE_ROW>(SERVER_PORT\IP port request was received on\yes)
<TABLE_ROW>(SERVER_SIGNATURE\server ID, host name and port\Apache)
<TABLE_ROW>(SERVER_SOFTWARE\software ID of HTTP server\yes)
<TABLE_ROW>(UNIQUE_ID\request-unique 19 character string\Apache)
<ENDTABLE>

<P> If the request path is set to provide them, there are also be variables
providing information about a Secure Sockets Layer transported request's SSL
environment.

<HEAD>(CGI Variable Demonstration\head_cgi_variable_demo)

<P> The basic CGI symbol names are demonstrated here with a call to a script 
that simply executes the following DCL code:

<CODE_EXAMPLE>
  $ SHOW SYMBOL WWW_*
  $ SHOW SYMBOL *
<ENDCODE_EXAMPLE>

<CP> Note how the request components are represented for
<QUOTE>(ISINDEX)-style searching (third item) and a forms-based query (fourth
item). 

<COMMENT>(....................................................................)

<COMMENT>(HTML=
<OL>
<LI> <A HREF="/cgi-bin/cgi_symbols">/cgi-bin/cgi_symbols</A>
<LI> <A HREF="/cgi-bin/cgi_symbols/ht_root/doc/htd">
     /cgi-bin/cgi_symbols/ht_root/doc/htd</A>
<LI> <A HREF="/cgi-bin/cgi_symbols/ht_root/doc/htd/*.*?string1+string2">
     /cgi-bin/cgi_symbols/ht_root/doc/htd/*.*?string1+string2</A>
<LI> <A HREF="/cgi-bin/cgi_symbols/ht_root/doc/htd?FirstField=for&SecondField=this">
     /cgi-bin/cgi_symbols/ht_root/doc/htd?FirstField=for&SecondField=this</A>
</OL>
)

<COMMENT>(HTML/OFF)
<P><BOX>(online demonstration)
<COMMENT>(HTML/ON)

<COMMENT>(....................................................................)

<HEAD>(UNIQUE_ID Note\head_cgi_unique_id)

<P> The UNIQUE_ID variable is a mostly Apache-compliant implementation (the
<QUOTE>(_) has been substituted for the <QUOTE>(@) to allow it's use in file
names), for each request generating a globally and temporally unique 19
character string that can be used where such a identifier might be needed. 
This string contains only <QUOTE>(A)-<QUOTE>(Z), <QUOTE>(a)-<QUOTE>(z),
<QUOTE>(0)-<QUOTE>(9), <QUOTE>(_) and <QUOTE>(-) characters and is generated
using a combination of time-stamp, host IP address, server system process
identifier and counter, and is <QUOTE>(guaranteed) to be unique in (Internet)
space and time. 

<COMMENT>(--------------------------------------------------------------------)

<HEAD1>(Script Output\head_script_output)

<P> This information applies to all subprocess-based scripting, CGI, CGIplus,
RTE, ISAPI.  For subprocess scripting WASD uses mailboxes for inter-process
communication (IPC).  These are efficient, versatile and allow direct output
from all VMS environments and utilities.  Like many VMS record-oriented devices
however there are some things to consider when using them.

<LIST>(UNNUMBERED)

<LE><EMPHASIS>(Record-Oriented\BOLD)

<P> The mailboxes are created record, not stream oriented.  This means records
output by standard VMS means (e.g. DCL, utilities, programming languages) are
discretely identified and may be processed appropriately by the server as text
or binary depending on the content-type.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(Maximum Record Size\BOLD)

<P> Being record oriented there is a maximum record size (MRS) that can
be output.  Records larger than this result in SYSTEM-F-MBTOOSML errors.  The
WASD default is 4096 bytes.  This may be changed using the
[BufferSizeDclOutput] configuration directive.  This allocation consumes
process BYTLM with each mailbox created so the account must be dimensioned
sufficiently to supply demands for this quota.  The maximum possible size for
this is a VMS-limit of 60,000 bytes.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(Buffer Space\BOLD)

<P> When created the mailbox has it's buffer space set.  With WASD IPC
mailboxes this is the same as the MRS.  The total data buffered may not exceed
this without the script entering a wait state (for the mailbox contents to be
cleared by the server).  As mailboxes use a little of the buffer space to
delimit records stored in it the amount of data is actually less than the total
buffer space.

<ENDLIST>

<P> To determine the maximum record size and total capacity of the mailbox
buffer between server and script WASD provides a CGI environment variable,
GATEWAY_MRS, containing an integer with this value.

<COMMENT>(--------------------------------------------------------------------)

<HEAD2>(CGI Compliant Output\head_cgi_output)

<P> Script response may be CGI or NPH compliant (see
<REFERENCE>(head_nph_output)).   CGI compliance means the script's response
must begin with a line containing one of the following fields.

<LIST>(UNNUMBERED)

<LE><EMPHASIS>(Status: \BOLD) an HTTP status code and associated
explanation string

<LE><EMPHASIS>(Content-Type: \BOLD) the script body's MIME content-type

<LE><EMPHASIS>(Location: \BOLD) a redirection URL

<ENDLIST>

<P> Other HTTP-compliant response fields may follow, with the response header
terminated and the response body begun by a single empty line.  The following 
is an example of a CGI-compliant response.

<CODE_EXAMPLE><LITERAL>(
  Content-Type: text/html
  Content-Length: 35

  <HTML>
  <B>Hello world!</B>
  </HTML>
)<ENDCODE_EXAMPLE>

<P> Strict CGI output compliance can be enabled and disabled using the
[CgiStrictOutput] configuration directive.  With it disabled the server will
accept any output from the script, if not CGI or NPH compliant then it
automatically generates plain-text header.  When enabled, if not a CGI or NPH
header the server returns a <QUOTE>(502 Bad Gateway) error.  For debugging
scripts generating this error introduce a <EMPHASIS>(plain-text) debug mode and
header, or use the WATCH facility's CGI item (see the Technical Overview).

<HEAD>(WASD Specifics\head_output_wasd_specifics)

<P> This section describes how WASD deals with some particular output issues.

<LIST>(UNNUMBERED)

<LE><EMPHASIS>(Content-Type: text/<HELLIPSIS>\BOLD)

<P> If the script response content-type is <QUOTE>(text/<HELLIPSIS>) (text
document) WASD assumes that output will be line-oriented and requiring HTTP
carriage-control (each record/line terminated by a line-feed), and will ensure
each record it receives is correctly terminated before passing it to the
client.  In this way DCL procedure output (and the VMS environment in general)
is supported transparently.  Any other content-type is assumed to be
<EMPHASIS>(binary) and no carriage-control is enforced.  This default behaviour
may be modified as described below.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(Carriage-Control\BOLD)

<P> Carriage-control behaviour for <UNDERLINE>(any) content-type may be
explicitly set using either of two additional response header fields.  The term
<EMPHASIS>(stream) is used to describe the server just transfering records,
without  additional processing, as they were received from the script.  This is
obviously necessary for binary/raw content such as images, octet-streams, etc.
The term <EMPHASIS>(record) describes the server ensuring each record it
receives has correct carriage-control - a trailing newline.  If not present one
is added.  This mode is useful for VMS textual streams (e.g. output from DCL
and VMS utilities).

<P> Using the Apache Group's proposed CGI/1.2 <QUOTE>(Script-Control:) field. 
The WASD extension-directives <EMPHASIS>(X-record-mode) and
<EMPHASIS>(X-stream-mode) sets the script output into each of the respective
modes. See <REFERENCE>(head_output_script_control).

<P> Examples of usage this field:

<CODE_EXAMPLE>
  Script-Control: X-stream-mode
  Script-Control: X-record-mode
<ENDCODE_EXAMPLE>

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(Script Output Buffering\BOLD)

<P> By default WASD writes each record received from the script to the
client as it is received.  This can range from a single byte to a complete
mailbox buffer full.  WASD leaves it up to the script to determine the rate at
which output flows back to the client.

<P> While this allows a certain flexibility it can be inefficient.  There will
be many instances where a script will be providing just a body of data to the
client, and wish to do it as quickly and efficiently as possible.  Using the
proposed CGI/1.2 <QUOTE>(Script-Control:) field with the WASD extension
directive <EMPHASIS>(X-buffer-records) a script can direct the server to buffer
as many script output records as possible before transfering it to the client. 
The following should be added to the CGI response header.

<CODE_EXAMPLE>
  Script-Control: X-buffer-records
<ENDCODE_EXAMPLE>

<P> While the above offers some significant improvements to efficiency and
perceived throughput the best approach is for the script to provide records the
same size as the mailbox (see <REFERENCE>(head_script_output) for detail on
determining this size if required).  The can be done explicitly by the script
programming  or if using the C language simply by changing <EMPHASIS>(stdout)
to a binary stream.  With this environment the C-RTL will control output,
automatically buffering as much as possible before writing it to the server.

<CODE_EXAMPLE>
  if ((stdout = freopen ("SYS$OUTPUT", "w", stdout, "ctx=bin")) == NULL)
     exit (vaxc$errno);
<ENDCODE_EXAMPLE>

<P> Also see the section describing <REFERENCE>(head_nph_c_script).

<ENDLIST>

<HEAD>(Script-Control:\head_output_script_control)

<P> The <EMPHASIS>(Apache Group) has proposed a CGI/1.2 that includes a
<EMPHASIS>(Script-Control:) CGI response header field.  WASD implements the
one proposed directive, along with a number of WASD extensions (those
beginning with the <QUOTE>(X-)).  Note that by convention extensions unknown by
an agent should be ignored, meaning that they can be freely included, only
being meaningful to WASD and not significant to other implementations.

<LIST>(UNNUMBERED)

<LE><EMPHASIS>(no-abort - \BOLD)
The server must not terminate the script during processing for either
no output or no-progress timeouts.  The script is to be left completely alone
to control it's own termination.  Caution, such scripts if problematic could
easily accumulate and <QUOTE>(clog up) a server or system.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-buffer-records - \BOLD)
Buffer records written by the script until there is [BufferSizeDclOutput] bytes
available then write it as a single block to the client.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-crlf-mode - \BOLD)
The server should always ensure each record has trailing carriage-return then
newline characters (0x0d, 0x0a).  This is generally what VMS requires for
carriage control on terminals, printers, etc.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-lifetime=<EMPHASIS>(value) - \BOLD)
The number of minutes before the idle script subprocess is deleted by the
server.  Zero sets it back to the default, <QUOTE>(none) disables this
functionality. 

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-record-mode - \BOLD)
The server should always ensure each record has a trailing newline
character (0x0a), regardless of whether the response is a <EMPHASIS>(text/...)
content-type or not.  This is what is usually required by browsers for
carriage-control in text documents.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-stream-mode - \BOLD)
The server is not to adjust the carriage-control of records regardless of
whether the response is a <EMPHASIS>(text/...) content-type or not.  What the
script writes is exactly what the client is sent.

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-timeout-noprogress=<EMPHASIS>(value) -\BOLD)
The number of minutes allowed where the script does not transfer any data to
the server before the server deletes the process.  Zero sets it back to the
default, <QUOTE>(none) disables this functionality. 

<COMMENT>(HTML=<P>)

<LE><EMPHASIS>(X-timeout-output=<EMPHASIS>(value) - \BOLD)
The number of minutes allowed before an active script is deleted by the server,
regardless of it still processing the request.  Zero sets it back to the
default, <QUOTE>(none) disables this functionality. 

<ENDLIST>

<P> The following is a simple example response where the server is instructed
not to delete the script process under any circumstances, and that the body
does not require any carriage-control changes.

<CODE_EXAMPLE>
  Content-Type: text/plain
  Script-Control: no-abort; X-stream-mode

  <EMPHASIS>(long, slowww script-output <HELLIPSIS>)
<ENDCODE_EXAMPLE>

<COMMENT>(....................................................................)

<HEAD>(Example DCL Scripts\head_example_dcl_scripts)

<P> A simple script to provide the system time might be:

<CODE_EXAMPLE>
  $ say = "write sys$output"
  $! the next two lines make it CGI-compliant
  $ say "Content-Type: text/plain"
  $ say ""
  $! start of plain-text body
  $ show time
<ENDCODE_EXAMPLE>

<P> A script to provide the system time more elaborately (using HTML):

<CODE_EXAMPLE><LITERAL>
  $ say = "write sys$output"
  $! the next two lines make it CGI-compliant
  $ say "Content-Type: text/html"
  $ say ""
  $! start of HTML script output
  $ say "<HTML>"
  $ say "Hello ''WWW_REMOTE_HOST'"  !(CGI variable)
  $ say "<P>"
  $ say "System time on node ''f$getsyi("nodename")' is:"
  $ say "<H1>''f$cvtime()'</H1>"
  $ say "</HTML>"
<ENDLITERAL>
<ENDCODE_EXAMPLE>

<HEAD2>(Non-Parsed-Header Output\head_nph_output)

<P> A script does not have to output a CGI-compliant data stream.  If it begins
with a HTTP header status line WASD assumes it will supply a
<EMPHASIS>(raw\BOLD) HTTP data stream, containing all the HTTP requirements. 
This is the same or equivalent to the <EMPHASIS>(non-parsed-header), or
<QUOTE>(nph<HELLIPSIS>) scripts of many environments.  This is an example of
such a script response.

<CODE_EXAMPLE><LITERAL>(
  HTTP/1.0 200 Success
  Content-Type: text/html
  Content-Length: 35

  <HTML>
  <B>Hello world!</B>
  </HTML>
)<ENDCODE_EXAMPLE>

<P> Any such script must observe the HyperText Transfer Protocol, supplying a
<EMPHASIS>(full response header and body, including correct
carriage-control\BOLD).  Once the server detects the HTTP status header line it
pays no more attention to any response header fields or body records, just
transfering everything directly to the client.  This can be very efficient, the
server just a conduit between script and client, but does transfer the
responsibility for a correct HTTP response onto the script.

<HEAD>(NPH DCL Script\head_nph_dcl_script)

<P> The following example shows a DCL script.  Note the full HTTP header and
each line explicitly terminated with a carriage-return and line-feed pair. 

<CODE_EXAMPLE><LITERAL>
  $ lf[0,8] = %x0a
  $ crlf[0,16] = %x0d0a
  $ say = "write sys$output"
  $! the next line determines that it is raw HTTP stream
  $ say "HTTP/1.0 200 Success" + crlf
  $ say "Content-Type: text/html" + crlf
  $! response header separating blank line
  $ say crlf
  $! start of HTML script output
  $ say "<HTML>" + lf 
  $ say "Hello ''WWW_REMOTE_HOST'" + lf 
  $ say "<P>" + lf 
  $ say "Local time is ''WWW_REQUEST_TIME_LOCAL'" + lf 
  $ say "</HTML>" + lf 
<ENDLITERAL>
<ENDCODE_EXAMPLE>

<HEAD>(CGIUTL Utility\head_cgiutl)

<P> This assists with the generation of HTTP responses, including the transfer
of binary content from files (copying a file back to the client as part of the
request), and the processing of the contents of POSTed requests from DCL.  See
<REFERENCE>(head_cgi_cgiutl).

<HEAD>(NPH C Script\head_nph_c_script)

<P> When scripting using the C programming language there can be considerable
efficiencies to be gained by providing a binary output stream from the script. 
This results in the C Run-Time Library (C-RTL) buffering output up to the
maximum supported by the IPC mailbox.  This may be simply enabled using a code
construct similar to following to reopen <EMPHASIS>(stdout) in binary mode.

<CODE_EXAMPLE>
  if ((stdout = freopen ("SYS$OUTPUT", "w", stdout, "ctx=bin")) == NULL)
     exit (vaxc$errno);
<ENDCODE_EXAMPLE>

<P> This is used consistently in WASD scripts.  Carriage-control must be
supplied as part of the C standard output (no differently to any other C
program).  Output can be be explicitly sent to the client at any stage using
the <EMPHASIS>(fflush()) standard library function.  Note that if the
<EMPHASIS>(fwrite()) function is used the current contents of the C-RTL buffer
are automatically flushed along the the content of the fwrite().

<CODE_EXAMPLE><LITERAL>
     fprintf (stdout,
  "HTTP/1.0 200 Success\r\n\
  Content-Type: text/html\r\n\
  \r\n\
  <HTML>\n\
  Hello %s\n\
  <P>\n\
  System time is %s\n\
  </HTML>\n",
     getenv("WWW_REMOTE_HOST"),
     getenv("WWW_REQUEST_TIME_LOCAL"));
<ENDLITERAL>
<ENDCODE_EXAMPLE>

<HEAD>(CGI Function Library\head_cgi_cgilib)

<P> A source code collection of C language functions useful for processing the
more vexing aspects of CGI/CGIplus programming.  See
<REFERENCE>(head_cgilib).

<HEAD1>(Raw HTTP Input (POST Processing)\head_nph_input)

<P> For POST and PUT HTTP methods (e.g. a POSTed HTML form) the body of the
request may be read from the HTTP$INPUT stream.  For executable image scripts
requiring the body to be present on SYS$INPUT (the C language
<EMPHASIS>(stdin) stream) a user-mode logical may be defined immediately
before invoking the image, as in the example.

<CODE_EXAMPLE>
  $ EGSCRIPT = "$HT_EXE:EGSCRIPT.EXE"
  $ DEFINE /USER SYS$INPUT HTTP$INPUT
  $ EGSCRIPT
<ENDCODE_EXAMPLE>

<P> The HTTP$INPUT stream may be explicitly opened and read.  Note that this is
a raw stream, and HTTP <EMPHASIS>(lines) (carriage-return/line-feed terminated
sequences of characters) may have been blocked  together for network transport. 
These would need to be explicity parsed by the program.

<COMMENT>(--------------------------------------------------------------------)
