CGIParse project is a C class library for parsing the input of a cgi program.
To start using CGIParse you first have to include the cgiparse.h header:
#include < cgiparse.h >
Thereafter you have to define the CGIParse object:
The CGIParse object then automatically reads the headers and the variables parsed to the program using environment variables and (if using POST or PUT) standard input.
Now the library has been initialized and we are ready to use it.
The headers parsed to CGIParse is easily available to the programmer after the library has been initialized. To retrieve them CGIParse provides functions named after the environment variable it retrieves. Fx. to retrieve the SERVER_SOFTWARE environment variable, you use the function server_software(). The functions providing these environment variables are:
It is important to note that if the environment variable you are trying to access doesn't exist, the function will return NULL if you were trying to retrieve a char* and -1 if it's a int.
The variables from the browser can of course also be accessed by CGIParse.
To retrieve the number of variables, you can use the int num() function, and to retrieve the variable names and parameters number i, you user the functions:
char* name ( int i );
char* parm ( int i );
You can also use the function char* parm ( const char *n ); to retrieve the parameter of the variable with name n.
When debugging your CGI application it can sometimes be useful to see what is transfered to the CGI application. You could of course program this yourself, but for your ease some functions for it has been provided the function htable() draws a html table with the header retrieved from CGI.
CGIParse also provide you with a function called ptable() which prints the variables sent to the CGI application.