diff --git a/src/cfgfile.c b/src/cfgfile.c index 30bc55e8..5cb633f7 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -1989,7 +1989,7 @@ static void _parse_paths(xmlDocPtr doc, if (configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] == '/') configuration->adminroot_dir[strlen(configuration->adminroot_dir)-1] = 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->source = (char *)xmlGetProp(node, XMLSTR("source")); alias->destination = (char *)xmlGetProp(node, XMLSTR("destination")); @@ -2021,6 +2021,10 @@ static void _parse_paths(xmlDocPtr doc, } else { alias->omode = OMODE_DEFAULT; } + + temp = (char *)xmlGetProp(node, XMLSTR("prefixmatch")); + alias->flags |= util_str_to_bool(temp) ? ALIAS_FLAG_PREFIXMATCH : 0; + current = configuration->aliases; last = NULL; while (current) { diff --git a/src/cfgfile.h b/src/cfgfile.h index e339a19e..7df6153e 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -155,6 +155,8 @@ typedef struct _mount_proxy { struct _mount_proxy *next; } mount_proxy; +#define ALIAS_FLAG_PREFIXMATCH 0x0001 + typedef struct _aliases { char *source; char *destination; @@ -162,6 +164,7 @@ typedef struct _aliases { char *bind_address; char *vhost; operation_mode omode; + unsigned int flags; struct _aliases *next; } aliases; diff --git a/src/connection.c b/src/connection.c index 1d4e5b84..84f87701 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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. */ /* Check for the URI to match. */ - if (strcmp(*uri, alias->source) != 0) - continue; + 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) + continue; + } /* Check for the server's port to match. */ 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. */ - if (alias->destination) - new_uri = strdup(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); + } + } if (alias->omode != OMODE_DEFAULT) client->mode = alias->omode; ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri);