aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/iso9660_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/iso9660_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/iso9660_archive_plugin.c')
-rw-r--r--src/archive/iso9660_archive_plugin.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/archive/iso9660_archive_plugin.c b/src/archive/iso9660_archive_plugin.c
index f6c6ed5f2..38003da94 100644
--- a/src/archive/iso9660_archive_plugin.c
+++ b/src/archive/iso9660_archive_plugin.c
@@ -163,14 +163,16 @@ iso9660_archive_close(struct archive_file *file)
/* single archive handling */
struct iso9660_input_stream {
+ struct input_stream base;
+
struct iso9660_archive_file *archive;
iso9660_stat_t *statbuf;
size_t max_blocks;
};
-static bool
-iso9660_archive_open_stream(struct archive_file *file, struct input_stream *is,
+static struct input_stream *
+iso9660_archive_open_stream(struct archive_file *file,
const char *pathname, GError **error_r)
{
struct iso9660_archive_file *context =
@@ -178,6 +180,7 @@ iso9660_archive_open_stream(struct archive_file *file, struct input_stream *is,
struct iso9660_input_stream *iis;
iis = g_new(struct iso9660_input_stream, 1);
+ input_stream_init(&iis->base, &iso9660_input_plugin);
iis->archive = context;
iis->statbuf = iso9660_ifs_stat_translate(context->iso, pathname);
@@ -185,31 +188,26 @@ iso9660_archive_open_stream(struct archive_file *file, struct input_stream *is,
g_free(iis);
g_set_error(error_r, iso9660_quark(), 0,
"not found in the ISO file: %s", pathname);
- return false;
+ return NULL;
}
- //setup file ops
- is->plugin = &iso9660_input_plugin;
- //insert back reference
- is->data = iis;
- is->ready = true;
+ iis->base.ready = true;
//we are not seekable
- is->seekable = false;
+ iis->base.seekable = false;
- is->size = iis->statbuf->size;
+ iis->base.size = iis->statbuf->size;
iis->max_blocks = CEILING(iis->statbuf->size, ISO_BLOCKSIZE);
refcount_inc(&context->ref);
- return true;
+ return &iis->base;
}
static void
iso9660_input_close(struct input_stream *is)
{
- struct iso9660_input_stream *iis =
- (struct iso9660_input_stream *)is->data;
+ struct iso9660_input_stream *iis = (struct iso9660_input_stream *)is;
g_free(iis->statbuf);
@@ -220,8 +218,7 @@ iso9660_input_close(struct input_stream *is)
static size_t
iso9660_input_read(struct input_stream *is, void *ptr, size_t size, GError **error_r)
{
- struct iso9660_input_stream *iis =
- (struct iso9660_input_stream *)is->data;
+ struct iso9660_input_stream *iis = (struct iso9660_input_stream *)is;
int toread, readed = 0;
int no_blocks, cur_block;
size_t left_bytes = iis->statbuf->size - is->offset;