diff options
author | Omar Polo <op@omarpolo.com> | 2023-06-06 08:18:57 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2023-06-06 08:18:57 +0000 |
commit | c68baad22af4c65c090a3ba6d83a155561275134 (patch) | |
tree | 7fbf71b9c1151fc0df1dace08e785c12e74d70a9 /config.c | |
parent | 0046c1fe9ca72ed024c8562d51e2b320f7968915 (diff) |
move config-related code to config.c
reuse it in ge too.
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 84 |
1 files changed, 84 insertions, 0 deletions
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)); +} |