From 7474fb8d8d4fd5b0b2f707938b9c2056a2d00a9b Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sun, 8 Nov 2020 18:23:03 +0000 Subject: [PATCH] Feature: Write correct history on initial attach of client --- src/connection.c | 5 +---- src/source.c | 17 +++++++++++++---- src/source.h | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/connection.c b/src/connection.c index 3ad7e8e2..ff0cb2ea 100644 --- a/src/connection.c +++ b/src/connection.c @@ -936,9 +936,6 @@ static void __add_listener_to_source(source_t *source, client_t *client) { size_t loop = 10; - if (navigation_history_navigate_to(&(client->history), source->identifier, NAVIGATION_DIRECTION_REPLACE_ALL) != 0) - ICECAST_LOG_ERROR("Can not change history: navigation of client=%p{.con.id=%llu, ...} to source=%p{.mount=%#H, ...} failed", client, (unsigned long long int)client->con->id, source, source->mount); - do { ICECAST_LOG_DEBUG("max on %s is %ld (cur %lu)", source->mount, source->max_listeners, source->listeners); @@ -1053,7 +1050,7 @@ static void _handle_get_request(client_t *client) { avl_tree_rlock(global.source_tree); /* let's see if this is a source or just a random fserve file */ - source = source_find_mount(client->uri); + source = source_find_mount_with_history(client->uri, &(client->history)); if (source) { /* true mount */ do { diff --git a/src/source.c b/src/source.c index a88f7541..fdecdd92 100644 --- a/src/source.c +++ b/src/source.c @@ -154,7 +154,7 @@ source_t *source_find_mount_raw(const char *mount) * check the fallback, and so on. Must have a global source lock to call * this function. */ -source_t *source_find_mount(const char *mount) +source_t *source_find_mount_with_history(const char *mount, navigation_history_t *history) { source_t *source = NULL; ice_config_t *config; @@ -166,10 +166,20 @@ source_t *source_find_mount(const char *mount) { source = source_find_mount_raw(mount); - if (source) - { + if (source) { + if (history) + navigation_history_navigate_to(history, source->identifier, NAVIGATION_DIRECTION_DOWN); + if (source->running || source->on_demand) break; + } else { + if (history) { + mount_identifier_t *identifier = mount_identifier_new(mount); + if (identifier) { + navigation_history_navigate_to(history, identifier, NAVIGATION_DIRECTION_DOWN); + refobject_unref(identifier); + } + } } /* we either have a source which is not active (relay) or no source @@ -188,7 +198,6 @@ source_t *source_find_mount(const char *mount) return source; } - int source_compare_sources(void *arg, void *a, void *b) { source_t *srca = (source_t *)a; diff --git a/src/source.h b/src/source.h index 55b55185..9184454d 100644 --- a/src/source.h +++ b/src/source.h @@ -92,7 +92,8 @@ void *source_client_thread (void *arg); void source_client_callback (client_t *client, void *source); void source_update_settings (ice_config_t *config, source_t *source, mount_proxy *mountinfo); void source_clear_source (source_t *source); -source_t *source_find_mount(const char *mount); +#define source_find_mount(mount) source_find_mount_with_history((mount), NULL) +source_t *source_find_mount_with_history(const char *mount, navigation_history_t *history); source_t *source_find_mount_raw(const char *mount); client_t *source_find_client(source_t *source, connection_id_t id); int source_compare_sources(void *arg, void *a, void *b);