about summary refs log tree commit diff stats
path: root/ui-shared.c
diff options
context:
space:
mode:
authorJason A. Donenfeld2018-11-21 03:16:11 +0100
committerJason A. Donenfeld2018-11-25 06:01:34 +0100
commit898b9e19e0eacd67456ddcc91ff173055e1c0e99 (patch)
tree3f056db3a9d329b43a0fa7c567ad54672ace5bfb /ui-shared.c
parentgit: use xz compressed archive for download (diff)
downloadcgit-898b9e19e0eacd67456ddcc91ff173055e1c0e99.tar.gz
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.c37
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)
68char *cgit_currenturl(void) 68char *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
79char *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
80const char *cgit_rooturl(void) 113const char *cgit_rooturl(void)
81{ 114{
82 if (ctx.cfg.virtual_root) 115 if (ctx.cfg.virtual_root)