-rw-r--r-- | ui-shared.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ui-shared.c b/ui-shared.c index 4818e70..c23bc75 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -17,56 +17,61 @@ const char cgit_doctype[] = | |||
17 | static char *http_date(time_t t) | 17 | static 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 | ||
30 | void cgit_print_error(char *msg) | 30 | void 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 | ||
37 | char *cgit_hosturl() | 37 | char *cgit_hosturl() |
38 | { | 38 | { |
39 | char *host, *port; | 39 | char *host, *port; |
40 | 40 | ||
41 | host = getenv("SERVER_NAME"); | 41 | host = getenv("HTTP_HOST"); |
42 | if (!host) | 42 | if (host) { |
43 | return NULL; | ||
44 | port = getenv("SERVER_PORT"); | ||
45 | if (port && atoi(port) != 80) | ||
46 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | ||
47 | else | ||
48 | host = xstrdup(host); | 43 | host = xstrdup(host); |
44 | } else { | ||
45 | host = getenv("SERVER_NAME"); | ||
46 | if (!host) | ||
47 | return NULL; | ||
48 | port = getenv("SERVER_PORT"); | ||
49 | if (port && atoi(port) != 80) | ||
50 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | ||
51 | else | ||
52 | host = xstrdup(host); | ||
53 | } | ||
49 | return host; | 54 | return host; |
50 | } | 55 | } |
51 | 56 | ||
52 | char *cgit_rooturl() | 57 | char *cgit_rooturl() |
53 | { | 58 | { |
54 | if (ctx.cfg.virtual_root) | 59 | if (ctx.cfg.virtual_root) |
55 | return fmt("%s/", ctx.cfg.virtual_root); | 60 | return fmt("%s/", ctx.cfg.virtual_root); |
56 | else | 61 | else |
57 | return ctx.cfg.script_name; | 62 | return ctx.cfg.script_name; |
58 | } | 63 | } |
59 | 64 | ||
60 | char *cgit_repourl(const char *reponame) | 65 | char *cgit_repourl(const char *reponame) |
61 | { | 66 | { |
62 | if (ctx.cfg.virtual_root) { | 67 | if (ctx.cfg.virtual_root) { |
63 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
64 | } else { | 69 | } else { |
65 | return fmt("?r=%s", reponame); | 70 | return fmt("?r=%s", reponame); |
66 | } | 71 | } |
67 | } | 72 | } |
68 | 73 | ||
69 | char *cgit_fileurl(const char *reponame, const char *pagename, | 74 | char *cgit_fileurl(const char *reponame, const char *pagename, |
70 | const char *filename, const char *query) | 75 | const char *filename, const char *query) |
71 | { | 76 | { |
72 | char *tmp; | 77 | char *tmp; |