diff options
author | Jason A. Donenfeld | 2018-11-21 03:16:11 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2018-11-25 06:01:34 +0100 |
commit | 898b9e19e0eacd67456ddcc91ff173055e1c0e99 (patch) | |
tree | 3f056db3a9d329b43a0fa7c567ad54672ace5bfb /ui-shared.c | |
parent | a22855747e97e55a7b7a2622fe671b8ca9af0981 (diff) | |
download | cgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.tar.gz cgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.tar.bz2 cgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.zip |
auth-filter: pass url with query string attached
Otherwise redirections come out wrong.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c index b53c56d..7a4c726 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -68,15 +68,48 @@ char *cgit_hosturl(void) | |||
68 | char *cgit_currenturl(void) | 68 | char *cgit_currenturl(void) |
69 | { | 69 | { |
70 | const char *root = cgit_rooturl(); | 70 | const char *root = cgit_rooturl(); |
71 | size_t len = strlen(root); | ||
72 | 71 | ||
73 | if (!ctx.qry.url) | 72 | if (!ctx.qry.url) |
74 | return xstrdup(root); | 73 | return xstrdup(root); |
75 | if (len && root[len - 1] == '/') | 74 | if (root[0] && root[strlen(root) - 1] == '/') |
76 | return fmtalloc("%s%s", root, ctx.qry.url); | 75 | return fmtalloc("%s%s", root, ctx.qry.url); |
77 | return fmtalloc("%s/%s", root, ctx.qry.url); | 76 | return fmtalloc("%s/%s", root, ctx.qry.url); |
78 | } | 77 | } |
79 | 78 | ||
79 | char *cgit_currentfullurl(void) | ||
80 | { | ||
81 | const char *root = cgit_rooturl(); | ||
82 | const char *orig_query = ctx.env.query_string ? ctx.env.query_string : ""; | ||
83 | size_t len = strlen(orig_query); | ||
84 | char *query = xmalloc(len + 2), *start_url, *ret; | ||
85 | |||
86 | /* Remove all url=... parts from query string */ | ||
87 | memcpy(query + 1, orig_query, len + 1); | ||
88 | query[0] = '?'; | ||
89 | start_url = query; | ||
90 | while ((start_url = strstr(start_url, "url=")) != NULL) { | ||
91 | if (start_url[-1] == '?' || start_url[-1] == '&') { | ||
92 | const char *end_url = strchr(start_url, '&'); | ||
93 | if (end_url) | ||
94 | memmove(start_url, end_url + 1, strlen(end_url)); | ||
95 | else | ||
96 | start_url[0] = '\0'; | ||
97 | } else | ||
98 | ++start_url; | ||
99 | } | ||
100 | if (!query[1]) | ||
101 | query[0] = '\0'; | ||
102 | |||
103 | if (!ctx.qry.url) | ||
104 | ret = fmtalloc("%s%s", root, query); | ||
105 | else if (root[0] && root[strlen(root) - 1] == '/') | ||
106 | ret = fmtalloc("%s%s%s", root, ctx.qry.url, query); | ||
107 | else | ||
108 | ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query); | ||
109 | free(query); | ||
110 | return ret; | ||
111 | } | ||
112 | |||
80 | const char *cgit_rooturl(void) | 113 | const char *cgit_rooturl(void) |
81 | { | 114 | { |
82 | if (ctx.cfg.virtual_root) | 115 | if (ctx.cfg.virtual_root) |