diff options
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 237 |
1 files changed, 129 insertions, 108 deletions
diff --git a/ui-shared.c b/ui-shared.c index 60aa2e3..aa65988 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | ||
10 | 11 | ||
11 | const char cgit_doctype[] = | 12 | const 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" |
@@ -25,14 +26,6 @@ static char *http_date(time_t t) | |||
25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 26 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
26 | } | 27 | } |
27 | 28 | ||
28 | static long ttl_seconds(long ttl) | ||
29 | { | ||
30 | if (ttl<0) | ||
31 | return 60 * 60 * 24 * 365; | ||
32 | else | ||
33 | return ttl * 60; | ||
34 | } | ||
35 | |||
36 | void cgit_print_error(char *msg) | 29 | void cgit_print_error(char *msg) |
37 | { | 30 | { |
38 | html("<div class='error'>"); | 31 | html("<div class='error'>"); |
@@ -42,16 +35,16 @@ void cgit_print_error(char *msg) | |||
42 | 35 | ||
43 | char *cgit_rooturl() | 36 | char *cgit_rooturl() |
44 | { | 37 | { |
45 | if (cgit_virtual_root) | 38 | if (ctx.cfg.virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 39 | return fmt("%s/", ctx.cfg.virtual_root); |
47 | else | 40 | else |
48 | return cgit_script_name; | 41 | return ctx.cfg.script_name; |
49 | } | 42 | } |
50 | 43 | ||
51 | char *cgit_repourl(const char *reponame) | 44 | char *cgit_repourl(const char *reponame) |
52 | { | 45 | { |
53 | if (cgit_virtual_root) { | 46 | if (ctx.cfg.virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 47 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
55 | } else { | 48 | } else { |
56 | return fmt("?r=%s", reponame); | 49 | return fmt("?r=%s", reponame); |
57 | } | 50 | } |
@@ -63,8 +56,8 @@ char *cgit_fileurl(const char *reponame, const char *pagename, | |||
63 | char *tmp; | 56 | char *tmp; |
64 | char *delim; | 57 | char *delim; |
65 | 58 | ||
66 | if (cgit_virtual_root) { | 59 | if (ctx.cfg.virtual_root) { |
67 | tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame, | 60 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
68 | pagename, (filename ? filename:"")); | 61 | pagename, (filename ? filename:"")); |
69 | delim = "?"; | 62 | delim = "?"; |
70 | } else { | 63 | } else { |
@@ -110,14 +103,14 @@ const char *cgit_repobasename(const char *reponame) | |||
110 | 103 | ||
111 | char *cgit_currurl() | 104 | char *cgit_currurl() |
112 | { | 105 | { |
113 | if (!cgit_virtual_root) | 106 | if (!ctx.cfg.virtual_root) |
114 | return cgit_script_name; | 107 | return ctx.cfg.script_name; |
115 | else if (cgit_query_page) | 108 | else if (ctx.qry.page) |
116 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 109 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
117 | else if (cgit_query_repo) | 110 | else if (ctx.qry.repo) |
118 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 111 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
119 | else | 112 | else |
120 | return fmt("%s/", cgit_virtual_root); | 113 | return fmt("%s/", ctx.cfg.virtual_root); |
121 | } | 114 | } |
122 | 115 | ||
123 | static char *repolink(char *title, char *class, char *page, char *head, | 116 | static char *repolink(char *title, char *class, char *page, char *head, |
@@ -137,12 +130,12 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
137 | html("'"); | 130 | html("'"); |
138 | } | 131 | } |
139 | html(" href='"); | 132 | html(" href='"); |
140 | if (cgit_virtual_root) { | 133 | if (ctx.cfg.virtual_root) { |
141 | html_attr(cgit_virtual_root); | 134 | html_attr(ctx.cfg.virtual_root); |
142 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 135 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 136 | html("/"); |
144 | html_attr(cgit_repo->url); | 137 | html_attr(ctx.repo->url); |
145 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 138 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
146 | html("/"); | 139 | html("/"); |
147 | if (page) { | 140 | if (page) { |
148 | html(page); | 141 | html(page); |
@@ -151,10 +144,10 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
151 | html_attr(path); | 144 | html_attr(path); |
152 | } | 145 | } |
153 | } else { | 146 | } else { |
154 | html(cgit_script_name); | 147 | html(ctx.cfg.script_name); |
155 | html("?url="); | 148 | html("?url="); |
156 | html_attr(cgit_repo->url); | 149 | html_attr(ctx.repo->url); |
157 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 150 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
158 | html("/"); | 151 | html("/"); |
159 | if (page) { | 152 | if (page) { |
160 | html(page); | 153 | html(page); |
@@ -164,7 +157,7 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
164 | } | 157 | } |
165 | delim = "&"; | 158 | delim = "&"; |
166 | } | 159 | } |
167 | if (head && strcmp(head, cgit_repo->defbranch)) { | 160 | if (head && strcmp(head, ctx.repo->defbranch)) { |
168 | html(delim); | 161 | html(delim); |
169 | html("h="); | 162 | html("h="); |
170 | html_attr(head); | 163 | html_attr(head); |
@@ -179,7 +172,7 @@ static void reporevlink(char *page, char *name, char *title, char *class, | |||
179 | char *delim; | 172 | char *delim; |
180 | 173 | ||
181 | delim = repolink(title, class, page, head, path); | 174 | delim = repolink(title, class, page, head, path); |
182 | if (rev && strcmp(rev, cgit_query_head)) { | 175 | if (rev && strcmp(rev, ctx.qry.head)) { |
183 | html(delim); | 176 | html(delim); |
184 | html("id="); | 177 | html("id="); |
185 | html_attr(rev); | 178 | html_attr(rev); |
@@ -201,7 +194,7 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
201 | char *delim; | 194 | char *delim; |
202 | 195 | ||
203 | delim = repolink(title, class, "log", head, path); | 196 | delim = repolink(title, class, "log", head, path); |
204 | if (rev && strcmp(rev, cgit_query_head)) { | 197 | if (rev && strcmp(rev, ctx.qry.head)) { |
205 | html(delim); | 198 | html(delim); |
206 | html("id="); | 199 | html("id="); |
207 | html_attr(rev); | 200 | html_attr(rev); |
@@ -229,11 +222,11 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
229 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 222 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
230 | char *rev) | 223 | char *rev) |
231 | { | 224 | { |
232 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 225 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
233 | name[cgit_max_msg_len] = '\0'; | 226 | name[ctx.cfg.max_msg_len] = '\0'; |
234 | name[cgit_max_msg_len - 1] = '.'; | 227 | name[ctx.cfg.max_msg_len - 1] = '.'; |
235 | name[cgit_max_msg_len - 2] = '.'; | 228 | name[ctx.cfg.max_msg_len - 2] = '.'; |
236 | name[cgit_max_msg_len - 3] = '.'; | 229 | name[ctx.cfg.max_msg_len - 3] = '.'; |
237 | } | 230 | } |
238 | reporevlink("commit", name, title, class, head, rev, NULL); | 231 | reporevlink("commit", name, title, class, head, rev, NULL); |
239 | } | 232 | } |
@@ -256,7 +249,7 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
256 | char *delim; | 249 | char *delim; |
257 | 250 | ||
258 | delim = repolink(title, class, "diff", head, path); | 251 | delim = repolink(title, class, "diff", head, path); |
259 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 252 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
260 | html(delim); | 253 | html(delim); |
261 | html("id="); | 254 | html("id="); |
262 | html_attr(new_rev); | 255 | html_attr(new_rev); |
@@ -284,7 +277,7 @@ void cgit_object_link(struct object *obj) | |||
284 | 277 | ||
285 | if (obj->type == OBJ_COMMIT) { | 278 | if (obj->type == OBJ_COMMIT) { |
286 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 279 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
287 | cgit_query_head, sha1_to_hex(obj->sha1)); | 280 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
288 | return; | 281 | return; |
289 | } else if (obj->type == OBJ_TREE) { | 282 | } else if (obj->type == OBJ_TREE) { |