[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
|1CGIplus|

|style|._cgipplus th { padding:0 0.3em 0 0.3em; font-size:1.1em; } |
|table-'_cgipplus|
|~ |: Common Gateway Interface |: |...| |: plus lower latency,
|~ |: |: |: plus greater throughput,
|~ |: |: |: plus far less system impact!
|!table|

|^ |&font-size:1.1em;.I know, I know!  The term |_CGIplus| is a bit |_too cute|
but I had to call it something!|

|^ CGIplus attempts to eliminate the overhead associated with creating the
script process and then executing the image of a CGI script.  It does this by
allowing the script process and any associated image/application to continue
executing between uses, eliminating startup overheads.  This reduces both the
load on the system and the request latency.  In this sense these advantages
parallel those offered by commercial HTTP server-integration APIs, such as
Netscape NSAPI and Microsoft ISAPI, without the disadvantages of such
proprietory interfaces, the API complexity, language dependency and server
process integration.

|^ Existing CGI scripts can rapidly and elegantly be modified to
additionally support CGIplus. The capability of scripts to easily
differentiate between and operate in both standard CGI and CGIplus
environments with a minimum of code revision offers great versatility.  Many
WASD scripts operate in both environments.

|0CGIplus Performance|

|^ A simple performance evaluation indicates the advantage of CGIplus.  See
"Techncial Overview, Performance" for some test results comparing the
CGI and CGIplus environments.

|^ Without a doubt, the subjective difference in activating the same script
within the standard CGI and CGIplus environments is quite startling!

|2CGIplus Programming|

|^ |*The script interface is still CGI||, with all the usual
environment variables and input/output streams available, which means a new API
does not need to be learned and existing CGI scripts are simple to modify.

|^ See examples in
|link%|/wasd_root/src/CGIplus/*.*|WASD_ROOT:[SRC.CGIPLUS]|

|^ Instead of having the CGI variables available from the environment
(generally accessed via the C Language |/getenv()| standard library
call, or via DCL symbols) a CGIplus script must read the CGI variables from an
I/O stream named CGIPLUSIN.  The variables can be supplied in one of two modes.

|bullet|

|item| |*Record Mode |-| | Each CGI variable is supplied as an individual
record (line).  This is the default, and simplest method.  Each contains a CGI
variable name (in upper-case), an equate symbol and then the variable value.
The format may be easily parsed and as the value contains no encoded characters
may be directly used.  The quantity of characters in each record depends on the
size of the variable name and the length of the associated value.  The value
can vary from zero, to tens, hundreds, even thousands of characters.  It is
limited by the size of the CGIPLUSIN mailbox, which is in turn set by the
[BufferSizeDclCgiPlusIn] configuration directive.

|item| |*Struct Mode |-| | All variables are supplied in a binary structure
which must be parsed by the receiving script.  This is the most efficient
method for providing the CGIplus script with its CGI environment.  Performance
improvements in the order of 50-100% have been measured.  This size of this
structure is limited by the size of the CGIPLUSIN mailbox, which is in turn set
as described above.

|!bullet|

|0Record-Mode CGIplus|

|^ This default and simple record-oriented mode allows any environment that
can read records from an input source to process CGIplus variables.  This of
course includes DCL (examples referenced below).

|bullet|

|item| The read will block between subsequent requests and so may be used to
coordinate the application.

|item| The first record read in any request can always be discarded.  This is
provided so that a script may be synchronized outside of the general CGIplus
variable read loop.  Record-mode can always be recognised by the single
exclamation symbol comprising this record.

|item| The CGIplus variable stream |*must always be completely
read||, record-by-record up until the the first empty record (blank line,
see below) before beginning any request processing. 

|item| An empty record (blank line) indicates the end of a single request's
CGIplus variable stream. Reading MUST be halted at this stage.  Request
processing may then commence.

|!bullet|

|0Struct-Mode CGIplus|

|^ This mode offers significantly lower system overheads and improves latency
and performance at the cost of the additional complexity of recovering the
variables from a binary structure.  Code examples and CGILIB functions make
this relatively trivial at the application level.

|bullet|

|item| The read will block between subsequent requests and so may be used to
coordinate the application.

|item| The first record read in any request contains the size of the following
binary record.  It is also provided so that a script may be synchronized outside
of the general CGIplus variable read loop.  Struct-mode can always be
recognised by the two, successive, leading exclamation marks preceding the
variable structure record size integer.

|item| The CGIplus variables are read as a single, binary I/O.

|item| The contents of the binary structure must be parsed to obtain the
individual CGI variables. Request processing may then commence.

|!bullet|

|0Requirements when using CGIplus|

|^ After processing, the CGIplus script can loop, waiting to read the details
of the next request from CGIPLUSIN.

|^ Request output (to the client) is written to SYS$OUTPUT (<stdout>) as per
normal CGI behaviour. |*End of output MUST be indicated by writing a special
EOF record to the output stream.|  A unique EOF sequence is  generated for each
use of DCL via a zombie or CGIplus script process. A non-repeating series of
bits most unlikely to occur in normal output is employed |...| but there is
still a very, very, very small chance of premature termination of output (one
in 2^\<sup\>224\</sup\> I think!)
See |link%|/wasd_root/src/httpd/cgi.c|WASD_ROOT:[SRC.HTTPD]CGI.C| for how the
value is generated.

|^ The CGIplus EOF string is obtained by the script from the logical name
CGIPLUSEOF, defined in the script process' process table, using the scripting
language's equivalent of F$TRNLNM(), SYS$TRNLNM(), or a getenv() call (in the C
standard library). This string will always contain less than 64 characters and
comprise only printable characters. It must be written at the conclusion of a
request's output to the output stream as a single record (line) but may also
contain a <CR><LF> or just <LF> trailing carriage-control (to allow for
programming language  requirements). It only has to be evaluated once, as the
processing begins, remaining the same for all requests over the life-time of
that instance of the script.

|^ HTTP input (raw request body stream) is still available to a CGIplus script.

|0CGI Function Library|

|^ A source code collection of C language functions useful for processing the
more vexing aspects of CGI/CGIplus/RTE programming (|link|Scripting Function
Library||).

|2Code Examples|

|^ Of course a CGIplus script should only have a single exit point and should
explicitly close files, free allocated memory, etc., after processing a request
(i.e. not rely on image run-down to clean-up after itself). It is particularly
important when modifying existing scripts to work in the CGIplus environment to
ensure this requirement is met (who of us hasn't thought "well, this file will
close when the image exits anyway"?)

|^ It is a simple task to design a script to modify its behaviour according to
the environment it is executing in. Detecting the presence or absence of the
CGIPLUSEOF logical is sufficient indication. The following C code fragment
shows simultaneously determining whether it is a standard or CGIplus
environment (and setting an appropriate boolean), and getting the CGIplus EOF
sequence (if it exists).

|code|
int  IsCgiPlus;
char  *CgiPlusEofPtr;

IsCgiPlus = ((CgiPlusEofPtr = getenv("CGIPLUSEOF")) != NULL);
|!code|

|0Record-Mode Code|

|^ The following C code fragment shows a basic CGIplus record-mode request
loop, reading lines from CGIPLUSIN, and some basic processing to select
required CGI variables for request processing.  Generally this level of coding
is not required as it is recommended to employ the functionality of something
like the CGILIB functiona library.

|code|
if (IsCgiPlus)
{
   char  *cptr;
   char  Line [1024],
         RemoteHost [128];
   FILE  *CgiPlusIn;

   if ((CgiPlusIn = fopen (getenv("CGIPLUSIN"), "r")) == NULL)
   {
      perror ("CGIplus: fopen");
      exit (0);
   }

   for (;;)
   {
      /* will block waiting for subsequent requests */
      for (;;)
      {
         /* should never have a problem reading CGIPLUSIN, but */
         if (fgets (Line, sizeof(Line), CgiPlusIn) == NULL)
         {
            perror ("CGIplus: fgets");
            exit (0);
         }
         /* first empty line signals the end of CGIplus variables */
         if (Line[0] == '\\n') break;
         /* remove the trailing newline */
         if ((cptr = strchr(Line, '\\n')) != NULL) *cptr = '\\0';

         /* process the CGI variable(s) we are interested in */
         if (!strncmp (Line, "WWW_REMOTE_HOST=", 16))
            strcpy (RemoteHost, Line+16);
      }

      |/(process request, signal end-of-output)||
   }
}
|!code|

