2009-03-13 18:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* http://www.musicpd.org
|
2004-05-04 21:08:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-05-04 21:08:46 +02:00
|
|
|
*/
|
|
|
|
|
2009-03-02 20:13:08 +01:00
|
|
|
#include "input_plugin.h"
|
2008-10-26 19:32:43 +01:00
|
|
|
#include "config.h"
|
2009-03-02 23:08:17 +01:00
|
|
|
#include "conf.h"
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2009-03-02 20:40:31 +01:00
|
|
|
#include "input/file_input_plugin.h"
|
2008-12-27 14:33:41 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_ARCHIVE
|
2009-03-02 20:40:31 +01:00
|
|
|
#include "input/archive_input_plugin.h"
|
2008-12-27 14:33:41 +01:00
|
|
|
#endif
|
2008-10-26 19:32:43 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CURL
|
2009-03-02 20:40:31 +01:00
|
|
|
#include "input/curl_input_plugin.h"
|
2008-10-26 19:32:43 +01:00
|
|
|
#endif
|
2004-05-18 04:46:13 +02:00
|
|
|
|
2009-03-02 23:11:31 +01:00
|
|
|
#include "input/lastfm_input_plugin.h"
|
|
|
|
|
2009-01-29 21:42:10 +01:00
|
|
|
#ifdef ENABLE_MMS
|
2009-03-02 20:40:31 +01:00
|
|
|
#include "input/mms_input_plugin.h"
|
2009-01-29 21:42:10 +01:00
|
|
|
#endif
|
|
|
|
|
2008-10-26 21:02:49 +01:00
|
|
|
#include <glib.h>
|
2008-11-15 19:27:30 +01:00
|
|
|
#include <assert.h>
|
2009-03-02 23:08:17 +01:00
|
|
|
#include <string.h>
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
static const struct input_plugin *const input_plugins[] = {
|
|
|
|
&input_plugin_file,
|
2008-12-27 14:33:41 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
2008-12-16 21:42:34 +01:00
|
|
|
&input_plugin_archive,
|
2008-12-27 14:33:41 +01:00
|
|
|
#endif
|
2008-10-26 20:38:44 +01:00
|
|
|
#ifdef HAVE_CURL
|
|
|
|
&input_plugin_curl,
|
|
|
|
#endif
|
2009-03-02 23:11:31 +01:00
|
|
|
#ifdef ENABLE_LASTFM
|
|
|
|
&lastfm_input_plugin,
|
|
|
|
#endif
|
2009-01-29 21:42:10 +01:00
|
|
|
#ifdef ENABLE_MMS
|
|
|
|
&input_plugin_mms,
|
|
|
|
#endif
|
2008-10-26 20:38:44 +01:00
|
|
|
};
|
|
|
|
|
2009-03-02 20:45:50 +01:00
|
|
|
static bool input_plugins_enabled[G_N_ELEMENTS(input_plugins)];
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
static const unsigned num_input_plugins =
|
|
|
|
sizeof(input_plugins) / sizeof(input_plugins[0]);
|
|
|
|
|
2009-03-02 23:08:17 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
void input_stream_global_init(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-03-02 23:08:17 +01:00
|
|
|
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))
|
2009-03-02 20:45:50 +01:00
|
|
|
input_plugins_enabled[i] = true;
|
2009-03-02 23:08:17 +01:00
|
|
|
}
|
2004-06-20 19:07:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 19:30:13 +01:00
|
|
|
void input_stream_global_finish(void)
|
|
|
|
{
|
2009-03-02 20:45:50 +01:00
|
|
|
for (unsigned i = 0; i < num_input_plugins; ++i)
|
|
|
|
if (input_plugins_enabled[i] &&
|
|
|
|
input_plugins[i]->finish != NULL)
|
|
|
|
input_plugins[i]->finish();
|
2008-10-26 19:30:13 +01:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
bool
|
2008-10-31 15:50:59 +01:00
|
|
|
input_stream_open(struct input_stream *is, const char *url)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:56:46 +01:00
|
|
|
is->seekable = false;
|
|
|
|
is->ready = false;
|
2008-10-26 20:34:47 +01:00
|
|
|
is->offset = 0;
|
2008-11-16 20:42:08 +01:00
|
|
|
is->size = -1;
|
2008-10-26 20:34:47 +01:00
|
|
|
is->error = 0;
|
|
|
|
is->mime = NULL;
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
for (unsigned i = 0; i < num_input_plugins; ++i) {
|
|
|
|
const struct input_plugin *plugin = input_plugins[i];
|
2008-10-26 19:32:43 +01:00
|
|
|
|
2009-03-02 23:08:17 +01:00
|
|
|
if (input_plugins_enabled[i] && plugin->open(is, url)) {
|
2009-01-30 00:40:14 +01:00
|
|
|
assert(is->plugin != NULL);
|
|
|
|
assert(is->plugin->close != NULL);
|
|
|
|
assert(is->plugin->read != NULL);
|
|
|
|
assert(is->plugin->eof != NULL);
|
2009-01-30 00:58:03 +01:00
|
|
|
assert(!is->seekable || is->plugin->seek != NULL);
|
2009-01-30 00:40:14 +01:00
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
return true;
|
2008-10-26 20:38:44 +01:00
|
|
|
}
|
|
|
|
}
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
return false;
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
bool
|
2008-10-28 20:39:09 +01:00
|
|
|
input_stream_seek(struct input_stream *is, off_t offset, int whence)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-30 00:58:03 +01:00
|
|
|
if (is->plugin->seek == NULL)
|
|
|
|
return false;
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->seek(is, offset, whence);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
struct tag *
|
|
|
|
input_stream_tag(struct input_stream *is)
|
|
|
|
{
|
|
|
|
assert(is != NULL);
|
|
|
|
|
|
|
|
return is->plugin->tag != NULL
|
|
|
|
? is->plugin->tag(is)
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
size_t
|
|
|
|
input_stream_read(struct input_stream *is, void *ptr, size_t size)
|
2004-05-04 21:08:46 +02:00
|
|
|
{
|
2008-11-15 19:27:30 +01:00
|
|
|
assert(ptr != NULL);
|
|
|
|
assert(size > 0);
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->read(is, ptr, size);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:54:52 +01:00
|
|
|
void input_stream_close(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:54:52 +01:00
|
|
|
is->plugin->close(is);
|
2008-10-26 21:02:49 +01:00
|
|
|
|
|
|
|
g_free(is->mime);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
2004-05-05 01:39:02 +02:00
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
bool input_stream_eof(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->eof(is);
|
2004-05-05 01:39:02 +02:00
|
|
|
}
|
2004-05-18 11:54:45 +02:00
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
int input_stream_buffer(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-30 00:58:03 +01:00
|
|
|
if (is->plugin->buffer == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->buffer(is);
|
2004-05-18 11:54:45 +02:00
|
|
|
}
|