From b06942e1bcf0dedac7f9421c555829ea34240a79 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Mon, 21 Mar 2022 23:13:30 +0000 Subject: [PATCH] Feature: Use settings from the listen socket for YP if there is only one Closes: #2354 --- src/listensocket.c | 16 ++++++++++++++++ src/listensocket.h | 1 + src/yp.c | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/src/listensocket.c b/src/listensocket.c index 6265b952..0a716be4 100644 --- a/src/listensocket.c +++ b/src/listensocket.c @@ -520,6 +520,22 @@ listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self return NULL; } +/* may return NULL if there is no default */ +listensocket_t * listensocket_container_get_default(listensocket_container_t *self) +{ + listensocket_t *ret = NULL; + + thread_rwlock_rlock(&self->rwlock); + if (self->sock_len == 1) { + if (refobject_ref(self->sock[0]) == 0) { + ret = self->sock[0]; + } + } + thread_rwlock_unlock(&self->rwlock); + + return ret; +} + listensocket_t ** listensocket_container_list_sockets(listensocket_container_t *self) { listensocket_t **res; diff --git a/src/listensocket.h b/src/listensocket.h index a37344a7..58a5caf0 100644 --- a/src/listensocket.h +++ b/src/listensocket.h @@ -27,6 +27,7 @@ connection_t * listensocket_container_accept(listensocket_container int listensocket_container_set_sockcount_cb(listensocket_container_t *self, void (*cb)(size_t count, void *userdata), void *userdata); ssize_t listensocket_container_sockcount(listensocket_container_t *self); listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id); +listensocket_t * listensocket_container_get_default(listensocket_container_t *self); /* may return NULL if there is no default */ listensocket_t ** listensocket_container_list_sockets(listensocket_container_t *self); bool listensocket_container_is_family_included(listensocket_container_t *self, sock_family_t family); diff --git a/src/yp.c b/src/yp.c index 106f34bf..a7c64bca 100644 --- a/src/yp.c +++ b/src/yp.c @@ -611,6 +611,11 @@ static ypdata_t *create_yp_entry (struct yp_server *server, const char *mount) if (!listen_socket) ICECAST_LOG_ERROR("Failure to find listen socket with ID %#H, using default.", server->listen_socket_id); + } else { + listen_socket = listensocket_container_get_default(global.listensockets); + if (!listen_socket) { + ICECAST_LOG_WARN("There is no listen socket defined for this YP nor is there a default. Listen URLs might be wrong."); + } } ret = client_get_baseurl(NULL, listen_socket, url, len, NULL, NULL, NULL, mount, NULL); if (ret >= len) {