From b42f3e1d15203927776a5b0954782287c901300f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 1 Feb 2022 07:28:26 -0500 Subject: Move more code from qpdf.cc into QPDFJob --- libqpdf/QPDFJob.cc | 89 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 25 deletions(-) (limited to 'libqpdf/QPDFJob.cc') diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index a06f87bc..bea8e358 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -629,10 +629,28 @@ QPDFJob::run() { this->m->warnings = true; } + if (this->m->warnings && (! this->m->suppress_warnings)) + { + if (createsOutput()) + { + (*this->m->cerr) + << this->m->message_prefix + << ": operation succeeded with warnings;" + << " resulting file may have some problems" + << std::endl; + } + else + { + (*this->m->cerr) + << this->m->message_prefix + << ": operation succeeded with warnings" + << std::endl; + } + } } bool -QPDFJob::hasWarnings() +QPDFJob::hasWarnings() const { return this->m->warnings; } @@ -643,6 +661,51 @@ QPDFJob::createsOutput() const return ((m->outfilename != nullptr) || m->replace_input); } +int +QPDFJob::getExitCode() const +{ + if (this->m->check_is_encrypted) + { + if (this->m->encryption_status & qpdf_es_encrypted) + { + QTC::TC("qpdf", "qpdf check encrypted encrypted"); + return 0; + } + else + { + QTC::TC("qpdf", "qpdf check encrypted not encrypted"); + return EXIT_IS_NOT_ENCRYPTED; + } + } + else if (this->m->check_requires_password) + { + if (this->m->encryption_status & qpdf_es_encrypted) + { + if (this->m->encryption_status & qpdf_es_password_incorrect) + { + QTC::TC("qpdf", "qpdf check password password incorrect"); + return 0; + } + else + { + QTC::TC("qpdf", "qpdf check password password correct"); + return EXIT_CORRECT_PASSWORD; + } + } + else + { + QTC::TC("qpdf", "qpdf check password not encrypted"); + return EXIT_IS_NOT_ENCRYPTED; + } + } + + if (this->m->warnings && (! this->m->warnings_exit_zero)) + { + return EXIT_WARNING; + } + return 0; +} + void QPDFJob::checkConfiguration() { @@ -726,30 +789,6 @@ QPDFJob::checkConfiguration() } } -bool -QPDFJob::suppressWarnings() -{ - return this->m->suppress_warnings; -} - -bool -QPDFJob::warningsExitZero() -{ - return this->m->warnings_exit_zero; -} - -bool -QPDFJob::checkRequiresPassword() -{ - return this->m->check_requires_password; -} - -bool -QPDFJob::checkIsEncrypted() -{ - return this->m->check_is_encrypted; -} - unsigned long QPDFJob::getEncryptionStatus() { -- cgit v1.2.3-54-g00ecf