diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-10-30 11:16:55 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-10-30 11:16:55 +0000 |
commit | 1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c (patch) | |
tree | 9c5ac88f1c430686d45de44ee36f29fe26be42b1 /src/libtipidee | |
parent | ad88c5ec68b1cfd47017face422132ab8c7b2874 (diff) | |
download | tipidee-1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c.tar.xz |
Revamp (and hopefully fix) resattr management
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee')
-rw-r--r-- | src/libtipidee/deps-lib/tipidee | 2 | ||||
-rw-r--r-- | src/libtipidee/tipidee_conf_get_resattr.c | 62 | ||||
-rw-r--r-- | src/libtipidee/tipidee_conf_get_resattr1.c | 36 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_resource.c | 5 |
4 files changed, 103 insertions, 2 deletions
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee index b20898b..d71ef89 100644 --- a/src/libtipidee/deps-lib/tipidee +++ b/src/libtipidee/deps-lib/tipidee @@ -4,6 +4,8 @@ tipidee_conf_get_argv.o tipidee_conf_get_content_type.o tipidee_conf_get_errorfile.o tipidee_conf_get_redirection.o +tipidee_conf_get_resattr.o +tipidee_conf_get_resattr1.o tipidee_conf_get_responseheaders.o tipidee_conf_get_string.o tipidee_conf_get_uint32.o diff --git a/src/libtipidee/tipidee_conf_get_resattr.c b/src/libtipidee/tipidee_conf_get_resattr.c new file mode 100644 index 0000000..9b33208 --- /dev/null +++ b/src/libtipidee/tipidee_conf_get_resattr.c @@ -0,0 +1,62 @@ +/* ISC license. */ + +#include <string.h> + +#include <skalibs/bytestr.h> + +#include <tipidee/conf.h> +#include <tipidee/resattr.h> + +#define FULLMASK ((1 << TIPIDEE_RA_BITS) - 1) + +int tipidee_conf_get_resattr (tipidee_conf const *conf, char const *res, tipidee_resattr *ra) +{ + tipidee_resattr rra = TIPIDEE_RESATTR_ZERO ; + size_t len = strlen(res) + 2 ; + char key[len + 1] ; + key[0] = 'A' ; key[1] = ':' ; + memcpy(key + 2, res, len - 2) ; + key[len] = '/' ; + while (len > 2 && (rra.mask & FULLMASK) != FULLMASK) + { + tipidee_resattr atom ; + int r ; + while (len > 2 && key[len] != '/') len-- ; + if (len <= 2) break ; + key[len--] = 0 ; + r = tipidee_conf_get_resattr1(conf, key, &atom) ; + if (r == -1) return 0 ; + if (r) + { + rra.flags = (~rra.mask & atom.mask & atom.flags) | ((rra.mask | ~atom.mask) & rra.flags) ; /* yup */ + rra.mask |= atom.mask ; + if (!rra.content_type) rra.content_type = atom.content_type ; + } + key[0] = 'a' ; + } + + if (!(rra.mask & TIPIDEE_RA_FLAG_NPH)) + { + char const *nphprefix ; + char *p = strchr(key+2, '/') ; + if (p) *p = 0 ; + key[0] = 'N' ; + nphprefix = tipidee_conf_get_string(conf, key) ; + if (nphprefix) + { + char const *base = strrchr(res, '/') ; + if (base && str_start(base + 1, nphprefix)) rra.flags |= 1 << TIPIDEE_RA_FLAG_NPH ; + else rra.flags &= ~(1 << TIPIDEE_RA_FLAG_NPH) ; + rra.mask |= 1 << TIPIDEE_RA_FLAG_NPH ; + } + } + + if (!(rra.flags & TIPIDEE_RA_FLAG_CGI) && !rra.content_type) + { + rra.content_type = tipidee_conf_get_content_type(conf, res) ; + if (!rra.content_type) return 0 ; + } + + *ra = rra ; + return 1 ; +} diff --git a/src/libtipidee/tipidee_conf_get_resattr1.c b/src/libtipidee/tipidee_conf_get_resattr1.c new file mode 100644 index 0000000..182a7ba --- /dev/null +++ b/src/libtipidee/tipidee_conf_get_resattr1.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include <stdint.h> +#include <errno.h> +#include <string.h> + +#include <skalibs/uint32.h> +#include <skalibs/cdb.h> + +#include <tipidee/resattr.h> +#include <tipidee/conf.h> + +#include <skalibs/posixishard.h> + +int tipidee_conf_get_resattr1 (tipidee_conf const *conf, char const *key, tipidee_resattr *ra) +{ + tipidee_resattr atom = TIPIDEE_RESATTR_ZERO ; + cdb_data data ; + if (!tipidee_conf_get(conf, key, &data)) return errno == ENOENT ? 0 : -1 ; + if (data.len < 9 || data.s[data.len - 1]) return (errno = EPROTO, -1) ; + uint32_unpack_big(data.s, &atom.flags) ; + uint32_unpack_big(data.s + 4, &atom.mask) ; + data.s += 8 ; data.len -= 8 ; + if (*data.s) + { + size_t len = strlen(data.s) + 1 ; + if (len > data.len) return (errno = EPROTO, -1) ; + atom.content_type = data.s ; + data.s += len ; + data.len -= len ; + } + else data.len-- ; + if (data.len) return (errno = EPROTO, -1) ; + *ra = atom ; + return 1 ; +} diff --git a/src/libtipidee/tipidee_log_resource.c b/src/libtipidee/tipidee_log_resource.c index 75196b0..efdea69 100644 --- a/src/libtipidee/tipidee_log_resource.c +++ b/src/libtipidee/tipidee_log_resource.c @@ -4,6 +4,7 @@ #include <skalibs/strerr.h> +#include <tipidee/resattr.h> #include <tipidee/log.h> void tipidee_log_resource (uint32_t v, tipidee_rql const *rql, char const *file, tipidee_resattr const *ra, char const *infopath) @@ -19,8 +20,8 @@ void tipidee_log_resource (uint32_t v, tipidee_rql const *rql, char const *file, a[m++] = " resource " ; a[m++] = file ; a[m++] = " type " ; - a[m++] = ra->iscgi ? ra->isnph ? "nph" : "cgi" : ra->content_type ; - if (ra->iscgi && infopath) + a[m++] = ra->flags & TIPIDEE_RA_FLAG_CGI ? ra->flags & TIPIDEE_RA_FLAG_NPH ? "nph" : "cgi" : ra->content_type ; + if (ra->flags & TIPIDEE_RA_FLAG_CGI && infopath) { a[m++] = " path_info /" ; a[m++] = infopath ; |