aboutsummaryrefslogtreecommitdiff
path: root/ex.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-03-31 16:32:18 +0000
committerOmar Polo <op@omarpolo.com>2021-03-31 16:32:18 +0000
commitb8e64ccd44290cdd34bdcd3fd85fb1a9cb7486dd (patch)
tree0e419f355bb2bda7a099fd1c113e1c04f7dfe723 /ex.c
parente0ebdf2d94159db669a67972b760d1920f11310b (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.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/ex.c b/ex.c
index d553fe7..e08da7b 100644
--- a/ex.c
+++ b/ex.c
@@ -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);
}