diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-06-25 09:01:50 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-06-25 09:01:50 +0000 |
| commit | 7c5d186df1f7f00567660354905435cedffc3e20 (patch) | |
| tree | 2911cf6d75a5be2a62fd493f2ad1a05ffc7c6bb3 /src/libtipidee | |
| parent | 51ff1577ce59449b36a86f21a90101bc2750943f (diff) | |
| download | tipidee-7c5d186df1f7f00567660354905435cedffc3e20.tar.gz | |
Implement fastcgi, except the protocol itself
Diffstat (limited to 'src/libtipidee')
| -rw-r--r-- | src/libtipidee/tipidee_conf_get_redirection.c | 42 |
1 files changed, 30 insertions, 12 deletions
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 <errno.h> +#include <stdint.h> #include <string.h> +#include <skalibs/uint16.h> +#include <skalibs/cdb.h> + +#include <tipidee/redirection.h> #include <tipidee/conf.h> #include <skalibs/posixishard.h> -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) ; } |
