summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-03-09 00:11:38 +0100
committerCarl Hetherington <cth@carlh.net>2024-03-09 00:11:38 +0100
commit80313b07095814f0178be70bc0651c1e052decea (patch)
tree5ea002e29340ee342344affce277aa0cd941d7db /src/lib
parent82f87c7711fb664b06b04d44792ed3820b3d1e01 (diff)
parent04b5957318df591f56e0a5d39720df143dc8230d (diff)
Merge branch 'main' into v2.17.x
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_content.cc8
-rw-r--r--src/lib/email.cc (renamed from src/lib/emailer.cc)31
-rw-r--r--src/lib/email.h (renamed from src/lib/emailer.h)7
-rw-r--r--src/lib/kdm_cli.cc4
-rw-r--r--src/lib/kdm_with_metadata.cc19
-rw-r--r--src/lib/send_notification_email_job.cc4
-rw-r--r--src/lib/send_problem_report_job.cc6
-rw-r--r--src/lib/util.cc29
-rw-r--r--src/lib/util.h2
-rw-r--r--src/lib/wscript2
10 files changed, 73 insertions, 39 deletions
diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc
index 378ba1882..c459a9ece 100644
--- a/src/lib/dcp_content.cc
+++ b/src/lib/dcp_content.cc
@@ -723,6 +723,14 @@ DCPContent::can_reference_audio (shared_ptr<const Film> film, string& why_not) c
return false;
}
+ if (audio && audio->stream()) {
+ auto const channels = audio->stream()->channels();
+ if (channels != film->audio_channels()) {
+ why_not = String::compose(_("it has a different number of audio channels than the project; set the project to have %1 channels."), channels);
+ return false;
+ }
+ }
+
auto part = [](shared_ptr<const Content> c) {
return static_cast<bool>(c->audio) && !c->audio->mapping().mapped_output_channels().empty();
};
diff --git a/src/lib/emailer.cc b/src/lib/email.cc
index f580e3c56..8557b40e0 100644
--- a/src/lib/emailer.cc
+++ b/src/lib/email.cc
@@ -21,7 +21,7 @@
#include "compose.hpp"
#include "config.h"
-#include "emailer.h"
+#include "email.h"
#include "exceptions.h"
#include <curl/curl.h>
#include <boost/algorithm/string.hpp>
@@ -39,7 +39,7 @@ using std::vector;
using dcp::ArrayData;
-Emailer::Emailer(string from, vector<string> to, string subject, string body)
+Email::Email(string from, vector<string> to, string subject, string body)
: _from (from)
, _to (to)
, _subject (subject)
@@ -51,7 +51,7 @@ Emailer::Emailer(string from, vector<string> to, string subject, string body)
string
-Emailer::fix (string s) const
+Email::fix(string s) const
{
boost::algorithm::replace_all (s, "\n", "\r\n");
boost::algorithm::replace_all (s, "\0", " ");
@@ -60,24 +60,24 @@ Emailer::fix (string s) const
void
-Emailer::add_cc (string cc)
+Email::add_cc(string cc)
{
_cc.push_back (cc);
}
void
-Emailer::add_bcc (string bcc)
+Email::add_bcc(string bcc)
{
_bcc.push_back (bcc);
}
void
-Emailer::add_attachment (boost::filesystem::path file, string name, string mime_type)
+Email::add_attachment(boost::filesystem::path file, string name, string mime_type)
{
Attachment a;
- a.file = file;
+ a.file = dcp::ArrayData(file);
a.name = name;
a.mime_type = mime_type;
_attachments.push_back (a);
@@ -87,19 +87,19 @@ Emailer::add_attachment (boost::filesystem::path file, string name, string mime_
static size_t
curl_data_shim (void* ptr, size_t size, size_t nmemb, void* userp)
{
- return reinterpret_cast<Emailer*>(userp)->get_data (ptr, size, nmemb);
+ return reinterpret_cast<Email*>(userp)->get_data (ptr, size, nmemb);
}
static int
curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp)
{
- return reinterpret_cast<Emailer*>(userp)->debug (curl, type, data, size);
+ return reinterpret_cast<Email*>(userp)->debug (curl, type, data, size);
}
size_t
-Emailer::get_data (void* ptr, size_t size, size_t nmemb)
+Email::get_data(void* ptr, size_t size, size_t nmemb)
{
size_t const t = min (_email.length() - _offset, size * nmemb);
memcpy (ptr, _email.substr (_offset, t).c_str(), t);
@@ -109,7 +109,7 @@ Emailer::get_data (void* ptr, size_t size, size_t nmemb)
void
-Emailer::send (string server, int port, EmailProtocol protocol, string user, string password)
+Email::send(string server, int port, EmailProtocol protocol, string user, string password)
{
char date_buffer[128];
time_t now = time (0);
@@ -171,8 +171,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str
}
bio = BIO_push (b64, bio);
- ArrayData data (i.file);
- BIO_write (bio, data.data(), data.size());
+ BIO_write(bio, i.file.data(), i.file.size());
(void) BIO_flush (bio);
char* out;
@@ -247,7 +246,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str
string
-Emailer::address_list(vector<string> addresses)
+Email::address_list(vector<string> addresses)
{
string o;
for (auto i: addresses) {
@@ -259,7 +258,7 @@ Emailer::address_list(vector<string> addresses)
int
-Emailer::debug (CURL *, curl_infotype type, char* data, size_t size)
+Email::debug(CURL *, curl_infotype type, char* data, size_t size)
{
if (type == CURLINFO_TEXT) {
_notes += string (data, size);
@@ -273,7 +272,7 @@ Emailer::debug (CURL *, curl_infotype type, char* data, size_t size)
string
-Emailer::encode_rfc1342 (string subject)
+Email::encode_rfc1342(string subject)
{
auto b64 = BIO_new(BIO_f_base64());
if (!b64) {
diff --git a/src/lib/emailer.h b/src/lib/email.h
index 78942ad1e..36398bfd8 100644
--- a/src/lib/emailer.h
+++ b/src/lib/email.h
@@ -23,13 +23,14 @@
#include <boost/scoped_array.hpp>
-class Emailer
+class Email
{
public:
- Emailer(std::string from, std::vector<std::string> to, std::string subject, std::string body);
+ Email(std::string from, std::vector<std::string> to, std::string subject, std::string body);
void add_cc (std::string cc);
void add_bcc (std::string bcc);
+ /** Add attachment, copying the contents of the file into memory */
void add_attachment (boost::filesystem::path file, std::string name, std::string mime_type);
void send (std::string server, int port, EmailProtocol protocol, std::string user = "", std::string password = "");
@@ -61,7 +62,7 @@ private:
std::vector<std::string> _bcc;
struct Attachment {
- boost::filesystem::path file;
+ dcp::ArrayData file;
std::string name;
std::string mime_type;
};
diff --git a/src/lib/kdm_cli.cc b/src/lib/kdm_cli.cc
index 4e3f9ccb7..e4fabe1a6 100644
--- a/src/lib/kdm_cli.cc
+++ b/src/lib/kdm_cli.cc
@@ -27,7 +27,7 @@
#include "cinema.h"
#include "config.h"
#include "dkdm_wrapper.h"
-#include "emailer.h"
+#include "email.h"
#include "exceptions.h"
#include "film.h"
#include "kdm_with_metadata.h"
@@ -609,7 +609,7 @@ try
if (list_cinemas) {
auto cinemas = Config::instance()->cinemas ();
for (auto i: cinemas) {
- out (String::compose("%1 (%2)", i->name, Emailer::address_list (i->emails)));
+ out (String::compose("%1 (%2)", i->name, Email::address_list(i->emails)));
}
return {};
}
diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc
index 10054f01e..f7ff84435 100644
--- a/src/lib/kdm_with_metadata.cc
+++ b/src/lib/kdm_with_metadata.cc
@@ -23,7 +23,7 @@
#include "config.h"
#include "cross.h"
#include "dcpomatic_log.h"
-#include "emailer.h"
+#include "email.h"
#include "kdm_with_metadata.h"
#include "screen.h"
#include "util.h"
@@ -238,14 +238,13 @@ send_emails (
auto subject = substitute_variables(config->kdm_subject());
auto body = substitute_variables(config->kdm_email());
- string screens;
+ vector<string> screens;
for (auto kdm: kdms_for_cinema) {
- auto screen_name = kdm->get('s');
- if (screen_name) {
- screens += *screen_name + ", ";
+ if (auto screen_name = kdm->get('s')) {
+ screens.push_back(*screen_name);
}
}
- boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
+ boost::algorithm::replace_all(body, "$SCREENS", screen_names_to_string(screens));
auto emails = first->emails();
std::copy(extra_addresses.begin(), extra_addresses.end(), std::back_inserter(emails));
@@ -253,7 +252,7 @@ send_emails (
continue;
}
- Emailer email (config->kdm_from(), { emails.front() }, subject, body);
+ Email email(config->kdm_from(), { emails.front() }, subject, body);
/* Use CC for the second and subsequent email addresses, so we seem less spammy (#2310) */
for (auto cc = std::next(emails.begin()); cc != emails.end(); ++cc) {
@@ -268,8 +267,9 @@ send_emails (
}
email.add_attachment (zip_file, container_name_format.get(first->name_values(), ".zip"), "application/zip");
+ dcp::filesystem::remove(zip_file);
- auto log_details = [](Emailer& email) {
+ auto log_details = [](Email& email) {
dcpomatic_log->log("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);
dcpomatic_log->log(email.email(), LogEntry::TYPE_DEBUG_EMAIL);
dcpomatic_log->log("Email session follows", LogEntry::TYPE_DEBUG_EMAIL);
@@ -279,13 +279,10 @@ send_emails (
try {
email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password());
} catch (...) {
- dcp::filesystem::remove(zip_file);
log_details (email);
throw;
}
log_details (email);
-
- dcp::filesystem::remove(zip_file);
}
}
diff --git a/src/lib/send_notification_email_job.cc b/src/lib/send_notification_email_job.cc
index f40e8fefa..a2f3016f9 100644
--- a/src/lib/send_notification_email_job.cc
+++ b/src/lib/send_notification_email_job.cc
@@ -22,7 +22,7 @@
#include "send_notification_email_job.h"
#include "exceptions.h"
#include "config.h"
-#include "emailer.h"
+#include "email.h"
#include "compose.hpp"
#include "i18n.h"
@@ -71,7 +71,7 @@ SendNotificationEmailJob::run ()
}
set_progress_unknown ();
- Emailer email (config->notification_from(), { config->notification_to() }, config->notification_subject(), _body);
+ Email email(config->notification_from(), { config->notification_to() }, config->notification_subject(), _body);
for (auto i: config->notification_cc()) {
email.add_cc (i);
}
diff --git a/src/lib/send_problem_report_job.cc b/src/lib/send_problem_report_job.cc
index 34822b156..9569aca3b 100644
--- a/src/lib/send_problem_report_job.cc
+++ b/src/lib/send_problem_report_job.cc
@@ -26,7 +26,7 @@
#include "film.h"
#include "log.h"
#include "version.h"
-#include "emailer.h"
+#include "email.h"
#include "environment_info.h"
#include <libxml++/libxml++.h>
@@ -108,8 +108,8 @@ SendProblemReportJob::run ()
body += "---<8----\n";
}
- Emailer emailer (_from, {"carl@dcpomatic.com"}, "DCP-o-matic problem report", body);
- emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS);
+ Email email(_from, {"carl@dcpomatic.com"}, "DCP-o-matic problem report", body);
+ email.send("main.carlh.net", 2525, EmailProtocol::STARTTLS);
set_progress (1);
set_state (FINISHED_OK);
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 01a7f0248..ef15b90e5 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -1120,7 +1120,6 @@ word_wrap(string input, int columns)
}
-
#ifdef DCPOMATIC_GROK
void
setup_grok_library_path()
@@ -1147,3 +1146,31 @@ setup_grok_library_path()
setenv("LD_LIBRARY_PATH", new_path.c_str(), 1);
}
#endif
+
+string
+screen_names_to_string(vector<string> names)
+{
+ if (names.empty()) {
+ return {};
+ }
+
+ auto number = [](string const& s) {
+ return s.find_first_not_of("0123456789") == string::npos;
+ };
+
+ if (std::find_if(names.begin(), names.end(), [number](string const& s) { return !number(s); }) == names.end()) {
+ std::sort(names.begin(), names.end(), [](string const& a, string const& b) {
+ return dcp::raw_convert<int>(a) < dcp::raw_convert<int>(b);
+ });
+ } else {
+ std::sort(names.begin(), names.end());
+ }
+
+ string result;
+ for (auto const& name: names) {
+ result += name + ", ";
+ }
+
+ return result.substr(0, result.length() - 2);
+}
+
diff --git a/src/lib/util.h b/src/lib/util.h
index b85cf0a33..4f64369d3 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -114,4 +114,6 @@ number_attribute(cxml::ConstNodePtr node, std::string name1, std::string name2)
return *value;
}
+extern std::string screen_names_to_string(std::vector<std::string> names);
+
#endif
diff --git a/src/lib/wscript b/src/lib/wscript
index 5bae3e0d1..878b503a8 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -87,7 +87,7 @@ sources = """
dkdm_recipient.cc
dkdm_wrapper.cc
dolby_cp750.cc
- emailer.cc
+ email.cc
empty.cc
encoder.cc
encode_server.cc