mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-30 18:38:52 +00:00
Add new Pl_String Pipeline
This commit is contained in:
parent
16139d97c8
commit
f4206a0938
@ -1,5 +1,8 @@
|
||||
2022-05-03 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* Add new Pipeline class Pl_String which appends to a std::string&
|
||||
passed to it at construction.
|
||||
|
||||
* Add new Pipeline class Pl_OStream, similar to Pl_StdioFile but
|
||||
takes a std::ostream instead of a FILE*.
|
||||
|
||||
|
3
TODO
3
TODO
@ -46,9 +46,6 @@ Output JSON v2
|
||||
----
|
||||
notes from 5/2:
|
||||
|
||||
Need new pipelines:
|
||||
* Pl_String to std::string with semantics like Pl_Buffer
|
||||
|
||||
See if I can change all output and error messages issued by the
|
||||
library, when context is available, to have a pipeline rather than a
|
||||
FILE* or std::ostream. This makes it possible for people to capture
|
||||
|
63
include/qpdf/Pl_String.hh
Normal file
63
include/qpdf/Pl_String.hh
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2005-2022 Jay Berkenbilt
|
||||
//
|
||||
// This file is part of qpdf.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Versions of qpdf prior to version 7 were released under the terms
|
||||
// of version 2.0 of the Artistic License. At your option, you may
|
||||
// continue to consider qpdf to be licensed under those terms. Please
|
||||
// see the manual for additional information.
|
||||
|
||||
// End-of-line pipeline that simply writes its data to a stdio FILE* object.
|
||||
|
||||
#ifndef PL_STRING_HH
|
||||
#define PL_STRING_HH
|
||||
|
||||
#include <qpdf/Pipeline.hh>
|
||||
|
||||
#include <string>
|
||||
|
||||
class QPDF_DLL_CLASS Pl_String: public Pipeline
|
||||
{
|
||||
public:
|
||||
QPDF_DLL
|
||||
Pl_String(char const* identifier, std::string& s);
|
||||
QPDF_DLL
|
||||
virtual ~Pl_String();
|
||||
|
||||
QPDF_DLL
|
||||
virtual void write(unsigned char const* buf, size_t len);
|
||||
QPDF_DLL
|
||||
virtual void finish();
|
||||
|
||||
private:
|
||||
class QPDF_DLL_PRIVATE Members
|
||||
{
|
||||
friend class Pl_String;
|
||||
|
||||
public:
|
||||
QPDF_DLL
|
||||
~Members() = default;
|
||||
|
||||
private:
|
||||
Members(std::string&);
|
||||
Members(Members const&) = delete;
|
||||
|
||||
std::string& s;
|
||||
};
|
||||
|
||||
std::shared_ptr<Members> m;
|
||||
};
|
||||
|
||||
#endif // PL_STRING_HH
|
@ -51,6 +51,7 @@ set(libqpdf_SOURCES
|
||||
Pl_RunLength.cc
|
||||
Pl_SHA2.cc
|
||||
Pl_StdioFile.cc
|
||||
Pl_String.cc
|
||||
Pl_TIFFPredictor.cc
|
||||
QPDF.cc
|
||||
QPDFAcroFormDocumentHelper.cc
|
||||
|
33
libqpdf/Pl_String.cc
Normal file
33
libqpdf/Pl_String.cc
Normal file
@ -0,0 +1,33 @@
|
||||
#include <qpdf/Pl_String.hh>
|
||||
|
||||
#include <qpdf/QUtil.hh>
|
||||
#include <errno.h>
|
||||
#include <stdexcept>
|
||||
|
||||
Pl_String::Members::Members(std::string& s) :
|
||||
s(s)
|
||||
{
|
||||
}
|
||||
|
||||
Pl_String::Pl_String(char const* identifier, std::string& s) :
|
||||
Pipeline(identifier, 0),
|
||||
m(new Members(s))
|
||||
{
|
||||
}
|
||||
|
||||
Pl_String::~Pl_String()
|
||||
{
|
||||
// Must be explicit and not inline -- see QPDF_DLL_CLASS in
|
||||
// README-maintainer
|
||||
}
|
||||
|
||||
void
|
||||
Pl_String::write(unsigned char const* buf, size_t len)
|
||||
{
|
||||
this->m->s.append(reinterpret_cast<char const*>(buf), len);
|
||||
}
|
||||
|
||||
void
|
||||
Pl_String::finish()
|
||||
{
|
||||
}
|
@ -120,6 +120,9 @@ For a detailed list of changes, please see the file
|
||||
- Add new ``Pipeline`` type ``Pl_OStream`` to write to a
|
||||
``std::ostream``.
|
||||
|
||||
- Add new ``Pipeline`` type ``Pl_String`` to append to a
|
||||
``std::string``.
|
||||
|
||||
- Other changes
|
||||
|
||||
- A new chapter on contributing to qpdf has been added to the
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <qpdf/Pl_QPDFTokenizer.hh>
|
||||
#include <qpdf/Pl_RunLength.hh>
|
||||
#include <qpdf/Pl_StdioFile.hh>
|
||||
#include <qpdf/Pl_String.hh>
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QPDFAcroFormDocumentHelper.hh>
|
||||
#include <qpdf/QPDFAnnotationObjectHelper.hh>
|
||||
@ -80,6 +81,7 @@ main()
|
||||
print_size(Pl_QPDFTokenizer);
|
||||
print_size(Pl_RunLength);
|
||||
print_size(Pl_StdioFile);
|
||||
print_size(Pl_String);
|
||||
print_size(QPDF);
|
||||
print_size(QPDFAcroFormDocumentHelper);
|
||||
print_size(QPDFAnnotationObjectHelper);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <qpdf/Pl_Discard.hh>
|
||||
#include <qpdf/Pl_Flate.hh>
|
||||
#include <qpdf/Pl_StdioFile.hh>
|
||||
#include <qpdf/Pl_String.hh>
|
||||
#include <qpdf/QIntC.hh>
|
||||
#include <qpdf/QPDFAcroFormDocumentHelper.hh>
|
||||
#include <qpdf/QPDFEmbeddedFileDocumentHelper.hh>
|
||||
@ -435,16 +436,13 @@ test_6(QPDF& pdf, char const* arg2)
|
||||
if (!metadata.isStream()) {
|
||||
throw std::logic_error("test 6 run on file with no metadata");
|
||||
}
|
||||
Pl_Buffer bufpl("buffer");
|
||||
std::string buf;
|
||||
Pl_String bufpl("buffer", buf);
|
||||
metadata.pipeStreamData(&bufpl, 0, qpdf_dl_none);
|
||||
Buffer* buf = bufpl.getBuffer();
|
||||
unsigned char const* data = buf->getBuffer();
|
||||
bool cleartext = false;
|
||||
if ((buf->getSize() > 9) &&
|
||||
(strncmp(reinterpret_cast<char const*>(data), "<?xpacket", 9) == 0)) {
|
||||
if (buf.substr(0, 9) == "<?xpacket") {
|
||||
cleartext = true;
|
||||
}
|
||||
delete buf;
|
||||
std::cout << "encrypted=" << (pdf.isEncrypted() ? 1 : 0)
|
||||
<< "; cleartext=" << (cleartext ? 1 : 0) << std::endl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user