Easy CGI unit

ezcgi, written by Michael Hess, provides a single class which offers simple access to the CGI environment which a CGI program operates under. It supports both GET and POST methods. It's intended for simple CGI programs which do not need full-blown CGI support. File uploads are not supported by this component.

To use the unit, a descendent of the TEZCGI class should be created and the DoPost or DoGet methods should be overidden.

Stringlist and stream support Null-terminated string support Exception support and string formatting routines Integer to hex code conversion table String constant used to convert a number to a hexadecimal code or back. Exception raised by TEZcgi Easy CGI class

TEZcgi implements all functionality to analyze the CGI environment and query the variables present in it. It's main use is the exposed variables.

Programs wishing to use this class should make a descendent class of this class and override the DoPost or DoGet methods. To run the program, an instance of this class must be created, and it's Run method should be invoked. This will analyze the environment and call the DoPost or DoGet method, depending on what HTTP method was used to invoke the program.

Creates a new instance of the TEZCGI component Create initializes the CGI program's environment: it reads the environment variables passed to the CGI program and stores them in the Variable property. Variables Names Values Removes the TEZCGI component from memory

Destroy removes all variables from memory and then calls the inherited destroy, removing the TEZCGI instance from memory.

Destroy should never be called directly. Instead Free should be used, or FreeAndNil

Create
Run the CGI application.

Run analyses the variables passed to the application, processes the request variables (it stores them in the Variables property) and calls the DoPost or DoGet methods, depending on the method passed to the web server.

After creating the instance of TEZCGI, the Run method is the only method that should be called when using this component.

Variables DoPost DoGet
Writes the content type to standard output WriteContent writes the content type cType to standard output, followed by an empty line. After this method was called, no more HTTP headers may be written to standard output. Any HTTP headers should be written before WriteContent is called. It should be called from the DoPost or DoGet methods. DoPost DoGet PutLine Content type Send a line of output to the web-client PutLine writes a line of text (sOut) to the web client (currently, to standard output). It should be called only after WriteContent was called with a content type of text. The sent text is not processed in any way, i.e. no HTML entities or so are inserted instead of special HTML characters. This should be done by the user. No check is performed whether the content type is right. WriteContent Text to be sent to the client. Return the value of a request variable. GetValue returns the value of the variable named Index, and returns DefaultValue if it is empty or does not exist. Values Value of variable. Name of variable. Value to return in case variable is empty. Method to handle POST requests DoPost is called by the Run method the POST method was used to invoke the CGI application. It should be overridden in descendents of TEZcgi to actually handle the request. Run DoGet Method to handle GET requests DoGet is called by the Run method the GET method was used to invoke the CGI application. It should be overridden in descendents of TEZcgi to actually handle the request. Run DoPost Variables passed to the CGI script

Values is a name-based array of variables that were passed to the script by the web server or the HTTP request. The Index variable is the name of the variable whose value should be retrieved. The following standard values are available:

AUTH_TYPE
Authorization type
CONTENT_LENGTH
Content length
CONTENT_TYPE
Content type
GATEWAY_INTERFACE
Used gateway interface
PATH_INFO
Requested URL
PATH_TRANSLATED
Transformed URL
QUERY_STRING
Client query string
REMOTE_ADDR
Address of remote client
REMOTE_HOST
DNS name of remote client
REMOTE_IDENT
Remote identity.
REMOTE_USER
Remote user
REQUEST_METHOD
Request methods (POST or GET)
SCRIPT_NAME
Script name
SERVER_NAME
Server host name
SERVER_PORT
Server port
SERVER_PROTOCOL
Server protocol
SERVER_SOFTWARE
Web server software
HTTP_ACCEPT
Accepted responses
HTTP_ACCEPT_CHARSET
Accepted character sets
HTTP_ACCEPT_ENCODING
Accepted encodings
HTTP_IF_MODIFIED_SINCE
Proxy information
HTTP_REFERER
Referring page
HTTP_USER_AGENT
Client software name

Other than the standard list, any variables that were passed by the web-client request, are also available. Note that the variables are case insensitive.

Name of variable to retrieve Indexed array with available variable names. Names provides indexed access to the available variable names. The Index may run from 0 to VariableCount. Any other value will result in an exception being raised. Index of the name to retrieve. Indexed array with variables as name=value pairs. Variables provides indexed access to the available variable names and values. The variables are returned as Name=Value pairs. The Index may run from 0 to VariableCount. Any other value will result in an exception being raised. Index of variable pair Number of available variables. TEZcgi.VariableCount returns the number of available CGI variables. This includes both the standard CGI environment variables and the request variables. The actual names and values can be retrieved with the Names and Variables properties. Names Variables Name of the server administrator Name is used when displaying an error message to the user. This should set prior to calling the method. Email of the server administrator Email is used when displaying an error message to the user. This should set prior to calling the method.