diff options
author | Lars Hjemli | 2009-08-11 10:12:53 +0200 |
---|---|---|
committer | Lars Hjemli | 2009-08-11 10:12:53 +0200 |
commit | 2c742d1a925486a47f74710325b3076a7742a9f9 (patch) | |
tree | e16e8de4c65cb659a5b487ac3f8a7d7254fef395 /ui-shared.c | |
parent | fcc6056230e367e276dcb5a292d45e272cc6e7e6 (diff) | |
parent | 80550bbe028b551550395653d32a0ba50db540ef (diff) | |
download | cgit-2c742d1a925486a47f74710325b3076a7742a9f9.tar.gz cgit-2c742d1a925486a47f74710325b3076a7742a9f9.tar.bz2 cgit-2c742d1a925486a47f74710325b3076a7742a9f9.zip |
Merge branch 'lh/embedded'
Diffstat (limited to 'ui-shared.c')
-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 | |||
@@ -36,10 +36,7 @@ void cgit_print_error(char *msg) | |||
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://"; |
@@ -47,22 +44,13 @@ char *cgit_httpscheme() | |||
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() |
@@ -467,9 +455,7 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
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) |
@@ -489,14 +475,17 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
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); |
@@ -534,7 +523,13 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
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 { |
@@ -543,9 +538,7 @@ void cgit_print_docend() | |||
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 | ||