Commit Diff


commit - 0046c1fe9ca72ed024c8562d51e2b320f7968915
commit + c68baad22af4c65c090a3ba6d83a155561275134
blob - 752e656ddf3c9cc5fda661ef928affcb351f2d7e
blob + d950f33526afcd47e86b940b54e6eb977ea37c60
--- Makefile
+++ Makefile
@@ -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 \
blob - /dev/null
blob + 7a438a5cda87f6c53de9803f4203f6ac80f6c410 (mode 644)
--- /dev/null
+++ 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));
+}
blob - 10d0c0010f5028b63b95669ba5b52d8a0995ce48
blob + 6afe035d3db117b210554f087755cb1f99bc6f59
--- ge.c
+++ ge.c
@@ -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) {
blob - a0f6b970abe5a313e0e5cdd7d82ae9ae858c6ec2
blob + 23471c34a2989c8a0eb6b88f0741f1e9f5dc0f5f
--- gmid.c
+++ gmid.c
@@ -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) {
blob - 3d755da82018c14a1bab0a289c733b6c3aa152f6
blob + 63d5daab0ddf7534f0aa76a6d9c4291100518466
--- gmid.h
+++ gmid.h
@@ -293,9 +293,11 @@ 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*);