summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 6a41fb0..b96237d 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -33,47 +33,47 @@ static long ttl_seconds(long ttl)
33 return ttl * 60; 33 return ttl * 60;
34} 34}
35 35
36void cgit_print_error(char *msg) 36void cgit_print_error(char *msg)
37{ 37{
38 html("<div class='error'>"); 38 html("<div class='error'>");
39 html_txt(msg); 39 html_txt(msg);
40 html("</div>\n"); 40 html("</div>\n");
41} 41}
42 42
43char *cgit_rooturl() 43char *cgit_rooturl()
44{ 44{
45 if (cgit_virtual_root) 45 if (ctx.cfg.virtual_root)
46 return fmt("%s/", cgit_virtual_root); 46 return fmt("%s/", ctx.cfg.virtual_root);
47 else 47 else
48 return cgit_script_name; 48 return ctx.cfg.script_name;
49} 49}
50 50
51char *cgit_repourl(const char *reponame) 51char *cgit_repourl(const char *reponame)
52{ 52{
53 if (cgit_virtual_root) { 53 if (ctx.cfg.virtual_root) {
54 return fmt("%s/%s/", cgit_virtual_root, reponame); 54 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
55 } else { 55 } else {
56 return fmt("?r=%s", reponame); 56 return fmt("?r=%s", reponame);
57 } 57 }
58} 58}
59 59
60char *cgit_fileurl(const char *reponame, const char *pagename, 60char *cgit_fileurl(const char *reponame, const char *pagename,
61 const char *filename, const char *query) 61 const char *filename, const char *query)
62{ 62{
63 char *tmp; 63 char *tmp;
64 char *delim; 64 char *delim;
65 65
66 if (cgit_virtual_root) { 66 if (ctx.cfg.virtual_root) {
67 tmp = fmt("%s/%s/%s/%s", cgit_virtual_root, reponame, 67 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
68 pagename, (filename ? filename:"")); 68 pagename, (filename ? filename:""));
69 delim = "?"; 69 delim = "?";
70 } else { 70 } else {
71 tmp = fmt("?url=%s/%s/%s", reponame, pagename, 71 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
72 (filename ? filename : "")); 72 (filename ? filename : ""));
73 delim = "&"; 73 delim = "&";
74 } 74 }
75 if (query) 75 if (query)
76 tmp = fmt("%s%s%s", tmp, delim, query); 76 tmp = fmt("%s%s%s", tmp, delim, query);
77 return tmp; 77 return tmp;
78} 78}
79 79
@@ -101,66 +101,66 @@ const char *cgit_repobasename(const char *reponame)
101 } 101 }
102 /* strip more trailing slashes if any */ 102 /* strip more trailing slashes if any */
103 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 103 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
104 /* find last slash in the remaining string */ 104 /* find last slash in the remaining string */
105 rv = strrchr(rvbuf,'/'); 105 rv = strrchr(rvbuf,'/');
106 if(rv) 106 if(rv)
107 return ++rv; 107 return ++rv;
108 return rvbuf; 108 return rvbuf;
109} 109}
110 110
111char *cgit_currurl() 111char *cgit_currurl()
112{ 112{
113 if (!cgit_virtual_root) 113 if (!ctx.cfg.virtual_root)
114 return cgit_script_name; 114 return ctx.cfg.script_name;
115 else if (ctx.qry.page) 115 else if (ctx.qry.page)
116 return fmt("%s/%s/%s/", cgit_virtual_root, ctx.qry.repo, ctx.qry.page); 116 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
117 else if (ctx.qry.repo) 117 else if (ctx.qry.repo)
118 return fmt("%s/%s/", cgit_virtual_root, ctx.qry.repo); 118 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
119 else 119 else
120 return fmt("%s/", cgit_virtual_root); 120 return fmt("%s/", ctx.cfg.virtual_root);
121} 121}
122 122
123static char *repolink(char *title, char *class, char *page, char *head, 123static char *repolink(char *title, char *class, char *page, char *head,
124 char *path) 124 char *path)
125{ 125{
126 char *delim = "?"; 126 char *delim = "?";
127 127
128 html("<a"); 128 html("<a");
129 if (title) { 129 if (title) {
130 html(" title='"); 130 html(" title='");
131 html_attr(title); 131 html_attr(title);
132 html("'"); 132 html("'");
133 } 133 }
134 if (class) { 134 if (class) {
135 html(" class='"); 135 html(" class='");
136 html_attr(class); 136 html_attr(class);
137 html("'"); 137 html("'");
138 } 138 }
139 html(" href='"); 139 html(" href='");
140 if (cgit_virtual_root) { 140 if (ctx.cfg.virtual_root) {
141 html_attr(cgit_virtual_root); 141 html_attr(ctx.cfg.virtual_root);
142 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 142 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
143 html("/"); 143 html("/");
144 html_attr(cgit_repo->url); 144 html_attr(cgit_repo->url);
145 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 145 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
146 html("/"); 146 html("/");
147 if (page) { 147 if (page) {
148 html(page); 148 html(page);
149 html("/"); 149 html("/");
150 if (path) 150 if (path)
151 html_attr(path); 151 html_attr(path);
152 } 152 }
153 } else { 153 } else {
154 html(cgit_script_name); 154 html(ctx.cfg.script_name);
155 html("?url="); 155 html("?url=");
156 html_attr(cgit_repo->url); 156 html_attr(cgit_repo->url);
157 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 157 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
158 html("/"); 158 html("/");
159 if (page) { 159 if (page) {
160 html(page); 160 html(page);
161 html("/"); 161 html("/");
162 if (path) 162 if (path)
163 html_attr(path); 163 html_attr(path);
164 } 164 }
165 delim = "&amp;"; 165 delim = "&amp;";
166 } 166 }
@@ -220,29 +220,29 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
220 html(delim); 220 html(delim);
221 html("ofs="); 221 html("ofs=");
222 htmlf("%d", ofs); 222 htmlf("%d", ofs);
223 } 223 }
224 html("'>"); 224 html("'>");
225 html_txt(name); 225 html_txt(name);
226 html("</a>"); 226 html("</a>");
227} 227}
228 228
229void cgit_commit_link(char *name, char *title, char *class, char *head, 229void cgit_commit_link(char *name, char *title, char *class, char *head,
230 char *rev) 230 char *rev)
231{ 231{
232 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { 232 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
233 name[cgit_max_msg_len] = '\0'; 233 name[ctx.cfg.max_msg_len] = '\0';
234 name[cgit_max_msg_len - 1] = '.'; 234 name[ctx.cfg.max_msg_len - 1] = '.';
235 name[cgit_max_msg_len - 2] = '.'; 235 name[ctx.cfg.max_msg_len - 2] = '.';
236 name[cgit_max_msg_len - 3] = '.'; 236 name[ctx.cfg.max_msg_len - 3] = '.';
237 } 237 }
238 reporevlink("commit", name, title, class, head, rev, NULL); 238 reporevlink("commit", name, title, class, head, rev, NULL);
239} 239}
240 240
241void cgit_refs_link(char *name, char *title, char *class, char *head, 241void cgit_refs_link(char *name, char *title, char *class, char *head,
242 char *rev, char *path) 242 char *rev, char *path)
243{ 243{
244 reporevlink("refs", name, title, class, head, rev, path); 244 reporevlink("refs", name, title, class, head, rev, path);
245} 245}
246 246
247void cgit_snapshot_link(char *name, char *title, char *class, char *head, 247void cgit_snapshot_link(char *name, char *title, char *class, char *head,
248 char *rev, char *archivename) 248 char *rev, char *archivename)
@@ -365,28 +365,28 @@ void cgit_print_docstart(char *title, struct cacheitem *item)
365 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 365 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
367 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 367 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
368 ttl_seconds(item->ttl))); 368 ttl_seconds(item->ttl)));
369 html("\n"); 369 html("\n");
370 html(cgit_doctype); 370 html(cgit_doctype);
371 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 371 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
372 html("<head>\n"); 372 html("<head>\n");
373 html("<title>"); 373 html("<title>");
374 html_txt(title); 374 html_txt(title);
375 html("</title>\n"); 375 html("</title>\n");
376 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 376 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
377 if (cgit_robots && *cgit_robots) 377 if (ctx.cfg.robots && *ctx.cfg.robots)
378 htmlf("<meta name='robots' content='%s'/>\n", cgit_robots); 378 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots);
379 html("<link rel='stylesheet' type='text/css' href='"); 379 html("<link rel='stylesheet' type='text/css' href='");
380 html_attr(cgit_css); 380 html_attr(ctx.cfg.css);
381 html("'/>\n"); 381 html("'/>\n");
382 html("</head>\n"); 382 html("</head>\n");
383 html("<body>\n"); 383 html("<body>\n");
384} 384}
385 385
386void cgit_print_docend() 386void cgit_print_docend()
387{ 387{
388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); 388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
389} 389}
390 390
391int print_branch_option(const char *refname, const unsigned char *sha1, 391int print_branch_option(const char *refname, const unsigned char *sha1,
392 int flags, void *cb_data) 392 int flags, void *cb_data)
@@ -430,25 +430,25 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
431 buf)); 431 buf));
432 html_link_open(url, NULL, "menu"); 432 html_link_open(url, NULL, "menu");
433 html_txt(strlpart(buf, 20)); 433 html_txt(strlpart(buf, 20));
434 html_link_close(); 434 html_link_close();
435 return 0; 435 return 0;
436} 436}
437 437
438void add_hidden_formfields(int incl_head, int incl_search, char *page) 438void add_hidden_formfields(int incl_head, int incl_search, char *page)
439{ 439{
440 char *url; 440 char *url;
441 441
442 if (!cgit_virtual_root) { 442 if (!ctx.cfg.virtual_root) {
443 url = fmt("%s/%s", ctx.qry.repo, page); 443 url = fmt("%s/%s", ctx.qry.repo, page);
444 if (ctx.qry.path) 444 if (ctx.qry.path)
445 url = fmt("%s/%s", url, ctx.qry.path); 445 url = fmt("%s/%s", url, ctx.qry.path);
446 html_hidden("url", url); 446 html_hidden("url", url);
447 } 447 }
448 448
449 if (incl_head && strcmp(ctx.qry.head, cgit_repo->defbranch)) 449 if (incl_head && strcmp(ctx.qry.head, cgit_repo->defbranch))
450 html_hidden("h", ctx.qry.head); 450 html_hidden("h", ctx.qry.head);
451 451
452 if (ctx.qry.sha1) 452 if (ctx.qry.sha1)
453 html_hidden("id", ctx.qry.sha1); 453 html_hidden("id", ctx.qry.sha1);
454 if (ctx.qry.sha2) 454 if (ctx.qry.sha2)
@@ -465,25 +465,25 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
465void cgit_print_pageheader(char *title, int show_search) 465void cgit_print_pageheader(char *title, int show_search)
466{ 466{
467 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 467 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
468 int header = 0; 468 int header = 0;
469 char *url; 469 char *url;
470 470
471 html("<table id='layout' summary=''>\n"); 471 html("<table id='layout' summary=''>\n");
472 html("<tr><td id='sidebar'>\n"); 472 html("<tr><td id='sidebar'>\n");
473 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
474 html("<tr><td class='sidebar'>\n<a href='"); 474 html("<tr><td class='sidebar'>\n<a href='");
475 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
476 htmlf("'><img src='%s' alt='cgit'/></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
477 cgit_logo); 477 ctx.cfg.logo);
478 html("</td></tr>\n<tr><td class='sidebar'>\n"); 478 html("</td></tr>\n<tr><td class='sidebar'>\n");
479 if (ctx.qry.repo) { 479 if (ctx.qry.repo) {
480 html("<h1 class='first'>"); 480 html("<h1 class='first'>");
481 html_txt(strrpart(cgit_repo->name, 20)); 481 html_txt(strrpart(cgit_repo->name, 20));
482 html("</h1>\n"); 482 html("</h1>\n");
483 html_txt(cgit_repo->desc); 483 html_txt(cgit_repo->desc);
484 if (cgit_repo->owner) { 484 if (cgit_repo->owner) {
485 html("<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");
486 html_txt(cgit_repo->owner); 486 html_txt(cgit_repo->owner);
487 } 487 }
488 html("<h1>navigate</h1>\n"); 488 html("<h1>navigate</h1>\n");
489 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, 489 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head,
@@ -492,70 +492,70 @@ void cgit_print_pageheader(char *title, int show_search)
492 0, NULL, NULL); 492 0, NULL, NULL);
493 cgit_tree_link("tree", NULL, "menu", ctx.qry.head, 493 cgit_tree_link("tree", NULL, "menu", ctx.qry.head,
494 ctx.qry.sha1, NULL); 494 ctx.qry.sha1, NULL);
495 cgit_commit_link("commit", NULL, "menu", ctx.qry.head, 495 cgit_commit_link("commit", NULL, "menu", ctx.qry.head,
496 ctx.qry.sha1); 496 ctx.qry.sha1);
497 cgit_diff_link("diff", NULL, "menu", ctx.qry.head, 497 cgit_diff_link("diff", NULL, "menu", ctx.qry.head,
498 ctx.qry.sha1, ctx.qry.sha2, NULL); 498 ctx.qry.sha1, ctx.qry.sha2, NULL);
499 cgit_patch_link("patch", NULL, "menu", ctx.qry.head, 499 cgit_patch_link("patch", NULL, "menu", ctx.qry.head,
500 ctx.qry.sha1); 500 ctx.qry.sha1);
501 501
502 for_each_ref(print_archive_ref, &header); 502 for_each_ref(print_archive_ref, &header);
503 503
504 if (cgit_repo->clone_url || cgit_clone_prefix) { 504 if (cgit_repo->clone_url || ctx.cfg.clone_prefix) {
505 html("<h1>clone</h1>\n"); 505 html("<h1>clone</h1>\n");
506 if (cgit_repo->clone_url) 506 if (cgit_repo->clone_url)
507 url = cgit_repo->clone_url; 507 url = cgit_repo->clone_url;
508 else 508 else
509 url = fmt("%s%s", cgit_clone_prefix, 509 url = fmt("%s%s", ctx.cfg.clone_prefix,
510 cgit_repo->url); 510 cgit_repo->url);
511 html("<a class='menu' href='"); 511 html("<a class='menu' href='");
512 html_attr(url); 512 html_attr(url);
513 html("' title='"); 513 html("' title='");
514 html_attr(url); 514 html_attr(url);
515 html("'>\n"); 515 html("'>\n");
516 html_txt(strrpart(url, 20)); 516 html_txt(strrpart(url, 20));
517 html("</a>\n"); 517 html("</a>\n");
518 } 518 }
519 519
520 html("<h1>branch</h1>\n"); 520 html("<h1>branch</h1>\n");
521 html("<form method='get' action=''>\n"); 521 html("<form method='get' action=''>\n");
522 add_hidden_formfields(0, 1, ctx.qry.page); 522 add_hidden_formfields(0, 1, ctx.qry.page);
523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
524 html("<select name='h' onchange='this.form.submit();'>\n"); 524 html("<select name='h' onchange='this.form.submit();'>\n");
525 for_each_branch_ref(print_branch_option, ctx.qry.head); 525 for_each_branch_ref(print_branch_option, ctx.qry.head);
526 html("</select>\n"); 526 html("</select>\n");
527 // html("</td><td>"); 527 // html("</td><td>");
528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
529 // html("</td></tr></table>"); 529 // html("</td></tr></table>");
530 html("</form>\n"); 530 html("</form>\n");
531 531
532 html("<h1>search</h1>\n"); 532 html("<h1>search</h1>\n");
533 html("<form method='get' action='"); 533 html("<form method='get' action='");
534 if (cgit_virtual_root) 534 if (ctx.cfg.virtual_root)
535 html_attr(cgit_fileurl(ctx.qry.repo, "log", 535 html_attr(cgit_fileurl(ctx.qry.repo, "log",
536 ctx.qry.path, NULL)); 536 ctx.qry.path, NULL));
537 html("'>\n"); 537 html("'>\n");
538 add_hidden_formfields(1, 0, "log"); 538 add_hidden_formfields(1, 0, "log");
539 html("<select name='qt'>\n"); 539 html("<select name='qt'>\n");
540 html_option("grep", "log msg", ctx.qry.grep); 540 html_option("grep", "log msg", ctx.qry.grep);
541 html_option("author", "author", ctx.qry.grep); 541 html_option("author", "author", ctx.qry.grep);
542 html_option("committer", "committer", ctx.qry.grep); 542 html_option("committer", "committer", ctx.qry.grep);
543 html("</select>\n"); 543 html("</select>\n");
544 html("<input class='txt' type='text' name='q' value='"); 544 html("<input class='txt' type='text' name='q' value='");
545 html_attr(ctx.qry.search); 545 html_attr(ctx.qry.search);
546 html("'/>\n"); 546 html("'/>\n");
547 html("</form>\n"); 547 html("</form>\n");
548 } else { 548 } else {
549 if (!cgit_index_info || html_include(cgit_index_info)) 549 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info))
550 html(default_info); 550 html(default_info);
551 } 551 }
552 552
553 html("</td></tr></table></td>\n"); 553 html("</td></tr></table></td>\n");
554 554
555 html("<td id='content'>\n"); 555 html("<td id='content'>\n");
556} 556}
557 557
558 558
559void cgit_print_snapshot_start(const char *mimetype, const char *filename, 559void cgit_print_snapshot_start(const char *mimetype, const char *filename,
560 struct cacheitem *item) 560 struct cacheitem *item)
561{ 561{