smf/smfservermodule/smfserver/transportmgr/smftransportmanagerutil.cpp
changeset 14 a469c0e6e7fb
parent 7 be09cf1f39dd
child 18 013a02bf2bb0
--- a/smf/smfservermodule/smfserver/transportmgr/smftransportmanagerutil.cpp	Mon Jun 07 11:43:45 2010 +0100
+++ b/smf/smfservermodule/smfserver/transportmgr/smftransportmanagerutil.cpp	Wed Jun 23 19:51:49 2010 +0530
@@ -19,12 +19,16 @@
  */
 
 // Include files
+#define EMULATORTESTING
+
 #include <QNetworkAccessManager>
 #include <QNetworkReply>
 #include <QSettings>
 #include <zlib.h>
+#ifdef EMULATORTESTING
 // For proxy settings on emulator only - REMOVE for device
 #include <QNetworkProxy>
+#endif
 
 #include "smftransportmanagerutil.h"
 #include "smfpluginmanager.h"
@@ -63,6 +67,43 @@
 		m_settings->setValue("Sent Data", 0);
 	if( !m_settings->contains("Received Data") )
 		m_settings->setValue("Received Data", 0);
+	
+#ifdef EMULATORTESTING
+	qDebug()<<"Using PROXY SETTINGS!!!, change for device settings";
+	
+	// Reading the keys, CSM Stubbed - START
+	QFile file("c:\\data\\DoNotShare.txt");
+	if (!file.open(QIODevice::ReadOnly))
+		{
+		qDebug()<<"File to read the windows username and password could not be opened, returning!!!";
+		return;
+		}
+	
+	QByteArray arr = file.readAll();
+	QList<QByteArray> list = arr.split(' ');
+	file.close();
+	
+	QString username(list[0]);
+	QString password(list[1]);
+
+    // For proxy settings on emulator only - REMOVE for device
+    QString httpProxy = "10.1.0.224";
+    QString httpPort = "3148";
+    
+	QString httpUser(username);
+	QString httpPass(password);
+
+    //==Classes used from Network Module==
+    QNetworkProxy proxy;
+
+    proxy.setType(QNetworkProxy::HttpProxy);
+    proxy.setHostName(httpProxy);
+    proxy.setPort(httpPort.toInt());
+    proxy.setUser(httpUser);
+    proxy.setPassword(httpPass);
+		
+    QNetworkProxy::setApplicationProxy(proxy);
+#endif
 	}
 
 
@@ -97,6 +138,7 @@
 		const QList<QUrl> &aUrlList,
 		bool &aSOPCompliant )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::get()";;
 	bool found = false;
 	QString hostName = aRequest.url().host();
 	
@@ -115,7 +157,7 @@
 	if(found)
 		{
 		aSOPCompliant = true;
-		
+
 		// Set header to accept gzip encoded data
 		aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding);
 		
@@ -126,6 +168,7 @@
 		aRequest.setRawHeader("User-Agent", kSmfUserAgent);
 		
 		QNetworkReply* reply = m_networkAccessManager.get(aRequest);
+		qDebug()<<"QNetworkReply of get() = "<<(long)reply;
 	
 		connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply *)), 
 				this, SLOT(networkReplyFinished(QNetworkReply *)));
@@ -141,6 +184,7 @@
 		{
 		// Error :: SAME ORIGIN POLICY violation!!!
 		aSOPCompliant = false;
+		qDebug()<<"SOP violation";
 		return NULL;
 		}
 	}
@@ -164,6 +208,7 @@
 		const QList<QUrl> &aUrlList,
 		bool &aSOPCompliant )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::post()";
 	bool found = false;
 	QString hostName = aRequest.url().host();
 	
@@ -182,6 +227,9 @@
 	if(found)
 		{
 		aSOPCompliant = true;
+
+		// Set header to accept gzip encoded data
+		aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding);
 		
 		// Set the cache control
 		aRequest.setRawHeader("Cache-Control", kSmfCacheControl);
@@ -189,7 +237,13 @@
 		// Put the same user agent for all requests sent by Smf
 		aRequest.setRawHeader("User-Agent", kSmfUserAgent);
 		
+#ifdef DETAILEDDEBUGGING
+		qDebug()<<"post data size is = "<<aPostData.size();
+		qDebug()<<"post data is = "<<QString(aPostData);
+#endif
+		
 		QNetworkReply* reply = m_networkAccessManager.post(aRequest, aPostData);
