diff options
author | Omar Polo <op@omarpolo.com> | 2021-01-18 18:43:47 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-01-18 18:43:47 +0000 |
commit | 982069a120a3d36483427ce00b9cf90a8bf4daab (patch) | |
tree | 4aceb73f1893525c98649586939437ed53f79a04 /mime.c | |
parent | 0fbe79b33c1d16b0611851e2019558ce8888a02e (diff) |
add "mime" and "default type" option for the configuration
Diffstat (limited to 'mime.c')
-rw-r--r-- | mime.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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; } |