summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2008-10-05 15:16:48 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-10-05 15:16:48 (UTC)
commitc6bea0375aa7898ea3229483741944303740801e (patch) (unidiff)
tree249000a4b85dbab2a7067042f9d835bc0a5e5f8f
parent20c895f6889a66d7cf43c67a7c22df6ef324ed5d (diff)
parent49ecbbddf0659c6409befcfe8989f92196133cda (diff)
downloadcgit-c6bea0375aa7898ea3229483741944303740801e.zip
cgit-c6bea0375aa7898ea3229483741944303740801e.tar.gz
cgit-c6bea0375aa7898ea3229483741944303740801e.tar.bz2
Merge branch 'lh/escape-urls'
* lh/escape-urls: ui-repolist + ui-shared: Use cgit_summary_link() ui-shared.c: add cgit_summary_link() ui-shared.c: use html_url_path() in repolink() html.c: add html_url_path
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--html.c16
-rw-r--r--html.h1
-rw-r--r--ui-repolist.c8
-rw-r--r--ui-shared.c20
-rw-r--r--ui-shared.h1
5 files changed, 32 insertions, 14 deletions
diff --git a/html.c b/html.c
index 167127f..d7d9fd7 100644
--- a/html.c
+++ b/html.c
@@ -83,96 +83,112 @@ void html_txt(char *txt)
83 if (t!=txt) 83 if (t!=txt)
84 html(txt); 84 html(txt);
85} 85}
86 86
87void html_ntxt(int len, char *txt) 87void 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("&gt;"); 95 html("&gt;");
96 else if (c=='<') 96 else if (c=='<')
97 html("&lt;"); 97 html("&lt;");
98 else if (c=='&') 98 else if (c=='&')
99 html("&amp;"); 99 html("&amp;");
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
110void html_attr(char *txt) 110void 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("&gt;"); 118 html("&gt;");
119 else if (c=='<') 119 else if (c=='<')
120 html("&lt;"); 120 html("&lt;");
121 else if (c=='\'') 121 else if (c=='\'')
122 html("&quote;"); 122 html("&quote;");
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
131void 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
131void html_url_arg(char *txt) 147void 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
147void html_hidden(char *name, char *value) 163void 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
156void html_option(char *value, char *text, char *selected_value) 172void 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
168void html_link_open(char *url, char *title, char *class) 184void 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);
diff --git a/html.h b/html.h
index 038cf60..a55d4b2 100644
--- a/html.h
+++ b/html.h
@@ -1,23 +1,24 @@
1#ifndef HTML_H 1#ifndef HTML_H
2#define HTML_H 2#define HTML_H
3 3
4extern int htmlfd; 4extern int htmlfd;
5 5
6extern void html_raw(const char *txt, size_t size); 6extern void html_raw(const char *txt, size_t size);
7extern void html(const char *txt); 7extern void html(const char *txt);
8extern void htmlf(const char *format,...); 8extern void htmlf(const char *format,...);
9extern void html_status(int code, const char *msg, int more_headers); 9extern void html_status(int code, const char *msg, int more_headers);
10extern void html_txt(char *txt); 10extern void html_txt(char *txt);
11extern void html_ntxt(int len, char *txt); 11extern void html_ntxt(int len, char *txt);
12extern void html_attr(char *txt); 12extern void html_attr(char *txt);
13extern void html_url_path(char *txt);
13extern void html_url_arg(char *txt); 14extern void html_url_arg(char *txt);
14extern void html_hidden(char *name, char *value); 15extern void html_hidden(char *name, char *value);
15extern void html_option(char *value, char *text, char *selected_value); 16extern void html_option(char *value, char *text, char *selected_value);
16extern void html_link_open(char *url, char *title, char *class); 17extern void html_link_open(char *url, char *title, char *class);
17extern void html_link_close(void); 18extern void html_link_close(void);
18extern void html_fileperm(unsigned short mode); 19extern void html_fileperm(unsigned short mode);
19extern int html_include(const char *filename); 20extern int html_include(const char *filename);
20 21
21extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); 22extern 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
@@ -86,85 +86,81 @@ void print_pager(int items, int pagelen, char *search)
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
94void cgit_print_repolist() 94void 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
166void cgit_print_site_readme() 162void 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
@@ -161,147 +161,152 @@ static void site_url(char *page, char *search, int ofs)
161 } 161 }
162} 162}
163 163
164static void site_link(char *page, char *name, char *title, char *class, 164static 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
185void cgit_index_link(char *name, char *title, char *class, char *pattern, 185void 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
191static char *repolink(char *title, char *class, char *page, char *head, 191static 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 = "&amp;"; 233 delim = "&amp;";
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 = "&amp;"; 239 delim = "&amp;";
240 } 240 }
241 return fmt("%s", delim); 241 return fmt("%s", delim);
242} 242}
243 243
244static void reporevlink(char *page, char *name, char *title, char *class, 244static 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
260void cgit_summary_link(char *name, char *title, char *class, char *head)
261{
262 reporevlink(NULL, name, title, class, head, NULL, NULL);
263}
264
260void cgit_tree_link(char *name, char *title, char *class, char *head, 265void 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
266void cgit_plain_link(char *name, char *title, char *class, char *head, 271void 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
272void cgit_log_link(char *name, char *title, char *class, char *head, 277void 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
303void cgit_commit_link(char *name, char *title, char *class, char *head, 308void 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';
@@ -553,127 +558,126 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
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
577char *hc(struct cgit_cmd *cmd, const char *page) 582char *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
582void cgit_print_pageheader(struct cgit_context *ctx) 587void 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'>");
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
4extern char *cgit_hosturl(); 4extern char *cgit_hosturl();
5extern char *cgit_repourl(const char *reponame); 5extern char *cgit_repourl(const char *reponame);
6extern char *cgit_fileurl(const char *reponame, const char *pagename, 6extern char *cgit_fileurl(const char *reponame, const char *pagename,
7 const char *filename, const char *query); 7 const char *filename, const char *query);
8extern char *cgit_pageurl(const char *reponame, const char *pagename, 8extern char *cgit_pageurl(const char *reponame, const char *pagename,
9 const char *query); 9 const char *query);
10 10
11extern void cgit_index_link(char *name, char *title, char *class, 11extern void cgit_index_link(char *name, char *title, char *class,
12 char *pattern, int ofs); 12 char *pattern, int ofs);
13extern void cgit_summary_link(char *name, char *title, char *class, char *head);
13extern void cgit_tree_link(char *name, char *title, char *class, char *head, 14extern void cgit_tree_link(char *name, char *title, char *class, char *head,
14 char *rev, char *path); 15 char *rev, char *path);
15extern void cgit_plain_link(char *name, char *title, char *class, char *head, 16extern void cgit_plain_link(char *name, char *title, char *class, char *head,
16 char *rev, char *path); 17 char *rev, char *path);
17extern void cgit_log_link(char *name, char *title, char *class, char *head, 18extern 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);
20extern void cgit_commit_link(char *name, char *title, char *class, char *head, 21extern void cgit_commit_link(char *name, char *title, char *class, char *head,
21 char *rev); 22 char *rev);
22extern void cgit_patch_link(char *name, char *title, char *class, char *head, 23extern void cgit_patch_link(char *name, char *title, char *class, char *head,
23 char *rev); 24 char *rev);
24extern void cgit_refs_link(char *name, char *title, char *class, char *head, 25extern void cgit_refs_link(char *name, char *title, char *class, char *head,
25 char *rev, char *path); 26 char *rev, char *path);
26extern void cgit_snapshot_link(char *name, char *title, char *class, 27extern void cgit_snapshot_link(char *name, char *title, char *class,
27 char *head, char *rev, char *archivename); 28 char *head, char *rev, char *archivename);
28extern void cgit_diff_link(char *name, char *title, char *class, char *head, 29extern 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);
30extern void cgit_object_link(struct object *obj); 31extern void cgit_object_link(struct object *obj);
31 32
32extern void cgit_print_error(char *msg); 33extern void cgit_print_error(char *msg);
33extern void cgit_print_date(time_t secs, char *format, int local_time); 34extern void cgit_print_date(time_t secs, char *format, int local_time);
34extern void cgit_print_age(time_t t, time_t max_relative, char *format); 35extern void cgit_print_age(time_t t, time_t max_relative, char *format);
35extern void cgit_print_http_headers(struct cgit_context *ctx); 36extern void cgit_print_http_headers(struct cgit_context *ctx);
36extern void cgit_print_docstart(struct cgit_context *ctx); 37extern void cgit_print_docstart(struct cgit_context *ctx);
37extern void cgit_print_docend(); 38extern void cgit_print_docend();
38extern void cgit_print_pageheader(struct cgit_context *ctx); 39extern void cgit_print_pageheader(struct cgit_context *ctx);
39extern void cgit_print_filemode(unsigned short mode); 40extern void cgit_print_filemode(unsigned short mode);
40extern void cgit_print_snapshot_links(const char *repo, const char *head, 41extern 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 */