Commit 94fffb33 authored by Max Kellermann's avatar Max Kellermann

archive/*: convert to C++

parent dc2e64c9
......@@ -130,14 +130,6 @@ mpd_headers = \
src/string_util.h \
src/zeroconf.h src/zeroconf-internal.h \
src/timer.h \
src/archive_api.h \
src/archive_internal.h \
src/archive_list.h \
src/archive_plugin.h \
src/archive/bz2_archive_plugin.h \
src/archive/iso9660_archive_plugin.h \
src/archive/zzip_archive_plugin.h \
src/input/archive_input_plugin.h \
src/mpd_error.h
src_mpd_SOURCES = \
......@@ -414,10 +406,11 @@ src_mpd_SOURCES += \
src/UpdateArchive.cxx src/UpdateArchive.hxx
libarchive_a_SOURCES = \
src/archive_api.c \
src/archive_list.c \
src/archive_plugin.c \
src/input/archive_input_plugin.c
src/ArchiveLookup.cxx src/ArchiveLookup.hxx \
src/ArchiveList.cxx src/ArchiveList.hxx \
src/ArchivePlugin.cxx src/ArchivePlugin.hxx \
src/ArchiveInternal.hxx \
src/input/ArchiveInputPlugin.cxx src/input/ArchiveInputPlugin.hxx
libarchive_a_CPPFLAGS = $(AM_CPPFLAGS) \
$(BZ2_CFLAGS) \
$(ISO9660_CFLAGS) \
......@@ -430,15 +423,21 @@ ARCHIVE_LIBS = \
$(ZZIP_LIBS)
if HAVE_BZ2
libarchive_a_SOURCES += src/archive/bz2_archive_plugin.c
libarchive_a_SOURCES += \
src/archive/Bzip2ArchivePlugin.cxx \
src/archive/Bzip2ArchivePlugin.hxx
endif
if HAVE_ZZIP
libarchive_a_SOURCES += src/archive/zzip_archive_plugin.c
libarchive_a_SOURCES += \
src/archive/ZzipArchivePlugin.cxx \
src/archive/ZzipArchivePlugin.hxx
endif
if HAVE_ISO9660
libarchive_a_SOURCES += src/archive/iso9660_archive_plugin.c
libarchive_a_SOURCES += \
src/archive/Iso9660ArchivePlugin.cxx \
src/archive/Iso9660ArchivePlugin.hxx
endif
else
......
/*
* 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_INTERNAL_H
#define MPD_ARCHIVE_INTERNAL_H
#ifndef MPD_ARCHIVE_INTERNAL_HXX
#define MPD_ARCHIVE_INTERNAL_HXX
struct archive_file {
const struct archive_plugin *plugin;
......
/*
* 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
......@@ -18,12 +18,12 @@
*/
#include "config.h"
#include "archive_list.h"
#include "archive_plugin.h"
#include "ArchiveList.hxx"
#include "ArchivePlugin.hxx"
#include "string_util.h"
#include "archive/bz2_archive_plugin.h"
#include "archive/iso9660_archive_plugin.h"
#include "archive/zzip_archive_plugin.h"
#include "archive/Bzip2ArchivePlugin.hxx"
#include "archive/Iso9660ArchivePlugin.hxx"
#include "archive/ZzipArchivePlugin.hxx"
#include <string.h>
#include <glib.h>
......
/*
* 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_LIST_H
#define MPD_ARCHIVE_LIST_H
#ifndef MPD_ARCHIVE_LIST_HXX
#define MPD_ARCHIVE_LIST_HXX
struct archive_plugin;
......
/*
* 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
......@@ -18,7 +18,7 @@
*/
#include "config.h" /* must be first for large file support */
#include "archive_api.h"
#include "ArchiveLookup.hxx"
#include <stdio.h>
......
/*
* 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_API_H
#define MPD_ARCHIVE_API_H
#ifndef MPD_ARCHIVE_LOOKUP_HXX
#define MPD_ARCHIVE_LOOKUP_HXX
/*
* This is the public API which is used by archive plugins to
......@@ -26,12 +26,6 @@
*
*/
#include "archive_internal.h"
#include "archive_plugin.h"
#include "input_stream.h"
#include <stdbool.h>
bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix);
#endif
......
/*
* 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.
*/
#include "archive_plugin.h"
#include "archive_internal.h"
#include "ArchivePlugin.hxx"
#include "ArchiveInternal.hxx"
#include <assert.h>
......
/*
* 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,13 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ARCHIVE_PLUGIN_H
#define MPD_ARCHIVE_PLUGIN_H
#ifndef MPD_ARCHIVE_PLUGIN_HXX
#define MPD_ARCHIVE_PLUGIN_HXX
#include <glib.h>
#include <stdbool.h>
struct input_stream;
struct archive_file;
......
......@@ -39,8 +39,8 @@
#endif
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
#include "archive_plugin.h"
#include "ArchiveList.hxx"
#include "ArchivePlugin.hxx"
#endif
#include <glib.h>
......
......@@ -22,7 +22,7 @@
#include "input/FileInputPlugin.hxx"
#ifdef ENABLE_ARCHIVE
#include "input/archive_input_plugin.h"
#include "input/ArchiveInputPlugin.hxx"
#endif
#ifdef ENABLE_CURL
......
......@@ -69,11 +69,9 @@ extern "C" {
#include "StickerDatabase.hxx"
#endif
extern "C" {
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
#include "ArchiveList.hxx"
#endif
}
#include <glib.h>
......
......@@ -25,11 +25,8 @@
#include "song.h"
#include "Mapper.hxx"
#include "fs/Path.hxx"
extern "C" {
#include "archive_list.h"
#include "archive_plugin.h"
}
#include "ArchiveList.hxx"
#include "ArchivePlugin.hxx"
#include <glib.h>
......
/*
* 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,
};
/*
* 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;
......
/*
* 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,
};
/*
* 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;
......
/*
* 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,
};
/*
* 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;
......
/*
* 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
......@@ -18,9 +18,10 @@
*/
#include "config.h"
#include "input/archive_input_plugin.h"
#include "archive_api.h"
#include "archive_list.h"
#include "ArchiveInputPlugin.hxx"
#include "ArchiveLookup.hxx"
#include "ArchiveList.hxx"
#include "ArchivePlugin.hxx"
#include "input_plugin.h"
#include <glib.h>
......@@ -78,6 +79,16 @@ input_archive_open(const char *pathname,
}
const struct input_plugin input_plugin_archive = {
.name = "archive",
.open = input_archive_open,
"archive",
nullptr,
nullptr,
input_archive_open,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
};
/*
* 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_INPUT_ARCHIVE_H
#define MPD_INPUT_ARCHIVE_H
#ifndef MPD_INPUT_ARCHIVE_HXX
#define MPD_INPUT_ARCHIVE_HXX
extern const struct input_plugin input_plugin_archive;
......
......@@ -26,11 +26,11 @@
extern "C" {
#include "text_input_stream.h"
}
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
#include "ArchiveList.hxx"
#endif
}
#include <glib.h>
......
......@@ -26,11 +26,9 @@
#include "InputInit.hxx"
#include "IOThread.hxx"
extern "C" {
#ifdef ENABLE_ARCHIVE
#include "archive_list.h"
#include "ArchiveList.hxx"
#endif
}
#include <glib.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment