PDA

View Full Version : Why QSslSocket not support DEFLATE algoritmus ? and other module by qt having zlib..



patrik08
1st October 2013, 00:37
Qt code having in so many lib zlib compression
On very networkmodule
and on class QZipStreamStrategy : public QOutputStrategy
&& on qtextodfwriter.cpp QTextOdfWriter odt format file..

now Why QSslSocket no?






// From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply_p.h
static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header
// gzip flag byte
#define HEAD_CRC 0x02 // bit 1 set: header CRC present
#define EXTRA_FIELD 0x04 // bit 2 set: extra field present
#define ORIG_NAME 0x08 // bit 3 set: original file name present
#define COMMENT 0x10 // bit 4 set: file comment present
#define RESERVED 0xE0 // bits 5..7: reserved
#define CHUNK 16384

// From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply.cpp
// && bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos) same file
/// bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos)

void ClientHandler::compressResponse(const QByteArray& uncompressed, QByteArray& deflated )
{
deflated = qCompress(uncompressed);

// eliminate qCompress size on first 4 bytes and 2 byte header
deflated = deflated.right(deflated.size() - 6);
// remove qCompress 4 byte footer
deflated = deflated.left(deflated.size() - 4);

QByteArray header;
header.resize(10);
header[0] = 0x1f; // gzip-magic[0]
header[1] = 0x8b; // gzip-magic[1]
header[2] = 0x08; // Compression method = DEFLATE
header[3] = 0x00; // Flags
header[4] = 0x00; // 4-7 is mtime
header[5] = 0x00;
header[6] = 0x00;
header[7] = 0x00;
header[8] = 0x00; // XFL
header[9] = 0x03; // OS=Unix

deflated.prepend(header);

QByteArray footer;
quint32 crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, (const uchar*)uncompressed.data(), uncompressed.size());
footer.resize(8);
footer[3] = (crc & 0xff000000) >> 24;
footer[2] = (crc & 0x00ff0000) >> 16;
footer[1] = (crc & 0x0000ff00) >> 8;
footer[0] = (crc & 0x000000ff);

quint32 isize = uncompressed.size();
footer[7] = (isize & 0xff000000) >> 24;
footer[6] = (isize & 0x00ff0000) >> 16;
footer[5] = (isize & 0x0000ff00) >> 8;
footer[4] = (isize & 0x000000ff);

deflated.append(footer);
}



I ned for imap big mail attachment over socket...
here standard http://www.ietf.org/rfc/rfc4978.txt

The following example illustrates how commands and responses are
compressed during a simple login sequence:

S: * OK [CAPABILITY IMAP4REV1 STARTTLS COMPRESS=DEFLATE]
C: a starttls
S: a OK TLS active

From this point on, everything is encrypted.

C: b login arnt pass27385621
S: b OK Logged in as arnt
C: c compress deflate
S: d OK DEFLATE active

From this point on, everything is compressed before being
encrypted.
now i muss subclass QSslSocket to having inside 20 line code to decompress chunk mail code...
i see on trojita mail client imap defalte ... over 1000 line class Socket subclass to having this 20 line uncompress this is like drugs..
:-( ...
http://trojita.flaska.net/

Note before encrypted!! is on deflate algoritmus... and now how i read this chunk? zlib encrypted.. this is very hot..
sorry my grammar english i like all latino language...
regards...

anda_skoa
1st October 2013, 11:09
QSslSocket, QTcpSocket, QFile, etc. are QIODevices. They provide low level data input/output, i.e. reading and writing blocks of data.
They don't interpret any data.

Applications or libraries using them can do with that data whatever they want, e.g. send it on, process it, discard it.
The application protocol layer knows how to interpret the data, in the case of IMAP it knows about tags and request and responses. And it is the one which has to know about compression and is the one that needs to handle it or pass this again on to the next layer.

Doing that has the additional advantage of separating transport from protocol, so each can be tested separately, or replaced, etc.

The code snippet you posted is doing exactly that.

Cheers,
_