Commit 1c443a1c3574706a57d71a0d066ef16280709383
1 parent
d90b4006
Refactor `QPDFJob::Selection` and `Inputs`: remove `Selection::password` member …
…and replace it with a setter that directly sets `Input::password`, centralize password handling, simplify file processing, and adjust related logic in `handlePageSpecs`.
Showing
3 changed files
with
10 additions
and
18 deletions
libqpdf/QPDFJob.cc
| @@ -2405,10 +2405,6 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | @@ -2405,10 +2405,6 @@ QPDFJob::Inputs::process(std::string const& filename, QPDFJob::Input& input) | ||
| 2405 | void | 2405 | void |
| 2406 | QPDFJob::Inputs::process_all() | 2406 | QPDFJob::Inputs::process_all() |
| 2407 | { | 2407 | { |
| 2408 | - for (auto& selection: selections) { | ||
| 2409 | - selection.process(*this); | ||
| 2410 | - } | ||
| 2411 | - | ||
| 2412 | if (!infile_name().empty()) { | 2408 | if (!infile_name().empty()) { |
| 2413 | files.erase(""); | 2409 | files.erase(""); |
| 2414 | } | 2410 | } |
| @@ -2479,7 +2475,7 @@ QPDFJob::Inputs::new_selection( | @@ -2479,7 +2475,7 @@ QPDFJob::Inputs::new_selection( | ||
| 2479 | std::string const& filename, std::string const& password, std::string const& range) | 2475 | std::string const& filename, std::string const& password, std::string const& range) |
| 2480 | { | 2476 | { |
| 2481 | auto& selection = new_selection(filename); | 2477 | auto& selection = new_selection(filename); |
| 2482 | - selection.password = password; | 2478 | + selection.password(password); |
| 2483 | selection.range = range; | 2479 | selection.range = range; |
| 2484 | } | 2480 | } |
| 2485 | 2481 | ||
| @@ -2501,11 +2497,13 @@ QPDFJob::Selection::filename() | @@ -2501,11 +2497,13 @@ QPDFJob::Selection::filename() | ||
| 2501 | } | 2497 | } |
| 2502 | 2498 | ||
| 2503 | void | 2499 | void |
| 2504 | -QPDFJob::Selection::process(QPDFJob::Inputs& in) | 2500 | +QPDFJob::Selection::password(std::string password) |
| 2505 | { | 2501 | { |
| 2506 | - if (!password.empty()) { | ||
| 2507 | - input().password = password; | 2502 | + auto& in = input(); |
| 2503 | + if (!in.password.empty()) { | ||
| 2504 | + usage("--password already specified for this file"); | ||
| 2508 | } | 2505 | } |
| 2506 | + in.password = password; | ||
| 2509 | } | 2507 | } |
| 2510 | 2508 | ||
| 2511 | // Handle all page specifications. | 2509 | // Handle all page specifications. |
libqpdf/QPDFJob_config.cc
| @@ -1025,11 +1025,7 @@ QPDFJob::PagesConfig::password(std::string const& arg) | @@ -1025,11 +1025,7 @@ QPDFJob::PagesConfig::password(std::string const& arg) | ||
| 1025 | if (config->o.m->inputs.selections.empty()) { | 1025 | if (config->o.m->inputs.selections.empty()) { |
| 1026 | usage("in --pages, --password must follow a file name"); | 1026 | usage("in --pages, --password must follow a file name"); |
| 1027 | } | 1027 | } |
| 1028 | - auto& last = config->o.m->inputs.selections.back(); | ||
| 1029 | - if (!last.password.empty()) { | ||
| 1030 | - usage("--password already specified for this file"); | ||
| 1031 | - } | ||
| 1032 | - last.password = arg; | 1028 | + config->o.m->inputs.selections.back().password(arg); |
| 1033 | return this; | 1029 | return this; |
| 1034 | } | 1030 | } |
| 1035 | 1031 |
libqpdf/qpdf/QPDFJob_private.hh
| @@ -12,9 +12,9 @@ struct QPDFJob::Selection | @@ -12,9 +12,9 @@ struct QPDFJob::Selection | ||
| 12 | { | 12 | { |
| 13 | Selection() = delete; | 13 | Selection() = delete; |
| 14 | 14 | ||
| 15 | - Selection(std::pair<const std::string, QPDFJob::Input>& entry); | 15 | + Selection(std::pair<const std::string, Input>& entry); |
| 16 | 16 | ||
| 17 | - Selection(QPDFJob::Selection const& other, int page) : | 17 | + Selection(Selection const& other, int page) : |
| 18 | in_entry(other.in_entry), | 18 | in_entry(other.in_entry), |
| 19 | selected_pages({page}) | 19 | selected_pages({page}) |
| 20 | { | 20 | { |
| @@ -22,11 +22,9 @@ struct QPDFJob::Selection | @@ -22,11 +22,9 @@ struct QPDFJob::Selection | ||
| 22 | 22 | ||
| 23 | QPDFJob::Input& input(); | 23 | QPDFJob::Input& input(); |
| 24 | std::string const& filename(); | 24 | std::string const& filename(); |
| 25 | - | ||
| 26 | - void process(Inputs& in); | 25 | + void password(std::string password); |
| 27 | 26 | ||
| 28 | std::pair<const std::string, QPDFJob::Input>* in_entry{nullptr}; | 27 | std::pair<const std::string, QPDFJob::Input>* in_entry{nullptr}; |
| 29 | - std::string password; | ||
| 30 | std::string range; // An empty range means all pages. | 28 | std::string range; // An empty range means all pages. |
| 31 | std::vector<int> selected_pages; | 29 | std::vector<int> selected_pages; |
| 32 | }; | 30 | }; |