FEATURES
---------------------------------

This library adds following features to your application:

CGI library, including:
	- Access to CGI forms data
	- Access to cookies
	- Access to HTTP headers
	- Sessions support - ability to save your data 
	  and restore it while session is alive (keep state mechanism)
	- Ability to store sessions in files or add your own session handlers
	- Thread safety
	- CGI and FastCGI support

Template engine:
	- Simple yet powerful template engine
	- Access to document object model (DOM) tree
	- Ability to extend templates command set
	- Text preprocessors - encode html special characters, strip HTML tags

USAGE
---------------------------------

A first CGI program:
------------------------------------------ CUT ----------------------------------------------
#include <stdio.h>
#include <cgi/cgi.h>

int main()
{
	t_cgi_context *ctx = cgi_context_create(NULL);
	int i;
	char *cookie;

	// Register variables which will be filled by form POST data ("name" && "file")
	POST_VAR(ctx, name);
	POST_VAR(ctx, file);

	// Set some cookie. When you set cookie, it does not appear immediately in
	// cookie_get cookies array, but simply sent to client to set cookie.
	cookie_set(ctx, "some_cookie", "some_cookie_value", 1000, NULL);

	if(!file) // If file is NULL, then the parameter was not found
	{
		fprintf(ctx->out, "Parameter 'file' does not exist!");
	}
	else
	{
		// Parameter was found. Test whether there were several fields with such name.
		// (if yes, an is_array property of field variable will be set to 1)

		// Output "is_array" property of file field. (note, that we don't need to
		// care about headers - they are sent automatically)

		fprintf(ctx->out, "<H1>file->is_array = %d; size = %d</H1><br/>\n", file->is_array, file->array_size);
		if(file->is_array)
		{
			for(i = 0; i < file->array_size; i ++)
			{
				if(!file->ff_array[i]->is_file)
					printf(ctx->out, "<H2>file[%d]=%s</H2><br/>\n", i, file->ff_array[i]->ff_data);
			}
		}
		else
		{
			printf("<H2>file=%s</H2><br/>\n", file->ff_data);
		}
	}

	// Try to get a cookie which we have set before
	if(cookie = cookie_get(ctx, "cookbook"))
	{
		printf("<h2>Cookie cookbook == \"%s\"</h2><br/>\n", cookie);
	}

	// Do some cleanup
	cgi_context_free(ctx);
}
------------------------------------------ CUT ----------------------------------------------

The following steps are to be done to complete your own CGI application:
	- Create CGI context
	- Start session mechanism, if needed
	- Register state variables
	- Process input data
	- Output result

ARCHITECTURE
---------------------------------

CGI library consists of several modules, which are mainly integrated by the main cgi module.
These modules are:
	- CGI form parser
	- CGI headers module
	- Cookies module
	- Session (keep state) module

The html parser and output module is separated from other in means that it is relatively
independent.

The following is a short description of all modules.

	CGI form parser
	---------------
CGI form data is parsed automatically when CGI context is created. There are several ways
to get form fields data:
	- Register GET or POST variable
	- Directly fetch a field from a fieldset
	
Variables can be registered using one of following constructions:
	GET_VAR(field_name)
	POST_VAR(field_name)

which respectively register POST or GET form field.

Three functions exist to fetch field data without registering variables.
	t_form_field *form_get_field(struct s_cgi_context *cgi_ctx, char *name);
	t_form_field *form_post_field(struct s_cgi_context *cgi_ctx, char *name);
	t_form_field *form_field(struct s_cgi_context *cgi_ctx, char *name);

which fetch GET, POST, and first of GET/POST fields with given name, respectively.


