summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 29036d0..10be3c0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -342,271 +342,277 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
342 342
343void cgit_refs_link(char *name, char *title, char *class, char *head, 343void cgit_refs_link(char *name, char *title, char *class, char *head,
344 char *rev, char *path) 344 char *rev, char *path)
345{ 345{
346 reporevlink("refs", name, title, class, head, rev, path); 346 reporevlink("refs", name, title, class, head, rev, path);
347} 347}
348 348
349void cgit_snapshot_link(char *name, char *title, char *class, char *head, 349void cgit_snapshot_link(char *name, char *title, char *class, char *head,
350 char *rev, char *archivename) 350 char *rev, char *archivename)
351{ 351{
352 reporevlink("snapshot", name, title, class, head, rev, archivename); 352 reporevlink("snapshot", name, title, class, head, rev, archivename);
353} 353}
354 354
355void cgit_diff_link(char *name, char *title, char *class, char *head, 355void cgit_diff_link(char *name, char *title, char *class, char *head,
356 char *new_rev, char *old_rev, char *path) 356 char *new_rev, char *old_rev, char *path)
357{ 357{
358 char *delim; 358 char *delim;
359 359
360 delim = repolink(title, class, "diff", head, path); 360 delim = repolink(title, class, "diff", head, path);
361 if (new_rev && strcmp(new_rev, ctx.qry.head)) { 361 if (new_rev && strcmp(new_rev, ctx.qry.head)) {
362 html(delim); 362 html(delim);
363 html("id="); 363 html("id=");
364 html_url_arg(new_rev); 364 html_url_arg(new_rev);
365 delim = "&"; 365 delim = "&";
366 } 366 }
367 if (old_rev) { 367 if (old_rev) {
368 html(delim); 368 html(delim);
369 html("id2="); 369 html("id2=");
370 html_url_arg(old_rev); 370 html_url_arg(old_rev);
371 } 371 }
372 html("'>"); 372 html("'>");
373 html_txt(name); 373 html_txt(name);
374 html("</a>"); 374 html("</a>");
375} 375}
376 376
377void cgit_patch_link(char *name, char *title, char *class, char *head, 377void cgit_patch_link(char *name, char *title, char *class, char *head,
378 char *rev) 378 char *rev)
379{ 379{
380 reporevlink("patch", name, title, class, head, rev, NULL); 380 reporevlink("patch", name, title, class, head, rev, NULL);
381} 381}
382 382
383void cgit_stats_link(char *name, char *title, char *class, char *head, 383void cgit_stats_link(char *name, char *title, char *class, char *head,
384 char *path) 384 char *path)
385{ 385{
386 reporevlink("stats", name, title, class, head, NULL, path); 386 reporevlink("stats", name, title, class, head, NULL, path);
387} 387}
388 388
389void cgit_object_link(struct object *obj) 389void cgit_object_link(struct object *obj)
390{ 390{
391 char *page, *shortrev, *fullrev, *name; 391 char *page, *shortrev, *fullrev, *name;
392 392
393 fullrev = sha1_to_hex(obj->sha1); 393 fullrev = sha1_to_hex(obj->sha1);
394 shortrev = xstrdup(fullrev); 394 shortrev = xstrdup(fullrev);
395 shortrev[10] = '\0'; 395 shortrev[10] = '\0';
396 if (obj->type == OBJ_COMMIT) { 396 if (obj->type == OBJ_COMMIT) {
397 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, 397 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
398 ctx.qry.head, fullrev); 398 ctx.qry.head, fullrev);
399 return; 399 return;
400 } else if (obj->type == OBJ_TREE) 400 } else if (obj->type == OBJ_TREE)
401 page = "tree"; 401 page = "tree";
402 else if (obj->type == OBJ_TAG) 402 else if (obj->type == OBJ_TAG)
403 page = "tag"; 403 page = "tag";
404 else 404 else
405 page = "blob"; 405 page = "blob";
406 name = fmt("%s %s...", typename(obj->type), shortrev); 406 name = fmt("%s %s...", typename(obj->type), shortrev);
407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
408} 408}
409 409
410void cgit_print_date(time_t secs, char *format, int local_time) 410void cgit_print_date(time_t secs, char *format, int local_time)
411{ 411{
412 char buf[64]; 412 char buf[64];
413 struct tm *time; 413 struct tm *time;
414 414
415 if (!secs) 415 if (!secs)
416 return; 416 return;
417 if(local_time) 417 if(local_time)
418 time = localtime(&secs); 418 time = localtime(&secs);
419 else 419 else
420 time = gmtime(&secs); 420 time = gmtime(&secs);
421 strftime(buf, sizeof(buf)-1, format, time); 421 strftime(buf, sizeof(buf)-1, format, time);
422 html_txt(buf); 422 html_txt(buf);
423} 423}
424 424
425void cgit_print_age(time_t t, time_t max_relative, char *format) 425void cgit_print_age(time_t t, time_t max_relative, char *format)
426{ 426{
427 time_t now, secs; 427 time_t now, secs;
428 428
429 if (!t) 429 if (!t)
430 return; 430 return;
431 time(&now); 431 time(&now);
432 secs = now - t; 432 secs = now - t;
433 433
434 if (secs > max_relative && max_relative >= 0) { 434 if (secs > max_relative && max_relative >= 0) {
435 cgit_print_date(t, format, ctx.cfg.local_time); 435 cgit_print_date(t, format, ctx.cfg.local_time);
436 return; 436 return;
437 } 437 }
438 438
439 if (secs < TM_HOUR * 2) { 439 if (secs < TM_HOUR * 2) {
440 htmlf("<span class='age-mins'>%.0f min.</span>", 440 htmlf("<span class='age-mins'>%.0f min.</span>",
441 secs * 1.0 / TM_MIN); 441 secs * 1.0 / TM_MIN);
442 return; 442 return;
443 } 443 }
444 if (secs < TM_DAY * 2) { 444 if (secs < TM_DAY * 2) {
445 htmlf("<span class='age-hours'>%.0f hours</span>", 445 htmlf("<span class='age-hours'>%.0f hours</span>",
446 secs * 1.0 / TM_HOUR); 446 secs * 1.0 / TM_HOUR);
447 return; 447 return;
448 } 448 }
449 if (secs < TM_WEEK * 2) { 449 if (secs < TM_WEEK * 2) {
450 htmlf("<span class='age-days'>%.0f days</span>", 450 htmlf("<span class='age-days'>%.0f days</span>",
451 secs * 1.0 / TM_DAY); 451 secs * 1.0 / TM_DAY);
452 return; 452 return;
453 } 453 }
454 if (secs < TM_MONTH * 2) { 454 if (secs < TM_MONTH * 2) {
455 htmlf("<span class='age-weeks'>%.0f weeks</span>", 455 htmlf("<span class='age-weeks'>%.0f weeks</span>",
456 secs * 1.0 / TM_WEEK); 456 secs * 1.0 / TM_WEEK);
457 return; 457 return;
458 } 458 }
459 if (secs < TM_YEAR * 2) { 459 if (secs < TM_YEAR * 2) {
460 htmlf("<span class='age-months'>%.0f months</span>", 460 htmlf("<span class='age-months'>%.0f months</span>",
461 secs * 1.0 / TM_MONTH); 461 secs * 1.0 / TM_MONTH);
462 return; 462 return;
463 } 463 }
464 htmlf("<span class='age-years'>%.0f years</span>", 464 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 465 secs * 1.0 / TM_YEAR);
466} 466}
467 467
468void cgit_print_http_headers(struct cgit_context *ctx) 468void cgit_print_http_headers(struct cgit_context *ctx)
469{ 469{
470 const char *method = getenv("REQUEST_METHOD");
471
470 if (ctx->page.status) 472 if (ctx->page.status)
471 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 473 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
472 if (ctx->page.mimetype && ctx->page.charset) 474 if (ctx->page.mimetype && ctx->page.charset)
473 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 475 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
474 ctx->page.charset); 476 ctx->page.charset);
475 else if (ctx->page.mimetype) 477 else if (ctx->page.mimetype)
476 htmlf("Content-Type: %s\n", ctx->page.mimetype); 478 htmlf("Content-Type: %s\n", ctx->page.mimetype);
477 if (ctx->page.size) 479 if (ctx->page.size)
478 htmlf("Content-Length: %ld\n", ctx->page.size); 480 htmlf("Content-Length: %ld\n", ctx->page.size);
479 if (ctx->page.filename) 481 if (ctx->page.filename)
480 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 482 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
481 ctx->page.filename); 483 ctx->page.filename);
482 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 484 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
483 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 485 htmlf("Expires: %s\n", http_date(ctx->page.expires));
486 if (ctx->page.etag)
487 htmlf("ETag: \"%s\"\n", ctx->page.etag);
484 html("\n"); 488 html("\n");
489 if (method && !strcmp(method, "HEAD"))
490 exit(0);
485} 491}
486 492
487void cgit_print_docstart(struct cgit_context *ctx) 493void cgit_print_docstart(struct cgit_context *ctx)
488{ 494{
489 char *host = cgit_hosturl(); 495 char *host = cgit_hosturl();
490 html(cgit_doctype); 496 html(cgit_doctype);
491 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 497 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
492 html("<head>\n"); 498 html("<head>\n");
493 html("<title>"); 499 html("<title>");
494 html_txt(ctx->page.title); 500 html_txt(ctx->page.title);
495 html("</title>\n"); 501 html("</title>\n");
496 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 502 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
497 if (ctx->cfg.robots && *ctx->cfg.robots) 503 if (ctx->cfg.robots && *ctx->cfg.robots)
498 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); 504 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
499 html("<link rel='stylesheet' type='text/css' href='"); 505 html("<link rel='stylesheet' type='text/css' href='");
500 html_attr(ctx->cfg.css); 506 html_attr(ctx->cfg.css);
501 html("'/>\n"); 507 html("'/>\n");
502 if (ctx->cfg.favicon) { 508 if (ctx->cfg.favicon) {
503 html("<link rel='shortcut icon' href='"); 509 html("<link rel='shortcut icon' href='");
504 html_attr(ctx->cfg.favicon); 510 html_attr(ctx->cfg.favicon);
505 html("'/>\n"); 511 html("'/>\n");
506 } 512 }
507 if (host && ctx->repo) { 513 if (host && ctx->repo) {
508 html("<link rel='alternate' title='Atom feed' href='"); 514 html("<link rel='alternate' title='Atom feed' href='");
509 html(cgit_httpscheme()); 515 html(cgit_httpscheme());
510 html_attr(cgit_hosturl()); 516 html_attr(cgit_hosturl());
511 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, 517 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
512 fmt("h=%s", ctx->qry.head))); 518 fmt("h=%s", ctx->qry.head)));
513 html("' type='application/atom+xml'/>"); 519 html("' type='application/atom+xml'/>");
514 } 520 }
515 html("</head>\n"); 521 html("</head>\n");
516 html("<body>\n"); 522 html("<body>\n");
517 if (ctx->cfg.header) 523 if (ctx->cfg.header)
518 html_include(ctx->cfg.header); 524 html_include(ctx->cfg.header);
519} 525}
520 526
521void cgit_print_docend() 527void cgit_print_docend()
522{ 528{
523 html("</div>"); 529 html("</div>");
524 if (ctx.cfg.footer) 530 if (ctx.cfg.footer)
525 html_include(ctx.cfg.footer); 531 html_include(ctx.cfg.footer);
526 else { 532 else {
527 htmlf("<div class='footer'>generated by cgit %s at ", 533 htmlf("<div class='footer'>generated by cgit %s at ",
528 cgit_version); 534 cgit_version);
529 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); 535 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
530 html("</div>\n"); 536 html("</div>\n");
531 } 537 }
532 html("</body>\n</html>\n"); 538 html("</body>\n</html>\n");
533} 539}
534 540
535int print_branch_option(const char *refname, const unsigned char *sha1, 541int print_branch_option(const char *refname, const unsigned char *sha1,
536 int flags, void *cb_data) 542 int flags, void *cb_data)
537{ 543{
538 char *name = (char *)refname; 544 char *name = (char *)refname;
539 html_option(name, name, ctx.qry.head); 545 html_option(name, name, ctx.qry.head);
540 return 0; 546 return 0;
541} 547}
542 548
543int print_archive_ref(const char *refname, const unsigned char *sha1, 549int print_archive_ref(const char *refname, const unsigned char *sha1,
544 int flags, void *cb_data) 550 int flags, void *cb_data)
545{ 551{
546 struct tag *tag; 552 struct tag *tag;
547 struct taginfo *info; 553 struct taginfo *info;
548 struct object *obj; 554 struct object *obj;
549 char buf[256], *url; 555 char buf[256], *url;
550 unsigned char fileid[20]; 556 unsigned char fileid[20];
551 int *header = (int *)cb_data; 557 int *header = (int *)cb_data;
552 558
553 if (prefixcmp(refname, "refs/archives")) 559 if (prefixcmp(refname, "refs/archives"))
554 return 0; 560 return 0;
555 strncpy(buf, refname+14, sizeof(buf)); 561 strncpy(buf, refname+14, sizeof(buf));
556 obj = parse_object(sha1); 562 obj = parse_object(sha1);
557 if (!obj) 563 if (!obj)
558 return 1; 564 return 1;
559 if (obj->type == OBJ_TAG) { 565 if (obj->type == OBJ_TAG) {
560 tag = lookup_tag(sha1); 566 tag = lookup_tag(sha1);
561 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 567 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
562 return 0; 568 return 0;
563 hashcpy(fileid, tag->tagged->sha1); 569 hashcpy(fileid, tag->tagged->sha1);
564 } else if (obj->type != OBJ_BLOB) { 570 } else if (obj->type != OBJ_BLOB) {
565 return 0; 571 return 0;
566 } else { 572 } else {
567 hashcpy(fileid, sha1); 573 hashcpy(fileid, sha1);
568 } 574 }
569 if (!*header) { 575 if (!*header) {
570 html("<h1>download</h1>\n"); 576 html("<h1>download</h1>\n");
571 *header = 1; 577 *header = 1;
572 } 578 }
573 url = cgit_pageurl(ctx.qry.repo, "blob", 579 url = cgit_pageurl(ctx.qry.repo, "blob",
574 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 580 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
575 buf)); 581 buf));
576 html_link_open(url, NULL, "menu"); 582 html_link_open(url, NULL, "menu");
577 html_txt(strlpart(buf, 20)); 583 html_txt(strlpart(buf, 20));
578 html_link_close(); 584 html_link_close();
579 return 0; 585 return 0;
580} 586}
581 587
582void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page) 588void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
583{ 589{
584 char *url; 590 char *url;
585 591
586 if (!ctx.cfg.virtual_root) { 592 if (!ctx.cfg.virtual_root) {
587 url = fmt("%s/%s", ctx.qry.repo, page); 593 url = fmt("%s/%s", ctx.qry.repo, page);
588 if (ctx.qry.path) 594 if (ctx.qry.path)
589 url = fmt("%s/%s", url, ctx.qry.path); 595 url = fmt("%s/%s", url, ctx.qry.path);
590 html_hidden("url", url); 596 html_hidden("url", url);
591 } 597 }
592 598
593 if (incl_head && ctx.qry.head && ctx.repo->defbranch && 599 if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
594 strcmp(ctx.qry.head, ctx.repo->defbranch)) 600 strcmp(ctx.qry.head, ctx.repo->defbranch))
595 html_hidden("h", ctx.qry.head); 601 html_hidden("h", ctx.qry.head);
596 602
597 if (ctx.qry.sha1) 603 if (ctx.qry.sha1)
598 html_hidden("id", ctx.qry.sha1); 604 html_hidden("id", ctx.qry.sha1);
599 if (ctx.qry.sha2) 605 if (ctx.qry.sha2)
600 html_hidden("id2", ctx.qry.sha2); 606 html_hidden("id2", ctx.qry.sha2);
601 if (ctx.qry.showmsg) 607 if (ctx.qry.showmsg)
602 html_hidden("showmsg", "1"); 608 html_hidden("showmsg", "1");
603 609
604 if (incl_search) { 610 if (incl_search) {
605 if (ctx.qry.grep) 611 if (ctx.qry.grep)
606 html_hidden("qt", ctx.qry.grep); 612 html_hidden("qt", ctx.qry.grep);
607 if (ctx.qry.search) 613 if (ctx.qry.search)
608 html_hidden("q", ctx.qry.search); 614 html_hidden("q", ctx.qry.search);
609 } 615 }
610} 616}
611 617
612const char *fallback_cmd = "repolist"; 618const char *fallback_cmd = "repolist";