2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <curl/curl.h>
21 #include "lib/compose.hpp"
22 #include "dolby_certificate_dialog.h"
27 using std::stringstream;
30 DolbyCertificateDialog::DolbyCertificateDialog (wxWindow* parent, boost::function<void (boost::filesystem::path)> load)
31 : DownloadCertificateDialog (parent, load)
33 add (_("Country"), true);
34 _country = add (new wxChoice (this, wxID_ANY));
35 _country->Append (N_("Hashemite Kingdom of Jordan"));
37 add (_("Cinema"), true);
38 _cinema = add (new wxChoice (this, wxID_ANY));
39 _cinema->Append (N_("Motion Picture Solutions London Mobile & QC"));
41 add_common_widgets ();
43 _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this));
44 _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this));
45 Bind (wxEVT_IDLE, boost::bind (&DolbyCertificateDialog::setup_countries, this));
52 ftp_data_ls (void* buffer, size_t size, size_t nmemb, void* data)
54 string* s = reinterpret_cast<string *> (data);
55 uint8_t* b = reinterpret_cast<uint8_t *> (buffer);
56 for (size_t i = 0; i < (size * nmemb); ++i) {
63 DolbyCertificateDialog::ftp_ls (string dir) const
65 CURL* curl = curl_easy_init ();
67 _message->SetLabel (N_("Could not set up libcurl"));
68 return list<string> ();
71 string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
72 if (url.substr (url.length() - 1, 1) != "/") {
75 curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
78 struct curl_slist* commands = 0;
79 commands = curl_slist_append (commands, "NLST");
80 curl_easy_setopt (curl, CURLOPT_POSTQUOTE, commands);
81 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ls_raw);
82 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ftp_data_ls);
83 curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
84 CURLcode const r = curl_easy_perform (curl);
86 _message->SetLabel (_("Problem occurred when contacting Dolby."));
87 return list<string> ();
90 stringstream s (ls_raw);
95 if (line.length() > 55) {
96 string const file = line.substr (55);
97 if (file != "." && file != "..") {
103 curl_easy_cleanup (curl);
109 DolbyCertificateDialog::setup_countries ()
111 if (_country->GetCount() > 0) {
116 _country->Append (_("Fetching..."));
117 _country->SetSelection (0);
120 list<string> const countries = ftp_ls ("");
122 for (list<string>::const_iterator i = countries.begin(); i != countries.end(); ++i) {
123 _country->Append (std_to_wx (*i));
128 DolbyCertificateDialog::country_selected ()
131 _cinema->Append (_("Fetching..."));
132 _cinema->SetSelection (0);
135 list<string> const cinemas = ftp_ls (wx_to_std (_country->GetStringSelection()));
137 for (list<string>::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) {
138 _cinema->Append (std_to_wx (*i));
143 DolbyCertificateDialog::cinema_selected ()
145 _download->Enable (true);
149 DolbyCertificateDialog::download ()