[hackers] [quark] Add target prefix mapping || Laslo Hunhold
commit 7b7f166dd58b572989d3980f973d9ed88325ece8
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Tue Feb 27 12:43:05 2018 +0100
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Feb 27 12:43:05 2018 +0100
Add target prefix mapping
This allows e.g. to redirect when a directory has been moved.
diff --git a/config.def.h b/config.def.h
index 1875ed3..8791951 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -25,6 +25,16 @@ static struct {
{ "example.org", "old\\.example\\.org", "/", "/old" },
};
+/* target prefix mapping */
+static const struct {
+ const char *vhost;
+ const char *from;
+ const char *to;
+} map[] = {
+ /* canonical host from to */
+ { "example.org", "/old/path/to/dir", "/new/path/to/dir" },
+};
+
/* mime-types */
static const struct {
char *ext;
diff --git a/http.c b/http.c
index 03ba680..d58d94a 100644
--- a/http.c
+++ b/http.c
_AT_@ -351,6 +351,24 @@ http_send_response(int fd, struct request *r)
}
}
+ /* apply target prefix mapping */
+ for (i = 0; i < LEN(map); i++) {
+ len = strlen(map[i].from);
+ if (!strncmp(realtarget, map[i].from, len)) {
+ /* match canonical host if vhosts are enabled */
+ if (vhosts && strcmp(map[i].vhost, vhostmatch)) {
+ continue;
+ }
+
+ /* swap out target prefix */
+ if (snprintf(realtarget, sizeof(realtarget), "%s%s", map[i].to,
+ realtarget + len) >= sizeof(realtarget)) {
+ return http_send_status(fd, S_REQUEST_TOO_LARGE);
+ }
+ break;
+ }
+ }
+
/* normalize target */
if (normabspath(realtarget)) {
return http_send_status(fd, S_BAD_REQUEST);
Received on Tue Feb 27 2018 - 12:44:07 CET
This archive was generated by hypermail 2.3.0
: Tue Feb 27 2018 - 12:48:29 CET