iTP Secure WebServer System Administrator's Guide (Version 7.0)

Using Common Gateway Interface (CGI) Programs
iTP Secure WebServer System Administrator’s Guide523346-012
8-35
Examples of a Pathway CGI Implementation
#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"));
}
Example 8-3. Sample Pathway CGI Program (page 2 of 3)