-rw-r--r-- | ui-shared.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index ca2ee82..5c5bcf3 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,427 +1,433 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
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 | 10 | ||
11 | const char cgit_doctype[] = | 11 | const char cgit_doctype[] = |
12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
14 | 14 | ||
15 | static char *http_date(time_t t) | 15 | static char *http_date(time_t t) |
16 | { | 16 | { |
17 | static char day[][4] = | 17 | static char day[][4] = |
18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
19 | static char month[][4] = | 19 | static char month[][4] = |
20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
22 | struct tm *tm = gmtime(&t); | 22 | struct tm *tm = gmtime(&t); |
23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 25 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
26 | } | 26 | } |
27 | 27 | ||
28 | static long ttl_seconds(long ttl) | 28 | static long ttl_seconds(long ttl) |
29 | { | 29 | { |
30 | if (ttl<0) | 30 | if (ttl<0) |
31 | return 60 * 60 * 24 * 365; | 31 | return 60 * 60 * 24 * 365; |
32 | else | 32 | else |
33 | return ttl * 60; | 33 | return ttl * 60; |
34 | } | 34 | } |
35 | 35 | ||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_fileurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *filename, const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, filename?filename:"", query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | 78 | char *cgit_pageurl(const char *reponame, const char *pagename, |
79 | const char *query) | 79 | const char *query) |
80 | { | 80 | { |
81 | return cgit_fileurl(reponame,pagename,0,query); | 81 | return cgit_fileurl(reponame,pagename,0,query); |
82 | } | 82 | } |
83 | 83 | ||
84 | const char *cgit_repobasename(const char *reponame) | 84 | const char *cgit_repobasename(const char *reponame) |
85 | { | 85 | { |
86 | /* I assume we don't need to store more than one repo basename */ | 86 | /* I assume we don't need to store more than one repo basename */ |
87 | static char rvbuf[1024]; | 87 | static char rvbuf[1024]; |
88 | int p; | 88 | int p; |
89 | const char *rv; | 89 | const char *rv; |
90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
91 | if(rvbuf[sizeof(rvbuf)-1]) | 91 | if(rvbuf[sizeof(rvbuf)-1]) |
92 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 92 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
93 | p = strlen(rvbuf)-1; | 93 | p = strlen(rvbuf)-1; |
94 | /* strip trailing slashes */ | 94 | /* strip trailing slashes */ |
95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
96 | /* strip trailing .git */ | 96 | /* strip trailing .git */ |
97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
98 | p -= 3; rvbuf[p--] = 0; | 98 | p -= 3; rvbuf[p--] = 0; |
99 | } | 99 | } |
100 | /* strip more trailing slashes if any */ | 100 | /* strip more trailing slashes if any */ |
101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
102 | /* find last slash in the remaining string */ | 102 | /* find last slash in the remaining string */ |
103 | rv = strrchr(rvbuf,'/'); | 103 | rv = strrchr(rvbuf,'/'); |
104 | if(rv) | 104 | if(rv) |
105 | return ++rv; | 105 | return ++rv; |
106 | return rvbuf; | 106 | return rvbuf; |
107 | } | 107 | } |
108 | 108 | ||
109 | char *cgit_currurl() | 109 | char *cgit_currurl() |
110 | { | 110 | { |
111 | if (!cgit_virtual_root) | 111 | if (!cgit_virtual_root) |
112 | return cgit_script_name; | 112 | return cgit_script_name; |
113 | else if (cgit_query_page) | 113 | else if (cgit_query_page) |
114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
115 | else if (cgit_query_repo) | 115 | else if (cgit_query_repo) |
116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
117 | else | 117 | else |
118 | return fmt("%s/", cgit_virtual_root); | 118 | return fmt("%s/", cgit_virtual_root); |
119 | } | 119 | } |
120 | 120 | ||
121 | static char *repolink(char *title, char *class, char *page, char *head, | 121 | static char *repolink(char *title, char *class, char *page, char *head, |
122 | char *path) | 122 | char *path) |
123 | { | 123 | { |
124 | char *delim = "?"; | 124 | char *delim = "?"; |
125 | 125 | ||
126 | html("<a"); | 126 | html("<a"); |
127 | if (title) { | 127 | if (title) { |
128 | html(" title='"); | 128 | html(" title='"); |
129 | html_attr(title); | 129 | html_attr(title); |
130 | html("'"); | 130 | html("'"); |
131 | } | 131 | } |
132 | if (class) { | 132 | if (class) { |
133 | html(" class='"); | 133 | html(" class='"); |
134 | html_attr(class); | 134 | html_attr(class); |
135 | html("'"); | 135 | html("'"); |
136 | } | 136 | } |
137 | html(" href='"); | 137 | html(" href='"); |
138 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
139 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
141 | html("/"); | 141 | html("/"); |
142 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | if (page) { | 145 | if (page) { |
146 | html(page); | 146 | html(page); |
147 | html("/"); | 147 | html("/"); |
148 | if (path) | 148 | if (path) |
149 | html_attr(path); | 149 | html_attr(path); |
150 | } | 150 | } |
151 | } else { | 151 | } else { |
152 | html(cgit_script_name); | 152 | html(cgit_script_name); |
153 | html("?url="); | 153 | html("?url="); |
154 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
156 | html("/"); | 156 | html("/"); |
157 | if (page) { | 157 | if (page) { |
158 | html(page); | 158 | html(page); |
159 | html("/"); | 159 | html("/"); |
160 | if (path) | 160 | if (path) |
161 | html_attr(path); | 161 | html_attr(path); |
162 | } | 162 | } |
163 | delim = "&"; | 163 | delim = "&"; |
164 | } | 164 | } |
165 | if (head && strcmp(head, cgit_repo->defbranch)) { | 165 | if (head && strcmp(head, cgit_repo->defbranch)) { |
166 | html(delim); | 166 | html(delim); |
167 | html("h="); | 167 | html("h="); |
168 | html_attr(head); | 168 | html_attr(head); |
169 | delim = "&"; | 169 | delim = "&"; |
170 | } | 170 | } |
171 | return fmt("%s", delim); | 171 | return fmt("%s", delim); |
172 | } | 172 | } |
173 | 173 | ||
174 | static void reporevlink(char *page, char *name, char *title, char *class, | 174 | static void reporevlink(char *page, char *name, char *title, char *class, |
175 | char *head, char *rev, char *path) | 175 | char *head, char *rev, char *path) |
176 | { | 176 | { |
177 | char *delim; | 177 | char *delim; |
178 | 178 | ||
179 | delim = repolink(title, class, page, head, path); | 179 | delim = repolink(title, class, page, head, path); |
180 | if (rev && strcmp(rev, cgit_query_head)) { | 180 | if (rev && strcmp(rev, cgit_query_head)) { |
181 | html(delim); | 181 | html(delim); |
182 | html("id="); | 182 | html("id="); |
183 | html_attr(rev); | 183 | html_attr(rev); |
184 | } | 184 | } |
185 | html("'>"); | 185 | html("'>"); |
186 | html_txt(name); | 186 | html_txt(name); |
187 | html("</a>"); | 187 | html("</a>"); |
188 | } | 188 | } |
189 | 189 | ||
190 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 190 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
191 | char *rev, char *path) | 191 | char *rev, char *path) |
192 | { | 192 | { |
193 | reporevlink("tree", name, title, class, head, rev, path); | 193 | reporevlink("tree", name, title, class, head, rev, path); |
194 | } | 194 | } |
195 | 195 | ||
196 | void cgit_log_link(char *name, char *title, char *class, char *head, | 196 | void cgit_log_link(char *name, char *title, char *class, char *head, |
197 | char *rev, char *path, int ofs) | 197 | char *rev, char *path, int ofs) |
198 | { | 198 | { |
199 | char *delim; | 199 | char *delim; |
200 | 200 | ||
201 | delim = repolink(title, class, "log", head, path); | 201 | delim = repolink(title, class, "log", head, path); |
202 | if (rev && strcmp(rev, cgit_query_head)) { | 202 | if (rev && strcmp(rev, cgit_query_head)) { |
203 | html(delim); | 203 | html(delim); |
204 | html("id="); | 204 | html("id="); |
205 | html_attr(rev); | 205 | html_attr(rev); |
206 | delim = "&"; | 206 | delim = "&"; |
207 | } | 207 | } |
208 | if (ofs > 0) { | 208 | if (ofs > 0) { |
209 | html(delim); | 209 | html(delim); |
210 | html("ofs="); | 210 | html("ofs="); |
211 | htmlf("%d", ofs); | 211 | htmlf("%d", ofs); |
212 | } | 212 | } |
213 | html("'>"); | 213 | html("'>"); |
214 | html_txt(name); | 214 | html_txt(name); |
215 | html("</a>"); | 215 | html("</a>"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 218 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
219 | char *rev) | 219 | char *rev) |
220 | { | 220 | { |
221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
222 | name[cgit_max_msg_len] = '\0'; | 222 | name[cgit_max_msg_len] = '\0'; |
223 | name[cgit_max_msg_len - 1] = '.'; | 223 | name[cgit_max_msg_len - 1] = '.'; |
224 | name[cgit_max_msg_len - 2] = '.'; | 224 | name[cgit_max_msg_len - 2] = '.'; |
225 | name[cgit_max_msg_len - 3] = '.'; | 225 | name[cgit_max_msg_len - 3] = '.'; |
226 | } | 226 | } |
227 | reporevlink("commit", name, title, class, head, rev, NULL); | 227 | reporevlink("commit", name, title, class, head, rev, NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | ||
231 | char *rev, char *archivename) | ||
232 | { | ||
233 | reporevlink("snapshot", name, title, class, head, rev, archivename); | ||
234 | } | ||
235 | |||
230 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 236 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
231 | char *new_rev, char *old_rev, char *path) | 237 | char *new_rev, char *old_rev, char *path) |
232 | { | 238 | { |
233 | char *delim; | 239 | char *delim; |
234 | 240 | ||
235 | delim = repolink(title, class, "diff", head, path); | 241 | delim = repolink(title, class, "diff", head, path); |
236 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 242 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
237 | html(delim); | 243 | html(delim); |
238 | html("id="); | 244 | html("id="); |
239 | html_attr(new_rev); | 245 | html_attr(new_rev); |
240 | delim = "&"; | 246 | delim = "&"; |
241 | } | 247 | } |
242 | if (old_rev) { | 248 | if (old_rev) { |
243 | html(delim); | 249 | html(delim); |
244 | html("id2="); | 250 | html("id2="); |
245 | html_attr(old_rev); | 251 | html_attr(old_rev); |
246 | } | 252 | } |
247 | html("'>"); | 253 | html("'>"); |
248 | html_txt(name); | 254 | html_txt(name); |
249 | html("</a>"); | 255 | html("</a>"); |
250 | } | 256 | } |
251 | 257 | ||
252 | void cgit_object_link(struct object *obj) | 258 | void cgit_object_link(struct object *obj) |
253 | { | 259 | { |
254 | char *page, *arg, *url; | 260 | char *page, *arg, *url; |
255 | 261 | ||
256 | if (obj->type == OBJ_COMMIT) { | 262 | if (obj->type == OBJ_COMMIT) { |
257 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 263 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
258 | cgit_query_head, sha1_to_hex(obj->sha1)); | 264 | cgit_query_head, sha1_to_hex(obj->sha1)); |
259 | return; | 265 | return; |
260 | } else if (obj->type == OBJ_TREE) { | 266 | } else if (obj->type == OBJ_TREE) { |
261 | page = "tree"; | 267 | page = "tree"; |
262 | arg = "id"; | 268 | arg = "id"; |
263 | } else { | 269 | } else { |
264 | page = "blob"; | 270 | page = "blob"; |
265 | arg = "id"; | 271 | arg = "id"; |
266 | } | 272 | } |
267 | 273 | ||
268 | url = cgit_pageurl(cgit_query_repo, page, | 274 | url = cgit_pageurl(cgit_query_repo, page, |
269 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 275 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
270 | html_link_open(url, NULL, NULL); | 276 | html_link_open(url, NULL, NULL); |
271 | htmlf("%s %s", typename(obj->type), | 277 | htmlf("%s %s", typename(obj->type), |
272 | sha1_to_hex(obj->sha1)); | 278 | sha1_to_hex(obj->sha1)); |
273 | html_link_close(); | 279 | html_link_close(); |
274 | } | 280 | } |
275 | 281 | ||
276 | void cgit_print_date(time_t secs, char *format) | 282 | void cgit_print_date(time_t secs, char *format) |
277 | { | 283 | { |
278 | char buf[64]; | 284 | char buf[64]; |
279 | struct tm *time; | 285 | struct tm *time; |
280 | 286 | ||
281 | time = gmtime(&secs); | 287 | time = gmtime(&secs); |
282 | strftime(buf, sizeof(buf)-1, format, time); | 288 | strftime(buf, sizeof(buf)-1, format, time); |
283 | html_txt(buf); | 289 | html_txt(buf); |
284 | } | 290 | } |
285 | 291 | ||
286 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 292 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
287 | { | 293 | { |
288 | time_t now, secs; | 294 | time_t now, secs; |
289 | 295 | ||
290 | time(&now); | 296 | time(&now); |
291 | secs = now - t; | 297 | secs = now - t; |
292 | 298 | ||
293 | if (secs > max_relative && max_relative >= 0) { | 299 | if (secs > max_relative && max_relative >= 0) { |
294 | cgit_print_date(t, format); | 300 | cgit_print_date(t, format); |
295 | return; | 301 | return; |
296 | } | 302 | } |
297 | 303 | ||
298 | if (secs < TM_HOUR * 2) { | 304 | if (secs < TM_HOUR * 2) { |
299 | htmlf("<span class='age-mins'>%.0f min.</span>", | 305 | htmlf("<span class='age-mins'>%.0f min.</span>", |
300 | secs * 1.0 / TM_MIN); | 306 | secs * 1.0 / TM_MIN); |
301 | return; | 307 | return; |
302 | } | 308 | } |
303 | if (secs < TM_DAY * 2) { | 309 | if (secs < TM_DAY * 2) { |
304 | htmlf("<span class='age-hours'>%.0f hours</span>", | 310 | htmlf("<span class='age-hours'>%.0f hours</span>", |
305 | secs * 1.0 / TM_HOUR); | 311 | secs * 1.0 / TM_HOUR); |
306 | return; | 312 | return; |
307 | } | 313 | } |
308 | if (secs < TM_WEEK * 2) { | 314 | if (secs < TM_WEEK * 2) { |
309 | htmlf("<span class='age-days'>%.0f days</span>", | 315 | htmlf("<span class='age-days'>%.0f days</span>", |
310 | secs * 1.0 / TM_DAY); | 316 | secs * 1.0 / TM_DAY); |
311 | return; | 317 | return; |
312 | } | 318 | } |
313 | if (secs < TM_MONTH * 2) { | 319 | if (secs < TM_MONTH * 2) { |
314 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 320 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
315 | secs * 1.0 / TM_WEEK); | 321 | secs * 1.0 / TM_WEEK); |
316 | return; | 322 | return; |
317 | } | 323 | } |
318 | if (secs < TM_YEAR * 2) { | 324 | if (secs < TM_YEAR * 2) { |
319 | htmlf("<span class='age-months'>%.0f months</span>", | 325 | htmlf("<span class='age-months'>%.0f months</span>", |
320 | secs * 1.0 / TM_MONTH); | 326 | secs * 1.0 / TM_MONTH); |
321 | return; | 327 | return; |
322 | } | 328 | } |
323 | htmlf("<span class='age-years'>%.0f years</span>", | 329 | htmlf("<span class='age-years'>%.0f years</span>", |
324 | secs * 1.0 / TM_YEAR); | 330 | secs * 1.0 / TM_YEAR); |
325 | } | 331 | } |
326 | 332 | ||
327 | void cgit_print_docstart(char *title, struct cacheitem *item) | 333 | void cgit_print_docstart(char *title, struct cacheitem *item) |
328 | { | 334 | { |
329 | html("Content-Type: text/html; charset=utf-8\n"); | 335 | html("Content-Type: text/html; charset=utf-8\n"); |
330 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 336 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
331 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 337 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
332 | ttl_seconds(item->ttl))); | 338 | ttl_seconds(item->ttl))); |
333 | html("\n"); | 339 | html("\n"); |
334 | html(cgit_doctype); | 340 | html(cgit_doctype); |
335 | html("<html>\n"); | 341 | html("<html>\n"); |
336 | html("<head>\n"); | 342 | html("<head>\n"); |
337 | html("<title>"); | 343 | html("<title>"); |
338 | html_txt(title); | 344 | html_txt(title); |
339 | html("</title>\n"); | 345 | html("</title>\n"); |
340 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 346 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
341 | html("<link rel='stylesheet' type='text/css' href='"); | 347 | html("<link rel='stylesheet' type='text/css' href='"); |
342 | html_attr(cgit_css); | 348 | html_attr(cgit_css); |
343 | html("'/>\n"); | 349 | html("'/>\n"); |
344 | html("</head>\n"); | 350 | html("</head>\n"); |
345 | html("<body>\n"); | 351 | html("<body>\n"); |
346 | } | 352 | } |
347 | 353 | ||
348 | void cgit_print_docend() | 354 | void cgit_print_docend() |
349 | { | 355 | { |
350 | html("</td></tr></table>"); | 356 | html("</td></tr></table>"); |
351 | html("</body>\n</html>\n"); | 357 | html("</body>\n</html>\n"); |
352 | } | 358 | } |
353 | 359 | ||
354 | void cgit_print_pageheader(char *title, int show_search) | 360 | void cgit_print_pageheader(char *title, int show_search) |
355 | { | 361 | { |
356 | html("<table id='layout'>"); | 362 | html("<table id='layout'>"); |
357 | html("<tr><td id='header'><a href='"); | 363 | html("<tr><td id='header'><a href='"); |
358 | html_attr(cgit_rooturl()); | 364 | html_attr(cgit_rooturl()); |
359 | html("'>"); | 365 | html("'>"); |
360 | html_txt(cgit_root_title); | 366 | html_txt(cgit_root_title); |
361 | html("</a></td><td id='logo'>"); | 367 | html("</a></td><td id='logo'>"); |
362 | html("<a href='"); | 368 | html("<a href='"); |
363 | html_attr(cgit_logo_link); | 369 | html_attr(cgit_logo_link); |
364 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 370 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
365 | html("</td></tr>"); | 371 | html("</td></tr>"); |
366 | html("<tr><td id='crumb'>"); | 372 | html("<tr><td id='crumb'>"); |
367 | if (cgit_query_repo) { | 373 | if (cgit_query_repo) { |
368 | html_txt(cgit_repo->name); | 374 | html_txt(cgit_repo->name); |
369 | html(" ("); | 375 | html(" ("); |
370 | html_txt(cgit_query_head); | 376 | html_txt(cgit_query_head); |
371 | html(") : "); | 377 | html(") : "); |
372 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, | 378 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, |
373 | NULL, NULL); | 379 | NULL, NULL); |
374 | html(" "); | 380 | html(" "); |
375 | cgit_log_link("log", NULL, NULL, cgit_query_head, | 381 | cgit_log_link("log", NULL, NULL, cgit_query_head, |
376 | cgit_query_sha1, cgit_query_path, 0); | 382 | cgit_query_sha1, cgit_query_path, 0); |
377 | html(" "); | 383 | html(" "); |
378 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, | 384 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, |
379 | cgit_query_sha1, NULL); | 385 | cgit_query_sha1, NULL); |
380 | html(" "); | 386 | html(" "); |
381 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, | 387 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, |
382 | cgit_query_sha1); | 388 | cgit_query_sha1); |
383 | html(" "); | 389 | html(" "); |
384 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, | 390 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, |
385 | cgit_query_sha1, cgit_query_sha2, | 391 | cgit_query_sha1, cgit_query_sha2, |
386 | cgit_query_path); | 392 | cgit_query_path); |
387 | } else { | 393 | } else { |
388 | html_txt("Index of repositories"); | 394 | html_txt("Index of repositories"); |
389 | } | 395 | } |
390 | html("</td>"); | 396 | html("</td>"); |
391 | html("<td id='search'>"); | 397 | html("<td id='search'>"); |
392 | if (show_search) { | 398 | if (show_search) { |
393 | html("<form method='get' action='"); | 399 | html("<form method='get' action='"); |
394 | html_attr(cgit_currurl()); | 400 | html_attr(cgit_currurl()); |
395 | html("'>"); | 401 | html("'>"); |
396 | if (!cgit_virtual_root) { | 402 | if (!cgit_virtual_root) { |
397 | if (cgit_query_repo) | 403 | if (cgit_query_repo) |
398 | html_hidden("r", cgit_query_repo); | 404 | html_hidden("r", cgit_query_repo); |
399 | if (cgit_query_page) | 405 | if (cgit_query_page) |
400 | html_hidden("p", cgit_query_page); | 406 | html_hidden("p", cgit_query_page); |
401 | } | 407 | } |
402 | if (cgit_query_head) | 408 | if (cgit_query_head) |
403 | html_hidden("h", cgit_query_head); | 409 | html_hidden("h", cgit_query_head); |
404 | if (cgit_query_sha1) | 410 | if (cgit_query_sha1) |
405 | html_hidden("id", cgit_query_sha1); | 411 | html_hidden("id", cgit_query_sha1); |
406 | if (cgit_query_sha2) | 412 | if (cgit_query_sha2) |
407 | html_hidden("id2", cgit_query_sha2); | 413 | html_hidden("id2", cgit_query_sha2); |
408 | html("<input type='text' name='q' value='"); | 414 | html("<input type='text' name='q' value='"); |
409 | html_attr(cgit_query_search); | 415 | html_attr(cgit_query_search); |
410 | html("'/></form>"); | 416 | html("'/></form>"); |
411 | } | 417 | } |
412 | html("</td></tr>"); | 418 | html("</td></tr>"); |
413 | html("<tr><td id='content' colspan='2'>"); | 419 | html("<tr><td id='content' colspan='2'>"); |
414 | } | 420 | } |
415 | 421 | ||
416 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 422 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
417 | struct cacheitem *item) | 423 | struct cacheitem *item) |
418 | { | 424 | { |
419 | htmlf("Content-Type: %s\n", mimetype); | 425 | htmlf("Content-Type: %s\n", mimetype); |
420 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 426 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
421 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 427 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
422 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 428 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
423 | ttl_seconds(item->ttl))); | 429 | ttl_seconds(item->ttl))); |
424 | html("\n"); | 430 | html("\n"); |
425 | } | 431 | } |
426 | 432 | ||
427 | /* vim:set sw=8: */ | 433 | /* vim:set sw=8: */ |