engine/src/HttpEventHandler.cpp
changeset 82 d87e984bd8b8
parent 2 29cda98b007e
child 83 a2e43aa1ad11
equal deleted inserted replaced
81:27f6f5827e5d 82:d87e984bd8b8
   107 				TInt valid = iFileServ.IsValidName(iFileName);
   107 				TInt valid = iFileServ.IsValidName(iFileName);
   108 				if (!valid)
   108 				if (!valid)
   109 					{
   109 					{
   110 					DP("The specified filename is not valid!.");
   110 					DP("The specified filename is not valid!.");
   111 					iSavingResponseBody = EFalse;
   111 					iSavingResponseBody = EFalse;
       
   112 					iHttpClient->ClientRequestCompleteL(KErrBadName);
   112 					}
   113 					}
   113 				else
   114 				else
   114 					{
   115 					{
   115 					if (iContinue) {
   116 					if (iContinue) {
   116 						TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite);
   117 						TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite);
   117 						if (err)
   118 						if (err)
   118 							{
   119 							{
   119 							DP("There was an error opening file");
   120 							DP("There was an error opening file");
   120 							iSavingResponseBody = EFalse;
   121 							iSavingResponseBody = EFalse;
       
   122 							iHttpClient->ClientRequestCompleteL(KErrInUse);
   121 							User::Leave(err);
   123 							User::Leave(err);
   122 							} else {
   124 							} 
       
   125 						else
       
   126 							{
   123 							int pos = -KByteOverlap;
   127 							int pos = -KByteOverlap;
   124 							if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) {
   128 							if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone)
       
   129 								{
   125 								DP("Failed to set position!");
   130 								DP("Failed to set position!");
       
   131 								iHttpClient->ClientRequestCompleteL(KErrGeneral);
   126 								User::Leave(err);
   132 								User::Leave(err);
       
   133 								}
       
   134 						iBytesDownloaded = (pos > 0) ? pos : 0;
       
   135 						iBytesTotal += iBytesDownloaded;
       
   136 						DP1("Total bytes is now %u", iBytesTotal);
       
   137 						DP1("Seeking end: %d", pos);
   127 							}
   138 							}
   128 							iBytesDownloaded = (pos > 0) ? pos : 0;
   139 						}
   129 							iBytesTotal += iBytesDownloaded;
   140 					else 
   130 							DP1("Total bytes is now %u", iBytesTotal);
   141 						{
   131 							DP1("Seeking end: %d", pos);
       
   132 							}
       
   133 					} else {
       
   134 						TInt err = iRespBodyFile.Replace(iFileServ,
   142 						TInt err = iRespBodyFile.Replace(iFileServ,
   135 														 iParsedFileName.FullName(),
   143 														 iParsedFileName.FullName(),
   136 														 EFileWrite);
   144 														 EFileWrite);
   137 						if (err)
   145 						if (err)
   138 							{
   146 							{
   158 				{
   166 				{
   159 				TPtrC8 bodyData;
   167 				TPtrC8 bodyData;
   160 				iRespBody->GetNextDataPart(bodyData);
   168 				iRespBody->GetNextDataPart(bodyData);
   161 				iBytesDownloaded += bodyData.Length();
   169 				iBytesDownloaded += bodyData.Length();
   162 				TInt error = iRespBodyFile.Write(bodyData);
   170 				TInt error = iRespBodyFile.Write(bodyData);
   163 				
       
   164 				// on writing error we close connection 
   171 				// on writing error we close connection 
   165 				if (error != KErrNone) {
   172 				if (error != KErrNone) {
   166 					//aTransaction.Close();
   173 					iRespBodyFile.Close();
   167 					iCallbacks.FileError(error);
   174 					iCallbacks.FileError(error);
   168 					iHttpClient->ClientRequestCompleteL(error);
   175 					iHttpClient->ClientRequestCompleteL(error);
   169 					return;
   176 					return;
   170 				}
   177 				}
   171 
   178 
   194 		case THTTPEvent::EFailed:
   201 		case THTTPEvent::EFailed:
   195 			{
   202 			{
   196 			DP("Transaction Failed");
   203 			DP("Transaction Failed");
   197 			aTransaction.Close();
   204 			aTransaction.Close();
   198 			
   205 			
   199 			if(iLastStatusCode == HTTPStatus::EOk || iLastStatusCode == HTTPStatus::ECreated || iLastStatusCode == HTTPStatus::EAccepted)
   206 //			if(iLastStatusCode == HTTPStatus::EOk || iLastStatusCode == HTTPStatus::ECreated || iLastStatusCode == HTTPStatus::EAccepted)
   200 				{
   207 //				{
   201 				iLastStatusCode = KErrNone;
   208 //				iLastStatusCode = KErrNone;
   202 				}
   209 //				}
   203 			
   210 			
   204 			iHttpClient->ClientRequestCompleteL(iLastStatusCode);
   211 			iHttpClient->ClientRequestCompleteL(KErrGeneral);
   205 			} break;
   212 			} break;
   206 		case THTTPEvent::ERedirectedPermanently:
   213 		case THTTPEvent::ERedirectedPermanently:
   207 			{
   214 			{
   208 			DP("Permanent Redirection");
   215 			DP("Permanent Redirection");
   209 			} break;
   216 			} break;
   225 	}
   232 	}
   226 
   233 
   227 TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
   234 TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
   228 	{
   235 	{
   229 	DP1("MHFRunError fired with error code %d", aError);
   236 	DP1("MHFRunError fired with error code %d", aError);
   230 
   237 	iHttpClient->ClientRequestCompleteL(aError);
   231 	return KErrNone;
   238 	return KErrNone;
   232 	}
   239 	}
   233 
   240 
   234 void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue)
   241 void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue)
   235 	{
   242 	{