commit afb86b2c8a6e846c6e088085f3b454f3b4bdd5c8 from: Omar Polo date: Fri Sep 23 12:45:10 2022 UTC simplify the configuration format don't require the awkward `server' block, just use a `proxy' block: proxy { source address port xyz hostname foo stylesheet "URL" } commit - cbd105cef32d502b2d191cabe53407ee9bac5913 commit + afb86b2c8a6e846c6e088085f3b454f3b4bdd5c8 blob - 3d23c2ed4686dab24f05a354b7f7d7c9850bb888 blob + 75cb58cebcb314bd5ee333e807e71c0734d1f29f --- config.c +++ config.c @@ -50,7 +50,7 @@ config_init(struct galileo *env) env->sc_prefork = PROXY_NUMPROC; /* Other configuration. */ - TAILQ_INIT(&env->sc_servers); + TAILQ_INIT(&env->sc_proxies); env->sc_sock_fd = -1; @@ -60,41 +60,40 @@ config_init(struct galileo *env) void config_purge(struct galileo *env) { - struct server *srv; + struct proxy *p; - while ((srv = TAILQ_FIRST(&env->sc_servers)) != NULL) { - TAILQ_REMOVE(&env->sc_servers, srv, srv_entry); - proxy_purge(srv); + while ((p = TAILQ_FIRST(&env->sc_proxies)) != NULL) { + TAILQ_REMOVE(&env->sc_proxies, p, pr_entry); + proxy_purge(p); } } int -config_setserver(struct galileo *env, struct server *srv) +config_setproxy(struct galileo *env, struct proxy *p) { struct privsep *ps = env->sc_ps; - if (proc_compose(ps, PROC_PROXY, IMSG_CFG_SRV, srv, sizeof(*srv)) - == -1) + if (proc_compose(ps, PROC_PROXY, IMSG_CFG_SRV, p, sizeof(*p)) == -1) fatal("proc_compose"); return 0; } int -config_getserver(struct galileo *env, struct imsg *imsg) +config_getproxy(struct galileo *env, struct imsg *imsg) { - struct server *srv; + struct proxy *proxy; - srv = xcalloc(1, sizeof(*srv)); - if (IMSG_DATA_SIZE(imsg) != sizeof(*srv)) + proxy = xcalloc(1, sizeof(*proxy)); + if (IMSG_DATA_SIZE(imsg) != sizeof(*proxy)) fatalx("%s: bad imsg size", __func__); - memcpy(srv, imsg->data, sizeof(*srv)); + memcpy(proxy, imsg->data, sizeof(*proxy)); log_debug("%s: server=%s proxy-to=%s:%d (%s)", __func__, - srv->srv_conf.host, srv->srv_conf.proxy_addr, - srv->srv_conf.proxy_port, srv->srv_conf.proxy_name); + proxy->pr_conf.host, proxy->pr_conf.proxy_addr, + proxy->pr_conf.proxy_port, proxy->pr_conf.proxy_name); - TAILQ_INSERT_TAIL(&env->sc_servers, srv, srv_entry); + TAILQ_INSERT_TAIL(&env->sc_proxies, proxy, pr_entry); return 0; } blob - f0dca409026b865ebce690d75fdd232c7052c2b5 blob + 447f69eec11373fc8347bf7ef04bd3438e4789f1 --- galileo.c +++ galileo.c @@ -205,19 +205,19 @@ main(int argc, char **argv) static int parent_configure(struct galileo *env) { - struct server *srv; + struct proxy *proxy; int id; - TAILQ_FOREACH(srv, &env->sc_servers, srv_entry) { - if (config_setserver(env, srv) == -1) - fatal("send server"); + TAILQ_FOREACH(proxy, &env->sc_proxies, pr_entry) { + if (config_setproxy(env, proxy) == -1) + fatal("send proxy"); } /* XXX: eventually they will be more than just one */ if (config_setsock(env) == -1) fatal("send socket"); - /* The servers need to reload their config. */ + /* The proxiess need to reload their config. */ env->sc_reload = env->sc_prefork; for (id = 0; id < PROC_MAX; id++) { blob - 37590580ae2b38c294c24ffe438fa1b2384859d5 blob + 01c32897bb8d5f0b0b97c8f0ef15b277e9f14665 --- galileo.h +++ galileo.h @@ -121,17 +121,17 @@ struct proxy_config { uint16_t proxy_port; /* TODO: turn into string */ }; -struct server { - TAILQ_ENTRY(server) srv_entry; - struct proxy_config srv_conf; +struct proxy { + TAILQ_ENTRY(proxy) pr_entry; + struct proxy_config pr_conf; }; -TAILQ_HEAD(serverlist, server); +TAILQ_HEAD(proxylist, proxy); struct galileo { char sc_conffile[PATH_MAX]; uint16_t sc_prefork; char sc_chroot[PATH_MAX]; - struct serverlist sc_servers; + struct proxylist sc_proxies; struct fcgi_tree sc_fcgi_socks; struct privsep *sc_ps; @@ -148,8 +148,8 @@ extern int privsep_process; /* config.c */ int config_init(struct galileo *); void config_purge(struct galileo *); -int config_setserver(struct galileo *, struct server *); -int config_getserver(struct galileo *, struct imsg *); +int config_setproxy(struct galileo *, struct proxy *); +int config_getproxy(struct galileo *, struct imsg *); int config_setsock(struct galileo *); int config_getsock(struct galileo *, struct imsg *); int config_setreset(struct galileo *); @@ -194,7 +194,7 @@ extern volatile int proxy_inflight; extern uint32_t proxy_fcg_id; void proxy(struct privsep *, struct privsep_proc *); -void proxy_purge(struct server *); +void proxy_purge(struct proxy *); int proxy_start_request(struct galileo *, struct client *); void proxy_client_free(struct client *); blob - 2f6ad087b9d0f3d8b128f73aef43fef2cd5bbe56 blob + f3ace66e6d54ee9b2e1a146beb72b64c66772252 --- parse.y +++ parse.y @@ -88,7 +88,7 @@ char *symget(const char *); int getservice(const char *); static struct galileo *conf = NULL; -static struct server *srv = NULL; +static struct proxy *pr = NULL; static int errors; typedef struct { @@ -102,7 +102,7 @@ typedef struct { %} %token INCLUDE ERROR -%token CHROOT HOSTNAME PORT PREFORK PROXY SERVER SOURCE STYLESHEET +%token CHROOT HOSTNAME PORT PREFORK PROXY SOURCE STYLESHEET %type NUMBER %type port %type STRING @@ -115,7 +115,7 @@ grammar : /* empty */ | grammar '\n' | grammar varset '\n' | grammar main '\n' - | grammar server '\n' + | grammar proxy '\n' | grammar error '\n' { file->errors++; } ; @@ -155,7 +155,7 @@ varset : STRING '=' STRING { main : PREFORK NUMBER { if ($2 <= 0 || $2 > PROC_MAX_INSTANCES) { yyerror("invalid number of preforked " - "servers: %lld", $2); + "proxies: %lld", $2); YYERROR; } conf->sc_prefork = $2; @@ -171,74 +171,64 @@ main : PREFORK NUMBER { } ; -server : SERVER STRING { - struct server *s; +proxy : PROXY STRING { + struct proxy *p; size_t n; - if ((s = calloc(1, sizeof(*s))) == NULL) + if ((p = calloc(1, sizeof(*p))) == NULL) fatal("calloc"); - n = strlcpy(s->srv_conf.host, $2, - sizeof(s->srv_conf.host)); - if (n >= sizeof(s->srv_conf.host)) { + n = strlcpy(p->pr_conf.host, $2, + sizeof(p->pr_conf.host)); + if (n >= sizeof(p->pr_conf.host)) { yyerror("server name too long"); free($2); - free(s); + free(p); YYERROR; } free($2); - srv = s; - TAILQ_INSERT_TAIL(&conf->sc_servers, srv, srv_entry); - } '{' optnl serveropts_l '}' { + pr = p; + TAILQ_INSERT_TAIL(&conf->sc_proxies, p, pr_entry); + } '{' optnl proxyopts_l '}' { /* check if duplicate */ /* eventually load the tls certs */ - srv = NULL; + pr = NULL; } ; -serveropts_l : serveropts_l serveroptsl nl - | serveroptsl optnl +proxyopts_l : proxyopts_l proxyoptsl nl + | proxyoptsl optnl ; -serveroptsl : PROXY STRING { - /* ... */ - } - | PROXY '{' optnl proxyopts_l '}' - | STYLESHEET string { +proxyoptsl : SOURCE STRING PORT port { size_t n; - n = strlcpy(srv->srv_conf.stylesheet, $2, - sizeof(srv->srv_conf.stylesheet)); - if (n >= sizeof(srv->srv_conf.stylesheet)) - yyerror("stylesheet path too long!"); + n = strlcpy(pr->pr_conf.proxy_addr, $2, + sizeof(pr->pr_conf.proxy_addr)); + if (n >= sizeof(pr->pr_conf.proxy_addr)) + yyerror("proxy source too long!"); + pr->pr_conf.proxy_port = $4; + free($2); } - ; - -proxyopts_l : proxyopts_l proxyoptsl nl - | proxyoptsl optnl - ; - -proxyoptsl : SOURCE STRING PORT port { + | HOSTNAME STRING { size_t n; - n = strlcpy(srv->srv_conf.proxy_addr, $2, - sizeof(srv->srv_conf.proxy_addr)); - if (n >= sizeof(srv->srv_conf.proxy_addr)) - yyerror("proxy source too long!"); - srv->srv_conf.proxy_port = $4; - + n = strlcpy(pr->pr_conf.proxy_name, $2, + sizeof(pr->pr_conf.proxy_name)); + if (n >= sizeof(pr->pr_conf.proxy_name)) + yyerror("proxy hostname too long!"); free($2); } - | HOSTNAME STRING { + | STYLESHEET string { size_t n; - n = strlcpy(srv->srv_conf.proxy_name, $2, - sizeof(srv->srv_conf.proxy_name)); - if (n >= sizeof(srv->srv_conf.proxy_name)) - yyerror("proxy hostname too long!"); + n = strlcpy(pr->pr_conf.stylesheet, $2, + sizeof(pr->pr_conf.stylesheet)); + if (n >= sizeof(pr->pr_conf.stylesheet)) + yyerror("stylesheet path too long!"); free($2); } ; @@ -319,7 +309,6 @@ lookup(char *s) { "port", PORT }, { "prefork", PREFORK }, { "proxy", PROXY }, - { "server", SERVER }, { "source", SOURCE }, { "stylesheet", STYLESHEET}, }; blob - 0715706983dee0bcf3a83eafd36fb16bf7bf8197 blob + c987fa20d8b181b09f97ab77043a03c203b76d9d --- proxy.c +++ proxy.c @@ -101,7 +101,7 @@ proxy_launch(struct galileo *env) } void -proxy_purge(struct server *srv) +proxy_purge(struct proxy *srv) { } @@ -121,7 +121,7 @@ proxy_dispatch_parent(int fd, struct privsep_proc *p, switch (imsg->hdr.type) { case IMSG_CFG_SRV: - if (config_getserver(env, imsg) == -1) + if (config_getproxy(env, imsg) == -1) fatal("config_getproxy"); break; case IMSG_CFG_SOCK: @@ -337,14 +337,14 @@ proxy_translate_gemtext(struct client *clt) static struct proxy_config * proxy_server_match(struct galileo *env, struct client *clt) { - struct server *srv; + struct proxy *pr; if (clt->clt_server_name == NULL) return NULL; - TAILQ_FOREACH(srv, &env->sc_servers, srv_entry) { - if (!strcmp(clt->clt_server_name, srv->srv_conf.host)) - return &srv->srv_conf; + TAILQ_FOREACH(pr, &env->sc_proxies, pr_entry) { + if (!strcmp(clt->clt_server_name, pr->pr_conf.host)) + return &pr->pr_conf; } return NULL;