+		qDebug()<<"QNetworkReply of post() = "<<(long)reply;
 	
 		connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply *)), 
 				this, SLOT(networkReplyFinished(QNetworkReply *)));
@@ -205,6 +259,7 @@
 		{
 		// Error :: SAME ORIGIN POLICY violation!!!
 		aSOPCompliant = false;
+		qDebug()<<"SOP violation";
 		return NULL;
 		}
 	}
@@ -226,6 +281,7 @@
 		const QList<QUrl> &aUrlList,
 		bool &aSOPCompliant )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::head()";
 	bool found = false;
 	QString hostName = aRequest.url().host();
 
@@ -244,6 +300,10 @@
 	if(found)
 		{
 		aSOPCompliant = true;
+		
+		// Set header to accept gzip encoded data
+		aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding);
+		
 		// Set the cache control
 		aRequest.setRawHeader("Cache-Control", kSmfCacheControl);
 		
@@ -251,6 +311,7 @@
 		aRequest.setRawHeader("User-Agent", kSmfUserAgent);
 		
 		QNetworkReply* reply = m_networkAccessManager.head(aRequest);
+		qDebug()<<"QNetworkReply of head() = "<<(long)reply;
 	
 		connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply *)), 
 				this, SLOT(networkReplyFinished(QNetworkReply *)));
@@ -266,6 +327,7 @@
 		{
 		// Error :: SAME ORIGIN POLICY violation!!!
 		aSOPCompliant = false;
+		qDebug()<<"SOP violation";
 		return NULL;
 		}
 	}
@@ -289,6 +351,7 @@
 		const QList<QUrl> &aUrlList,
 		bool &aSOPCompliant )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::put()";
 	bool found = false;
 	QString hostName = aRequest.url().host();
 
@@ -307,6 +370,10 @@
 	if(found)
 		{
 		aSOPCompliant = true;
+		
+		// Set header to accept gzip encoded data
+		aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding);
+		
 		// Set the cache control
 		aRequest.setRawHeader("Cache-Control", kSmfCacheControl);
 		
@@ -314,6 +381,7 @@
 		aRequest.setRawHeader("User-Agent", kSmfUserAgent);
 		
 		QNetworkReply* reply = m_networkAccessManager.put(aRequest, aPostData);
+		qDebug()<<"QNetworkReply of put() = "<<(long)reply;
 	
 		connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply *)), 
 				this, SLOT(networkReplyFinished(QNetworkReply *)));
@@ -329,6 +397,7 @@
 		{
 		// Error :: SAME ORIGIN POLICY violation!!!
 		aSOPCompliant = false;
+		qDebug()<<"SOP violation";
 		return NULL;
 		}
 	}
@@ -350,6 +419,7 @@
 		const QList<QUrl> &aUrlList,
 		bool &aSOPCompliant )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::deleteResource()";
 	bool found = false;
 	QString hostName = aRequest.url().host();
 
@@ -368,6 +438,10 @@
 	if(found)
 		{
 		aSOPCompliant = true;
+		
+		// Set header to accept gzip encoded data
+		aRequest.setRawHeader("Accept-encoding", kSmfAcceptEncoding);
+		
 		// Set the cache control
 		aRequest.setRawHeader("Cache-Control", kSmfCacheControl);
 		
@@ -375,6 +449,7 @@
 		aRequest.setRawHeader("User-Agent", kSmfUserAgent);
 		
 		QNetworkReply* reply = m_networkAccessManager.deleteResource(aRequest);
+		qDebug()<<"QNetworkReply of deleteResource() = "<<(long)reply;
 	
 		connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply *)), 
 				this, SLOT(networkReplyFinished(QNetworkReply *)));
@@ -390,6 +465,7 @@
 		{
 		// Error :: SAME ORIGIN POLICY violation!!!
 		aSOPCompliant = false;
+		qDebug()<<"SOP violation";
 		return NULL;
 		}
 	}
@@ -405,6 +481,8 @@
 bool SmfTransportManagerUtil::cancelRequest ( 
 		QNetworkReply *aCancelReply )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::cancelRequest()";
