KVALID_STRING(3) Library Functions Manual KVALID_STRING(3)

kvalid_bit, kvalid_date, kvalid_double, kvalid_email, kvalid_int, kvalid_string, kvalid_stringne, kvalid_udouble, kvalid_uintpredefined validation functions for kcgi

library “libkcgi”

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

int
kvalid_bit(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);

The predefined kcgi(3) validation functions check kp->val and kp->valsz. On successful validation, the appropriate kp->parsed field is set to the validated value and its type stored in kp->type. These functions are designed for use in the valid field of struct kvalid, documented in khttp_parse(3).

The validation functions perform the following validations:

()
A bit number in the range from 1 to 64 (first bit, second bit, and so on) or 0 to indicate no bit. Sets KPAIR_INTEGER.
()
Converts an ISO 8601 YYYY-MM-DD date to the number of seconds since or before the UNIX Epoch, 1970-01-01. Dates before 1582 are not accepted. Beyond syntax, dates are checked for correctness (days in month, leap years, etc.). Sets KPAIR_INTEGER.
()
A signed double-precision floating-point number in strtod(3) format. Sets KPAIR_DOUBLE.
()
A loosely-validated e-mail address consisting of at most 254 characters, with a user part (at least one character) and a domain part (at least one character). This will allow invalid e-mail addresses, but will not prevent any otherwise valid ones by over-strict testing. The validated string is trimmed for white-space and lowercased. Sets KPAIR_STRING.
()
A 64-bit signed integer. Sets KPAIR_INTEGER.
()
A NUL-terminated string that is allowed to be empty. The validation fails if kp->valsz does not match (kp->val). Sets KPAIR_STRING.
()
The same as kvalid_string() except that validation fails if the string is empty.
()
The same as kvalid_double() except that validation fails if the number is zero or negative.
()
The same as kvalid_int() except that validation fails if the number is negative. The range does not extend to UINT64_MAX, but is limited to INT64_MAX.

All validation functions return 1 if validation succeeds or 0 if it fails.

kcgi(3), khttp_fcgi_init(3), khttp_parse(3), kutil_invalidate(3)

These functions were written by Kristaps Dzonsons <kristaps@bsd.lv>.

The functions kvalid_double() and kvalid_udouble() might attempt to access locale information, which might fail in a sandbox.

September 23, 2021 OpenBSD 6.7