diff options
author | aavit <qt_aavit@ovi.com> | 2012-06-06 15:16:49 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-08 00:53:10 +0200 |
commit | 1f461ac45bfa8887261510a95fb33a346d68eaba (patch) | |
tree | 031911dd37be3545f1243e84b5dbc101c7294f79 /src/network | |
parent | 02191b6e4b03fe05b1b953b3e5d5e456cc5817c9 (diff) |
Namespace the bundled zlib symbols, to avoid clash with user zlib
When Qt is being compiled and is using the bundled zlib, QtCore needs
to export the zlib symbols, since zlib is needed in other Qt
libraries as well. That gives a danger of a potentially disastrous
symbol clash if the user later on links with both Qt and an external
zlib (ref. e.g. QTBUG-15071).
This commit enables a zlib compilation flag that causes all zlib
symbols to be redefined with a prefix. Hence, they will not clash
with a standard zlib.
A minor drawback is that zlib.h will now have #defines for a few
semi-normal identifiers. Hence, a couple of more changes are done:
In the private qzip code, the identifer crc32 had to be renamed.
QHttpNetworkReplyPrivate needed no change, but as a defensive measure
the #include <zlib.h> is moved from the _p.h file to the .cpp file,
to avoid surprising compilation errors later in code that include
that header.
This commit does not in itself solve the issue of how to let Qt
libraries outside of qtbase use the same bundled zlib, but it is
a prerequisite for that.
Change-Id: If84105901a8c90d35009faffe660c85a6bd2fee5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 71 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkreply_p.h | 12 |
2 files changed, 50 insertions, 33 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 8c8c834042..dc6f9972b3 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -52,6 +52,10 @@ # include <QtNetwork/qsslconfiguration.h> #endif +#ifndef QT_NO_COMPRESS +#include <zlib.h> +#endif + QT_BEGIN_NAMESPACE QHttpNetworkReply::QHttpNetworkReply(const QUrl &url, QObject *parent) @@ -67,8 +71,8 @@ QHttpNetworkReply::~QHttpNetworkReply() } #ifndef QT_NO_COMPRESS - if (d->autoDecompress && d->isCompressed()) - inflateEnd(&d->inflateStrm); + if (d->autoDecompress && d->isCompressed() && d->inflateStrm) + inflateEnd(d->inflateStrm); #endif } @@ -281,11 +285,19 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl) autoDecompress(false), responseData(), requestIsPrepared(false) ,pipeliningUsed(false), downstreamLimited(false) ,userProvidedDownloadBuffer(0) +#ifndef QT_NO_COMPRESS + ,inflateStrm(0) +#endif + { } QHttpNetworkReplyPrivate::~QHttpNetworkReplyPrivate() { +#ifndef QT_NO_COMPRESS + if (inflateStrm) + delete inflateStrm; +#endif } void QHttpNetworkReplyPrivate::clearHttpLayerInformation() @@ -300,8 +312,8 @@ void QHttpNetworkReplyPrivate::clearHttpLayerInformation() lastChunkRead = false; connectionCloseEnabled = true; #ifndef QT_NO_COMPRESS - if (autoDecompress) - inflateEnd(&inflateStrm); + if (autoDecompress && inflateStrm) + inflateEnd(inflateStrm); #endif fields.clear(); } @@ -530,15 +542,17 @@ qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) #ifndef QT_NO_COMPRESS if (autoDecompress && isCompressed()) { // allocate inflate state - inflateStrm.zalloc = Z_NULL; - inflateStrm.zfree = Z_NULL; - inflateStrm.opaque = Z_NULL; - inflateStrm.avail_in = 0; - inflateStrm.next_in = Z_NULL; + if (!inflateStrm) + inflateStrm = new z_stream; + inflateStrm->zalloc = Z_NULL; + inflateStrm->zfree = Z_NULL; + inflateStrm->opaque = Z_NULL; + inflateStrm->avail_in = 0; + inflateStrm->next_in = Z_NULL; // "windowBits can also be greater than 15 for optional gzip decoding. // Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection" // http://www.zlib.net/manual.html - int ret = inflateInit2(&inflateStrm, MAX_WBITS+32); + int ret = inflateInit2(inflateStrm, MAX_WBITS+32); if (ret != Z_OK) return -1; } @@ -685,47 +699,50 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QByteDataBuff #ifndef QT_NO_COMPRESS qint64 QHttpNetworkReplyPrivate::uncompressBodyData(QByteDataBuffer *in, QByteDataBuffer *out) { + if (!inflateStrm) + return -1; + bool triedRawDeflate = false; for (int i = 0; i < in->bufferCount(); i++) { QByteArray &bIn = (*in)[i]; - inflateStrm.avail_in = bIn.size(); - inflateStrm.next_in = reinterpret_cast<Bytef*>(bIn.data()); + inflateStrm->avail_in = bIn.size(); + inflateStrm->next_in = reinterpret_cast<Bytef*>(bIn.data()); do { QByteArray bOut; // make a wild guess about the uncompressed size. - bOut.reserve(inflateStrm.avail_in * 3 + 512); - inflateStrm.avail_out = bOut.capacity(); - inflateStrm.next_out = reinterpret_cast<Bytef*>(bOut.data()); + bOut.reserve(inflateStrm->avail_in * 3 + 512); + inflateStrm->avail_out = bOut.capacity(); + inflateStrm->next_out = reinterpret_cast<Bytef*>(bOut.data()); - int ret = inflate(&inflateStrm, Z_NO_FLUSH); + int ret = inflate(inflateStrm, Z_NO_FLUSH); //All negative return codes are errors, in the context of HTTP compression, Z_NEED_DICT is also an error. // in the case where we get Z_DATA_ERROR this could be because we recieved raw deflate compressed data. if (ret == Z_DATA_ERROR && !triedRawDeflate) { - inflateEnd(&inflateStrm); + inflateEnd(inflateStrm); triedRawDeflate = true; - inflateStrm.zalloc = Z_NULL; - inflateStrm.zfree = Z_NULL; - inflateStrm.opaque = Z_NULL; - inflateStrm.avail_in = 0; - inflateStrm.next_in = Z_NULL; - int ret = inflateInit2(&inflateStrm, -MAX_WBITS); + inflateStrm->zalloc = Z_NULL; + inflateStrm->zfree = Z_NULL; + inflateStrm->opaque = Z_NULL; + inflateStrm->avail_in = 0; + inflateStrm->next_in = Z_NULL; + int ret = inflateInit2(inflateStrm, -MAX_WBITS); if (ret != Z_OK) { return -1; } else { - inflateStrm.avail_in = bIn.size(); - inflateStrm.next_in = reinterpret_cast<Bytef*>(bIn.data()); + inflateStrm->avail_in = bIn.size(); + inflateStrm->next_in = reinterpret_cast<Bytef*>(bIn.data()); continue; } } else if (ret < 0 || ret == Z_NEED_DICT) { return -1; } - bOut.resize(bOut.capacity() - inflateStrm.avail_out); + bOut.resize(bOut.capacity() - inflateStrm->avail_out); out->append(bOut); if (ret == Z_STREAM_END) return out->byteAmount(); - } while (inflateStrm.avail_in > 0); + } while (inflateStrm->avail_in > 0); } return out->byteAmount(); diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index b3c16a8258..75139f474b 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -56,7 +56,7 @@ #ifndef QT_NO_HTTP #ifndef QT_NO_COMPRESS -#include <zlib.h> +struct z_stream_s; #endif #include <QtNetwork/qtcpsocket.h> @@ -227,11 +227,6 @@ public: QPointer<QHttpNetworkConnection> connection; QPointer<QHttpNetworkConnectionChannel> connectionChannel; -#ifndef QT_NO_COMPRESS - z_stream inflateStrm; - qint64 uncompressBodyData(QByteDataBuffer *in, QByteDataBuffer *out); -#endif - bool autoDecompress; QByteDataBuffer responseData; // uncompressed body @@ -242,6 +237,11 @@ public: bool downstreamLimited; char* userProvidedDownloadBuffer; + +#ifndef QT_NO_COMPRESS + z_stream_s *inflateStrm; + qint64 uncompressBodyData(QByteDataBuffer *in, QByteDataBuffer *out); +#endif }; |