archive/*: convert to C++
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,8 +22,9 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "archive/bz2_archive_plugin.h"
|
||||
#include "archive_api.h"
|
||||
#include "Bzip2ArchivePlugin.hxx"
|
||||
#include "ArchiveInternal.hxx"
|
||||
#include "ArchivePlugin.hxx"
|
||||
#include "input_internal.h"
|
||||
#include "input_plugin.h"
|
||||
#include "refcount.h"
|
||||
@@ -47,6 +48,21 @@ struct bz2_archive_file {
|
||||
char *name;
|
||||
bool reset;
|
||||
struct input_stream *istream;
|
||||
|
||||
bz2_archive_file() {
|
||||
archive_file_init(&base, &bz2_archive_plugin);
|
||||
refcount_init(&ref);
|
||||
}
|
||||
|
||||
void Unref() {
|
||||
if (!refcount_dec(&ref))
|
||||
return;
|
||||
|
||||
g_free(name);
|
||||
|
||||
input_stream_close(istream);
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
||||
struct bz2_input_stream {
|
||||
@@ -61,7 +77,7 @@ struct bz2_input_stream {
|
||||
char buffer[5000];
|
||||
};
|
||||
|
||||
static const struct input_plugin bz2_inputplugin;
|
||||
extern const struct input_plugin bz2_inputplugin;
|
||||
|
||||
static inline GQuark
|
||||
bz2_quark(void)
|
||||
@@ -80,7 +96,7 @@ bz2_alloc(struct bz2_input_stream *data, GError **error_r)
|
||||
data->bzstream.bzfree = NULL;
|
||||
data->bzstream.opaque = NULL;
|
||||
|
||||
data->bzstream.next_in = (void *) data->buffer;
|
||||
data->bzstream.next_in = (char *) data->buffer;
|
||||
data->bzstream.avail_in = 0;
|
||||
|
||||
ret = BZ2_bzDecompressInit(&data->bzstream, 0, 0);
|
||||
@@ -111,13 +127,9 @@ bz2_destroy(struct bz2_input_stream *data)
|
||||
static struct archive_file *
|
||||
bz2_open(const char *pathname, GError **error_r)
|
||||
{
|
||||
struct bz2_archive_file *context;
|
||||
struct bz2_archive_file *context = new bz2_archive_file();
|
||||
int len;
|
||||
|
||||
context = g_malloc(sizeof(*context));
|
||||
archive_file_init(&context->base, &bz2_archive_plugin);
|
||||
refcount_init(&context->ref);
|
||||
|
||||
//open archive
|
||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||
context->istream = input_stream_open(pathname,
|
||||
@@ -125,7 +137,7 @@ bz2_open(const char *pathname, GError **error_r)
|
||||
NULL,
|
||||
error_r);
|
||||
if (context->istream == NULL) {
|
||||
g_free(context);
|
||||
delete context;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -166,13 +178,7 @@ bz2_close(struct archive_file *file)
|
||||
{
|
||||
struct bz2_archive_file *context = (struct bz2_archive_file *) file;
|
||||
|
||||
if (!refcount_dec(&context->ref))
|
||||
return;
|
||||
|
||||
g_free(context->name);
|
||||
|
||||
input_stream_close(context->istream);
|
||||
g_free(context);
|
||||
context->Unref();
|
||||
}
|
||||
|
||||
/* single archive handling */
|
||||
@@ -254,7 +260,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length,
|
||||
return 0;
|
||||
|
||||
bzstream = &bis->bzstream;
|
||||
bzstream->next_out = ptr;
|
||||
bzstream->next_out = (char *)ptr;
|
||||
bzstream->avail_out = length;
|
||||
|
||||
do {
|
||||
@@ -296,19 +302,30 @@ static const char *const bz2_extensions[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct input_plugin bz2_inputplugin = {
|
||||
.close = bz2_is_close,
|
||||
.read = bz2_is_read,
|
||||
.eof = bz2_is_eof,
|
||||
const struct input_plugin bz2_inputplugin = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
bz2_is_close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
bz2_is_read,
|
||||
bz2_is_eof,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
const struct archive_plugin bz2_archive_plugin = {
|
||||
.name = "bz2",
|
||||
.open = bz2_open,
|
||||
.scan_reset = bz2_scan_reset,
|
||||
.scan_next = bz2_scan_next,
|
||||
.open_stream = bz2_open_stream,
|
||||
.close = bz2_close,
|
||||
.suffixes = bz2_extensions
|
||||
"bz2",
|
||||
nullptr,
|
||||
nullptr,
|
||||
bz2_open,
|
||||
bz2_scan_reset,
|
||||
bz2_scan_next,
|
||||
bz2_open_stream,
|
||||
bz2_close,
|
||||
bz2_extensions,
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -17,8 +17,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_ARCHIVE_BZ2_H
|
||||
#define MPD_ARCHIVE_BZ2_H
|
||||
#ifndef MPD_ARCHIVE_BZ2_HXX
|
||||
#define MPD_ARCHIVE_BZ2_HXX
|
||||
|
||||
extern const struct archive_plugin bz2_archive_plugin;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,8 +22,9 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "archive/iso9660_archive_plugin.h"
|
||||
#include "archive_api.h"
|
||||
#include "Iso9660ArchivePlugin.hxx"
|
||||
#include "ArchiveInternal.hxx"
|
||||
#include "ArchivePlugin.hxx"
|
||||
#include "input_internal.h"
|
||||
#include "input_plugin.h"
|
||||
#include "refcount.h"
|
||||
@@ -46,7 +47,7 @@ struct iso9660_archive_file {
|
||||
GSList *iter;
|
||||
};
|
||||
|
||||
static const struct input_plugin iso9660_input_plugin;
|
||||
extern const struct input_plugin iso9660_input_plugin;
|
||||
|
||||
static inline GQuark
|
||||
iso9660_quark(void)
|
||||
@@ -76,7 +77,7 @@ listdir_recur(const char *psz_path, struct iso9660_archive_file *context)
|
||||
strcpy(pathname, psz_path);
|
||||
strcat(pathname, statbuf->filename);
|
||||
|
||||
if (_STAT_DIR == statbuf->type ) {
|
||||
if (iso9660_stat_s::_STAT_DIR == statbuf->type ) {
|
||||
if (strcmp(statbuf->filename, ".") && strcmp(statbuf->filename, "..")) {
|
||||
strcat(pathname, "/");
|
||||
listdir_recur(pathname, context);
|
||||
@@ -133,7 +134,7 @@ iso9660_archive_scan_next(struct archive_file *file)
|
||||
char *data = NULL;
|
||||
if (context->iter != NULL) {
|
||||
///fetch data and goto next
|
||||
data = context->iter->data;
|
||||
data = (char *)context->iter->data;
|
||||
context->iter = g_slist_next(context->iter);
|
||||
}
|
||||
return data;
|
||||
@@ -273,18 +274,29 @@ static const char *const iso9660_archive_extensions[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct input_plugin iso9660_input_plugin = {
|
||||
.close = iso9660_input_close,
|
||||
.read = iso9660_input_read,
|
||||
.eof = iso9660_input_eof,
|
||||
const struct input_plugin iso9660_input_plugin = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
iso9660_input_close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
iso9660_input_read,
|
||||
iso9660_input_eof,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
const struct archive_plugin iso9660_archive_plugin = {
|
||||
.name = "iso",
|
||||
.open = iso9660_archive_open,
|
||||
.scan_reset = iso9660_archive_scan_reset,
|
||||
.scan_next = iso9660_archive_scan_next,
|
||||
.open_stream = iso9660_archive_open_stream,
|
||||
.close = iso9660_archive_close,
|
||||
.suffixes = iso9660_archive_extensions
|
||||
"iso",
|
||||
nullptr,
|
||||
nullptr,
|
||||
iso9660_archive_open,
|
||||
iso9660_archive_scan_reset,
|
||||
iso9660_archive_scan_next,
|
||||
iso9660_archive_open_stream,
|
||||
iso9660_archive_close,
|
||||
iso9660_archive_extensions,
|
||||
};
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -17,8 +17,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_ARCHIVE_ISO9660_H
|
||||
#define MPD_ARCHIVE_ISO9660_H
|
||||
#ifndef MPD_ARCHIVE_ISO9660_HXX
|
||||
#define MPD_ARCHIVE_ISO9660_HXX
|
||||
|
||||
extern const struct archive_plugin iso9660_archive_plugin;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,9 +22,9 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "archive/zzip_archive_plugin.h"
|
||||
#include "archive_api.h"
|
||||
#include "archive_api.h"
|
||||
#include "ZzipArchivePlugin.hxx"
|
||||
#include "ArchiveInternal.hxx"
|
||||
#include "ArchivePlugin.hxx"
|
||||
#include "input_internal.h"
|
||||
#include "input_plugin.h"
|
||||
#include "refcount.h"
|
||||
@@ -41,9 +41,30 @@ struct zzip_archive {
|
||||
ZZIP_DIR *dir;
|
||||
GSList *list;
|
||||
GSList *iter;
|
||||
|
||||
zzip_archive() {
|
||||
archive_file_init(&base, &zzip_archive_plugin);
|
||||
refcount_init(&ref);
|
||||
}
|
||||
|
||||
void Unref() {
|
||||
if (!refcount_dec(&ref))
|
||||
return;
|
||||
|
||||
if (list) {
|
||||
//free list
|
||||
for (GSList *tmp = list; tmp != NULL; tmp = g_slist_next(tmp))
|
||||
g_free(tmp->data);
|
||||
g_slist_free(list);
|
||||
}
|
||||
//close archive
|
||||
zzip_dir_close (dir);
|
||||
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
||||
static const struct input_plugin zzip_input_plugin;
|
||||
extern const struct input_plugin zzip_input_plugin;
|
||||
|
||||
static inline GQuark
|
||||
zzip_quark(void)
|
||||
@@ -56,12 +77,9 @@ zzip_quark(void)
|
||||
static struct archive_file *
|
||||
zzip_archive_open(const char *pathname, GError **error_r)
|
||||
{
|
||||
struct zzip_archive *context = g_malloc(sizeof(*context));
|
||||
struct zzip_archive *context = new zzip_archive();
|
||||
ZZIP_DIRENT dirent;
|
||||
|
||||
archive_file_init(&context->base, &zzip_archive_plugin);
|
||||
refcount_init(&context->ref);
|
||||
|
||||
// open archive
|
||||
context->list = NULL;
|
||||
context->dir = zzip_dir_open(pathname, NULL);
|
||||
@@ -97,7 +115,7 @@ zzip_archive_scan_next(struct archive_file *file)
|
||||
char *data = NULL;
|
||||
if (context->iter != NULL) {
|
||||
///fetch data and goto next
|
||||
data = context->iter->data;
|
||||
data = (char *)context->iter->data;
|
||||
context->iter = g_slist_next(context->iter);
|
||||
}
|
||||
return data;
|
||||
@@ -108,19 +126,7 @@ zzip_archive_close(struct archive_file *file)
|
||||
{
|
||||
struct zzip_archive *context = (struct zzip_archive *) file;
|
||||
|
||||
if (!refcount_dec(&context->ref))
|
||||
return;
|
||||
|
||||
if (context->list) {
|
||||
//free list
|
||||
for (GSList *tmp = context->list; tmp != NULL; tmp = g_slist_next(tmp))
|
||||
g_free(tmp->data);
|
||||
g_slist_free(context->list);
|
||||
}
|
||||
//close archive
|
||||
zzip_dir_close (context->dir);
|
||||
|
||||
g_free(context);
|
||||
context->Unref();
|
||||
}
|
||||
|
||||
/* single archive handling */
|
||||
@@ -228,19 +234,29 @@ static const char *const zzip_archive_extensions[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
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 input_plugin zzip_input_plugin = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
zzip_input_close,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
zzip_input_read,
|
||||
zzip_input_eof,
|
||||
zzip_input_seek,
|
||||
};
|
||||
|
||||
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
|
||||
"zzip",
|
||||
nullptr,
|
||||
nullptr,
|
||||
zzip_archive_open,
|
||||
zzip_archive_scan_reset,
|
||||
zzip_archive_scan_next,
|
||||
zzip_archive_open_stream,
|
||||
zzip_archive_close,
|
||||
zzip_archive_extensions,
|
||||
};
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
||||
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -17,8 +17,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_ARCHIVE_ZZIP_H
|
||||
#define MPD_ARCHIVE_ZZIP_H
|
||||
#ifndef MPD_ARCHIVE_ZZIP_HXX
|
||||
#define MPD_ARCHIVE_ZZIP_HXX
|
||||
|
||||
extern const struct archive_plugin zzip_archive_plugin;
|
||||
|
Reference in New Issue
Block a user