aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <jberkenbilt@users.noreply.github.com>2023-04-02 15:01:26 +0200
committerGitHub <noreply@github.com>2023-04-02 15:01:26 +0200
commit230f1ab29039c30c5974d17ddcb0667ceedccf79 (patch)
tree3b1f1269122f88b316338a5c99046ae0e4077ae6 /libqpdf
parentf8e39253be9d1806ccdb88d8117b7418f2045da1 (diff)
parent41f79bedbc1ebc2666471ec97b87999410242973 (diff)
downloadqpdf-230f1ab29039c30c5974d17ddcb0667ceedccf79.tar.zst
Merge pull request #933 from m-holger/c_job
C-API : expose QPDFJob::createQPDF and writeQPDF
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/qpdf-c.cc45
-rw-r--r--libqpdf/qpdf/qpdf-c_impl.hh47
-rw-r--r--libqpdf/qpdfjob-c.cc25
3 files changed, 73 insertions, 44 deletions
diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc
index cb104c73..01987365 100644
--- a/libqpdf/qpdf-c.cc
+++ b/libqpdf/qpdf-c.cc
@@ -12,6 +12,7 @@
#include <qpdf/QPDFWriter.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh>
+#include <qpdf/qpdf-c_impl.hh>
#include <qpdf/qpdflogger-c_impl.hh>
#include <cstring>
@@ -20,50 +21,6 @@
#include <stdexcept>
#include <string>
-struct _qpdf_error
-{
- std::shared_ptr<QPDFExc> exc;
-};
-
-struct _qpdf_data
-{
- _qpdf_data();
- ~_qpdf_data() = default;
-
- std::shared_ptr<QPDF> qpdf;
- std::shared_ptr<QPDFWriter> qpdf_writer;
-
- std::shared_ptr<QPDFExc> error;
- _qpdf_error tmp_error;
- std::list<QPDFExc> warnings;
- std::string tmp_string;
-
- // Parameters for functions we call
- char const* filename; // or description
- char const* buffer;
- unsigned long long size;
- char const* password;
- bool write_memory;
- std::shared_ptr<Buffer> output_buffer;
-
- // QPDFObjectHandle support
- bool silence_errors;
- bool oh_error_occurred;
- std::map<qpdf_oh, std::shared_ptr<QPDFObjectHandle>> oh_cache;
- qpdf_oh next_oh;
- std::set<std::string> cur_iter_dict_keys;
- std::set<std::string>::const_iterator dict_iter;
- std::string cur_dict_key;
-};
-
-_qpdf_data::_qpdf_data() :
- write_memory(false),
- silence_errors(false),
- oh_error_occurred(false),
- next_oh(0)
-{
-}
-
// must set qpdf->filename and qpdf->password
static void
call_read(qpdf_data qpdf)
diff --git a/libqpdf/qpdf/qpdf-c_impl.hh b/libqpdf/qpdf/qpdf-c_impl.hh
new file mode 100644
index 00000000..0d52cf10
--- /dev/null
+++ b/libqpdf/qpdf/qpdf-c_impl.hh
@@ -0,0 +1,47 @@
+#include <qpdf/qpdf-c.h>
+
+#include <memory>
+
+#include <qpdf/QPDF.hh>
+#include <qpdf/QPDFExc.hh>
+#include <qpdf/QPDFWriter.hh>
+
+struct _qpdf_error
+{
+ std::shared_ptr<QPDFExc> exc;
+};
+
+struct _qpdf_data
+{
+ _qpdf_data() = default;
+
+ _qpdf_data(std::unique_ptr<QPDF>&& qpdf) :
+ qpdf(std::move(qpdf)){};
+
+ ~_qpdf_data() = default;
+
+ std::shared_ptr<QPDF> qpdf;
+ std::shared_ptr<QPDFWriter> qpdf_writer;
+
+ std::shared_ptr<QPDFExc> error;
+ _qpdf_error tmp_error;
+ std::list<QPDFExc> warnings;
+ std::string tmp_string;
+
+ // Parameters for functions we call
+ char const* filename{nullptr}; // or description
+ char const* buffer{nullptr};
+ unsigned long long size{0};
+ char const* password{nullptr};
+ bool write_memory{false};
+ std::shared_ptr<Buffer> output_buffer;
+
+ // QPDFObjectHandle support
+ bool silence_errors{false};
+ bool oh_error_occurred{false};
+ std::map<qpdf_oh, std::shared_ptr<QPDFObjectHandle>> oh_cache;
+ qpdf_oh next_oh{0};
+ std::set<std::string> cur_iter_dict_keys;
+ std::set<std::string>::const_iterator dict_iter;
+ std::string cur_dict_key;
+};
diff --git a/libqpdf/qpdfjob-c.cc b/libqpdf/qpdfjob-c.cc
index 889afec6..ddb33349 100644
--- a/libqpdf/qpdfjob-c.cc
+++ b/libqpdf/qpdfjob-c.cc
@@ -4,6 +4,7 @@
#include <qpdf/QPDFLogger.hh>
#include <qpdf/QPDFUsage.hh>
#include <qpdf/QUtil.hh>
+#include <qpdf/qpdf-c_impl.hh>
#include <qpdf/qpdflogger-c_impl.hh>
#include <cstdio>
@@ -98,6 +99,30 @@ qpdfjob_run(qpdfjob_handle j)
});
}
+qpdf_data
+qpdfjob_create_qpdf(qpdfjob_handle j)
+{
+ QUtil::setLineBuf(stdout);
+ try {
+ auto qpdf = j->j.createQPDF();
+ return qpdf ? new _qpdf_data(std::move(qpdf)) : nullptr;
+ } catch (std::exception& e) {
+ *j->j.getLogger()->getError()
+ << j->j.getMessagePrefix() << ": " << e.what() << "\n";
+ }
+ return nullptr;
+}
+
+int
+qpdfjob_write_qpdf(qpdfjob_handle j, qpdf_data qpdf)
+{
+ QUtil::setLineBuf(stdout);
+ return wrap_qpdfjob(j, [qpdf](qpdfjob_handle jh) {
+ jh->j.writeQPDF(*(qpdf->qpdf));
+ return jh->j.getExitCode();
+ });
+}
+
static int
run_with_handle(std::function<int(qpdfjob_handle)> fn)
{