author | Lars Hjemli <hjemli@gmail.com> | 2008-03-25 01:43:51 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-04-08 19:35:00 (UTC) |
commit | fa4dfee5489d8c829da92637dd84e8650439f313 (patch) (unidiff) | |
tree | 2c5e6ffd0a20de58de7353acb278e76a56d23bb6 | |
parent | 23296ad648c0e2a9e3cf40a3de322b10ad25cce3 (diff) | |
download | cgit-fa4dfee5489d8c829da92637dd84e8650439f313.zip cgit-fa4dfee5489d8c829da92637dd84e8650439f313.tar.gz cgit-fa4dfee5489d8c829da92637dd84e8650439f313.tar.bz2 |
Don't specify mimetype in ui-blob.c
But be sure to specify correct filename. This way, the client can hopefully
guess a sensible mimetype based on the filename suffix, and cgit can ignore
the issue altogether.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-blob.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 3 |
2 files changed, 3 insertions, 2 deletions
@@ -1,43 +1,43 @@ | |||
1 | /* ui-blob.c: show blob content | 1 | /* ui-blob.c: show blob content |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | void cgit_print_blob(const char *hex, char *path) | 13 | void cgit_print_blob(const char *hex, char *path) |
14 | { | 14 | { |
15 | 15 | ||
16 | unsigned char sha1[20]; | 16 | unsigned char sha1[20]; |
17 | enum object_type type; | 17 | enum object_type type; |
18 | unsigned char *buf; | 18 | unsigned char *buf; |
19 | unsigned long size; | 19 | unsigned long size; |
20 | 20 | ||
21 | if (get_sha1_hex(hex, sha1)){ | 21 | if (get_sha1_hex(hex, sha1)){ |
22 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 22 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | 25 | ||
26 | type = sha1_object_info(sha1, &size); | 26 | type = sha1_object_info(sha1, &size); |
27 | if (type == OBJ_BAD) { | 27 | if (type == OBJ_BAD) { |
28 | cgit_print_error(fmt("Bad object name: %s", hex)); | 28 | cgit_print_error(fmt("Bad object name: %s", hex)); |
29 | return; | 29 | return; |
30 | } | 30 | } |
31 | 31 | ||
32 | buf = read_sha1_file(sha1, &type, &size); | 32 | buf = read_sha1_file(sha1, &type, &size); |
33 | if (!buf) { | 33 | if (!buf) { |
34 | cgit_print_error(fmt("Error reading object %s", hex)); | 34 | cgit_print_error(fmt("Error reading object %s", hex)); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | 37 | ||
38 | buf[size] = '\0'; | 38 | buf[size] = '\0'; |
39 | ctx.page.mimetype = "text/plain"; | 39 | ctx.page.mimetype = NULL; |
40 | ctx.page.filename = path; | 40 | ctx.page.filename = path; |
41 | cgit_print_http_headers(&ctx); | 41 | cgit_print_http_headers(&ctx); |
42 | write(htmlfd, buf, size); | 42 | write(htmlfd, buf, size); |
43 | } | 43 | } |
@@ -1,218 +1,219 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | char *curr_rev; | 13 | char *curr_rev; |
14 | char *match_path; | 14 | char *match_path; |
15 | int header = 0; | 15 | int header = 0; |
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, char *path) | 17 | static void print_object(const unsigned char *sha1, char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf; |
21 | unsigned long size, lineno, start, idx; | 21 | unsigned long size, lineno, start, idx; |
22 | const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>"; | 22 | const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>"; |
23 | 23 | ||
24 | type = sha1_object_info(sha1, &size); | 24 | type = sha1_object_info(sha1, &size); |
25 | if (type == OBJ_BAD) { | 25 | if (type == OBJ_BAD) { |
26 | cgit_print_error(fmt("Bad object name: %s", | 26 | cgit_print_error(fmt("Bad object name: %s", |
27 | sha1_to_hex(sha1))); | 27 | sha1_to_hex(sha1))); |
28 | return; | 28 | return; |
29 | } | 29 | } |
30 | 30 | ||
31 | buf = read_sha1_file(sha1, &type, &size); | 31 | buf = read_sha1_file(sha1, &type, &size); |
32 | if (!buf) { | 32 | if (!buf) { |
33 | cgit_print_error(fmt("Error reading object %s", | 33 | cgit_print_error(fmt("Error reading object %s", |
34 | sha1_to_hex(sha1))); | 34 | sha1_to_hex(sha1))); |
35 | return; | 35 | return; |
36 | } | 36 | } |
37 | 37 | ||
38 | html(" blob: <a href='"); | 38 | html(" blob: <a href='"); |
39 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); | 39 | html_attr(cgit_pageurl(ctx.qry.repo, "blob", |
40 | fmt("id=%s&path=%s", sha1_to_hex(sha1), path))); | ||
40 | htmlf("'>%s</a>",sha1_to_hex(sha1)); | 41 | htmlf("'>%s</a>",sha1_to_hex(sha1)); |
41 | 42 | ||
42 | html("<table summary='blob content' class='blob'>\n"); | 43 | html("<table summary='blob content' class='blob'>\n"); |
43 | idx = 0; | 44 | idx = 0; |
44 | start = 0; | 45 | start = 0; |
45 | lineno = 0; | 46 | lineno = 0; |
46 | while(idx < size) { | 47 | while(idx < size) { |
47 | if (buf[idx] == '\n') { | 48 | if (buf[idx] == '\n') { |
48 | buf[idx] = '\0'; | 49 | buf[idx] = '\0'; |
49 | htmlf(linefmt, ++lineno); | 50 | htmlf(linefmt, ++lineno); |
50 | html_txt(buf + start); | 51 | html_txt(buf + start); |
51 | html("</td></tr>\n"); | 52 | html("</td></tr>\n"); |
52 | start = idx + 1; | 53 | start = idx + 1; |
53 | } | 54 | } |
54 | idx++; | 55 | idx++; |
55 | } | 56 | } |
56 | htmlf(linefmt, ++lineno); | 57 | htmlf(linefmt, ++lineno); |
57 | html_txt(buf + start); | 58 | html_txt(buf + start); |
58 | html("</td></tr>\n"); | 59 | html("</td></tr>\n"); |
59 | html("</table>\n"); | 60 | html("</table>\n"); |
60 | } | 61 | } |
61 | 62 | ||
62 | 63 | ||
63 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 64 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
64 | const char *pathname, unsigned int mode, int stage) | 65 | const char *pathname, unsigned int mode, int stage) |
65 | { | 66 | { |
66 | char *name; | 67 | char *name; |
67 | char *fullpath; | 68 | char *fullpath; |
68 | enum object_type type; | 69 | enum object_type type; |
69 | unsigned long size = 0; | 70 | unsigned long size = 0; |
70 | 71 | ||
71 | name = xstrdup(pathname); | 72 | name = xstrdup(pathname); |
72 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", | 73 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
73 | ctx.qry.path ? "/" : "", name); | 74 | ctx.qry.path ? "/" : "", name); |
74 | 75 | ||
75 | type = sha1_object_info(sha1, &size); | 76 | type = sha1_object_info(sha1, &size); |
76 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { | 77 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
77 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 78 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
78 | name, | 79 | name, |
79 | sha1_to_hex(sha1)); | 80 | sha1_to_hex(sha1)); |
80 | return 0; | 81 | return 0; |
81 | } | 82 | } |
82 | 83 | ||
83 | html("<tr><td class='ls-mode'>"); | 84 | html("<tr><td class='ls-mode'>"); |
84 | cgit_print_filemode(mode); | 85 | cgit_print_filemode(mode); |
85 | html("</td><td>"); | 86 | html("</td><td>"); |
86 | if (S_ISGITLINK(mode)) { | 87 | if (S_ISGITLINK(mode)) { |
87 | htmlf("<a class='ls-mod' href='"); | 88 | htmlf("<a class='ls-mod' href='"); |
88 | html_attr(fmt(ctx.repo->module_link, | 89 | html_attr(fmt(ctx.repo->module_link, |
89 | name, | 90 | name, |
90 | sha1_to_hex(sha1))); | 91 | sha1_to_hex(sha1))); |
91 | html("'>"); | 92 | html("'>"); |
92 | html_txt(name); | 93 | html_txt(name); |
93 | html("</a>"); | 94 | html("</a>"); |
94 | } else if (S_ISDIR(mode)) { | 95 | } else if (S_ISDIR(mode)) { |
95 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, | 96 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
96 | curr_rev, fullpath); | 97 | curr_rev, fullpath); |
97 | } else { | 98 | } else { |
98 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, | 99 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
99 | curr_rev, fullpath); | 100 | curr_rev, fullpath); |
100 | } | 101 | } |
101 | htmlf("</td><td class='ls-size'>%li</td>", size); | 102 | htmlf("</td><td class='ls-size'>%li</td>", size); |
102 | 103 | ||
103 | html("<td>"); | 104 | html("<td>"); |
104 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, | 105 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
105 | fullpath, 0, NULL, NULL); | 106 | fullpath, 0, NULL, NULL); |
106 | html("</td></tr>\n"); | 107 | html("</td></tr>\n"); |
107 | free(name); | 108 | free(name); |
108 | return 0; | 109 | return 0; |
109 | } | 110 | } |
110 | 111 | ||
111 | static void ls_head() | 112 | static void ls_head() |
112 | { | 113 | { |
113 | html("<table summary='tree listing' class='list'>\n"); | 114 | html("<table summary='tree listing' class='list'>\n"); |
114 | html("<tr class='nohover'>"); | 115 | html("<tr class='nohover'>"); |
115 | html("<th class='left'>Mode</th>"); | 116 | html("<th class='left'>Mode</th>"); |
116 | html("<th class='left'>Name</th>"); | 117 | html("<th class='left'>Name</th>"); |
117 | html("<th class='right'>Size</th>"); | 118 | html("<th class='right'>Size</th>"); |
118 | html("<th/>"); | 119 | html("<th/>"); |
119 | html("</tr>\n"); | 120 | html("</tr>\n"); |
120 | header = 1; | 121 | header = 1; |
121 | } | 122 | } |
122 | 123 | ||
123 | static void ls_tail() | 124 | static void ls_tail() |
124 | { | 125 | { |
125 | if (!header) | 126 | if (!header) |
126 | return; | 127 | return; |
127 | html("</table>\n"); | 128 | html("</table>\n"); |
128 | header = 0; | 129 | header = 0; |
129 | } | 130 | } |
130 | 131 | ||
131 | static void ls_tree(const unsigned char *sha1, char *path) | 132 | static void ls_tree(const unsigned char *sha1, char *path) |
132 | { | 133 | { |
133 | struct tree *tree; | 134 | struct tree *tree; |
134 | 135 | ||
135 | tree = parse_tree_indirect(sha1); | 136 | tree = parse_tree_indirect(sha1); |
136 | if (!tree) { | 137 | if (!tree) { |
137 | cgit_print_error(fmt("Not a tree object: %s", | 138 | cgit_print_error(fmt("Not a tree object: %s", |
138 | sha1_to_hex(sha1))); | 139 | sha1_to_hex(sha1))); |
139 | return; | 140 | return; |
140 | } | 141 | } |
141 | 142 | ||
142 | ls_head(); | 143 | ls_head(); |
143 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); | 144 | read_tree_recursive(tree, "", 0, 1, NULL, ls_item); |
144 | ls_tail(); | 145 | ls_tail(); |
145 | } | 146 | } |
146 | 147 | ||
147 | 148 | ||
148 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 149 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
149 | const char *pathname, unsigned mode, int stage) | 150 | const char *pathname, unsigned mode, int stage) |
150 | { | 151 | { |
151 | static int state; | 152 | static int state; |
152 | static char buffer[PATH_MAX]; | 153 | static char buffer[PATH_MAX]; |
153 | char *url; | 154 | char *url; |
154 | 155 | ||
155 | if (state == 0) { | 156 | if (state == 0) { |
156 | memcpy(buffer, base, baselen); | 157 | memcpy(buffer, base, baselen); |
157 | strcpy(buffer+baselen, pathname); | 158 | strcpy(buffer+baselen, pathname); |
158 | url = cgit_pageurl(ctx.qry.repo, "tree", | 159 | url = cgit_pageurl(ctx.qry.repo, "tree", |
159 | fmt("h=%s&path=%s", curr_rev, buffer)); | 160 | fmt("h=%s&path=%s", curr_rev, buffer)); |
160 | html("/"); | 161 | html("/"); |
161 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, | 162 | cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, |
162 | curr_rev, buffer); | 163 | curr_rev, buffer); |
163 | 164 | ||
164 | if (strcmp(match_path, buffer)) | 165 | if (strcmp(match_path, buffer)) |
165 | return READ_TREE_RECURSIVE; | 166 | return READ_TREE_RECURSIVE; |
166 | 167 | ||
167 | if (S_ISDIR(mode)) { | 168 | if (S_ISDIR(mode)) { |
168 | state = 1; | 169 | state = 1; |
169 | ls_head(); | 170 | ls_head(); |
170 | return READ_TREE_RECURSIVE; | 171 | return READ_TREE_RECURSIVE; |
171 | } else { | 172 | } else { |
172 | print_object(sha1, buffer); | 173 | print_object(sha1, buffer); |
173 | return 0; | 174 | return 0; |
174 | } | 175 | } |
175 | } | 176 | } |
176 | ls_item(sha1, base, baselen, pathname, mode, stage); | 177 | ls_item(sha1, base, baselen, pathname, mode, stage); |
177 | return 0; | 178 | return 0; |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
181 | /* | 182 | /* |
182 | * Show a tree or a blob | 183 | * Show a tree or a blob |
183 | * rev: the commit pointing at the root tree object | 184 | * rev: the commit pointing at the root tree object |
184 | * path: path to tree or blob | 185 | * path: path to tree or blob |
185 | */ | 186 | */ |
186 | void cgit_print_tree(const char *rev, char *path) | 187 | void cgit_print_tree(const char *rev, char *path) |
187 | { | 188 | { |
188 | unsigned char sha1[20]; | 189 | unsigned char sha1[20]; |
189 | struct commit *commit; | 190 | struct commit *commit; |
190 | const char *paths[] = {path, NULL}; | 191 | const char *paths[] = {path, NULL}; |
191 | 192 | ||
192 | if (!rev) | 193 | if (!rev) |
193 | rev = ctx.qry.head; | 194 | rev = ctx.qry.head; |
194 | 195 | ||
195 | curr_rev = xstrdup(rev); | 196 | curr_rev = xstrdup(rev); |
196 | if (get_sha1(rev, sha1)) { | 197 | if (get_sha1(rev, sha1)) { |
197 | cgit_print_error(fmt("Invalid revision name: %s", rev)); | 198 | cgit_print_error(fmt("Invalid revision name: %s", rev)); |
198 | return; | 199 | return; |
199 | } | 200 | } |
200 | commit = lookup_commit_reference(sha1); | 201 | commit = lookup_commit_reference(sha1); |
201 | if (!commit || parse_commit(commit)) { | 202 | if (!commit || parse_commit(commit)) { |
202 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); | 203 | cgit_print_error(fmt("Invalid commit reference: %s", rev)); |
203 | return; | 204 | return; |
204 | } | 205 | } |
205 | 206 | ||
206 | html("path: <a href='"); | 207 | html("path: <a href='"); |
207 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); | 208 | html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); |
208 | html("'>root</a>"); | 209 | html("'>root</a>"); |
209 | 210 | ||
210 | if (path == NULL) { | 211 | if (path == NULL) { |
211 | ls_tree(commit->tree->object.sha1, NULL); | 212 | ls_tree(commit->tree->object.sha1, NULL); |
212 | return; | 213 | return; |
213 | } | 214 | } |
214 | 215 | ||
215 | match_path = path; | 216 | match_path = path; |
216 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); | 217 | read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); |
217 | ls_tail(); | 218 | ls_tail(); |
218 | } | 219 | } |