diff options
author | Max Kellermann <max@duempel.org> | 2009-12-30 23:27:37 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-01-01 17:25:07 +0100 |
commit | d3b763a48c09a60a0c0b5ccb6cccd9376875c470 (patch) | |
tree | 83b8794f78ef8941806cf5757888d8abf2eaa126 /src/archive/zzip_archive_plugin.c | |
parent | 816b6ad4a71c3ade95e62b62396f2b0415c03f20 (diff) | |
download | mpd-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/archive/zzip_archive_plugin.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/archive/zzip_archive_plugin.c b/src/archive/zzip_archive_plugin.c index 3e0c063c2..7e59a0935 100644 --- a/src/archive/zzip_archive_plugin.c +++ b/src/archive/zzip_archive_plugin.c @@ -125,13 +125,15 @@ zzip_archive_close(struct archive_file *file) /* single archive handling */ struct zzip_input_stream { + struct input_stream base; + struct zzip_archive *archive; ZZIP_FILE *file; }; -static bool -zzip_archive_open_stream(struct archive_file *file, struct input_stream *is, +static struct input_stream * +zzip_archive_open_stream(struct archive_file *file, const char *pathname, GError **error_r) { struct zzip_archive *context = (struct zzip_archive *) file; @@ -139,6 +141,7 @@ zzip_archive_open_stream(struct archive_file *file, struct input_stream *is, ZZIP_STAT z_stat; zis = g_new(struct zzip_input_stream, 1); + input_stream_init(&zis->base, &zzip_input_plugin); zis->archive = context; zis->file = zzip_file_open(context->dir, pathname, 0); @@ -146,29 +149,25 @@ zzip_archive_open_stream(struct archive_file *file, struct input_stream *is, g_free(zis); g_set_error(error_r, zzip_quark(), 0, "not found in the ZIP file: %s", pathname); - return false; + return NULL; } - //setup file ops - is->plugin = &zzip_input_plugin; - //insert back reference - is->data = zis; - is->ready = true; + zis->base.ready = true; //we are seekable (but its not recommendent to do so) - is->seekable = true; + zis->base.seekable = true; zzip_file_stat(zis->file, &z_stat); - is->size = z_stat.st_size; + zis->base.size = z_stat.st_size; refcount_inc(&context->ref); - return true; + return &zis->base; } static void zzip_input_close(struct input_stream *is) { - struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data; + struct zzip_input_stream *zis = (struct zzip_input_stream *)is; zzip_file_close(zis->file); zzip_archive_close(&zis->archive->base); @@ -179,7 +178,7 @@ static size_t zzip_input_read(struct input_stream *is, void *ptr, size_t size, GError **error_r) { - struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data; + struct zzip_input_stream *zis = (struct zzip_input_stream *)is; int ret; ret = zzip_file_read(zis->file, ptr, size); @@ -197,7 +196,7 @@ zzip_input_read(struct input_stream *is, void *ptr, size_t size, static bool zzip_input_eof(struct input_stream *is) { - struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data; + struct zzip_input_stream *zis = (struct zzip_input_stream *)is; return (goffset)zzip_tell(zis->file) == is->size; } @@ -206,7 +205,7 @@ static bool zzip_input_seek(struct input_stream *is, goffset offset, int whence, GError **error_r) { - struct zzip_input_stream *zis = (struct zzip_input_stream *)is->data; + struct zzip_input_stream *zis = (struct zzip_input_stream *)is; zzip_off_t ofs = zzip_seek(zis->file, offset, whence); if (ofs != -1) { g_set_error(error_r, zzip_quark(), ofs, |