From 6c0b0e29767d59bd1f79ca2aa86ba30166e51537 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Mon, 28 May 2018 09:07:07 +0000 Subject: [PATCH] Update: Make the alias dereferencing loop more easy --- src/connection.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/connection.c b/src/connection.c index 8a6fc20d..1d4e5b84 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1107,19 +1107,34 @@ static int _handle_aliases(client_t *client, char **uri) alias = config->aliases; - while (alias) { - if (strcmp(*uri, alias->source) == 0 && - (alias->port == -1 || alias->port == serverport) && - (alias->bind_address == NULL || (serverhost != NULL && strcmp(alias->bind_address, serverhost) == 0)) && - (alias->vhost == NULL || (vhost != NULL && strcmp(alias->vhost, vhost) == 0)) ) { - if (alias->destination) - new_uri = strdup(alias->destination); - if (alias->omode != OMODE_DEFAULT) - client->mode = alias->omode; - ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri); - break; - } - alias = alias->next; + /* We now go thru all aliases and see if any matches. */ + for (; alias; alias = alias->next) { + /* We check for several aspects, if they DO NOT match, we continue with our search. */ + + /* Check for the URI to match. */ + if (strcmp(*uri, alias->source) != 0) + continue; + + /* Check for the server's port to match. */ + if (alias->port != -1 && alias->port != serverport) + continue; + + /* Check for the server's bind address to match. */ + if (alias->bind_address != NULL && serverhost != NULL && strcmp(alias->bind_address, serverhost) != 0) + continue; + + /* Check for the vhost to match. */ + if (alias->vhost != NULL && vhost != NULL && strcmp(alias->vhost, vhost) != 0) + continue; + + /* Ok, we found a matching entry. */ + + if (alias->destination) + new_uri = strdup(alias->destination); + if (alias->omode != OMODE_DEFAULT) + client->mode = alias->omode; + ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri); + break; } config_release_config();