1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Feature: Allow prefix matching aliases

This commit is contained in:
Philipp Schafft 2018-05-28 09:37:28 +00:00
parent 6c0b0e2976
commit 29c0501237
3 changed files with 25 additions and 5 deletions

View File

@ -1989,7 +1989,7 @@ static void _parse_paths(xmlDocPtr doc,
if (configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] == '/') if (configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] == '/')
configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] = 0; configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] = 0;
} else if (xmlStrcmp(node->name, XMLSTR("resource")) == 0 || xmlStrcmp(node->name, XMLSTR("alias")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("resource")) == 0 || xmlStrcmp(node->name, XMLSTR("alias")) == 0) {
alias = malloc(sizeof(aliases)); alias = calloc(1, sizeof(aliases));
alias->next = NULL; alias->next = NULL;
alias->source = (char *)xmlGetProp(node, XMLSTR("source")); alias->source = (char *)xmlGetProp(node, XMLSTR("source"));
alias->destination = (char *)xmlGetProp(node, XMLSTR("destination")); alias->destination = (char *)xmlGetProp(node, XMLSTR("destination"));
@ -2021,6 +2021,10 @@ static void _parse_paths(xmlDocPtr doc,
} else { } else {
alias->omode = OMODE_DEFAULT; alias->omode = OMODE_DEFAULT;
} }
temp = (char *)xmlGetProp(node, XMLSTR("prefixmatch"));
alias->flags |= util_str_to_bool(temp) ? ALIAS_FLAG_PREFIXMATCH : 0;
current = configuration->aliases; current = configuration->aliases;
last = NULL; last = NULL;
while (current) { while (current) {

View File

@ -155,6 +155,8 @@ typedef struct _mount_proxy {
struct _mount_proxy *next; struct _mount_proxy *next;
} mount_proxy; } mount_proxy;
#define ALIAS_FLAG_PREFIXMATCH 0x0001
typedef struct _aliases { typedef struct _aliases {
char *source; char *source;
char *destination; char *destination;
@ -162,6 +164,7 @@ typedef struct _aliases {
char *bind_address; char *bind_address;
char *vhost; char *vhost;
operation_mode omode; operation_mode omode;
unsigned int flags;
struct _aliases *next; struct _aliases *next;
} aliases; } aliases;

View File

@ -1112,8 +1112,15 @@ static int _handle_aliases(client_t *client, char **uri)
/* We check for several aspects, if they DO NOT match, we continue with our search. */ /* We check for several aspects, if they DO NOT match, we continue with our search. */
/* Check for the URI to match. */ /* Check for the URI to match. */
if (alias->flags & ALIAS_FLAG_PREFIXMATCH) {
size_t len = strlen(alias->source);
if (strncmp(*uri, alias->source, len) != 0)
continue;
ICECAST_LOG_DEBUG("Match: *uri='%s', alias->source='%s', len=%zu", *uri, alias->source, len);
} else {
if (strcmp(*uri, alias->source) != 0) if (strcmp(*uri, alias->source) != 0)
continue; continue;
}
/* Check for the server's port to match. */ /* Check for the server's port to match. */
if (alias->port != -1 && alias->port != serverport) if (alias->port != -1 && alias->port != serverport)
@ -1129,8 +1136,14 @@ static int _handle_aliases(client_t *client, char **uri)
/* Ok, we found a matching entry. */ /* Ok, we found a matching entry. */
if (alias->destination) if (alias->destination) {
if (alias->flags & ALIAS_FLAG_PREFIXMATCH) {
size_t len = strlen(alias->source);
asprintf(&new_uri, "%s%s", alias->destination, (*uri) + len);
} else {
new_uri = strdup(alias->destination); new_uri = strdup(alias->destination);
}
}
if (alias->omode != OMODE_DEFAULT) if (alias->omode != OMODE_DEFAULT)
client->mode = alias->omode; client->mode = alias->omode;
ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri); ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri);