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,164 +1,175 @@ | |||
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 { |
85 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 96 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
86 | (filename ? filename : "")); | 97 | (filename ? filename : "")); |
87 | delim = "&"; | 98 | delim = "&"; |
88 | } | 99 | } |
89 | if (query) | 100 | if (query) |
90 | tmp = fmt("%s%s%s", tmp, delim, query); | 101 | tmp = fmt("%s%s%s", tmp, delim, query); |
91 | return tmp; | 102 | return tmp; |
92 | } | 103 | } |
93 | 104 | ||
94 | char *cgit_pageurl(const char *reponame, const char *pagename, | 105 | char *cgit_pageurl(const char *reponame, const char *pagename, |
95 | const char *query) | 106 | const char *query) |
96 | { | 107 | { |
97 | return cgit_fileurl(reponame,pagename,0,query); | 108 | return cgit_fileurl(reponame,pagename,0,query); |
98 | } | 109 | } |
99 | 110 | ||
100 | const char *cgit_repobasename(const char *reponame) | 111 | const char *cgit_repobasename(const char *reponame) |
101 | { | 112 | { |
102 | /* I assume we don't need to store more than one repo basename */ | 113 | /* I assume we don't need to store more than one repo basename */ |
103 | static char rvbuf[1024]; | 114 | static char rvbuf[1024]; |
104 | int p; | 115 | int p; |
105 | const char *rv; | 116 | const char *rv; |
106 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 117 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
107 | if(rvbuf[sizeof(rvbuf)-1]) | 118 | if(rvbuf[sizeof(rvbuf)-1]) |
108 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 119 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
109 | p = strlen(rvbuf)-1; | 120 | p = strlen(rvbuf)-1; |
110 | /* strip trailing slashes */ | 121 | /* strip trailing slashes */ |
111 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 122 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
112 | /* strip trailing .git */ | 123 | /* strip trailing .git */ |
113 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 124 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
114 | p -= 3; rvbuf[p--] = 0; | 125 | p -= 3; rvbuf[p--] = 0; |
115 | } | 126 | } |
116 | /* strip more trailing slashes if any */ | 127 | /* strip more trailing slashes if any */ |
117 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 128 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
118 | /* find last slash in the remaining string */ | 129 | /* find last slash in the remaining string */ |
119 | rv = strrchr(rvbuf,'/'); | 130 | rv = strrchr(rvbuf,'/'); |
120 | if(rv) | 131 | if(rv) |
121 | return ++rv; | 132 | return ++rv; |
122 | return rvbuf; | 133 | return rvbuf; |
123 | } | 134 | } |
124 | 135 | ||
125 | char *cgit_currurl() | 136 | char *cgit_currurl() |
126 | { | 137 | { |
127 | if (!ctx.cfg.virtual_root) | 138 | if (!ctx.cfg.virtual_root) |
128 | return ctx.cfg.script_name; | 139 | return ctx.cfg.script_name; |
129 | else if (ctx.qry.page) | 140 | else if (ctx.qry.page) |
130 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 141 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
131 | else if (ctx.qry.repo) | 142 | else if (ctx.qry.repo) |
132 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 143 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
133 | else | 144 | else |
134 | return fmt("%s/", ctx.cfg.virtual_root); | 145 | return fmt("%s/", ctx.cfg.virtual_root); |
135 | } | 146 | } |
136 | 147 | ||
137 | static void site_url(char *page, char *search, int ofs) | 148 | static void site_url(char *page, char *search, int ofs) |
138 | { | 149 | { |
139 | char *delim = "?"; | 150 | char *delim = "?"; |
140 | 151 | ||
141 | if (ctx.cfg.virtual_root) { | 152 | if (ctx.cfg.virtual_root) { |
142 | html_attr(ctx.cfg.virtual_root); | 153 | html_attr(ctx.cfg.virtual_root); |
143 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 154 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
144 | html("/"); | 155 | html("/"); |
145 | } else | 156 | } else |
146 | html(ctx.cfg.script_name); | 157 | html(ctx.cfg.script_name); |
147 | 158 | ||
148 | if (page) { | 159 | if (page) { |
149 | htmlf("?p=%s", page); | 160 | htmlf("?p=%s", page); |
150 | delim = "&"; | 161 | delim = "&"; |
151 | } | 162 | } |
152 | if (search) { | 163 | if (search) { |
153 | html(delim); | 164 | html(delim); |
154 | html("q="); | 165 | html("q="); |
155 | html_attr(search); | 166 | html_attr(search); |
156 | delim = "&"; | 167 | delim = "&"; |
157 | } | 168 | } |
158 | if (ofs) { | 169 | if (ofs) { |
159 | html(delim); | 170 | html(delim); |
160 | htmlf("ofs=%d", ofs); | 171 | htmlf("ofs=%d", ofs); |
161 | } | 172 | } |
162 | } | 173 | } |
163 | 174 | ||
164 | static void site_link(char *page, char *name, char *title, char *class, | 175 | static void site_link(char *page, char *name, char *title, char *class, |
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 */ |