Add a stored list of DKDMs to the creator rather than just a load button (#767).
[dcpomatic.git] / src / lib / config.cc
index a51c775a38132f2fd72502c605cdf26635759703..54d42a1b94899b405759673d4acf6e5db01f53f2 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include "config.h"
-#include "server.h"
 #include "filter.h"
 #include "ratio.h"
 #include "types.h"
@@ -38,6 +37,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
+#include <boost/thread.hpp>
 #include <cstdlib>
 #include <fstream>
 #include <iostream>
@@ -91,14 +91,13 @@ Config::set_defaults ()
        _mail_port = 25;
        _mail_user = "";
        _mail_password = "";
-       _kdm_subject = _("KDM delivery");
        _kdm_from = "";
        _kdm_cc = "";
        _kdm_bcc = "";
        _check_for_updates = false;
        _check_for_test_updates = false;
        _maximum_j2k_bandwidth = 250000000;
-       _log_types = Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR;
+       _log_types = LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR;
        _automatic_audio_analysis = false;
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = false;
@@ -122,14 +121,29 @@ Config::restore_defaults ()
        Config::instance()->changed ();
 }
 
+shared_ptr<dcp::CertificateChain>
+Config::create_certificate_chain ()
+{
+       return shared_ptr<dcp::CertificateChain> (
+               new dcp::CertificateChain (
+                       openssl_path(),
+                       "dcpomatic.com",
+                       "dcpomatic.com",
+                       ".dcpomatic.smpte-430-2.ROOT",
+                       ".dcpomatic.smpte-430-2.INTERMEDIATE",
+                       "CS.dcpomatic.smpte-430-2.LEAF"
+                       )
+               );
+}
+
 void
 Config::read ()
 {
        if (!have_existing ()) {
                /* Make a new set of signing certificates and key */
-               _signer_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _signer_chain = create_certificate_chain ();
                /* And similar for decryption of KDMs */
-               _decryption_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _decryption_chain = create_certificate_chain ();
                write ();
                return;
        }
@@ -232,9 +246,9 @@ Config::read ()
        _check_for_test_updates = f.optional_bool_child("CheckForTestUpdates").get_value_or (false);
 
        _maximum_j2k_bandwidth = f.optional_number_child<int> ("MaximumJ2KBandwidth").get_value_or (250000000);
-       _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate");
+       _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate").get_value_or (false);
 
-       _log_types = f.optional_number_child<int> ("LogTypes").get_value_or (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR);
+       _log_types = f.optional_number_child<int> ("LogTypes").get_value_or (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR);
        _automatic_audio_analysis = f.optional_bool_child ("AutomaticAudioAnalysis").get_value_or (false);
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = f.optional_bool_child ("Win32Console").get_value_or (false);
@@ -256,7 +270,7 @@ Config::read ()
                _signer_chain = c;
        } else {
                /* Make a new set of signing certificates and key */
-               _signer_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _signer_chain = create_certificate_chain ();
        }
 
        cxml::NodePtr decryption = f.optional_node_child ("Decryption");
@@ -268,8 +282,14 @@ Config::read ()
                c->set_key (decryption->string_child ("PrivateKey"));
                _decryption_chain = c;
        } else {
-               _decryption_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _decryption_chain = create_certificate_chain ();
+       }
+
+       list<cxml::NodePtr> dkdm = f.node_children ("DKDM");
+       BOOST_FOREACH (cxml::NodePtr i, f.node_children ("DKDM")) {
+               _dkdms.push_back (dcp::EncryptedKDM (i->content ()));
        }
+
 }
 
 /** @return Filename to write configuration to */
@@ -402,6 +422,10 @@ Config::write () const
                root->add_child("History")->add_child_text (i->string ());
        }
 
+       BOOST_FOREACH (dcp::EncryptedKDM i, _dkdms) {
+               root->add_child("DKDM")->add_child_text (i.as_xml ());
+       }
+
        try {
                doc.write_to_file_formatted (file().string ());
        } catch (xmlpp::exception& e) {
@@ -443,6 +467,8 @@ Config::changed (Property what)
 void
 Config::set_kdm_email_to_default ()
 {
+       _kdm_subject = _("KDM delivery: $CPL_NAME");
+
        _kdm_email = _(
                "Dear Projectionist\n\n"
                "Please find attached KDMs for $CPL_NAME.\n\n"