FunctionDocumentation

voidcgi_end()
Performs cgi clean ups.Provides some methods to clean memory or any
other job that need to be done before the end of the application.
Seealso:cgi_initchar*cgi_escape_special_chars(char*str)
Transforms’ special characters into hexadecimal form ( %E1
).Parameters:str String to parse
Returns:
The new string
Seealso:cgi_unescape_special_charsvoidcgi_fatal(constchar*msg)
Kills the application with a message.Writes msg and terminate
Parameters:msg Message to send to the browser before killing
intcgi_include(constchar*filename)
Include static files.Function used to include static data ( normaly
html files ). File contents will never be processed. Note that I don’t
scan for any special character. The reason I did it is, if the you are
using this library, you have a shell where you can compile the cgi
program. And can do much more ;-)
Parameters:filename Filename with full path to include
Returns:
If an error occurs and libcgi_debug is true, then a warning message
is showed.
Seealso:
libcgi_debug
cgi_include(’top_bar.htm’);
intcgi_init()
Main cgi function.Configures all (most?) we need to get cgi library
working correctly. It MUST be called before any other cgi function.
Seealso:cgi_end, cgi_process_form, cgi_init_headersvoidcgi_init_headers()
Initialize HTML headers.You need to call this function before that any
content is send to the brosert, otherwise you’ll get an error (Error
500).
Seealso:cgi_initchar*cgi_param(constchar*var_name)
Gets the of HTML or URL variable indicated by ’name’.Parameters:name Form Variable name
Seealso:cgi_param_multiple, cgi_process_form, cgi_init
// ...
char *contents;
cgi_init();
cgi_process_form();
cgi_init_headers();
contents = cgi_param(’foo’);
puts(contents);
// ...
char*cgi_param_multiple(constchar*name)
Return all values with the same name sent by a form.Parameters:name Form variable name
Returns:
Form variable contents
Seealso:cgi_param
Example: For example, if in your HTML you have something like
’What do you like??’
Computers : <input type=’checkbox’ name=’like’ value=’computers’><br>
Internet : <input type=’checkbox’ name=’like’ value=’net’><br>
games : <input type=’checkbox’ name=’like’ ’value=’games’’><br>
then, to retrieve all values, you can make a code like
// ...
char *data;
\ ...
while ((data = cgi_param_multiple(’like’)) != NULL)
puts(data);
\ ...
formvars*cgi_process_form()
Process HTML form or URL data.Used to retrieve GET or POST data. It
handles automaticaly the correct REQUEST_METHOD, so you don’t need to
afraid about it.
Returns:
Returns the contents of URL or FORM into a formvars variable, or
NULL if FALSE. Most of time, you don’t need any variable to store
the form data, because is used an internal variable to manipulate
the contents.
Seealso:cgi_init, cgi_init_headersvoidcgi_redirect(char*url)
Recirects to the specified url.Remember that you cannot send any header
before this function, or it will not work. Note:
LibCGI does not implement RFC 2396 to make the lib simple and quick.
You should be sure to pass a correct URI to this function.
Parameters:url url to redirect the browser
cgi_redirect(’http://wwww.linux.org’);
voidcgi_send_header(constchar*header)
Sends a specific header.Sends a specific HTTP header. You won’t need to
add ’\n\n’ chars.
Parameters:header HTTP header to send, without new line characteres
Returns:
True
Seealso:cgi_init_headerschar*cgi_unescape_special_chars(char*str)
Transforms’ URL special chars.Search for special chars ( like %E1 ) in
str, converting them to the ascii character correspondent.
Parameters:str String containing data to parse
Returns:
The new string
Seealso:cgi_escape_special_chars