Commit 07ee2814 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Cleanup: Renamed alias -> resource

parent 29c05012
......@@ -573,8 +573,8 @@ void config_clear(ice_config_t *c)
*nextrelay;
mount_proxy *mount,
*nextmount;
aliases *alias,
*nextalias;
resource_t *resource,
*nextresource;
#ifdef USE_YP
int i;
#endif
......@@ -633,15 +633,15 @@ void config_clear(ice_config_t *c)
mount = nextmount;
}
alias = c->aliases;
while (alias) {
nextalias = alias->next;
xmlFree(alias->source);
xmlFree(alias->destination);
xmlFree(alias->bind_address);
xmlFree(alias->vhost);
free(alias);
alias = nextalias;
resource = c->resources;
while (resource) {
nextresource = resource->next;
xmlFree(resource->source);
xmlFree(resource->destination);
xmlFree(resource->bind_address);
xmlFree(resource->vhost);
free(resource);
resource = nextresource;
}
dirnode = c->dir_list;
......@@ -1905,7 +1905,7 @@ static void _parse_paths(xmlDocPtr doc,
ice_config_t *configuration)
{
char *temp;
aliases *alias,
resource_t *resource,
*current,
*last;
......@@ -1989,52 +1989,52 @@ 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 = calloc(1, sizeof(aliases));
alias->next = NULL;
alias->source = (char *)xmlGetProp(node, XMLSTR("source"));
alias->destination = (char *)xmlGetProp(node, XMLSTR("destination"));
if (!alias->destination)
alias->destination = (char *)xmlGetProp(node, XMLSTR("dest"));
if (!alias->source && alias->destination) {
alias->source = alias->destination;
alias->destination = NULL;
} else if (!alias->source && !alias->destination) {
xmlFree(alias->source);
xmlFree(alias->destination);
free(alias);
resource = calloc(1, sizeof(resource_t));
resource->next = NULL;
resource->source = (char *)xmlGetProp(node, XMLSTR("source"));
resource->destination = (char *)xmlGetProp(node, XMLSTR("destination"));
if (!resource->destination)
resource->destination = (char *)xmlGetProp(node, XMLSTR("dest"));
if (!resource->source && resource->destination) {
resource->source = resource->destination;
resource->destination = NULL;
} else if (!resource->source && !resource->destination) {
xmlFree(resource->source);
xmlFree(resource->destination);
free(resource);
continue;
}
temp = (char *)xmlGetProp(node, XMLSTR("port"));
if(temp != NULL) {
alias->port = util_str_to_int(temp, alias->port);
resource->port = util_str_to_int(temp, resource->port);
xmlFree(temp);
} else {
alias->port = -1;
resource->port = -1;
}
alias->bind_address = (char *)xmlGetProp(node, XMLSTR("bind-address"));
alias->vhost = (char *)xmlGetProp(node, XMLSTR("vhost"));
resource->bind_address = (char *)xmlGetProp(node, XMLSTR("bind-address"));
resource->vhost = (char *)xmlGetProp(node, XMLSTR("vhost"));
temp = (char *)xmlGetProp(node, XMLSTR("omode"));
if (temp) {
alias->omode = config_str_to_omode(temp);
resource->omode = config_str_to_omode(temp);
xmlFree(temp);
} else {
alias->omode = OMODE_DEFAULT;
resource->omode = OMODE_DEFAULT;
}
temp = (char *)xmlGetProp(node, XMLSTR("prefixmatch"));
alias->flags |= util_str_to_bool(temp) ? ALIAS_FLAG_PREFIXMATCH : 0;
resource->flags |= util_str_to_bool(temp) ? ALIAS_FLAG_PREFIXMATCH : 0;
current = configuration->aliases;
current = configuration->resources;
last = NULL;
while (current) {
last = current;
current = current->next;
}
if(last) {
last->next = alias;
last->next = resource;
} else {
configuration->aliases = alias;
configuration->resources = resource;
}
}
} while ((node = node->next));
......
......@@ -157,7 +157,7 @@ typedef struct _mount_proxy {
#define ALIAS_FLAG_PREFIXMATCH 0x0001
typedef struct _aliases {
typedef struct _resource {
char *source;
char *destination;
int port;
......@@ -165,8 +165,8 @@ typedef struct _aliases {
char *vhost;
operation_mode omode;
unsigned int flags;
struct _aliases *next;
} aliases;
struct _resource *next;
} resource_t;
typedef struct _listener_t {
struct _listener_t *next;
......@@ -241,7 +241,7 @@ typedef struct ice_config_tag {
char *allowfile;
char *webroot_dir;
char *adminroot_dir;
aliases *aliases;
resource_t *resources;
char *access_log;
char *error_log;
......
......@@ -1074,10 +1074,10 @@ static void _handle_shoutcast_compatible(client_queue_t *node)
return;
}
/* Handle <alias> lookups here.
/* Handle <resource> lookups here.
*/
static int _handle_aliases(client_t *client, char **uri)
static int _handle_resources(client_t *client, char **uri)
{
const char *http_host = httpp_getvar(client->parser, "host");
char *serverhost = NULL;
......@@ -1087,7 +1087,7 @@ static int _handle_aliases(client_t *client, char **uri)
char *new_uri = NULL;
ice_config_t *config;
listener_t *listen_sock;
aliases *alias;
resource_t *resource;
if (http_host) {
vhost = strdup(http_host);
......@@ -1105,48 +1105,48 @@ static int _handle_aliases(client_t *client, char **uri)
serverport = listen_sock->port;
}
alias = config->aliases;
resource = config->resources;
/* We now go thru all aliases and see if any matches. */
for (; alias; alias = alias->next) {
/* We now go thru all resources and see if any matches. */
for (; resource; resource = resource->next) {
/* 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)
if (resource->flags & ALIAS_FLAG_PREFIXMATCH) {
size_t len = strlen(resource->source);
if (strncmp(*uri, resource->source, len) != 0)
continue;
ICECAST_LOG_DEBUG("Match: *uri='%s', alias->source='%s', len=%zu", *uri, alias->source, len);
ICECAST_LOG_DEBUG("Match: *uri='%s', resource->source='%s', len=%zu", *uri, resource->source, len);
} else {
if (strcmp(*uri, alias->source) != 0)
if (strcmp(*uri, resource->source) != 0)
continue;
}
/* Check for the server's port to match. */
if (alias->port != -1 && alias->port != serverport)
if (resource->port != -1 && resource->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)
if (resource->bind_address != NULL && serverhost != NULL && strcmp(resource->bind_address, serverhost) != 0)
continue;
/* Check for the vhost to match. */
if (alias->vhost != NULL && vhost != NULL && strcmp(alias->vhost, vhost) != 0)
if (resource->vhost != NULL && vhost != NULL && strcmp(resource->vhost, vhost) != 0)
continue;
/* Ok, we found a matching entry. */
if (alias->destination) {
if (alias->flags & ALIAS_FLAG_PREFIXMATCH) {
size_t len = strlen(alias->source);
asprintf(&new_uri, "%s%s", alias->destination, (*uri) + len);
if (resource->destination) {
if (resource->flags & ALIAS_FLAG_PREFIXMATCH) {
size_t len = strlen(resource->source);
asprintf(&new_uri, "%s%s", resource->destination, (*uri) + len);
} else {
new_uri = strdup(alias->destination);
new_uri = strdup(resource->destination);
}
}
if (alias->omode != OMODE_DEFAULT)
client->mode = alias->omode;
ICECAST_LOG_DEBUG("alias has made %s into %s", *uri, new_uri);
if (resource->omode != OMODE_DEFAULT)
client->mode = resource->omode;
ICECAST_LOG_DEBUG("resource has made %s into %s", *uri, new_uri);
break;
}
......@@ -1405,7 +1405,7 @@ static void _handle_connection(void)
client->mode = config_str_to_omode(httpp_get_query_param(client->parser, "omode"));
if (_handle_aliases(client, &uri) != 0) {
if (_handle_resources(client, &uri) != 0) {
client_destroy (client);
continue;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment