summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index cc1ab8b..2eff79d 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,41 +1,42 @@
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#include "html.h"
10 11
11const char cgit_doctype[] = 12const char cgit_doctype[] =
12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 13"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 14" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
14 15
15static char *http_date(time_t t) 16static char *http_date(time_t t)
16{ 17{
17 static char day[][4] = 18 static char day[][4] =
18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 19 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
19 static char month[][4] = 20 static char month[][4] =
20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 21 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 22 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
22 struct tm *tm = gmtime(&t); 23 struct tm *tm = gmtime(&t);
23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 24 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, 25 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
25 tm->tm_hour, tm->tm_min, tm->tm_sec); 26 tm->tm_hour, tm->tm_min, tm->tm_sec);
26} 27}
27 28
28static long ttl_seconds(long ttl) 29static long ttl_seconds(long ttl)
29{ 30{
30 if (ttl<0) 31 if (ttl<0)
31 return 60 * 60 * 24 * 365; 32 return 60 * 60 * 24 * 365;
32 else 33 else
33 return ttl * 60; 34 return ttl * 60;
34} 35}
35 36
36void cgit_print_error(char *msg) 37void cgit_print_error(char *msg)
37{ 38{
38 html("<div class='error'>"); 39 html("<div class='error'>");
39 html_txt(msg); 40 html_txt(msg);
40 html("</div>\n"); 41 html("</div>\n");
41} 42}
@@ -538,33 +539,48 @@ void cgit_print_pageheader(char *title, int show_search)
538 add_hidden_formfields(1, 0, "log"); 539 add_hidden_formfields(1, 0, "log");
539 html("<select name='qt'>\n"); 540 html("<select name='qt'>\n");
540 html_option("grep", "log msg", ctx.qry.grep); 541 html_option("grep", "log msg", ctx.qry.grep);
541 html_option("author", "author", ctx.qry.grep); 542 html_option("author", "author", ctx.qry.grep);
542 html_option("committer", "committer", ctx.qry.grep); 543 html_option("committer", "committer", ctx.qry.grep);
543 html("</select>\n"); 544 html("</select>\n");
544 html("<input class='txt' type='text' name='q' value='"); 545 html("<input class='txt' type='text' name='q' value='");
545 html_attr(ctx.qry.search); 546 html_attr(ctx.qry.search);
546 html("'/>\n"); 547 html("'/>\n");
547 html("</form>\n"); 548 html("</form>\n");
548 } else { 549 } else {
549 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) 550 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info))
550 html(default_info); 551 html(default_info);
551 } 552 }
552 553
553 html("</td></tr></table></td>\n"); 554 html("</td></tr></table></td>\n");
554 555
555 html("<td id='content'>\n"); 556 html("<td id='content'>\n");
556} 557}
557 558
558 559
559void cgit_print_snapshot_start(const char *mimetype, const char *filename, 560void cgit_print_snapshot_start(const char *mimetype, const char *filename,
560 struct cacheitem *item) 561 struct cacheitem *item)
561{ 562{
562 htmlf("Content-Type: %s\n", mimetype); 563 htmlf("Content-Type: %s\n", mimetype);
563 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 564 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
564 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 565 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
565 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 566 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
566 ttl_seconds(item->ttl))); 567 ttl_seconds(item->ttl)));
567 html("\n"); 568 html("\n");
568} 569}
569 570
571void cgit_print_filemode(unsigned short mode)
572{
573 if (S_ISDIR(mode))
574 html("d");
575 else if (S_ISLNK(mode))
576 html("l");
577 else if (S_ISGITLINK(mode))
578 html("m");
579 else
580 html("-");
581 html_fileperm(mode >> 6);
582 html_fileperm(mode >> 3);
583 html_fileperm(mode);
584}
585
570/* vim:set sw=8: */ 586/* vim:set sw=8: */