inputStream.c 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* the Music Player Daemon (MPD)
 * (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
 * 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
 */

#include "inputStream.h"

21 22 23
#include "inputStream_file.h"
#include "inputStream_http.h"

24 25 26 27
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

28 29 30 31 32
void initInputStream() {
	inputStream_initFile();
	inputStream_initHttp();
}

33
int openInputStream(InputStream * inStream, char * url) {
Warren Dukes's avatar
Warren Dukes committed
34 35 36 37 38 39 40 41
        inStream->offset = 0;
        inStream->size = 0;
        inStream->error = 0;
        inStream->mime = NULL;
        inStream->seekable = 0;
        inStream->metaName = NULL;
        inStream->metaTitle = NULL;

42 43
        if(inputStream_fileOpen(inStream,url) == 0) return 0;
        if(inputStream_httpOpen(inStream,url) == 0) return 0;
44

45
        return -1;
46 47
}

48
int seekInputStream(InputStream * inStream, long offset, int whence) {
49
        return inStream->seekFunc(inStream,offset,whence);
50 51
}

52 53
size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size, 
		size_t nmemb)
54
{
55
        return inStream->readFunc(inStream,ptr,size,nmemb);
56 57
}

58
int closeInputStream(InputStream * inStream) {
Warren Dukes's avatar
Warren Dukes committed
59 60 61 62
        if(inStream->mime) free(inStream->mime);
        if(inStream->metaName) free(inStream->metaName);
        if(inStream->metaTitle) free(inStream->metaTitle);

63
        return inStream->closeFunc(inStream);
64
}
65 66

int inputStreamAtEOF(InputStream * inStream) {
67
        return inStream->atEOFFunc(inStream);
68
}
69 70 71 72

int bufferInputStream(InputStream * inStream) {
        return inStream->bufferFunc(inStream);
}