KVALID_STRING(3)

πŸ“¦
version 1.0.1 Β· 2 versions
, in alpine 3.24

✨ 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, range 1 to 64 (like, first bit, second bit, and so on), or 0 to mean no bit at all. sets KPAIR_INTEGER. 🧚
  • kvalid_date() β€” takes an ISO 8601 YYYY-MM-DD date and converts it to the number of seconds since or before the UNIX Epoch, 1970-01-01. dates before 1582 are 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. sets KPAIR_INTEGER. ⭐
  • kvalid_double() β€” a signed double-precision floating-point number in strtod(3) format. sets KPAIR_DOUBLE. 🌈
  • kvalid_email() β€” a loosely-validated e-mail address, at most 254 characters, 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. sets KPAIR_STRING. πŸ’Œ
  • kvalid_int() β€” a 64-bit signed integer. sets KPAIR_INTEGER. πŸ”₯
  • kvalid_string() β€” a NUL-terminated string that's allowed to be empty. validation fails if kp->valsz does not match strlen(kp->val). sets KPAIR_STRING. πŸ“
  • kvalid_stringne() β€” the same as kvalid_string() except validation fails if the string is empty. the "ne" is basically "not empty", main character energy. πŸ’€
  • kvalid_udouble() β€” the same as kvalid_double() except validation fails if the number is zero or negative. πŸ™ˆ
  • kvalid_uint() β€” the same as kvalid_int() except validation fails if the number is negative. and heads up: the range does not extend to UINT64_MAX, it's limited to INT64_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() and kvalid_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms