Update to 6762
[qball-mpd.git] / src / inputStream.c
blob013d75f17f76e416b39c08d7cb140c1d2a145ba6
1 /* the Music Player Daemon (MPD)
2 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3 * This project's homepage is: http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "inputStream.h"
21 #include "inputStream_file.h"
22 #include "inputStream_http.h"
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <unistd.h>
28 void initInputStream(void)
30 inputStream_initFile();
31 inputStream_initHttp();
34 int openInputStream(InputStream * inStream, char *url)
36 inStream->offset = 0;
37 inStream->size = 0;
38 inStream->error = 0;
39 inStream->mime = NULL;
40 inStream->seekable = 0;
41 inStream->metaName = NULL;
42 inStream->metaTitle = NULL;
44 if (inputStream_fileOpen(inStream, url) == 0)
45 return 0;
46 if (inputStream_httpOpen(inStream, url) == 0)
47 return 0;
49 return -1;
52 int seekInputStream(InputStream * inStream, long offset, int whence)
54 return inStream->seekFunc(inStream, offset, whence);
57 size_t readFromInputStream(InputStream * inStream, void *ptr, size_t size,
58 size_t nmemb)
60 return inStream->readFunc(inStream, ptr, size, nmemb);
63 int closeInputStream(InputStream * inStream)
65 if (inStream->mime)
66 free(inStream->mime);
67 if (inStream->metaName)
68 free(inStream->metaName);
69 if (inStream->metaTitle)
70 free(inStream->metaTitle);
72 return inStream->closeFunc(inStream);
75 int inputStreamAtEOF(InputStream * inStream)
77 return inStream->atEOFFunc(inStream);
80 int bufferInputStream(InputStream * inStream)
82 return inStream->bufferFunc(inStream);