Support download of certificates from Qube (#1460).
authorCarl Hetherington <cth@carlh.net>
Thu, 7 Feb 2019 23:54:07 +0000 (23:54 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 10 May 2019 22:43:42 +0000 (23:43 +0100)
src/lib/internet.cc
src/lib/internet.h
src/wx/download_certificate_dialog.cc
src/wx/qube_certificate_panel.cc [new file with mode: 0644]
src/wx/qube_certificate_panel.h [new file with mode: 0644]
src/wx/wscript

index e0af49b6698e64c75148ec5ecfddee14e1c75969..b993117bb5e93cc3b58e77264c7dcd3ce0b14f79 100644 (file)
@@ -39,6 +39,46 @@ using boost::optional;
 using boost::function;
 using boost::algorithm::trim;
 
+static size_t
+ls_url_data (void* buffer, size_t size, size_t nmemb, void* output)
+{
+       string* s = reinterpret_cast<string*>(output);
+       char* c = reinterpret_cast<char*>(buffer);
+       for (size_t i = 0; i < (size * nmemb); ++i) {
+               *s += c[i];
+       }
+       return nmemb;
+}
+
+list<string>
+ls_url (string url)
+{
+       CURL* curl = curl_easy_init ();
+       curl_easy_setopt (curl, CURLOPT_URL, url.c_str());
+       curl_easy_setopt (curl, CURLOPT_DIRLISTONLY, 1);
+
+       string ls;
+       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ls_url_data);
+       curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ls);
+       CURLcode const cr = curl_easy_perform (curl);
+
+       if (cr != CURLE_OK) {
+               return list<string>();
+       }
+
+       list<string> result;
+       result.push_back("");
+       for (size_t i = 0; i < ls.size(); ++i) {
+               if (ls[i] == '\n') {
+                       result.push_back("");
+               } else {
+                       result.back() += ls[i];
+               }
+       }
+
+       result.pop_back ();
+       return result;
+}
 
 static size_t
 get_from_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
index 125533b5d7e39aa21741c2b370d3c36fadd66db6..5f9a25e3b2ab166adf7c81e8f0e330cb25bc7fda 100644 (file)
@@ -27,3 +27,4 @@ class ScopedTemporary;
 boost::optional<std::string> get_from_url (std::string url, bool pasv, bool skip_pasv_ip, ScopedTemporary& temp);
 boost::optional<std::string> get_from_url (std::string url, bool pasv, bool skip_pasv_ip, boost::function<void (boost::filesystem::path)> load);
 boost::optional<std::string> get_from_zip_url (std::string url, std::string file, bool pasv, bool skip_pasv_ip, boost::function<void (boost::filesystem::path)> load);
+std::list<std::string> ls_url (std::string url);
index e2ce9f088c5915a2c783c5733cdffc4d2568bf7f..ec9f6dade09bf3c8f6d280dad46d5d6fbe92e364 100644 (file)
@@ -22,6 +22,7 @@
 #include "barco_alchemy_certificate_panel.h"
 #include "christie_certificate_panel.h"
 #include "gdc_certificate_panel.h"
+#include "qube_certificate_panel.h"
 #include "download_certificate_dialog.h"
 #include "static_text.h"
 #include "wx_util.h"
@@ -51,6 +52,8 @@ DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
        _pages.push_back (new BarcoAlchemyCertificatePanel (this));
        _pages.push_back (new ChristieCertificatePanel (this));
        _pages.push_back (new GDCCertificatePanel (this));
+       _pages.push_back (new QubeCertificatePanel (this, N_("QXI")));
+       _pages.push_back (new QubeCertificatePanel (this, N_("QXPD")));
 
        BOOST_FOREACH (DownloadCertificatePanel* i, _pages) {
                _notebook->AddPage (i, i->name(), true);
@@ -69,6 +72,8 @@ DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
 
        _notebook->SetSelection (0);
 
+       SetMinSize (wxSize(640, -1));
+
        setup_sensitivity ();
 }
 
diff --git a/src/wx/qube_certificate_panel.cc b/src/wx/qube_certificate_panel.cc
new file mode 100644 (file)
index 0000000..f6e3049
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "qube_certificate_panel.h"
+#include "download_certificate_dialog.h"
+#include "wx_util.h"
+#include "lib/internet.h"
+#include "lib/compose.hpp"
+#include "lib/config.h"
+#include <boost/algorithm/string/predicate.hpp>
+
+using std::string;
+using std::list;
+using boost::optional;
+
+static string const base = "ftp://certificates.qubecinema.com/";
+
+QubeCertificatePanel::QubeCertificatePanel (DownloadCertificateDialog* dialog, string type)
+       : DownloadCertificatePanel (dialog)
+       , _type (type)
+{
+
+}
+
+void
+QubeCertificatePanel::do_download ()
+{
+       list<string> files = ls_url(String::compose("%1SMPTE-%2/", base, _type));
+       if (files.empty()) {
+               error_dialog (this, _("Could not read certificates from Qube server."));
+               return;
+       }
+
+       string const serial = wx_to_std(_serial->GetValue());
+       optional<string> name;
+       BOOST_FOREACH (string i, files) {
+               if (boost::algorithm::starts_with(i, String::compose("%1-%2-", _type, serial))) {
+                       name = i;
+                       break;
+               }
+       }
+
+       if (!name) {
+               _dialog->message()->SetLabel(wxT(""));
+               error_dialog (this, wxString::Format(_("Could not find serial number %s"), std_to_wx(serial).data()));
+               return;
+       }
+
+       optional<string> error = get_from_url (String::compose("%1SMPTE-%2/%3", base, _type, *name), true, boost::bind (&DownloadCertificatePanel::load, this, _1));
+
+       if (error) {
+               _dialog->message()->SetLabel(wxT(""));
+               error_dialog (this, std_to_wx(*error));
+       } else {
+               _dialog->message()->SetLabel (_("Certificate downloaded"));
+               _dialog->setup_sensitivity ();
+       }
+}
+
+wxString
+QubeCertificatePanel::name () const
+{
+       return _("Qube") + " " + std_to_wx(_type);
+}
diff --git a/src/wx/qube_certificate_panel.h b/src/wx/qube_certificate_panel.h
new file mode 100644 (file)
index 0000000..89c67f6
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "download_certificate_panel.h"
+
+class QubeCertificatePanel : public DownloadCertificatePanel
+{
+public:
+       QubeCertificatePanel (DownloadCertificateDialog* dialog, std::string type);
+
+       void do_download ();
+       wxString name () const;
+
+private:
+       std::string _type;
+};
index 816f5a63fb4a88ea35f7ca7197cc87a8d5ad426f..193093e142220715c085ac587a825fdab24461c3 100644 (file)
@@ -102,6 +102,7 @@ sources = """
           playhead_to_frame_dialog.cc
           question_dialog.cc
           rating_dialog.cc
+          qube_certificate_panel.cc
           recreate_chain_dialog.cc
           repeat_dialog.cc
           report_problem_dialog.cc