aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-18 18:48:37 +0000
committerOmar Polo <op@omarpolo.com>2021-01-18 18:48:37 +0000
commita010b0ddc5aa8cf49207b0ab87d36be6ebb320cf (patch)
tree90e5f634d00fd548c378c9852a0891765bc7e297
parent982069a120a3d36483427ce00b9cf90a8bf4daab (diff)
move mimes into the struct config
-rw-r--r--gmid.h21
-rw-r--r--mime.c50
2 files changed, 36 insertions, 35 deletions
diff --git a/gmid.h b/gmid.h
index bbf70d3..5d4b5f8 100644
--- a/gmid.h
+++ b/gmid.h
@@ -64,11 +64,24 @@ struct vhost {
extern struct vhost hosts[HOSTSLEN];
+struct etm { /* extension to mime */
+ const char *mime;
+ const char *ext;
+};
+
+struct mimes {
+ char *def;
+ struct etm *t;
+ size_t len;
+ size_t cap;
+};
+
struct conf {
- int foreground;
- int port;
- int ipv6;
- uint32_t protos;
+ int foreground;
+ int port;
+ int ipv6;
+ uint32_t protos;
+ struct mimes mimes;
};
extern struct conf conf;
diff --git a/mime.c b/mime.c
index 121dee0..35ff72e 100644
--- a/mime.c
+++ b/mime.c
@@ -20,31 +20,18 @@
#include "gmid.h"
-struct etm { /* extension to mime */
- const char *mime;
- const char *ext;
-};
-
-struct mimes {
- char *def;
- struct etm *t;
- size_t len;
- size_t cap;
-};
-
-struct mimes mimes;
-
void
init_mime(void)
{
- mimes.len = 0;
- mimes.cap = 2;
+ conf.mimes.len = 0;
+ conf.mimes.cap = 2;
- if ((mimes.t = calloc(mimes.cap, sizeof(struct etm))) == NULL)
+ conf.mimes.t = calloc(conf.mimes.cap, sizeof(struct etm));
+ if (conf.mimes.t == NULL)
fatal("calloc: %s", strerror(errno));
- mimes.def = strdup("application/octet-stream");
- if (mimes.def == NULL)
+ conf.mimes.def = strdup("application/octet-stream");
+ if (conf.mimes.def == NULL)
fatal("strdup: %s", strerror(errno));
}
@@ -52,8 +39,8 @@ init_mime(void)
void
set_default_mime(const char *m)
{
- free(mimes.def);
- if ((mimes.def = strdup(m)) == NULL)
+ free(conf.mimes.def);
+ if ((conf.mimes.def = strdup(m)) == NULL)
fatal("strdup: %s", strerror(errno));
}
@@ -61,16 +48,17 @@ set_default_mime(const char *m)
void
add_mime(const char *mime, const char *ext)
{
- if (mimes.len == mimes.cap) {
- mimes.cap *= 1.5;
- mimes.t = realloc(mimes.t, mimes.cap * sizeof(struct etm));
- if (mimes.t == NULL)
+ if (conf.mimes.len == conf.mimes.cap) {
+ conf.mimes.cap *= 1.5;
+ conf.mimes.t = realloc(conf.mimes.t,
+ conf.mimes.cap * sizeof(struct etm));
+ if (conf.mimes.t == NULL)
fatal("realloc: %s", strerror(errno));
}
- mimes.t[mimes.len].mime = mime;
- mimes.t[mimes.len].ext = ext;
- mimes.len++;
+ conf.mimes.t[conf.mimes.len].mime = mime;
+ conf.mimes.t[conf.mimes.len].ext = ext;
+ conf.mimes.len++;
}
/* load a default set of common mime-extension associations */
@@ -120,11 +108,11 @@ mime(const char *path)
struct etm *t;
if ((ext = path_ext(path)) == NULL)
- return mimes.def;
+ return conf.mimes.def;
- for (t = mimes.t; t->mime != NULL; ++t)
+ for (t = conf.mimes.t; t->mime != NULL; ++t)
if (!strcmp(ext, t->ext))
return t->mime;
- return mimes.def;
+ return conf.mimes.def;
}