diff options
-rw-r--r-- | cgit.c | 13 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 21 | ||||
-rw-r--r-- | ui-atom.c | 2 | ||||
-rw-r--r-- | ui-commit.c | 12 | ||||
-rw-r--r-- | ui-patch.c | 6 | ||||
-rw-r--r-- | ui-plain.c | 20 | ||||
-rw-r--r-- | ui-tag.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 8 |
9 files changed, 74 insertions, 13 deletions
diff --git a/cgit.c b/cgit.c index b3a98c1..dbec196 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -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 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 28 | struct cgit_filter *new_filter(const char *cmd, int extra_args) |
21 | { | 29 | { |
22 | struct cgit_filter *f; | 30 | struct cgit_filter *f; |
@@ -66,6 +74,8 @@ void config_cb(const char *name, const char *value) | |||
66 | ctx.cfg.virtual_root = ""; | 74 | ctx.cfg.virtual_root = ""; |
67 | } else if (!strcmp(name, "nocache")) | 75 | } else if (!strcmp(name, "nocache")) |
68 | ctx.cfg.nocache = atoi(value); | 76 | ctx.cfg.nocache = atoi(value); |
77 | else if (!strcmp(name, "noplainemail")) | ||
78 | ctx.cfg.noplainemail = atoi(value); | ||
69 | else if (!strcmp(name, "noheader")) | 79 | else if (!strcmp(name, "noheader")) |
70 | ctx.cfg.noheader = atoi(value); | 80 | ctx.cfg.noheader = atoi(value); |
71 | else if (!strcmp(name, "snapshots")) | 81 | else if (!strcmp(name, "snapshots")) |
@@ -120,6 +130,8 @@ void config_cb(const char *name, const char *value) | |||
120 | ctx.cfg.clone_prefix = xstrdup(value); | 130 | ctx.cfg.clone_prefix = xstrdup(value); |
121 | else if (!strcmp(name, "local-time")) | 131 | else if (!strcmp(name, "local-time")) |
122 | ctx.cfg.local_time = atoi(value); | 132 | ctx.cfg.local_time = atoi(value); |
133 | else if (!prefixcmp(name, "mimetype.")) | ||
134 | add_mimetype(name + 9, value); | ||
123 | else if (!strcmp(name, "repo.group")) | 135 | else if (!strcmp(name, "repo.group")) |
124 | ctx.cfg.repo_group = xstrdup(value); | 136 | ctx.cfg.repo_group = xstrdup(value); |
125 | else if (!strcmp(name, "repo.url")) | 137 | else if (!strcmp(name, "repo.url")) |
@@ -236,6 +248,7 @@ static void prepare_context(struct cgit_context *ctx) | |||
236 | ctx->page.modified = time(NULL); | 248 | ctx->page.modified = time(NULL); |
237 | ctx->page.expires = ctx->page.modified; | 249 | ctx->page.expires = ctx->page.modified; |
238 | ctx->page.etag = NULL; | 250 | ctx->page.etag = NULL; |
251 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | ||
239 | } | 252 | } |
240 | 253 | ||
241 | struct refmatch { | 254 | struct refmatch { |
diff --git a/cgit.h b/cgit.h index f10ba05..b8557ac 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <string-list.h> | ||
18 | #include <xdiff-interface.h> | 19 | #include <xdiff-interface.h> |
19 | #include <xdiff/xdiff.h> | 20 | #include <xdiff/xdiff.h> |
20 | #include <utf8.h> | 21 | #include <utf8.h> |
@@ -179,12 +180,14 @@ struct cgit_config { | |||
179 | int max_repodesc_len; | 180 | int max_repodesc_len; |
180 | int max_stats; | 181 | int max_stats; |
181 | int nocache; | 182 | int nocache; |
183 | int noplainemail; | ||
182 | int noheader; | 184 | int noheader; |
183 | int renamelimit; | 185 | int renamelimit; |
184 | int snapshots; | 186 | int snapshots; |
185 | int summary_branches; | 187 | int summary_branches; |
186 | int summary_log; | 188 | int summary_log; |
187 | int summary_tags; | 189 | int summary_tags; |
190 | struct string_list mimetypes; | ||
188 | struct cgit_filter *commit_filter; | 191 | struct cgit_filter *commit_filter; |
189 | struct cgit_filter *source_filter; | 192 | struct cgit_filter *source_filter; |
190 | }; | 193 | }; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index ffb3e0f..dc63637 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -153,6 +153,10 @@ max-stats:: | |||
153 | "month", "quarter" and "year". If unspecified, statistics are | 153 | "month", "quarter" and "year". If unspecified, statistics are |
154 | disabled. Default value: none. See also: "repo.max-stats". | 154 | disabled. Default value: none. See also: "repo.max-stats". |
155 | 155 | ||
156 | mimetype.<ext>:: | ||
157 | Set the mimetype for the specified filename extension. This is used | ||
158 | by the `plain` command when returning blob content. | ||
159 | |||
156 | module-link:: | 160 | module-link:: |
157 | Text which will be used as the formatstring for a hyperlink when a | 161 | Text which will be used as the formatstring for a hyperlink when a |
158 | submodule is printed in a directory listing. The arguments for the | 162 | submodule is printed in a directory listing. The arguments for the |
@@ -164,6 +168,10 @@ nocache:: | |||
164 | deprecated, and will not be honored starting with cgit-1.0. Default | 168 | deprecated, and will not be honored starting with cgit-1.0. Default |
165 | value: "0". | 169 | value: "0". |
166 | 170 | ||
171 | noplainemail:: | ||
172 | If set to "1" showing full author email adresses will be disabled. | ||
173 | Default value: "0". | ||
174 | |||
167 | noheader:: | 175 | noheader:: |
168 | Flag which, when set to "1", will make cgit omit the standard header | 176 | Flag which, when set to "1", will make cgit omit the standard header |
169 | on all pages. Default value: none. See also: "embedded". | 177 | on all pages. Default value: none. See also: "embedded". |
@@ -345,6 +353,19 @@ snapshots=tar.gz tar.bz2 zip | |||
345 | 353 | ||
346 | 354 | ||
347 | ## | 355 | ## |
356 | ## List of common mimetypes | ||
357 | ## | ||
358 | |||
359 | mimetype.git=image/git | ||
360 | mimetype.html=text/html | ||
361 | mimetype.jpg=image/jpeg | ||
362 | mimetype.jpeg=image/jpeg | ||
363 | mimetype.pdf=application/pdf | ||
364 | mimetype.png=image/png | ||
365 | mimetype.svg=image/svg+xml | ||
366 | |||
367 | |||
368 | ## | ||
348 | ## List of repositories. | 369 | ## List of repositories. |
349 | ## PS: Any repositories listed when repo.group is unset will not be | 370 | ## PS: Any repositories listed when repo.group is unset will not be |
350 | ## displayed under a group heading | 371 | ## displayed under a group heading |
diff --git a/ui-atom.c b/ui-atom.c index e5c31d9..808b2d0 100644 --- a/ui-atom.c +++ b/ui-atom.c | |||
@@ -32,7 +32,7 @@ void add_entry(struct commit *commit, char *host) | |||
32 | html_txt(info->author); | 32 | html_txt(info->author); |
33 | html("</name>\n"); | 33 | html("</name>\n"); |
34 | } | 34 | } |
35 | if (info->author_email) { | 35 | if (info->author_email && !ctx.cfg.noplainemail) { |
36 | mail = xstrdup(info->author_email); | 36 | mail = xstrdup(info->author_email); |
37 | t = strchr(mail, '<'); | 37 | t = strchr(mail, '<'); |
38 | if (t) | 38 | if (t) |
diff --git a/ui-commit.c b/ui-commit.c index 5815b58..d6b73ee 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -40,15 +40,19 @@ void cgit_print_commit(char *hex) | |||
40 | html("<table summary='commit info' class='commit-info'>\n"); | 40 | html("<table summary='commit info' class='commit-info'>\n"); |
41 | html("<tr><th>author</th><td>"); | 41 | html("<tr><th>author</th><td>"); |
42 | html_txt(info->author); | 42 | html_txt(info->author); |
43 | html(" "); | 43 | if (!ctx.cfg.noplainemail) { |
44 | html_txt(info->author_email); | 44 | html(" "); |
45 | html_txt(info->author_email); | ||
46 | } | ||
45 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
46 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); | 48 | cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); |
47 | html("</td></tr>\n"); | 49 | html("</td></tr>\n"); |
48 | html("<tr><th>committer</th><td>"); | 50 | html("<tr><th>committer</th><td>"); |
49 | html_txt(info->committer); | 51 | html_txt(info->committer); |
50 | html(" "); | 52 | if (!ctx.cfg.noplainemail) { |
51 | html_txt(info->committer_email); | 53 | html(" "); |
54 | html_txt(info->committer_email); | ||
55 | } | ||
52 | html("</td><td class='right'>"); | 56 | html("</td><td class='right'>"); |
53 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); | 57 | cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); |
54 | html("</td></tr>\n"); | 58 | html("</td></tr>\n"); |
diff --git a/ui-patch.c b/ui-patch.c index 5d665d3..2a8f7a5 100644 --- a/ui-patch.c +++ b/ui-patch.c | |||
@@ -108,7 +108,11 @@ void cgit_print_patch(char *hex) | |||
108 | ctx.page.filename = patchname; | 108 | ctx.page.filename = patchname; |
109 | cgit_print_http_headers(&ctx); | 109 | cgit_print_http_headers(&ctx); |
110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); | 110 | htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); |
111 | htmlf("From: %s %s\n", info->author, info->author_email); | 111 | htmlf("From: %s", info->author); |
112 | if (!ctx.cfg.noplainemail) { | ||
113 | htmlf(" %s", info->author_email); | ||
114 | } | ||
115 | html("\n"); | ||
112 | html("Date: "); | 116 | html("Date: "); |
113 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); | 117 | cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); |
114 | htmlf("Subject: %s\n\n", info->subject); | 118 | htmlf("Subject: %s\n\n", info->subject); |
diff --git a/ui-plain.c b/ui-plain.c index 93a3a05..27c6dae 100644 --- a/ui-plain.c +++ b/ui-plain.c | |||
@@ -17,8 +17,9 @@ int match; | |||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf, *ext; |
21 | unsigned long size; | 21 | unsigned long size; |
22 | struct string_list_item *mime; | ||
22 | 23 | ||
23 | type = sha1_object_info(sha1, &size); | 24 | type = sha1_object_info(sha1, &size); |
24 | if (type == OBJ_BAD) { | 25 | if (type == OBJ_BAD) { |
@@ -31,10 +32,19 @@ static void print_object(const unsigned char *sha1, const char *path) | |||
31 | html_status(404, "Not found", 0); | 32 | html_status(404, "Not found", 0); |
32 | return; | 33 | return; |
33 | } | 34 | } |
34 | if (buffer_is_binary(buf, size)) | 35 | ctx.page.mimetype = NULL; |
35 | ctx.page.mimetype = "application/octet-stream"; | 36 | ext = strrchr(path, '.'); |
36 | else | 37 | if (ext && *(++ext)) { |
37 | ctx.page.mimetype = "text/plain"; | 38 | mime = string_list_lookup(ext, &ctx.cfg.mimetypes); |
39 | if (mime) | ||
40 | ctx.page.mimetype = (char *)mime->util; | ||
41 | } | ||
42 | if (!ctx.page.mimetype) { | ||
43 | if (buffer_is_binary(buf, size)) | ||
44 | ctx.page.mimetype = "application/octet-stream"; | ||
45 | else | ||
46 | ctx.page.mimetype = "text/plain"; | ||
47 | } | ||
38 | ctx.page.filename = fmt("%s", path); | 48 | ctx.page.filename = fmt("%s", path); |
39 | ctx.page.size = size; | 49 | ctx.page.size = size; |
40 | ctx.page.etag = sha1_to_hex(sha1); | 50 | ctx.page.etag = sha1_to_hex(sha1); |
diff --git a/ui-tag.c b/ui-tag.c index 0e056e0..a9c8670 100644 --- a/ui-tag.c +++ b/ui-tag.c | |||
@@ -64,7 +64,7 @@ void cgit_print_tag(char *revname) | |||
64 | if (info->tagger) { | 64 | if (info->tagger) { |
65 | html("<tr><td>Tagged by</td><td>"); | 65 | html("<tr><td>Tagged by</td><td>"); |
66 | html_txt(info->tagger); | 66 | html_txt(info->tagger); |
67 | if (info->tagger_email) { | 67 | if (info->tagger_email && !ctx.cfg.noplainemail) { |
68 | html(" "); | 68 | html(" "); |
69 | html_txt(info->tagger_email); | 69 | html_txt(info->tagger_email); |
70 | } | 70 | } |
diff --git a/ui-tree.c b/ui-tree.c index caf6a9e..c608754 100644 --- a/ui-tree.c +++ b/ui-tree.c | |||
@@ -113,6 +113,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
113 | { | 113 | { |
114 | char *name; | 114 | char *name; |
115 | char *fullpath; | 115 | char *fullpath; |
116 | char *class; | ||
116 | enum object_type type; | 117 | enum object_type type; |
117 | unsigned long size = 0; | 118 | unsigned long size = 0; |
118 | 119 | ||
@@ -145,7 +146,12 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
145 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, | 146 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
146 | curr_rev, fullpath); | 147 | curr_rev, fullpath); |
147 | } else { | 148 | } else { |
148 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, | 149 | class = strrchr(name, '.'); |
150 | if (class != NULL) { | ||
151 | class = fmt("ls-blob %s", class + 1); | ||
152 | } else | ||
153 | class = "ls-blob"; | ||
154 | cgit_tree_link(name, NULL, class, ctx.qry.head, | ||
149 | curr_rev, fullpath); | 155 | curr_rev, fullpath); |
150 | } | 156 | } |
151 | htmlf("</td><td class='ls-size'>%li</td>", size); | 157 | htmlf("</td><td class='ls-size'>%li</td>", size); |