aboutsummaryrefslogtreecommitdiff
path: root/mime.c
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 /mime.c
parent0fbe79b33c1d16b0611851e2019558ce8888a02e (diff)
add "mime" and "default type" option for the configuration
Diffstat (limited to 'mime.c')
-rw-r--r--mime.c20
1 files changed, 17 insertions, 3 deletions
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;
}