aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-30 00:53:32 +0100
committerMax Kellermann <max@duempel.org>2009-01-30 00:53:32 +0100
commit82cfce76eb5787f1a24151f6a3840a999ed82659 (patch)
tree05c8ee19ff9bd9cc69e6f50c1aeeacc77efbde44
parentdc1cc7e7e52960cceea5514397ec33f7ffc0dd6d (diff)
downloadmpd-82cfce76eb5787f1a24151f6a3840a999ed82659.tar.gz
mpd-82cfce76eb5787f1a24151f6a3840a999ed82659.tar.xz
mpd-82cfce76eb5787f1a24151f6a3840a999ed82659.zip
archive: replaced setup_stream() with open_stream()
The open_stream() method opens the input_stream. This allows the archive plugin to do its own initialization, and it also allows it to use input_stream.data. We can remove input_stream.archive now, which was unnatural to have in the first place.
Diffstat (limited to '')
-rw-r--r--src/archive/bz2_plugin.c23
-rw-r--r--src/archive/iso_plugin.c23
-rw-r--r--src/archive/zip_plugin.c28
-rw-r--r--src/archive_api.h9
-rw-r--r--src/decoder_thread.c2
-rw-r--r--src/input_archive.c85
-rw-r--r--src/input_stream.h2
7 files changed, 37 insertions, 135 deletions
diff --git a/src/archive/bz2_plugin.c b/src/archive/bz2_plugin.c
index b63a9ddfc..6067d2acc 100644
--- a/src/archive/bz2_plugin.c
+++ b/src/archive/bz2_plugin.c
@@ -148,22 +148,16 @@ bz2_close(struct archive_file *file)
/* single archive handling */
-static void
-bz2_setup_stream(struct archive_file *file, struct input_stream *is)
+static bool
+bz2_open_stream(struct archive_file *file, struct input_stream *is,
+ G_GNUC_UNUSED const char *path)
{
bz2_context *context = (bz2_context *) file;
//setup file ops
is->plugin = &bz2_inputplugin;
//insert back reference
- is->archive = context;
+ is->data = context;
is->seekable = false;
-}
-
-
-static bool
-bz2_is_open(struct input_stream *is, G_GNUC_UNUSED const char *url)
-{
- bz2_context *context = (bz2_context *) is->archive;
if (!bz2_alloc(context)) {
g_warning("alloc bz2 failed\n");
@@ -175,7 +169,7 @@ bz2_is_open(struct input_stream *is, G_GNUC_UNUSED const char *url)
static void
bz2_is_close(struct input_stream *is)
{
- bz2_context *context = (bz2_context *) is->archive;
+ bz2_context *context = (bz2_context *) is->data;
bz2_destroy(context);
is->data = NULL;
}
@@ -211,7 +205,7 @@ bz2_fillbuffer(bz2_context *context,
static size_t
bz2_is_read(struct input_stream *is, void *ptr, size_t size)
{
- bz2_context *context = (bz2_context *) is->archive;
+ bz2_context *context = (bz2_context *) is->data;
bz_stream *bzstream;
int bz_result;
size_t numBytes = size;
@@ -253,7 +247,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
bz2_is_eof(struct input_stream *is)
{
- bz2_context *context = (bz2_context *) is->archive;
+ bz2_context *context = (bz2_context *) is->data;
if (context->last_bz_result == BZ_STREAM_END) {
return true;
@@ -283,7 +277,6 @@ static const char *const bz2_extensions[] = {
};
static const struct input_plugin bz2_inputplugin = {
- .open = bz2_is_open,
.close = bz2_is_close,
.read = bz2_is_read,
.eof = bz2_is_eof,
@@ -296,7 +289,7 @@ const struct archive_plugin bz2_plugin = {
.open = bz2_open,
.scan_reset = bz2_scan_reset,
.scan_next = bz2_scan_next,
- .setup_stream = bz2_setup_stream,
+ .open_stream = bz2_open_stream,
.close = bz2_close,
.suffixes = bz2_extensions
};
diff --git a/src/archive/iso_plugin.c b/src/archive/iso_plugin.c
index d74d69577..de5582e2c 100644
--- a/src/archive/iso_plugin.c
+++ b/src/archive/iso_plugin.c
@@ -136,23 +136,17 @@ iso_close(struct archive_file *file)
/* single archive handling */
-static void
-iso_setup_stream(struct archive_file *file, struct input_stream *is)
+static bool
+iso_open_stream(struct archive_file *file, struct input_stream *is,
+ const char *pathname)
{
iso_context *context = (iso_context *) file;
//setup file ops
is->plugin = &iso_inputplugin;
//insert back reference
- is->archive = context;
+ is->data = context;
//we are not seekable
is->seekable = false;
-}
-
-
-static bool
-iso_is_open(struct input_stream *is, const char *pathname)
-{
- iso_context *context = (iso_context *) is->archive;
context->statbuf = iso9660_ifs_stat_translate (context->iso, pathname);
@@ -168,7 +162,7 @@ iso_is_open(struct input_stream *is, const char *pathname)
static void
iso_is_close(struct input_stream *is)
{
- iso_context *context = (iso_context *) is->archive;
+ iso_context *context = (iso_context *) is->data;
g_free(context->statbuf);
}
@@ -176,7 +170,7 @@ iso_is_close(struct input_stream *is)
static size_t
iso_is_read(struct input_stream *is, void *ptr, size_t size)
{
- iso_context *context = (iso_context *) is->archive;
+ iso_context *context = (iso_context *) is->data;
int toread, readed = 0;
int no_blocks, cur_block;
size_t left_bytes = context->statbuf->size - context->cur_ofs;
@@ -213,7 +207,7 @@ iso_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
iso_is_eof(struct input_stream *is)
{
- iso_context *context = (iso_context *) is->archive;
+ iso_context *context = (iso_context *) is->data;
return (context->cur_ofs == context->statbuf->size);
}
@@ -238,7 +232,6 @@ static const char *const iso_extensions[] = {
};
static const struct input_plugin iso_inputplugin = {
- .open = iso_is_open,
.close = iso_is_close,
.read = iso_is_read,
.eof = iso_is_eof,
@@ -251,7 +244,7 @@ const struct archive_plugin iso_plugin = {
.open = iso_open,
.scan_reset = iso_scan_reset,
.scan_next = iso_scan_next,
- .setup_stream = iso_setup_stream,
+ .open_stream = iso_open_stream,
.close = iso_close,
.suffixes = iso_extensions
};
diff --git a/src/archive/zip_plugin.c b/src/archive/zip_plugin.c
index d318adc06..9df449ab5 100644
--- a/src/archive/zip_plugin.c
+++ b/src/archive/zip_plugin.c
@@ -103,24 +103,19 @@ zip_close(struct archive_file *file)
/* single archive handling */
-static void
-zip_setup_stream(struct archive_file *file, struct input_stream *is)
+static bool
+zip_open_stream(struct archive_file *file, struct input_stream *is,
+ const char *pathname)
{
zip_context *context = (zip_context *) file;
+ ZZIP_STAT z_stat;
+
//setup file ops
is->plugin = &zip_inputplugin;
//insert back reference
- is->archive = context;
+ is->data = context;
//we are seekable (but its not recommendent to do so)
is->seekable = true;
-}
-
-
-static bool
-zip_is_open(struct input_stream *is, const char *pathname)
-{
- zip_context *context = (zip_context *) is->archive;
- ZZIP_STAT z_stat;
context->file = zzip_file_open(context->dir, pathname, 0);
if (!context->file) {
@@ -135,14 +130,14 @@ zip_is_open(struct input_stream *is, const char *pathname)
static void
zip_is_close(struct input_stream *is)
{
- zip_context *context = (zip_context *) is->archive;
+ zip_context *context = (zip_context *) is->data;
zzip_file_close (context->file);
}
static size_t
zip_is_read(struct input_stream *is, void *ptr, size_t size)
{
- zip_context *context = (zip_context *) is->archive;
+ zip_context *context = (zip_context *) is->data;
int ret;
ret = zzip_file_read(context->file, ptr, size);
if (ret < 0) {
@@ -155,7 +150,7 @@ zip_is_read(struct input_stream *is, void *ptr, size_t size)
static bool
zip_is_eof(struct input_stream *is)
{
- zip_context *context = (zip_context *) is->archive;
+ zip_context *context = (zip_context *) is->data;
return ((size_t) zzip_tell(context->file) == context->length);
}
@@ -163,7 +158,7 @@ static bool
zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
{
- zip_context *context = (zip_context *) is->archive;
+ zip_context *context = (zip_context *) is->data;
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
if (ofs != -1) {
is->offset = ofs;
@@ -186,7 +181,6 @@ static const char *const zip_extensions[] = {
};
static const struct input_plugin zip_inputplugin = {
- .open = zip_is_open,
.close = zip_is_close,
.read = zip_is_read,
.eof = zip_is_eof,
@@ -199,7 +193,7 @@ const struct archive_plugin zip_plugin = {
.open = zip_open,
.scan_reset = zip_scan_reset,
.scan_next = zip_scan_next,
- .setup_stream = zip_setup_stream,
+ .open_stream = zip_open_stream,
.close = zip_close,
.suffixes = zip_extensions
};
diff --git a/src/archive_api.h b/src/archive_api.h
index 3c9e979f6..a3761bf93 100644
--- a/src/archive_api.h
+++ b/src/archive_api.h
@@ -70,11 +70,12 @@ struct archive_plugin {
char *(*scan_next)(struct archive_file *);
/**
- * this is used to setup input stream handle, to be able to read
- * from archive. open method of inputstream can be the used to
- * extract particular file
+ * Opens an input_stream of a file within the archive.
+ *
+ * @param path the path within the archive
*/
- void (*setup_stream)(struct archive_file *, struct input_stream *is);
+ bool (*open_stream)(struct archive_file *, struct input_stream *is,
+ const char *path);
/**
* closes archive file.
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 97555f44d..b7939111a 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -127,7 +127,7 @@ static void decoder_run_song(const struct song *song, const char *uri)
pcm_convert_init(&decoder.conv_state);
ret = false;
- if (!song_is_file(song)) {
+ if (!song_is_file(song) || true) {
unsigned int next = 0;
/* first we try mime types: */
diff --git a/src/input_archive.c b/src/input_archive.c
index 387ad465a..26a44d2f4 100644
--- a/src/input_archive.c
+++ b/src/input_archive.c
@@ -16,29 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "input_archive.h"
#include "archive_api.h"
#include "archive_list.h"
-#include "input_archive.h"
#include "input_stream.h"
-#include "gcc.h"
-#include "log.h"
-#include "ls.h"
-#include <stdbool.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <assert.h>
#include <glib.h>
-typedef struct {
- const struct archive_plugin *aplugin;
- const struct input_plugin *iplugin;
- struct archive_file *file;
-} archive_context;
-
/**
* select correct archive plugin to handle the input stream
* may allow stacking of archive plugins. for example for handling
@@ -50,8 +34,8 @@ typedef struct {
static bool
input_archive_open(struct input_stream *is, const char *pathname)
{
- archive_context *arch_ctx;
const struct archive_plugin *arplug;
+ struct archive_file *file;
char *archive, *filename, *suffix, *pname;
bool opened;
@@ -74,24 +58,10 @@ input_archive_open(struct input_stream *is, const char *pathname)
return false;
}
- arch_ctx = (archive_context *) g_malloc(sizeof(archive_context));
+ file = arplug->open(archive);
- //setup archive plugin pointer
- arch_ctx->aplugin = arplug;
- //open archive file
- arch_ctx->file = arplug->open(archive);
//setup fileops
- arplug->setup_stream(arch_ctx->file, is);
- //setup input plugin backup
- arch_ctx->iplugin = is->plugin;
- is->plugin = &input_plugin_archive;
-
- //internal handle
- is->plugin = &input_plugin_archive;
- is->data = arch_ctx;
-
- //open archive
- opened = arch_ctx->iplugin->open(is, filename);
+ opened = arplug->open_stream(file, is, filename);
if (!opened) {
g_warning("open inarchive file %s failed\n\n",filename);
@@ -102,53 +72,6 @@ input_archive_open(struct input_stream *is, const char *pathname)
return opened;
}
-static void
-input_archive_close(struct input_stream *is)
-{
- archive_context *arch_ctx = (archive_context *)is->data;
- //close archive infile ops
- arch_ctx->iplugin->close(is);
- //close archive
- arch_ctx->aplugin->close(arch_ctx->file);
- //free private data
- g_free(arch_ctx);
-}
-
-static bool
-input_archive_seek(struct input_stream *is, off_t offset, int whence)
-{
- archive_context *arch_ctx = (archive_context *)is->data;
- return arch_ctx->iplugin->seek(is, offset, whence);
-}
-
-static size_t
-input_archive_read(struct input_stream *is, void *ptr, size_t size)
-{
- archive_context *arch_ctx = (archive_context *)is->data;
- assert(ptr != NULL);
- assert(size > 0);
- return arch_ctx->iplugin->read(is, ptr, size);
-}
-
-static bool
-input_archive_eof(struct input_stream *is)
-{
- archive_context *arch_ctx = (archive_context *)is->data;
- return arch_ctx->iplugin->eof(is);
-}
-
-static int
-input_archive_buffer(struct input_stream *is)
-{
- archive_context *arch_ctx = (archive_context *)is->data;
- return arch_ctx->iplugin->buffer(is);
-}
-
const struct input_plugin input_plugin_archive = {
.open = input_archive_open,
- .close = input_archive_close,
- .buffer = input_archive_buffer,
- .read = input_archive_read,
- .eof = input_archive_eof,
- .seek = input_archive_seek,
};
diff --git a/src/input_stream.h b/src/input_stream.h
index f57ac3120..d8698c4cd 100644
--- a/src/input_stream.h
+++ b/src/input_stream.h
@@ -77,8 +77,6 @@ struct input_stream {
* the MIME content type of the resource, or NULL if unknown
*/
char *mime;
-
- void *archive;
};
/**