Skip to content

Commit 065394c

Browse files
committed
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 <[email protected]>
1 parent 48ddb8f commit 065394c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

http.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ http_send_response(int fd, struct request *r)
394394
for (i = 0; i < s.map_len; i++) {
395395
len = strlen(s.map[i].from);
396396
if (!strncmp(realtarget, s.map[i].from, len)) {
397-
/* match canonical host if vhosts are enabled */
398-
if (s.vhost && strcmp(s.map[i].chost, vhostmatch)) {
397+
/* match canonical host if vhosts are enabled and
398+
* the mapping specifies a canonical host */
399+
if (s.vhost && s.map[i].chost &&
400+
strcmp(s.map[i].chost, vhostmatch)) {
399401
continue;
400402
}
401403

main.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ main(int argc, char *argv[])
155155
sizeof(struct map)))) {
156156
die("reallocarray:");
157157
}
158-
if (!(s.map[s.map_len - 1].chost = strtok(tok, " ")) ||
159-
!(s.map[s.map_len - 1].from = strtok(NULL, " ")) ||
160-
!(s.map[s.map_len - 1].to = strtok(NULL, " ")) ||
161-
strtok(NULL, "")) {
158+
if (!(s.map[s.map_len - 1].from = strtok(tok, " ")) ||
159+
!(s.map[s.map_len - 1].to = strtok(NULL, " "))) {
160+
usage();
161+
}
162+
s.map[s.map_len - 1].chost = strtok(NULL, " ");
163+
if (strtok(NULL, "")) {
162164
usage();
163165
}
164166
break;

quark.1

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.Dd 2019-02-18
1+
.Dd 2019-02-24
22
.Dt QUARK 1
33
.Os suckless.org
44
.Sh NAME
@@ -57,16 +57,15 @@ Enable directory listing.
5757
Add the target prefix mapping rule specified by
5858
.Ar map ,
5959
which has the form
60-
.Qq Pa chost from to ,
60+
.Qq Pa from to [chost] ,
6161
where each element is separated with whitespace.
6262
.Pp
6363
The prefix
6464
.Pa from
65-
of all matching targets, especially only of those requests for the canonical
66-
virtual host
67-
.Pa chost
68-
when virtual hosts are specified, is then replaced with
69-
.Pa to .
65+
of all matching targets is replaced with
66+
.Pa to ,
67+
optionally limited to the canonical virtual host
68+
.Pa chost .
7069
If no virtual hosts are given,
7170
.Pa chost
7271
is ignored.

0 commit comments

Comments
 (0)