Skip to content

Commit

Permalink
Hide zlib and expat libs from the user of Poco libraries (replaces #4579
Browse files Browse the repository at this point in the history
) (#4724)

* foundation: Remove unused ucp.h

Nothing use this and it is not even included in Visual Studio project
files. Remove it so it will not confuse any more.

* foundation: Hide zlib from user

Hide zlib completly from user. This way we do not need to publish zlib.h
or zconfig.h.

As we now have two different pointer initalizing in constructor I choose
to use unique pointers so it is more obvious those are safe. I also
choose to use make_unique which default initalize z_stream_t. This makes
code more readable as we do not need to specifie every field of
z_stream_t. It really should not matter much if we initialize couple
field for nothing. If does we should add comment about that. Still
keeping _buffer without inializing as it is quite big.

* xml: Hide expat and ParserEngine from user

Hide expat completly from user. This way we do not need to publish
expat.h or expat_external.h.

I move also headers to orignal locations so diff is smaller compared to
original.

* chore(Foundation): Compression level constants

---------

Co-authored-by: Kari Argillander <[email protected]>
  • Loading branch information
matejk and Kari Argillander authored Oct 4, 2024
1 parent af3b3b1 commit aab4058
Show file tree
Hide file tree
Showing 24 changed files with 248 additions and 512 deletions.
6 changes: 0 additions & 6 deletions Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ else()
src/pcre2_xclass.c
)

# zlib
POCO_HEADERS(SRCS zlib
include/Poco/zconf.h
include/Poco/zlib.h
)

POCO_SOURCES(SRCS zlib
src/adler32.c
src/compress.c
Expand Down
36 changes: 22 additions & 14 deletions Foundation/include/Poco/DeflatingStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
#if defined(POCO_UNBUNDLED)
#include <zlib.h>
#else
#include "Poco/zlib.h"
#endif

struct z_stream_s;


namespace Poco {
Expand All @@ -47,6 +44,17 @@ class Foundation_API DeflatingStreamBuf: public BufferedStreamBuf
STREAM_GZIP /// Create a gzip header, use CRC-32 checksum.
};

enum CompressionLevel
/// Constants for compression levels.
/// Note to maintainers: These must be kept in sync with the constants
/// defined by zlib.
{
DEFAULT_COMPRESSION = -1,
NO_COMPRESSION = 0,
BEST_SPEED = 1,
BEST_COMPRESSION = 9
};

DeflatingStreamBuf(std::istream& istr, StreamType type, int level);
/// Creates a DeflatingStreamBuf for compressing data read
/// from the given input stream.
Expand Down Expand Up @@ -89,11 +97,11 @@ class Foundation_API DeflatingStreamBuf: public BufferedStreamBuf
DEFLATE_BUFFER_SIZE = 32768
};

std::istream* _pIstr;
std::ostream* _pOstr;
char* _buffer;
z_stream _zstr;
bool _eof;
std::istream* _pIstr;
std::ostream* _pOstr;
char* _buffer;
z_stream_s* _pZstr;
bool _eof;
};


Expand All @@ -104,7 +112,7 @@ class Foundation_API DeflatingIOS: public virtual std::ios
/// order of the stream buffer and base classes.
{
public:
DeflatingIOS(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
DeflatingIOS(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = DeflatingStreamBuf::DEFAULT_COMPRESSION);
/// Creates a DeflatingIOS for compressing data passed
/// through and forwarding it to the given output stream.

Expand All @@ -115,7 +123,7 @@ class Foundation_API DeflatingIOS: public virtual std::ios
/// Please refer to the zlib documentation of deflateInit2() for a description
/// of the windowBits parameter.

DeflatingIOS(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
DeflatingIOS(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = DeflatingStreamBuf::DEFAULT_COMPRESSION);
/// Creates a DeflatingIOS for compressing data read
/// from the given input stream.

Expand Down Expand Up @@ -150,7 +158,7 @@ class Foundation_API DeflatingOutputStream: public std::ostream, public Deflatin
/// ostr.close();
{
public:
DeflatingOutputStream(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
DeflatingOutputStream(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = DeflatingStreamBuf::DEFAULT_COMPRESSION);
/// Creates a DeflatingOutputStream for compressing data passed
/// through and forwarding it to the given output stream.

Expand Down Expand Up @@ -179,7 +187,7 @@ class Foundation_API DeflatingInputStream: public std::istream, public Deflating
/// using zlib's deflate algorithm.
{
public:
DeflatingInputStream(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
DeflatingInputStream(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = DeflatingStreamBuf::DEFAULT_COMPRESSION);
/// Creates a DeflatingIOS for compressing data read
/// from the given input stream.

Expand Down
19 changes: 8 additions & 11 deletions Foundation/include/Poco/InflatingStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
#if defined(POCO_UNBUNDLED)
#include <zlib.h>
#else
#include "Poco/zlib.h"
#endif

struct z_stream_s;


namespace Poco {
Expand Down Expand Up @@ -92,12 +89,12 @@ class Foundation_API InflatingStreamBuf: public BufferedStreamBuf
INFLATE_BUFFER_SIZE = 32768
};

std::istream* _pIstr;
std::ostream* _pOstr;
char* _buffer;
z_stream _zstr;
bool _eof;
bool _check;
std::istream* _pIstr;
std::ostream* _pOstr;
char* _buffer;
z_stream_s* _pZstr;
bool _eof;
bool _check;
};


Expand Down
2 changes: 1 addition & 1 deletion Foundation/src/Checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#if defined(POCO_UNBUNDLED)
#include <zlib.h>
#else
#include "Poco/zlib.h"
#include "zlib.h"
#endif


Expand Down
Loading

0 comments on commit aab4058

Please sign in to comment.