From bbaedb17d52cf14cf1abc3f24a90dfa06f875440 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 26 Oct 2008 19:38:50 +0100 Subject: input_stream: renamed sources, no CamelCase Renamed inputStream.c and inputStream_file.c. --- src/Makefile.am | 8 ++-- src/decoder_api.h | 2 +- src/inputStream.c | 98 ----------------------------------------- src/inputStream.h | 68 ----------------------------- src/inputStream_file.c | 115 ------------------------------------------------- src/inputStream_file.h | 40 ----------------- src/input_curl.c | 2 +- src/input_file.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ src/input_file.h | 40 +++++++++++++++++ src/input_stream.c | 98 +++++++++++++++++++++++++++++++++++++++++ src/input_stream.h | 68 +++++++++++++++++++++++++++++ src/main.c | 2 +- 12 files changed, 328 insertions(+), 328 deletions(-) delete mode 100644 src/inputStream.c delete mode 100644 src/inputStream.h delete mode 100644 src/inputStream_file.c delete mode 100644 src/inputStream_file.h create mode 100644 src/input_file.c create mode 100644 src/input_file.h create mode 100644 src/input_stream.c create mode 100644 src/input_stream.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 12e690cf7..15d15e175 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,8 +47,8 @@ mpd_headers = \ decoder_list.h \ decoder/_flac_common.h \ decoder/_ogg_common.h \ - inputStream.h \ - inputStream_file.h \ + input_stream.h \ + input_file.h \ client.h \ list.h \ dlist.h \ @@ -128,8 +128,8 @@ mpd_SOURCES = \ dirvec.c \ update.c \ decoder_list.c \ - inputStream.c \ - inputStream_file.c \ + input_stream.c \ + input_file.c \ client.c \ ioops.c \ list.c \ diff --git a/src/decoder_api.h b/src/decoder_api.h index 7d8a1e567..8096d3cd8 100644 --- a/src/decoder_api.h +++ b/src/decoder_api.h @@ -26,7 +26,7 @@ * */ -#include "inputStream.h" +#include "input_stream.h" #include "replayGain.h" #include "tag.h" #include "tag_id3.h" diff --git a/src/inputStream.c b/src/inputStream.c deleted file mode 100644 index b293cb1cd..000000000 --- a/src/inputStream.c +++ /dev/null @@ -1,98 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) - * 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" -#include "config.h" - -#include "inputStream_file.h" - -#ifdef HAVE_CURL -#include "input_curl.h" -#endif - -#include - -void initInputStream(void) -{ - inputStream_initFile(); -#ifdef HAVE_CURL - input_curl_global_init(); -#endif -} - -void input_stream_global_finish(void) -{ -#ifdef HAVE_CURL - input_curl_global_finish(); -#endif -} - -int openInputStream(struct input_stream *inStream, char *url) -{ - inStream->ready = 0; - inStream->offset = 0; - inStream->size = 0; - inStream->error = 0; - inStream->mime = NULL; - inStream->seekable = 0; - inStream->metaName = NULL; - inStream->metaTitle = NULL; - - if (inputStream_fileOpen(inStream, url) == 0) - return 0; - -#ifdef HAVE_CURL - if (input_curl_open(inStream, url)) - return 0; -#endif - - return -1; -} - -int seekInputStream(struct input_stream *inStream, long offset, int whence) -{ - return inStream->seekFunc(inStream, offset, whence); -} - -size_t readFromInputStream(struct input_stream *inStream, - void *ptr, size_t size) -{ - return inStream->readFunc(inStream, ptr, size); -} - -int closeInputStream(struct input_stream *inStream) -{ - if (inStream->mime) - free(inStream->mime); - if (inStream->metaName) - free(inStream->metaName); - if (inStream->metaTitle) - free(inStream->metaTitle); - - return inStream->closeFunc(inStream); -} - -int inputStreamAtEOF(struct input_stream *inStream) -{ - return inStream->atEOFFunc(inStream); -} - -int bufferInputStream(struct input_stream *inStream) -{ - return inStream->bufferFunc(inStream); -} diff --git a/src/inputStream.h b/src/inputStream.h deleted file mode 100644 index db4d6ff57..000000000 --- a/src/inputStream.h +++ /dev/null @@ -1,68 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) - * 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 - */ - -#ifndef INPUT_STREAM_H -#define INPUT_STREAM_H - -#include - -typedef struct input_stream InputStream; - -struct input_stream { - int ready; - - int error; - long offset; - size_t size; - char *mime; - int seekable; - - int (*seekFunc)(struct input_stream *inStream, long offset, - int whence); - size_t (*readFunc)(struct input_stream *inStream, void *ptr, - size_t size); - int (*closeFunc)(struct input_stream *inStream); - int (*atEOFFunc)(struct input_stream *inStream); - int (*bufferFunc)(struct input_stream *inStream); - - void *data; - char *metaName; - char *metaTitle; -}; - -void initInputStream(void); - -void input_stream_global_finish(void); - -int isUrlSaneForInputStream(char *url); - -/* if an error occurs for these 3 functions, then -1 is returned and errno - for the input stream is set */ -int openInputStream(struct input_stream *inStream, char *url); -int seekInputStream(struct input_stream *inStream, long offset, int whence); -int closeInputStream(struct input_stream *inStream); -int inputStreamAtEOF(struct input_stream *inStream); - -/* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing - was buffered */ -int bufferInputStream(struct input_stream *inStream); - -size_t readFromInputStream(struct input_stream *inStream, - void *ptr, size_t size); - -#endif diff --git a/src/inputStream_file.c b/src/inputStream_file.c deleted file mode 100644 index 9b5a1a62d..000000000 --- a/src/inputStream_file.c +++ /dev/null @@ -1,115 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) - * 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_file.h" - -#include "log.h" -#include "os_compat.h" - -void inputStream_initFile(void) -{ -} - -int inputStream_fileOpen(struct input_stream *inStream, char *filename) -{ - FILE *fp; - - fp = fopen(filename, "r"); - if (!fp) { - inStream->error = errno; - return -1; - } - - inStream->seekable = 1; - - fseek(fp, 0, SEEK_END); - inStream->size = ftell(fp); - fseek(fp, 0, SEEK_SET); - -#ifdef POSIX_FADV_SEQUENTIAL - posix_fadvise(fileno(fp), (off_t)0, inStream->size, POSIX_FADV_SEQUENTIAL); -#endif - - inStream->data = fp; - inStream->seekFunc = inputStream_fileSeek; - inStream->closeFunc = inputStream_fileClose; - inStream->readFunc = inputStream_fileRead; - inStream->atEOFFunc = inputStream_fileAtEOF; - inStream->bufferFunc = inputStream_fileBuffer; - - inStream->ready = 1; - - return 0; -} - -int inputStream_fileSeek(struct input_stream *inStream, long offset, - int whence) -{ - if (fseek((FILE *) inStream->data, offset, whence) == 0) { - inStream->offset = ftell((FILE *) inStream->data); - } else { - inStream->error = errno; - return -1; - } - - return 0; -} - -size_t inputStream_fileRead(struct input_stream *inStream, - void *ptr, size_t size) -{ - size_t readSize; - - readSize = fread(ptr, 1, size, (FILE *) inStream->data); - if (readSize <= 0 && ferror((FILE *) inStream->data)) { - inStream->error = errno; - DEBUG("inputStream_fileRead: error reading: %s\n", - strerror(inStream->error)); - } - - inStream->offset = ftell((FILE *) inStream->data); - - return readSize; -} - -int inputStream_fileClose(struct input_stream *inStream) -{ - if (fclose((FILE *) inStream->data) < 0) { - inStream->error = errno; - return -1; - } - - return 0; -} - -int inputStream_fileAtEOF(struct input_stream *inStream) -{ - if (feof((FILE *) inStream->data)) - return 1; - - if (ferror((FILE *) inStream->data) && inStream->error != EINTR) { - return 1; - } - - return 0; -} - -int inputStream_fileBuffer(mpd_unused struct input_stream *inStream) -{ - return 0; -} diff --git a/src/inputStream_file.h b/src/inputStream_file.h deleted file mode 100644 index 9199d9c01..000000000 --- a/src/inputStream_file.h +++ /dev/null @@ -1,40 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) - * 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 - */ - -#ifndef INPUT_STREAM_FILE_H -#define INPUT_STREAM_FILE_H - -#include "inputStream.h" - -void inputStream_initFile(void); - -int inputStream_fileOpen(struct input_stream *inStream, char *filename); - -int inputStream_fileSeek(struct input_stream *inStream, long offset, - int whence); - -size_t inputStream_fileRead(struct input_stream *inStream, - void *ptr, size_t size); - -int inputStream_fileClose(struct input_stream *inStream); - -int inputStream_fileAtEOF(struct input_stream *inStream); - -int inputStream_fileBuffer(struct input_stream *inStream); - -#endif diff --git a/src/input_curl.c b/src/input_curl.c index 3c32d7118..fc78adca0 100644 --- a/src/input_curl.c +++ b/src/input_curl.c @@ -17,7 +17,7 @@ */ #include "input_curl.h" -#include "inputStream.h" +#include "input_stream.h" #include "gcc.h" #include "dlist.h" diff --git a/src/input_file.c b/src/input_file.c new file mode 100644 index 000000000..de7d0b5a3 --- /dev/null +++ b/src/input_file.c @@ -0,0 +1,115 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * 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 "input_file.h" + +#include "log.h" +#include "os_compat.h" + +void inputStream_initFile(void) +{ +} + +int inputStream_fileOpen(struct input_stream *inStream, char *filename) +{ + FILE *fp; + + fp = fopen(filename, "r"); + if (!fp) { + inStream->error = errno; + return -1; + } + + inStream->seekable = 1; + + fseek(fp, 0, SEEK_END); + inStream->size = ftell(fp); + fseek(fp, 0, SEEK_SET); + +#ifdef POSIX_FADV_SEQUENTIAL + posix_fadvise(fileno(fp), (off_t)0, inStream->size, POSIX_FADV_SEQUENTIAL); +#endif + + inStream->data = fp; + inStream->seekFunc = inputStream_fileSeek; + inStream->closeFunc = inputStream_fileClose; + inStream->readFunc = inputStream_fileRead; + inStream->atEOFFunc = inputStream_fileAtEOF; + inStream->bufferFunc = inputStream_fileBuffer; + + inStream->ready = 1; + + return 0; +} + +int inputStream_fileSeek(struct input_stream *inStream, long offset, + int whence) +{ + if (fseek((FILE *) inStream->data, offset, whence) == 0) { + inStream->offset = ftell((FILE *) inStream->data); + } else { + inStream->error = errno; + return -1; + } + + return 0; +} + +size_t inputStream_fileRead(struct input_stream *inStream, + void *ptr, size_t size) +{ + size_t readSize; + + readSize = fread(ptr, 1, size, (FILE *) inStream->data); + if (readSize <= 0 && ferror((FILE *) inStream->data)) { + inStream->error = errno; + DEBUG("inputStream_fileRead: error reading: %s\n", + strerror(inStream->error)); + } + + inStream->offset = ftell((FILE *) inStream->data); + + return readSize; +} + +int inputStream_fileClose(struct input_stream *inStream) +{ + if (fclose((FILE *) inStream->data) < 0) { + inStream->error = errno; + return -1; + } + + return 0; +} + +int inputStream_fileAtEOF(struct input_stream *inStream) +{ + if (feof((FILE *) inStream->data)) + return 1; + + if (ferror((FILE *) inStream->data) && inStream->error != EINTR) { + return 1; + } + + return 0; +} + +int inputStream_fileBuffer(mpd_unused struct input_stream *inStream) +{ + return 0; +} diff --git a/src/input_file.h b/src/input_file.h new file mode 100644 index 000000000..00d85a36c --- /dev/null +++ b/src/input_file.h @@ -0,0 +1,40 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * 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 + */ + +#ifndef INPUT_STREAM_FILE_H +#define INPUT_STREAM_FILE_H + +#include "input_stream.h" + +void inputStream_initFile(void); + +int inputStream_fileOpen(struct input_stream *inStream, char *filename); + +int inputStream_fileSeek(struct input_stream *inStream, long offset, + int whence); + +size_t inputStream_fileRead(struct input_stream *inStream, + void *ptr, size_t size); + +int inputStream_fileClose(struct input_stream *inStream); + +int inputStream_fileAtEOF(struct input_stream *inStream); + +int inputStream_fileBuffer(struct input_stream *inStream); + +#endif diff --git a/src/input_stream.c b/src/input_stream.c new file mode 100644 index 000000000..607cfc358 --- /dev/null +++ b/src/input_stream.c @@ -0,0 +1,98 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * 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 "input_stream.h" +#include "config.h" + +#include "input_file.h" + +#ifdef HAVE_CURL +#include "input_curl.h" +#endif + +#include + +void initInputStream(void) +{ + inputStream_initFile(); +#ifdef HAVE_CURL + input_curl_global_init(); +#endif +} + +void input_stream_global_finish(void) +{ +#ifdef HAVE_CURL + input_curl_global_finish(); +#endif +} + +int openInputStream(struct input_stream *inStream, char *url) +{ + inStream->ready = 0; + inStream->offset = 0; + inStream->size = 0; + inStream->error = 0; + inStream->mime = NULL; + inStream->seekable = 0; + inStream->metaName = NULL; + inStream->metaTitle = NULL; + + if (inputStream_fileOpen(inStream, url) == 0) + return 0; + +#ifdef HAVE_CURL + if (input_curl_open(inStream, url)) + return 0; +#endif + + return -1; +} + +int seekInputStream(struct input_stream *inStream, long offset, int whence) +{ + return inStream->seekFunc(inStream, offset, whence); +} + +size_t readFromInputStream(struct input_stream *inStream, + void *ptr, size_t size) +{ + return inStream->readFunc(inStream, ptr, size); +} + +int closeInputStream(struct input_stream *inStream) +{ + if (inStream->mime) + free(inStream->mime); + if (inStream->metaName) + free(inStream->metaName); + if (inStream->metaTitle) + free(inStream->metaTitle); + + return inStream->closeFunc(inStream); +} + +int inputStreamAtEOF(struct input_stream *inStream) +{ + return inStream->atEOFFunc(inStream); +} + +int bufferInputStream(struct input_stream *inStream) +{ + return inStream->bufferFunc(inStream); +} diff --git a/src/input_stream.h b/src/input_stream.h new file mode 100644 index 000000000..db4d6ff57 --- /dev/null +++ b/src/input_stream.h @@ -0,0 +1,68 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * 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 + */ + +#ifndef INPUT_STREAM_H +#define INPUT_STREAM_H + +#include + +typedef struct input_stream InputStream; + +struct input_stream { + int ready; + + int error; + long offset; + size_t size; + char *mime; + int seekable; + + int (*seekFunc)(struct input_stream *inStream, long offset, + int whence); + size_t (*readFunc)(struct input_stream *inStream, void *ptr, + size_t size); + int (*closeFunc)(struct input_stream *inStream); + int (*atEOFFunc)(struct input_stream *inStream); + int (*bufferFunc)(struct input_stream *inStream); + + void *data; + char *metaName; + char *metaTitle; +}; + +void initInputStream(void); + +void input_stream_global_finish(void); + +int isUrlSaneForInputStream(char *url); + +/* if an error occurs for these 3 functions, then -1 is returned and errno + for the input stream is set */ +int openInputStream(struct input_stream *inStream, char *url); +int seekInputStream(struct input_stream *inStream, long offset, int whence); +int closeInputStream(struct input_stream *inStream); +int inputStreamAtEOF(struct input_stream *inStream); + +/* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing + was buffered */ +int bufferInputStream(struct input_stream *inStream); + +size_t readFromInputStream(struct input_stream *inStream, + void *ptr, size_t size); + +#endif diff --git a/src/main.c b/src/main.c index 80f4fecf6..d870aaa7f 100644 --- a/src/main.c +++ b/src/main.c @@ -41,7 +41,7 @@ #include "replayGain.h" #include "decoder_list.h" #include "audioOutput.h" -#include "inputStream.h" +#include "input_stream.h" #include "state_file.h" #include "tag.h" #include "dbUtils.h" -- cgit v1.2.3