diff options
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 37 | ||||
-rw-r--r-- | ui-shared.h | 1 |
3 files changed, 37 insertions, 3 deletions
@@ -645,7 +645,7 @@ static inline void open_auth_filter(const char *function) | |||
645 | ctx.env.https ? ctx.env.https : "", | 645 | ctx.env.https ? ctx.env.https : "", |
646 | ctx.qry.repo ? ctx.qry.repo : "", | 646 | ctx.qry.repo ? ctx.qry.repo : "", |
647 | ctx.qry.page ? ctx.qry.page : "", | 647 | ctx.qry.page ? ctx.qry.page : "", |
648 | ctx.qry.url ? ctx.qry.url : "", | 648 | cgit_currentfullurl(), |
649 | cgit_loginurl()); | 649 | cgit_loginurl()); |
650 | } | 650 | } |
651 | 651 | ||
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) |
diff --git a/ui-shared.h b/ui-shared.h index 4d5978b..6964873 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -5,6 +5,7 @@ extern const char *cgit_httpscheme(void); | |||
5 | extern char *cgit_hosturl(void); | 5 | extern char *cgit_hosturl(void); |
6 | extern const char *cgit_rooturl(void); | 6 | extern const char *cgit_rooturl(void); |
7 | extern char *cgit_currenturl(void); | 7 | extern char *cgit_currenturl(void); |
8 | extern char *cgit_currentfullurl(void); | ||
8 | extern const char *cgit_loginurl(void); | 9 | extern const char *cgit_loginurl(void); |
9 | extern char *cgit_repourl(const char *reponame); | 10 | extern char *cgit_repourl(const char *reponame); |
10 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 11 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |