Skip to content
Snippets Groups Projects
Commit 7dd8826c authored by Aline Gondim Santos's avatar Aline Gondim Santos
Browse files

plugins: use minizip instead of libarchive

GitLab: #525
Change-Id: I7de174626bbb97c40ac58ceea9d99d9fe8b95bd9
parent 451854b2
Branches
Tags
No related merge requests found
...@@ -465,7 +465,11 @@ AS_IF([test "x$enable_plugin" != "xno"], ...@@ -465,7 +465,11 @@ AS_IF([test "x$enable_plugin" != "xno"],
AS_IF([test "$SYS" = linux], AS_IF([test "$SYS" = linux],
[PKG_CHECK_MODULES([ARCHIVE], [libarchive >= 3.0],, [PKG_CHECK_MODULES([ARCHIVE], [libarchive >= 3.0],,
AC_MSG_ERROR([libarchive not found]))], AC_MSG_ERROR([libarchive not found]))],
[])], [AS_IF([test "$SYS" = darwin],
[PKG_CHECK_MODULES([MINIZIP], [minizip >= 3.0.0],,
AC_MSG_ERROR([libminizip not found]))],
[])]
)],
[AM_CONDITIONAL(ENABLE_PLUGIN, false)]); [AM_CONDITIONAL(ENABLE_PLUGIN, false)]);
dnl Video is default-enabled dnl Video is default-enabled
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
LIBARCHIVE_VERSION := 3.4.0 LIBARCHIVE_VERSION := 3.4.0
LIBARCHIVE_URL := https://github.com/libarchive/libarchive/releases/download/v$(LIBARCHIVE_VERSION)/libarchive-$(LIBARCHIVE_VERSION).tar.gz LIBARCHIVE_URL := https://github.com/libarchive/libarchive/releases/download/v$(LIBARCHIVE_VERSION)/libarchive-$(LIBARCHIVE_VERSION).tar.gz
ifndef HAVE_MACOSX
PKGS += libarchive PKGS += libarchive
ifeq ($(call need_pkg,"libarchive >= 3.4.0"),) ifeq ($(call need_pkg,"libarchive >= 3.4.0"),)
PKGS_FOUND += libarchive PKGS_FOUND += libarchive
else else
DEPS_libarchive += nettle DEPS_libarchive += nettle
endif endif
endif
LIBARCHIVE_CMAKECONF := \ LIBARCHIVE_CMAKECONF := \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
......
98c9bdcea79a88a2dd69cec6c49f8565edf78ab9cddbf0e85e08b049b300b187f176bf57d5a894bf777bec0a097e46ecc05f78dab9cd5726fd473ffd8718dce0 minizip-ng-3.0.1.tar.gz
4281095bf642ae0839b0253ccb2de59262f72f2671ec13f3a2d3c144dd5bce3d7105128b79e472d65f3c6621fa715668c29f2af8b6e2a7e8ebaa1e8ea4c00cab minizip-ng-3.0.0.tar.gz
{
"name": "minizip",
"version": "3.0.0",
"url": "https://github.com/zlib-ng/minizip-ng/archive/refs/tags/__VERSION__.tar.gz",
"deps": ["zlib", "iconv"],
"patches": [],
"win_patches": [],
"project_paths": [],
"with_env" : "",
"custom_scripts": {
"pre_build": [
"mkdir build"
],
"build": [
"cmake -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib -S . -B ./build",
"cmake --build ./build --config Release --target install"
],
"post_build": []
}
}
# MINIZIP
LIBMINIZIP_VERSION := 3.0.0
LIBMINIZIP_URL := https://github.com/zlib-ng/minizip-ng/archive/refs/tags/$(LIBMINIZIP_VERSION).tar.gz
ifdef HAVE_MACOSX
PKGS += minizip
ifeq ($(call need_pkg,"minizip >= 3.0.0"),)
PKGS_FOUND += minizip
endif
endif
DEPS_minizip = zlib iconv
LIBMINIZIP_CMAKECONF := \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
-DMZ_FORCE_FETCH_LIBS=ON \
-DMZ_FETCH_LIBS=ON
$(TARBALLS)/minizip-ng-$(LIBMINIZIP_VERSION).tar.gz:
$(call download,$(LIBMINIZIP_URL))
.sum-minizip: minizip-ng-$(LIBMINIZIP_VERSION).tar.gz
minizip: minizip-ng-$(LIBMINIZIP_VERSION).tar.gz
$(UNPACK)
$(MOVE)
.minizip: minizip toolchain.cmake .sum-minizip
cd $< && mkdir -p buildlib
ifdef HAVE_ANDROID
cd $< && cp -R contrib/android/include/* $(PREFIX)/include
endif
cd $< && cd buildlib && $(HOSTVARS) $(CMAKE) .. $(LIBMINIZIP_CMAKECONF)
cd $< && cd buildlib && $(MAKE) install
cd $< && rm -r buildlib
touch $@
...@@ -84,9 +84,14 @@ libring_la_LDFLAGS = \ ...@@ -84,9 +84,14 @@ libring_la_LDFLAGS = \
$(AM_LDFLAGS) $(AM_LDFLAGS)
if ENABLE_PLUGIN if ENABLE_PLUGIN
if HAVE_OSX
libring_la_LDFLAGS += \
@MINIZIP_LIBS@
else
libring_la_LDFLAGS += \ libring_la_LDFLAGS += \
@ARCHIVE_LIBS@ @ARCHIVE_LIBS@
endif endif
endif
if HAVE_WIN32 if HAVE_WIN32
......
...@@ -34,8 +34,17 @@ ...@@ -34,8 +34,17 @@
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN
extern "C" { extern "C" {
#if defined(__APPLE__)
#include <mz.h>
#include <mz_strm.h>
#include <mz_strm_os.h>
#include <mz_zip.h>
#include <mz_zip_rw.h>
#include <filesystem>
#else
#include <archive.h> #include <archive.h>
#include <archive_entry.h> #include <archive_entry.h>
#endif
} }
#endif #endif
...@@ -207,6 +216,7 @@ openGzip(const std::string& path, const char* mode) ...@@ -207,6 +216,7 @@ openGzip(const std::string& path, const char* mode)
} }
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN
#if !defined(__APPLE__)
// LIBARCHIVE DEFINITIONS // LIBARCHIVE DEFINITIONS
//========================== //==========================
using ArchivePtr = std::unique_ptr<archive, void (*)(archive*)>; using ArchivePtr = std::unique_ptr<archive, void (*)(archive*)>;
...@@ -249,40 +259,67 @@ createArchiveDiskWriter() ...@@ -249,40 +259,67 @@ createArchiveDiskWriter()
archive_write_free(a); archive_write_free(a);
}}; }};
} }
#endif
//========================== //==========================
#endif
#endif
std::vector<std::string> void
listArchiveContent(const std::string& archivePath) uncompressArchive(const std::string& archivePath, const std::string& dir, const FileMatchPair& f)
{ {
std::vector<std::string> fileNames;
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN
ArchivePtr archiveReader = createArchiveReader(); #if defined(__APPLE__)
struct archive_entry* entry; void* zip_handle = NULL;
int r; mz_zip_file* info = NULL;
// Set reader formats(archive) and filters(compression) fileutils::check_dir(dir.c_str());
archive_read_support_filter_all(archiveReader.get());
archive_read_support_format_all(archiveReader.get());
// Try to read the archive mz_zip_create(&zip_handle);
if ((r = archive_read_open_filename(archiveReader.get(), archivePath.c_str(), 10240))) { auto status = mz_zip_reader_open_file(zip_handle, archivePath.c_str());
throw std::runtime_error(archive_error_string(archiveReader.get())); status |= mz_zip_reader_goto_first_entry(zip_handle);
}
while (archive_read_next_header(archiveReader.get(), &entry) == ARCHIVE_OK) { while (status == MZ_OK) {
std::string fileEntry = archive_entry_pathname(entry) ? archive_entry_pathname(entry) status |= mz_zip_reader_entry_get_info(zip_handle, &info);
: "Undefined"; if (status != MZ_OK) {
fileNames.push_back(fileEntry); fileutils::removeAll(dir, true);
break;
} }
#endif std::string filename(info->filename, (size_t)info->filename_size);
return fileNames; const auto& fileMatchPair = f(filename);
if (fileMatchPair.first) {
auto filePath = dir + DIR_SEPARATOR_STR + fileMatchPair.second;
std::filesystem::path directory(filePath);
directory = directory.remove_filename();
if (!std::filesystem::exists(directory))
fileutils::check_dir(directory.c_str());
mz_zip_reader_entry_open(zip_handle);
void* buffStream = NULL;
buffStream = mz_stream_os_create(&buffStream);
if (mz_stream_os_open(buffStream, filePath.c_str(), MZ_OPEN_MODE_WRITE | MZ_OPEN_MODE_CREATE) == MZ_OK) {
int chunkSize = 8192;
std::vector<uint8_t> fileContent;
fileContent.resize(chunkSize);
while (auto ret = mz_zip_reader_entry_read(zip_handle, (void*) fileContent.data(), chunkSize)) {
ret = mz_stream_os_write(buffStream, (void*) fileContent.data(), ret);
if (ret < 0) {
fileutils::removeAll(dir, true);
status = 1;
}
}
mz_stream_os_close(buffStream);
mz_stream_os_delete(&buffStream);
} else {
fileutils::removeAll(dir, true);
status = 1;
}
mz_zip_reader_entry_close(zip_handle);
}
status |= mz_zip_reader_goto_next_entry(zip_handle);
} }
void mz_zip_reader_close(zip_handle);
uncompressArchive(const std::string& archivePath, const std::string& dir, const FileMatchPair& f) mz_zip_delete(&zip_handle);
{
#ifdef ENABLE_PLUGIN #else
int r; int r;
ArchivePtr archiveReader = createArchiveReader(); ArchivePtr archiveReader = createArchiveReader();
...@@ -360,6 +397,7 @@ uncompressArchive(const std::string& archivePath, const std::string& dir, const ...@@ -360,6 +397,7 @@ uncompressArchive(const std::string& archivePath, const std::string& dir, const
} }
} }
#endif #endif
#endif
} }
std::vector<uint8_t> std::vector<uint8_t>
...@@ -367,6 +405,33 @@ readFileFromArchive(const std::string& archivePath, const std::string& fileRelat ...@@ -367,6 +405,33 @@ readFileFromArchive(const std::string& archivePath, const std::string& fileRelat
{ {
std::vector<uint8_t> fileContent; std::vector<uint8_t> fileContent;
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN
#if defined(__APPLE__)
void* zip_handle = NULL;
mz_zip_file* info;
mz_zip_create(&zip_handle);
auto status = mz_zip_reader_open_file(zip_handle, archivePath.c_str());
status |= mz_zip_reader_goto_first_entry(zip_handle);
while (status == MZ_OK) {
status = mz_zip_reader_entry_get_info(zip_handle, &info);
if (status != MZ_OK)
break;
std::string_view filename(info->filename, (size_t)info->filename_size);
if (filename == fileRelativePathName) {
mz_zip_reader_entry_open(zip_handle);
fileContent.resize(info->uncompressed_size);
mz_zip_reader_entry_read(zip_handle, (void*) fileContent.data(), info->uncompressed_size);
mz_zip_reader_entry_close(zip_handle);
status = -1;
} else {
status = mz_zip_reader_goto_next_entry(zip_handle);
}
}
mz_zip_reader_close(zip_handle);
mz_zip_delete(&zip_handle);
#else
long r; long r;
ArchivePtr archiveReader = createArchiveReader(); ArchivePtr archiveReader = createArchiveReader();
struct archive_entry* entry; struct archive_entry* entry;
...@@ -422,6 +487,7 @@ readFileFromArchive(const std::string& archivePath, const std::string& fileRelat ...@@ -422,6 +487,7 @@ readFileFromArchive(const std::string& archivePath, const std::string& fileRelat
} }
} }
throw std::runtime_error("File " + fileRelativePathName + " not found in the archive"); throw std::runtime_error("File " + fileRelativePathName + " not found in the archive");
#endif
#endif #endif
return fileContent; return fileContent;
} }
......
...@@ -68,13 +68,6 @@ std::vector<uint8_t> decompressGzip(const std::string& path); ...@@ -68,13 +68,6 @@ std::vector<uint8_t> decompressGzip(const std::string& path);
*/ */
gzFile openGzip(const std::string& path, const char* mode); gzFile openGzip(const std::string& path, const char* mode);
/**
* @brief listArchiveContent
* @param archivePath
* @return list of relative file path names
*/
std::vector<std::string> listArchiveContent(const std::string& archivePath);
/** /**
* @brief uncompressArchive Uncompresses an archive and puts the different files * @brief uncompressArchive Uncompresses an archive and puts the different files
* in dir folder according to a FileMatchPair f * in dir folder according to a FileMatchPair f
......
...@@ -24,9 +24,6 @@ libplugin_la_SOURCES = \ ...@@ -24,9 +24,6 @@ libplugin_la_SOURCES = \
chatservicesmanager.cpp \ chatservicesmanager.cpp \
callservicesmanager.cpp callservicesmanager.cpp
libplugin_la_LIBADD = @ARCHIVE_LIBS@
libplugin_la_CXXFLAGS = \ libplugin_la_CXXFLAGS = \
-I./ \ -I./ \
-I../ \ -I../ \
......
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
#include "preferences.h" #include "preferences.h"
#include "dring/plugin_manager_interface.h" #include "dring/plugin_manager_interface.h"
extern "C" {
#include <archive.h>
}
#define PLUGIN_ALREADY_INSTALLED 100 /* Plugin already installed with the same version */ #define PLUGIN_ALREADY_INSTALLED 100 /* Plugin already installed with the same version */
#define PLUGIN_OLD_VERSION 200 /* Plugin already installed with a newer version */ #define PLUGIN_OLD_VERSION 200 /* Plugin already installed with a newer version */
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
* @return 0 if success * @return 0 if success
* 100 if already installed with similar version * 100 if already installed with similar version
* 200 if already installed with newer version * 200 if already installed with newer version
* libarchive error codes otherwise * libarchive (mizip in apple platforms) error codes otherwise
*/ */
int installPlugin(const std::string& jplPath, bool force); int installPlugin(const std::string& jplPath, bool force);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment