Commit e2d6bdb8 authored by Karl Heyes's avatar Karl Heyes
Browse files

add function to do mount list search (could be extended later), call it from

various places including the shoutcast source client auth which previously
only used the global source password.

svn path=/icecast/trunk/icecast/; revision=9240
parent 6d48d6c4
...@@ -979,3 +979,17 @@ static void _add_server(xmlDocPtr doc, xmlNodePtr node, ...@@ -979,3 +979,17 @@ static void _add_server(xmlDocPtr doc, xmlNodePtr node,
} }
/* return the mount details that match the supplied mountpoint */
mount_proxy *config_find_mount (ice_config_t *config, const char *mount)
{
mount_proxy *mountinfo = config->mounts;
while (mountinfo)
{
if (strcmp (mountinfo->mountname, mount) == 0)
break;
mountinfo = mountinfo->next;
}
return mountinfo;
}
...@@ -160,6 +160,7 @@ int config_initial_parse_file(const char *filename); ...@@ -160,6 +160,7 @@ int config_initial_parse_file(const char *filename);
int config_parse_cmdline(int arg, char **argv); int config_parse_cmdline(int arg, char **argv);
void config_set_config(ice_config_t *config); void config_set_config(ice_config_t *config);
void config_clear(ice_config_t *config); void config_clear(ice_config_t *config);
mount_proxy *config_find_mount (ice_config_t *config, const char *mount);
int config_rehash(void); int config_rehash(void);
......
...@@ -449,7 +449,7 @@ int connection_complete_source (source_t *source) ...@@ -449,7 +449,7 @@ int connection_complete_source (source_t *source)
if (global.sources < config->source_limit) if (global.sources < config->source_limit)
{ {
char *contenttype; char *contenttype;
mount_proxy *mountproxy = config->mounts; mount_proxy *mountproxy;
format_type_t format_type; format_type_t format_type;
/* setup format handler */ /* setup format handler */
...@@ -516,15 +516,10 @@ int connection_complete_source (source_t *source) ...@@ -516,15 +516,10 @@ int connection_complete_source (source_t *source)
} }
} }
while (mountproxy) mountproxy = config_find_mount (config, source->mount);
{ if (mountproxy)
if (strcmp (mountproxy->mountname, source->mount) == 0) source_apply_mount (source, mountproxy);
{
source_apply_mount (source, mountproxy);
break;
}
mountproxy = mountproxy->next;
}
config_release_config(); config_release_config();
source->shutdown_rwlock = &_source_shutdown_rwlock; source->shutdown_rwlock = &_source_shutdown_rwlock;
...@@ -651,7 +646,7 @@ int connection_check_relay_pass(http_parser_t *parser) ...@@ -651,7 +646,7 @@ int connection_check_relay_pass(http_parser_t *parser)
return ret; return ret;
} }
int connection_check_source_pass(http_parser_t *parser, char *mount) int connection_check_source_pass(http_parser_t *parser, const char *mount)
{ {
ice_config_t *config = config_get_config(); ice_config_t *config = config_get_config();
char *pass = config->source_password; char *pass = config->source_password;
...@@ -660,22 +655,16 @@ int connection_check_source_pass(http_parser_t *parser, char *mount) ...@@ -660,22 +655,16 @@ int connection_check_source_pass(http_parser_t *parser, char *mount)
int ice_login = config->ice_login; int ice_login = config->ice_login;
char *protocol; char *protocol;
mount_proxy *mountinfo = config->mounts; mount_proxy *mountinfo = config_find_mount (config, mount);
thread_mutex_lock(&(config_locks()->mounts_lock));
while(mountinfo) { if (mountinfo)
if(!strcmp(mountinfo->mountname, mount)) { {
if(mountinfo->password) if (mountinfo->password)
pass = mountinfo->password; pass = mountinfo->password;
if(mountinfo->username) if (mountinfo->username)
user = mountinfo->username; user = mountinfo->username;
break;
}
mountinfo = mountinfo->next;
} }
thread_mutex_unlock(&(config_locks()->mounts_lock));
if(!pass) { if(!pass) {
WARN0("No source password set, rejecting source"); WARN0("No source password set, rejecting source");
config_release_config(); config_release_config();
...@@ -1081,7 +1070,11 @@ static void *_handle_connection(void *arg) ...@@ -1081,7 +1070,11 @@ static void *_handle_connection(void *arg)
config = config_get_config(); config = config_get_config();
if (config->listeners[i].shoutcast_compat) { if (config->listeners[i].shoutcast_compat) {
char *shoutcast_mount = strdup (config->shoutcast_mount); char *shoutcast_mount = strdup (config->shoutcast_mount);
source_password = strdup(config->source_password); mount_proxy *mountinfo = config_find_mount (config, config->shoutcast_mount);
if (mountinfo && mountinfo->password)
source_password = strdup (mountinfo->password);
else
source_password = strdup (config->source_password);
config_release_config(); config_release_config();
_handle_shoutcast_compatible(con, shoutcast_mount, source_password); _handle_shoutcast_compatible(con, shoutcast_mount, source_password);
free(source_password); free(source_password);
......
...@@ -52,7 +52,7 @@ int connection_complete_source (struct source_tag *source); ...@@ -52,7 +52,7 @@ int connection_complete_source (struct source_tag *source);
void connection_inject_event(int eventnum, void *event_data); void connection_inject_event(int eventnum, void *event_data);
int connection_check_source_pass(http_parser_t *parser, char *mount); int connection_check_source_pass(http_parser_t *parser, const char *mount);
int connection_check_relay_pass(http_parser_t *parser); int connection_check_relay_pass(http_parser_t *parser);
int connection_check_admin_pass(http_parser_t *parser); int connection_check_admin_pass(http_parser_t *parser);
......
...@@ -147,34 +147,22 @@ source_t *source_find_mount (const char *mount) ...@@ -147,34 +147,22 @@ source_t *source_find_mount (const char *mount)
int depth = 0; int depth = 0;
config = config_get_config(); config = config_get_config();
while (mount != NULL) while (mount && depth < MAX_FALLBACK_DEPTH)
{ {
/* limit the number of times through, maybe infinite */
if (depth > MAX_FALLBACK_DEPTH)
{
source = NULL;
break;
}
source = source_find_mount_raw(mount); source = source_find_mount_raw(mount);
if (source != NULL && source->running) if (source != NULL && source->running)
break; break;
/* source is not running, meaning that the fallback is not configured /* we either have a source which is not active (relay) or no source
within the source, we need to check the mount list */ * at all. Check the mounts list for fallback settings
mountinfo = config->mounts; */
mountinfo = config_find_mount (config, mount);
source = NULL; source = NULL;
while (mountinfo)
{ if (mountinfo == NULL)
if (strcmp (mountinfo->mountname, mount) == 0) break;
break; mount = mountinfo->fallback_mount;
mountinfo = mountinfo->next;
}
if (mountinfo)
mount = mountinfo->fallback_mount;
else
mount = NULL;
depth++; depth++;
} }
......
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