From fdc0329e649c961591bf1525438a560ca5a2049c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Feb 2022 16:30:38 +0100 Subject: [PATCH] archive/List: add option to disable archive plugins in mpd.conf Closes https://github.com/MusicPlayerDaemon/MPD/issues/1384 --- NEWS | 2 ++ doc/plugins.rst | 2 ++ doc/user.rst | 29 +++++++++++++++++++++++++++++ src/Main.cxx | 2 +- src/archive/ArchiveList.cxx | 18 ++++++++++++++++-- src/archive/ArchiveList.hxx | 7 ++++--- src/config/Option.hxx | 1 + src/config/Templates.cxx | 1 + test/dump_text_file.cxx | 2 +- test/run_input.cxx | 2 +- test/visit_archive.cxx | 2 +- 11 files changed, 59 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 9b36b4573..aced502eb 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ ver 0.24 (not yet released) * protocol - "playlistfind"/"playlistsearch" have "sort" and "window" parameters - filter "prio" (for "playlistfind"/"playlistsearch") +* archive + - add option to disable archive plugins in mpd.conf * player - add option "mixramp_analyzer" to scan MixRamp tags on-the-fly * tags diff --git a/doc/plugins.rst b/doc/plugins.rst index 6eeaad735..b4d5b6500 100644 --- a/doc/plugins.rst +++ b/doc/plugins.rst @@ -1395,6 +1395,8 @@ xspf Reads XSPF playlist files. +.. _archive_plugins: + Archive plugins =============== diff --git a/doc/user.rst b/doc/user.rst index f35731e42..1dbb148cc 100644 --- a/doc/user.rst +++ b/doc/user.rst @@ -341,6 +341,35 @@ The following table lists the input options valid for all plugins: More information can be found in the :ref:`input_plugins` reference. +Configuring archive plugins +--------------------------- + +To configure an archive plugin, add an :code:`archive_plugin` block to +:file:`mpd.conf`: + +.. code-block:: none + + archive_plugin { + name "zzip" + enabled "no" + } + +The following table lists the input options valid for all plugins: + +.. list-table:: + :widths: 20 80 + :header-rows: 1 + + * - Name + - Description + * - **name** + - The name of the plugin + * - **enabled yes|no** + - Allows you to disable a plugin without recompiling. By + default, all plugins are enabled. + +More information can be found in the :ref:`archive_plugins` reference. + .. _input_cache: Configuring the Input Cache diff --git a/src/Main.cxx b/src/Main.cxx index bf59eb26f..2f951bbb6 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -385,7 +385,7 @@ MainConfigured(const CommandLineOptions &options, initPermissions(raw_config); spl_global_init(raw_config); #ifdef ENABLE_ARCHIVE - const ScopeArchivePluginsInit archive_plugins_init; + const ScopeArchivePluginsInit archive_plugins_init{raw_config}; #endif pcm_convert_global_init(raw_config); diff --git a/src/archive/ArchiveList.cxx b/src/archive/ArchiveList.cxx index 488708158..3a1094450 100644 --- a/src/archive/ArchiveList.cxx +++ b/src/archive/ArchiveList.cxx @@ -20,6 +20,8 @@ #include "ArchiveList.hxx" #include "ArchivePlugin.hxx" #include "archive/Features.h" +#include "config/Data.hxx" +#include "config/Block.hxx" #include "util/StringUtil.hxx" #include "plugins/Bzip2ArchivePlugin.hxx" #include "plugins/Iso9660ArchivePlugin.hxx" @@ -74,10 +76,21 @@ archive_plugin_from_name(const char *name) noexcept return nullptr; } -void archive_plugin_init_all() +void +archive_plugin_init_all(const ConfigData &config) { + ConfigBlock empty; + for (unsigned i = 0; archive_plugins[i] != nullptr; ++i) { const auto &plugin = *archive_plugins[i]; + + const auto *param = + config.FindBlock(ConfigBlockOption::ARCHIVE_PLUGIN, + "name", plugin.name); + if (param != nullptr && !param->GetBlockValue("enabled", true)) + /* the plugin is disabled in mpd.conf */ + continue; + if (plugin.init == nullptr || plugin.init()) archive_plugins_enabled[i] = true; } @@ -86,8 +99,9 @@ void archive_plugin_init_all() void archive_plugin_deinit_all() noexcept { + unsigned i = 0; archive_plugins_for_each_enabled(plugin) - if (plugin->finish != nullptr) + if (archive_plugins_enabled[i++] && plugin->finish != nullptr) plugin->finish(); } diff --git a/src/archive/ArchiveList.hxx b/src/archive/ArchiveList.hxx index 488ea39ce..0a6f161a1 100644 --- a/src/archive/ArchiveList.hxx +++ b/src/archive/ArchiveList.hxx @@ -22,6 +22,7 @@ #include +struct ConfigData; struct ArchivePlugin; extern const ArchivePlugin *const archive_plugins[]; @@ -42,7 +43,7 @@ archive_plugin_from_name(const char *name) noexcept; /* this is where we "load" all the "plugins" ;-) */ void -archive_plugin_init_all(); +archive_plugin_init_all(const ConfigData &config); /* this is where we "unload" all the "plugins" */ void @@ -50,8 +51,8 @@ archive_plugin_deinit_all() noexcept; class ScopeArchivePluginsInit { public: - ScopeArchivePluginsInit() { - archive_plugin_init_all(); + explicit ScopeArchivePluginsInit(const ConfigData &config) { + archive_plugin_init_all(config); } ~ScopeArchivePluginsInit() noexcept { diff --git a/src/config/Option.hxx b/src/config/Option.hxx index 54ec38d05..ba29a90a7 100644 --- a/src/config/Option.hxx +++ b/src/config/Option.hxx @@ -91,6 +91,7 @@ enum class ConfigBlockOption { DECODER, INPUT, INPUT_CACHE, + ARCHIVE_PLUGIN, PLAYLIST_PLUGIN, RESAMPLER, AUDIO_FILTER, diff --git a/src/config/Templates.cxx b/src/config/Templates.cxx index c59932060..aa696988d 100644 --- a/src/config/Templates.cxx +++ b/src/config/Templates.cxx @@ -90,6 +90,7 @@ const ConfigTemplate config_block_templates[] = { { "decoder", true }, { "input", true }, { "input_cache" }, + { "archive_plugin", true }, { "playlist_plugin", true }, { "resampler" }, { "filter", true }, diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index ced972123..863cebaa6 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -41,7 +41,7 @@ class GlobalInit { EventThread io_thread; #ifdef ENABLE_ARCHIVE - const ScopeArchivePluginsInit archive_plugins_init; + const ScopeArchivePluginsInit archive_plugins_init{config}; #endif const ScopeInputPluginsInit input_plugins_init{config, io_thread.GetEventLoop()}; diff --git a/test/run_input.cxx b/test/run_input.cxx index 8ba9fe491..7877650f3 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -137,7 +137,7 @@ class GlobalInit { EventThread io_thread; #ifdef ENABLE_ARCHIVE - const ScopeArchivePluginsInit archive_plugins_init; + const ScopeArchivePluginsInit archive_plugins_init{config}; #endif const ScopeInputPluginsInit input_plugins_init{config, io_thread.GetEventLoop()}; diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx index 5a89c0e85..beaab082d 100644 --- a/test/visit_archive.cxx +++ b/test/visit_archive.cxx @@ -41,7 +41,7 @@ class GlobalInit { EventThread io_thread; #ifdef ENABLE_ARCHIVE - const ScopeArchivePluginsInit archive_plugins_init; + const ScopeArchivePluginsInit archive_plugins_init{config}; #endif const ScopeInputPluginsInit input_plugins_init{config, io_thread.GetEventLoop()};