diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-02-07 23:54:07 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-05-08 23:25:22 +0100 |
| commit | 3b0607f899f8b1b91547f01cf3717cde16096be2 (patch) | |
| tree | a40166f6584d84b16f4017b43ec76c323696b9ce | |
| parent | 958c87eb5dfc23ea5fa66e9590ca8fc271f25572 (diff) | |
Support download of certificates from Qube (#1460).
| -rw-r--r-- | src/lib/internet.cc | 40 | ||||
| -rw-r--r-- | src/lib/internet.h | 1 | ||||
| -rw-r--r-- | src/wx/download_certificate_dialog.cc | 5 | ||||
| -rw-r--r-- | src/wx/qube_certificate_panel.cc | 81 | ||||
| -rw-r--r-- | src/wx/qube_certificate_panel.h | 33 | ||||
| -rw-r--r-- | src/wx/wscript | 1 |
6 files changed, 161 insertions, 0 deletions
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<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) 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<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); 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 <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 index 000000000..89c67f60e --- /dev/null +++ b/src/wx/qube_certificate_panel.h @@ -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; +}; 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 |
