diff options
author | Omar Polo <op@omarpolo.com> | 2021-01-18 18:18:57 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-01-18 18:18:57 +0000 |
commit | 0fbe79b33c1d16b0611851e2019558ce8888a02e (patch) | |
tree | df6bac6c8325f8d62862949129010683186bd784 /gmid.c | |
parent | 132cae8c6f2c5866ff84058ac9461ca95d63ed8b (diff) |
improve mime handling
we still have an hardcoded list, but this implements the API needed to
modify the mappings.
Diffstat (limited to 'gmid.c')
-rw-r--r-- | gmid.c | 58 |
1 files changed, 4 insertions, 54 deletions
@@ -32,28 +32,6 @@ int exfd; struct conf conf; -struct etm { /* file extension to mime */ - const char *mime; - const char *ext; -} filetypes[] = { - {"application/pdf", "pdf"}, - - {"image/gif", "gif"}, - {"image/jpeg", "jpg"}, - {"image/jpeg", "jpeg"}, - {"image/png", "png"}, - {"image/svg+xml", "svg"}, - - {"text/gemini", "gemini"}, - {"text/gemini", "gmi"}, - {"text/markdown", "markdown"}, - {"text/markdown", "md"}, - {"text/plain", "txt"}, - {"text/xml", "xml"}, - - {NULL, NULL} -}; - void fatal(const char *fmt, ...) { @@ -142,38 +120,6 @@ filesize(int fd) return len; } -const char * -path_ext(const char *path) -{ - const char *end; - - end = path + strlen(path)-1; - for (; end != path; --end) { - if (*end == '.') - return end+1; - if (*end == '/') - break; - } - - return NULL; -} - -const char * -mime(const char *path) -{ - const char *ext, *def = "application/octet-stream"; - struct etm *t; - - if ((ext = path_ext(path)) == NULL) - return def; - - for (t = filetypes; t->mime != NULL; ++t) - if (!strcmp(ext, t->ext)) - return t->mime; - - return def; -} - char * absolutify_path(const char *path) { @@ -304,6 +250,8 @@ listener_main() struct tls *ctx = NULL; struct tls_config *tlsconf; + load_default_mime(); + if ((tlsconf = tls_config_new()) == NULL) fatal("tls_config_new"); @@ -362,6 +310,8 @@ main(int argc, char **argv) conf.ipv6 = 0; conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3; + init_mime(); + while ((ch = getopt(argc, argv, "6C:c:d:fhK:np:x:")) != -1) { switch (ch) { case '6': |