equal
deleted
inserted
replaced
159 // Set header to accept gzip encoded data |
159 // Set header to accept gzip encoded data |
160 aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding); |
160 aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding); |
161 |
161 |
162 // Set the cache control |
162 // Set the cache control |
163 aRequest.setRawHeader("Cache-Control", kSmfCacheControl); |
163 aRequest.setRawHeader("Cache-Control", kSmfCacheControl); |
164 |
164 |
165 // Put the same user agent for all requests sent by Smf |
165 // Put the same user agent for all requests sent by Smf |
166 aRequest.setRawHeader("User-Agent", kSmfUserAgent); |
166 aRequest.setRawHeader("User-Agent", kSmfUserAgent); |
167 |
167 |
168 QNetworkReply* reply = m_networkAccessManager.get(aRequest); |
168 QNetworkReply* reply = m_networkAccessManager.get(aRequest); |
169 qDebug()<<"QNetworkReply of get() = "<<(long)reply; |
169 qDebug()<<"QNetworkReply of get() = "<<(long)reply; |
599 // If so, inflate the gzip deflated data |
599 // If so, inflate the gzip deflated data |
600 if((QString("1f") == QString(firstByte.toHex())) && (QString("8b") == QString(secondByte.toHex())) ) |
600 if((QString("1f") == QString(firstByte.toHex())) && (QString("8b") == QString(secondByte.toHex())) ) |
601 { |
601 { |
602 gzipEncoded = true; |
602 gzipEncoded = true; |
603 qDebug()<<"Response is gzip encoded!!!"; |
603 qDebug()<<"Response is gzip encoded!!!"; |
604 arr = inflateResponse(response, error); |
604 arr = inflateResponse(response, error); |
605 if(!arr) |
605 if(!arr) |
606 trResult = SmfTransportOpGzipError; |
606 trResult = SmfTransportOpGzipError; |
607 } |
607 } |
608 else |
608 else |
609 { |
609 { |
662 |
662 |
663 // Get the uncompressed size of the response (last 4 bytes of the compressed data as per GZIP format spec) |
663 // Get the uncompressed size of the response (last 4 bytes of the compressed data as per GZIP format spec) |
664 QByteArray sizeStr; |
664 QByteArray sizeStr; |
665 for(int count = 1 ; count <= 4 ; count++) |
665 for(int count = 1 ; count <= 4 ; count++) |
666 sizeStr.append(aResponse[aResponse.size()-count]); |
666 sizeStr.append(aResponse[aResponse.size()-count]); |
|
667 #ifdef DETAILEDDEBUGGING |
667 qDebug()<<"Size string as a string = "<<QString(sizeStr.toHex()); |
668 qDebug()<<"Size string as a string = "<<QString(sizeStr.toHex()); |
|
669 #endif |
668 bool ok = false; |
670 bool ok = false; |
669 int uncomSize = sizeStr.toHex().toInt(&ok, 16); |
671 int uncomSize = sizeStr.toHex().toInt(&ok, 16); |
670 qDebug()<<"Size of uncompressed data = "<<uncomSize; |
672 qDebug()<<"Size of uncompressed data = "<<uncomSize; |
671 |
673 |
672 // Initialize the data required for zlib method call |
674 // Initialize the data required for zlib method call |
686 stream.opaque = Z_NULL; |
688 stream.opaque = Z_NULL; |
687 stream.avail_in = 0; |
689 stream.avail_in = 0; |
688 stream.next_in = Z_NULL; |
690 stream.next_in = Z_NULL; |
689 |
691 |
690 int ret = inflateInit2(&stream, 16+MAX_WBITS); |
692 int ret = inflateInit2(&stream, 16+MAX_WBITS); |
|
693 #ifdef DETAILEDDEBUGGING |
691 qDebug()<<"return value of inflateInit2() = "<<ret; |
694 qDebug()<<"return value of inflateInit2() = "<<ret; |
|
695 #endif |
692 if(Z_OK != ret) |
696 if(Z_OK != ret) |
693 { |
697 { |
694 qDebug()<<"Error in inflateInit2, returning..."; |
698 qDebug()<<"Error in inflateInit2, returning..."; |
695 delete[] out; |
699 delete[] out; |
696 if(Z_STREAM_ERROR == ret) |
700 if(Z_STREAM_ERROR == ret) |
709 stream.next_in = (unsigned char *)aResponse.data(); |
713 stream.next_in = (unsigned char *)aResponse.data(); |
710 stream.avail_out = uncomSize; |
714 stream.avail_out = uncomSize; |
711 stream.next_out = out; |
715 stream.next_out = out; |
712 |
716 |
713 ret = inflate(&stream, Z_NO_FLUSH); |
717 ret = inflate(&stream, Z_NO_FLUSH); |
|
718 #ifdef DETAILEDDEBUGGING |
714 qDebug()<<"return value of inflate() = "<<ret; |
719 qDebug()<<"return value of inflate() = "<<ret; |
|
720 #endif |
715 |
721 |
716 switch (ret) |
722 switch (ret) |
717 { |
723 { |
718 // fall through |
724 // fall through |
719 case Z_NEED_DICT: |
725 case Z_NEED_DICT: |
720 case Z_DATA_ERROR: |
726 case Z_DATA_ERROR: |
721 case Z_MEM_ERROR: |
727 case Z_MEM_ERROR: |
722 { |
728 { |
|
729 qDebug()<<"Error in inflate, returning..."; |
723 (void)inflateEnd(&stream); |
730 (void)inflateEnd(&stream); |
724 delete[] out; |
731 delete[] out; |
725 aError = SmfTMGzipDataError; |
732 aError = SmfTMGzipDataError; |
726 return NULL; |
733 return NULL; |
727 } |
734 } |
734 QByteArray *uncompressedData = new QByteArray((char *)out, stream.total_out); |
741 QByteArray *uncompressedData = new QByteArray((char *)out, stream.total_out); |
735 delete[] out; |
742 delete[] out; |
736 |
743 |
737 // If there is some unwanted data at the end of uncompressed data, chop them |
744 // If there is some unwanted data at the end of uncompressed data, chop them |
738 int chopLength = uncompressedData->size() - uncomSize; |
745 int chopLength = uncompressedData->size() - uncomSize; |
|
746 #ifdef DETAILEDDEBUGGING |
739 qDebug()<<"old size of uncompressed data = "<<uncompressedData->size(); |
747 qDebug()<<"old size of uncompressed data = "<<uncompressedData->size(); |
|
748 #endif |
740 uncompressedData->chop(chopLength); |
749 uncompressedData->chop(chopLength); |
|
750 #ifdef DETAILEDDEBUGGING |
741 qDebug()<<"new size of uncompressed data = "<<uncompressedData->size(); |
751 qDebug()<<"new size of uncompressed data = "<<uncompressedData->size(); |
|
752 #endif |
742 |
753 |
743 return uncompressedData; |
754 return uncompressedData; |
744 } |
755 } |
745 |
756 |
746 |
757 |
776 int mem_level = 8; |
787 int mem_level = 8; |
777 int strategy = Z_DEFAULT_STRATEGY; |
788 int strategy = Z_DEFAULT_STRATEGY; |
778 |
789 |
779 // Call deflateInit2 for gzip compression initialization |
790 // Call deflateInit2 for gzip compression initialization |
780 int initError = deflateInit2(&stream, level, method, windowBits, mem_level, strategy); |
791 int initError = deflateInit2(&stream, level, method, windowBits, mem_level, strategy); |
|
792 #ifdef DETAILEDDEBUGGING |
781 qDebug()<<"Return value of deflateInit2() = "<<initError; |
793 qDebug()<<"Return value of deflateInit2() = "<<initError; |
782 qDebug()<<"Error msg if any = "<<QString(zError(initError)); |
794 qDebug()<<"Error msg if any = "<<QString(zError(initError)); |
|
795 #endif |
783 |
796 |
784 if(Z_OK != initError) |
797 if(Z_OK != initError) |
785 { |
798 { |
786 qDebug()<<"deflateInit2() failed, returning error = "<<QString(zError(initError)); |
799 qDebug()<<"deflateInit2() failed, returning error = "<<QString(zError(initError)); |
787 |
800 |