aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFJob_config.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-25 22:37:17 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commit0a354af02cf51aeb1602596988c8f826b47b3a81 (patch)
tree3d101f330f411080149082db2dba5291d9b7003f /libqpdf/QPDFJob_config.cc
parenta87dcba13f4501adc448d82c58fa1dfa7274046d (diff)
downloadqpdf-0a354af02cf51aeb1602596988c8f826b47b3a81.tar.zst
QPDFJob: convert AddAttachment handlers
Diffstat (limited to 'libqpdf/QPDFJob_config.cc')
-rw-r--r--libqpdf/QPDFJob_config.cc124
1 files changed, 123 insertions, 1 deletions
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index 34f15b9f..ad970aa4 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -509,7 +509,7 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config& c) :
}
QPDFJob::CopyAttConfig&
-QPDFJob::CopyAttConfig::filename(char const* parameter)
+QPDFJob::CopyAttConfig::path(char const* parameter)
{
this->caf.path = parameter;
return *this;
@@ -541,3 +541,125 @@ QPDFJob::CopyAttConfig::end()
this->config.o.attachments_to_copy.push_back(this->caf);
return this->config;
}
+
+QPDFJob::AttConfig::AttConfig(Config& c) :
+ config(c)
+{
+}
+
+std::shared_ptr<QPDFJob::AttConfig>
+QPDFJob::Config::addAttachment()
+{
+ return std::shared_ptr<AttConfig>(new AttConfig(*this));
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::path(char const* parameter)
+{
+ this->att.path = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::key(char const* parameter)
+{
+ this->att.key = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::filename(char const* parameter)
+{
+ this->att.filename = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::creationdate(char const* parameter)
+{
+ if (! QUtil::pdf_time_to_qpdf_time(parameter))
+ {
+ // QXXXQ
+ throw std::runtime_error(
+ std::string(parameter) + " is not a valid PDF timestamp");
+ }
+ this->att.creationdate = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::moddate(char const* parameter)
+{
+ if (! QUtil::pdf_time_to_qpdf_time(parameter))
+ {
+ // QXXXQ
+ throw std::runtime_error(
+ std::string(parameter) + " is not a valid PDF timestamp");
+ }
+ this->att.moddate = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::mimetype(char const* parameter)
+{
+ if (strchr(parameter, '/') == nullptr)
+ {
+ // QXXXQ
+ throw std::runtime_error(
+ "mime type should be specified as type/subtype");
+ }
+ this->att.mimetype = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::description(char const* parameter)
+{
+ this->att.description = parameter;
+ return *this;
+}
+
+QPDFJob::AttConfig&
+QPDFJob::AttConfig::replace()
+{
+ this->att.replace = true;
+ return *this;
+}
+
+QPDFJob::Config&
+QPDFJob::AttConfig::end()
+{
+ // QXXXQ runtime_error
+
+ static std::string now = QUtil::qpdf_time_to_pdf_time(
+ QUtil::get_current_qpdf_time());
+ if (this->att.path.empty())
+ {
+ throw std::runtime_error("add attachment: no path specified");
+ }
+ std::string last_element = QUtil::path_basename(this->att.path);
+ if (last_element.empty())
+ {
+ throw std::runtime_error("path for --add-attachment may not be empty");
+ }
+ if (this->att.filename.empty())
+ {
+ this->att.filename = last_element;
+ }
+ if (this->att.key.empty())
+ {
+ this->att.key = last_element;
+ }
+ if (this->att.creationdate.empty())
+ {
+ this->att.creationdate = now;
+ }
+ if (this->att.moddate.empty())
+ {
+ this->att.moddate = now;
+ }
+
+ this->config.o.attachments_to_add.push_back(this->att);
+ return this->config;
+}