|0Struct-Mode Code|

|^ This mode requires significantly more code than record-mode.  A
self-contained C language function, allowing CGI variable processing in
standard CGI, CGIplus record-mode and CGIplus struct-mode, is available for
inclusion in user applications.  It automatically detects the environment and
changes behaviour to suit.  This or CGILIB is strongly recommended.

|^ See source in
|link%|/wasd_root/src/CGIplus/CGIplus_cgivar.c|\
WASD_ROOT:[SRC.CGIPLUS]CGIPLUS_CGIVAR.C|

|0CGIplus Output|

|^ CGI scripts can write output in record (line-by-line) or binary mode (more
efficient because of buffering by the C RTL).  When in binary mode the output
stream must be flushed immediately before and after writing the CGIplus EOF
sequence (note that in binary a full HTTP stream must also be used). This code
fragment shows placing a script output stream into binary mode and the flushing
steps.

|code|
/* reopen output stream so that the '\\r' and '\\n' are not filtered */
if ((stdout = freopen ("SYS$OUTPUT", "w", stdout, "ctx=bin")) == NULL)
   exit (vaxc$errno);

do {

   |/(read request ...)||

   /* CGI response header */
   fprintf (stdout, "Content-Type: text/html\\n\\n");

   |/(other output ...)||

   if (IsCgiPlus)
   {
      /* the CGIplus EOF must be an independant I/O record */
      fflush (stdout);
      fprintf (stdout, "%s", CgiPlusEofPtr);
      fflush (stdout);
   }

} while (IsCgiPlus);
|!code|

If the script output is not binary (using default <stdout>) it is only
necessary to ensure the EOF string has a record-delimiting new-line.

|code|
fprintf (stdout, "%s\\n", CgiPlusEofPtr);
|!code|

Other languages may not have this same requirement.  DCL procedures are quite
capable of being used as CGIplus scripts.

|^ See examples in
|link%|/wasd_root/src/CGIplus/*.*|WASD_ROOT:[SRC.CGIPLUS]|

|note|
|0Hint!|
Whenever developing CGIplus scripts/applications (unlike standard CGI) don't
forget that after compiling, the old image must be purged from the server
before trying out the new!!!  (I've been caught a number of times |=.:^)|  |^
Scripting processes may be purged or deleted using (see
|link%|../features/##HTTPd Command Line++in++WASD Features||).

|code|
$ HTTPD /DO=DCL=DELETE
$ HTTPD /DO=DCL=PURGE
|!code|
|!note|

|2Other Considerations|

|^ Multiple CGIplus scripts may be executing in multiple processes at any one
time.  This includes multiple instances of any particular script.  It is the
server's task to track these, distributing appropriate requests to idle
processes, monitoring those currently processing requests, creating new
instances if and when necessary, and deleting the least-used, idle CGIplus
processes when configurable thresholds are reached.  Of course it is the
script's job to maintain coherency if multiple instances may result in resource
conflicts or race conditions, etc., between the scripts.

|^ The CGIplus script process can be given a finite life-time set by
configuration parameter (see "Features and Facilities, Server Configuration"). 
If this life-time is not set then  the CGIplus will persist indefinitely (i.e.
until purged due to soft-limits being reached, or explicitly purged/deleted). 
When a life-time has been set the CGIplus process is automatically deleted
after being idle for the specified period (i.e. not having processed a
request).  This can be useful in preventing sporadically used scripts from
cluttering up the system indefinitely.

|^ In addition, an idle CGIplus script can be run-down by the server at any
time the script process soft-limit is reached, so resources should be largely
quiescent when not actually processing (|link|Script Process Run-down||).  Of
course, in extreme situations, a CGIplus process may also be manually
terminated from the command line (e.g. STOP/ID=).

|^ Some CGIplus scripting information and management is available via the
server administration menu, see "Features and Facilities, Server Reports".

|0CGIplus Rule Mapping|

|^ CGIplus scripts are differentiated from standard CGI scripts in the mapping
rule configuration file using the "script+" and "exec+" directives (see
|link%|../config/##Request Processing Configuration++in++WASD Configuration||).

|^ Scripts capable of operating in both standard CGI and CGIplus environments
may simply be accessed in either via rules such as

|code|
exec /cgi-bin/* /cgi-bin/*
exec+ /cgiplus-bin/* /cgi-bin/*
|!code|

while specific scripts can be individually designated as CGIplus using

|code|
script+ /cgiplus_example* /cgi-bin/cgiplus_example*
|!code|

|note|
|0Hint!|
When changing CGIplus script mapping it is advised to purge execution of
existing scripts then reloading the mapping rules.  Some conflict is possible
when using new rules while existing CGIplus scripts are executing.
|code|
$ HTTPD /DO=DCL=PURGE
$ HTTPD /DO=MAP
|!code|
|!note|