diff options
author | Jason A. Donenfeld | 2015-08-12 14:50:09 +0200 |
---|---|---|
committer | Jason A. Donenfeld | 2015-08-12 15:03:32 +0200 |
commit | d7034806a4b1279f62d606501f831dcad31798e6 (patch) | |
tree | 1aafe109f0598dcb3b32dda27173031893e5956a | |
parent | 13c2d3df0440ce04273de3149631a9bd97490c6e (diff) | |
download | cgit-d7034806a4b1279f62d606501f831dcad31798e6.tar.gz cgit-d7034806a4b1279f62d606501f831dcad31798e6.tar.bz2 cgit-d7034806a4b1279f62d606501f831dcad31798e6.zip |
about: always ensure page has a trailing slash
Otherwise we can't easily embed links to other /about/ pages.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cmd.c | 12 | ||||
-rw-r--r-- | cmd.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 8 | ||||
-rw-r--r-- | ui-shared.h | 3 |
5 files changed, 26 insertions, 2 deletions
@@ -742,6 +742,9 @@ static void process_request(void) | |||
742 | if (ctx.repo && prepare_repo_cmd()) | 742 | if (ctx.repo && prepare_repo_cmd()) |
743 | return; | 743 | return; |
744 | 744 | ||
745 | if (cmd->pre) | ||
746 | cmd->pre(); | ||
747 | |||
745 | if (cmd->want_layout) { | 748 | if (cmd->want_layout) { |
746 | cgit_print_http_headers(); | 749 | cgit_print_http_headers(); |
747 | cgit_print_docstart(); | 750 | cgit_print_docstart(); |
@@ -44,6 +44,12 @@ static void about_fn(void) | |||
44 | cgit_print_site_readme(); | 44 | cgit_print_site_readme(); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void about_pre(void) | ||
48 | { | ||
49 | if (ctx.repo && !ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') | ||
50 | cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); | ||
51 | } | ||
52 | |||
47 | static void blob_fn(void) | 53 | static void blob_fn(void) |
48 | { | 54 | { |
49 | cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); | 55 | cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); |
@@ -136,15 +142,17 @@ static void tree_fn(void) | |||
136 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); | 142 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); |
137 | } | 143 | } |
138 | 144 | ||
145 | #define def_cmp(name, want_repo, want_layout, want_vpath, is_clone) \ | ||
146 | {#name, name##_fn, name##_pre, want_repo, want_layout, want_vpath, is_clone} | ||
139 | #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ | 147 | #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ |
140 | {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} | 148 | {#name, name##_fn, NULL, want_repo, want_layout, want_vpath, is_clone} |
141 | 149 | ||
142 | struct cgit_cmd *cgit_get_cmd(void) | 150 | struct cgit_cmd *cgit_get_cmd(void) |
143 | { | 151 | { |
144 | static struct cgit_cmd cmds[] = { | 152 | static struct cgit_cmd cmds[] = { |
145 | def_cmd(HEAD, 1, 0, 0, 1), | 153 | def_cmd(HEAD, 1, 0, 0, 1), |
146 | def_cmd(atom, 1, 0, 0, 0), | 154 | def_cmd(atom, 1, 0, 0, 0), |
147 | def_cmd(about, 0, 1, 0, 0), | 155 | def_cmp(about, 0, 1, 0, 0), |
148 | def_cmd(blob, 1, 0, 0, 0), | 156 | def_cmd(blob, 1, 0, 0, 0), |
149 | def_cmd(commit, 1, 1, 1, 0), | 157 | def_cmd(commit, 1, 1, 1, 0), |
150 | def_cmd(diff, 1, 1, 1, 0), | 158 | def_cmd(diff, 1, 1, 1, 0), |
@@ -2,10 +2,12 @@ | |||
2 | #define CMD_H | 2 | #define CMD_H |
3 | 3 | ||
4 | typedef void (*cgit_cmd_fn)(void); | 4 | typedef void (*cgit_cmd_fn)(void); |
5 | typedef void (*cgit_cmd_pre_fn)(void); | ||
5 | 6 | ||
6 | struct cgit_cmd { | 7 | struct cgit_cmd { |
7 | const char *name; | 8 | const char *name; |
8 | cgit_cmd_fn fn; | 9 | cgit_cmd_fn fn; |
10 | cgit_cmd_pre_fn pre; | ||
9 | unsigned int want_repo:1, | 11 | unsigned int want_repo:1, |
10 | want_layout:1, | 12 | want_layout:1, |
11 | want_vpath:1, | 13 | want_vpath:1, |
diff --git a/ui-shared.c b/ui-shared.c index e755c92..4f84b7c 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -689,6 +689,14 @@ void cgit_print_http_headers(void) | |||
689 | exit(0); | 689 | exit(0); |
690 | } | 690 | } |
691 | 691 | ||
692 | void cgit_redirect(const char *url, bool permanent) | ||
693 | { | ||
694 | htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found"); | ||
695 | htmlf("Location: %s\n", url); | ||
696 | htmlf("\n"); | ||
697 | exit(0); | ||
698 | } | ||
699 | |||
692 | static void print_rel_vcs_link(const char *url) | 700 | static void print_rel_vcs_link(const char *url) |
693 | { | 701 | { |
694 | html("<link rel='vcs-git' href='"); | 702 | html("<link rel='vcs-git' href='"); |
diff --git a/ui-shared.h b/ui-shared.h index 1b8ecb5..43d0fa6 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef UI_SHARED_H | 1 | #ifndef UI_SHARED_H |
2 | #define UI_SHARED_H | 2 | #define UI_SHARED_H |
3 | 3 | ||
4 | #include <stdbool.h> | ||
5 | |||
4 | extern const char *cgit_httpscheme(); | 6 | extern const char *cgit_httpscheme(); |
5 | extern const char *cgit_hosturl(); | 7 | extern const char *cgit_hosturl(); |
6 | extern const char *cgit_rooturl(); | 8 | extern const char *cgit_rooturl(); |
@@ -61,6 +63,7 @@ extern void cgit_vprint_error(const char *fmt, va_list ap); | |||
61 | extern void cgit_print_date(time_t secs, const char *format, int local_time); | 63 | extern void cgit_print_date(time_t secs, const char *format, int local_time); |
62 | extern void cgit_print_age(time_t t, time_t max_relative, const char *format); | 64 | extern void cgit_print_age(time_t t, time_t max_relative, const char *format); |
63 | extern void cgit_print_http_headers(void); | 65 | extern void cgit_print_http_headers(void); |
66 | extern void cgit_redirect(const char *url, bool permanent); | ||
64 | extern void cgit_print_docstart(void); | 67 | extern void cgit_print_docstart(void); |
65 | extern void cgit_print_docend(); | 68 | extern void cgit_print_docend(); |
66 | extern void cgit_print_pageheader(void); | 69 | extern void cgit_print_pageheader(void); |