From 1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 30 Oct 2023 11:16:55 +0000 Subject: Revamp (and hopefully fix) resattr management Signed-off-by: Laurent Bercot --- src/libtipidee/tipidee_conf_get_resattr1.c | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/libtipidee/tipidee_conf_get_resattr1.c (limited to 'src/libtipidee/tipidee_conf_get_resattr1.c') 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 +#include +#include + +#include +#include + +#include +#include + +#include + +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 ; +} -- cgit v1.3.1