aboutsummaryrefslogtreecommitdiffstats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2008-03-24 08:51:19 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2008-03-24 08:51:19 (JST)
commitf3c1a187fe2bc33f8423cd535d5045899699995b (patch)
treeb5c553da7b108900535fcfcd24b78bdd0ac62387 /ui-shared.c
parentb1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (diff)
downloadcgit-f3c1a187fe2bc33f8423cd535d5045899699995b.zip
cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.gz
Add struct cgit_page to cgit_context
This struct is used when generating http headers, and as such is another small step towards the goal of the whole cleanup series; to invoke each page/view function with a function pointer. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c112
1 files changed, 51 insertions, 61 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 2eff79d..2596023 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -26,14 +26,6 @@ static char *http_date(time_t t)
26 tm->tm_hour, tm->tm_min, tm->tm_sec); 26 tm->tm_hour, tm->tm_min, tm->tm_sec);
27} 27}
28 28
29static long ttl_seconds(long ttl)
30{
31 if (ttl<0)
32 return 60 * 60 * 24 * 365;
33 else
34 return ttl * 60;
35}
36
37void cgit_print_error(char *msg) 29void cgit_print_error(char *msg)
38{ 30{
39 html("<div class='error'>"); 31 html("<div class='error'>");
@@ -361,24 +353,34 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
361 secs * 1.0 / TM_YEAR); 353 secs * 1.0 / TM_YEAR);
362} 354}
363 355
364void cgit_print_docstart(char *title, struct cacheitem *item) 356void cgit_print_http_headers(struct cgit_context *ctx)
365{ 357{
366 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 358 if (ctx->page.mimetype && ctx->page.charset)
367 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 359 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
368 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 360 ctx->page.charset);
369 ttl_seconds(item->ttl))); 361 else if (ctx->page.mimetype)
362 htmlf("Content-Type: %s\n", ctx->page.mimetype);
363 if (ctx->page.filename)
364 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
365 ctx->page.filename);
366 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
367 htmlf("Expires: %s\n", http_date(ctx->page.expires));
370 html("\n"); 368 html("\n");
369}
370
371void cgit_print_docstart(struct cgit_context *ctx)
372{
371 html(cgit_doctype); 373 html(cgit_doctype);
372 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 374 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
373 html("<head>\n"); 375 html("<head>\n");
374 html("<title>"); 376 html("<title>");
375 html_txt(title); 377 html_txt(ctx->page.title);
376 html("</title>\n"); 378 html("</title>\n");
377 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 379 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
378 if (ctx.cfg.robots && *ctx.cfg.robots) 380 if (ctx->cfg.robots && *ctx->cfg.robots)
379 htmlf("<meta name='robots' content='%s'/>\n", ctx.cfg.robots); 381 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
380 html("<link rel='stylesheet' type='text/css' href='"); 382 html("<link rel='stylesheet' type='text/css' href='");
381 html_attr(ctx.cfg.css); 383 html_attr(ctx->cfg.css);
382 html("'/>\n"); 384 html("'/>\n");
383 html("</head>\n"); 385 html("</head>\n");
384 html("<body>\n"); 386 html("<body>\n");
@@ -463,7 +465,7 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
463 } 465 }
464} 466}
465 467
466void cgit_print_pageheader(char *title, int show_search) 468void cgit_print_pageheader(struct cgit_context *ctx)
467{ 469{
468 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 470 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
469 int header = 0; 471 int header = 0;
@@ -475,40 +477,40 @@ void cgit_print_pageheader(char *title, int show_search)
475 html("<tr><td class='sidebar'>\n<a href='"); 477 html("<tr><td class='sidebar'>\n<a href='");
476 html_attr(cgit_rooturl()); 478 html_attr(cgit_rooturl());
477 htmlf("'><img src='%s' alt='cgit'/></a>\n", 479 htmlf("'><img src='%s' alt='cgit'/></a>\n",
478 ctx.cfg.logo); 480 ctx->cfg.logo);
479 html("</td></tr>\n<tr><td class='sidebar'>\n"); 481 html("</td></tr>\n<tr><td class='sidebar'>\n");
480 if (ctx.repo) { 482 if (ctx->repo) {
481 html("<h1 class='first'>"); 483 html("<h1 class='first'>");
482 html_txt(strrpart(ctx.repo->name, 20)); 484 html_txt(strrpart(ctx->repo->name, 20));
483 html("</h1>\n"); 485 html("</h1>\n");
484 html_txt(ctx.repo->desc); 486 html_txt(ctx->repo->desc);
485 if (ctx.repo->owner) { 487 if (ctx->repo->owner) {
486 html("<h1>owner</h1>\n"); 488 html("<h1>owner</h1>\n");
487 html_txt(ctx.repo->owner); 489 html_txt(ctx->repo->owner);
488 } 490 }
489 html("<h1>navigate</h1>\n"); 491 html("<h1>navigate</h1>\n");
490 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, 492 reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head,
491 NULL, NULL); 493 NULL, NULL);
492 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, 494 cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL,
493 0, NULL, NULL); 495 0, NULL, NULL);
494 cgit_tree_link("tree", NULL, "menu", ctx.qry.head, 496 cgit_tree_link("tree", NULL, "menu", ctx->qry.head,
495 ctx.qry.sha1, NULL); 497 ctx->qry.sha1, NULL);
496 cgit_commit_link("commit", NULL, "menu", ctx.qry.head, 498 cgit_commit_link("commit", NULL, "menu", ctx->qry.head,
497 ctx.qry.sha1); 499 ctx->qry.sha1);
498 cgit_diff_link("diff", NULL, "menu", ctx.qry.head, 500 cgit_diff_link("diff", NULL, "menu", ctx->qry.head,
499 ctx.qry.sha1, ctx.qry.sha2, NULL); 501 ctx->qry.sha1, ctx->qry.sha2, NULL);
500 cgit_patch_link("patch", NULL, "menu", ctx.qry.head, 502 cgit_patch_link("patch", NULL, "menu", ctx->qry.head,
501 ctx.qry.sha1); 503 ctx->qry.sha1);
502 504
503 for_each_ref(print_archive_ref, &header); 505 for_each_ref(print_archive_ref, &header);
504 506
505 if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { 507 if (ctx->repo->clone_url || ctx->cfg.clone_prefix) {
506 html("<h1>clone</h1>\n"); 508 html("<h1>clone</h1>\n");
507 if (ctx.repo->clone_url) 509 if (ctx->repo->clone_url)
508 url = ctx.repo->clone_url; 510 url = ctx->repo->clone_url;
509 else 511 else
510 url = fmt("%s%s", ctx.cfg.clone_prefix, 512 url = fmt("%s%s", ctx->cfg.clone_prefix,
511 ctx.repo->url); 513 ctx->repo->url);
512 html("<a class='menu' href='"); 514 html("<a class='menu' href='");
513 html_attr(url); 515 html_attr(url);
514 html("' title='"); 516 html("' title='");
@@ -520,10 +522,10 @@ void cgit_print_pageheader(char *title, int show_search)
520 522
521 html("<h1>branch</h1>\n"); 523 html("<h1>branch</h1>\n");
522 html("<form method='get' action=''>\n"); 524 html("<form method='get' action=''>\n");
523 add_hidden_formfields(0, 1, ctx.qry.page); 525 add_hidden_formfields(0, 1, ctx->qry.page);
524// html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 526// html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
525 html("<select name='h' onchange='this.form.submit();'>\n"); 527 html("<select name='h' onchange='this.form.submit();'>\n");
526 for_each_branch_ref(print_branch_option, ctx.qry.head); 528 for_each_branch_ref(print_branch_option, ctx->qry.head);
527 html("</select>\n"); 529 html("</select>\n");
528// html("</td><td>"); 530// html("</td><td>");
529 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 531 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
@@ -532,22 +534,22 @@ void cgit_print_pageheader(char *title, int show_search)
532 534
533 html("<h1>search</h1>\n"); 535 html("<h1>search</h1>\n");
534 html("<form method='get' action='"); 536 html("<form method='get' action='");
535 if (ctx.cfg.virtual_root) 537 if (ctx->cfg.virtual_root)
536 html_attr(cgit_fileurl(ctx.qry.repo, "log", 538 html_attr(cgit_fileurl(ctx->qry.repo, "log",
537 ctx.qry.path, NULL)); 539 ctx->qry.path, NULL));
538 html("'>\n"); 540 html("'>\n");
539 add_hidden_formfields(1, 0, "log"); 541 add_hidden_formfields(1, 0, "log");
540 html("<select name='qt'>\n"); 542 html("<select name='qt'>\n");
541 html_option("grep", "log msg", ctx.qry.grep); 543 html_option("grep", "log msg", ctx->qry.grep);
542 html_option("author", "author", ctx.qry.grep); 544 html_option("author", "author", ctx->qry.grep);
543 html_option("committer", "committer", ctx.qry.grep); 545 html_option("committer", "committer", ctx->qry.grep);
544 html("</select>\n"); 546 html("</select>\n");
545 html("<input class='txt' type='text' name='q' value='"); 547 html("<input class='txt' type='text' name='q' value='");
546 html_attr(ctx.qry.search); 548 html_attr(ctx->qry.search);
547 html("'/>\n"); 549 html("'/>\n");
548 html("</form>\n"); 550 html("</form>\n");
549 } else { 551 } else {
550 if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info)) 552 if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info))
551 html(default_info); 553 html(default_info);
552 } 554 }
553 555
@@ -556,18 +558,6 @@ void cgit_print_pageheader(char *title, int show_search)
556 html("<td id='content'>\n"); 558 html("<td id='content'>\n");
557} 559}
558 560
559
560void cgit_print_snapshot_start(const char *mimetype, const char *filename,
561 struct cacheitem *item)
562{
563 htmlf("Content-Type: %s\n", mimetype);
564 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
565 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
566 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
567 ttl_seconds(item->ttl)));
568 html("\n");
569}
570
571void cgit_print_filemode(unsigned short mode) 561void cgit_print_filemode(unsigned short mode)
572{ 562{
573 if (S_ISDIR(mode)) 563 if (S_ISDIR(mode))