2023-02-25 19:18:13 +00:00
|
|
|
// Copyright (c) 2005-2023 Jay Berkenbilt
|
2008-04-29 12:55:25 +00:00
|
|
|
//
|
2017-09-14 16:44:31 +00:00
|
|
|
// 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.
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#ifndef PL_BUFFER_HH
|
|
|
|
#define PL_BUFFER_HH
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// This pipeline accumulates the data passed to it into a memory buffer. Each subsequent use of
|
|
|
|
// this buffer appends to the data accumulated so far. getBuffer() may be called only after calling
|
|
|
|
// finish() and before calling any subsequent write(). At that point, a dynamically allocated
|
2009-02-21 02:54:31 +00:00
|
|
|
// Buffer object is returned and the internal buffer is reset. The caller is responsible for
|
2008-04-29 12:55:25 +00:00
|
|
|
// deleting the returned Buffer.
|
|
|
|
//
|
|
|
|
// For this pipeline, "next" may be null. If a next pointer is provided, this pipeline will also
|
|
|
|
// pass the data through to it.
|
|
|
|
|
|
|
|
#include <qpdf/Buffer.hh>
|
|
|
|
#include <qpdf/Pipeline.hh>
|
2022-09-23 19:15:39 +00:00
|
|
|
#include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785)
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-02-06 16:40:24 +00:00
|
|
|
#include <memory>
|
2023-08-22 20:44:58 +00:00
|
|
|
#include <vector>
|
2022-02-06 16:40:24 +00:00
|
|
|
|
2022-04-10 13:29:11 +00:00
|
|
|
class QPDF_DLL_CLASS Pl_Buffer: public Pipeline
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2023-05-20 11:46:50 +00:00
|
|
|
Pl_Buffer(char const* identifier, Pipeline* next = nullptr);
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2023-05-20 13:25:46 +00:00
|
|
|
~Pl_Buffer() override;
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2023-05-20 13:25:46 +00:00
|
|
|
void write(unsigned char const*, size_t) override;
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2023-05-20 13:25:46 +00:00
|
|
|
void finish() override;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// Each call to getBuffer() resets this object -- see notes above.
|
|
|
|
// The caller is responsible for deleting the returned Buffer object. See also
|
2022-02-06 17:30:18 +00:00
|
|
|
// getBufferSharedPointer() and getMallocBuffer().
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2008-04-29 12:55:25 +00:00
|
|
|
Buffer* getBuffer();
|
|
|
|
|
2022-02-06 17:30:18 +00:00
|
|
|
// Same as getBuffer but wraps the result in a shared pointer.
|
|
|
|
QPDF_DLL
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<Buffer> getBufferSharedPointer();
|
2022-02-06 17:30:18 +00:00
|
|
|
|
2021-12-17 12:33:42 +00:00
|
|
|
// getMallocBuffer behaves in the same was as getBuffer except the buffer is allocated with
|
|
|
|
// malloc(), making it suitable for use when calling from other languages. If there is no data,
|
|
|
|
// *buf is set to a null pointer and *len is set to 0. Otherwise, *buf is a buffer of size *len
|
|
|
|
// allocated with malloc(). It is the caller's responsibility to call free() on the buffer.
|
|
|
|
QPDF_DLL
|
|
|
|
void getMallocBuffer(unsigned char** buf, size_t* len);
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
private:
|
2022-04-10 13:29:11 +00:00
|
|
|
class QPDF_DLL_PRIVATE Members
|
2019-06-22 01:32:47 +00:00
|
|
|
{
|
|
|
|
friend class Pl_Buffer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QPDF_DLL
|
2022-04-15 23:44:07 +00:00
|
|
|
~Members() = default;
|
2019-06-22 01:32:47 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-23 11:46:54 +00:00
|
|
|
Members() = default;
|
2022-04-15 23:44:07 +00:00
|
|
|
Members(Members const&) = delete;
|
2019-06-22 01:32:47 +00:00
|
|
|
|
2022-09-23 11:46:54 +00:00
|
|
|
bool ready{true};
|
2023-08-22 20:44:58 +00:00
|
|
|
std::vector<unsigned char> data;
|
2019-06-22 01:32:47 +00:00
|
|
|
};
|
|
|
|
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<Members> m;
|
2008-04-29 12:55:25 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // PL_BUFFER_HH
|