aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--src/archive/bz2_archive_plugin.c5
-rw-r--r--src/archive/iso9660_archive_plugin.c6
-rw-r--r--src/archive/zzip_archive_plugin.c6
-rw-r--r--src/archive_internal.h9
-rw-r--r--src/archive_plugin.c87
-rw-r--r--src/archive_plugin.h17
-rw-r--r--src/input/archive_input_plugin.c6
-rw-r--r--src/update_walk.c8
9 files changed, 133 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index f2e8cf3db..0d74ab36b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -369,6 +369,7 @@ if ENABLE_ARCHIVE
ARCHIVE_SRC += \
src/archive_api.c \
src/archive_list.c \
+ src/archive_plugin.c \
src/input/archive_input_plugin.c
endif
diff --git a/src/archive/bz2_archive_plugin.c b/src/archive/bz2_archive_plugin.c
index 766c558ed..e8e5c556c 100644
--- a/src/archive/bz2_archive_plugin.c
+++ b/src/archive/bz2_archive_plugin.c
@@ -40,6 +40,8 @@
#define BZ_BUFSIZE 5000
struct bz2_archive_file {
+ struct archive_file base;
+
char *name;
bool reset;
struct input_stream istream;
@@ -102,6 +104,7 @@ bz2_open(const char *pathname)
int len;
context = g_malloc(sizeof(*context));
+ archive_file_init(&context->base, &bz2_archive_plugin);
//open archive
if (!input_stream_open(&context->istream, pathname, NULL)) {
@@ -118,7 +121,7 @@ bz2_open(const char *pathname)
context->name[len - 4] = 0; //remove .bz2 suffix
}
- return (struct archive_file *) context;
+ return &context->base;
}
static void
diff --git a/src/archive/iso9660_archive_plugin.c b/src/archive/iso9660_archive_plugin.c
index 0c21d5128..ccab9e614 100644
--- a/src/archive/iso9660_archive_plugin.c
+++ b/src/archive/iso9660_archive_plugin.c
@@ -35,6 +35,8 @@
#define CEILING(x, y) ((x+(y-1))/y)
struct iso9660_archive_file {
+ struct archive_file base;
+
iso9660_t *iso;
iso9660_stat_t *statbuf;
size_t cur_ofs;
@@ -93,6 +95,8 @@ iso9660_archive_open(const char *pathname)
struct iso9660_archive_file *context =
g_new(struct iso9660_archive_file, 1);
+ archive_file_init(&context->base, &iso9660_archive_plugin);
+
context->list = NULL;
/* open archive */
@@ -104,7 +108,7 @@ iso9660_archive_open(const char *pathname)
listdir_recur("/", context);
- return (struct archive_file *)context;
+ return &context->base;
}
static void
diff --git a/src/archive/zzip_archive_plugin.c b/src/archive/zzip_archive_plugin.c
index ba89e82b3..1174629ae 100644
--- a/src/archive/zzip_archive_plugin.c
+++ b/src/archive/zzip_archive_plugin.c
@@ -32,6 +32,8 @@
#include <string.h>
struct zzip_archive {
+ struct archive_file base;
+
ZZIP_DIR *dir;
ZZIP_FILE *file;
size_t length;
@@ -55,6 +57,8 @@ zzip_archive_open(const char *pathname)
struct zzip_archive *context = g_malloc(sizeof(*context));
ZZIP_DIRENT dirent;
+ archive_file_init(&context->base, &zzip_archive_plugin);
+
// open archive
context->list = NULL;
context->dir = zzip_dir_open(pathname, NULL);
@@ -71,7 +75,7 @@ zzip_archive_open(const char *pathname)
}
}
- return (struct archive_file *)context;
+ return &context->base;
}
static void
diff --git a/src/archive_internal.h b/src/archive_internal.h
index 130d25d65..3d973381e 100644
--- a/src/archive_internal.h
+++ b/src/archive_internal.h
@@ -21,7 +21,14 @@
#define MPD_ARCHIVE_INTERNAL_H
struct archive_file {
- int placeholder;
+ const struct archive_plugin *plugin;
};
+static inline void
+archive_file_init(struct archive_file *archive_file,
+ const struct archive_plugin *plugin)
+{
+ archive_file->plugin = plugin;
+}
+
#endif
diff --git a/src/archive_plugin.c b/src/archive_plugin.c
new file mode 100644
index 000000000..2626c53fb
--- /dev/null
+++ b/src/archive_plugin.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "archive_plugin.h"
+#include "archive_internal.h"
+
+#include <assert.h>
+
+struct archive_file *
+archive_file_open(const struct archive_plugin *plugin, const char *path)
+{
+ struct archive_file *file;
+
+ assert(plugin != NULL);
+ assert(plugin->open != NULL);
+ assert(path != NULL);
+
+ file = plugin->open(path);
+
+ if (file != NULL) {
+ assert(file->plugin != NULL);
+ assert(file->plugin->close != NULL);
+ assert(file->plugin->scan_reset != NULL);
+ assert(file->plugin->scan_next != NULL);
+ assert(file->plugin->open_stream != NULL);
+ }
+
+ return file;
+}
+
+void
+archive_file_close(struct archive_file *file)
+{
+ assert(file != NULL);
+ assert(file->plugin != NULL);
+ assert(file->plugin->close != NULL);
+
+ file->plugin->close(file);
+}
+
+void
+archive_file_scan_reset(struct archive_file *file)
+{
+ assert(file != NULL);
+ assert(file->plugin != NULL);
+ assert(file->plugin->scan_reset != NULL);
+ assert(file->plugin->scan_next != NULL);
+
+ file->plugin->scan_reset(file);
+}
+
+char *
+archive_file_scan_next(struct archive_file *file)
+{
+ assert(file != NULL);
+ assert(file->plugin != NULL);
+ assert(file->plugin->scan_next != NULL);
+
+ return file->plugin->scan_next(file);
+}
+
+bool
+archive_file_open_stream(struct archive_file *file, struct input_stream *is,
+ const char *path, GError **error_r)
+{
+ assert(file != NULL);
+ assert(file->plugin != NULL);
+ assert(file->plugin->open_stream != NULL);
+
+ return file->plugin->open_stream(file, is, path, error_r);
+}
diff --git a/src/archive_plugin.h b/src/archive_plugin.h
index 864eb5e72..1c35293d1 100644
--- a/src/archive_plugin.h
+++ b/src/archive_plugin.h
@@ -89,5 +89,20 @@ struct archive_plugin {
const char *const*suffixes;
};
-#endif
+struct archive_file *
+archive_file_open(const struct archive_plugin *plugin, const char *path);
+
+void
+archive_file_close(struct archive_file *file);
+
+void
+archive_file_scan_reset(struct archive_file *file);
+char *
+archive_file_scan_next(struct archive_file *file);
+
+bool
+archive_file_open_stream(struct archive_file *file, struct input_stream *is,
+ const char *path, GError **error_r);
+
+#endif
diff --git a/src/input/archive_input_plugin.c b/src/input/archive_input_plugin.c
index ad077828a..4847b4483 100644
--- a/src/input/archive_input_plugin.c
+++ b/src/input/archive_input_plugin.c
@@ -61,14 +61,14 @@ input_archive_open(struct input_stream *is, const char *pathname,
return false;
}
- file = arplug->open(archive);
+ file = archive_file_open(arplug, archive);
//setup fileops
- opened = arplug->open_stream(file, is, filename, error_r);
+ opened = archive_file_open_stream(file, is, filename, error_r);
g_free(pname);
if (!opened) {
- arplug->close(file);
+ archive_file_close(file);
} else {
is->ready = true;
}
diff --git a/src/update_walk.c b/src/update_walk.c
index 31b60bd67..f6f924bd6 100644
--- a/src/update_walk.c
+++ b/src/update_walk.c
@@ -409,7 +409,7 @@ update_archive_file(struct directory *parent, const char *name,
path_fs = map_directory_child_fs(parent, name);
/* open archive */
- file = plugin->open(path_fs);
+ file = archive_file_open(plugin, path_fs);
if (file == NULL) {
g_warning("unable to open archive %s", path_fs);
g_free(path_fs);
@@ -429,15 +429,15 @@ update_archive_file(struct directory *parent, const char *name,
directory->mtime = st->st_mtime;
- plugin->scan_reset(file);
+ archive_file_scan_reset(file);
- while ((filepath = plugin->scan_next(file)) != NULL) {
+ while ((filepath = archive_file_scan_next(file)) != NULL) {
/* split name into directory and file */
g_debug("adding archive file: %s", filepath);
update_archive_tree(directory, filepath);
}
- plugin->close(file);
+ archive_file_close(file);
}
#endif