From 8e0b15333228ab973571eec498af41d3cbb8ab63 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 10 Dec 2021 13:37:01 -0500 Subject: [PATCH] Expose QPDFObjectHandle::addTokenFilter (fixes #580) --- ChangeLog | 4 ++++ include/qpdf/QPDFObjectHandle.hh | 1 + qpdf/test_driver.cc | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 341ae8e4..9efbdc15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-12-10 Jay Berkenbilt + * Add missing QPDF_DLL to QPDFObjectHandle::addTokenFilter so that + it is actually accessible as part of the public interface as + intended. Fixes #580. + * C API: Overhaul how errors are handle the C API's object handle interfaces. Clarify documentation regarding object accessors and how type errors and warnings are handled. Many cases that used to diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 31afd01b..ccc3993e 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -456,6 +456,7 @@ class QPDFObjectHandle // be applied to a page object, and which will automatically // handle the case of pages whose contents are split across // multiple streams. + QPDF_DLL void addTokenFilter(PointerHolder token_filter); // Legacy helpers for parsing content streams. These methods are diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 613dc5bd..d4bfe2af 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -2704,14 +2704,27 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "--- parseContents ---" << std::endl; ParserCallbacks cb; fx1.parseContents(&cb); - Pl_Buffer b("buffer"); - fx1.addContentTokenFilter(new TokenFilter); - fx1.pipeContents(&b); - std::unique_ptr buf(b.getBuffer()); - std::string s( - reinterpret_cast(buf->getBuffer()), - buf->getSize()); - assert(s.find("/bye") != std::string::npos); + // Do this once with addContentTokenFilter and once with + // addTokenFilter to show that they are the same and to ensure + // that addTokenFilter is directly exercised in testing. + for (int i = 0; i < 2; i++) + { + Pl_Buffer b("buffer"); + if (i == 0) + { + fx1.addContentTokenFilter(new TokenFilter); + } + else + { + fx1.getObjectHandle().addTokenFilter(new TokenFilter); + } + fx1.pipeContents(&b); + std::unique_ptr buf(b.getBuffer()); + std::string s( + reinterpret_cast(buf->getBuffer()), + buf->getSize()); + assert(s.find("/bye") != std::string::npos); + } } else if (n == 73) {