author | Lars Hjemli <hjemli@gmail.com> | 2009-08-11 08:12:53 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-08-11 08:12:53 (UTC) |
commit | 2c742d1a925486a47f74710325b3076a7742a9f9 (patch) (unidiff) | |
tree | e16e8de4c65cb659a5b487ac3f8a7d7254fef395 /ui-shared.c | |
parent | fcc6056230e367e276dcb5a292d45e272cc6e7e6 (diff) | |
parent | 80550bbe028b551550395653d32a0ba50db540ef (diff) | |
download | cgit-2c742d1a925486a47f74710325b3076a7742a9f9.zip cgit-2c742d1a925486a47f74710325b3076a7742a9f9.tar.gz cgit-2c742d1a925486a47f74710325b3076a7742a9f9.tar.bz2 |
Merge branch 'lh/embedded'
-rw-r--r-- | ui-shared.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/ui-shared.c b/ui-shared.c index 015c52b..cf06511 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -31,43 +31,31 @@ void cgit_print_error(char *msg) | |||
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
34 | html("</div>\n"); | 34 | html("</div>\n"); |
35 | } | 35 | } |
36 | 36 | ||
37 | char *cgit_httpscheme() | 37 | char *cgit_httpscheme() |
38 | { | 38 | { |
39 | char *https; | 39 | if (ctx.env.https && !strcmp(ctx.env.https, "on")) |
40 | |||
41 | https = getenv("HTTPS"); | ||
42 | if (https != NULL && strcmp(https, "on") == 0) | ||
43 | return "https://"; | 40 | return "https://"; |
44 | else | 41 | else |
45 | return "http://"; | 42 | return "http://"; |
46 | } | 43 | } |
47 | 44 | ||
48 | char *cgit_hosturl() | 45 | char *cgit_hosturl() |
49 | { | 46 | { |
50 | char *host, *port; | 47 | if (ctx.env.http_host) |
51 | 48 | return ctx.env.http_host; | |
52 | host = getenv("HTTP_HOST"); | 49 | if (!ctx.env.server_name) |
53 | if (host) { | 50 | return NULL; |
54 | host = xstrdup(host); | 51 | if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) |
55 | } else { | 52 | return ctx.env.server_name; |
56 | host = getenv("SERVER_NAME"); | 53 | return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); |
57 | if (!host) | ||
58 | return NULL; | ||
59 | port = getenv("SERVER_PORT"); | ||
60 | if (port && atoi(port) != 80) | ||
61 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | ||
62 | else | ||
63 | host = xstrdup(host); | ||
64 | } | ||
65 | return host; | ||
66 | } | 54 | } |
67 | 55 | ||
68 | char *cgit_rooturl() | 56 | char *cgit_rooturl() |
69 | { | 57 | { |
70 | if (ctx.cfg.virtual_root) | 58 | if (ctx.cfg.virtual_root) |
71 | return fmt("%s/", ctx.cfg.virtual_root); | 59 | return fmt("%s/", ctx.cfg.virtual_root); |
72 | else | 60 | else |
73 | return ctx.cfg.script_name; | 61 | return ctx.cfg.script_name; |
@@ -462,19 +450,17 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
462 | return; | 450 | return; |
463 | } | 451 | } |
464 | htmlf("<span class='age-years'>%.0f years</span>", | 452 | htmlf("<span class='age-years'>%.0f years</span>", |
465 | secs * 1.0 / TM_YEAR); | 453 | secs * 1.0 / TM_YEAR); |
466 | } | 454 | } |
467 | 455 | ||
468 | void cgit_print_http_headers(struct cgit_context *ctx) | 456 | void cgit_print_http_headers(struct cgit_context *ctx) |
469 | { | 457 | { |
470 | const char *method = getenv("REQUEST_METHOD"); | 458 | if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) |
471 | |||
472 | if (ctx->cfg.embedded) | ||
473 | return; | 459 | return; |
474 | 460 | ||
475 | if (ctx->page.status) | 461 | if (ctx->page.status) |
476 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | 462 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); |
477 | if (ctx->page.mimetype && ctx->page.charset) | 463 | if (ctx->page.mimetype && ctx->page.charset) |
478 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 464 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
479 | ctx->page.charset); | 465 | ctx->page.charset); |
480 | else if (ctx->page.mimetype) | 466 | else if (ctx->page.mimetype) |
@@ -484,24 +470,27 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
484 | if (ctx->page.filename) | 470 | if (ctx->page.filename) |
485 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 471 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
486 | ctx->page.filename); | 472 | ctx->page.filename); |
487 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 473 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
488 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 474 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
489 | if (ctx->page.etag) | 475 | if (ctx->page.etag) |
490 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | 476 | htmlf("ETag: \"%s\"\n", ctx->page.etag); |
491 | html("\n"); | 477 | html("\n"); |
492 | if (method && !strcmp(method, "HEAD")) | 478 | if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) |
493 | exit(0); | 479 | exit(0); |
494 | } | 480 | } |
495 | 481 | ||
496 | void cgit_print_docstart(struct cgit_context *ctx) | 482 | void cgit_print_docstart(struct cgit_context *ctx) |
497 | { | 483 | { |
498 | if (ctx->cfg.embedded) | 484 | if (ctx->cfg.embedded) { |
485 | if (ctx->cfg.header) | ||
486 | html_include(ctx->cfg.header); | ||
499 | return; | 487 | return; |
488 | } | ||
500 | 489 | ||
501 | char *host = cgit_hosturl(); | 490 | char *host = cgit_hosturl(); |
502 | html(cgit_doctype); | 491 | html(cgit_doctype); |
503 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 492 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
504 | html("<head>\n"); | 493 | html("<head>\n"); |
505 | html("<title>"); | 494 | html("<title>"); |
506 | html_txt(ctx->page.title); | 495 | html_txt(ctx->page.title); |
507 | html("</title>\n"); | 496 | html("</title>\n"); |
@@ -529,28 +518,32 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
529 | html("</head>\n"); | 518 | html("</head>\n"); |
530 | html("<body>\n"); | 519 | html("<body>\n"); |
531 | if (ctx->cfg.header) | 520 | if (ctx->cfg.header) |
532 | html_include(ctx->cfg.header); | 521 | html_include(ctx->cfg.header); |
533 | } | 522 | } |
534 | 523 | ||
535 | void cgit_print_docend() | 524 | void cgit_print_docend() |
536 | { | 525 | { |
537 | html("</div>"); | 526 | html("</div> <!-- class=content -->\n"); |
527 | if (ctx.cfg.embedded) { | ||
528 | html("</div> <!-- id=cgit -->\n"); | ||
529 | if (ctx.cfg.footer) | ||
530 | html_include(ctx.cfg.footer); | ||
531 | return; | ||
532 | } | ||
538 | if (ctx.cfg.footer) | 533 | if (ctx.cfg.footer) |
539 | html_include(ctx.cfg.footer); | 534 | html_include(ctx.cfg.footer); |
540 | else { | 535 | else { |
541 | htmlf("<div class='footer'>generated by cgit %s at ", | 536 | htmlf("<div class='footer'>generated by cgit %s at ", |
542 | cgit_version); | 537 | cgit_version); |
543 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 538 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
544 | html("</div>\n"); | 539 | html("</div>\n"); |
545 | } | 540 | } |
546 | html("</div>"); | 541 | html("</div> <!-- id=cgit -->\n"); |
547 | if (ctx.cfg.embedded) | ||
548 | return; | ||
549 | html("</body>\n</html>\n"); | 542 | html("</body>\n</html>\n"); |
550 | } | 543 | } |
551 | 544 | ||
552 | int print_branch_option(const char *refname, const unsigned char *sha1, | 545 | int print_branch_option(const char *refname, const unsigned char *sha1, |
553 | int flags, void *cb_data) | 546 | int flags, void *cb_data) |
554 | { | 547 | { |
555 | char *name = (char *)refname; | 548 | char *name = (char *)refname; |
556 | html_option(name, name, ctx.qry.head); | 549 | html_option(name, name, ctx.qry.head); |