Change target prefix mapping argument order

Put the chost-specification at the end and make it optional. This makes
more sense than having to give an arbitrary useless name in case you
weren't using virtual hosts in the first place.

While at it, clear up the wording in the manpage.

Signed-off-by: Laslo Hunhold <dev@frign.de>
This commit is contained in:
Laslo Hunhold 2019-02-24 00:40:46 +01:00
parent 48ddb8fefb
commit 065394cb64
No known key found for this signature in database
GPG key ID: 69576BD24CFCB980
3 changed files with 16 additions and 13 deletions

6
http.c
View file

@ -394,8 +394,10 @@ http_send_response(int fd, struct request *r)
for (i = 0; i < s.map_len; i++) { for (i = 0; i < s.map_len; i++) {
len = strlen(s.map[i].from); len = strlen(s.map[i].from);
if (!strncmp(realtarget, s.map[i].from, len)) { if (!strncmp(realtarget, s.map[i].from, len)) {
/* match canonical host if vhosts are enabled */ /* match canonical host if vhosts are enabled and
if (s.vhost && strcmp(s.map[i].chost, vhostmatch)) { * the mapping specifies a canonical host */
if (s.vhost && s.map[i].chost &&
strcmp(s.map[i].chost, vhostmatch)) {
continue; continue;
} }

10
main.c
View file

@ -155,10 +155,12 @@ main(int argc, char *argv[])
sizeof(struct map)))) { sizeof(struct map)))) {
die("reallocarray:"); die("reallocarray:");
} }
if (!(s.map[s.map_len - 1].chost = strtok(tok, " ")) || if (!(s.map[s.map_len - 1].from = strtok(tok, " ")) ||
!(s.map[s.map_len - 1].from = strtok(NULL, " ")) || !(s.map[s.map_len - 1].to = strtok(NULL, " "))) {
!(s.map[s.map_len - 1].to = strtok(NULL, " ")) || usage();
strtok(NULL, "")) { }
s.map[s.map_len - 1].chost = strtok(NULL, " ");
if (strtok(NULL, "")) {
usage(); usage();
} }
break; break;

13
quark.1
View file

@ -1,4 +1,4 @@
.Dd 2019-02-18 .Dd 2019-02-24
.Dt QUARK 1 .Dt QUARK 1
.Os suckless.org .Os suckless.org
.Sh NAME .Sh NAME
@ -57,16 +57,15 @@ Enable directory listing.
Add the target prefix mapping rule specified by Add the target prefix mapping rule specified by
.Ar map , .Ar map ,
which has the form which has the form
.Qq Pa chost from to , .Qq Pa from to [chost] ,
where each element is separated with whitespace. where each element is separated with whitespace.
.Pp .Pp
The prefix The prefix
.Pa from .Pa from
of all matching targets, especially only of those requests for the canonical of all matching targets is replaced with
virtual host .Pa to ,
.Pa chost optionally limited to the canonical virtual host
when virtual hosts are specified, is then replaced with .Pa chost .
.Pa to .
If no virtual hosts are given, If no virtual hosts are given,
.Pa chost .Pa chost
is ignored. is ignored.