iTP Secure WebServer System Administrator's Guide (Version 7.0)
Using Common Gateway Interface (CGI) Programs
iTP Secure WebServer System Administrator’s Guide—523346-012
8-33
Design Guidelines
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 need to watch for memory leaks and file-open leaks.
•
State information should not be maintained in the server.
Example 8-2. Sample cgilib.h File
#ifndef _CGILIB
#define _CGILIB
#ifndef _CGI_NO_EXTERNALS
extern void _MAIN (void);
int *DummyMainPTR = (int *) _MAIN
#endif
size_t CGI_fwrite(const void *buffer,size_t size,size_t num_items,FILE
*stream);
size_t CGI_fread (void *buf, size_t size,size_t num_items,FILE *stream);
char *CGI_fgets(char *, int, FILE * stream);
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 */