CGI Library
These functions help you write virtual document (CGI) programs using C.
Look at the template.c file for an illustrative example.
Feel free to download the latest
distributions from ftp.eit.com.
- main()
- cgi_main(cgi_info *ci)
- int get_cgi_info(cgi_info *)
- form_entry *get_form_entries(cgi_info *)
- void free_form_entries(cgi_info *)
- char *parmval(form_entry *, char *)
- int syn_mimeheader(char *, char *)
- int print_mimeheader(char *)
- int syn_base_url(char *, cgi_info *)
- int print_base_url(cgi_info *)
- int mcode(cgi_info *)
- char *trim(char *s)
- char *sanitize(char *to, char *from)
- void print_sel_list(char *tname, char **opts, char *init)
- void print_input_blank(char *tname, unsigned size, char *init)
- void print_submit(char *label)
- char *strmaxcpy(char *s1, char *s2, int n)
Synopsis
#include "libcgi/cgi.h"
main()
cgi_main(cgi_info *ci)
Description
libcgi contains a simple stub of a main program, which merely
calls cgi_main with a struct filled with all the CGI
vars. Thus cgi_main is actually the entry point for
your CGI-processing code. It is this way to be upwardly-compatible
with a scheme for virtual document "daemons" that we're hatching.
Synopsis
#include "libcgi/cgi.h"
int get_cgi_info(cgi_info *)
Description
This routine paws through the environment and fills up the struct
provided, which must already be allocated.
This function is called by main, and the result passed to
cgi_main.
Returns
zero if there is a problem.
Synopsis
#include "libcgi/cgi.h"
form_entry *get_form_entries(cgi_info *)
void free_form_entries(cgi_info *)
char *parmval(form_entry *, char *)
Description
get_form_entries parses any form inputs information into a linked-list
of name/value pairs, returning the head pointer of that list. It does
all plus-to-space and hex code translations.
free_form_entries reclaims all the memory from the provided linked-list.
parmval return the value corresponding to the name in the second
argument (a caseless string compar) by a linear search through the list
in the first argument.
Returns
get_form_enties returns the head pointer, or NULL if there is a problem
or no form input information was available.
parmval returns the corresponding value string or NULL if there is a
problem or no matching name.
Synopsis
#include "libcgi/cgi.h"
int syn_mimeheader(char *, char *)
int print_mimeheader(char *)
Description
syn_mimeheader creates a MIME header based on the MIME type in
the second string and writes it into the first string buffer
(including trailing double-newline).
print_mimeheader creates the same MIME header based on the MIME
type in its sole argument, and prints it to stdout
Returns
both return 0 if there is a problem
Synopsis
#include "libcgi/cgi.h"
int syn_base_url(char *, cgi_info *)
int print_base_url(cgi_info *)
Description
syn_base_url reconstructs the virtual document's URL given the
cgi_info, minus any query string, and fills the provided char
buffer.
print_base_url does the same but prints to stdout instead
Returns
both return 0 if there is a problem
Synopsis
#include "libcgi/cgi.h"
int mcode(cgi_info *)
Description
This function examines the request_method in the cgi information
and returns an integer code. These codes are defined in cgi.h.
Returns
0 if it doesn't recognize the method name, otherwise the code as
defined in cgi.h
Synopsis
#include "libcgi/cgi.h"
char *trim(char *s)
Description
Changes the string from blank-padded to NULL-padded
Returns
its argument
Synopsis
#include "libcgi/cgi.h"
char *sanitize(char *to, char *from)
Description
Prepares the string for inclusion in a URL. That is, the from
string is copied to the to buffer except that blanks are turned
into '+' characters and non-alphanumerics are turned into
3-character sequences of a '%' followed by two hex digits
corresponding to the ascii code.
Returns
the to string
Synopsis
#include "libcgi/cgi.h"
void print_sel_list(char *tname, char **opts, char *init)
Description
Prints an HTML+ selection list construct to stdout. The name of
the SELECT tag is given by tname, and the NULL-terminated string
array opts is turned into separate OPTION tags with values
corresponding to entries in opts. If any of these entries
are a caseless match with init, then that OPTION tag is the
default selection.
Synopsis
#include "libcgi/cgi.h"
void print_input_blank(char *tname, unsigned size, char *init)
Description
Prints an HTML+ INPUT tag (of type text) to stdout. The tag's
name is tname, its size is size, and initial value is init.
Synopsis
#include "libcgi/cgi.h"
void print_submit(char *label)
Description
Prints an HTML+ INPUT tag of type submit to stdout. The submit
button will be labelled by label if non-NULL.
Synopsis
#include "libcgi/cgi.h"
char *strmaxcpy(char *s1, char *s2, int n)
Description
copies at most n-1 characters from s2 into s1, and then
null-terminates. Handy for truncating while copying.
Returns
s1 as long as n > 0, NULL otherwise
wsk@eit.com