aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-12-30 23:27:37 +0100
committerMax Kellermann <max@duempel.org>2010-01-01 17:25:07 +0100
commitd3b763a48c09a60a0c0b5ccb6cccd9376875c470 (patch)
tree83b8794f78ef8941806cf5757888d8abf2eaa126 /src/playlist
parent816b6ad4a71c3ade95e62b62396f2b0415c03f20 (diff)
downloadmpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.gz
mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.xz
mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.zip
input_stream: return allocated input_stream objects
Major API redesign: don't let the caller allocate the input_stream object. Let each input plugin allocate its own (derived/extended) input_stream pointer. The "data" attribute can now be removed, and all input plugins simply cast the input_stream pointer to their own structure (with an "struct input_stream base" as the first attribute).
Diffstat (limited to '')
-rw-r--r--src/playlist/lastfm_playlist_plugin.c44
-rw-r--r--src/playlist_list.c6
-rw-r--r--src/playlist_list.h4
-rw-r--r--src/playlist_queue.c21
4 files changed, 35 insertions, 40 deletions
diff --git a/src/playlist/lastfm_playlist_plugin.c b/src/playlist/lastfm_playlist_plugin.c
index 25e1adb1d..afb3979d9 100644
--- a/src/playlist/lastfm_playlist_plugin.c
+++ b/src/playlist/lastfm_playlist_plugin.c
@@ -35,7 +35,7 @@
struct lastfm_playlist {
struct playlist_provider base;
- struct input_stream is;
+ struct input_stream *is;
struct playlist_provider *xspf;
};
@@ -85,15 +85,14 @@ lastfm_finish(void)
static char *
lastfm_get(const char *url)
{
- struct input_stream input_stream;
+ struct input_stream *input_stream;
GError *error = NULL;
- bool success;
int ret;
char buffer[4096];
size_t length = 0, nbytes;
- success = input_stream_open(&input_stream, url, &error);
- if (!success) {
+ input_stream = input_stream_open(url, &error);
+ if (input_stream == NULL) {
if (error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
@@ -102,10 +101,10 @@ lastfm_get(const char *url)
return NULL;
}
- while (!input_stream.ready) {
- ret = input_stream_buffer(&input_stream, &error);
+ while (!input_stream->ready) {
+ ret = input_stream_buffer(input_stream, &error);
if (ret < 0) {
- input_stream_close(&input_stream);
+ input_stream_close(input_stream);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
@@ -113,7 +112,7 @@ lastfm_get(const char *url)
}
do {
- nbytes = input_stream_read(&input_stream, buffer + length,
+ nbytes = input_stream_read(input_stream, buffer + length,
sizeof(buffer) - length, &error);
if (nbytes == 0) {
if (error != NULL) {
@@ -121,18 +120,18 @@ lastfm_get(const char *url)
g_error_free(error);
}
- if (input_stream_eof(&input_stream))
+ if (input_stream_eof(input_stream))
break;
/* I/O error */
- input_stream_close(&input_stream);
+ input_stream_close(input_stream);
return NULL;
}
length += nbytes;
} while (length < sizeof(buffer));
- input_stream_close(&input_stream);
+ input_stream_close(input_stream);
return g_strndup(buffer, length);
}
@@ -168,7 +167,6 @@ lastfm_open_uri(const char *uri)
struct lastfm_playlist *playlist;
GError *error = NULL;
char *p, *q, *response, *session;
- bool success;
/* handshake */
@@ -231,10 +229,10 @@ lastfm_open_uri(const char *uri)
NULL);
g_free(session);
- success = input_stream_open(&playlist->is, p, &error);
+ playlist->is = input_stream_open(p, &error);
g_free(p);
- if (!success) {
+ if (playlist->is == NULL) {
if (error != NULL) {
g_warning("Failed to load XSPF playlist: %s",
error->message);
@@ -245,10 +243,10 @@ lastfm_open_uri(const char *uri)
return NULL;
}
- while (!playlist->is.ready) {
- int ret = input_stream_buffer(&playlist->is, &error);
+ while (!playlist->is->ready) {
+ int ret = input_stream_buffer(playlist->is, &error);
if (ret < 0) {
- input_stream_close(&playlist->is);
+ input_stream_close(playlist->is);
g_free(playlist);
g_warning("%s", error->message);
g_error_free(error);
@@ -262,14 +260,14 @@ lastfm_open_uri(const char *uri)
/* last.fm does not send a MIME type, we have to fake it here
:-( */
- g_free(playlist->is.mime);
- playlist->is.mime = g_strdup("application/xspf+xml");
+ g_free(playlist->is->mime);
+ playlist->is->mime = g_strdup("application/xspf+xml");
/* parse the XSPF playlist */
- playlist->xspf = playlist_list_open_stream(&playlist->is, NULL);
+ playlist->xspf = playlist_list_open_stream(playlist->is, NULL);
if (playlist->xspf == NULL) {
- input_stream_close(&playlist->is);
+ input_stream_close(playlist->is);
g_free(playlist);
g_warning("Failed to parse XSPF playlist");
return NULL;
@@ -284,7 +282,7 @@ lastfm_close(struct playlist_provider *_playlist)
struct lastfm_playlist *playlist = (struct lastfm_playlist *)_playlist;
playlist_plugin_close(playlist->xspf);
- input_stream_close(&playlist->is);
+ input_stream_close(playlist->is);
g_free(playlist);
}
diff --git a/src/playlist_list.c b/src/playlist_list.c
index 46fd238c1..d034f4c1e 100644
--- a/src/playlist_list.c
+++ b/src/playlist_list.c
@@ -293,10 +293,11 @@ playlist_suffix_supported(const char *suffix)
}
struct playlist_provider *
-playlist_list_open_path(struct input_stream *is, const char *path_fs)
+playlist_list_open_path(const char *path_fs)
{
GError *error = NULL;
const char *suffix;
+ struct input_stream *is;
struct playlist_provider *playlist;
assert(path_fs != NULL);
@@ -305,7 +306,8 @@ playlist_list_open_path(struct input_stream *is, const char *path_fs)
if (suffix == NULL || !playlist_suffix_supported(suffix))
return NULL;
- if (!input_stream_open(is, path_fs, &error)) {
+ is = input_stream_open(path_fs, &error);
+ if (is == NULL) {
if (error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
diff --git a/src/playlist_list.h b/src/playlist_list.h
index 84e179b4d..f19fa6579 100644
--- a/src/playlist_list.h
+++ b/src/playlist_list.h
@@ -54,12 +54,10 @@ playlist_list_open_stream(struct input_stream *is, const char *uri);
/**
* Opens a playlist from a local file.
*
- * @param is an uninitialized #input_stream object (must be closed
- * with input_stream_close() if this function succeeds)
* @param path_fs the path of the playlist file
* @return a playlist, or NULL on error
*/
struct playlist_provider *
-playlist_list_open_path(struct input_stream *is, const char *path_fs);
+playlist_list_open_path(const char *path_fs);
#endif
diff --git a/src/playlist_queue.c b/src/playlist_queue.c
index 5c000b148..327cdcacc 100644
--- a/src/playlist_queue.c
+++ b/src/playlist_queue.c
@@ -163,16 +163,15 @@ playlist_open_remote_into_queue(const char *uri, struct playlist *dest)
{
GError *error = NULL;
struct playlist_provider *playlist;
- bool stream = false;
- struct input_stream is;
+ struct input_stream *is = NULL;
enum playlist_result result;
assert(uri_has_scheme(uri));
playlist = playlist_list_open_uri(uri);
if (playlist == NULL) {
- stream = input_stream_open(&is, uri, &error);
- if (!stream) {
+ is = input_stream_open(uri, &error);
+ if (is == NULL) {
if (error != NULL) {
g_warning("Failed to open %s: %s",
uri, error->message);
@@ -182,9 +181,9 @@ playlist_open_remote_into_queue(const char *uri, struct playlist *dest)
return PLAYLIST_RESULT_NO_SUCH_LIST;
}
- playlist = playlist_list_open_stream(&is, uri);
+ playlist = playlist_list_open_stream(is, uri);
if (playlist == NULL) {
- input_stream_close(&is);
+ input_stream_close(is);
return PLAYLIST_RESULT_NO_SUCH_LIST;
}
}
@@ -192,8 +191,8 @@ playlist_open_remote_into_queue(const char *uri, struct playlist *dest)
result = playlist_load_into_queue(uri, playlist, dest);
playlist_plugin_close(playlist);
- if (stream)
- input_stream_close(&is);
+ if (is != NULL)
+ input_stream_close(is);
return result;
}
@@ -203,15 +202,13 @@ playlist_open_path_into_queue(const char *path_fs, const char *uri,
struct playlist *dest)
{
struct playlist_provider *playlist;
- struct input_stream is;
enum playlist_result result;
if ((playlist = playlist_list_open_uri(path_fs)) != NULL)
result = playlist_load_into_queue(uri, playlist, dest);
- else if ((playlist = playlist_list_open_path(&is, path_fs)) != NULL) {
+ else if ((playlist = playlist_list_open_path(path_fs)) != NULL)
result = playlist_load_into_queue(uri, playlist, dest);
- input_stream_close(&is);
- } else
+ else
return PLAYLIST_RESULT_NO_SUCH_LIST;
playlist_plugin_close(playlist);