diff options
-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
diff --git a/cgit.c b/cgit.c index ed02614..baad1c8 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -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(); |
diff --git a/cmd.c b/cmd.c index 188cd56..e86b0ea 100644 --- a/cmd.c +++ b/cmd.c | |||
@@ -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), |
diff --git a/cmd.h b/cmd.h index 752f078..2507ca5 100644 --- a/cmd.h +++ b/cmd.h | |||
@@ -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); |