+	
 	// Checks if this transaction is running
 	if( aCancelReply->isRunning() )
 		{
@@ -464,6 +542,10 @@
  */
 void SmfTransportManagerUtil::networkReplyFinished ( QNetworkReply *aNetworkReply )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::networkReplyFinished()";
+	qDebug()<<"QNetworkReply = "<<(long)aNetworkReply;
+	qDebug()<<"QNetworkReply error code = "<<aNetworkReply->error();
+	
 	// remove the QNetworkReply instance from the list of outstanding transactions
 	int index = m_activeNetwReplyList.indexOf(aNetworkReply);
 	if( index >= 0 )
@@ -473,73 +555,132 @@
 	SmfTransportResult trResult;
 	convertErrorType(aNetworkReply->error(), trResult);
 	
-	// Store the data received
+	// Read the response from the device
+	QByteArray response = aNetworkReply->readAll();
+	qDebug()<<"Response size is = "<<response.size();
+#ifdef DETAILEDDEBUGGING
+	qDebug()<<"Response is = "<<QString(response);
+#endif
+
+	// Store the number of bytes of data received
 	bool converted = false;
 	quint64 data = m_settings->value("Received Data").toULongLong(&converted);
 	if(converted)
 		{
-		data += aNetworkReply->readBufferSize();
+		data += response.size();
 		m_settings->setValue("Received Data", data);
 		}
 
-	int error = 0;
+	SmfError error = SmfUnknownError;
 	QByteArray *arr = NULL;
 	
-	// Read the response from the device
-	QByteArray response = aNetworkReply->readAll();
+#ifdef DETAILEDDEBUGGING
+	foreach(QByteArray arr, aNetworkReply->rawHeaderList())
+			qDebug()<<QString(arr)<<" = "<<QString(aNetworkReply->rawHeader(arr));
+#endif
 	
 	// Check if the http response header has the raw header "Content-Encoding:gzip"
-	// If so, inflate the gzip deflated data
+	bool gzipEncoded = false;
 	QByteArray headerKey("Content-Encoding");
 	if(aNetworkReply->hasRawHeader(headerKey))
 		{
-		SmfPluginManager::getInstance()->server()->writeLog("Response is gzip encoded!!!");
+		qDebug()<<"Content-Encoding:"<<QString(aNetworkReply->rawHeader(headerKey));
+		
+		// If http response header has the raw header "Content-Encoding:gzip"
 		if( "gzip" == QString(aNetworkReply->rawHeader(headerKey)))
+			{
+			QByteArray firstByte(1, response[0]);
+			QByteArray secondByte(1, response[1]);
+			
+#ifdef DETAILEDDEBUGGING
+			qDebug()<<"first byte : "<<QString(firstByte.toHex());
+			qDebug()<<"second byte : "<<QString(secondByte.toHex());
+#endif
+			
+			// And the header says the response is a valid gzip data. 
+			// If so, inflate the gzip deflated data
+			if((QString("1f") == QString(firstByte.toHex())) && (QString("8b") == QString(secondByte.toHex())) )
+				{
+				gzipEncoded = true;
+				qDebug()<<"Response is gzip encoded!!!";
 			arr = inflateResponse(response, error);
+				if(!arr)
+					trResult = SmfTransportOpGzipError;
+			}
 		else
-			SmfPluginManager::getInstance()->server()->writeLog("Unsupported encoding format!!! - error");
+			{
+				qDebug()<<"Header says gzip encoded, but response is not a valid data, so ignoring the header!!!";
+				arr = new QByteArray(response);
+				}
+			}
+		else
+			{
+			qDebug()<<"Unsupported encoding format!!! - error";
+			trResult = SmfTransportOpUnsupportedContentEncodingFormat;
+			}
 		}
+	
 	else
-		SmfPluginManager::getInstance()->server()->writeLog("Response is not gzip encoded");
+		{
+		qDebug()<<"Response is not gzip encoded";
+		arr = new QByteArray(response);
+		}
 	
+	// Write the uncompressed data to a file
+#ifdef DETAILEDDEBUGGING
+	if(arr)
+		{
+		QFile file1("c:\\data\\networkResponse.txt");
+		if (!file1.open(QIODevice::WriteOnly))
+			qDebug()<<"File to write the network response could not be opened";
+		file1.write(*arr);
+		file1.close();
+		}
+#endif
 
 	SmfPluginManager::getInstance()->responseAvailable ( trResult, aNetworkReply, arr );
 	}
 
 
 /**
- * Method to deflate a gzipped network response. Once this method is called, 
- * QNetworkReply internal buffer for holding network response is emptied.
- * @param aResponse The QByteArray instance holding the gzip encoded data
+ * Method to inflate a gzipped network response.
+ * @param aResponse The QByteArray holding the gzip encoded data
  * @param aError Argument indicating error
- * @return a QByteArray* containing the deflated data. If deflating fails, 
- * the encoded data itself without deflation is returned.
+ * @return a QByteArray* containing the inflated data. If inflation fails, 
+ * NULL is returned
  */
