Download raw body.
httpd: replace server_match by server_bysocket and server_byname
httpd: replace server_match by server_bysocket and server_byname
On Thu, 22 Oct 2026 17:37:13 +0200,
Rafael Sadowski <rafael@sizeofvoid.org> wrote:
>
> I would like to introduce this two wrapper functions which makes the
> caller code more readable.
>
> No functional change, OK?
>
> Rafael
>
Maybe make server_match() static and does not use it outside of new helpers?
> diff --git a/httpd.c b/httpd.c
> index 4d537ec..03d18e3 100644
> --- a/httpd.c
> +++ b/httpd.c
> @@ -299,7 +299,7 @@ parent_configure(struct httpd *env)
> /* start the rekey of the tls ticket keys */
> if (srv->srv_conf.flags & SRVFLAG_TLS &&
> srv->srv_conf.tls_ticket_lifetime &&
> - server_match(srv, 0) == srv)
> + server_bysocket(srv) == srv)
> parent_tls_ticket_rekey_start(srv);
> if (config_setserver(env, srv) == -1)
> fatal("send server");
> diff --git a/httpd.h b/httpd.h
> index 1e54479..0226fd4 100644
> --- a/httpd.h
> +++ b/httpd.h
> @@ -694,7 +694,8 @@ struct server *server_byaddr(struct sockaddr *, in_port_t);
> struct server_config *serverconfig_byid(uint32_t);
> int server_foreach(int (*)(struct server *,
> struct server_config *, void *), void *);
> -struct server *server_match(struct server *, int);
> +struct server *server_byname(struct server *);
> +struct server *server_bysocket(struct server *);
>
> SPLAY_PROTOTYPE(client_tree, client, clt_nodes, server_client_cmp);
>
> diff --git a/parse.y b/parse.y
> index 3da8450..66d1edb 100644
> --- a/parse.y
> +++ b/parse.y
> @@ -351,7 +351,7 @@ server : SERVER optmatch STRING {
> srv_conf = &srv->srv_conf;
>
> /* Check if the new server already exists. */
> - if (server_match(srv, 1) != NULL) {
> + if (server_byname(srv) != NULL) {
> yyerror("server \"%s\" defined twice",
> srv->srv_conf.name);
> serverconfig_free(srv_conf);
> @@ -366,7 +366,7 @@ server : SERVER optmatch STRING {
> YYERROR;
> }
>
> - if ((s = server_match(srv, 0)) != NULL) {
> + if ((s = server_bysocket(srv)) != NULL) {
> if ((s->srv_conf.flags & SRVFLAG_TLS) !=
> (srv->srv_conf.flags & SRVFLAG_TLS)) {
> yyerror("server \"%s\": tls and "
> @@ -2658,7 +2658,7 @@ server_inherit(struct server *src, struct server_config *alias,
> }
>
> /* Check if the new server already exists */
> - if (server_match(dst, 1) != NULL) {
> + if (server_byname(dst) != NULL) {
> yyerror("server \"%s\" defined twice",
> dst->srv_conf.name);
> serverconfig_free(&dst->srv_conf);
> diff --git a/server.c b/server.c
> index 9975a1c..eb1270b 100644
> --- a/server.c
> +++ b/server.c
> @@ -69,6 +69,7 @@ void server_tls_handshake(int, short, void *);
> void server_accept(int, short, void *);
> void server_input(struct client *);
> void server_inflight_dec(struct client *, const char *);
> +static struct server *server_match(struct server *, int);
>
> extern void bufferevent_read_pressure_cb(struct evbuffer *, size_t,
> size_t, void *);
> @@ -607,6 +608,25 @@ server_foreach(int (*srv_cb)(struct server *,
> return (0);
> }
>
> +/*
> + * Return the server with the same name, address and port.
> + */
> +struct server *
> +server_byname(struct server *s)
> +{
> + return server_match(s, 1);
> +}
> +
> +/*
> + * Return the first server with the same address and port.
> + * This is the server that owns the socket.
> + */
> +struct server *
> +server_bysocket(struct server *s)
> +{
> + return server_match(s, 0);
> +}
> +
> struct server *
> server_match(struct server *s2, int match_name)
> {
>
--
wbr, Kirill
httpd: replace server_match by server_bysocket and server_byname
httpd: replace server_match by server_bysocket and server_byname