From 35a7379dda587add9d94dc4f710414a23976d6e7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 7 Feb 2019 23:54:07 +0000 Subject: [PATCH] Support download of certificates from Qube (#1460). --- src/lib/internet.cc | 40 +++++++++++++ src/lib/internet.h | 1 + src/wx/download_certificate_dialog.cc | 5 ++ src/wx/qube_certificate_panel.cc | 81 +++++++++++++++++++++++++++ src/wx/qube_certificate_panel.h | 33 +++++++++++ src/wx/wscript | 1 + 6 files changed, 161 insertions(+) create mode 100644 src/wx/qube_certificate_panel.cc create mode 100644 src/wx/qube_certificate_panel.h diff --git a/src/lib/internet.cc b/src/lib/internet.cc index e0af49b66..b993117bb 100644 --- a/src/lib/internet.cc +++ b/src/lib/internet.cc @@ -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(output); + char* c = reinterpret_cast(buffer); + for (size_t i = 0; i < (size * nmemb); ++i) { + *s += c[i]; + } + return nmemb; +} + +list +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(); + } + + list 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) diff --git a/src/lib/internet.h b/src/lib/internet.h index 125533b5d..5f9a25e3b 100644 --- a/src/lib/internet.h +++ b/src/lib/internet.h @@ -27,3 +27,4 @@ class ScopedTemporary; boost::optional get_from_url (std::string url, bool pasv, bool skip_pasv_ip, ScopedTemporary& temp); boost::optional get_from_url (std::string url, bool pasv, bool skip_pasv_ip, boost::function load); boost::optional get_from_zip_url (std::string url, std::string file, bool pasv, bool skip_pasv_ip, boost::function load); +std::list ls_url (std::string url); diff --git a/src/wx/download_certificate_dialog.cc b/src/wx/download_certificate_dialog.cc index e2ce9f088..ec9f6dade 100644 --- a/src/wx/download_certificate_dialog.cc +++ b/src/wx/download_certificate_dialog.cc @@ -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 index 000000000..f6e304955 --- /dev/null +++ b/src/wx/qube_certificate_panel.cc @@ -0,0 +1,81 @@ +/* + Copyright (C) 2019 Carl Hetherington + + 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 . + +*/ + +#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 + +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 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 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 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 index 000000000..89c67f60e --- /dev/null +++ b/src/wx/qube_certificate_panel.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2019 Carl Hetherington + + 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 . + +*/ + +#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; +}; diff --git a/src/wx/wscript b/src/wx/wscript index 816f5a63f..193093e14 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -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 -- 2.30.2