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 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
35 _country = new wxChoice (this, wxID_ANY);
36 add_label_to_sizer (table, this, _("Country"), true);
37 table->Add (_country, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
38 _country->Append (N_("Hashemite Kingdom of Jordan"));
40 _cinema = new wxChoice (this, wxID_ANY);
41 add_label_to_sizer (table, this, _("Cinema"), true);
42 table->Add (_cinema, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
43 _cinema->Append (N_("Wometco Dominicana Palacio Del Cine"));
44 _overall_sizer->Add (table);
46 add_common_widgets ();
48 _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this));
49 _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this));
56 ftp_data_ls (void* buffer, size_t size, size_t nmemb, void* data)
58 string* s = reinterpret_cast<string *> (data);
59 uint8_t* b = reinterpret_cast<uint8_t *> (buffer);
60 for (size_t i = 0; i < (size * nmemb); ++i) {
67 DolbyCertificateDialog::ftp_ls (string dir) const
69 CURL* curl = curl_easy_init ();
71 _message->SetLabel (N_("Could not set up libcurl"));
72 return list<string> ();
75 string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
76 if (url.substr (url.length() - 1, 1) != "/") {
79 curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
82 struct curl_slist* commands = 0;
83 commands = curl_slist_append (commands, "NLST");
84 curl_easy_setopt (curl, CURLOPT_POSTQUOTE, commands);
85 curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ls_raw);
86 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ftp_data_ls);
87 curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
88 CURLcode const r = curl_easy_perform (curl);
90 _message->SetLabel (_("Problem occurred when contacting Dolby."));
91 return list<string> ();
94 stringstream s (ls_raw);
99 if (line.length() > 55) {
100 string const file = line.substr (55);
101 if (file != "." && file != "..") {
107 curl_easy_cleanup (curl);
113 DolbyCertificateDialog::setup ()
115 _message->SetLabel (_("Fetching available countries"));
117 list<string> const countries = ftp_ls ("");
118 for (list<string>::const_iterator i = countries.begin(); i != countries.end(); ++i) {
119 _country->Append (std_to_wx (*i));
121 _message->SetLabel ("");
125 DolbyCertificateDialog::country_selected ()
127 _message->SetLabel (_("Fetching available cinemas"));
129 list<string> const cinemas = ftp_ls (wx_to_std (_country->GetStringSelection()));
131 for (list<string>::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) {
132 _cinema->Append (std_to_wx (*i));
134 _message->SetLabel ("");
138 DolbyCertificateDialog::cinema_selected ()
140 _download->Enable (true);
144 DolbyCertificateDialog::download ()