-rw-r--r-- | html.c | 16 | ||||
-rw-r--r-- | html.h | 1 | ||||
-rw-r--r-- | ui-repolist.c | 8 | ||||
-rw-r--r-- | ui-shared.c | 20 | ||||
-rw-r--r-- | ui-shared.h | 1 |
5 files changed, 32 insertions, 14 deletions
@@ -1,273 +1,289 @@ | |||
1 | /* html.c: helper functions for html output | 1 | /* html.c: helper functions for html output |
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 <unistd.h> | 9 | #include <unistd.h> |
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <stdarg.h> | 12 | #include <stdarg.h> |
13 | #include <string.h> | 13 | #include <string.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | int htmlfd = STDOUT_FILENO; | 16 | int htmlfd = STDOUT_FILENO; |
17 | 17 | ||
18 | char *fmt(const char *format, ...) | 18 | char *fmt(const char *format, ...) |
19 | { | 19 | { |
20 | static char buf[8][1024]; | 20 | static char buf[8][1024]; |
21 | static int bufidx; | 21 | static int bufidx; |
22 | int len; | 22 | int len; |
23 | va_list args; | 23 | va_list args; |
24 | 24 | ||
25 | bufidx++; | 25 | bufidx++; |
26 | bufidx &= 7; | 26 | bufidx &= 7; |
27 | 27 | ||
28 | va_start(args, format); | 28 | va_start(args, format); |
29 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 29 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
30 | va_end(args); | 30 | va_end(args); |
31 | if (len>sizeof(buf[bufidx])) { | 31 | if (len>sizeof(buf[bufidx])) { |
32 | fprintf(stderr, "[html.c] string truncated: %s\n", format); | 32 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
33 | exit(1); | 33 | exit(1); |
34 | } | 34 | } |
35 | return buf[bufidx]; | 35 | return buf[bufidx]; |
36 | } | 36 | } |
37 | 37 | ||
38 | void html_raw(const char *data, size_t size) | 38 | void html_raw(const char *data, size_t size) |
39 | { | 39 | { |
40 | write(htmlfd, data, size); | 40 | write(htmlfd, data, size); |
41 | } | 41 | } |
42 | 42 | ||
43 | void html(const char *txt) | 43 | void html(const char *txt) |
44 | { | 44 | { |
45 | write(htmlfd, txt, strlen(txt)); | 45 | write(htmlfd, txt, strlen(txt)); |
46 | } | 46 | } |
47 | 47 | ||
48 | void htmlf(const char *format, ...) | 48 | void htmlf(const char *format, ...) |
49 | { | 49 | { |
50 | static char buf[65536]; | 50 | static char buf[65536]; |
51 | va_list args; | 51 | va_list args; |
52 | 52 | ||
53 | va_start(args, format); | 53 | va_start(args, format); |
54 | vsnprintf(buf, sizeof(buf), format, args); | 54 | vsnprintf(buf, sizeof(buf), format, args); |
55 | va_end(args); | 55 | va_end(args); |
56 | html(buf); | 56 | html(buf); |
57 | } | 57 | } |
58 | 58 | ||
59 | void html_status(int code, const char *msg, int more_headers) | 59 | void html_status(int code, const char *msg, int more_headers) |
60 | { | 60 | { |
61 | htmlf("Status: %d %s\n", code, msg); | 61 | htmlf("Status: %d %s\n", code, msg); |
62 | if (!more_headers) | 62 | if (!more_headers) |
63 | html("\n"); | 63 | html("\n"); |
64 | } | 64 | } |
65 | 65 | ||
66 | void html_txt(char *txt) | 66 | void html_txt(char *txt) |
67 | { | 67 | { |
68 | char *t = txt; | 68 | char *t = txt; |
69 | while(t && *t){ | 69 | while(t && *t){ |
70 | int c = *t; | 70 | int c = *t; |
71 | if (c=='<' || c=='>' || c=='&') { | 71 | if (c=='<' || c=='>' || c=='&') { |
72 | write(htmlfd, txt, t - txt); | 72 | write(htmlfd, txt, t - txt); |
73 | if (c=='>') | 73 | if (c=='>') |
74 | html(">"); | 74 | html(">"); |
75 | else if (c=='<') | 75 | else if (c=='<') |
76 | html("<"); | 76 | html("<"); |
77 | else if (c=='&') | 77 | else if (c=='&') |
78 | html("&"); | 78 | html("&"); |
79 | txt = t+1; | 79 | txt = t+1; |
80 | } | 80 | } |
81 | t++; | 81 | t++; |
82 | } | 82 | } |
83 | if (t!=txt) | 83 | if (t!=txt) |
84 | html(txt); | 84 | html(txt); |
85 | } | 85 | } |
86 | 86 | ||
87 | void html_ntxt(int len, char *txt) | 87 | void html_ntxt(int len, char *txt) |
88 | { | 88 | { |
89 | char *t = txt; | 89 | char *t = txt; |
90 | while(t && *t && len--){ | 90 | while(t && *t && len--){ |
91 | int c = *t; | 91 | int c = *t; |
92 | if (c=='<' || c=='>' || c=='&') { | 92 | if (c=='<' || c=='>' || c=='&') { |
93 | write(htmlfd, txt, t - txt); | 93 | write(htmlfd, txt, t - txt); |
94 | if (c=='>') | 94 | if (c=='>') |
95 | html(">"); | 95 | html(">"); |
96 | else if (c=='<') | 96 | else if (c=='<') |
97 | html("<"); | 97 | html("<"); |
98 | else if (c=='&') | 98 | else if (c=='&') |
99 | html("&"); | 99 | html("&"); |
100 | txt = t+1; | 100 | txt = t+1; |
101 | } | 101 | } |
102 | t++; | 102 | t++; |
103 | } | 103 | } |
104 | if (t!=txt) | 104 | if (t!=txt) |
105 | write(htmlfd, txt, t - txt); | 105 | write(htmlfd, txt, t - txt); |
106 | if (len<0) | 106 | if (len<0) |
107 | html("..."); | 107 | html("..."); |
108 | } | 108 | } |
109 | 109 | ||
110 | void html_attr(char *txt) | 110 | void html_attr(char *txt) |
111 | { | 111 | { |
112 | char *t = txt; | 112 | char *t = txt; |
113 | while(t && *t){ | 113 | while(t && *t){ |
114 | int c = *t; | 114 | int c = *t; |
115 | if (c=='<' || c=='>' || c=='\'') { | 115 | if (c=='<' || c=='>' || c=='\'') { |
116 | write(htmlfd, txt, t - txt); | 116 | write(htmlfd, txt, t - txt); |
117 | if (c=='>') | 117 | if (c=='>') |
118 | html(">"); | 118 | html(">"); |
119 | else if (c=='<') | 119 | else if (c=='<') |
120 | html("<"); | 120 | html("<"); |
121 | else if (c=='\'') | 121 | else if (c=='\'') |
122 | html(""e;"); | 122 | html(""e;"); |
123 | txt = t+1; | 123 | txt = t+1; |
124 | } | 124 | } |
125 | t++; | 125 | t++; |
126 | } | 126 | } |
127 | if (t!=txt) | 127 | if (t!=txt) |
128 | html(txt); | 128 | html(txt); |
129 | } | 129 | } |
130 | 130 | ||
131 | void html_url_path(char *txt) | ||
132 | { | ||
133 | char *t = txt; | ||
134 | while(t && *t){ | ||
135 | int c = *t; | ||
136 | if (c=='"' || c=='#' || c=='\'' || c=='?') { | ||
137 | write(htmlfd, txt, t - txt); | ||
138 | write(htmlfd, fmt("%%%2x", c), 3); | ||
139 | txt = t+1; | ||
140 | } | ||
141 | t++; | ||
142 | } | ||
143 | if (t!=txt) | ||
144 | html(txt); | ||
145 | } | ||
146 | |||
131 | void html_url_arg(char *txt) | 147 | void html_url_arg(char *txt) |
132 | { | 148 | { |
133 | char *t = txt; | 149 | char *t = txt; |
134 | while(t && *t){ | 150 | while(t && *t){ |
135 | int c = *t; | 151 | int c = *t; |
136 | if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') { | 152 | if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') { |
137 | write(htmlfd, txt, t - txt); | 153 | write(htmlfd, txt, t - txt); |
138 | write(htmlfd, fmt("%%%2x", c), 3); | 154 | write(htmlfd, fmt("%%%2x", c), 3); |
139 | txt = t+1; | 155 | txt = t+1; |
140 | } | 156 | } |
141 | t++; | 157 | t++; |
142 | } | 158 | } |
143 | if (t!=txt) | 159 | if (t!=txt) |
144 | html(txt); | 160 | html(txt); |
145 | } | 161 | } |
146 | 162 | ||
147 | void html_hidden(char *name, char *value) | 163 | void html_hidden(char *name, char *value) |
148 | { | 164 | { |
149 | html("<input type='hidden' name='"); | 165 | html("<input type='hidden' name='"); |
150 | html_attr(name); | 166 | html_attr(name); |
151 | html("' value='"); | 167 | html("' value='"); |
152 | html_attr(value); | 168 | html_attr(value); |
153 | html("'/>"); | 169 | html("'/>"); |
154 | } | 170 | } |
155 | 171 | ||
156 | void html_option(char *value, char *text, char *selected_value) | 172 | void html_option(char *value, char *text, char *selected_value) |
157 | { | 173 | { |
158 | html("<option value='"); | 174 | html("<option value='"); |
159 | html_attr(value); | 175 | html_attr(value); |
160 | html("'"); | 176 | html("'"); |
161 | if (selected_value && !strcmp(selected_value, value)) | 177 | if (selected_value && !strcmp(selected_value, value)) |
162 | html(" selected='selected'"); | 178 | html(" selected='selected'"); |
163 | html(">"); | 179 | html(">"); |
164 | html_txt(text); | 180 | html_txt(text); |
165 | html("</option>\n"); | 181 | html("</option>\n"); |
166 | } | 182 | } |
167 | 183 | ||
168 | void html_link_open(char *url, char *title, char *class) | 184 | void html_link_open(char *url, char *title, char *class) |
169 | { | 185 | { |
170 | html("<a href='"); | 186 | html("<a href='"); |
171 | html_attr(url); | 187 | html_attr(url); |
172 | if (title) { | 188 | if (title) { |
173 | html("' title='"); | 189 | html("' title='"); |
174 | html_attr(title); | 190 | html_attr(title); |
175 | } | 191 | } |
176 | if (class) { | 192 | if (class) { |
177 | html("' class='"); | 193 | html("' class='"); |
178 | html_attr(class); | 194 | html_attr(class); |
179 | } | 195 | } |
180 | html("'>"); | 196 | html("'>"); |
181 | } | 197 | } |
182 | 198 | ||
183 | void html_link_close(void) | 199 | void html_link_close(void) |
184 | { | 200 | { |
185 | html("</a>"); | 201 | html("</a>"); |
186 | } | 202 | } |
187 | 203 | ||
188 | void html_fileperm(unsigned short mode) | 204 | void html_fileperm(unsigned short mode) |
189 | { | 205 | { |
190 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 206 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
191 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 207 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
192 | } | 208 | } |
193 | 209 | ||
194 | int html_include(const char *filename) | 210 | int html_include(const char *filename) |
195 | { | 211 | { |
196 | FILE *f; | 212 | FILE *f; |
197 | char buf[4096]; | 213 | char buf[4096]; |
198 | size_t len; | 214 | size_t len; |
199 | 215 | ||
200 | if (!(f = fopen(filename, "r"))) { | 216 | if (!(f = fopen(filename, "r"))) { |
201 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", | 217 | fprintf(stderr, "[cgit] Failed to include file %s: %s (%d).\n", |
202 | filename, strerror(errno), errno); | 218 | filename, strerror(errno), errno); |
203 | return -1; | 219 | return -1; |
204 | } | 220 | } |
205 | while((len = fread(buf, 1, 4096, f)) > 0) | 221 | while((len = fread(buf, 1, 4096, f)) > 0) |
206 | write(htmlfd, buf, len); | 222 | write(htmlfd, buf, len); |
207 | fclose(f); | 223 | fclose(f); |
208 | return 0; | 224 | return 0; |
209 | } | 225 | } |
210 | 226 | ||
211 | int hextoint(char c) | 227 | int hextoint(char c) |
212 | { | 228 | { |
213 | if (c >= 'a' && c <= 'f') | 229 | if (c >= 'a' && c <= 'f') |
214 | return 10 + c - 'a'; | 230 | return 10 + c - 'a'; |
215 | else if (c >= 'A' && c <= 'F') | 231 | else if (c >= 'A' && c <= 'F') |
216 | return 10 + c - 'A'; | 232 | return 10 + c - 'A'; |
217 | else if (c >= '0' && c <= '9') | 233 | else if (c >= '0' && c <= '9') |
218 | return c - '0'; | 234 | return c - '0'; |
219 | else | 235 | else |
220 | return -1; | 236 | return -1; |
221 | } | 237 | } |
222 | 238 | ||
223 | char *convert_query_hexchar(char *txt) | 239 | char *convert_query_hexchar(char *txt) |
224 | { | 240 | { |
225 | int d1, d2; | 241 | int d1, d2; |
226 | if (strlen(txt) < 3) { | 242 | if (strlen(txt) < 3) { |
227 | *txt = '\0'; | 243 | *txt = '\0'; |
228 | return txt-1; | 244 | return txt-1; |
229 | } | 245 | } |
230 | d1 = hextoint(*(txt+1)); | 246 | d1 = hextoint(*(txt+1)); |
231 | d2 = hextoint(*(txt+2)); | 247 | d2 = hextoint(*(txt+2)); |
232 | if (d1<0 || d2<0) { | 248 | if (d1<0 || d2<0) { |
233 | strcpy(txt, txt+3); | 249 | strcpy(txt, txt+3); |
234 | return txt-1; | 250 | return txt-1; |
235 | } else { | 251 | } else { |
236 | *txt = d1 * 16 + d2; | 252 | *txt = d1 * 16 + d2; |
237 | strcpy(txt+1, txt+3); | 253 | strcpy(txt+1, txt+3); |
238 | return txt; | 254 | return txt; |
239 | } | 255 | } |
240 | } | 256 | } |
241 | 257 | ||
242 | int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) | 258 | int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) |
243 | { | 259 | { |
244 | char *t, *value = NULL, c; | 260 | char *t, *value = NULL, c; |
245 | 261 | ||
246 | if (!txt) | 262 | if (!txt) |
247 | return 0; | 263 | return 0; |
248 | 264 | ||
249 | t = txt = strdup(txt); | 265 | t = txt = strdup(txt); |
250 | if (t == NULL) { | 266 | if (t == NULL) { |
251 | printf("Out of memory\n"); | 267 | printf("Out of memory\n"); |
252 | exit(1); | 268 | exit(1); |
253 | } | 269 | } |
254 | while((c=*t) != '\0') { | 270 | while((c=*t) != '\0') { |
255 | if (c=='=') { | 271 | if (c=='=') { |
256 | *t = '\0'; | 272 | *t = '\0'; |
257 | value = t+1; | 273 | value = t+1; |
258 | } else if (c=='+') { | 274 | } else if (c=='+') { |
259 | *t = ' '; | 275 | *t = ' '; |
260 | } else if (c=='%') { | 276 | } else if (c=='%') { |
261 | t = convert_query_hexchar(t); | 277 | t = convert_query_hexchar(t); |
262 | } else if (c=='&') { | 278 | } else if (c=='&') { |
263 | *t = '\0'; | 279 | *t = '\0'; |
264 | (*fn)(txt, value); | 280 | (*fn)(txt, value); |
265 | txt = t+1; | 281 | txt = t+1; |
266 | value = NULL; | 282 | value = NULL; |
267 | } | 283 | } |
268 | t++; | 284 | t++; |
269 | } | 285 | } |
270 | if (t!=txt) | 286 | if (t!=txt) |
271 | (*fn)(txt, value); | 287 | (*fn)(txt, value); |
272 | return 0; | 288 | return 0; |
273 | } | 289 | } |
@@ -1,23 +1,24 @@ | |||
1 | #ifndef HTML_H | 1 | #ifndef HTML_H |
2 | #define HTML_H | 2 | #define HTML_H |
3 | 3 | ||
4 | extern int htmlfd; | 4 | extern int htmlfd; |
5 | 5 | ||
6 | extern void html_raw(const char *txt, size_t size); | 6 | extern void html_raw(const char *txt, size_t size); |
7 | extern void html(const char *txt); | 7 | extern void html(const char *txt); |
8 | extern void htmlf(const char *format,...); | 8 | extern void htmlf(const char *format,...); |
9 | extern void html_status(int code, const char *msg, int more_headers); | 9 | extern void html_status(int code, const char *msg, int more_headers); |
10 | extern void html_txt(char *txt); | 10 | extern void html_txt(char *txt); |
11 | extern void html_ntxt(int len, char *txt); | 11 | extern void html_ntxt(int len, char *txt); |
12 | extern void html_attr(char *txt); | 12 | extern void html_attr(char *txt); |
13 | extern void html_url_path(char *txt); | ||
13 | extern void html_url_arg(char *txt); | 14 | extern void html_url_arg(char *txt); |
14 | extern void html_hidden(char *name, char *value); | 15 | extern void html_hidden(char *name, char *value); |
15 | extern void html_option(char *value, char *text, char *selected_value); | 16 | extern void html_option(char *value, char *text, char *selected_value); |
16 | extern void html_link_open(char *url, char *title, char *class); | 17 | extern void html_link_open(char *url, char *title, char *class); |
17 | extern void html_link_close(void); | 18 | extern void html_link_close(void); |
18 | extern void html_fileperm(unsigned short mode); | 19 | extern void html_fileperm(unsigned short mode); |
19 | extern int html_include(const char *filename); | 20 | extern int html_include(const char *filename); |
20 | 21 | ||
21 | extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); | 22 | extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); |
22 | 23 | ||
23 | #endif /* HTML_H */ | 24 | #endif /* HTML_H */ |
diff --git a/ui-repolist.c b/ui-repolist.c index 725338b..ab050c7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,170 +1,166 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
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 <time.h> | 9 | #include <time.h> |
10 | 10 | ||
11 | #include "cgit.h" | 11 | #include "cgit.h" |
12 | #include "html.h" | 12 | #include "html.h" |
13 | #include "ui-shared.h" | 13 | #include "ui-shared.h" |
14 | 14 | ||
15 | time_t read_agefile(char *path) | 15 | time_t read_agefile(char *path) |
16 | { | 16 | { |
17 | FILE *f; | 17 | FILE *f; |
18 | static char buf[64], buf2[64]; | 18 | static char buf[64], buf2[64]; |
19 | 19 | ||
20 | if (!(f = fopen(path, "r"))) | 20 | if (!(f = fopen(path, "r"))) |
21 | return -1; | 21 | return -1; |
22 | fgets(buf, sizeof(buf), f); | 22 | fgets(buf, sizeof(buf), f); |
23 | fclose(f); | 23 | fclose(f); |
24 | if (parse_date(buf, buf2, sizeof(buf2))) | 24 | if (parse_date(buf, buf2, sizeof(buf2))) |
25 | return strtoul(buf2, NULL, 10); | 25 | return strtoul(buf2, NULL, 10); |
26 | else | 26 | else |
27 | return 0; | 27 | return 0; |
28 | } | 28 | } |
29 | 29 | ||
30 | static void print_modtime(struct cgit_repo *repo) | 30 | static void print_modtime(struct cgit_repo *repo) |
31 | { | 31 | { |
32 | char *path; | 32 | char *path; |
33 | struct stat s; | 33 | struct stat s; |
34 | 34 | ||
35 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 35 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
36 | if (stat(path, &s) == 0) { | 36 | if (stat(path, &s) == 0) { |
37 | cgit_print_age(read_agefile(path), -1, NULL); | 37 | cgit_print_age(read_agefile(path), -1, NULL); |
38 | return; | 38 | return; |
39 | } | 39 | } |
40 | 40 | ||
41 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 41 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
42 | if (stat(path, &s) != 0) | 42 | if (stat(path, &s) != 0) |
43 | return; | 43 | return; |
44 | cgit_print_age(s.st_mtime, -1, NULL); | 44 | cgit_print_age(s.st_mtime, -1, NULL); |
45 | } | 45 | } |
46 | 46 | ||
47 | int is_match(struct cgit_repo *repo) | 47 | int is_match(struct cgit_repo *repo) |
48 | { | 48 | { |
49 | if (!ctx.qry.search) | 49 | if (!ctx.qry.search) |
50 | return 1; | 50 | return 1; |
51 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) | 51 | if (repo->url && strcasestr(repo->url, ctx.qry.search)) |
52 | return 1; | 52 | return 1; |
53 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) | 53 | if (repo->name && strcasestr(repo->name, ctx.qry.search)) |
54 | return 1; | 54 | return 1; |
55 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) | 55 | if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) |
56 | return 1; | 56 | return 1; |
57 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) | 57 | if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) |
58 | return 1; | 58 | return 1; |
59 | return 0; | 59 | return 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | int is_in_url(struct cgit_repo *repo) | 62 | int is_in_url(struct cgit_repo *repo) |
63 | { | 63 | { |
64 | if (!ctx.qry.url) | 64 | if (!ctx.qry.url) |
65 | return 1; | 65 | return 1; |
66 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) | 66 | if (repo->url && !prefixcmp(repo->url, ctx.qry.url)) |
67 | return 1; | 67 | return 1; |
68 | return 0; | 68 | return 0; |
69 | } | 69 | } |
70 | 70 | ||
71 | void print_header(int columns) | 71 | void print_header(int columns) |
72 | { | 72 | { |
73 | html("<tr class='nohover'>" | 73 | html("<tr class='nohover'>" |
74 | "<th class='left'>Name</th>" | 74 | "<th class='left'>Name</th>" |
75 | "<th class='left'>Description</th>" | 75 | "<th class='left'>Description</th>" |
76 | "<th class='left'>Owner</th>" | 76 | "<th class='left'>Owner</th>" |
77 | "<th class='left'>Idle</th>"); | 77 | "<th class='left'>Idle</th>"); |
78 | if (ctx.cfg.enable_index_links) | 78 | if (ctx.cfg.enable_index_links) |
79 | html("<th class='left'>Links</th>"); | 79 | html("<th class='left'>Links</th>"); |
80 | html("</tr>\n"); | 80 | html("</tr>\n"); |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void print_pager(int items, int pagelen, char *search) | 84 | void print_pager(int items, int pagelen, char *search) |
85 | { | 85 | { |
86 | int i; | 86 | int i; |
87 | html("<div class='pager'>"); | 87 | html("<div class='pager'>"); |
88 | for(i = 0; i * pagelen < items; i++) | 88 | for(i = 0; i * pagelen < items; i++) |
89 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, | 89 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, |
90 | search, i * pagelen); | 90 | search, i * pagelen); |
91 | html("</div>"); | 91 | html("</div>"); |
92 | } | 92 | } |
93 | 93 | ||
94 | void cgit_print_repolist() | 94 | void cgit_print_repolist() |
95 | { | 95 | { |
96 | int i, columns = 4, hits = 0, header = 0; | 96 | int i, columns = 4, hits = 0, header = 0; |
97 | char *last_group = NULL; | 97 | char *last_group = NULL; |
98 | 98 | ||
99 | if (ctx.cfg.enable_index_links) | 99 | if (ctx.cfg.enable_index_links) |
100 | columns++; | 100 | columns++; |
101 | 101 | ||
102 | ctx.page.title = ctx.cfg.root_title; | 102 | ctx.page.title = ctx.cfg.root_title; |
103 | cgit_print_http_headers(&ctx); | 103 | cgit_print_http_headers(&ctx); |
104 | cgit_print_docstart(&ctx); | 104 | cgit_print_docstart(&ctx); |
105 | cgit_print_pageheader(&ctx); | 105 | cgit_print_pageheader(&ctx); |
106 | 106 | ||
107 | if (ctx.cfg.index_header) | 107 | if (ctx.cfg.index_header) |
108 | html_include(ctx.cfg.index_header); | 108 | html_include(ctx.cfg.index_header); |
109 | 109 | ||
110 | html("<table summary='repository list' class='list nowrap'>"); | 110 | html("<table summary='repository list' class='list nowrap'>"); |
111 | for (i=0; i<cgit_repolist.count; i++) { | 111 | for (i=0; i<cgit_repolist.count; i++) { |
112 | ctx.repo = &cgit_repolist.repos[i]; | 112 | ctx.repo = &cgit_repolist.repos[i]; |
113 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) | 113 | if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) |
114 | continue; | 114 | continue; |
115 | hits++; | 115 | hits++; |
116 | if (hits <= ctx.qry.ofs) | 116 | if (hits <= ctx.qry.ofs) |
117 | continue; | 117 | continue; |
118 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) | 118 | if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) |
119 | continue; | 119 | continue; |
120 | if (!header++) | 120 | if (!header++) |
121 | print_header(columns); | 121 | print_header(columns); |
122 | if ((last_group == NULL && ctx.repo->group != NULL) || | 122 | if ((last_group == NULL && ctx.repo->group != NULL) || |
123 | (last_group != NULL && ctx.repo->group == NULL) || | 123 | (last_group != NULL && ctx.repo->group == NULL) || |
124 | (last_group != NULL && ctx.repo->group != NULL && | 124 | (last_group != NULL && ctx.repo->group != NULL && |
125 | strcmp(ctx.repo->group, last_group))) { | 125 | strcmp(ctx.repo->group, last_group))) { |
126 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 126 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
127 | columns); | 127 | columns); |
128 | html_txt(ctx.repo->group); | 128 | html_txt(ctx.repo->group); |
129 | html("</td></tr>"); | 129 | html("</td></tr>"); |
130 | last_group = ctx.repo->group; | 130 | last_group = ctx.repo->group; |
131 | } | 131 | } |
132 | htmlf("<tr><td class='%s'>", | 132 | htmlf("<tr><td class='%s'>", |
133 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); | 133 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); |
134 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); | 134 | cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); |
135 | html_txt(ctx.repo->name); | ||
136 | html_link_close(); | ||
137 | html("</td><td>"); | 135 | html("</td><td>"); |
138 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); | 136 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); |
139 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); | 137 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); |
140 | html_link_close(); | 138 | html_link_close(); |
141 | html("</td><td>"); | 139 | html("</td><td>"); |
142 | html_txt(ctx.repo->owner); | 140 | html_txt(ctx.repo->owner); |
143 | html("</td><td>"); | 141 | html("</td><td>"); |
144 | print_modtime(ctx.repo); | 142 | print_modtime(ctx.repo); |
145 | html("</td>"); | 143 | html("</td>"); |
146 | if (ctx.cfg.enable_index_links) { | 144 | if (ctx.cfg.enable_index_links) { |
147 | html("<td>"); | 145 | html("<td>"); |
148 | html_link_open(cgit_repourl(ctx.repo->url), | 146 | cgit_summary_link("summary", NULL, "button", NULL); |
149 | NULL, "button"); | ||
150 | html("summary</a>"); | ||
151 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, | 147 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
152 | 0, NULL, NULL); | 148 | 0, NULL, NULL); |
153 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | 149 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); |
154 | html("</td>"); | 150 | html("</td>"); |
155 | } | 151 | } |
156 | html("</tr>\n"); | 152 | html("</tr>\n"); |
157 | } | 153 | } |
158 | html("</table>"); | 154 | html("</table>"); |
159 | if (!hits) | 155 | if (!hits) |
160 | cgit_print_error("No repositories found"); | 156 | cgit_print_error("No repositories found"); |
161 | else if (hits > ctx.cfg.max_repo_count) | 157 | else if (hits > ctx.cfg.max_repo_count) |
162 | print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search); | 158 | print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search); |
163 | cgit_print_docend(); | 159 | cgit_print_docend(); |
164 | } | 160 | } |
165 | 161 | ||
166 | void cgit_print_site_readme() | 162 | void cgit_print_site_readme() |
167 | { | 163 | { |
168 | if (ctx.cfg.root_readme) | 164 | if (ctx.cfg.root_readme) |
169 | html_include(ctx.cfg.root_readme); | 165 | html_include(ctx.cfg.root_readme); |
170 | } | 166 | } |
diff --git a/ui-shared.c b/ui-shared.c index a2f636c..1fc5c09 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,712 +1,716 @@ | |||
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_hosturl() | 37 | char *cgit_hosturl() |
38 | { | 38 | { |
39 | char *host, *port; | 39 | char *host, *port; |
40 | 40 | ||
41 | host = getenv("HTTP_HOST"); | 41 | host = getenv("HTTP_HOST"); |
42 | if (host) { | 42 | if (host) { |
43 | host = xstrdup(host); | 43 | host = xstrdup(host); |
44 | } else { | 44 | } else { |
45 | host = getenv("SERVER_NAME"); | 45 | host = getenv("SERVER_NAME"); |
46 | if (!host) | 46 | if (!host) |
47 | return NULL; | 47 | return NULL; |
48 | port = getenv("SERVER_PORT"); | 48 | port = getenv("SERVER_PORT"); |
49 | if (port && atoi(port) != 80) | 49 | if (port && atoi(port) != 80) |
50 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | 50 | host = xstrdup(fmt("%s:%d", host, atoi(port))); |
51 | else | 51 | else |
52 | host = xstrdup(host); | 52 | host = xstrdup(host); |
53 | } | 53 | } |
54 | return host; | 54 | return host; |
55 | } | 55 | } |
56 | 56 | ||
57 | char *cgit_rooturl() | 57 | char *cgit_rooturl() |
58 | { | 58 | { |
59 | if (ctx.cfg.virtual_root) | 59 | if (ctx.cfg.virtual_root) |
60 | return fmt("%s/", ctx.cfg.virtual_root); | 60 | return fmt("%s/", ctx.cfg.virtual_root); |
61 | else | 61 | else |
62 | return ctx.cfg.script_name; | 62 | return ctx.cfg.script_name; |
63 | } | 63 | } |
64 | 64 | ||
65 | char *cgit_repourl(const char *reponame) | 65 | char *cgit_repourl(const char *reponame) |
66 | { | 66 | { |
67 | if (ctx.cfg.virtual_root) { | 67 | if (ctx.cfg.virtual_root) { |
68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
69 | } else { | 69 | } else { |
70 | return fmt("?r=%s", reponame); | 70 | return fmt("?r=%s", reponame); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | char *cgit_fileurl(const char *reponame, const char *pagename, | 74 | char *cgit_fileurl(const char *reponame, const char *pagename, |
75 | const char *filename, const char *query) | 75 | const char *filename, const char *query) |
76 | { | 76 | { |
77 | char *tmp; | 77 | char *tmp; |
78 | char *delim; | 78 | char *delim; |
79 | 79 | ||
80 | if (ctx.cfg.virtual_root) { | 80 | if (ctx.cfg.virtual_root) { |
81 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 81 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
82 | pagename, (filename ? filename:"")); | 82 | pagename, (filename ? filename:"")); |
83 | delim = "?"; | 83 | delim = "?"; |
84 | } else { | 84 | } else { |
85 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 85 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
86 | (filename ? filename : "")); | 86 | (filename ? filename : "")); |
87 | delim = "&"; | 87 | delim = "&"; |
88 | } | 88 | } |
89 | if (query) | 89 | if (query) |
90 | tmp = fmt("%s%s%s", tmp, delim, query); | 90 | tmp = fmt("%s%s%s", tmp, delim, query); |
91 | return tmp; | 91 | return tmp; |
92 | } | 92 | } |
93 | 93 | ||
94 | char *cgit_pageurl(const char *reponame, const char *pagename, | 94 | char *cgit_pageurl(const char *reponame, const char *pagename, |
95 | const char *query) | 95 | const char *query) |
96 | { | 96 | { |
97 | return cgit_fileurl(reponame,pagename,0,query); | 97 | return cgit_fileurl(reponame,pagename,0,query); |
98 | } | 98 | } |
99 | 99 | ||
100 | const char *cgit_repobasename(const char *reponame) | 100 | const char *cgit_repobasename(const char *reponame) |
101 | { | 101 | { |
102 | /* I assume we don't need to store more than one repo basename */ | 102 | /* I assume we don't need to store more than one repo basename */ |
103 | static char rvbuf[1024]; | 103 | static char rvbuf[1024]; |
104 | int p; | 104 | int p; |
105 | const char *rv; | 105 | const char *rv; |
106 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 106 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
107 | if(rvbuf[sizeof(rvbuf)-1]) | 107 | if(rvbuf[sizeof(rvbuf)-1]) |
108 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 108 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
109 | p = strlen(rvbuf)-1; | 109 | p = strlen(rvbuf)-1; |
110 | /* strip trailing slashes */ | 110 | /* strip trailing slashes */ |
111 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 111 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
112 | /* strip trailing .git */ | 112 | /* strip trailing .git */ |
113 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 113 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
114 | p -= 3; rvbuf[p--] = 0; | 114 | p -= 3; rvbuf[p--] = 0; |
115 | } | 115 | } |
116 | /* strip more trailing slashes if any */ | 116 | /* strip more trailing slashes if any */ |
117 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 117 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
118 | /* find last slash in the remaining string */ | 118 | /* find last slash in the remaining string */ |
119 | rv = strrchr(rvbuf,'/'); | 119 | rv = strrchr(rvbuf,'/'); |
120 | if(rv) | 120 | if(rv) |
121 | return ++rv; | 121 | return ++rv; |
122 | return rvbuf; | 122 | return rvbuf; |
123 | } | 123 | } |
124 | 124 | ||
125 | char *cgit_currurl() | 125 | char *cgit_currurl() |
126 | { | 126 | { |
127 | if (!ctx.cfg.virtual_root) | 127 | if (!ctx.cfg.virtual_root) |
128 | return ctx.cfg.script_name; | 128 | return ctx.cfg.script_name; |
129 | else if (ctx.qry.page) | 129 | else if (ctx.qry.page) |
130 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 130 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
131 | else if (ctx.qry.repo) | 131 | else if (ctx.qry.repo) |
132 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 132 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
133 | else | 133 | else |
134 | return fmt("%s/", ctx.cfg.virtual_root); | 134 | return fmt("%s/", ctx.cfg.virtual_root); |
135 | } | 135 | } |
136 | 136 | ||
137 | static void site_url(char *page, char *search, int ofs) | 137 | static void site_url(char *page, char *search, int ofs) |
138 | { | 138 | { |
139 | char *delim = "?"; | 139 | char *delim = "?"; |
140 | 140 | ||
141 | if (ctx.cfg.virtual_root) { | 141 | if (ctx.cfg.virtual_root) { |
142 | html_attr(ctx.cfg.virtual_root); | 142 | html_attr(ctx.cfg.virtual_root); |
143 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 143 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | } else | 145 | } else |
146 | html(ctx.cfg.script_name); | 146 | html(ctx.cfg.script_name); |
147 | 147 | ||
148 | if (page) { | 148 | if (page) { |
149 | htmlf("?p=%s", page); | 149 | htmlf("?p=%s", page); |
150 | delim = "&"; | 150 | delim = "&"; |
151 | } | 151 | } |
152 | if (search) { | 152 | if (search) { |
153 | html(delim); | 153 | html(delim); |
154 | html("q="); | 154 | html("q="); |
155 | html_attr(search); | 155 | html_attr(search); |
156 | delim = "&"; | 156 | delim = "&"; |
157 | } | 157 | } |
158 | if (ofs) { | 158 | if (ofs) { |
159 | html(delim); | 159 | html(delim); |
160 | htmlf("ofs=%d", ofs); | 160 | htmlf("ofs=%d", ofs); |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | static void site_link(char *page, char *name, char *title, char *class, | 164 | static void site_link(char *page, char *name, char *title, char *class, |
165 | char *search, int ofs) | 165 | char *search, int ofs) |
166 | { | 166 | { |
167 | html("<a"); | 167 | html("<a"); |
168 | if (title) { | 168 | if (title) { |
169 | html(" title='"); | 169 | html(" title='"); |
170 | html_attr(title); | 170 | html_attr(title); |
171 | html("'"); | 171 | html("'"); |
172 | } | 172 | } |
173 | if (class) { | 173 | if (class) { |
174 | html(" class='"); | 174 | html(" class='"); |
175 | html_attr(class); | 175 | html_attr(class); |
176 | html("'"); | 176 | html("'"); |
177 | } | 177 | } |
178 | html(" href='"); | 178 | html(" href='"); |
179 | site_url(page, search, ofs); | 179 | site_url(page, search, ofs); |
180 | html("'>"); | 180 | html("'>"); |
181 | html_txt(name); | 181 | html_txt(name); |
182 | html("</a>"); | 182 | html("</a>"); |
183 | } | 183 | } |
184 | 184 | ||
185 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | 185 | void cgit_index_link(char *name, char *title, char *class, char *pattern, |
186 | int ofs) | 186 | int ofs) |
187 | { | 187 | { |
188 | site_link(NULL, name, title, class, pattern, ofs); | 188 | site_link(NULL, name, title, class, pattern, ofs); |
189 | } | 189 | } |
190 | 190 | ||
191 | static char *repolink(char *title, char *class, char *page, char *head, | 191 | static char *repolink(char *title, char *class, char *page, char *head, |
192 | char *path) | 192 | char *path) |
193 | { | 193 | { |
194 | char *delim = "?"; | 194 | char *delim = "?"; |
195 | 195 | ||
196 | html("<a"); | 196 | html("<a"); |
197 | if (title) { | 197 | if (title) { |
198 | html(" title='"); | 198 | html(" title='"); |
199 | html_attr(title); | 199 | html_attr(title); |
200 | html("'"); | 200 | html("'"); |
201 | } | 201 | } |
202 | if (class) { | 202 | if (class) { |
203 | html(" class='"); | 203 | html(" class='"); |
204 | html_attr(class); | 204 | html_attr(class); |
205 | html("'"); | 205 | html("'"); |
206 | } | 206 | } |
207 | html(" href='"); | 207 | html(" href='"); |
208 | if (ctx.cfg.virtual_root) { | 208 | if (ctx.cfg.virtual_root) { |
209 | html_attr(ctx.cfg.virtual_root); | 209 | html_url_path(ctx.cfg.virtual_root); |
210 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 210 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
211 | html("/"); | 211 | html("/"); |
212 | html_attr(ctx.repo->url); | 212 | html_url_path(ctx.repo->url); |
213 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 213 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
214 | html("/"); | 214 | html("/"); |
215 | if (page) { | 215 | if (page) { |
216 | html(page); | 216 | html_url_path(page); |
217 | html("/"); | 217 | html("/"); |
218 | if (path) | 218 | if (path) |
219 | html_attr(path); | 219 | html_url_path(path); |
220 | } | 220 | } |
221 | } else { | 221 | } else { |
222 | html(ctx.cfg.script_name); | 222 | html(ctx.cfg.script_name); |
223 | html("?url="); | 223 | html("?url="); |
224 | html_url_arg(ctx.repo->url); | 224 | html_url_arg(ctx.repo->url); |
225 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 225 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
226 | html("/"); | 226 | html("/"); |
227 | if (page) { | 227 | if (page) { |
228 | html_url_arg(page); | 228 | html_url_arg(page); |
229 | html("/"); | 229 | html("/"); |
230 | if (path) | 230 | if (path) |
231 | html_url_arg(path); | 231 | html_url_arg(path); |
232 | } | 232 | } |
233 | delim = "&"; | 233 | delim = "&"; |
234 | } | 234 | } |
235 | if (head && strcmp(head, ctx.repo->defbranch)) { | 235 | if (head && strcmp(head, ctx.repo->defbranch)) { |
236 | html(delim); | 236 | html(delim); |
237 | html("h="); | 237 | html("h="); |
238 | html_url_arg(head); | 238 | html_url_arg(head); |
239 | delim = "&"; | 239 | delim = "&"; |
240 | } | 240 | } |
241 | return fmt("%s", delim); | 241 | return fmt("%s", delim); |
242 | } | 242 | } |
243 | 243 | ||
244 | static void reporevlink(char *page, char *name, char *title, char *class, | 244 | static void reporevlink(char *page, char *name, char *title, char *class, |
245 | char *head, char *rev, char *path) | 245 | char *head, char *rev, char *path) |
246 | { | 246 | { |
247 | char *delim; | 247 | char *delim; |
248 | 248 | ||
249 | delim = repolink(title, class, page, head, path); | 249 | delim = repolink(title, class, page, head, path); |
250 | if (rev && strcmp(rev, ctx.qry.head)) { | 250 | if (rev && strcmp(rev, ctx.qry.head)) { |
251 | html(delim); | 251 | html(delim); |
252 | html("id="); | 252 | html("id="); |
253 | html_url_arg(rev); | 253 | html_url_arg(rev); |
254 | } | 254 | } |
255 | html("'>"); | 255 | html("'>"); |
256 | html_txt(name); | 256 | html_txt(name); |
257 | html("</a>"); | 257 | html("</a>"); |
258 | } | 258 | } |
259 | 259 | ||
260 | void cgit_summary_link(char *name, char *title, char *class, char *head) | ||
261 | { | ||
262 | reporevlink(NULL, name, title, class, head, NULL, NULL); | ||
263 | } | ||
264 | |||
260 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 265 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
261 | char *rev, char *path) | 266 | char *rev, char *path) |
262 | { | 267 | { |
263 | reporevlink("tree", name, title, class, head, rev, path); | 268 | reporevlink("tree", name, title, class, head, rev, path); |
264 | } | 269 | } |
265 | 270 | ||
266 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 271 | void cgit_plain_link(char *name, char *title, char *class, char *head, |
267 | char *rev, char *path) | 272 | char *rev, char *path) |
268 | { | 273 | { |
269 | reporevlink("plain", name, title, class, head, rev, path); | 274 | reporevlink("plain", name, title, class, head, rev, path); |
270 | } | 275 | } |
271 | 276 | ||
272 | void cgit_log_link(char *name, char *title, char *class, char *head, | 277 | void cgit_log_link(char *name, char *title, char *class, char *head, |
273 | char *rev, char *path, int ofs, char *grep, char *pattern) | 278 | char *rev, char *path, int ofs, char *grep, char *pattern) |
274 | { | 279 | { |
275 | char *delim; | 280 | char *delim; |
276 | 281 | ||
277 | delim = repolink(title, class, "log", head, path); | 282 | delim = repolink(title, class, "log", head, path); |
278 | if (rev && strcmp(rev, ctx.qry.head)) { | 283 | if (rev && strcmp(rev, ctx.qry.head)) { |
279 | html(delim); | 284 | html(delim); |
280 | html("id="); | 285 | html("id="); |
281 | html_url_arg(rev); | 286 | html_url_arg(rev); |
282 | delim = "&"; | 287 | delim = "&"; |
283 | } | 288 | } |
284 | if (grep && pattern) { | 289 | if (grep && pattern) { |
285 | html(delim); | 290 | html(delim); |
286 | html("qt="); | 291 | html("qt="); |
287 | html_url_arg(grep); | 292 | html_url_arg(grep); |
288 | delim = "&"; | 293 | delim = "&"; |
289 | html(delim); | 294 | html(delim); |
290 | html("q="); | 295 | html("q="); |
291 | html_url_arg(pattern); | 296 | html_url_arg(pattern); |
292 | } | 297 | } |
293 | if (ofs > 0) { | 298 | if (ofs > 0) { |
294 | html(delim); | 299 | html(delim); |
295 | html("ofs="); | 300 | html("ofs="); |
296 | htmlf("%d", ofs); | 301 | htmlf("%d", ofs); |
297 | } | 302 | } |
298 | html("'>"); | 303 | html("'>"); |
299 | html_txt(name); | 304 | html_txt(name); |
300 | html("</a>"); | 305 | html("</a>"); |
301 | } | 306 | } |
302 | 307 | ||
303 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 308 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
304 | char *rev) | 309 | char *rev) |
305 | { | 310 | { |
306 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 311 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
307 | name[ctx.cfg.max_msg_len] = '\0'; | 312 | name[ctx.cfg.max_msg_len] = '\0'; |
308 | name[ctx.cfg.max_msg_len - 1] = '.'; | 313 | name[ctx.cfg.max_msg_len - 1] = '.'; |
309 | name[ctx.cfg.max_msg_len - 2] = '.'; | 314 | name[ctx.cfg.max_msg_len - 2] = '.'; |
310 | name[ctx.cfg.max_msg_len - 3] = '.'; | 315 | name[ctx.cfg.max_msg_len - 3] = '.'; |
311 | } | 316 | } |
312 | reporevlink("commit", name, title, class, head, rev, NULL); | 317 | reporevlink("commit", name, title, class, head, rev, NULL); |
313 | } | 318 | } |
314 | 319 | ||
315 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 320 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
316 | char *rev, char *path) | 321 | char *rev, char *path) |
317 | { | 322 | { |
318 | reporevlink("refs", name, title, class, head, rev, path); | 323 | reporevlink("refs", name, title, class, head, rev, path); |
319 | } | 324 | } |
320 | 325 | ||
321 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 326 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
322 | char *rev, char *archivename) | 327 | char *rev, char *archivename) |
323 | { | 328 | { |
324 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 329 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
325 | } | 330 | } |
326 | 331 | ||
327 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 332 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
328 | char *new_rev, char *old_rev, char *path) | 333 | char *new_rev, char *old_rev, char *path) |
329 | { | 334 | { |
330 | char *delim; | 335 | char *delim; |
331 | 336 | ||
332 | delim = repolink(title, class, "diff", head, path); | 337 | delim = repolink(title, class, "diff", head, path); |
333 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 338 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
334 | html(delim); | 339 | html(delim); |
335 | html("id="); | 340 | html("id="); |
336 | html_url_arg(new_rev); | 341 | html_url_arg(new_rev); |
337 | delim = "&"; | 342 | delim = "&"; |
338 | } | 343 | } |
339 | if (old_rev) { | 344 | if (old_rev) { |
340 | html(delim); | 345 | html(delim); |
341 | html("id2="); | 346 | html("id2="); |
342 | html_url_arg(old_rev); | 347 | html_url_arg(old_rev); |
343 | } | 348 | } |
344 | html("'>"); | 349 | html("'>"); |
345 | html_txt(name); | 350 | html_txt(name); |
346 | html("</a>"); | 351 | html("</a>"); |
347 | } | 352 | } |
348 | 353 | ||
349 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 354 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
350 | char *rev) | 355 | char *rev) |
351 | { | 356 | { |
352 | reporevlink("patch", name, title, class, head, rev, NULL); | 357 | reporevlink("patch", name, title, class, head, rev, NULL); |
353 | } | 358 | } |
354 | 359 | ||
355 | void cgit_object_link(struct object *obj) | 360 | void cgit_object_link(struct object *obj) |
356 | { | 361 | { |
357 | char *page, *arg, *url; | 362 | char *page, *arg, *url; |
358 | 363 | ||
359 | if (obj->type == OBJ_COMMIT) { | 364 | if (obj->type == OBJ_COMMIT) { |
360 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 365 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
361 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 366 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
362 | return; | 367 | return; |
363 | } else if (obj->type == OBJ_TREE) { | 368 | } else if (obj->type == OBJ_TREE) { |
364 | page = "tree"; | 369 | page = "tree"; |
365 | arg = "id"; | 370 | arg = "id"; |
366 | } else if (obj->type == OBJ_TAG) { | 371 | } else if (obj->type == OBJ_TAG) { |
367 | page = "tag"; | 372 | page = "tag"; |
368 | arg = "id"; | 373 | arg = "id"; |
369 | } else { | 374 | } else { |
370 | page = "blob"; | 375 | page = "blob"; |
371 | arg = "id"; | 376 | arg = "id"; |
372 | } | 377 | } |
373 | 378 | ||
374 | url = cgit_pageurl(ctx.qry.repo, page, | 379 | url = cgit_pageurl(ctx.qry.repo, page, |
375 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 380 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
376 | html_link_open(url, NULL, NULL); | 381 | html_link_open(url, NULL, NULL); |
377 | htmlf("%s %s", typename(obj->type), | 382 | htmlf("%s %s", typename(obj->type), |
378 | sha1_to_hex(obj->sha1)); | 383 | sha1_to_hex(obj->sha1)); |
379 | html_link_close(); | 384 | html_link_close(); |
380 | } | 385 | } |
381 | 386 | ||
382 | void cgit_print_date(time_t secs, char *format, int local_time) | 387 | void cgit_print_date(time_t secs, char *format, int local_time) |
383 | { | 388 | { |
384 | char buf[64]; | 389 | char buf[64]; |
385 | struct tm *time; | 390 | struct tm *time; |
386 | 391 | ||
387 | if (!secs) | 392 | if (!secs) |
388 | return; | 393 | return; |
389 | if(local_time) | 394 | if(local_time) |
390 | time = localtime(&secs); | 395 | time = localtime(&secs); |
391 | else | 396 | else |
392 | time = gmtime(&secs); | 397 | time = gmtime(&secs); |
393 | strftime(buf, sizeof(buf)-1, format, time); | 398 | strftime(buf, sizeof(buf)-1, format, time); |
394 | html_txt(buf); | 399 | html_txt(buf); |
395 | } | 400 | } |
396 | 401 | ||
397 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 402 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
398 | { | 403 | { |
399 | time_t now, secs; | 404 | time_t now, secs; |
400 | 405 | ||
401 | if (!t) | 406 | if (!t) |
402 | return; | 407 | return; |
403 | time(&now); | 408 | time(&now); |
404 | secs = now - t; | 409 | secs = now - t; |
405 | 410 | ||
406 | if (secs > max_relative && max_relative >= 0) { | 411 | if (secs > max_relative && max_relative >= 0) { |
407 | cgit_print_date(t, format, ctx.cfg.local_time); | 412 | cgit_print_date(t, format, ctx.cfg.local_time); |
408 | return; | 413 | return; |
409 | } | 414 | } |
410 | 415 | ||
411 | if (secs < TM_HOUR * 2) { | 416 | if (secs < TM_HOUR * 2) { |
412 | htmlf("<span class='age-mins'>%.0f min.</span>", | 417 | htmlf("<span class='age-mins'>%.0f min.</span>", |
413 | secs * 1.0 / TM_MIN); | 418 | secs * 1.0 / TM_MIN); |
414 | return; | 419 | return; |
415 | } | 420 | } |
416 | if (secs < TM_DAY * 2) { | 421 | if (secs < TM_DAY * 2) { |
417 | htmlf("<span class='age-hours'>%.0f hours</span>", | 422 | htmlf("<span class='age-hours'>%.0f hours</span>", |
418 | secs * 1.0 / TM_HOUR); | 423 | secs * 1.0 / TM_HOUR); |
419 | return; | 424 | return; |
420 | } | 425 | } |
421 | if (secs < TM_WEEK * 2) { | 426 | if (secs < TM_WEEK * 2) { |
422 | htmlf("<span class='age-days'>%.0f days</span>", | 427 | htmlf("<span class='age-days'>%.0f days</span>", |
423 | secs * 1.0 / TM_DAY); | 428 | secs * 1.0 / TM_DAY); |
424 | return; | 429 | return; |
425 | } | 430 | } |
426 | if (secs < TM_MONTH * 2) { | 431 | if (secs < TM_MONTH * 2) { |
427 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 432 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
428 | secs * 1.0 / TM_WEEK); | 433 | secs * 1.0 / TM_WEEK); |
429 | return; | 434 | return; |
430 | } | 435 | } |
431 | if (secs < TM_YEAR * 2) { | 436 | if (secs < TM_YEAR * 2) { |
432 | htmlf("<span class='age-months'>%.0f months</span>", | 437 | htmlf("<span class='age-months'>%.0f months</span>", |
433 | secs * 1.0 / TM_MONTH); | 438 | secs * 1.0 / TM_MONTH); |
434 | return; | 439 | return; |
435 | } | 440 | } |
436 | htmlf("<span class='age-years'>%.0f years</span>", | 441 | htmlf("<span class='age-years'>%.0f years</span>", |
437 | secs * 1.0 / TM_YEAR); | 442 | secs * 1.0 / TM_YEAR); |
438 | } | 443 | } |
439 | 444 | ||
440 | void cgit_print_http_headers(struct cgit_context *ctx) | 445 | void cgit_print_http_headers(struct cgit_context *ctx) |
441 | { | 446 | { |
442 | if (ctx->page.mimetype && ctx->page.charset) | 447 | if (ctx->page.mimetype && ctx->page.charset) |
443 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 448 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
444 | ctx->page.charset); | 449 | ctx->page.charset); |
445 | else if (ctx->page.mimetype) | 450 | else if (ctx->page.mimetype) |
446 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 451 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
447 | if (ctx->page.size) | 452 | if (ctx->page.size) |
448 | htmlf("Content-Length: %ld\n", ctx->page.size); | 453 | htmlf("Content-Length: %ld\n", ctx->page.size); |
449 | if (ctx->page.filename) | 454 | if (ctx->page.filename) |
450 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 455 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
451 | ctx->page.filename); | 456 | ctx->page.filename); |
452 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 457 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
453 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 458 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
454 | html("\n"); | 459 | html("\n"); |
455 | } | 460 | } |
456 | 461 | ||
457 | void cgit_print_docstart(struct cgit_context *ctx) | 462 | void cgit_print_docstart(struct cgit_context *ctx) |
458 | { | 463 | { |
459 | char *host = cgit_hosturl(); | 464 | char *host = cgit_hosturl(); |
460 | html(cgit_doctype); | 465 | html(cgit_doctype); |
461 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 466 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
462 | html("<head>\n"); | 467 | html("<head>\n"); |
463 | html("<title>"); | 468 | html("<title>"); |
464 | html_txt(ctx->page.title); | 469 | html_txt(ctx->page.title); |
465 | html("</title>\n"); | 470 | html("</title>\n"); |
466 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 471 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
467 | if (ctx->cfg.robots && *ctx->cfg.robots) | 472 | if (ctx->cfg.robots && *ctx->cfg.robots) |
468 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 473 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
469 | html("<link rel='stylesheet' type='text/css' href='"); | 474 | html("<link rel='stylesheet' type='text/css' href='"); |
470 | html_attr(ctx->cfg.css); | 475 | html_attr(ctx->cfg.css); |
471 | html("'/>\n"); | 476 | html("'/>\n"); |
472 | if (ctx->cfg.favicon) { | 477 | if (ctx->cfg.favicon) { |
473 | html("<link rel='shortcut icon' href='"); | 478 | html("<link rel='shortcut icon' href='"); |
474 | html_attr(ctx->cfg.favicon); | 479 | html_attr(ctx->cfg.favicon); |
475 | html("'/>\n"); | 480 | html("'/>\n"); |
476 | } | 481 | } |
477 | if (host && ctx->repo) { | 482 | if (host && ctx->repo) { |
478 | html("<link rel='alternate' title='Atom feed' href='http://"); | 483 | html("<link rel='alternate' title='Atom feed' href='http://"); |
479 | html_attr(cgit_hosturl()); | 484 | html_attr(cgit_hosturl()); |
480 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 485 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
481 | fmt("h=%s", ctx->qry.head))); | 486 | fmt("h=%s", ctx->qry.head))); |
482 | html("' type='application/atom+xml'/>"); | 487 | html("' type='application/atom+xml'/>"); |
483 | } | 488 | } |
484 | html("</head>\n"); | 489 | html("</head>\n"); |
485 | html("<body>\n"); | 490 | html("<body>\n"); |
486 | } | 491 | } |
487 | 492 | ||
488 | void cgit_print_docend() | 493 | void cgit_print_docend() |
489 | { | 494 | { |
490 | html("</div>"); | 495 | html("</div>"); |
491 | if (ctx.cfg.footer) | 496 | if (ctx.cfg.footer) |
492 | html_include(ctx.cfg.footer); | 497 | html_include(ctx.cfg.footer); |
493 | else { | 498 | else { |
494 | html("<div class='footer'>generated "); | 499 | html("<div class='footer'>generated "); |
495 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 500 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
496 | htmlf(" by cgit %s", cgit_version); | 501 | htmlf(" by cgit %s", cgit_version); |
497 | html("</div>\n"); | 502 | html("</div>\n"); |
498 | } | 503 | } |
499 | html("</body>\n</html>\n"); | 504 | html("</body>\n</html>\n"); |
500 | } | 505 | } |
501 | 506 | ||
502 | int print_branch_option(const char *refname, const unsigned char *sha1, | 507 | int print_branch_option(const char *refname, const unsigned char *sha1, |
503 | int flags, void *cb_data) | 508 | int flags, void *cb_data) |
504 | { | 509 | { |
505 | char *name = (char *)refname; | 510 | char *name = (char *)refname; |
506 | html_option(name, name, ctx.qry.head); | 511 | html_option(name, name, ctx.qry.head); |
507 | return 0; | 512 | return 0; |
508 | } | 513 | } |
509 | 514 | ||
510 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 515 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
511 | int flags, void *cb_data) | 516 | int flags, void *cb_data) |
512 | { | 517 | { |
513 | struct tag *tag; | 518 | struct tag *tag; |
514 | struct taginfo *info; | 519 | struct taginfo *info; |
515 | struct object *obj; | 520 | struct object *obj; |
516 | char buf[256], *url; | 521 | char buf[256], *url; |
517 | unsigned char fileid[20]; | 522 | unsigned char fileid[20]; |
518 | int *header = (int *)cb_data; | 523 | int *header = (int *)cb_data; |
519 | 524 | ||
520 | if (prefixcmp(refname, "refs/archives")) | 525 | if (prefixcmp(refname, "refs/archives")) |
521 | return 0; | 526 | return 0; |
522 | strncpy(buf, refname+14, sizeof(buf)); | 527 | strncpy(buf, refname+14, sizeof(buf)); |
523 | obj = parse_object(sha1); | 528 | obj = parse_object(sha1); |
524 | if (!obj) | 529 | if (!obj) |
525 | return 1; | 530 | return 1; |
526 | if (obj->type == OBJ_TAG) { | 531 | if (obj->type == OBJ_TAG) { |
527 | tag = lookup_tag(sha1); | 532 | tag = lookup_tag(sha1); |
528 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 533 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
529 | return 0; | 534 | return 0; |
530 | hashcpy(fileid, tag->tagged->sha1); | 535 | hashcpy(fileid, tag->tagged->sha1); |
531 | } else if (obj->type != OBJ_BLOB) { | 536 | } else if (obj->type != OBJ_BLOB) { |
532 | return 0; | 537 | return 0; |
533 | } else { | 538 | } else { |
534 | hashcpy(fileid, sha1); | 539 | hashcpy(fileid, sha1); |
535 | } | 540 | } |
536 | if (!*header) { | 541 | if (!*header) { |
537 | html("<h1>download</h1>\n"); | 542 | html("<h1>download</h1>\n"); |
538 | *header = 1; | 543 | *header = 1; |
539 | } | 544 | } |
540 | url = cgit_pageurl(ctx.qry.repo, "blob", | 545 | url = cgit_pageurl(ctx.qry.repo, "blob", |
541 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 546 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
542 | buf)); | 547 | buf)); |
543 | html_link_open(url, NULL, "menu"); | 548 | html_link_open(url, NULL, "menu"); |
544 | html_txt(strlpart(buf, 20)); | 549 | html_txt(strlpart(buf, 20)); |
545 | html_link_close(); | 550 | html_link_close(); |
546 | return 0; | 551 | return 0; |
547 | } | 552 | } |
548 | 553 | ||
549 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 554 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
550 | { | 555 | { |
551 | char *url; | 556 | char *url; |
552 | 557 | ||
553 | if (!ctx.cfg.virtual_root) { | 558 | if (!ctx.cfg.virtual_root) { |
554 | url = fmt("%s/%s", ctx.qry.repo, page); | 559 | url = fmt("%s/%s", ctx.qry.repo, page); |
555 | if (ctx.qry.path) | 560 | if (ctx.qry.path) |
556 | url = fmt("%s/%s", url, ctx.qry.path); | 561 | url = fmt("%s/%s", url, ctx.qry.path); |
557 | html_hidden("url", url); | 562 | html_hidden("url", url); |
558 | } | 563 | } |
559 | 564 | ||
560 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 565 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
561 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 566 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
562 | html_hidden("h", ctx.qry.head); | 567 | html_hidden("h", ctx.qry.head); |
563 | 568 | ||
564 | if (ctx.qry.sha1) | 569 | if (ctx.qry.sha1) |
565 | html_hidden("id", ctx.qry.sha1); | 570 | html_hidden("id", ctx.qry.sha1); |
566 | if (ctx.qry.sha2) | 571 | if (ctx.qry.sha2) |
567 | html_hidden("id2", ctx.qry.sha2); | 572 | html_hidden("id2", ctx.qry.sha2); |
568 | 573 | ||
569 | if (incl_search) { | 574 | if (incl_search) { |
570 | if (ctx.qry.grep) | 575 | if (ctx.qry.grep) |
571 | html_hidden("qt", ctx.qry.grep); | 576 | html_hidden("qt", ctx.qry.grep); |
572 | if (ctx.qry.search) | 577 | if (ctx.qry.search) |
573 | html_hidden("q", ctx.qry.search); | 578 | html_hidden("q", ctx.qry.search); |
574 | } | 579 | } |
575 | } | 580 | } |
576 | 581 | ||
577 | char *hc(struct cgit_cmd *cmd, const char *page) | 582 | char *hc(struct cgit_cmd *cmd, const char *page) |
578 | { | 583 | { |
579 | return (strcmp(cmd->name, page) ? NULL : "active"); | 584 | return (strcmp(cmd->name, page) ? NULL : "active"); |
580 | } | 585 | } |
581 | 586 | ||
582 | void cgit_print_pageheader(struct cgit_context *ctx) | 587 | void cgit_print_pageheader(struct cgit_context *ctx) |
583 | { | 588 | { |
584 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 589 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
585 | 590 | ||
586 | html("<table id='header'>\n"); | 591 | html("<table id='header'>\n"); |
587 | html("<tr>\n"); | 592 | html("<tr>\n"); |
588 | html("<td class='logo' rowspan='2'><a href='"); | 593 | html("<td class='logo' rowspan='2'><a href='"); |
589 | if (ctx->cfg.logo_link) | 594 | if (ctx->cfg.logo_link) |
590 | html_attr(ctx->cfg.logo_link); | 595 | html_attr(ctx->cfg.logo_link); |
591 | else | 596 | else |
592 | html_attr(cgit_rooturl()); | 597 | html_attr(cgit_rooturl()); |
593 | html("'><img src='"); | 598 | html("'><img src='"); |
594 | html_attr(ctx->cfg.logo); | 599 | html_attr(ctx->cfg.logo); |
595 | html("' alt='cgit logo'/></a></td>\n"); | 600 | html("' alt='cgit logo'/></a></td>\n"); |
596 | 601 | ||
597 | html("<td class='main'>"); | 602 | html("<td class='main'>"); |
598 | if (ctx->repo) { | 603 | if (ctx->repo) { |
599 | cgit_index_link("index", NULL, NULL, NULL, 0); | 604 | cgit_index_link("index", NULL, NULL, NULL, 0); |
600 | html(" : "); | 605 | html(" : "); |
601 | reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"), | 606 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
602 | ctx->qry.head, NULL, NULL); | ||
603 | html("</td><td class='form'>"); | 607 | html("</td><td class='form'>"); |
604 | html("<form method='get' action=''>\n"); | 608 | html("<form method='get' action=''>\n"); |
605 | add_hidden_formfields(0, 1, ctx->qry.page); | 609 | add_hidden_formfields(0, 1, ctx->qry.page); |
606 | html("<select name='h' onchange='this.form.submit();'>\n"); | 610 | html("<select name='h' onchange='this.form.submit();'>\n"); |
607 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 611 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
608 | html("</select> "); | 612 | html("</select> "); |
609 | html("<input type='submit' name='' value='switch'/>"); | 613 | html("<input type='submit' name='' value='switch'/>"); |
610 | html("</form>"); | 614 | html("</form>"); |
611 | } else | 615 | } else |
612 | html_txt(ctx->cfg.root_title); | 616 | html_txt(ctx->cfg.root_title); |
613 | html("</td></tr>\n"); | 617 | html("</td></tr>\n"); |
614 | 618 | ||
615 | html("<tr><td class='sub'>"); | 619 | html("<tr><td class='sub'>"); |
616 | if (ctx->repo) { | 620 | if (ctx->repo) { |
617 | html_txt(ctx->repo->desc); | 621 | html_txt(ctx->repo->desc); |
618 | html("</td><td class='sub right'>"); | 622 | html("</td><td class='sub right'>"); |
619 | html_txt(ctx->repo->owner); | 623 | html_txt(ctx->repo->owner); |
620 | } else { | 624 | } else { |
621 | if (ctx->cfg.root_desc) | 625 | if (ctx->cfg.root_desc) |
622 | html_txt(ctx->cfg.root_desc); | 626 | html_txt(ctx->cfg.root_desc); |
623 | else if (ctx->cfg.index_info) | 627 | else if (ctx->cfg.index_info) |
624 | html_include(ctx->cfg.index_info); | 628 | html_include(ctx->cfg.index_info); |
625 | } | 629 | } |
626 | html("</td></tr></table>\n"); | 630 | html("</td></tr></table>\n"); |
627 | 631 | ||
628 | html("<table class='tabs'><tr><td>\n"); | 632 | html("<table class='tabs'><tr><td>\n"); |
629 | if (ctx->repo) { | 633 | if (ctx->repo) { |
630 | reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), | 634 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, |
631 | ctx->qry.head, NULL, NULL); | 635 | ctx->qry.head); |
632 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 636 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
633 | ctx->qry.sha1, NULL); | 637 | ctx->qry.sha1, NULL); |
634 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 638 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
635 | NULL, NULL, 0, NULL, NULL); | 639 | NULL, NULL, 0, NULL, NULL); |
636 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 640 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
637 | ctx->qry.sha1, NULL); | 641 | ctx->qry.sha1, NULL); |
638 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 642 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
639 | ctx->qry.head, ctx->qry.sha1); | 643 | ctx->qry.head, ctx->qry.sha1); |
640 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 644 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
641 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 645 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
642 | if (ctx->repo->readme) | 646 | if (ctx->repo->readme) |
643 | reporevlink("about", "about", NULL, | 647 | reporevlink("about", "about", NULL, |
644 | hc(cmd, "about"), ctx->qry.head, NULL, | 648 | hc(cmd, "about"), ctx->qry.head, NULL, |
645 | NULL); | 649 | NULL); |
646 | html("</td><td class='form'>"); | 650 | html("</td><td class='form'>"); |
647 | html("<form class='right' method='get' action='"); | 651 | html("<form class='right' method='get' action='"); |
648 | if (ctx->cfg.virtual_root) | 652 | if (ctx->cfg.virtual_root) |
649 | html_attr(cgit_fileurl(ctx->qry.repo, "log", | 653 | html_attr(cgit_fileurl(ctx->qry.repo, "log", |
650 | ctx->qry.path, NULL)); | 654 | ctx->qry.path, NULL)); |
651 | html("'>\n"); | 655 | html("'>\n"); |
652 | add_hidden_formfields(1, 0, "log"); | 656 | add_hidden_formfields(1, 0, "log"); |
653 | html("<select name='qt'>\n"); | 657 | html("<select name='qt'>\n"); |
654 | html_option("grep", "log msg", ctx->qry.grep); | 658 | html_option("grep", "log msg", ctx->qry.grep); |
655 | html_option("author", "author", ctx->qry.grep); | 659 | html_option("author", "author", ctx->qry.grep); |
656 | html_option("committer", "committer", ctx->qry.grep); | 660 | html_option("committer", "committer", ctx->qry.grep); |
657 | html("</select>\n"); | 661 | html("</select>\n"); |
658 | html("<input class='txt' type='text' size='10' name='q' value='"); | 662 | html("<input class='txt' type='text' size='10' name='q' value='"); |
659 | html_attr(ctx->qry.search); | 663 | html_attr(ctx->qry.search); |
660 | html("'/>\n"); | 664 | html("'/>\n"); |
661 | html("<input type='submit' value='search'/>\n"); | 665 | html("<input type='submit' value='search'/>\n"); |
662 | html("</form>\n"); | 666 | html("</form>\n"); |
663 | } else { | 667 | } else { |
664 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); | 668 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); |
665 | if (ctx->cfg.root_readme) | 669 | if (ctx->cfg.root_readme) |
666 | site_link("about", "about", NULL, hc(cmd, "about"), | 670 | site_link("about", "about", NULL, hc(cmd, "about"), |
667 | NULL, 0); | 671 | NULL, 0); |
668 | html("</td><td class='form'>"); | 672 | html("</td><td class='form'>"); |
669 | html("<form method='get' action='"); | 673 | html("<form method='get' action='"); |
670 | html_attr(cgit_rooturl()); | 674 | html_attr(cgit_rooturl()); |
671 | html("'>\n"); | 675 | html("'>\n"); |
672 | html("<input type='text' name='q' size='10' value='"); | 676 | html("<input type='text' name='q' size='10' value='"); |
673 | html_attr(ctx->qry.search); | 677 | html_attr(ctx->qry.search); |
674 | html("'/>\n"); | 678 | html("'/>\n"); |
675 | html("<input type='submit' value='search'/>\n"); | 679 | html("<input type='submit' value='search'/>\n"); |
676 | html("</form>"); | 680 | html("</form>"); |
677 | } | 681 | } |
678 | html("</td></tr></table>\n"); | 682 | html("</td></tr></table>\n"); |
679 | html("<div class='content'>"); | 683 | html("<div class='content'>"); |
680 | } | 684 | } |
681 | 685 | ||
682 | void cgit_print_filemode(unsigned short mode) | 686 | void cgit_print_filemode(unsigned short mode) |
683 | { | 687 | { |
684 | if (S_ISDIR(mode)) | 688 | if (S_ISDIR(mode)) |
685 | html("d"); | 689 | html("d"); |
686 | else if (S_ISLNK(mode)) | 690 | else if (S_ISLNK(mode)) |
687 | html("l"); | 691 | html("l"); |
688 | else if (S_ISGITLINK(mode)) | 692 | else if (S_ISGITLINK(mode)) |
689 | html("m"); | 693 | html("m"); |
690 | else | 694 | else |
691 | html("-"); | 695 | html("-"); |
692 | html_fileperm(mode >> 6); | 696 | html_fileperm(mode >> 6); |
693 | html_fileperm(mode >> 3); | 697 | html_fileperm(mode >> 3); |
694 | html_fileperm(mode); | 698 | html_fileperm(mode); |
695 | } | 699 | } |
696 | 700 | ||
697 | void cgit_print_snapshot_links(const char *repo, const char *head, | 701 | void cgit_print_snapshot_links(const char *repo, const char *head, |
698 | const char *hex, int snapshots) | 702 | const char *hex, int snapshots) |
699 | { | 703 | { |
700 | const struct cgit_snapshot_format* f; | 704 | const struct cgit_snapshot_format* f; |
701 | char *filename; | 705 | char *filename; |
702 | 706 | ||
703 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 707 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
704 | if (!(snapshots & f->bit)) | 708 | if (!(snapshots & f->bit)) |
705 | continue; | 709 | continue; |
706 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 710 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
707 | f->suffix); | 711 | f->suffix); |
708 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 712 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
709 | (char *)hex, filename); | 713 | (char *)hex, filename); |
710 | html("<br/>"); | 714 | html("<br/>"); |
711 | } | 715 | } |
712 | } | 716 | } |
diff --git a/ui-shared.h b/ui-shared.h index 747f092..0cd5ed1 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -1,43 +1,44 @@ | |||
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_hosturl(); | 4 | extern char *cgit_hosturl(); |
5 | extern char *cgit_repourl(const char *reponame); | 5 | extern char *cgit_repourl(const char *reponame); |
6 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 6 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
7 | const char *filename, const char *query); | 7 | const char *filename, const char *query); |
8 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 8 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
9 | const char *query); | 9 | const char *query); |
10 | 10 | ||
11 | extern void cgit_index_link(char *name, char *title, char *class, | 11 | extern void cgit_index_link(char *name, char *title, char *class, |
12 | char *pattern, int ofs); | 12 | char *pattern, int ofs); |
13 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); | ||
13 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 14 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
14 | char *rev, char *path); | 15 | char *rev, char *path); |
15 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, | 16 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, |
16 | char *rev, char *path); | 17 | char *rev, char *path); |
17 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 18 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
18 | char *rev, char *path, int ofs, char *grep, | 19 | char *rev, char *path, int ofs, char *grep, |
19 | char *pattern); | 20 | char *pattern); |
20 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 21 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
21 | char *rev); | 22 | char *rev); |
22 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, | 23 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, |
23 | char *rev); | 24 | char *rev); |
24 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | 25 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
25 | char *rev, char *path); | 26 | char *rev, char *path); |
26 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 27 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
27 | char *head, char *rev, char *archivename); | 28 | char *head, char *rev, char *archivename); |
28 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 29 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
29 | char *new_rev, char *old_rev, char *path); | 30 | char *new_rev, char *old_rev, char *path); |
30 | extern void cgit_object_link(struct object *obj); | 31 | extern void cgit_object_link(struct object *obj); |
31 | 32 | ||
32 | extern void cgit_print_error(char *msg); | 33 | extern void cgit_print_error(char *msg); |
33 | extern void cgit_print_date(time_t secs, char *format, int local_time); | 34 | extern void cgit_print_date(time_t secs, char *format, int local_time); |
34 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 35 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
35 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 36 | extern void cgit_print_http_headers(struct cgit_context *ctx); |
36 | extern void cgit_print_docstart(struct cgit_context *ctx); | 37 | extern void cgit_print_docstart(struct cgit_context *ctx); |
37 | extern void cgit_print_docend(); | 38 | extern void cgit_print_docend(); |
38 | extern void cgit_print_pageheader(struct cgit_context *ctx); | 39 | extern void cgit_print_pageheader(struct cgit_context *ctx); |
39 | extern void cgit_print_filemode(unsigned short mode); | 40 | extern void cgit_print_filemode(unsigned short mode); |
40 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 41 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
41 | const char *hex, int snapshots); | 42 | const char *hex, int snapshots); |
42 | 43 | ||
43 | #endif /* UI_SHARED_H */ | 44 | #endif /* UI_SHARED_H */ |