aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libqpdf/QPDFJob_json.cc40
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf/bad-json-overlay-no-file.json5
-rw-r--r--qpdf/qtest/qpdf/bad-overlay-no-file-json.out10
-rw-r--r--qpdf/qtest/qpdfjob.test1
5 files changed, 50 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
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index 8d242f43..397cbf97 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -691,3 +691,4 @@ QPDFPageDocumentHelper flatten resources missing or invalid 0
QPDF recover xref stream 0
QPDFJob misplaced page range 0
QPDFJob duplicated range 0
+QPDFJob json over/under no file 0
diff --git a/qpdf/qtest/qpdf/bad-json-overlay-no-file.json b/qpdf/qtest/qpdf/bad-json-overlay-no-file.json
new file mode 100644
index 00000000..25d5a2f6
--- /dev/null
+++ b/qpdf/qtest/qpdf/bad-json-overlay-no-file.json
@@ -0,0 +1,5 @@
+{
+ "overlay": {
+ "to": "1-z"
+ }
+}
diff --git a/qpdf/qtest/qpdf/bad-overlay-no-file-json.out b/qpdf/qtest/qpdf/bad-overlay-no-file-json.out
new file mode 100644
index 00000000..63d98c59
--- /dev/null
+++ b/qpdf/qtest/qpdf/bad-overlay-no-file-json.out
@@ -0,0 +1,10 @@
+
+qpdf: error with job-json file bad-json-overlay-no-file.json: file is required in underlay/overlay specification
+Run qpdf --job-json-help for information on the file format.
+
+For help:
+ qpdf --help=usage usage information
+ qpdf --help=topic help on a topic
+ qpdf --help=--option help on an option
+ qpdf --help general help and a topic list
+
diff --git a/qpdf/qtest/qpdfjob.test b/qpdf/qtest/qpdfjob.test
index 57ad608a..f1ef942f 100644
--- a/qpdf/qtest/qpdfjob.test
+++ b/qpdf/qtest/qpdfjob.test
@@ -26,6 +26,7 @@ my @bad_json = (
"encrypt-missing-password",
"encrypt-no-key-length",
"pages-no-file",
+ "overlay-no-file",
"schema-error",
"json-error"
);