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
@@ -119,24 +119,40 @@ void html_attr(char *txt)
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 }
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
@@ -122,41 +122,37 @@ void cgit_print_repolist()
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);
diff --git a/ui-shared.c b/ui-shared.c
index a2f636c..1fc5c09 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -197,35 +197,35 @@ static char *repolink(char *title, char *class, char *page, char *head,
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);
@@ -248,24 +248,29 @@ static void reporevlink(char *page, char *name, char *title, char *class,
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
@@ -589,26 +594,25 @@ void cgit_print_pageheader(struct cgit_context *ctx)
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
@@ -618,26 +622,26 @@ void cgit_print_pageheader(struct cgit_context *ctx)
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,
diff --git a/ui-shared.h b/ui-shared.h
index 747f092..0cd5ed1 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,24 +1,25 @@
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,