diff options
author | Omar Polo <op@omarpolo.com> | 2022-02-26 14:00:20 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2022-02-26 14:00:20 +0000 |
commit | ee219d702e4b1db5a985be5087f0e682b567618b (patch) | |
tree | a6884643c969600b26623ddc4a486d78b8a3684d | |
parent | 88971f9a4e71c199c28fac3a1e9ccf39f44279f1 (diff) |
add type { ... } block to define mime types mapping
The `map' rule is powerful but quite annoying to use if you have/need
lots of entries (and clutters the configuration file too.)
The `type' block is blatantly stolen from httpd(8) and allows for a way
more nice usage:
type {
include "/usr/share/misc/mime.types"
}
or even
type {
text/markdown md markdown
text/x-perl pl pm
# ...
}
-rw-r--r-- | parse.y | 43 |
1 files changed, 41 insertions, 2 deletions
@@ -99,6 +99,7 @@ void add_param(char *, char *, int); static struct vhost *host; static struct location *loc; static struct proxy *proxy; +static char *current_media; static int errors; typedef struct { @@ -128,7 +129,7 @@ typedef struct { %token PARAM PORT PREFORK PROTO PROTOCOLS PROXY %token RELAY_TO REQUIRE RETURN ROOT %token SERVER SNI SPAWN STRIP -%token TCP TOEXT TYPE +%token TCP TOEXT TYPE TYPES %token USE_TLS USER %token VERIFYNAME @@ -138,7 +139,7 @@ typedef struct { %token <v.number> NUM %type <v.number> bool -%type <v.string> string +%type <v.string> string numberstring %% @@ -148,6 +149,7 @@ conf : /* empty */ | conf varset '\n' | conf option '\n' | conf vhost '\n' + | conf types '\n' | conf error '\n' { file->errors++; } ; @@ -183,6 +185,17 @@ string : string STRING { | STRING ; +numberstring : NUM { + char *s; + if (asprintf(&s, "%d", $1) == -1) { + yyerror("asprintf: number"); + YYERROR; + } + $$ = s; + } + | STRING + ; + varset : STRING '=' string { char *s = $1; while (*s++) { @@ -455,11 +468,36 @@ fastcgi : SPAWN string { } ; +types : TYPES '{' optnl mediaopts_l '}' + ; + +mediaopts_l : mediaopts_l mediaoptsl nl + | mediaoptsl nl + ; + +mediaoptsl : STRING { current_media = $1; } medianames_l optsemicolon + | include + ; + +medianames_l : medianames_l medianamesl + | medianamesl + ; + +medianamesl : numberstring { add_mime(&conf.mime, current_media, $1); } + ; + +nl : '\n' optnl + ; + optnl : '\n' optnl /* zero or more newlines */ | ';' optnl /* semicolons too */ | /*empty*/ ; +optsemicolon : ';' + | + ; + %% static struct keyword { @@ -509,6 +547,7 @@ static struct keyword { {"tcp", TCP}, {"to-ext", TOEXT}, {"type", TYPE}, + {"types", TYPES}, {"use-tls", USE_TLS}, {"user", USER}, {"verifyname", VERIFYNAME}, |