author | Diego Ongaro <ongardie@gmail.com> | 2009-06-10 23:09:55 (UTC) |
---|---|---|
committer | Diego Ongaro <ongardie@gmail.com> | 2009-06-11 05:00:35 (UTC) |
commit | 87a89aed41136d388537b146000c4af6c1135a8c (patch) (unidiff) | |
tree | 2c01ff09a613424ce526922cb130540a04f6ce9d | |
parent | 45e7fcecc1117440e6274ce3c6ab7d893c4986ee (diff) | |
download | cgit-87a89aed41136d388537b146000c4af6c1135a8c.zip cgit-87a89aed41136d388537b146000c4af6c1135a8c.tar.gz cgit-87a89aed41136d388537b146000c4af6c1135a8c.tar.bz2 |
add cgit_httpscheme() -> http:// or https://
-rw-r--r-- | ui-shared.c | 11 | ||||
-rw-r--r-- | ui-shared.h | 1 |
2 files changed, 12 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 | |||
@@ -1,84 +1,95 @@ | |||
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 "cmd.h" | 10 | #include "cmd.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const 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 | ||
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_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 | |||
37 | char *cgit_hosturl() | 48 | char *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 | ||
57 | char *cgit_rooturl() | 68 | char *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); |
61 | else | 72 | else |
62 | return ctx.cfg.script_name; | 73 | return ctx.cfg.script_name; |
63 | } | 74 | } |
64 | 75 | ||
65 | char *cgit_repourl(const char *reponame) | 76 | char *cgit_repourl(const char *reponame) |
66 | { | 77 | { |
67 | if (ctx.cfg.virtual_root) { | 78 | if (ctx.cfg.virtual_root) { |
68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 79 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
69 | } else { | 80 | } else { |
70 | return fmt("?r=%s", reponame); | 81 | return fmt("?r=%s", reponame); |
71 | } | 82 | } |
72 | } | 83 | } |
73 | 84 | ||
74 | char *cgit_fileurl(const char *reponame, const char *pagename, | 85 | char *cgit_fileurl(const char *reponame, const char *pagename, |
75 | const char *filename, const char *query) | 86 | const char *filename, const char *query) |
76 | { | 87 | { |
77 | char *tmp; | 88 | char *tmp; |
78 | char *delim; | 89 | char *delim; |
79 | 90 | ||
80 | if (ctx.cfg.virtual_root) { | 91 | if (ctx.cfg.virtual_root) { |
81 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 92 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
82 | pagename, (filename ? filename:"")); | 93 | pagename, (filename ? filename:"")); |
83 | delim = "?"; | 94 | delim = "?"; |
84 | } else { | 95 | } else { |
diff --git a/ui-shared.h b/ui-shared.h index 5a3821f..bff4826 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -1,49 +1,50 @@ | |||
1 | #ifndef UI_SHARED_H | 1 | #ifndef UI_SHARED_H |
2 | #define UI_SHARED_H | 2 | #define UI_SHARED_H |
3 | 3 | ||
4 | extern char *cgit_httpscheme(); | ||
4 | extern char *cgit_hosturl(); | 5 | extern char *cgit_hosturl(); |
5 | extern char *cgit_repourl(const char *reponame); | 6 | extern char *cgit_repourl(const char *reponame); |
6 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 7 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
7 | const char *filename, const char *query); | 8 | const char *filename, const char *query); |
8 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 9 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
9 | const char *query); | 10 | const char *query); |
10 | 11 | ||
11 | extern void cgit_index_link(char *name, char *title, char *class, | 12 | extern void cgit_index_link(char *name, char *title, char *class, |
12 | char *pattern, int ofs); | 13 | char *pattern, int ofs); |
13 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); | 14 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); |
14 | extern void cgit_tag_link(char *name, char *title, char *class, char *head, | 15 | extern void cgit_tag_link(char *name, char *title, char *class, char *head, |
15 | char *rev); | 16 | char *rev); |
16 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 17 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
17 | char *rev, char *path); | 18 | char *rev, char *path); |
18 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, | 19 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, |
19 | char *rev, char *path); | 20 | char *rev, char *path); |
20 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 21 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
21 | char *rev, char *path, int ofs, char *grep, | 22 | char *rev, char *path, int ofs, char *grep, |
22 | char *pattern, int showmsg); | 23 | char *pattern, int showmsg); |
23 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 24 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
24 | char *rev); | 25 | char *rev); |
25 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, | 26 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, |
26 | char *rev); | 27 | char *rev); |
27 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | 28 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
28 | char *rev, char *path); | 29 | char *rev, char *path); |
29 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 30 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
30 | char *head, char *rev, char *archivename); | 31 | char *head, char *rev, char *archivename); |
31 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 32 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
32 | char *new_rev, char *old_rev, char *path); | 33 | char *new_rev, char *old_rev, char *path); |
33 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, | 34 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, |
34 | char *path); | 35 | char *path); |
35 | extern void cgit_object_link(struct object *obj); | 36 | extern void cgit_object_link(struct object *obj); |
36 | 37 | ||
37 | extern void cgit_print_error(char *msg); | 38 | extern void cgit_print_error(char *msg); |
38 | extern void cgit_print_date(time_t secs, char *format, int local_time); | 39 | extern void cgit_print_date(time_t secs, char *format, int local_time); |
39 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 40 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
40 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 41 | extern void cgit_print_http_headers(struct cgit_context *ctx); |
41 | extern void cgit_print_docstart(struct cgit_context *ctx); | 42 | extern void cgit_print_docstart(struct cgit_context *ctx); |
42 | extern void cgit_print_docend(); | 43 | extern void cgit_print_docend(); |
43 | extern void cgit_print_pageheader(struct cgit_context *ctx); | 44 | extern void cgit_print_pageheader(struct cgit_context *ctx); |
44 | extern void cgit_print_filemode(unsigned short mode); | 45 | extern void cgit_print_filemode(unsigned short mode); |
45 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 46 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
46 | const char *hex, int snapshots); | 47 | const char *hex, int snapshots); |
47 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, | 48 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, |
48 | char *page); | 49 | char *page); |
49 | #endif /* UI_SHARED_H */ | 50 | #endif /* UI_SHARED_H */ |