aboutsummaryrefslogtreecommitdiffstats
path: root/ui-plain.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-plain.c')
-rw-r--r--ui-plain.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/ui-plain.c b/ui-plain.c
index d68518e..0dd1a8b 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -19,10 +19,8 @@ struct walk_tree_context {
19static int print_object(const unsigned char *sha1, const char *path) 19static int print_object(const unsigned char *sha1, const char *path)
20{ 20{
21 enum object_type type; 21 enum object_type type;
22 char *buf, *ext; 22 char *buf, *mimetype;
23 unsigned long size; 23 unsigned long size;
24 struct string_list_item *mime;
25 int freemime;
26 24
27 type = sha1_object_info(sha1, &size); 25 type = sha1_object_info(sha1, &size);
28 if (type == OBJ_BAD) { 26 if (type == OBJ_BAD) {
@@ -35,22 +33,10 @@ static int print_object(const unsigned char *sha1, const char *path)
35 cgit_print_error_page(404, "Not found", "Not found"); 33 cgit_print_error_page(404, "Not found", "Not found");
36 return 0; 34 return 0;
37 } 35 }
38 ctx.page.mimetype = NULL; 36
39 ext = strrchr(path, '.'); 37 mimetype = get_mimetype_for_filename(path);
40 freemime = 0; 38 ctx.page.mimetype = mimetype;
41 if (ext && *(++ext)) { 39
42 mime = string_list_lookup(&ctx.cfg.mimetypes, ext);
43 if (mime) {
44 ctx.page.mimetype = (char *)mime->util;
45 ctx.page.charset = NULL;
46 } else {
47 ctx.page.mimetype = get_mimetype_from_file(ctx.cfg.mimetype_file, ext);
48 if (ctx.page.mimetype) {
49 freemime = 1;
50 ctx.page.charset = NULL;
51 }
52 }
53 }
54 if (!ctx.page.mimetype) { 40 if (!ctx.page.mimetype) {
55 if (buffer_is_binary(buf, size)) { 41 if (buffer_is_binary(buf, size)) {
56 ctx.page.mimetype = "application/octet-stream"; 42 ctx.page.mimetype = "application/octet-stream";
@@ -64,9 +50,7 @@ static int print_object(const unsigned char *sha1, const char *path)
64 ctx.page.etag = sha1_to_hex(sha1); 50 ctx.page.etag = sha1_to_hex(sha1);
65 cgit_print_http_headers(); 51 cgit_print_http_headers();
66 html_raw(buf, size); 52 html_raw(buf, size);
67 /* If we allocated this, then casting away const is safe. */ 53 free(mimetype);
68 if (freemime)
69 free((char*) ctx.page.mimetype);
70 return 1; 54 return 1;
71} 55}
72 56