[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]
/*****************************************************************************/
/*
                             CGIplusLoop.c

A skeletal program serving as a template for CGIplus-capable scripts.
CGIplus only!  Has simple loop, blocking while waiting for requests, and then
obtaining CGIplus variables.


COPYRIGHT
---------
Copyright (C) 1997-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.


08-JUN-97  MGD  v1.0.0, initial development
*/
/*****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>

int  IsCgiPlus = 0;
char  *CgiPlusEofPtr = NULL;

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

main ()

{
#  define CGIPLUS_LINE_SIZE 1024

   int  Count = 0;
   char  *cptr;
   char  Line [CGIPLUS_LINE_SIZE],
         RemoteHost [128];
   FILE  *SysCommand;

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

   if (!IsCgiPlus)
   {
      fprintf (stdout,
"Content-Type: text/html\n\
\n\
Sorry! &nbsp;CGIplus only!\n");
      exit (1);
   }

   if ((SysCommand = fopen (getenv("CGIPLUSIN"), "r")) == NULL)
      return (vaxc$errno);

   for (;;)
   {
      /* will block waiting for subsequent requests */
      for (;;)
      {
         if (fgets (Line, sizeof(Line), SysCommand) == NULL) exit (vaxc$errno);
         /* 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';

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

      fprintf (stdout,
"Content-Type: text/html\n\
Expires: Thu, 01 Jan 1970 00:00:01 GMT\n\
\n\
%d. <B>Hello world</B> ... well the \
<FONT SIZE=+1>&nbsp;<TT>%s</TT>&nbsp;</FONT> part of it anyway!\n",
               ++Count, RemoteHost);

      /* record-oriented <stdout>, no need to flush, write end-of-output line */
      if (IsCgiPlus) fprintf (stdout, "%s\n", CgiPlusEofPtr);
   }

   exit (1);
}

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