iTP Secure WebServer System Administrators Guide (Version 7.5+)

Table 22 Sample cgilib.h File (continued)
int CGI_feof(FILE * stream);
int CGI_printf(const char *format, ...);
int CGI_getc(FILE * stream);
int CGI_puts(const char *buffer);
int CGI_main(int argc, char *argv[]);
void ErrorAbort(void);
void CGI_connection_abort(void);
void CGI_initialize(void);
void CGI_terminate(void);
int CGI_fflush(FILE * stream);
int CGI_set_fflush_timer(int seconds);
void CGI_Capture(void);
#endif /* CGILIB */
Design Guidelines
Most CGI programs do not clean up their environments. Programs are written with the assumption
that the process exits upon completion of the HTTP request. Because Pathway CGI programs are
persistent, you should be aware of these coding considerations:
Code must be written to be serially reusable between invocations of CGI_main.
The CGI environment changes on each invocation of CGI_main. To access your environment
variables, use CGI_initialize(), as follows:
1. Write a CGI_initialize() routine in your CGI program.
2. In this routine, call getenv(). This returns the current environment variable.
3. In your CGI_main routine, call getenv() again. This call returns the WebServer's
environment variables.
You must watch for memory leaks and file-open leaks.
State information should not be maintained in the server.
Examples of a Pathway CGI Implementation
“Sample Pathway CGI Program (page 162) displays you how a CGI program might be written as
a Pathway server class.
Table 23 Sample Pathway CGI Program
/*
This is a simple little test program that demonstrates how to
write a CGI routine as a Pathway Server Class.
This routine assumes that the forms data has been put into
the standard environment. The "Region" command that should
be used is:
Region /* {
AddCGI AUTOMATIC_FORM_DECODING ON
}
To retrieve the value of the following filled out form entry:
<INPUT SIZE=30 NAME="First_Name"> <b>Your First Name</b> <br>
Use:
getenv("First_Name");
OR
Region /* {
AddCGI AUTOMATIC_FORM_DECODING ON
AddCGI FORM_DECODING_PREFIX
your_prefix_
}
To retrieve the value of the following filled out form entry:
<INPUT SIZE=30 NAME="First_Name"> <b>Your First Name</b> <br>
Use:
getenv("your_prefix_First_Name");
In the first example the environment variables will be made with the same
162 Using Common Gateway Interface (CGI) Programs