author | Lars Hjemli <hjemli@gmail.com> | 2009-02-13 19:43:30 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 10:55:15 (UTC) |
commit | c4d46c7035d07070ac1ebf0c0b44df927358687f (patch) (unidiff) | |
tree | 562cf4f01afe78b92b13ad5be5dc01e07db04a66 /cgit.c | |
parent | 286a905842dc0bec6d21a614ec4a97c5f19d5bc4 (diff) | |
download | cgit-c4d46c7035d07070ac1ebf0c0b44df927358687f.zip cgit-c4d46c7035d07070ac1ebf0c0b44df927358687f.tar.gz cgit-c4d46c7035d07070ac1ebf0c0b44df927358687f.tar.bz2 |
Add support for mime type registration and lookup
This patch makes it possible to register mappings from filename
extension to mime type in cgitrc and use this mapping when returning
blob content in `plain` view.
The reason for adding this mapping to cgitrc (as opposed to parsing
something like /etc/mime.types) is to allow quick lookup of a limited
number of filename extensions (/etc/mime-types on my machine currently
contains over 700 entries).
NB: A nice addition to this patch would be to parse /etc/mime.types
when `plain` view is requested for a file with an extension for which
there is no mapping registered in cgitrc.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -17,6 +17,14 @@ | |||
17 | 17 | ||
18 | const char *cgit_version = CGIT_VERSION; | 18 | const char *cgit_version = CGIT_VERSION; |
19 | 19 | ||
20 | void add_mimetype(const char *name, const char *value) | ||
21 | { | ||
22 | struct string_list_item *item; | ||
23 | |||
24 | item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); | ||
25 | item->util = xstrdup(value); | ||
26 | } | ||
27 | |||
20 | void config_cb(const char *name, const char *value) | 28 | void config_cb(const char *name, const char *value) |
21 | { | 29 | { |
22 | if (!strcmp(name, "root-title")) | 30 | if (!strcmp(name, "root-title")) |
@@ -101,6 +109,8 @@ void config_cb(const char *name, const char *value) | |||
101 | ctx.cfg.clone_prefix = xstrdup(value); | 109 | ctx.cfg.clone_prefix = xstrdup(value); |
102 | else if (!strcmp(name, "local-time")) | 110 | else if (!strcmp(name, "local-time")) |
103 | ctx.cfg.local_time = atoi(value); | 111 | ctx.cfg.local_time = atoi(value); |
112 | else if (!prefixcmp(name, "mimetype.")) | ||
113 | add_mimetype(name + 9, value); | ||
104 | else if (!strcmp(name, "repo.group")) | 114 | else if (!strcmp(name, "repo.group")) |
105 | ctx.cfg.repo_group = xstrdup(value); | 115 | ctx.cfg.repo_group = xstrdup(value); |
106 | else if (!strcmp(name, "repo.url")) | 116 | else if (!strcmp(name, "repo.url")) |
@@ -213,6 +223,7 @@ static void prepare_context(struct cgit_context *ctx) | |||
213 | ctx->page.modified = time(NULL); | 223 | ctx->page.modified = time(NULL); |
214 | ctx->page.expires = ctx->page.modified; | 224 | ctx->page.expires = ctx->page.modified; |
215 | ctx->page.etag = NULL; | 225 | ctx->page.etag = NULL; |
226 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | ||
216 | } | 227 | } |
217 | 228 | ||
218 | struct refmatch { | 229 | struct refmatch { |