From 898b9e19e0eacd67456ddcc91ff173055e1c0e99 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 21 Nov 2018 03:16:11 +0100 Subject: auth-filter: pass url with query string attached Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld --- ui-shared.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'ui-shared.c') 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) char *cgit_currenturl(void) { const char *root = cgit_rooturl(); - size_t len = strlen(root); if (!ctx.qry.url) return xstrdup(root); - if (len && root[len - 1] == '/') + if (root[0] && root[strlen(root) - 1] == '/') return fmtalloc("%s%s", root, ctx.qry.url); return fmtalloc("%s/%s", root, ctx.qry.url); } +char *cgit_currentfullurl(void) +{ + const char *root = cgit_rooturl(); + const char *orig_query = ctx.env.query_string ? ctx.env.query_string : ""; + size_t len = strlen(orig_query); + char *query = xmalloc(len + 2), *start_url, *ret; + + /* Remove all url=... parts from query string */ + memcpy(query + 1, orig_query, len + 1); + query[0] = '?'; + start_url = query; + while ((start_url = strstr(start_url, "url=")) != NULL) { + if (start_url[-1] == '?' || start_url[-1] == '&') { + const char *end_url = strchr(start_url, '&'); + if (end_url) + memmove(start_url, end_url + 1, strlen(end_url)); + else + start_url[0] = '\0'; + } else + ++start_url; + } + if (!query[1]) + query[0] = '\0'; + + if (!ctx.qry.url) + ret = fmtalloc("%s%s", root, query); + else if (root[0] && root[strlen(root) - 1] == '/') + ret = fmtalloc("%s%s%s", root, ctx.qry.url, query); + else + ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query); + free(query); + return ret; +} + const char *cgit_rooturl(void) { if (ctx.cfg.virtual_root) -- cgit 1.4.1 class='txt' type='search' size='10' name='q' value=''/>
Commit message (Collapse)Author
2019-11-08Check that password is hashedJune McEnroe
2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe
On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever.
2019-11-08Only change AWAY status for registered clientsJune McEnroe
Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either.
2019-11-07Just write the example normallyJune McEnroe
2019-11-07Include path in readlinkat errorJune McEnroe
2019-11-07Call clientConsume before clientRecvJune McEnroe
This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it.
2019-11-06Use -l:filename in Linux.mkJune McEnroe
2019-11-06Fix compat.h for #defined strlcpyJune McEnroe
2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe
2019-11-06Document calico service configurationJune McEnroe
2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe
2019-11-06Document pounce service configurationJune McEnroe
2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe
2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe
2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe
2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe