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

Using Common Gateway Interface (CGI) Programs
iTP Secure WebServer System Administrators Guide522659-001
8-32
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 the following 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.
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 */