Integrate compiled regex into vhost array
This commit is contained in:
parent
233bf68b4b
commit
e592bbc0fe
2 changed files with 10 additions and 16 deletions
|
@ -13,10 +13,11 @@ static const int maxnprocs = 512;
|
||||||
#define HEADER_MAX 4096
|
#define HEADER_MAX 4096
|
||||||
#define FIELD_MAX 200
|
#define FIELD_MAX 200
|
||||||
|
|
||||||
static const struct {
|
static struct {
|
||||||
char *name;
|
const char *name;
|
||||||
char *regex;
|
const char *regex;
|
||||||
char *dir;
|
const char *dir;
|
||||||
|
regex_t re;
|
||||||
} vhost[] = {
|
} vhost[] = {
|
||||||
{ "example.org", "^(www.)example.org$", "/example.org" },
|
{ "example.org", "^(www.)example.org$", "/example.org" },
|
||||||
};
|
};
|
||||||
|
|
17
quark.c
17
quark.c
|
@ -102,9 +102,6 @@ static char *status_str[] = {
|
||||||
[S_VERSION_NOT_SUPPORTED] = "HTTP Version not supported",
|
[S_VERSION_NOT_SUPPORTED] = "HTTP Version not supported",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vhost regex compilate */
|
|
||||||
static regex_t vhost_regex[LEN(vhost)];
|
|
||||||
|
|
||||||
long long strtonum(const char *, long long, long long, const char **);
|
long long strtonum(const char *, long long, long long, const char **);
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -566,14 +563,10 @@ sendresponse(int fd, struct request *r)
|
||||||
/* match vhost */
|
/* match vhost */
|
||||||
if (vhosts) {
|
if (vhosts) {
|
||||||
for (i = 0; i < LEN(vhost); i++) {
|
for (i = 0; i < LEN(vhost); i++) {
|
||||||
if (!regexec(&vhost_regex[i], r->field[REQ_HOST], 0,
|
if (!regexec(&vhost[i].re, r->field[REQ_HOST], 0,
|
||||||
NULL, 0)) {
|
NULL, 0) &&
|
||||||
break;
|
/* switch to vhost directory */
|
||||||
}
|
chdir(vhost[i].dir) < 0) {
|
||||||
}
|
|
||||||
if (i < LEN(vhost)) {
|
|
||||||
/* switch to vhost directory */
|
|
||||||
if (chdir(vhost[i].dir) < 0) {
|
|
||||||
return sendstatus(fd, (errno == EACCES) ?
|
return sendstatus(fd, (errno == EACCES) ?
|
||||||
S_FORBIDDEN : S_NOT_FOUND);
|
S_FORBIDDEN : S_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
@ -971,7 +964,7 @@ main(int argc, char *argv[])
|
||||||
/* compile and check the supplied vhost regexes */
|
/* compile and check the supplied vhost regexes */
|
||||||
if (vhosts) {
|
if (vhosts) {
|
||||||
for (i = 0; i < LEN(vhost); i++) {
|
for (i = 0; i < LEN(vhost); i++) {
|
||||||
if (regcomp(&vhost_regex[i], vhost[i].regex,
|
if (regcomp(&vhost[i].re, vhost[i].regex,
|
||||||
REG_ICASE | REG_NOSUB)) {
|
REG_ICASE | REG_NOSUB)) {
|
||||||
die("%s: regcomp '%s': invalid regex\n", argv0,
|
die("%s: regcomp '%s': invalid regex\n", argv0,
|
||||||
vhost[i].regex);
|
vhost[i].regex);
|
||||||
|
|
Loading…
Reference in a new issue