summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorDiego Ongaro <ongardie@gmail.com>2009-06-10 23:09:55 (UTC)
committer Diego Ongaro <ongardie@gmail.com>2009-06-11 05:00:35 (UTC)
commit87a89aed41136d388537b146000c4af6c1135a8c (patch) (unidiff)
tree2c01ff09a613424ce526922cb130540a04f6ce9d /ui-shared.c
parent45e7fcecc1117440e6274ce3c6ab7d893c4986ee (diff)
downloadcgit-87a89aed41136d388537b146000c4af6c1135a8c.zip
cgit-87a89aed41136d388537b146000c4af6c1135a8c.tar.gz
cgit-87a89aed41136d388537b146000c4af6c1135a8c.tar.bz2
add cgit_httpscheme() -> http:// or https://
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index de77bbf..749ea35 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -13,48 +13,59 @@
13const char cgit_doctype[] = 13const char cgit_doctype[] =
14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
16 16
17static char *http_date(time_t t) 17static char *http_date(time_t t)
18{ 18{
19 static char day[][4] = 19 static char day[][4] =
20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
21 static char month[][4] = 21 static char month[][4] =
22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
24 struct tm *tm = gmtime(&t); 24 struct tm *tm = gmtime(&t);
25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
27 tm->tm_hour, tm->tm_min, tm->tm_sec); 27 tm->tm_hour, tm->tm_min, tm->tm_sec);
28} 28}
29 29
30void cgit_print_error(char *msg) 30void cgit_print_error(char *msg)
31{ 31{
32 html("<div class='error'>"); 32 html("<div class='error'>");
33 html_txt(msg); 33 html_txt(msg);
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_httpscheme()
38{
39 char *https;
40
41 https = getenv("HTTPS");
42 if (https != NULL && strcmp(https, "on") == 0)
43 return "https://";
44 else
45 return "http://";
46}
47
37char *cgit_hosturl() 48char *cgit_hosturl()
38{ 49{
39 char *host, *port; 50 char *host, *port;
40 51
41 host = getenv("HTTP_HOST"); 52 host = getenv("HTTP_HOST");
42 if (host) { 53 if (host) {
43 host = xstrdup(host); 54 host = xstrdup(host);
44 } else { 55 } else {
45 host = getenv("SERVER_NAME"); 56 host = getenv("SERVER_NAME");
46 if (!host) 57 if (!host)
47 return NULL; 58 return NULL;
48 port = getenv("SERVER_PORT"); 59 port = getenv("SERVER_PORT");
49 if (port && atoi(port) != 80) 60 if (port && atoi(port) != 80)
50 host = xstrdup(fmt("%s:%d", host, atoi(port))); 61 host = xstrdup(fmt("%s:%d", host, atoi(port)));
51 else 62 else
52 host = xstrdup(host); 63 host = xstrdup(host);
53 } 64 }
54 return host; 65 return host;
55} 66}
56 67
57char *cgit_rooturl() 68char *cgit_rooturl()
58{ 69{
59 if (ctx.cfg.virtual_root) 70 if (ctx.cfg.virtual_root)
60 return fmt("%s/", ctx.cfg.virtual_root); 71 return fmt("%s/", ctx.cfg.virtual_root);