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:
parent
6c0b0e2976
commit
29c0501237
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 (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)
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user