[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]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
/*****************************************************************************/
/*
                                IPCtickler.c

The CGI script Inter-Process Communication (IPC) tickler is designed to allow a
script programmer to gain an appreciation of the way WASD interacts with VMS'
record-oriented Input/Output (I/O) design, how the C Language Run-Time Library
interprets U**x I/O conventions into this, how WASD attempts to accomodate
both, how the mechanisms a script can use to explicitly convey exact
requirements to WASD ... and finally, how these affect output (in particular
the carriage-control) delivered to the client.  Use

  http://the.host.name/cgi-bin/ipctickler

to obtain an HTML form allowing control of several parameters into the script.


COPYRIGHT
---------
Copyright (C) 2005-2021 Mark G.Daniel.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


BUILD DETAILS
-------------
$ @BUILD_ONE BUILD IPCTICKLER


VERSION HISTORY
---------------
30-JAN-2007  MGD  v1.2.0, modify for non-WASD but CGI compliant server
                          (in this case to investigate Purveyor CGI)
30-AUG-2005  MGD  v1.1.0, ctx=xplct (thanks JPP)
27-AUG-2005  MGD  v1.0.0, initial development
*/
/*****************************************************************************/

#define SOFTWAREVN "1.2.0"
#define SOFTWARENM "IPCTICKLER"
#ifdef __ALPHA
   char SoftwareID [] = SOFTWARENM " AXP-" SOFTWAREVN;
#endif
#ifdef __ia64
   char SoftwareID [] = SOFTWARENM " IA64-" SOFTWAREVN;
#endif
#ifdef __VAX
   char SoftwareID [] = SOFTWARENM " VAX-" SOFTWAREVN;
#endif
#ifdef __x86_64
   char SoftwareID [] = SOFTWARENM " X86-" SOFTWAREVN;
#endif

#define SS$_FISH 2928

#ifndef SETENV_FORM
#define SETENV_FORM 0
#endif

/* standard C header files */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>

int TicklerForm (int);

/*****************************************************************************/
/*
*/

main ()

