aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2024-01-09 22:54:11 +0100
committerJay Berkenbilt <ejb@ql.org>2024-01-10 22:45:14 +0100
commit12f7a4461b18b4be94002fa0043fd0e98e80a274 (patch)
tree12b946b2de5bf685b20f03ff75e1126b13d2e73c /libqpdf
parent6488b156f736660ea0636af0003bd863e23af640 (diff)
downloadqpdf-12f7a4461b18b4be94002fa0043fd0e98e80a274.tar.zst
Handle pages/under/overlay JSON file in begin
...since they have to be handled before other options. It was working because, in both cases, `file` was alphabetically before the other keys, but this implementation gives a stronger guarantee.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFJob_json.cc40
1 files changed, 33 insertions, 7 deletions
diff --git a/libqpdf/QPDFJob_json.cc b/libqpdf/QPDFJob_json.cc
index 797ee81d..35963169 100644
--- a/libqpdf/QPDFJob_json.cc
+++ b/libqpdf/QPDFJob_json.cc
@@ -57,6 +57,8 @@ namespace
bare_handler_t bindBare(void (Handlers::*f)());
json_handler_t bindJSON(void (Handlers::*f)(JSON));
+ void beginUnderOverlay(JSON const& j);
+
std::list<std::shared_ptr<JSONHandler>> json_handlers;
bool partial;
JSONHandler* jh{nullptr}; // points to last of json_handlers
@@ -226,6 +228,24 @@ Handlers::handle(JSON& j)
}
void
+Handlers::beginUnderOverlay(JSON const& j)
+{
+ // File has to be processed before items, so handle it here.
+ bool file_seen = false;
+ std::string file;
+ j.forEachDictItem([&](std::string const& key, JSON const& value) {
+ if (key == "file") {
+ file_seen = value.getString(file);
+ }
+ });
+ if (!file_seen) {
+ QTC::TC("qpdf", "QPDFJob json over/under no file");
+ usage("file is required in underlay/overlay specification");
+ }
+ c_uo->file(file);
+}
+
+void
Handlers::setupInputFile()
{
addParameter([this](char const* p) { c_main->inputFile(p); });
@@ -468,16 +488,17 @@ void
Handlers::beginPages(JSON j)
{
bool file_seen = false;
+ std::string file;
j.forEachDictItem([&](std::string const& key, JSON const& value) {
if (key == "file") {
- std::string v;
- file_seen = value.getString(v);
+ file_seen = value.getString(file);
}
});
if (!file_seen) {
QTC::TC("qpdf", "QPDFJob json pages no file");
usage("file is required in page specification");
}
+ c_pages->file(file);
}
void
@@ -489,7 +510,8 @@ Handlers::endPages()
void
Handlers::setupPagesFile()
{
- addParameter([this](char const* p) { c_pages->file(p); });
+ // This is handled in beginPages since file() has to be called first.
+ ignoreItem();
}
void
@@ -499,9 +521,10 @@ Handlers::setupPagesPassword()
}
void
-Handlers::beginOverlay(JSON)
+Handlers::beginOverlay(JSON j)
{
this->c_uo = c_main->overlay();
+ beginUnderOverlay(j);
}
void
@@ -514,7 +537,8 @@ Handlers::endOverlay()
void
Handlers::setupOverlayFile()
{
- addParameter([this](char const* p) { c_uo->file(p); });
+ // This is handled in beginOverlay since file() has to be called first.
+ ignoreItem();
}
void
@@ -524,9 +548,10 @@ Handlers::setupOverlayPassword()
}
void
-Handlers::beginUnderlay(JSON)
+Handlers::beginUnderlay(JSON j)
{
this->c_uo = c_main->underlay();
+ beginUnderOverlay(j);
}
void
@@ -539,7 +564,8 @@ Handlers::endUnderlay()
void
Handlers::setupUnderlayFile()
{
- addParameter([this](char const* p) { c_uo->file(p); });
+ // This is handled in beginUnderlay since file() has to be called first.
+ ignoreItem();
}
void