diff options
author | Omar Polo <op@omarpolo.com> | 2021-03-31 16:32:18 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-03-31 16:32:18 +0000 |
commit | b8e64ccd44290cdd34bdcd3fd85fb1a9cb7486dd (patch) | |
tree | 0e419f355bb2bda7a099fd1c113e1c04f7dfe723 /ex.c | |
parent | e0ebdf2d94159db669a67972b760d1920f11310b (diff) |
list instead of fixed-size array for vhosts and locations
saves some bytes of memory and removes the limit on the maximum number
of vhosts and location blocks.
Diffstat (limited to 'ex.c')
-rw-r--r-- | ex.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -210,12 +210,27 @@ childerr: _exit(1); } +static struct vhost * +host_nth(size_t n) +{ + struct vhost *h; + + TAILQ_FOREACH(h, &hosts, vhosts) { + if (n == 0) + return h; + n--; + } + + return NULL; +} + static void handle_imsg_cgi_req(struct imsgbuf *ibuf, struct imsg *imsg, size_t datalen) { - struct cgireq req; - struct iri iri; - int fd; + struct vhost *h; + struct cgireq req; + struct iri iri; + int fd; if (datalen != sizeof(req)) abort(); @@ -234,10 +249,10 @@ handle_imsg_cgi_req(struct imsgbuf *ibuf, struct imsg *imsg, size_t datalen) if (*iri.query == '\0') iri.query = NULL; - if (req.host_off > HOSTSLEN || hosts[req.host_off].domain == NULL) + if ((h = host_nth(req.host_off)) == NULL) abort(); - fd = launch_cgi(&iri, &req, &hosts[req.host_off]); + fd = launch_cgi(&iri, &req, h); imsg_compose(ibuf, IMSG_CGI_RES, imsg->hdr.peerid, 0, fd, NULL, 0); imsg_flush(ibuf); } |