author | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:40:25 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-07-25 09:41:06 (UTC) |
commit | fbe091a716447be496519ce439451d36d5b9fc24 (patch) (unidiff) | |
tree | c6560c6f2ab6b4760ac6eaecda1759321da2746e | |
parent | e429fb0cca1e8c78da0ec38fe578bafdeec65534 (diff) | |
parent | 694dd43886f23723f415aed3afb62131cdbcaa51 (diff) | |
download | cgit-fbe091a716447be496519ce439451d36d5b9fc24.zip cgit-fbe091a716447be496519ce439451d36d5b9fc24.tar.gz cgit-fbe091a716447be496519ce439451d36d5b9fc24.tar.bz2 |
Merge branch 'do/https'
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-atom.c | 6 | ||||
-rw-r--r-- | ui-shared.c | 14 | ||||
-rw-r--r-- | ui-shared.h | 1 |
3 files changed, 18 insertions, 3 deletions
@@ -1,129 +1,131 @@ | |||
1 | /* ui-atom.c: functions for atom feeds | 1 | /* ui-atom.c: functions for atom feeds |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | void add_entry(struct commit *commit, char *host) | 13 | void add_entry(struct commit *commit, char *host) |
14 | { | 14 | { |
15 | char delim = '&'; | 15 | char delim = '&'; |
16 | char *hex; | 16 | char *hex; |
17 | char *mail, *t, *t2; | 17 | char *mail, *t, *t2; |
18 | struct commitinfo *info; | 18 | struct commitinfo *info; |
19 | 19 | ||
20 | info = cgit_parse_commit(commit); | 20 | info = cgit_parse_commit(commit); |
21 | hex = sha1_to_hex(commit->object.sha1); | 21 | hex = sha1_to_hex(commit->object.sha1); |
22 | html("<entry>\n"); | 22 | html("<entry>\n"); |
23 | html("<title>"); | 23 | html("<title>"); |
24 | html_txt(info->subject); | 24 | html_txt(info->subject); |
25 | html("</title>\n"); | 25 | html("</title>\n"); |
26 | html("<updated>"); | 26 | html("<updated>"); |
27 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); | 27 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); |
28 | html("</updated>\n"); | 28 | html("</updated>\n"); |
29 | html("<author>\n"); | 29 | html("<author>\n"); |
30 | if (info->author) { | 30 | if (info->author) { |
31 | html("<name>"); | 31 | html("<name>"); |
32 | html_txt(info->author); | 32 | html_txt(info->author); |
33 | html("</name>\n"); | 33 | html("</name>\n"); |
34 | } | 34 | } |
35 | if (info->author_email) { | 35 | if (info->author_email) { |
36 | mail = xstrdup(info->author_email); | 36 | mail = xstrdup(info->author_email); |
37 | t = strchr(mail, '<'); | 37 | t = strchr(mail, '<'); |
38 | if (t) | 38 | if (t) |
39 | t++; | 39 | t++; |
40 | else | 40 | else |
41 | t = mail; | 41 | t = mail; |
42 | t2 = strchr(t, '>'); | 42 | t2 = strchr(t, '>'); |
43 | if (t2) | 43 | if (t2) |
44 | *t2 = '\0'; | 44 | *t2 = '\0'; |
45 | html("<email>"); | 45 | html("<email>"); |
46 | html_txt(t); | 46 | html_txt(t); |
47 | html("</email>\n"); | 47 | html("</email>\n"); |
48 | free(mail); | 48 | free(mail); |
49 | } | 49 | } |
50 | html("</author>\n"); | 50 | html("</author>\n"); |
51 | html("<published>"); | 51 | html("<published>"); |
52 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); | 52 | cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); |
53 | html("</published>\n"); | 53 | html("</published>\n"); |
54 | if (host) { | 54 | if (host) { |
55 | html("<link rel='alternate' type='text/html' href='http://"); | 55 | html("<link rel='alternate' type='text/html' href='"); |
56 | html(cgit_httpscheme()); | ||
56 | html_attr(host); | 57 | html_attr(host); |
57 | html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL)); | 58 | html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL)); |
58 | if (ctx.cfg.virtual_root) | 59 | if (ctx.cfg.virtual_root) |
59 | delim = '?'; | 60 | delim = '?'; |
60 | htmlf("%cid=%s", delim, hex); | 61 | htmlf("%cid=%s", delim, hex); |
61 | html("'/>\n"); | 62 | html("'/>\n"); |
62 | } | 63 | } |
63 | htmlf("<id>%s</id>\n", hex); | 64 | htmlf("<id>%s</id>\n", hex); |
64 | html("<content type='text'>\n"); | 65 | html("<content type='text'>\n"); |
65 | html_txt(info->msg); | 66 | html_txt(info->msg); |
66 | html("</content>\n"); | 67 | html("</content>\n"); |
67 | html("<content type='xhtml'>\n"); | 68 | html("<content type='xhtml'>\n"); |
68 | html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); | 69 | html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); |
69 | html("<pre>\n"); | 70 | html("<pre>\n"); |
70 | html_txt(info->msg); | 71 | html_txt(info->msg); |
71 | html("</pre>\n"); | 72 | html("</pre>\n"); |
72 | html("</div>\n"); | 73 | html("</div>\n"); |
73 | html("</content>\n"); | 74 | html("</content>\n"); |
74 | html("</entry>\n"); | 75 | html("</entry>\n"); |
75 | cgit_free_commitinfo(info); | 76 | cgit_free_commitinfo(info); |
76 | } | 77 | } |
77 | 78 | ||
78 | 79 | ||
79 | void cgit_print_atom(char *tip, char *path, int max_count) | 80 | void cgit_print_atom(char *tip, char *path, int max_count) |
80 | { | 81 | { |
81 | char *host; | 82 | char *host; |
82 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 83 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
83 | struct commit *commit; | 84 | struct commit *commit; |
84 | struct rev_info rev; | 85 | struct rev_info rev; |
85 | int argc = 2; | 86 | int argc = 2; |
86 | 87 | ||
87 | if (!tip) | 88 | if (!tip) |
88 | argv[1] = ctx.qry.head; | 89 | argv[1] = ctx.qry.head; |
89 | 90 | ||
90 | if (path) { | 91 | if (path) { |
91 | argv[argc++] = "--"; | 92 | argv[argc++] = "--"; |
92 | argv[argc++] = path; | 93 | argv[argc++] = path; |
93 | } | 94 | } |
94 | 95 | ||
95 | init_revisions(&rev, NULL); | 96 | init_revisions(&rev, NULL); |
96 | rev.abbrev = DEFAULT_ABBREV; | 97 | rev.abbrev = DEFAULT_ABBREV; |
97 | rev.commit_format = CMIT_FMT_DEFAULT; | 98 | rev.commit_format = CMIT_FMT_DEFAULT; |
98 | rev.verbose_header = 1; | 99 | rev.verbose_header = 1; |
99 | rev.show_root_diff = 0; | 100 | rev.show_root_diff = 0; |
100 | rev.max_count = max_count; | 101 | rev.max_count = max_count; |
101 | setup_revisions(argc, argv, &rev, NULL); | 102 | setup_revisions(argc, argv, &rev, NULL); |
102 | prepare_revision_walk(&rev); | 103 | prepare_revision_walk(&rev); |
103 | 104 | ||
104 | host = cgit_hosturl(); | 105 | host = cgit_hosturl(); |
105 | ctx.page.mimetype = "text/xml"; | 106 | ctx.page.mimetype = "text/xml"; |
106 | ctx.page.charset = "utf-8"; | 107 | ctx.page.charset = "utf-8"; |
107 | cgit_print_http_headers(&ctx); | 108 | cgit_print_http_headers(&ctx); |
108 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); | 109 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); |
109 | html("<title>"); | 110 | html("<title>"); |
110 | html_txt(ctx.repo->name); | 111 | html_txt(ctx.repo->name); |
111 | html("</title>\n"); | 112 | html("</title>\n"); |
112 | html("<subtitle>"); | 113 | html("<subtitle>"); |
113 | html_txt(ctx.repo->desc); | 114 | html_txt(ctx.repo->desc); |
114 | html("</subtitle>\n"); | 115 | html("</subtitle>\n"); |
115 | if (host) { | 116 | if (host) { |
116 | html("<link rel='alternate' type='text/html' href='http://"); | 117 | html("<link rel='alternate' type='text/html' href='"); |
118 | html(cgit_httpscheme()); | ||
117 | html_attr(host); | 119 | html_attr(host); |
118 | html_attr(cgit_repourl(ctx.repo->url)); | 120 | html_attr(cgit_repourl(ctx.repo->url)); |
119 | html("'/>\n"); | 121 | html("'/>\n"); |
120 | } | 122 | } |
121 | while ((commit = get_revision(&rev)) != NULL) { | 123 | while ((commit = get_revision(&rev)) != NULL) { |
122 | add_entry(commit, host); | 124 | add_entry(commit, host); |
123 | free(commit->buffer); | 125 | free(commit->buffer); |
124 | commit->buffer = NULL; | 126 | commit->buffer = NULL; |
125 | free_commit_list(commit->parents); | 127 | free_commit_list(commit->parents); |
126 | commit->parents = NULL; | 128 | commit->parents = NULL; |
127 | } | 129 | } |
128 | html("</feed>\n"); | 130 | html("</feed>\n"); |
129 | } | 131 | } |
diff --git a/ui-shared.c b/ui-shared.c index 2630f23..29036d0 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,100 +1,111 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
18 | { | 18 | { |
19 | static char day[][4] = | 19 | static char day[][4] = |
20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
21 | static char month[][4] = | 21 | static char month[][4] = |
22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
23 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
24 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | 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() | ||
38 | { | ||
39 | char *https; | ||
40 | |||
41 | https = getenv("HTTPS"); | ||
42 | if (https != NULL && strcmp(https, "on") == 0) | ||
43 | return "https://"; | ||
44 | else | ||
45 | return "http://"; | ||
46 | } | ||
47 | |||
37 | char *cgit_hosturl() | 48 | char *cgit_hosturl() |
38 | { | 49 | { |
39 | char *host, *port; | 50 | char *host, *port; |
40 | 51 | ||
41 | host = getenv("HTTP_HOST"); | 52 | host = getenv("HTTP_HOST"); |
42 | if (host) { | 53 | if (host) { |
43 | host = xstrdup(host); | 54 | host = xstrdup(host); |
44 | } else { | 55 | } else { |
45 | host = getenv("SERVER_NAME"); | 56 | host = getenv("SERVER_NAME"); |
46 | if (!host) | 57 | if (!host) |
47 | return NULL; | 58 | return NULL; |
48 | port = getenv("SERVER_PORT"); | 59 | port = getenv("SERVER_PORT"); |
49 | if (port && atoi(port) != 80) | 60 | if (port && atoi(port) != 80) |
50 | host = xstrdup(fmt("%s:%d", host, atoi(port))); | 61 | host = xstrdup(fmt("%s:%d", host, atoi(port))); |
51 | else | 62 | else |
52 | host = xstrdup(host); | 63 | host = xstrdup(host); |
53 | } | 64 | } |
54 | return host; | 65 | return host; |
55 | } | 66 | } |
56 | 67 | ||
57 | char *cgit_rooturl() | 68 | char *cgit_rooturl() |
58 | { | 69 | { |
59 | if (ctx.cfg.virtual_root) | 70 | if (ctx.cfg.virtual_root) |
60 | return fmt("%s/", ctx.cfg.virtual_root); | 71 | return fmt("%s/", ctx.cfg.virtual_root); |
61 | else | 72 | else |
62 | return ctx.cfg.script_name; | 73 | return ctx.cfg.script_name; |
63 | } | 74 | } |
64 | 75 | ||
65 | char *cgit_repourl(const char *reponame) | 76 | char *cgit_repourl(const char *reponame) |
66 | { | 77 | { |
67 | if (ctx.cfg.virtual_root) { | 78 | if (ctx.cfg.virtual_root) { |
68 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 79 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
69 | } else { | 80 | } else { |
70 | return fmt("?r=%s", reponame); | 81 | return fmt("?r=%s", reponame); |
71 | } | 82 | } |
72 | } | 83 | } |
73 | 84 | ||
74 | char *cgit_fileurl(const char *reponame, const char *pagename, | 85 | char *cgit_fileurl(const char *reponame, const char *pagename, |
75 | const char *filename, const char *query) | 86 | const char *filename, const char *query) |
76 | { | 87 | { |
77 | char *tmp; | 88 | char *tmp; |
78 | char *delim; | 89 | char *delim; |
79 | 90 | ||
80 | if (ctx.cfg.virtual_root) { | 91 | if (ctx.cfg.virtual_root) { |
81 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 92 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
82 | pagename, (filename ? filename:"")); | 93 | pagename, (filename ? filename:"")); |
83 | delim = "?"; | 94 | delim = "?"; |
84 | } else { | 95 | } else { |
85 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 96 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
86 | (filename ? filename : "")); | 97 | (filename ? filename : "")); |
87 | delim = "&"; | 98 | delim = "&"; |
88 | } | 99 | } |
89 | if (query) | 100 | if (query) |
90 | tmp = fmt("%s%s%s", tmp, delim, query); | 101 | tmp = fmt("%s%s%s", tmp, delim, query); |
91 | return tmp; | 102 | return tmp; |
92 | } | 103 | } |
93 | 104 | ||
94 | char *cgit_pageurl(const char *reponame, const char *pagename, | 105 | char *cgit_pageurl(const char *reponame, const char *pagename, |
95 | const char *query) | 106 | const char *query) |
96 | { | 107 | { |
97 | return cgit_fileurl(reponame,pagename,0,query); | 108 | return cgit_fileurl(reponame,pagename,0,query); |
98 | } | 109 | } |
99 | 110 | ||
100 | const char *cgit_repobasename(const char *reponame) | 111 | const char *cgit_repobasename(const char *reponame) |
@@ -433,129 +444,130 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
433 | if (secs < TM_DAY * 2) { | 444 | if (secs < TM_DAY * 2) { |
434 | htmlf("<span class='age-hours'>%.0f hours</span>", | 445 | htmlf("<span class='age-hours'>%.0f hours</span>", |
435 | secs * 1.0 / TM_HOUR); | 446 | secs * 1.0 / TM_HOUR); |
436 | return; | 447 | return; |
437 | } | 448 | } |
438 | if (secs < TM_WEEK * 2) { | 449 | if (secs < TM_WEEK * 2) { |
439 | htmlf("<span class='age-days'>%.0f days</span>", | 450 | htmlf("<span class='age-days'>%.0f days</span>", |
440 | secs * 1.0 / TM_DAY); | 451 | secs * 1.0 / TM_DAY); |
441 | return; | 452 | return; |
442 | } | 453 | } |
443 | if (secs < TM_MONTH * 2) { | 454 | if (secs < TM_MONTH * 2) { |
444 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 455 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
445 | secs * 1.0 / TM_WEEK); | 456 | secs * 1.0 / TM_WEEK); |
446 | return; | 457 | return; |
447 | } | 458 | } |
448 | if (secs < TM_YEAR * 2) { | 459 | if (secs < TM_YEAR * 2) { |
449 | htmlf("<span class='age-months'>%.0f months</span>", | 460 | htmlf("<span class='age-months'>%.0f months</span>", |
450 | secs * 1.0 / TM_MONTH); | 461 | secs * 1.0 / TM_MONTH); |
451 | return; | 462 | return; |
452 | } | 463 | } |
453 | htmlf("<span class='age-years'>%.0f years</span>", | 464 | htmlf("<span class='age-years'>%.0f years</span>", |
454 | secs * 1.0 / TM_YEAR); | 465 | secs * 1.0 / TM_YEAR); |
455 | } | 466 | } |
456 | 467 | ||
457 | void cgit_print_http_headers(struct cgit_context *ctx) | 468 | void cgit_print_http_headers(struct cgit_context *ctx) |
458 | { | 469 | { |
459 | if (ctx->page.status) | 470 | if (ctx->page.status) |
460 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | 471 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); |
461 | if (ctx->page.mimetype && ctx->page.charset) | 472 | if (ctx->page.mimetype && ctx->page.charset) |
462 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 473 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
463 | ctx->page.charset); | 474 | ctx->page.charset); |
464 | else if (ctx->page.mimetype) | 475 | else if (ctx->page.mimetype) |
465 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 476 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
466 | if (ctx->page.size) | 477 | if (ctx->page.size) |
467 | htmlf("Content-Length: %ld\n", ctx->page.size); | 478 | htmlf("Content-Length: %ld\n", ctx->page.size); |
468 | if (ctx->page.filename) | 479 | if (ctx->page.filename) |
469 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 480 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
470 | ctx->page.filename); | 481 | ctx->page.filename); |
471 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 482 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
472 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 483 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
473 | html("\n"); | 484 | html("\n"); |
474 | } | 485 | } |
475 | 486 | ||
476 | void cgit_print_docstart(struct cgit_context *ctx) | 487 | void cgit_print_docstart(struct cgit_context *ctx) |
477 | { | 488 | { |
478 | char *host = cgit_hosturl(); | 489 | char *host = cgit_hosturl(); |
479 | html(cgit_doctype); | 490 | html(cgit_doctype); |
480 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 491 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
481 | html("<head>\n"); | 492 | html("<head>\n"); |
482 | html("<title>"); | 493 | html("<title>"); |
483 | html_txt(ctx->page.title); | 494 | html_txt(ctx->page.title); |
484 | html("</title>\n"); | 495 | html("</title>\n"); |
485 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 496 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
486 | if (ctx->cfg.robots && *ctx->cfg.robots) | 497 | if (ctx->cfg.robots && *ctx->cfg.robots) |
487 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 498 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
488 | html("<link rel='stylesheet' type='text/css' href='"); | 499 | html("<link rel='stylesheet' type='text/css' href='"); |
489 | html_attr(ctx->cfg.css); | 500 | html_attr(ctx->cfg.css); |
490 | html("'/>\n"); | 501 | html("'/>\n"); |
491 | if (ctx->cfg.favicon) { | 502 | if (ctx->cfg.favicon) { |
492 | html("<link rel='shortcut icon' href='"); | 503 | html("<link rel='shortcut icon' href='"); |
493 | html_attr(ctx->cfg.favicon); | 504 | html_attr(ctx->cfg.favicon); |
494 | html("'/>\n"); | 505 | html("'/>\n"); |
495 | } | 506 | } |
496 | if (host && ctx->repo) { | 507 | if (host && ctx->repo) { |
497 | html("<link rel='alternate' title='Atom feed' href='http://"); | 508 | html("<link rel='alternate' title='Atom feed' href='"); |
509 | html(cgit_httpscheme()); | ||
498 | html_attr(cgit_hosturl()); | 510 | html_attr(cgit_hosturl()); |
499 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 511 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
500 | fmt("h=%s", ctx->qry.head))); | 512 | fmt("h=%s", ctx->qry.head))); |
501 | html("' type='application/atom+xml'/>"); | 513 | html("' type='application/atom+xml'/>"); |
502 | } | 514 | } |
503 | html("</head>\n"); | 515 | html("</head>\n"); |
504 | html("<body>\n"); | 516 | html("<body>\n"); |
505 | if (ctx->cfg.header) | 517 | if (ctx->cfg.header) |
506 | html_include(ctx->cfg.header); | 518 | html_include(ctx->cfg.header); |
507 | } | 519 | } |
508 | 520 | ||
509 | void cgit_print_docend() | 521 | void cgit_print_docend() |
510 | { | 522 | { |
511 | html("</div>"); | 523 | html("</div>"); |
512 | if (ctx.cfg.footer) | 524 | if (ctx.cfg.footer) |
513 | html_include(ctx.cfg.footer); | 525 | html_include(ctx.cfg.footer); |
514 | else { | 526 | else { |
515 | htmlf("<div class='footer'>generated by cgit %s at ", | 527 | htmlf("<div class='footer'>generated by cgit %s at ", |
516 | cgit_version); | 528 | cgit_version); |
517 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 529 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
518 | html("</div>\n"); | 530 | html("</div>\n"); |
519 | } | 531 | } |
520 | html("</body>\n</html>\n"); | 532 | html("</body>\n</html>\n"); |
521 | } | 533 | } |
522 | 534 | ||
523 | int print_branch_option(const char *refname, const unsigned char *sha1, | 535 | int print_branch_option(const char *refname, const unsigned char *sha1, |
524 | int flags, void *cb_data) | 536 | int flags, void *cb_data) |
525 | { | 537 | { |
526 | char *name = (char *)refname; | 538 | char *name = (char *)refname; |
527 | html_option(name, name, ctx.qry.head); | 539 | html_option(name, name, ctx.qry.head); |
528 | return 0; | 540 | return 0; |
529 | } | 541 | } |
530 | 542 | ||
531 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 543 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
532 | int flags, void *cb_data) | 544 | int flags, void *cb_data) |
533 | { | 545 | { |
534 | struct tag *tag; | 546 | struct tag *tag; |
535 | struct taginfo *info; | 547 | struct taginfo *info; |
536 | struct object *obj; | 548 | struct object *obj; |
537 | char buf[256], *url; | 549 | char buf[256], *url; |
538 | unsigned char fileid[20]; | 550 | unsigned char fileid[20]; |
539 | int *header = (int *)cb_data; | 551 | int *header = (int *)cb_data; |
540 | 552 | ||
541 | if (prefixcmp(refname, "refs/archives")) | 553 | if (prefixcmp(refname, "refs/archives")) |
542 | return 0; | 554 | return 0; |
543 | strncpy(buf, refname+14, sizeof(buf)); | 555 | strncpy(buf, refname+14, sizeof(buf)); |
544 | obj = parse_object(sha1); | 556 | obj = parse_object(sha1); |
545 | if (!obj) | 557 | if (!obj) |
546 | return 1; | 558 | return 1; |
547 | if (obj->type == OBJ_TAG) { | 559 | if (obj->type == OBJ_TAG) { |
548 | tag = lookup_tag(sha1); | 560 | tag = lookup_tag(sha1); |
549 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 561 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
550 | return 0; | 562 | return 0; |
551 | hashcpy(fileid, tag->tagged->sha1); | 563 | hashcpy(fileid, tag->tagged->sha1); |
552 | } else if (obj->type != OBJ_BLOB) { | 564 | } else if (obj->type != OBJ_BLOB) { |
553 | return 0; | 565 | return 0; |
554 | } else { | 566 | } else { |
555 | hashcpy(fileid, sha1); | 567 | hashcpy(fileid, sha1); |
556 | } | 568 | } |
557 | if (!*header) { | 569 | if (!*header) { |
558 | html("<h1>download</h1>\n"); | 570 | html("<h1>download</h1>\n"); |
559 | *header = 1; | 571 | *header = 1; |
560 | } | 572 | } |
561 | url = cgit_pageurl(ctx.qry.repo, "blob", | 573 | url = cgit_pageurl(ctx.qry.repo, "blob", |
diff --git a/ui-shared.h b/ui-shared.h index 5a3821f..bff4826 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -1,49 +1,50 @@ | |||
1 | #ifndef UI_SHARED_H | 1 | #ifndef UI_SHARED_H |
2 | #define UI_SHARED_H | 2 | #define UI_SHARED_H |
3 | 3 | ||
4 | extern char *cgit_httpscheme(); | ||
4 | extern char *cgit_hosturl(); | 5 | extern char *cgit_hosturl(); |
5 | extern char *cgit_repourl(const char *reponame); | 6 | extern char *cgit_repourl(const char *reponame); |
6 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 7 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
7 | const char *filename, const char *query); | 8 | const char *filename, const char *query); |
8 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 9 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
9 | const char *query); | 10 | const char *query); |
10 | 11 | ||
11 | extern void cgit_index_link(char *name, char *title, char *class, | 12 | extern void cgit_index_link(char *name, char *title, char *class, |
12 | char *pattern, int ofs); | 13 | char *pattern, int ofs); |
13 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); | 14 | extern void cgit_summary_link(char *name, char *title, char *class, char *head); |
14 | extern void cgit_tag_link(char *name, char *title, char *class, char *head, | 15 | extern void cgit_tag_link(char *name, char *title, char *class, char *head, |
15 | char *rev); | 16 | char *rev); |
16 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 17 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
17 | char *rev, char *path); | 18 | char *rev, char *path); |
18 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, | 19 | extern void cgit_plain_link(char *name, char *title, char *class, char *head, |
19 | char *rev, char *path); | 20 | char *rev, char *path); |
20 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 21 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
21 | char *rev, char *path, int ofs, char *grep, | 22 | char *rev, char *path, int ofs, char *grep, |
22 | char *pattern, int showmsg); | 23 | char *pattern, int showmsg); |
23 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 24 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
24 | char *rev); | 25 | char *rev); |
25 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, | 26 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, |
26 | char *rev); | 27 | char *rev); |
27 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | 28 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, |
28 | char *rev, char *path); | 29 | char *rev, char *path); |
29 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 30 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
30 | char *head, char *rev, char *archivename); | 31 | char *head, char *rev, char *archivename); |
31 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 32 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
32 | char *new_rev, char *old_rev, char *path); | 33 | char *new_rev, char *old_rev, char *path); |
33 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, | 34 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, |
34 | char *path); | 35 | char *path); |
35 | extern void cgit_object_link(struct object *obj); | 36 | extern void cgit_object_link(struct object *obj); |
36 | 37 | ||
37 | extern void cgit_print_error(char *msg); | 38 | extern void cgit_print_error(char *msg); |
38 | extern void cgit_print_date(time_t secs, char *format, int local_time); | 39 | extern void cgit_print_date(time_t secs, char *format, int local_time); |
39 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 40 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
40 | extern void cgit_print_http_headers(struct cgit_context *ctx); | 41 | extern void cgit_print_http_headers(struct cgit_context *ctx); |
41 | extern void cgit_print_docstart(struct cgit_context *ctx); | 42 | extern void cgit_print_docstart(struct cgit_context *ctx); |
42 | extern void cgit_print_docend(); | 43 | extern void cgit_print_docend(); |
43 | extern void cgit_print_pageheader(struct cgit_context *ctx); | 44 | extern void cgit_print_pageheader(struct cgit_context *ctx); |
44 | extern void cgit_print_filemode(unsigned short mode); | 45 | extern void cgit_print_filemode(unsigned short mode); |
45 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 46 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
46 | const char *hex, int snapshots); | 47 | const char *hex, int snapshots); |
47 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, | 48 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, |
48 | char *page); | 49 | char *page); |
49 | #endif /* UI_SHARED_H */ | 50 | #endif /* UI_SHARED_H */ |