iTP Secure WebServer System Administrators Guide (Version 7.5+)
Table 23 Sample Pathway CGI Program (continued)
names as the name portion of the name value pair.
In the second example the names of all decoded from are prefixed with the
prefix "your_prefix_".
Using the prefix option can be useful if you expect duplication of names on
your form with default CGI parameters.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/types.h>
#include <cgilib.h>
extern char **environ;
int CGI_main(int argc,char *argv[])
{
static int get=0;
static int post=0;
int i=0;
int content_length=0;
int count_read;
char buffer[4096];
char *name=NULL;
char *equalsign=NULL;
int Test_Count=0;
/* Always print a header */
CGI_printf("Content-type: text/html\n\n");
/* This is a logical case on REQUEST_METHOD */
/* CASE=HEAD */
if (!strcmp(getenv("REQUEST_METHOD"),"HEAD")){
/* Nothing to do here */
/* CASE=GET */
}
else if (!strcmp(getenv("REQUEST_METHOD"),"GET")){
get++;
CGI_printf("<title>Template CGI Demo Form</title>");
CGI_printf("<h1>CGI Forms Demo</h1>\n");
CGI_printf("<FORM METHOD=\"POST\"ACTION=\"%s\">\n,
getenv("SCRIPT_NAME"));
}
CGI_printf("<INPUT SIZE=30 NAME=\"First_Name\"> <b>Your First Name</b>
<br>");
CGI_printf("<INPUT SIZE=30 NAME=\"Last_Name\"> <b>Your Last Name</b>
<br>");
CGI_printf("The following entry will control the number of test lines
that are printed in the response.<BR>");
CGI_printf("<INPUT SIZE=6 NAME=\"Test_Count\" ><b>Test Line count</b>
br>");
CGI_printf("<INPUT TYPE=\"submit\" VALUE=\"Send
Message\"></form><br></html>%c%c",LF,LF);
/* CASE=POST */
} else if (!strcmp(getenv("REQUEST_METHOD"),"POST")){
post++;
CGI_printf("<title>CGI Demo Form</title>\n);
CGI_printf("<h1>CGI Form Response</h1>\n");
CGI_printf("Get count: %d<BR>Post count: %d<BR>\n",get,post);
CGI_printf("<H2>Environment Variables</H2>\n);
/* This loop reads through the environment variables and displays them
*/
for (i=0;environ[i];i++) {
strcpy(buffer,environ[i]);
equalsign=strchr(buffer,'=');
*equalsign=0;
equalsign+=1;
CGI_printf("<b>%s</b> %s<BR>\n%c",buffer, equalsign);
}
Test_Count=atoi(getenv("Test_Count"));
Examples of a Pathway CGI Implementation 163