{
   static char  fillch [] =
"0123456789_abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   int  hexch, total_chars, mrs, result, rec_size,
        use_fputs, use_fwrite_n1, use_fwrite_1n;
   char  *bptr, *bufptr, *cptr, *ctxptr, *ctypeptr, *xplctptr,
         *modeptr, *mrsptr, *qsptr, *sptr, *zptr;
   char  vname [256] = "WWW_FORM_",
         value [256];

   /*********/
   /* begin */
   /*********/

   mrsptr = getenv("WWW_GATEWAY_MRS");
   if (mrsptr)
      mrs = atoi(mrsptr);
   else
      mrs = 0;

   qsptr = getenv("WWW_QUERY_STRING");
   if (qsptr && !*qsptr) qsptr = NULL;
   if (!qsptr)
   {
      TicklerForm (mrs);
      exit (1);
   }

   if (!getenv("WWW_FORM_CHARS"))
   {

#if SETENV_FORM
#if __CRTL_VER >= 70000000 /* yup - only V7.0 and later */

      /* no "FORM_" CGI environment variables, make some */
      cptr = qsptr;
      while (*cptr)
      {
         sptr = vname + 9;
         while (*cptr && *cptr != '=') *sptr++ = toupper(*cptr++);
         if (!*cptr) exit (SS$_FISH);
         *sptr = '\0';
         cptr++;
         sptr = value;
         while (*cptr && *cptr != '&')
         {
            if (*cptr == '%')
            {
               if (sscanf (cptr+1, "%2X", &hexch) != 1) exit (SS$_FISH);
               *sptr++ = (char)hexch;
               cptr += 3;
            }
            else
               *sptr++ = *cptr++;
         }
         *sptr = '\0';
         if (*cptr) cptr++;
         setenv (vname, value, 1);
      }

#endif /* __CRTL_VER >= 70000000 */
#endif /* SETENV_FORM */

      if (!getenv("WWW_FORM_CHARS")) exit (SS$_FISH);
   }

   cptr = getenv("WWW_FORM_CHARS");
   if (!cptr) cptr = "2048";
   total_chars = atoi(cptr);

   cptr = getenv("WWW_FORM_SIZE");
   if (!cptr) cptr = "0";
   rec_size = atoi(cptr);

   cptr = getenv("WWW_FORM_CTX");
   if (!cptr) cptr = "";
   if (!strcmp (cptr, "rec")) 
       ctxptr = "ctx=rec";
   else
   if (!strcmp (cptr, "bin")) 
       ctxptr = "ctx=bin";
   else
       ctxptr = "ctx=rec";

   cptr = getenv("WWW_FORM_XPLCT");
   if (!cptr) cptr = "";
   if (*cptr)
      xplctptr = "ctx=xplct";
   else
      xplctptr = NULL;

   cptr = getenv("WWW_FORM_FUNC");
   if (!cptr) cptr = "";
   use_fputs = use_fwrite_n1 = use_fwrite_1n = 0;
   if (!strcmp (cptr, "fputs")) 
      use_fputs = 1;
   else
   if (!strcmp (cptr, "fwrite_n1")) 
      use_fwrite_n1 = 1;
   else
   if (!strcmp (cptr, "fwrite_1n")) 
      use_fwrite_1n = 1;
   else
      use_fputs = 1;

   cptr = getenv("WWW_FORM_MODE");
   if (!cptr) cptr = "";
   if (!strcmp (cptr, "x-record-mode")) 
       modeptr = "Script-Control: X-record-mode\n";
   else
   if (!strcmp (cptr, "x-stream-mode")) 
       modeptr = "Script-Control: X-stream-mode\n";
   else
       modeptr = "";

   cptr = getenv("WWW_FORM_BUFFER");
   if (!cptr) cptr = "";
   if (!strcmp (cptr, "x-buffer-records")) 
       bufptr = "Script-Control: X-buffer-records\n";
   else
       bufptr = "";

   ctypeptr = getenv("WWW_FORM_CTYPE");
   if (!ctypeptr) ctypeptr = "text/plain";

   /* make it obvious for an observer by tuning off transfer optimisations */
   fprintf (stdout,
"Content-Type: %s\n\
Script-Control: X-content-encoding-gzip=0\n\
Script-Control: X-transfer-encoding-chunked=0\n\
%s%s\n",
            ctypeptr, modeptr, bufptr);

   if (xplctptr)
      if (!(stdout = freopen ("SYS$OUTPUT:", "w", stdout, ctxptr, xplctptr)))
         exit (vaxc$errno);
   else
      if (!(stdout = freopen ("SYS$OUTPUT:", "w", stdout, ctxptr)))
         exit (vaxc$errno);

   fprintf (stdout,
"mailbox mrs: %d\nrecord size: %d\ntotal chars: %d\n\
fopen(%s%s%s)\n%s%s%s\n%s%s",
            mrs, rec_size, total_chars,
            ctxptr, xplctptr ? "," : "", xplctptr ? xplctptr : "",
            use_fputs ? "fputs()" : "",
            use_fwrite_n1 ? "fwrite(n,1)" : "",
            use_fwrite_1n ? "fwrite(1,n)" : "",
            modeptr, bufptr);
   fflush (stdout);

   if (!rec_size) rec_size = sizeof(fillch);
   bptr = sptr = calloc (1, total_chars+2);
   if (!bptr) exit (vaxc$errno);
   zptr = sptr + total_chars;
   while (sptr < zptr)
   {
      if (!*cptr) cptr = fillch;
      if (!((sptr - bptr) % rec_size))
      {
         *sptr++ = '\n';
         *sptr++ = '*';
         cptr = fillch;
      }
      *sptr++ = *cptr++;
   }
   *sptr = '\n';
   *sptr = '\0';

   if (use_fputs)
   {
      result = fputs (bptr, stdout);
      if (result >= 0) result = total_chars;
   }
   else 
   if (use_fwrite_n1)
   {
      result = fwrite (bptr, total_chars, 1, stdout);
      result = result * total_chars;
   }
   else 
      result = fwrite (bptr, 1, total_chars, stdout);
   fflush (stdout);

   if (!strcmp (modeptr, "Script-Control: X-stream-mode\n"))
      fputs ("\n", stdout);
   if (result >= 0)
      fprintf (stdout, "\nOUTPUT: %d chars\n", result);
   else
      fprintf (stdout, "+++ OUTPUT FAILED +++\n");
}

/*****************************************************************************/
/*
*/

TicklerForm (int mrs)

{
   char  *CgiScriptNamePtr;

   /*********/
   /* begin */
   /*********/

   CgiScriptNamePtr = getenv ("WWW_SCRIPT_NAME");
   if (!CgiScriptNamePtr) exit (SS$_FISH);

   fprintf (stdout,
"Content-Type: text/html\n\
\n\
<HTML>\n\
<HEAD>\n\
<TITLE>%s</TITLE>\n\
</HEAD>\n\
<BODY>\n\
<FORM ACTION=\"%s\" METHOD=\"GET\">\n\
<TABLE CELLPADDING=\"5\" CELLSPACING=\"2\" BORDER=\"0\">\n\
<TR><TH COLSPAN=\"4\"><U>CGI Script IPC Tickler</U></TH></TR>\n\
<TR><TD></TD></TR>\n\
<TR><TH ALIGN=\"right\">mailbox MRS:&nbsp;</TH>\
<TD ALIGN=\"left\">%d</TD></TR>\n\
<TR><TH ALIGN=\"right\">record size:&nbsp;</TH><TD ALIGN=\"left\">\
<INPUT TYPE=\"text\" NAME=\"size\" VALUE=\"0\" SIZE=\"5\">\
</TD></TR>\n\
<TR><TH ALIGN=\"right\">total chars:&nbsp;</TH><TD ALIGN=\"left\">\
<INPUT TYPE=\"text\" NAME=\"chars\" VALUE=\"%d\" SIZE=\"7\">\
</TD></TR>\n\
<TR><TH ALIGN=\"right\">fopen() ctx=&nbsp;</TH><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"ctx\" VALUE=\"rec\" CHECKED>rec\
</TD><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"ctx\" VALUE=\"bin\">bin\
</TD></TR>\n\
<TR><TD COLSPAN=\"2\"></TD><TD>\
<INPUT TYPE=\"checkbox\" NAME=\"xplct\" VALUE=\"yep\">xplct\
</TD></TR>\n\
<TR><TH ALIGN=\"right\">function:&nbsp;</TH><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"func\" VALUE=\"fputs\" CHECKED>fputs()\
</TD><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"func\" VALUE=\"fwrite_n1\">fwrite(n,1)\
</TD><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"func\" VALUE=\"fwrite_1n\">fwrite(1,n)\
</TD></TR>\n\
<TR><TH ALIGN=\"right\" VALIGN=\"top\" ROWSPAN=\"2\">script-control:&nbsp;</TH>\
<TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"mode\" VALUE=\"x-record-mode\">X-record-mode\
</TD><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"mode\" VALUE=\"x-stream-mode\">X-stream-mode\
</TD><TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"mode\" VALUE=\"\" CHECKED>(none)\
</TD></TR>\n\
<TR><TD></TD><TD>\
<INPUT TYPE=\"checkbox\" NAME=\"buffer\" VALUE=\"x-buffer-records\">X-buffer-records\
</TD></TR>\n\
<TR><TH ALIGN=\"right\">content-type:</TH>\
<TD ALIGN=\"left\">\
<INPUT TYPE=\"radio\" NAME=\"ctype\" VALUE=\"text/plain\" CHECKED>\
text/plain\
</TD><TD ALIGN=\"left\" COLSPAN=\"2\">\
<INPUT TYPE=\"radio\" NAME=\"ctype\" VALUE=\"application/octet-stream\">\
application/octet-stream\
</TD></TR>\n\
<TR><TD></TD></TR>\n\
<TR><TD ALIGN=\"center\" COLSPAN=\"4\">\
<INPUT TYPE=\"submit\" VALUE=\"tickle\">&nbsp;&nbsp;&nbsp;\
<INPUT TYPE=\"reset\" VALUE=\"reset\">\
</TD></TR>\n\
</TABLE>\n\
<TABLE CELLPADDING=\"20\" CELLSPACING=\"0\" BORDER=\"0\">\n\
<TR><TD>\n\
The CGI script Inter-Process Communication (IPC) tickler is designed to \
allow a script programmer to gain an appreciation of the way WASD interacts \
with VMS\' record-oriented Input/Output (I/O) design, how the C Language \
Run-Time Library interprets U**x I/O conventions into this, how WASD \
attempts to accomodate both, how the mechanisms a script can use to \
explicitly convey exact requirements to WASD ... and finally, how these \
affect output (in particular the carriage-control) delivered to the client.\n\
<P>Check the WASD <A HREF=\"/wasd_root/doc/scripting/\">Scripting</A> document \
for information on the handling of \
<A HREF=\"/wasd_root/doc/scripting/scripting_0200.html\">Script Output</A> in \
relation to &quot;text/..&quot; and non-&quot;text/..&quot; content-type.\n\
Use this utility to manipulate the record size (number of characters between \
newlines) and total characters output against stream mode and C-RTL output \
function, to observe how (implied) carriage-control is provided to the \
client.\n\
WASD CGI response fields can be added to manipulate the desired programming \
requirement and outcome.\n\
<P>Use the \
<A HREF=\"/wasd_root/doc/features/features_0900.html\">WATCH facility</A> \
with <I>CGI</I>, <I>DCL</I> and <I>Network Activity/Data</I> items to \
directly observe the octets provided by the script and subsequently provided \
to the client.\n\
</TD></TR>\n\
</TABLE>\n\
</BODY>\n\
</HTML>\n",
      SoftwareID, CgiScriptNamePtr, mrs, mrs/2);
}

/*****************************************************************************/