aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-18 18:43:47 +0000
committerOmar Polo <op@omarpolo.com>2021-01-18 18:43:47 +0000
commit982069a120a3d36483427ce00b9cf90a8bf4daab (patch)
tree4aceb73f1893525c98649586939437ed53f79a04
parent0fbe79b33c1d16b0611851e2019558ce8888a02e (diff)
add "mime" and "default type" option for the configuration
-rw-r--r--gmid.h2
-rw-r--r--lex.l3
-rw-r--r--mime.c20
-rw-r--r--parse.y5
-rw-r--r--sample.conf3
5 files changed, 28 insertions, 5 deletions
diff --git a/gmid.h b/gmid.h
index 6656367..bbf70d3 100644
--- a/gmid.h
+++ b/gmid.h
@@ -149,8 +149,10 @@ extern int yylex(void);
/* mime.c */
void init_mime(void);
+void set_default_mime(const char*);
void add_mime(const char*, const char*);
void load_default_mime(void);
+int load_mime_file(const char*);
const char *mime(const char*);
/* server.c */
diff --git a/lex.l b/lex.l
index 4b6cf88..cb6326a 100644
--- a/lex.l
+++ b/lex.l
@@ -55,6 +55,9 @@ daemon return TDAEMON;
ipv6 return TIPV6;
port return TPORT;
protocols return TPROTOCOLS;
+mime return TMIME;
+default return TDEFAULT;
+type return TTYPE;
server return TSERVER;
cert return TCERT;
diff --git a/mime.c b/mime.c
index cb2f28a..121dee0 100644
--- a/mime.c
+++ b/mime.c
@@ -26,6 +26,7 @@ struct etm { /* extension to mime */
};
struct mimes {
+ char *def;
struct etm *t;
size_t len;
size_t cap;
@@ -41,6 +42,19 @@ init_mime(void)
if ((mimes.t = calloc(mimes.cap, sizeof(struct etm))) == NULL)
fatal("calloc: %s", strerror(errno));
+
+ mimes.def = strdup("application/octet-stream");
+ if (mimes.def == NULL)
+ fatal("strdup: %s", strerror(errno));
+
+}
+
+void
+set_default_mime(const char *m)
+{
+ free(mimes.def);
+ if ((mimes.def = strdup(m)) == NULL)
+ fatal("strdup: %s", strerror(errno));
}
/* register mime for the given extension */
@@ -102,15 +116,15 @@ path_ext(const char *path)
const char *
mime(const char *path)
{
- const char *ext, *def = "application/octet-stream";
+ const char *ext;
struct etm *t;
if ((ext = path_ext(path)) == NULL)
- return def;
+ return mimes.def;
for (t = mimes.t; t->mime != NULL; ++t)
if (!strcmp(ext, t->ext))
return t->mime;
- return def;
+ return mimes.def;
}
diff --git a/parse.y b/parse.y
index f4a21cf..286969a 100644
--- a/parse.y
+++ b/parse.y
@@ -42,8 +42,7 @@ extern void yyerror(const char*);
int num;
}
-%token TBOOL TSTRING TNUM
-%token TDAEMON TIPV6 TPORT TPROTOCOLS TSERVER
+%token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE TSERVER
%token TCERT TKEY TROOT TCGI
%token TERR
@@ -66,6 +65,8 @@ option : TDAEMON TBOOL { conf.foreground = !$2; }
if (tls_config_parse_protocols(&conf.protos, $2) == -1)
errx(1, "invalid protocols string \"%s\"", $2);
}
+ | TMIME TSTRING TSTRING { add_mime($2, $3); }
+ | TDEFAULT TTYPE TSTRING { set_default_mime($3); }
;
vhosts : /* empty */
diff --git a/sample.conf b/sample.conf
index 646b930..08d6541 100644
--- a/sample.conf
+++ b/sample.conf
@@ -4,6 +4,9 @@ daemon on # enable daemon mode
# decomment to allow only TLSv1.3
#protocols "tlsv1.3"
+# add the mapping for the extension rtf to the MIME application/rtf
+mime "application/rtf" "rtf"
+
# server block example
server "example.com" {
cert "/path/to/cert.pem"