summaryrefslogtreecommitdiff
path: root/libs/pbd/pbd
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-09-13 16:14:08 +0200
committerRobin Gareus <robin@gareus.org>2016-09-13 16:14:40 +0200
commit53ee3e2e722eeac80a16dc4fcf15dc6c34e1e099 (patch)
treeaf62d7c2ef438cbb6b738831153d02907ae902ce /libs/pbd/pbd
parent3193aa93ce456549067465129006da2b685b5bdb (diff)
Add support for built-in file/url unzip/untar
This introduces new build-dependency: libarchive (http://www.libarchive.org/)
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r--libs/pbd/pbd/file_archive.h138
1 files changed, 138 insertions, 0 deletions
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 <robin@gareus.org>
+ *
+ * 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 <pthread.h>
+
+#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<std::string> contents ();
+
+ //PBD::Signal2<void, size_t, size_t> 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<std::string> contents_url ();
+ std::vector<std::string> contents_file ();
+
+ int extract_url ();
+ int extract_file ();
+
+ int do_extract (struct archive* a);
+ std::vector<std::string> get_contents (struct archive *a);
+
+ bool is_url ();
+
+ Request _req;
+ pthread_t _tid;
+};
+
+} /* namespace */
+#endif // _reallocpool_h_