Use sqlite for cinema and DKDM recipient lists.
[dcpomatic.git] / src / lib / screen.cc
1 /*
2     Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "cinema.h"
23 #include "cinema_list.h"
24 #include "config.h"
25 #include "film.h"
26 #include "kdm_util.h"
27 #include "kdm_with_metadata.h"
28 #include "screen.h"
29 #include <libxml++/libxml++.h>
30 #include <boost/algorithm/string.hpp>
31 #include <boost/date_time/posix_time/posix_time.hpp>
32
33
34 using std::list;
35 using std::make_shared;
36 using std::shared_ptr;
37 using std::string;
38 using std::vector;
39 using boost::optional;
40 using namespace dcpomatic;
41
42
43 vector<string>
44 Screen::trusted_device_thumbprints () const
45 {
46         vector<string> t;
47         for (auto i: trusted_devices) {
48                 t.push_back (i.thumbprint());
49         }
50         return t;
51 }
52
53
54 KDMWithMetadataPtr
55 kdm_for_screen (
56         std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm,
57         CinemaID cinema_id,
58         Cinema const& cinema,
59         Screen const& screen,
60         dcp::LocalTime valid_from,
61         dcp::LocalTime valid_to,
62         dcp::Formulation formulation,
63         bool disable_forensic_marking_picture,
64         optional<int> disable_forensic_marking_audio,
65         vector<KDMCertificatePeriod>& period_checks
66         )
67 {
68         if (!screen.recipient) {
69                 return {};
70         }
71
72         period_checks.push_back(check_kdm_and_certificate_validity_periods(cinema.name, screen.name, screen.recipient.get(), valid_from, valid_to));
73
74         auto signer = Config::instance()->signer_chain();
75         if (!signer->valid()) {
76                 throw InvalidSignerError();
77         }
78
79         auto kdm = make_kdm(valid_from, valid_to).encrypt(
80                 signer, screen.recipient.get(), screen.trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio
81                 );
82
83         dcp::NameFormat::Map name_values;
84         name_values['c'] = cinema.name;
85         name_values['s'] = screen.name;
86         name_values['f'] = kdm.content_title_text();
87         name_values['b'] = valid_from.date() + " " + valid_from.time_of_day(true, false);
88         name_values['e'] = valid_to.date() + " " + valid_to.time_of_day(true, false);
89         name_values['i'] = kdm.cpl_id();
90
91         return make_shared<KDMWithMetadata>(name_values, cinema_id, cinema.emails, kdm);
92 }
93