From cfb350f4f01f28cdd6fa973602bd45681a64cf46 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Mar 2009 23:08:17 +0100 Subject: input: pass config_param to input_plugin.init() Allow input plugins to configure with an "input" block in mpd.conf. Also allow the user to disable a plugin completely. --- src/input_stream.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'src/input_stream.c') diff --git a/src/input_stream.c b/src/input_stream.c index 8896415bb..e07a3ab52 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -18,6 +18,7 @@ #include "input_plugin.h" #include "config.h" +#include "conf.h" #include "input/file_input_plugin.h" @@ -35,6 +36,7 @@ #include #include +#include static const struct input_plugin *const input_plugins[] = { &input_plugin_file, @@ -54,11 +56,45 @@ static bool input_plugins_enabled[G_N_ELEMENTS(input_plugins)]; static const unsigned num_input_plugins = sizeof(input_plugins) / sizeof(input_plugins[0]); +/** + * Find the "input" configuration block for the specified plugin. + * + * @param plugin_name the name of the input plugin + * @return the configuration block, or NULL if none was configured + */ +static const struct config_param * +input_plugin_config(const char *plugin_name) +{ + const struct config_param *param = NULL; + + while ((param = config_get_next_param(CONF_INPUT, param)) != NULL) { + const char *name = + config_get_block_string(param, "plugin", NULL); + if (name == NULL) + g_error("input configuration without 'plugin' name in line %d", + param->line); + + if (strcmp(name, plugin_name) == 0) + return param; + } + + return NULL; +} + void input_stream_global_init(void) { - for (unsigned i = 0; i < num_input_plugins; ++i) - if (input_plugins[i]->init == NULL || input_plugins[i]->init()) + for (unsigned i = 0; i < num_input_plugins; ++i) { + const struct input_plugin *plugin = input_plugins[i]; + const struct config_param *param = + input_plugin_config(plugin->name); + + if (!config_get_block_bool(param, "enabled", true)) + /* the plugin is disabled in mpd.conf */ + continue; + + if (plugin->init == NULL || plugin->init(param)) input_plugins_enabled[i] = true; + } } void input_stream_global_finish(void) @@ -82,10 +118,8 @@ input_stream_open(struct input_stream *is, const char *url) for (unsigned i = 0; i < num_input_plugins; ++i) { const struct input_plugin *plugin = input_plugins[i]; - if (plugin->open(is, url)) { + if (input_plugins_enabled[i] && plugin->open(is, url)) { assert(is->plugin != NULL); - assert(is->plugin->open == NULL || - is->plugin == plugin); assert(is->plugin->close != NULL); assert(is->plugin->read != NULL); assert(is->plugin->eof != NULL); -- cgit v1.2.3