KVALID_STRING(3)
β¨ KVALID_STRING(3) β¨ β the validation girlies of libkcgi
okay so bestie, listen π this is the manual page for KVALID_STRING(3) from the library libkcgi, and it's literally the whole roster of predefined validation functions. they're small, they're iconic, they do one job each, and they ate. let's get into it π
πΈ SYNOPSIS πΈ
like all good things, it starts with some includes:
#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);
nine functions. same signature. no cap, they're all just int f(struct kpair *kp). simple queen behavior π
π¦ DESCRIPTION π¦
so the predefined kcgi(3) validation functions do their whole thing by checking kp->val and kp->valsz. when validation succeeds β slay β they set the appropriate kp->parsed field to the validated value and stash its type in kp->type. π
these functions were literally designed to go in the valid field of struct kvalid, which is documented over in khttp_parse(3). iykyk.
here's what each one actually validates:
kvalid_bit()β a bit number, range1to64(like, first bit, second bit, and so on), or0to mean no bit at all. setsKPAIR_INTEGER. π§kvalid_date()β takes an ISO 8601YYYY-MM-DDdate and converts it to the number of seconds since or before the UNIX Epoch,1970-01-01. dates before1582are not accepted, periodt. and it's not just syntax checking β it verifies the date's actually correct (days in month, leap years, etc.) because she's thorough like that. setsKPAIR_INTEGER. βkvalid_double()β a signed double-precision floating-point number instrtod(3)format. setsKPAIR_DOUBLE. πkvalid_email()β a loosely-validated e-mail address, at most254characters, with a user part (at least one character) and a domain part (at least one character). heads up bestie: this will allow many invalid e-mail addresses, but it will not prevent any otherwise valid ones by over-strict testing β it's giving lenient on purpose. the validated string gets trimmed for white-space and lowercased. setsKPAIR_STRING. πkvalid_int()β a 64-bit signed integer. setsKPAIR_INTEGER. π₯kvalid_string()β a NUL-terminated string that's allowed to be empty. validation fails ifkp->valszdoes not matchstrlen(kp->val). setsKPAIR_STRING. πkvalid_stringne()β the same askvalid_string()except validation fails if the string is empty. the "ne" is basically "not empty", main character energy. πkvalid_udouble()β the same askvalid_double()except validation fails if the number is zero or negative. πkvalid_uint()β the same askvalid_int()except validation fails if the number is negative. and heads up: the range does not extend toUINT64_MAX, it's limited toINT64_MAX. noted bestie π«Ά
π RETURN VALUES π
all the validation functions return 1 if validation succeeds or 0 if it fails. that's it. that's the whole vibe check. π―
π SEE ALSO π
kcgi(3), khttp_fcgi_init(3), khttp_parse(3), kutil_invalidate(3)
go read those next, they're all linked in the group chat β¨
π AUTHORS π
these functions were written by Kristaps Dzonsons <kristaps@bsd.lv>. thank you legend π«‘
π BUGS π
real talk:kvalid_double()andkvalid_udouble()might attempt to access locale information, which might fail in a sandbox. so if you're sandboxed and those two act up, that's why π not their fault (kind of their fault).
and that's the page!! this version came from the Debian packaging, dated $Mdocdate$, and yeah β it's still KVALID_STRING(3) at the end of the day π bye bestie, go validate something πΈ
π¦ where this page comes from
- alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
- Copyright (c) 2014, 2017 Kristaps Dzonsons <kristaps@bsd.lv>
- Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms