summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config.cc34
-rw-r--r--src/lib/config.h78
-rw-r--r--src/lib/internet.cc53
-rw-r--r--src/lib/internet.h1
-rw-r--r--src/lib/scoped_temporary.h5
5 files changed, 155 insertions, 16 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 7e2cdabf6..76c70ed5d 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -156,6 +156,12 @@ Config::set_defaults ()
for (int i = 0; i < NOTIFICATION_COUNT; ++i) {
_notification[i] = false;
}
+ _barco_username = optional<string>();
+ _barco_password = optional<string>();
+ _christie_username = optional<string>();
+ _christie_password = optional<string>();
+ _gdc_username = optional<string>();
+ _gdc_password = optional<string>();
_allowed_dcp_frame_rates.clear ();
_allowed_dcp_frame_rates.push_back (24);
@@ -463,6 +469,13 @@ try
}
}
+ _barco_username = f.optional_string_child("BarcoUsername");
+ _barco_password = f.optional_string_child("BarcoPassword");
+ _christie_username = f.optional_string_child("ChristieUsername");
+ _christie_password = f.optional_string_child("ChristiePassword");
+ _gdc_username = f.optional_string_child("GDCUsername");
+ _gdc_password = f.optional_string_child("GDCPassword");
+
/* Replace any cinemas from config.xml with those from the configured file */
if (boost::filesystem::exists (_cinemas_file)) {
cxml::Document f ("Cinemas");
@@ -806,6 +819,27 @@ Config::write_config () const
e->add_child_text (_notification[i] ? "1" : "0");
}
+ if (_barco_username) {
+ root->add_child("BarcoUsername")->add_child_text(*_barco_username);
+ }
+ if (_barco_password) {
+ root->add_child("BarcoPassword")->add_child_text(*_barco_password);
+ }
+
+ if (_christie_username) {
+ root->add_child("ChristieUsername")->add_child_text(*_christie_username);
+ }
+ if (_christie_password) {
+ root->add_child("ChristiePassword")->add_child_text(*_christie_password);
+ }
+
+ if (_gdc_username) {
+ root->add_child("GDCUsername")->add_child_text(*_gdc_username);
+ }
+ if (_gdc_password) {
+ root->add_child("GDCPassword")->add_child_text(*_gdc_password);
+ }
+
try {
doc.write_to_file_formatted(config_file().string());
} catch (xmlpp::exception& e) {
diff --git a/src/lib/config.h b/src/lib/config.h
index dbe6a9c21..0be3b20b9 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -423,6 +423,30 @@ public:
return _notification[n];
}
+ boost::optional<std::string> barco_username () const {
+ return _barco_username;
+ }
+
+ boost::optional<std::string> barco_password () const {
+ return _barco_password;
+ }
+
+ boost::optional<std::string> christie_username () const {
+ return _christie_username;
+ }
+
+ boost::optional<std::string> christie_password () const {
+ return _christie_password;
+ }
+
+ boost::optional<std::string> gdc_username () const {
+ return _gdc_username;
+ }
+
+ boost::optional<std::string> gdc_password () const {
+ return _gdc_password;
+ }
+
/* SET (mostly) */
void set_master_encoding_threads (int n) {
@@ -769,6 +793,54 @@ public:
maybe_set (_notification[n], v);
}
+ void set_barco_username (std::string u) {
+ maybe_set (_barco_username, u);
+ }
+
+ void unset_barco_username () {
+ maybe_set (_barco_username, boost::optional<std::string>());
+ }
+
+ void set_barco_password (std::string p) {
+ maybe_set (_barco_password, p);
+ }
+
+ void unset_barco_password () {
+ maybe_set (_barco_password, boost::optional<std::string>());
+ }
+
+ void set_christie_username (std::string u) {
+ maybe_set (_christie_username, u);
+ }
+
+ void unset_christie_username () {
+ maybe_set (_christie_username, boost::optional<std::string>());
+ }
+
+ void set_christie_password (std::string p) {
+ maybe_set (_christie_password, p);
+ }
+
+ void unset_christie_password () {
+ maybe_set (_christie_password, boost::optional<std::string>());
+ }
+
+ void set_gdc_username (std::string u) {
+ maybe_set (_gdc_username, u);
+ }
+
+ void unset_gdc_username () {
+ maybe_set (_gdc_username, boost::optional<std::string>());
+ }
+
+ void set_gdc_password (std::string p) {
+ maybe_set (_gdc_password, p);
+ }
+
+ void unset_gdc_password () {
+ maybe_set (_gdc_password, boost::optional<std::string>());
+ }
+
void changed (Property p = OTHER);
boost::signals2::signal<void (Property)> Changed;
/** Emitted if read() failed on an existing Config file. There is nothing
@@ -944,6 +1016,12 @@ private:
boost::optional<int> _decode_reduction;
bool _default_notify;
bool _notification[NOTIFICATION_COUNT];
+ boost::optional<std::string> _barco_username;
+ boost::optional<std::string> _barco_password;
+ boost::optional<std::string> _christie_username;
+ boost::optional<std::string> _christie_password;
+ boost::optional<std::string> _gdc_username;
+ boost::optional<std::string> _gdc_password;
static int const _current_version;
diff --git a/src/lib/internet.cc b/src/lib/internet.cc
index c1bb5e88f..846dbf7ca 100644
--- a/src/lib/internet.cc
+++ b/src/lib/internet.cc
@@ -38,27 +38,23 @@ using boost::optional;
using boost::function;
using boost::algorithm::trim;
+
static size_t
-get_from_zip_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
+get_from_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
{
FILE* f = reinterpret_cast<FILE*> (stream);
return fwrite (buffer, size, nmemb, f);
}
-/** @param url URL of ZIP file.
- * @param file Filename within ZIP file.
- * @param load Function passed a (temporary) filesystem path of the unpacked file.
- */
+static
optional<string>
-get_from_zip_url (string url, string file, bool pasv, function<void (boost::filesystem::path)> load)
+get_from_url (string url, bool pasv, ScopedTemporary& temp)
{
- /* Download the ZIP file to temp_zip */
CURL* curl = curl_easy_init ();
- curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+ curl_easy_setopt (curl, CURLOPT_URL, url.c_str());
- ScopedTemporary temp_zip;
- FILE* f = temp_zip.open ("wb");
- curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, get_from_zip_url_data);
+ FILE* f = temp.open ("w");
+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, get_from_url_data);
curl_easy_setopt (curl, CURLOPT_WRITEDATA, f);
curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
curl_easy_setopt (curl, CURLOPT_FTP_USE_EPRT, 0);
@@ -71,10 +67,39 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
CURLcode const cr = curl_easy_perform (curl);
- temp_zip.close ();
+ temp.close ();
curl_easy_cleanup (curl);
if (cr != CURLE_OK) {
- return String::compose (_("Download failed (%1/%2 error %3)"), url, file, (int) cr);
+ return String::compose (_("Download failed (%1 error %2)"), url, (int) cr);
+ }
+
+ return optional<string>();
+}
+
+optional<string>
+get_from_url (string url, bool pasv, function<void (boost::filesystem::path)> load)
+{
+ ScopedTemporary temp;
+ optional<string> e = get_from_url (url, pasv, temp);
+ if (e) {
+ return e;
+ }
+ load (temp.file());
+ return optional<string>();
+}
+
+/** @param url URL of ZIP file.
+ * @param file Filename within ZIP file.
+ * @param load Function passed a (temporary) filesystem path of the unpacked file.
+ */
+optional<string>
+get_from_zip_url (string url, string file, bool pasv, function<void (boost::filesystem::path)> load)
+{
+ /* Download the ZIP file to temp_zip */
+ ScopedTemporary temp_zip;
+ optional<string> e = get_from_url (url, pasv, temp_zip);
+ if (e) {
+ return e;
}
/* Open the ZIP file and read `file' out of it */
@@ -110,7 +135,7 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
}
ScopedTemporary temp_cert;
- f = temp_cert.open ("wb");
+ FILE* f = temp_cert.open ("wb");
char buffer[4096];
while (true) {
int const N = zip_fread (file_in_zip, buffer, sizeof (buffer));
diff --git a/src/lib/internet.h b/src/lib/internet.h
index 9b88bde97..15746a44a 100644
--- a/src/lib/internet.h
+++ b/src/lib/internet.h
@@ -22,4 +22,5 @@
#include <boost/function.hpp>
#include <boost/filesystem.hpp>
+boost::optional<std::string> get_from_url (std::string url, bool pasv, boost::function<void (boost::filesystem::path)> load);
boost::optional<std::string> get_from_zip_url (std::string url, std::string file, bool pasv, boost::function<void (boost::filesystem::path)> load);
diff --git a/src/lib/scoped_temporary.h b/src/lib/scoped_temporary.h
index 87c8e387f..986f565a0 100644
--- a/src/lib/scoped_temporary.h
+++ b/src/lib/scoped_temporary.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -19,12 +19,13 @@
*/
#include <boost/filesystem.hpp>
+#include <boost/noncopyable.hpp>
#include <cstdio>
/** @class ScopedTemporary
* @brief A temporary file which is deleted when the ScopedTemporary object goes out of scope.
*/
-class ScopedTemporary
+class ScopedTemporary : public boost::noncopyable
{
public:
ScopedTemporary ();