diff --git a/src/cfgfile.c b/src/cfgfile.c index 5cfb9e4d..48f21777 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -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; +} + diff --git a/src/cfgfile.h b/src/cfgfile.h index e87dee04..fababb8f 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -160,6 +160,7 @@ int config_initial_parse_file(const char *filename); int config_parse_cmdline(int arg, char **argv); void config_set_config(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); diff --git a/src/connection.c b/src/connection.c index 722b9925..e4ceb63a 100644 --- a/src/connection.c +++ b/src/connection.c @@ -449,7 +449,7 @@ int connection_complete_source (source_t *source) if (global.sources < config->source_limit) { char *contenttype; - mount_proxy *mountproxy = config->mounts; + mount_proxy *mountproxy; format_type_t format_type; /* setup format handler */ @@ -516,15 +516,10 @@ int connection_complete_source (source_t *source) } } - while (mountproxy) - { - if (strcmp (mountproxy->mountname, source->mount) == 0) - { - source_apply_mount (source, mountproxy); - break; - } - mountproxy = mountproxy->next; - } + mountproxy = config_find_mount (config, source->mount); + if (mountproxy) + source_apply_mount (source, mountproxy); + config_release_config(); source->shutdown_rwlock = &_source_shutdown_rwlock; @@ -651,7 +646,7 @@ int connection_check_relay_pass(http_parser_t *parser) 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(); char *pass = config->source_password; @@ -660,22 +655,16 @@ int connection_check_source_pass(http_parser_t *parser, char *mount) int ice_login = config->ice_login; char *protocol; - mount_proxy *mountinfo = config->mounts; - thread_mutex_lock(&(config_locks()->mounts_lock)); + mount_proxy *mountinfo = config_find_mount (config, mount); - while(mountinfo) { - if(!strcmp(mountinfo->mountname, mount)) { - if(mountinfo->password) - pass = mountinfo->password; - if(mountinfo->username) - user = mountinfo->username; - break; - } - mountinfo = mountinfo->next; + if (mountinfo) + { + if (mountinfo->password) + pass = mountinfo->password; + if (mountinfo->username) + user = mountinfo->username; } - thread_mutex_unlock(&(config_locks()->mounts_lock)); - if(!pass) { WARN0("No source password set, rejecting source"); config_release_config(); @@ -1081,7 +1070,11 @@ static void *_handle_connection(void *arg) config = config_get_config(); if (config->listeners[i].shoutcast_compat) { 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(); _handle_shoutcast_compatible(con, shoutcast_mount, source_password); free(source_password); diff --git a/src/connection.h b/src/connection.h index 3b9356c1..086efcf0 100644 --- a/src/connection.h +++ b/src/connection.h @@ -52,7 +52,7 @@ int connection_complete_source (struct source_tag *source); 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_admin_pass(http_parser_t *parser); diff --git a/src/source.c b/src/source.c index 6ce65516..663a24a0 100644 --- a/src/source.c +++ b/src/source.c @@ -147,34 +147,22 @@ source_t *source_find_mount (const char *mount) int depth = 0; 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); if (source != NULL && source->running) break; - /* source is not running, meaning that the fallback is not configured - within the source, we need to check the mount list */ - mountinfo = config->mounts; + /* we either have a source which is not active (relay) or no source + * at all. Check the mounts list for fallback settings + */ + mountinfo = config_find_mount (config, mount); source = NULL; - while (mountinfo) - { - if (strcmp (mountinfo->mountname, mount) == 0) - break; - mountinfo = mountinfo->next; - } - if (mountinfo) - mount = mountinfo->fallback_mount; - else - mount = NULL; + + if (mountinfo == NULL) + break; + mount = mountinfo->fallback_mount; depth++; }