aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtipidee/tipidee_conf_get_resattr.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-30 11:16:55 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-30 11:16:55 +0000
commit1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c (patch)
tree9c5ac88f1c430686d45de44ee36f29fe26be42b1 /src/libtipidee/tipidee_conf_get_resattr.c
parentad88c5ec68b1cfd47017face422132ab8c7b2874 (diff)
downloadtipidee-1c5f682f4dcbca5afa9dd4a9688bde40efaeb12c.tar.gz
Revamp (and hopefully fix) resattr management
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_conf_get_resattr.c')
-rw-r--r--src/libtipidee/tipidee_conf_get_resattr.c62
1 files changed, 62 insertions, 0 deletions
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 ;
+}