2004-05-04 21:08:46 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-05-04 21:08:46 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2008-10-26 19:38:50 +01:00
|
|
|
#include "input_stream.h"
|
2008-10-26 19:32:43 +01:00
|
|
|
#include "config.h"
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2008-10-26 19:38:50 +01:00
|
|
|
#include "input_file.h"
|
2008-10-26 19:32:43 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CURL
|
|
|
|
#include "input_curl.h"
|
|
|
|
#endif
|
2004-05-18 04:46:13 +02:00
|
|
|
|
2008-10-08 10:49:29 +02:00
|
|
|
#include <stdlib.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,
|
|
|
|
#ifdef HAVE_CURL
|
|
|
|
&input_plugin_curl,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned num_input_plugins =
|
|
|
|
sizeof(input_plugins) / sizeof(input_plugins[0]);
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
void input_stream_global_init(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 19:32:43 +01:00
|
|
|
#ifdef HAVE_CURL
|
|
|
|
input_curl_global_init();
|
|
|
|
#endif
|
2004-06-20 19:07:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 19:30:13 +01:00
|
|
|
void input_stream_global_finish(void)
|
|
|
|
{
|
2008-10-26 19:32:43 +01:00
|
|
|
#ifdef HAVE_CURL
|
|
|
|
input_curl_global_finish();
|
|
|
|
#endif
|
2008-10-26 19:30:13 +01:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
int input_stream_open(struct input_stream *is, char *url)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:34:47 +01:00
|
|
|
is->ready = 0;
|
|
|
|
is->offset = 0;
|
|
|
|
is->size = 0;
|
|
|
|
is->error = 0;
|
|
|
|
is->mime = NULL;
|
|
|
|
is->seekable = 0;
|
|
|
|
is->meta_name = NULL;
|
|
|
|
is->meta_title = 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
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
if (plugin->open(is, url)) {
|
|
|
|
is->plugin = plugin;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return -1;
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
int input_stream_seek(struct input_stream *is, long offset, int whence)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->seek(is, offset, whence);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
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-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:34:47 +01:00
|
|
|
int input_stream_close(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:34:47 +01:00
|
|
|
if (is->mime)
|
|
|
|
free(is->mime);
|
|
|
|
if (is->meta_name)
|
|
|
|
free(is->meta_name);
|
|
|
|
if (is->meta_title)
|
|
|
|
free(is->meta_title);
|
|
|
|
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->close(is);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
2004-05-05 01:39:02 +02:00
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
int 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
|
|
|
{
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->buffer(is);
|
2004-05-18 11:54:45 +02:00
|
|
|
}
|