From 53ee3e2e722eeac80a16dc4fcf15dc6c34e1e099 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 13 Sep 2016 16:14:08 +0200 Subject: Add support for built-in file/url unzip/untar This introduces new build-dependency: libarchive (http://www.libarchive.org/) --- libs/pbd/pbd/file_archive.h | 138 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 libs/pbd/pbd/file_archive.h (limited to 'libs/pbd/pbd') diff --git a/libs/pbd/pbd/file_archive.h b/libs/pbd/pbd/file_archive.h new file mode 100644 index 0000000000..ad1f85941f --- /dev/null +++ b/libs/pbd/pbd/file_archive.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2016 Robin Gareus + * + * 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 _pbd_archive_h_ +#define _pbd_archive_h_ + +#include + +#include "pbd/signals.h" + +#ifndef LIBPBD_API +#include "pbd/libpbd_visibility.h" +#endif + + +namespace PBD { + +class LIBPBD_API FileArchive +{ + public: + FileArchive (const std::string& url); + + int inflate (const std::string& destdir); + std::vector contents (); + + //PBD::Signal2 progress; // TODO + + struct MemPipe { + public: + MemPipe () + : data (NULL) + , size (0) + , done (false) + { + pthread_mutex_init (&_lock, NULL); + pthread_cond_init (&_ready, NULL); + } + + ~MemPipe () + { + lock (); + free (data); + unlock (); + + pthread_mutex_destroy (&_lock); + pthread_cond_destroy (&_ready); + } + + void reset () + { + lock (); + free (data); + data = 0; + size = 0; + done = false; + unlock (); + } + + void lock () { pthread_mutex_lock (&_lock); } + void unlock () { pthread_mutex_unlock (&_lock); } + void signal () { pthread_cond_signal (&_ready); } + void wait () { pthread_cond_wait (&_ready, &_lock); } + + uint8_t buf[8192]; + uint8_t* data; + size_t size; + bool done; + + private: + pthread_mutex_t _lock; + pthread_cond_t _ready; + }; + + struct Request { + public: + Request (const std::string& u) + { + if (u.size () > 0) { + url = strdup (u.c_str()); + } else { + url = NULL; + } + } + + ~Request () + { + free (url); + } + + bool is_remote () const + { + if (!strncmp (url, "https://", 8) || !strncmp (url, "http://", 7) || !strncmp (url, "ftp://", 6)) { + return true; + } + return false; + } + + char* url; + MemPipe mp; + }; + + private: + + int process_file (); + int process_url (); + + std::vector contents_url (); + std::vector contents_file (); + + int extract_url (); + int extract_file (); + + int do_extract (struct archive* a); + std::vector get_contents (struct archive *a); + + bool is_url (); + + Request _req; + pthread_t _tid; +}; + +} /* namespace */ +#endif // _reallocpool_h_ -- cgit v1.2.3