aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/bz2_archive_plugin.c
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/archive/bz2_archive_plugin.c
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 'src/archive/bz2_archive_plugin.c')
-rw-r--r--src/archive/bz2_archive_plugin.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/archive/bz2_archive_plugin.c b/src/archive/bz2_archive_plugin.c
index 07d174403..75b4b1ece 100644
--- a/src/archive/bz2_archive_plugin.c
+++ b/src/archive/bz2_archive_plugin.c
@@ -45,10 +45,12 @@ struct bz2_archive_file {
char *name;
bool reset;
- struct input_stream istream;
+ struct input_stream *istream;
};
struct bz2_input_stream {
+ struct input_stream base;
+
struct bz2_archive_file *archive;
bool eof;
@@ -111,7 +113,8 @@ bz2_open(const char *pathname, GError **error_r)
refcount_init(&context->ref);
//open archive
- if (!input_stream_open(&context->istream, pathname, error_r)) {
+ context->istream = input_stream_open(pathname, error_r);
+ if (context->istream == NULL) {
g_free(context);
return NULL;
}
@@ -158,44 +161,42 @@ bz2_close(struct archive_file *file)
g_free(context->name);
- input_stream_close(&context->istream);
+ input_stream_close(context->istream);
g_free(context);
}
/* single archive handling */
-static bool
-bz2_open_stream(struct archive_file *file, struct input_stream *is,
+static struct input_stream *
+bz2_open_stream(struct archive_file *file,
G_GNUC_UNUSED const char *path, GError **error_r)
{
struct bz2_archive_file *context = (struct bz2_archive_file *) file;
struct bz2_input_stream *bis = g_new(struct bz2_input_stream, 1);
+ input_stream_init(&bis->base, &bz2_inputplugin);
+
bis->archive = context;
- //setup file ops
- is->plugin = &bz2_inputplugin;
- //insert back reference
- is->data = bis;
- is->ready = true;
- is->seekable = false;
+ bis->base.ready = true;
+ bis->base.seekable = false;
if (!bz2_alloc(bis, error_r)) {
g_free(bis);
- return false;
+ return NULL;
}
bis->eof = false;
refcount_inc(&context->ref);
- return true;
+ return &bis->base;
}
static void
bz2_is_close(struct input_stream *is)
{
- struct bz2_input_stream *bis = (struct bz2_input_stream *)is->data;
+ struct bz2_input_stream *bis = (struct bz2_input_stream *)is;
bz2_destroy(bis);
@@ -215,7 +216,7 @@ bz2_fillbuffer(struct bz2_input_stream *bis, GError **error_r)
if (bzstream->avail_in > 0)
return true;
- count = input_stream_read(&bis->archive->istream,
+ count = input_stream_read(bis->archive->istream,
bis->buffer, sizeof(bis->buffer),
error_r);
if (count == 0)
@@ -230,7 +231,7 @@ static size_t
bz2_is_read(struct input_stream *is, void *ptr, size_t length,
GError **error_r)
{
- struct bz2_input_stream *bis = (struct bz2_input_stream *)is->data;
+ struct bz2_input_stream *bis = (struct bz2_input_stream *)is;
bz_stream *bzstream;
int bz_result;
size_t nbytes = 0;
@@ -269,7 +270,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length,
static bool
bz2_is_eof(struct input_stream *is)
{
- struct bz2_input_stream *bis = (struct bz2_input_stream *)is->data;
+ struct bz2_input_stream *bis = (struct bz2_input_stream *)is;
return bis->eof;
}