iTP Secure WebServer System Administrator's Guide (iTPWebSvr 5.1+)

Using Common Gateway Interface (CGI) Programs
iTP Secure WebServer System Administrators Guide522659-001
8-35
Examples of a Pathway CGI Implementation
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"));
if (Test_Count){
CGI_printf("<h2>Printing %d test lines.</h2>",Test_Count);
for (i=1;i<=Test_Count;i++){
CGI_printf("Test Line %d
....|...10....|...20....|...30....|...40....|...50<BR>",i);
}
}
/* CASE=DEFAULT FALL THROUGH */
} else {
CGI_printf("Unrecognized method '%s'.\n", getenv("REQUEST_METHOD"));
}
return 0;
}
Example 8-3. Sample Pathway CGI Program (page 3 of 3)