Results 1 to 2 of 2

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

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Why QSslSocket not support DEFLATE algoritmus ? and other module by qt having zlib..

    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?


    Qt Code:
    1. // From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply_p.h
    2. static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header
    3. // gzip flag byte
    4. #define HEAD_CRC 0x02 // bit 1 set: header CRC present
    5. #define EXTRA_FIELD 0x04 // bit 2 set: extra field present
    6. #define ORIG_NAME 0x08 // bit 3 set: original file name present
    7. #define COMMENT 0x10 // bit 4 set: file comment present
    8. #define RESERVED 0xE0 // bits 5..7: reserved
    9. #define CHUNK 16384
    10.  
    11. // From qtsdk-2010.05/qt/src/network/access/qhttpnetworkreply.cpp
    12. // && bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos) same file
    13. /// bool ClientParser::gzipCheckHeader(QByteArray &content, int &pos)
    14.  
    15. void ClientHandler::compressResponse(const QByteArray& uncompressed, QByteArray& deflated )
    16. {
    17. deflated = qCompress(uncompressed);
    18.  
    19. // eliminate qCompress size on first 4 bytes and 2 byte header
    20. deflated = deflated.right(deflated.size() - 6);
    21. // remove qCompress 4 byte footer
    22. deflated = deflated.left(deflated.size() - 4);
    23.  
    24. QByteArray header;
    25. header.resize(10);
    26. header[0] = 0x1f; // gzip-magic[0]
    27. header[1] = 0x8b; // gzip-magic[1]
    28. header[2] = 0x08; // Compression method = DEFLATE
    29. header[3] = 0x00; // Flags
    30. header[4] = 0x00; // 4-7 is mtime
    31. header[5] = 0x00;
    32. header[6] = 0x00;
    33. header[7] = 0x00;
    34. header[8] = 0x00; // XFL
    35. header[9] = 0x03; // OS=Unix
    36.  
    37. deflated.prepend(header);
    38.  
    39. QByteArray footer;
    40. quint32 crc = crc32(0L, Z_NULL, 0);
    41. crc = crc32(crc, (const uchar*)uncompressed.data(), uncompressed.size());
    42. footer.resize(8);
    43. footer[3] = (crc & 0xff000000) >> 24;
    44. footer[2] = (crc & 0x00ff0000) >> 16;
    45. footer[1] = (crc & 0x0000ff00) >> 8;
    46. footer[0] = (crc & 0x000000ff);
    47.  
    48. quint32 isize = uncompressed.size();
    49. footer[7] = (isize & 0xff000000) >> 24;
    50. footer[6] = (isize & 0x00ff0000) >> 16;
    51. footer[5] = (isize & 0x0000ff00) >> 8;
    52. footer[4] = (isize & 0x000000ff);
    53.  
    54. deflated.append(footer);
    55. }
    To copy to clipboard, switch view to plain text mode 

    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...

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why QSslSocket not support DEFLATE algoritmus ? and other module by qt having zl

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    patrik08 (3rd October 2013)

Similar Threads

  1. QSslSocket get SNI
    By Landkeeper in forum Qt Programming
    Replies: 0
    Last Post: 22nd June 2013, 14:04
  2. Replies: 0
    Last Post: 5th August 2012, 01:03
  3. QSslSocket example
    By Ratheendrans in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2011, 20:51
  4. Replies: 1
    Last Post: 6th May 2011, 14:11
  5. Replace -qt-zlib version from 1.2.3 to 1.2.5
    By sandor in forum Installation and Deployment
    Replies: 1
    Last Post: 28th April 2011, 08:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.