diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-07-04 04:03:12 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-07-04 04:03:12 +0000 |
| commit | 24daa5813f277023f7b8453338870369bf00a3ca (patch) | |
| tree | fc19981595bd9be15daef821c0b5259c4f4907cb /src/libtipidee/tipidee_fcgi_addenv.c | |
| parent | 45808dbc6dc1b90fa512add692252bc15760a214 (diff) | |
| download | tipidee-24daa5813f277023f7b8453338870369bf00a3ca.tar.gz | |
Implement FastCGI, initial version
Diffstat (limited to 'src/libtipidee/tipidee_fcgi_addenv.c')
| -rw-r--r-- | src/libtipidee/tipidee_fcgi_addenv.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_fcgi_addenv.c b/src/libtipidee/tipidee_fcgi_addenv.c new file mode 100644 index 0000000..fb9e859 --- /dev/null +++ b/src/libtipidee/tipidee_fcgi_addenv.c @@ -0,0 +1,41 @@ +/* ISC license. */ + +#include <errno.h> + +#include <skalibs/uint32.h> +#include <skalibs/stralloc.h> + +#include <tipidee/fcgi.h> + +static int encode (stralloc *sa, size_t n) +{ + if (n <= 0x7f) + { + char c = n ; + return stralloc_catb(sa, &c, 1) ; + } + else if (n < 0x7ffffffful) + { + char pack[4] ; + uint32_pack_big(pack, n | 0x80000000) ; + return stralloc_catb(sa, pack, 4) ; + } + else return (errno = EOVERFLOW, 0) ; +} + +int tipidee_fcgi_addenvb (stralloc *sa, char const *key, size_t keylen, char const *val, size_t vallen) +{ + size_t start = sa->len ; + if (!encode(sa, keylen)) return 0 ; + if (!encode(sa, vallen) + || !stralloc_catb(sa, key, keylen) + || !stralloc_catb(sa, val, vallen)) goto err ; + if (sa->len > 0x7fff) goto err0 ; + return 1 ; + + err0: + errno = E2BIG ; + err: + sa->len = start ; + return 0 ; +} |
