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: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;
|
|
|
|
|
|
|
|
if (input_file_open(is, url) == 0)
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2008-10-26 19:32:43 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CURL
|
2008-10-26 20:34:47 +01:00
|
|
|
if (input_curl_open(is, url))
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2008-10-26 19:32:43 +01:00
|
|
|
#endif
|
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:34:47 +01:00
|
|
|
return is->seekFunc(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:34:47 +01:00
|
|
|
return is->readFunc(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);
|
|
|
|
|
|
|
|
return is->closeFunc(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:34:47 +01:00
|
|
|
return is->atEOFFunc(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:34:47 +01:00
|
|
|
return is->bufferFunc(is);
|
2004-05-18 11:54:45 +02:00
|
|
|
}
|