blob: 9b33208de051628359b2de15a7b8f7227c49d318 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 ;
}
|