aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/archive/bz2_plugin.c55
-rw-r--r--src/archive/iso_plugin.c1
-rw-r--r--src/archive/zip_plugin.c3
-rw-r--r--src/archive_api.c5
-rw-r--r--src/archive_api.h63
-rw-r--r--src/archive_list.c25
-rw-r--r--src/archive_list.h2
-rw-r--r--src/archive_plugin.h89
8 files changed, 136 insertions, 107 deletions
diff --git a/src/archive/bz2_plugin.c b/src/archive/bz2_plugin.c
index 0ef042e90..693dd4dba 100644
--- a/src/archive/bz2_plugin.c
+++ b/src/archive/bz2_plugin.c
@@ -21,9 +21,9 @@
* single bz2 archive handling (requires libbz2)
*/
+#include "config.h"
#include "archive_api.h"
#include "input_plugin.h"
-#include "config.h"
#include <stdint.h>
#include <stddef.h>
@@ -32,23 +32,22 @@
#include <bzlib.h>
#ifdef HAVE_OLDER_BZIP2
-#define BZ2_bzDecompressInit bzDecompressInit
-#define BZ2_bzDecompress bzDecompress
+#define BZ2_bzDecompressInit bzDecompressInit
+#define BZ2_bzDecompress bzDecompress
#endif
#define BZ_BUFSIZE 5000
typedef struct {
- char *name;
- bool reset;
+ char *name;
+ bool reset;
struct input_stream istream;
- int last_bz_result;
- int last_parent_result;
- bz_stream bzstream;
- char *buffer;
+ int last_bz_result;
+ int last_parent_result;
+ bz_stream bzstream;
+ char *buffer;
} bz2_context;
-
static const struct input_plugin bz2_inputplugin;
/* single archive handling allocation helpers */
@@ -85,22 +84,21 @@ bz2_destroy(bz2_context *data)
/* archive open && listing routine */
static struct archive_file *
-bz2_open(char * pathname)
+bz2_open(char *pathname)
{
bz2_context *context;
char *name;
int len;
- context = g_malloc(sizeof(bz2_context));
- if (!context) {
- return NULL;
- }
+ context = g_malloc(sizeof(*context));
+
//open archive
if (!input_stream_open(&context->istream, pathname)) {
g_warning("failed to open an bzip2 archive %s\n",pathname);
g_free(context);
return NULL;
}
+
//capture filename
name = strrchr(pathname, '/');
if (name == NULL) {
@@ -108,12 +106,15 @@ bz2_open(char * pathname)
g_free(context);
return NULL;
}
- context->name = g_strdup(name+1);
+
+ context->name = g_strdup(name + 1);
+
//remove suffix
len = strlen(context->name);
if (len > 4) {
- context->name[len-4] = 0; //remove .bz2 suffix
+ context->name[len - 4] = 0; //remove .bz2 suffix
}
+
return (struct archive_file *) context;
}
@@ -129,10 +130,12 @@ bz2_scan_next(struct archive_file *file)
{
bz2_context *context = (bz2_context *) file;
char *name = NULL;
+
if (context->reset) {
name = context->name;
context->reset = false;
}
+
return name;
}
@@ -154,6 +157,7 @@ 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
@@ -164,6 +168,7 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is,
g_warning("alloc bz2 failed\n");
return false;
}
+
return true;
}
@@ -177,9 +182,8 @@ bz2_is_close(struct input_stream *is)
bz2_close((struct archive_file *)context);
}
-static int
-bz2_fillbuffer(bz2_context *context,
- size_t numBytes)
+static bool
+bz2_fillbuffer(bz2_context *context, size_t numBytes)
{
size_t count;
bz_stream *bzstream;
@@ -187,14 +191,15 @@ bz2_fillbuffer(bz2_context *context,
bzstream = &context->bzstream;
if (bzstream->avail_in > 0)
- return 0;
+ return true;
count = input_stream_read(&context->istream,
- context->buffer, BZ_BUFSIZE);
+ context->buffer, BZ_BUFSIZE);
if (count == 0) {
if (bzstream->avail_out == numBytes)
- return -1;
+ return false;
+
if (!input_stream_eof(&context->istream))
context->last_parent_result = 1;
} else {
@@ -202,7 +207,7 @@ bz2_fillbuffer(bz2_context *context,
bzstream->avail_in = count;
}
- return 0;
+ return true;
}
static size_t
@@ -224,7 +229,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t size)
bzstream->avail_out = numBytes;
while (bzstream->avail_out != 0) {
- if (bz2_fillbuffer(context, numBytes) != 0)
+ if (!bz2_fillbuffer(context, numBytes))
break;
bz_result = BZ2_bzDecompress(bzstream);
diff --git a/src/archive/iso_plugin.c b/src/archive/iso_plugin.c
index 9063af0fc..b56653d56 100644
--- a/src/archive/iso_plugin.c
+++ b/src/archive/iso_plugin.c
@@ -21,6 +21,7 @@
* iso archive handling (requires cdio, and iso9660)
*/
+#include "config.h"
#include "archive_api.h"
#include "input_plugin.h"
diff --git a/src/archive/zip_plugin.c b/src/archive/zip_plugin.c
index 243d46418..95bc1d02b 100644
--- a/src/archive/zip_plugin.c
+++ b/src/archive/zip_plugin.c
@@ -21,6 +21,7 @@
* zip archive handling (requires zziplib)
*/
+#include "config.h"
#include "archive_api.h"
#include "archive_api.h"
#include "input_plugin.h"
@@ -160,7 +161,7 @@ zip_is_eof(struct input_stream *is)
static bool
zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
- G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
+ G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence)
{
zip_context *context = (zip_context *) is->data;
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
diff --git a/src/archive_api.c b/src/archive_api.c
index 153afa361..574960558 100644
--- a/src/archive_api.c
+++ b/src/archive_api.c
@@ -17,6 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h" /* must be first for large file support */
+#include "archive_api.h"
+
#include <stdio.h>
#include <string.h>
@@ -26,8 +29,6 @@
#include <errno.h>
#include <glib.h>
-#include "archive_api.h"
-
/**
*
* archive_lookup is used to determine if part of pathname refers to an regular
diff --git a/src/archive_api.h b/src/archive_api.h
index 2efcc1e6a..20a4f9277 100644
--- a/src/archive_api.h
+++ b/src/archive_api.h
@@ -27,72 +27,11 @@
*/
#include "archive_internal.h"
+#include "archive_plugin.h"
#include "input_stream.h"
#include <stdbool.h>
-struct archive_file;
-
-struct archive_plugin {
- const char *name;
-
- /**
- * optional, set this to NULL if the archive plugin doesn't
- * have/need one this must false if there is an error and
- * true otherwise
- */
- bool (*init)(void);
-
- /**
- * optional, set this to NULL if the archive plugin doesn't
- * have/need one
- */
- void (*finish)(void);
-
- /**
- * tryes to open archive file and associates handle with archive
- * returns pointer to handle used is all operations with this archive
- * or NULL when opening fails
- */
- struct archive_file *(*open)(char * pathname);
-
- /**
- * reset routine will move current read index in archive to default
- * position and then the filenames from archives can be read
- * via scan_next routine
- */
- void (*scan_reset)(struct archive_file *);
-
- /**
- * the read method will return corresponding files from archive
- * (as pathnames) and move read index to next file. When there is no
- * next file it return NULL.
- */
- char *(*scan_next)(struct archive_file *);
-
- /**
- * Opens an input_stream of a file within the archive.
- *
- * If this function succeeds, then the #input_stream "owns"
- * the archive file and will automatically close it.
- *
- * @param path the path within the archive
- */
- bool (*open_stream)(struct archive_file *, struct input_stream *is,
- const char *path);
-
- /**
- * closes archive file.
- */
- void (*close)(struct archive_file *);
-
- /**
- * suffixes handled by this plugin.
- * last element in these arrays must always be a NULL
- */
- const char *const*suffixes;
-};
-
bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix);
#endif
diff --git a/src/archive_list.c b/src/archive_list.c
index 8228fc961..0edbb305f 100644
--- a/src/archive_list.c
+++ b/src/archive_list.c
@@ -17,10 +17,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "archive_list.h"
-#include "archive_api.h"
+#include "archive_plugin.h"
#include "utils.h"
-#include "config.h"
#include <string.h>
#include <glib.h>
@@ -42,25 +42,20 @@ static const struct archive_plugin *const archive_plugins[] = {
NULL
};
-enum {
- num_archive_plugins = G_N_ELEMENTS(archive_plugins)-1,
-};
-
/** which plugins have been initialized successfully? */
-static bool archive_plugins_enabled[num_archive_plugins+1];
+static bool archive_plugins_enabled[G_N_ELEMENTS(archive_plugins) - 1];
const struct archive_plugin *
archive_plugin_from_suffix(const char *suffix)
{
- unsigned i;
-
if (suffix == NULL)
return NULL;
- for (i=0; i < num_archive_plugins; ++i) {
+ for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (archive_plugins_enabled[i] &&
- stringFoundInStringArray(plugin->suffixes, suffix)) {
+ plugin->suffixes != NULL &&
+ string_array_contains(plugin->suffixes, suffix)) {
++i;
return plugin;
}
@@ -71,7 +66,7 @@ archive_plugin_from_suffix(const char *suffix)
const struct archive_plugin *
archive_plugin_from_name(const char *name)
{
- for (unsigned i = 0; i < num_archive_plugins; ++i) {
+ for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (archive_plugins_enabled[i] &&
strcmp(plugin->name, name) == 0)
@@ -84,7 +79,7 @@ void archive_plugin_print_all_suffixes(FILE * fp)
{
const char *const*suffixes;
- for (unsigned i = 0; i < num_archive_plugins; ++i) {
+ for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (!archive_plugins_enabled[i])
continue;
@@ -101,7 +96,7 @@ void archive_plugin_print_all_suffixes(FILE * fp)
void archive_plugin_init_all(void)
{
- for (unsigned i = 0; i < num_archive_plugins; ++i) {
+ for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (plugin->init == NULL || archive_plugins[i]->init())
archive_plugins_enabled[i] = true;
@@ -110,7 +105,7 @@ void archive_plugin_init_all(void)
void archive_plugin_deinit_all(void)
{
- for (unsigned i = 0; i < num_archive_plugins; ++i) {
+ for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (archive_plugins_enabled[i] && plugin->finish != NULL)
archive_plugins[i]->finish();
diff --git a/src/archive_list.h b/src/archive_list.h
index 55278fbc4..2534b2b18 100644
--- a/src/archive_list.h
+++ b/src/archive_list.h
@@ -20,8 +20,6 @@
#ifndef MPD_ARCHIVE_LIST_H
#define MPD_ARCHIVE_LIST_H
-#include "archive_api.h"
-
#include <stdio.h>
struct archive_plugin;
diff --git a/src/archive_plugin.h b/src/archive_plugin.h
new file mode 100644
index 000000000..df2dcff47
--- /dev/null
+++ b/src/archive_plugin.h
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+#ifndef MPD_ARCHIVE_PLUGIN_H
+#define MPD_ARCHIVE_PLUGIN_H
+
+#include <stdbool.h>
+
+struct input_stream;
+struct archive_file;
+
+struct archive_plugin {
+ const char *name;
+
+ /**
+ * optional, set this to NULL if the archive plugin doesn't
+ * have/need one this must false if there is an error and
+ * true otherwise
+ */
+ bool (*init)(void);
+
+ /**
+ * optional, set this to NULL if the archive plugin doesn't
+ * have/need one
+ */
+ void (*finish)(void);
+
+ /**
+ * tryes to open archive file and associates handle with archive
+ * returns pointer to handle used is all operations with this archive
+ * or NULL when opening fails
+ */
+ struct archive_file *(*open)(char * pathname);
+
+ /**
+ * reset routine will move current read index in archive to default
+ * position and then the filenames from archives can be read
+ * via scan_next routine
+ */
+ void (*scan_reset)(struct archive_file *);
+
+ /**
+ * the read method will return corresponding files from archive
+ * (as pathnames) and move read index to next file. When there is no
+ * next file it return NULL.
+ */
+ char *(*scan_next)(struct archive_file *);
+
+ /**
+ * Opens an input_stream of a file within the archive.
+ *
+ * If this function succeeds, then the #input_stream "owns"
+ * the archive file and will automatically close it.
+ *
+ * @param path the path within the archive
+ */
+ bool (*open_stream)(struct archive_file *, struct input_stream *is,
+ const char *path);
+
+ /**
+ * closes archive file.
+ */
+ void (*close)(struct archive_file *);
+
+ /**
+ * suffixes handled by this plugin.
+ * last element in these arrays must always be a NULL
+ */
+ const char *const*suffixes;
+};
+
+#endif
+