From 871d296ab1e7d679937d203af587ef8cd1602186 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 30 Mar 2022 23:51:30 +0000 Subject: [PATCH] Feature: Added SOURCE_FLAG_FORMAT_GENERIC, and SOURCE_FLAG_LEGACY_METADATA --- src/admin.c | 2 ++ src/connection.c | 3 +++ src/source.c | 28 +++++++++++++++++----------- src/source.h | 5 ++++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/admin.c b/src/admin.c index 2ee9758a..24aa1ae4 100644 --- a/src/admin.c +++ b/src/admin.c @@ -1226,6 +1226,7 @@ static void command_metadata(client_t *client, if (source->parser && source->parser->req_type == httpp_req_put) { ICECAST_LOG_ERROR("Got legacy SOURCE-style metadata update command on " "source connected with PUT at mountpoint %H", source->mount); + source_set_flags(source, SOURCE_FLAG_LEGACY_METADATA); } COMMAND_REQUIRE(client, "mode", action); @@ -1270,6 +1271,7 @@ static void command_metadata(client_t *client, } else { ICECAST_LOG_ERROR("Got legacy shoutcast-style metadata update command " "on source that does not accept it at mountpoint %H", source->mount); + source_set_flags(source, SOURCE_FLAG_LEGACY_METADATA); admin_send_response_simple(client, source, response, "Mountpoint will not accept URL updates", 1); return; diff --git a/src/connection.c b/src/connection.c index 2d9b6dfe..71e56f2b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -952,6 +952,9 @@ int connection_complete_source(source_t *source, int response) format_type = FORMAT_TYPE_GENERIC; } + if (format_type == FORMAT_TYPE_GENERIC) + source_set_flags(source, SOURCE_FLAG_FORMAT_GENERIC); + if (format_get_plugin (format_type, source) < 0) { global_unlock(); config_release_config(); diff --git a/src/source.c b/src/source.c index c3b865f5..02d109b0 100644 --- a/src/source.c +++ b/src/source.c @@ -74,17 +74,6 @@ static int _free_client(void *key); static void _parse_audio_info (source_t *source, const char *s); static void source_shutdown (source_t *source); -static void source_set_flags(source_t *source, source_flags_t flags) -{ - /* check if we need to do anything at all */ - if ((source->flags & flags) == flags) - return; - - thread_mutex_lock(&source->lock); - source->flags |= flags; - thread_mutex_unlock(&source->lock); -} - /* Allocate a new source with the stated mountpoint, if one already * exists with that mountpoint in the global source tree then return * NULL. @@ -1541,5 +1530,22 @@ health_t source_get_health(source_t *source) if (!(flags & SOURCE_FLAG_GOT_DATA)) health = health_atbest(health, HEALTH_ERROR); + if (flags & SOURCE_FLAG_FORMAT_GENERIC) + health = health_atbest(health, HEALTH_WARNING); + + if (flags & SOURCE_FLAG_LEGACY_METADATA) + health = health_atbest(health, HEALTH_ERROR); + return health; } + +void source_set_flags(source_t *source, source_flags_t flags) +{ + /* check if we need to do anything at all */ + if ((source->flags & flags) == flags) + return; + + thread_mutex_lock(&source->lock); + source->flags |= flags; + thread_mutex_unlock(&source->lock); +} diff --git a/src/source.h b/src/source.h index 64dc9b0d..3a08e924 100644 --- a/src/source.h +++ b/src/source.h @@ -31,8 +31,10 @@ typedef uint_least32_t source_flags_t; #define SOURCE_FLAG_GOT_DATA ((source_flags_t)0x00000001U) +#define SOURCE_FLAG_FORMAT_GENERIC ((source_flags_t)0x00000002U) +#define SOURCE_FLAG_LEGACY_METADATA ((source_flags_t)0x00000004U) -#define SOURCE_FLAGS_CLEARABLE ((source_flags_t)0) +#define SOURCE_FLAGS_CLEARABLE (SOURCE_FLAG_LEGACY_METADATA) struct source_tag { mutex_t lock; @@ -123,6 +125,7 @@ void source_recheck_mounts (int update_all); bool source_write_dumpfile(source_t *source, const void *buffer, size_t len); void source_kill_dumpfile(source_t *source); health_t source_get_health(source_t *source); +void source_set_flags(source_t *source, source_flags_t flags); extern mutex_t move_clients_mutex;