From 7c5d186df1f7f00567660354905435cedffc3e20 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 25 Jun 2026 09:01:50 +0000 Subject: Implement fastcgi, except the protocol itself --- src/libtipidee/tipidee_conf_get_redirection.c | 42 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/libtipidee') diff --git a/src/libtipidee/tipidee_conf_get_redirection.c b/src/libtipidee/tipidee_conf_get_redirection.c index a8397ec..9c2456a 100644 --- a/src/libtipidee/tipidee_conf_get_redirection.c +++ b/src/libtipidee/tipidee_conf_get_redirection.c @@ -1,35 +1,53 @@ /* ISC license. */ #include +#include #include +#include +#include + +#include #include #include -static int get_redir (tipidee_conf const *conf, size_t minl, char *key, size_t l, char const *path, tipidee_redirection *r) +static int get_redir (tipidee_conf const *conf, size_t minl, char *key, size_t l, char const *path, tipidee_redirection *rd) { - char const *v = 0 ; + cdb_data data ; + int r = 0 ; key[0] = 'R' ; key[l] = '/' ; errno = ENOENT ; - while (!v) + while (!r) { if (errno != ENOENT) return -1 ; while (l >= minl && key[l] != '/') l-- ; - if (l < minl) break ; + if (l < minl) return 0 ; key[l--] = 0 ; - v = tipidee_conf_get_string(conf, key) ; + r = tipidee_conf_get(conf, key, &data) ; key[0] = 'r' ; } - if (!v || ((unsigned char)v[0] & 128)) return 0 ; - r->type = v[0] ; - r->location = v+1 ; - r->sub = path + (l - minl + 1) ; + if (data.len < 5) return (errno = EILSEQ, -1) ; + rd->sub = path + (l - minl + 1) ; + rd->type = *data.s++ ; data.len-- ; + if (!rd->type) + return data.len ? (errno = EILSEQ, -1) : 1 ; + rd->flags = *data.s++ ; data.len-- ; + if (rd->type >= 2 && rd->flags & TIPIDEE_REDIR_ISINET) + { + if (data.len != (rd->flags & TIPIDEE_REDIR_ISV6 ? 18 : 6)) + return (errno = EILSEQ, -1) ; + uint16_unpack_big(data.s, &rd->port) ; + data.s += 2 ; data.len -= 2 ; + } + else if (data.s[data.len - 1]) + return (errno = EILSEQ, -1) ; + rd->addr = data.s ; return 1 ; } -int tipidee_conf_get_redirection (tipidee_conf const *conf, char const *docroot, size_t docrootlen, char const *path, tipidee_redirection *r) +int tipidee_conf_get_redirection (tipidee_conf const *conf, char const *docroot, size_t docrootlen, char const *path, tipidee_redirection *rd) { size_t pathlen = strlen(path) ; char key[docrootlen + pathlen + 3] ; @@ -37,7 +55,7 @@ int tipidee_conf_get_redirection (tipidee_conf const *conf, char const *docroot, memcpy(key + 2, docroot, docrootlen) ; memcpy(key + 2 + docrootlen, path, pathlen + 1) ; { - int e = get_redir(conf, 2 + docrootlen, key, 2 + docrootlen + pathlen, path, r) ; + int e = get_redir(conf, 2 + docrootlen, key, 2 + docrootlen + pathlen, path, rd) ; if (e) return e ; } { @@ -47,5 +65,5 @@ int tipidee_conf_get_redirection (tipidee_conf const *conf, char const *docroot, } memcpy(key + 2, docroot, docrootlen) ; memcpy(key + 2 + docrootlen, path, pathlen + 1) ; - return get_redir(conf, 2 + docrootlen, key, 2 + docrootlen + pathlen, path, r) ; + return get_redir(conf, 2 + docrootlen, key, 2 + docrootlen + pathlen, path, rd) ; } -- cgit v1.3.1