aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/zzip_archive_plugin.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/archive/zzip_archive_plugin.c (renamed from src/archive/zip_plugin.c)104
1 files changed, 61 insertions, 43 deletions
diff --git a/src/archive/zip_plugin.c b/src/archive/zzip_archive_plugin.c
index 243d46418..43c880aab 100644
--- a/src/archive/zip_plugin.c
+++ b/src/archive/zzip_archive_plugin.c
@@ -21,6 +21,8 @@
* zip archive handling (requires zziplib)
*/
+#include "config.h"
+#include "archive/zzip_archive_plugin.h"
#include "archive_api.h"
#include "archive_api.h"
#include "input_plugin.h"
@@ -29,29 +31,40 @@
#include <glib.h>
#include <string.h>
-typedef struct {
+struct zzip_archive {
+ struct archive_file base;
+
ZZIP_DIR *dir;
ZZIP_FILE *file;
size_t length;
GSList *list;
GSList *iter;
-} zip_context;
+};
+
+static const struct input_plugin zzip_input_plugin;
-static const struct input_plugin zip_inputplugin;
+static inline GQuark
+zzip_quark(void)
+{
+ return g_quark_from_static_string("zzip");
+}
/* archive open && listing routine */
static struct archive_file *
-zip_open(char * pathname)
+zzip_archive_open(const char *pathname, GError **error_r)
{
- zip_context *context = g_malloc(sizeof(zip_context));
+ 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);
if (context->dir == NULL) {
- g_warning("zipfile %s open failed\n", pathname);
+ g_set_error(error_r, zzip_quark(), 0,
+ "Failed to open ZIP file %s", pathname);
return NULL;
}
@@ -63,21 +76,21 @@ zip_open(char * pathname)
}
}
- return (struct archive_file *)context;
+ return &context->base;
}
static void
-zip_scan_reset(struct archive_file *file)
+zzip_archive_scan_reset(struct archive_file *file)
{
- zip_context *context = (zip_context *) file;
+ struct zzip_archive *context = (struct zzip_archive *) file;
//reset iterator
context->iter = context->list;
}
static char *
-zip_scan_next(struct archive_file *file)
+zzip_archive_scan_next(struct archive_file *file)
{
- zip_context *context = (zip_context *) file;
+ struct zzip_archive *context = (struct zzip_archive *) file;
char *data = NULL;
if (context->iter != NULL) {
///fetch data and goto next
@@ -88,9 +101,9 @@ zip_scan_next(struct archive_file *file)
}
static void
-zip_close(struct archive_file *file)
+zzip_archive_close(struct archive_file *file)
{
- zip_context *context = (zip_context *) file;
+ struct zzip_archive *context = (struct zzip_archive *) file;
if (context->list) {
//free list
for (GSList *tmp = context->list; tmp != NULL; tmp = g_slist_next(tmp))
@@ -106,14 +119,14 @@ zip_close(struct archive_file *file)
/* single archive handling */
static bool
-zip_open_stream(struct archive_file *file, struct input_stream *is,
- const char *pathname)
+zzip_archive_open_stream(struct archive_file *file, struct input_stream *is,
+ const char *pathname, GError **error_r)
{
- zip_context *context = (zip_context *) file;
+ struct zzip_archive *context = (struct zzip_archive *) file;
ZZIP_STAT z_stat;
//setup file ops
- is->plugin = &zip_inputplugin;
+ is->plugin = &zzip_input_plugin;
//insert back reference
is->data = context;
//we are seekable (but its not recommendent to do so)
@@ -121,7 +134,8 @@ zip_open_stream(struct archive_file *file, struct input_stream *is,
context->file = zzip_file_open(context->dir, pathname, 0);
if (!context->file) {
- g_warning("file %s not found in the zipfile\n", pathname);
+ g_set_error(error_r, zzip_quark(), 0,
+ "not found in the ZIP file: %s", pathname);
return false;
}
zzip_file_stat(context->file, &z_stat);
@@ -130,41 +144,45 @@ zip_open_stream(struct archive_file *file, struct input_stream *is,
}
static void
-zip_is_close(struct input_stream *is)
+zzip_input_close(struct input_stream *is)
{
- zip_context *context = (zip_context *) is->data;
+ struct zzip_archive *context = (struct zzip_archive *) is->data;
zzip_file_close (context->file);
- zip_close((struct archive_file *)context);
+ zzip_archive_close((struct archive_file *)context);
}
static size_t
-zip_is_read(struct input_stream *is, void *ptr, size_t size)
+zzip_input_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
{
- zip_context *context = (zip_context *) is->data;
+ struct zzip_archive *context = (struct zzip_archive *) is->data;
int ret;
ret = zzip_file_read(context->file, ptr, size);
if (ret < 0) {
- g_warning("error %d reading zipfile\n", ret);
+ g_set_error(error_r, zzip_quark(), ret,
+ "zzip_file_read() has failed");
return 0;
}
return ret;
}
static bool
-zip_is_eof(struct input_stream *is)
+zzip_input_eof(struct input_stream *is)
{
- zip_context *context = (zip_context *) is->data;
+ struct zzip_archive *context = (struct zzip_archive *) is->data;
return ((size_t) zzip_tell(context->file) == context->length);
}
static bool
-zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
- G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
+zzip_input_seek(struct input_stream *is,
+ goffset offset, int whence, GError **error_r)
{
- zip_context *context = (zip_context *) is->data;
+ struct zzip_archive *context = (struct zzip_archive *) is->data;
zzip_off_t ofs = zzip_seek(context->file, offset, whence);
if (ofs != -1) {
+ g_set_error(error_r, zzip_quark(), ofs,
+ "zzip_seek() has failed");
is->offset = ofs;
return true;
}
@@ -173,24 +191,24 @@ zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
/* exported structures */
-static const char *const zip_extensions[] = {
+static const char *const zzip_archive_extensions[] = {
"zip",
NULL
};
-static const struct input_plugin zip_inputplugin = {
- .close = zip_is_close,
- .read = zip_is_read,
- .eof = zip_is_eof,
- .seek = zip_is_seek,
+static const struct input_plugin zzip_input_plugin = {
+ .close = zzip_input_close,
+ .read = zzip_input_read,
+ .eof = zzip_input_eof,
+ .seek = zzip_input_seek,
};
-const struct archive_plugin zip_plugin = {
- .name = "zip",
- .open = zip_open,
- .scan_reset = zip_scan_reset,
- .scan_next = zip_scan_next,
- .open_stream = zip_open_stream,
- .close = zip_close,
- .suffixes = zip_extensions
+const struct archive_plugin zzip_archive_plugin = {
+ .name = "zzip",
+ .open = zzip_archive_open,
+ .scan_reset = zzip_archive_scan_reset,
+ .scan_next = zzip_archive_scan_next,
+ .open_stream = zzip_archive_open_stream,
+ .close = zzip_archive_close,
+ .suffixes = zzip_archive_extensions
};