-QByteArray* SmfTransportManagerUtil::inflateResponse ( QByteArray &aResponse, int& aError )
+QByteArray* SmfTransportManagerUtil::inflateResponse ( QByteArray &aResponse, SmfError& aError )
 	{
-	Q_UNUSED(aError)
+	qDebug()<<"Inside SmfTransportManagerUtil::inflateResponse()";
+	
 	// Read the response from the device
-	SmfPluginManager::getInstance()->server()->writeLog("Encoded response content = "+QString(aResponse.toHex()));
-	SmfPluginManager::getInstance()->server()->writeLog("Encoded response content size = "+QString::number(aResponse.size(), 10));
+	qDebug()<<"Encoded response content size = "<<aResponse.size();
+	
+	if(aResponse.size() <= 0)
+		{
+		aError = SmfTMUnknownContentError;
+		return NULL;
+		}
 	
 	// Get the uncompressed size of the response (last 4 bytes of the compressed data as per GZIP format spec)
 	QByteArray sizeStr;
 	for(int count = 1 ; count <= 4 ; count++)
 		sizeStr.append(aResponse[aResponse.size()-count]);
-	SmfPluginManager::getInstance()->server()->writeLog("Size string as a string = "+QString(sizeStr.toHex()));
+	qDebug()<<"Size string as a string = "<<QString(sizeStr.toHex());
 	bool ok = false;
 	int uncomSize = sizeStr.toHex().toInt(&ok, 16);
-	SmfPluginManager::getInstance()->server()->writeLog("Size of uncompressed data = "+QString::number(uncomSize, 10));
+	qDebug()<<"Size of uncompressed data = "<<uncomSize;
 
 	// Initialize the data required for zlib method call
 	z_stream stream;
 	unsigned char *out = new unsigned char[uncomSize];
 	if(out)
-		SmfPluginManager::getInstance()->server()->writeLog("Memory allocated for output buffer");
+		qDebug()<<"Memory allocated for output buffer";
 	else
 		{
 		//Error
-		SmfPluginManager::getInstance()->server()->writeLog("Memory not allocated for output buffer!!!");
+		qDebug()<<"Memory not allocated for output buffer!!!";
+		aError = SmfMemoryAllocationFailure;
 		return NULL;
 		}
 	stream.zalloc = Z_NULL;
@@ -549,11 +690,19 @@
 	stream.next_in = Z_NULL;
 	
 	int ret = inflateInit2(&stream, 16+MAX_WBITS);
-	SmfPluginManager::getInstance()->server()->writeLog("return value of inflateInit2() = "+QString::number(ret, 10));
+	qDebug()<<"return value of inflateInit2() = "<<ret;
 	if(Z_OK != ret)
 		{
-		SmfPluginManager::getInstance()->server()->writeLog("Error in inflateInit2, returning...");
+		qDebug()<<"Error in inflateInit2, returning...";
 		delete[] out;
+		if(Z_STREAM_ERROR == ret)
+			aError = SmfTMGzipStreamError;
+		else if(Z_MEM_ERROR == ret)
+			aError = SmfTMGzipMemoryError;
+		else if(Z_DATA_ERROR == ret)
+			aError = SmfTMGzipDataError;
+		else
+			aError = SmfUnknownError;
 		return NULL;
 		}
 
@@ -564,7 +713,7 @@
 	stream.next_out = out;
 	
 	ret = inflate(&stream, Z_NO_FLUSH);
-	SmfPluginManager::getInstance()->server()->writeLog("return value of inflate() = "+QString::number(ret, 10));
+	qDebug()<<"return value of inflate() = "<<ret;
 	
 	switch (ret) 
 		{
@@ -575,42 +724,209 @@
 			{
 			(void)inflateEnd(&stream);
 			delete[] out;
+			aError = SmfTMGzipDataError;
 			return NULL;
 			}
 		}
 
-	SmfPluginManager::getInstance()->server()->writeLog("total bytes read so far = "+QString::number(stream.total_in, 10));
-	SmfPluginManager::getInstance()->server()->writeLog("total bytes output so far = "+QString::number(stream.total_out, 10));
+	qDebug()<<"total bytes read so far = "<<stream.total_in;
+	qDebug()<<"total bytes output so far = "<<stream.total_out;
 
 	// Write the inflated data to a QByteArray
-	QByteArray *uncompressedData = new QByteArray((char *)out);
+	QByteArray *uncompressedData = new QByteArray((char *)out, stream.total_out);
 	delete[] out;
 	
 	// If there is some unwanted data at the end of uncompressed data, chop them
 	int chopLength = uncompressedData->size() - uncomSize;
-	SmfPluginManager::getInstance()->server()->writeLog("uncompressedData before chopping = "+QString(uncompressedData->toHex()));
-	SmfPluginManager::getInstance()->server()->writeLog("old size of uncompressed data = "+QString::number(uncompressedData->size(), 10));
+	qDebug()<<"old size of uncompressed data = "<<uncompressedData->size();
 	uncompressedData->chop(chopLength);
-	SmfPluginManager::getInstance()->server()->writeLog("new size of uncompressed data = "+QString::number(uncompressedData->size(), 10));
-	SmfPluginManager::getInstance()->server()->writeLog("uncompressedData after chopping = "+QString(uncompressedData->toHex()));
-
-	// Write the uncompressed data to a file
-	QFile file1("c:\\data\\uncompressedflickrresponse.txt");
-	if (!file1.open(QIODevice::WriteOnly))
-		SmfPluginManager::getInstance()->server()->writeLog("File to write the uncompressed response could not be opened");
-	file1.write(uncompressedData->data());
-	file1.close();
-	SmfPluginManager::getInstance()->server()->writeLog("uncompressed data written to c:\\data\\uncompressedflickrresponse.txt");
+	qDebug()<<"new size of uncompressed data = "<<uncompressedData->size();
 	
 	return uncompressedData;
 	}
 
