aboutsummaryrefslogtreecommitdiffstats
path: root/src/input_archive.c
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 /src/input_archive.c
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/input_archive.c85
1 files changed, 4 insertions, 81 deletions
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,
};