sf_cgi(3)

NAME
params, param, param2, set_cookie, cookie, cookies, html_quote, getlanguageprefs - functions to support CGI programming

url_decode, url_encode - recoding functions

lang_recode, windows_1251_to_koi8_r, koi8_r_to_windows_1251, cp 866_to_koi8_r, koi8_r_to_cpp_866, iso_8859_5_to_koi8_r - charset recoding functions

SYNOPSIS
#include <strfunc.h>
char *
param(char *fieldname);
svect *
param2(char *fieldname, int flags);

int
set_cookie(char *name, char *value, char *optDomain, char *optPath, time_t optMaxAge, char *optComment, int optSecure);
char *
cookie(char *name);
svect *
cookies(void);
char *
html_quote(char *);
svect *
getlanguageprefs(void);

URL-encoding and decoding
char *
url_decode(char *str);
char *
url_encode(char *str);

char *
lang_recode(char *string, char table[]);
char *
windows_1251_to_koi8_r(char *string);
char *
koi8_r_to_windows_1251(char *string);
char *
cp_866_to_koi8_r(char *string);
char *
koi8_r_to_cp_866(char *string);
char *
iso_8859_5_to_koi8_r(char *string);

DESCRIPTION
These routines give the user a method of dealing with CGI forms and other related data.

char * param(char *paramName) function used to obtain the form parameters by specifying their names.

svect * param2(char *paramName, int flags) may be required if multiple values are expected. It stores the current result in the internal buffer and other invocations will destroy its contents. Flags used to specify the type of returned values. If flags = 0, param2() will return the decoded values of the parameter specified by paramName. If flags = 1, param2() will return the unmodified (non-decoded) values. If flags = 2, param2() will return the appropriate content types (to use with multipart forms and binary values).

svect * params(void) used to get all the parameter names (keys). Not always applicable, sure.

char * cookie(char *cookieName) and svect * cookies(void) functions are used to obtain the cookie by its name or all cookie names, respectively.

int set_cookie(char *name, char *value, char *optDomain, char *optPath, time_t optMaxAge, char *optComment, int optSecure) is used to set a cookie. Arguments prefixed by 'opt' are optional.

char * html_quote(char *) used to escape some symbols, such as quotation mark, ampersand, left and right angle quotes, and others. This function can be used to safe include any text to the html document.

svect * getlanguageprefs() returns a pointer to an internal svect structure containing the array of user-preferred languages (from HTTP_ACCEPT_LANGUAGE ). If this information is not available, it returns NULL.

char * url_decode(char *) and url_encode(char *) are used to deal with url-encoded strings.

lang_recode(char *string, char table[]) used to recode a string with the specified table. Table size must be no less than 128 bytes, it represents the upper half of the character table. windows_1251_to_koi8_r(), koi8_r_to_windows_1251() and other recoding functions are self-descriptive too. If you want to add some other charset encodings, please call the author or use char lang_recode().

EXAMPLE

    void cgiparse() {
    	char *login, pwd, oldpwd;
    	login = param("login");
    	pwd = param("password");
    	oldpwd = param("oldpassword");
    	if(!login || !pwd || !oldpwd) {
    		printf("One or more parameters are missing.\n");
    		return;
    	};
    	/* ... some job ... */
    	/* This will produce the following output:
    	 * "John Smith &lt;john@smith.com&gt;\n"
    	 */
    	printf("%s\n", html_quote("John Smith <john@smith.com>") );
    };

SEE ALSO
strfunc(3), svect(3), replace(3), limittextwidth(3).

AUTHORS
Lev Walkin <vlm@spelio.net.ru>