+
+/**
+ * Method to deflate a network request to gzip format.
+ * @param aResponse The QByteArray that has to be gzipped
+ * @param aError Argument indicating error
+ * @return a QByteArray* containing the deflated data. If deflation fails, 
+ * NULL is returned
+ */
+QByteArray* SmfTransportManagerUtil::deflateRequest( QByteArray &aResponse, SmfError& aError )
+	{
+	qDebug()<<"Inside SmfTransportManagerUtil::deflateRequest()";
+	
+	if(aResponse.size() <= 0)
+		{
+		aError = SmfTMUnknownContentError;
+		return NULL;
+		}
+	
+	// Initialize the data required for zlib initialize method call
+	z_stream stream;
+	stream.zalloc = Z_NULL;
+	stream.zfree = Z_NULL;
+	stream.opaque = Z_NULL;
+	stream.next_in = (unsigned char *)aResponse.data();
+	stream.avail_in = aResponse.size();
+	stream.total_out = 0;
+
+	int level = Z_DEFAULT_COMPRESSION;
+	int method = Z_DEFLATED;
+	int windowBits = 16+MAX_WBITS;
+	int mem_level = 8;
+	int strategy = Z_DEFAULT_STRATEGY;
+	
+	// Call deflateInit2 for gzip compression initialization
+	int initError = deflateInit2(&stream, level, method, windowBits, mem_level, strategy);
+	qDebug()<<"Return value of deflateInit2() = "<<initError;
+	qDebug()<<"Error msg if any = "<<QString(zError(initError));
+	
+	if(Z_OK != initError)
+		{
+		qDebug()<<"deflateInit2() failed, returning error = "<<QString(zError(initError));
+		
+		if(Z_STREAM_ERROR == initError)
+			aError = SmfTMGzipStreamError;
+		else if(Z_MEM_ERROR == initError)
+			aError = SmfTMGzipMemoryError;
+		else if(Z_DATA_ERROR == initError)
+			aError = SmfTMGzipDataError;
+		else
+			aError = SmfUnknownError;
+		return NULL;
+		}
+
+	// Initialize the data required for inflate() method call
+	int out_size = (int)((aResponse.size()*1.01)+17);
+	unsigned char *out = new unsigned char[out_size];
+	if(out)
+		{
+		qDebug()<<"Memory allocated for output buffer with size = "<<out_size;
+		memset(out, 0, out_size);
+		}
+	else
+		{
+		//Error
+		qDebug()<<"Memory not allocated for output buffer!!!";
+		
+		deflateEnd(&stream);
+		aError = SmfTMGzipDataError;
+		return NULL;
+		}
+
+	stream.next_out = out;
+	stream.avail_out = out_size;
+	
+#ifdef DETAILEDDEBUGGING
+	qDebug()<<"Before calling deflate()";
+	qDebug()<<"next_in = "<<(long)stream.next_in;
+	qDebug()<<"avail_in = "<<stream.avail_in;
+	qDebug()<<"next_out = "<<(long)stream.next_out;
+	qDebug()<<"avail_out = "<<stream.avail_out;
+	qDebug()<<"total_in = "<<stream.total_in;
+	qDebug()<<"total_out = "<<stream.total_out;
+#endif
+	
+	int deflateStatus;
+	do
+		{
+		stream.next_out = out + stream.total_out;
+		stream.avail_out = out_size - stream.total_out;
+		
+		deflateStatus = deflate(&stream, Z_FINISH);
+		qDebug()<<"Return value of deflate() is = "<<deflateStatus;
+		qDebug()<<"Error msg if any = "<<QString(zError(deflateStatus));
+		
+#ifdef DETAILEDDEBUGGING
+		qDebug()<<"avail_in = "<<stream.avail_in;
+		qDebug()<<"avail_out = "<<stream.avail_out;
+		qDebug()<<"total_in = "<<stream.total_in;
+		qDebug()<<"total_out = "<<stream.total_out;
+#endif
+		
+		}while(Z_OK == deflateStatus);
+	
+     if (Z_STREAM_END != deflateStatus)  
+     {  
+         QString errorMsg;  
+         switch (deflateStatus)  
+         {  
+             case Z_ERRNO:  
+                 errorMsg.append("Error occured while reading file.");
+                 aError = SmfUnknownError;
+                 break;  
+             case Z_STREAM_ERROR:  
+                 errorMsg.append("The stream state was inconsistent (e.g., next_in or next_out was NULL).");
+                 aError = SmfTMGzipStreamError;
+                 break;  
+             case Z_DATA_ERROR:  
+                 errorMsg.append("The deflate data was invalid or incomplete.");
+                 aError = SmfTMGzipDataError;
+                 break;  
+             case Z_MEM_ERROR:  
+                 errorMsg.append("Memory could not be allocated for processing.");
+                 aError = SmfTMGzipMemoryError;
+                 break;  
+             case Z_BUF_ERROR:  
+                 errorMsg.append("Ran out of output buffer for writing compressed bytes.");
+                 aError = SmfTMGzipMemoryError;
+                 break;  
+             case Z_VERSION_ERROR:  
+                 errorMsg.append("The version of zlib.h and the version of the library linked do not match.");
+                 aError = SmfUnknownError;
+                 break;  
+             default:  
+                 errorMsg.append("Unknown error code.");
+                 aError = SmfUnknownError;
+         }  
+   
+         qDebug()<<"Error string for deflate() is = "<<errorMsg;
+         
+         // Free data structures that were dynamically created for the stream.  
+         deflateEnd(&stream);  
+   
+         return NULL;  
+     } 
+			
+     int retVal = deflateEnd(&stream);
+	qDebug()<<"Return value of deflateEnd() = "<<retVal;
+	qDebug()<<"Error msg if any = "<<QString(zError(retVal));
+
+#ifdef DETAILEDDEBUGGING
+	/*QByteArray byteArray;
+	for (int i=0; i<stream.total_out;i++)
+		{
+		QString str(out[i]);
+		byteArray.clear();
+		byteArray.append(str.toAscii());
+		qDebug()<<QString("out[%1] = '%2'").arg(i).arg(QString(byteArray.toHex()));
+		}*/
+#endif
+	
+	// Write the inflated data to a QByteArray
+	QByteArray *compressedData = new QByteArray((char*)out, stream.total_out);
+	delete[] out;
+	qDebug()<<"Number of bytes of compressed data = "<<compressedData->size();
+	
+#ifdef DETAILEDDEBUGGING
+	qDebug()<<"compressed data = "<<QString(compressedData->toHex());
+#endif
+	
+	return compressedData;
+	}
+
+
+
 /**
  * Method called when the QNetworkReply detects an error in processing.
  * @param aError The QNetworkReply error code 
  */
 void SmfTransportManagerUtil::networkReplyError ( QNetworkReply::NetworkError aError )
 	{
+	qDebug()<<"Inside SmfTransportManagerUtil::networkReplyError()";
+	
 	// indicate the error to the plugin manager
 	SmfTransportResult trResult;
 	convertErrorType(aError, trResult);