diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | config.c | 84 | ||||
-rw-r--r-- | ge.c | 3 | ||||
-rw-r--r-- | gmid.c | 71 | ||||
-rw-r--r-- | gmid.h | 6 |
5 files changed, 96 insertions, 74 deletions
@@ -18,7 +18,8 @@ # all. TESTS= -GMID_SRCS = dirs.c \ +GMID_SRCS = config.c \ + dirs.c \ fcgi.c \ gmid.c \ iri.c \ @@ -34,7 +35,8 @@ GMID_SRCS = dirs.c \ GMID_OBJS = ${GMID_SRCS:.c=.o} ${COBJS} -GE_SRCS = dirs.c \ +GE_SRCS = config.c \ + dirs.c \ fcgi.c \ ge.c \ iri.c \ diff --git a/config.c b/config.c new file mode 100644 index 0000000..7a438a5 --- /dev/null +++ b/config.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 Omar Polo <op@omarpolo.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "gmid.h" + +#include <string.h> + +void +config_init(void) +{ + TAILQ_INIT(&hosts); + + conf.port = 1965; + conf.ipv6 = 0; + conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3; + + init_mime(&conf.mime); + + conf.prefork = 3; +} + +void +config_free(void) +{ + struct vhost *h, *th; + struct location *l, *tl; + struct proxy *p, *tp; + struct envlist *e, *te; + struct alist *a, *ta; + int v; + + v = conf.verbose; + + free_mime(&conf.mime); + memset(&conf, 0, sizeof(conf)); + + conf.verbose = v; + + TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) { + TAILQ_FOREACH_SAFE(l, &h->locations, locations, tl) { + TAILQ_REMOVE(&h->locations, l, locations); + + if (l->dirfd != -1) + close(l->dirfd); + + free(l); + } + + TAILQ_FOREACH_SAFE(e, &h->params, envs, te) { + TAILQ_REMOVE(&h->params, e, envs); + free(e); + } + + TAILQ_FOREACH_SAFE(a, &h->aliases, aliases, ta) { + TAILQ_REMOVE(&h->aliases, a, aliases); + free(a); + } + + TAILQ_FOREACH_SAFE(p, &h->proxies, proxies, tp) { + TAILQ_REMOVE(&h->proxies, p, proxies); + tls_unload_file(p->cert, p->certlen); + tls_unload_file(p->key, p->keylen); + free(p); + } + + TAILQ_REMOVE(&hosts, h, vhosts); + free(h); + } + + memset(fcgi, 0, sizeof(fcgi)); +} @@ -209,8 +209,7 @@ main(int argc, char **argv) setlocale(LC_CTYPE, ""); logger_init(); - conf.port = 1965; - conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3; + config_init(); while ((ch = getopt_long(argc, argv, "d:H:hp:Vv", opts, NULL)) != -1) { switch (ch) { @@ -113,71 +113,6 @@ make_socket(int port, int family) return sock; } -void -init_config(void) -{ - TAILQ_INIT(&hosts); - - conf.port = 1965; - conf.ipv6 = 0; - conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3; - - init_mime(&conf.mime); - - conf.prefork = 3; -} - -void -free_config(void) -{ - struct vhost *h, *th; - struct location *l, *tl; - struct proxy *p, *tp; - struct envlist *e, *te; - struct alist *a, *ta; - int v; - - v = conf.verbose; - - free_mime(&conf.mime); - memset(&conf, 0, sizeof(conf)); - - conf.verbose = v; - - TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) { - TAILQ_FOREACH_SAFE(l, &h->locations, locations, tl) { - TAILQ_REMOVE(&h->locations, l, locations); - - if (l->dirfd != -1) - close(l->dirfd); - - free(l); - } - - TAILQ_FOREACH_SAFE(e, &h->params, envs, te) { - TAILQ_REMOVE(&h->params, e, envs); - free(e); - } - - TAILQ_FOREACH_SAFE(a, &h->aliases, aliases, ta) { - TAILQ_REMOVE(&h->aliases, a, aliases); - free(a); - } - - TAILQ_FOREACH_SAFE(p, &h->proxies, proxies, tp) { - TAILQ_REMOVE(&h->proxies, p, proxies); - tls_unload_file(p->cert, p->certlen); - tls_unload_file(p->key, p->keylen); - free(p); - } - - TAILQ_REMOVE(&hosts, h, vhosts); - free(h); - } - - memset(fcgi, 0, sizeof(fcgi)); -} - static int wait_signal(void) { @@ -319,7 +254,7 @@ main(int argc, char **argv) setlocale(LC_CTYPE, ""); logger_init(); - init_config(); + config_init(); while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch (ch) { @@ -416,8 +351,8 @@ main(int argc, char **argv) old_ipv6 = conf.ipv6; old_port = conf.port; - free_config(); - init_config(); + config_free(); + config_init(); parse_conf(config_path); if (old_port != conf.port) { @@ -293,10 +293,12 @@ enum imsg_type { char *data_dir(void); void load_local_cert(struct vhost*, const char*, const char*); int make_socket(int, int); -void init_config(void); -void free_config(void); void drop_priv(void); +/* config.c */ +void config_init(void); +void config_free(void); + void yyerror(const char*, ...); void parse_conf(const char*); void print_conf(void); |