KVALID_STRING(3)

NAME
kutil_invalidate, kvalid_date, kvalid_double, kvalid_email, kvalid_int, kvalid_string, kvalid_stringne, kvalid_udouble, kvalid_uint - basic validation functions for kcgi

LIBRARY
libkcgi

SYNOPSIS
#include <stdint.h>
#include <kcgi.h>
void
kutil_invalidate(struct kreq *req, struct kpair *kp);
int
kvalid_date(struct kpair *kp);
int
kvalid_double(struct kpair *kp);
int
kvalid_email(struct kpair *kp);
int
kvalid_int(struct kpair *kp);
int
kvalid_string(struct kpair *kp);
int
kvalid_stringne(struct kpair *kp);
int
kvalid_udouble(struct kpair *kp);
int
kvalid_uint(struct kpair *kp);

DESCRIPTION
The kvalid_date, kvalid_double, kvalid_email, kvalid_int, kvalid_string, kvalid_stringne, kvalid_udouble and kvalid_uint, functions are basic validators for kcgi(3) and are passed into the khttp_parse(3) or khttp_fcgi_init(3) functions to validate input data. If a field is checked for validation during parse, it will first be noted in fields of struct kreq. If validated, the pair will be bucketed into the field-corresponding index of cookiemap or fieldmap, depending on the input source. If not, it will be bucketed into cookienmap or fieldnmap. Thus, a (e.g., cookie) field that appears in the input stream will appear in either cookiemap or cookienmap of struct kreq after parse.

The kutil_invalidate marks a validated input pair as invalid, moving it from the cookiemap or fieldmap bucket into the appropriate cookienmap or fieldnmap bucket of struct kreq. If the field is not valid to begin with, this fuction does nothing.

The validators perform the following validations:

kvalid_date()
    An ISO 8601 YYYY-MM-DD date. Set as a KPAIR_INTEGER in the number of seconds since the UNIX epoch.

kvalid_double()
    A signed double-precision floating-point number. See strtod(3). Note: this might use the locale and should be re-written. It sets as KPAIR_DOUBLE.

kvalid_email()
    A loosely-validated e-mail address consisting of at most 254 characters, with a user part (at least one character) and domain part (at least 4 characters). The validated string is trimmed for white-space and lowercased. It sets as KPAIR_STRING.

kvalid_int()
    A 64-bit signed integer. Sets KPAIR_INTEGER.

kvalid_string()
    A nil-terminated (possibly-empty) string. ( Since all field entries are binary, this checks whether the binary length is the same as the nil-terminated string, so no truncation occurs.) This sets KPAIR_STRING.

kvalid_stringne()
    A non-empty string via kvalid_string().

kvalid_udouble()
    A double-precision floating-point number via kvalid_double() that's strictly greater than zero.

kvalid_uint()
    A 64-bit integer via kvalid_int() that's weakly greater than zero.

RETURN VALUES
kvalid_date, kvalid_double, kvalid_email, kvalid_int, kvalid_string, kvalid_stringne, kvalid_udouble, and kvalid_uint return 0 if validation fails. If validation succeeds, the pair's parsed and type fields are set accordingly.

AUTHORS
The kutil_invalidate, kvalid_date, kvalid_double, kvalid_email, kvalid_int, kvalid_string, kvalid_stringne, kvalid_udouble and kvalid_uint functions were written by Kristaps Dzonsons <kristaps@bsd.lv>.