X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fconfig.cc;h=6862cc565550f6af5e8e3cd13b005260cbb12450;hb=1858190cff2f960f3d1f0a5cc02c69da86088f5b;hp=657d79b7148a6d4c2333eaed127f8524c0f7679a;hpb=3b970d4c3089bbf7ca2c7f59d8d18142ed49de65;p=dcpomatic.git diff --git a/src/lib/config.cc b/src/lib/config.cc index 657d79b71..6862cc565 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -21,6 +21,8 @@ #include "server.h" #include "filter.h" #include "ratio.h" +#include "types.h" +#include "log.h" #include "dcp_content_type.h" #include "cinema_sound_processor.h" #include "colour_conversion.h" @@ -29,14 +31,16 @@ #include "cross.h" #include "raw_convert.h" #include -#include #include #include #include +#include #include #include +#include #include #include +#include #include "i18n.h" @@ -67,19 +71,34 @@ Config::set_defaults () _num_local_encoding_threads = max (2U, boost::thread::hardware_concurrency ()); _server_port_base = 6192; _use_any_servers = true; + _servers.clear (); + _only_servers_encode = false; + _tms_protocol = PROTOCOL_SCP; + _tms_ip = ""; _tms_path = "."; + _tms_user = ""; + _tms_password = ""; _cinema_sound_processor = CinemaSoundProcessor::from_id (N_("dolby_cp750")); _allow_any_dcp_frame_rate = false; + _language = optional (); _default_still_length = 10; _default_container = Ratio::from_id ("185"); _default_dcp_content_type = DCPContentType::from_isdcf_name ("FTR"); _default_j2k_bandwidth = 100000000; _default_audio_delay = 0; + _mail_server = ""; _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; + _automatic_audio_analysis = false; #ifdef DCPOMATIC_WINDOWS _win32_console = false; #endif @@ -105,11 +124,12 @@ Config::restore_defaults () void Config::read () { - if (!boost::filesystem::exists (file ())) { + if (!have_existing ()) { /* Make a new set of signing certificates and key */ - _signer.reset (new dcp::Signer (openssl_path ())); - /* And decryption keys */ - make_decryption_keys (); + _signer_chain.reset (new dcp::CertificateChain (openssl_path ())); + /* And similar for decryption of KDMs */ + _decryption_chain.reset (new dcp::CertificateChain (openssl_path ())); + write (); return; } @@ -140,6 +160,8 @@ Config::read () } } + _only_servers_encode = f.optional_bool_child ("OnlyServersEncode").get_value_or (false); + _tms_protocol = static_cast (f.optional_number_child ("TMSProtocol").get_value_or (static_cast (PROTOCOL_SCP))); _tms_ip = f.string_child ("TMSIP"); _tms_path = f.string_child ("TMSPath"); _tms_user = f.string_child ("TMSUser"); @@ -172,6 +194,8 @@ Config::read () _dcp_issuer = f.string_child ("DCPIssuer"); } + _dcp_creator = f.optional_string_child ("DCPCreator").get_value_or (""); + if (version && version.get() >= 2) { _default_isdcf_metadata = ISDCFMetadata (f.node_child ("ISDCFMetadata")); } else { @@ -209,6 +233,7 @@ Config::read () _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate"); _log_types = f.optional_number_child ("LogTypes").get_value_or (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::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); #endif @@ -219,46 +244,35 @@ Config::read () } cxml::NodePtr signer = f.optional_node_child ("Signer"); - dcp::CertificateChain signer_chain; if (signer) { + shared_ptr c (new dcp::CertificateChain ()); /* Read the signing certificates and private key in from the config file */ - list certificates = signer->node_children ("Certificate"); - for (list::const_iterator i = certificates.begin(); i != certificates.end(); ++i) { - signer_chain.add (dcp::Certificate ((*i)->content ())); + BOOST_FOREACH (cxml::NodePtr i, signer->node_children ("Certificate")) { + c->add (dcp::Certificate (i->content ())); } - - _signer.reset (new dcp::Signer (signer_chain, signer->string_child ("PrivateKey"))); + c->set_key (signer->string_child ("PrivateKey")); + _signer_chain = c; } else { /* Make a new set of signing certificates and key */ - _signer.reset (new dcp::Signer (openssl_path ())); + _signer_chain.reset (new dcp::CertificateChain (openssl_path ())); } - if (f.optional_string_child ("DecryptionCertificate")) { - _decryption_certificate = dcp::Certificate (f.string_child ("DecryptionCertificate")); - } - - if (f.optional_string_child ("DecryptionPrivateKey")) { - _decryption_private_key = f.string_child ("DecryptionPrivateKey"); - } - - if (!f.optional_string_child ("DecryptionCertificate") || !f.optional_string_child ("DecryptionPrivateKey")) { - /* Generate our own decryption certificate and key if either is not present in config */ - make_decryption_keys (); + cxml::NodePtr decryption = f.optional_node_child ("Decryption"); + if (decryption) { + shared_ptr c (new dcp::CertificateChain ()); + BOOST_FOREACH (cxml::NodePtr i, decryption->node_children ("Certificate")) { + c->add (dcp::Certificate (i->content ())); + } + c->set_key (decryption->string_child ("PrivateKey")); + _decryption_chain = c; + } else { + _decryption_chain.reset (new dcp::CertificateChain (openssl_path ())); } } -void -Config::make_decryption_keys () -{ - boost::filesystem::path p = dcp::make_certificate_chain (openssl_path ()); - _decryption_certificate = dcp::Certificate (dcp::file_to_string (p / "leaf.signed.pem")); - _decryption_private_key = dcp::file_to_string (p / "leaf.key"); - boost::filesystem::remove_all (p); -} - /** @return Filename to write configuration to */ boost::filesystem::path -Config::file () const +Config::file (bool create_directories) { boost::filesystem::path p; #ifdef DCPOMATIC_OSX @@ -272,7 +286,9 @@ Config::file () const p /= "dcpomatic2"; #endif boost::system::error_code ec; - boost::filesystem::create_directories (p, ec); + if (create_directories) { + boost::filesystem::create_directories (p, ec); + } p /= "config.xml"; return p; } @@ -289,9 +305,9 @@ Config::instance () /* configuration load failed; never mind, just stick with the default. */ - cerr << "dcpomatic: failed to load configuration (" << e.what() << ")\n"; + cerr << "dcpomatic: warning: configuration did not load (" << e.what() << "); using defaults\n"; } catch (...) { - cerr << "dcpomatic: failed to load configuration\n"; + cerr << "dcpomatic: warning: configuration did not load; using defaults\n"; } } @@ -315,6 +331,8 @@ Config::write () const root->add_child("Server")->add_child_text (*i); } + root->add_child("OnlyServersEncode")->add_child_text (_only_servers_encode ? "1" : "0"); + root->add_child("TMSProtocol")->add_child_text (raw_convert (_tms_protocol)); root->add_child("TMSIP")->add_child_text (_tms_ip); root->add_child("TMSPath")->add_child_text (_tms_path); root->add_child("TMSUser")->add_child_text (_tms_user); @@ -332,6 +350,7 @@ Config::write () const root->add_child("DefaultDCPContentType")->add_child_text (_default_dcp_content_type->isdcf_name ()); } root->add_child("DCPIssuer")->add_child_text (_dcp_issuer); + root->add_child("DCPCreator")->add_child_text (_dcp_creator); _default_isdcf_metadata.as_xml (root->add_child ("ISDCFMetadata")); @@ -359,19 +378,22 @@ Config::write () const root->add_child("MaximumJ2KBandwidth")->add_child_text (raw_convert (_maximum_j2k_bandwidth)); root->add_child("AllowAnyDCPFrameRate")->add_child_text (_allow_any_dcp_frame_rate ? "1" : "0"); root->add_child("LogTypes")->add_child_text (raw_convert (_log_types)); + root->add_child("AutomaticAudioAnalysis")->add_child_text (_automatic_audio_analysis ? "1" : "0"); #ifdef DCPOMATIC_WINDOWS root->add_child("Win32Console")->add_child_text (_win32_console ? "1" : "0"); #endif xmlpp::Element* signer = root->add_child ("Signer"); - dcp::CertificateChain::List certs = _signer->certificates().root_to_leaf (); - for (dcp::CertificateChain::List::const_iterator i = certs.begin(); i != certs.end(); ++i) { - signer->add_child("Certificate")->add_child_text (i->certificate (true)); + BOOST_FOREACH (dcp::Certificate const & i, _signer_chain->root_to_leaf ()) { + signer->add_child("Certificate")->add_child_text (i.certificate (true)); } - signer->add_child("PrivateKey")->add_child_text (_signer->key ()); + signer->add_child("PrivateKey")->add_child_text (_signer_chain->key().get ()); - root->add_child("DecryptionCertificate")->add_child_text (_decryption_certificate.certificate (true)); - root->add_child("DecryptionPrivateKey")->add_child_text (_decryption_private_key); + xmlpp::Element* decryption = root->add_child ("Decryption"); + BOOST_FOREACH (dcp::Certificate const & i, _decryption_chain->root_to_leaf ()) { + decryption->add_child("Certificate")->add_child_text (i.certificate (true)); + } + decryption->add_child("PrivateKey")->add_child_text (_decryption_chain->key().get ()); for (vector::const_iterator i = _history.begin(); i != _history.end(); ++i) { root->add_child("History")->add_child_text (i->string ()); @@ -410,9 +432,9 @@ Config::drop () } void -Config::changed () +Config::changed (Property what) { - Changed (); + Changed (what); } void @@ -448,3 +470,9 @@ Config::add_to_history (boost::filesystem::path p) changed (); } + +bool +Config::have_existing () +{ + return boost::filesystem::exists (file (false)); +}