engine/src/HttpClient.cpp
branchRCL_3
changeset 285 4d42a5e09930
parent 126 c2f1ea38ec70
child 310 2e0299e13cbf
equal deleted inserted replaced
283:08a3356e8364 285:4d42a5e09930
    18 
    18 
    19 const TInt KTempBufferSize = 100;
    19 const TInt KTempBufferSize = 100;
    20 
    20 
    21 CHttpClient::~CHttpClient()
    21 CHttpClient::~CHttpClient()
    22   {
    22   {
       
    23 	
       
    24 	iPodcastModel.ConnectionEngine().RemoveObserver(this);
       
    25 	 
    23   if (iHandler)
    26   if (iHandler)
    24   	{
    27   	{
    25   	iHandler->CloseSaveFile();
    28   	iHandler->CloseSaveFile();
    26 	delete iHandler;
    29 	delete iHandler;
    27   	}
    30   	}
   109 	DP("ConnectHttpSessionL END");	
   112 	DP("ConnectHttpSessionL END");	
   110 }
   113 }
   111 
   114 
   112 void CHttpClient::ConnectCompleteL(TInt aErrorCode)
   115 void CHttpClient::ConnectCompleteL(TInt aErrorCode)
   113 	{
   116 	{
       
   117 	DP1("CHttpClient::ConnectCompleteL BEGIN, aErrorCode=%d", aErrorCode);
       
   118 	DP1("    iWaitingForGet=%d", iWaitingForGet);
   114 	if(iWaitingForGet)
   119 	if(iWaitingForGet)
   115 		{
   120 		{
   116 		iWaitingForGet = EFalse;
   121 		iWaitingForGet = EFalse;
   117 		if( aErrorCode == KErrNone)
   122 		if( aErrorCode == KErrNone)
   118 			{
   123 			{
       
   124 			TRAP_IGNORE(iSession.OpenL());
       
   125 			DP("    one");
   119 			RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
   126 			RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
       
   127 			DP("    one point five");
   120 			RStringPool pool = iSession.StringPool();
   128 			RStringPool pool = iSession.StringPool();
   121 			// Attach to socket server
   129 			// Attach to socket server
       
   130 			DP("    two");
   122 			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iPodcastModel.ConnectionEngine().SockServ().Handle()));
   131 			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iPodcastModel.ConnectionEngine().SockServ().Handle()));
   123 			// Attach to connection
   132 			// Attach to connection
       
   133 			DP("    three");
   124 			TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection());
   134 			TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection());
   125 			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr));
   135 			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr));
   126 
   136 			DP("    four");
   127 
   137 
   128 			iPodcastModel.SetProxyUsageIfNeededL(iSession);
   138 			iPodcastModel.SetProxyUsageIfNeededL(iSession);
   129 			DoGetAfterConnectL();		
   139 			DoGetAfterConnectL();
       
   140 			//iWaitingForGet = EFalse; // set to true by DoGetAfterConnectL
   130 			}
   141 			}
   131 		else
   142 		else
   132 			{
   143 			{
   133 			ClientRequestCompleteL(KErrCouldNotConnect);
   144 			ClientRequestCompleteL(KErrCouldNotConnect);
   134 			iSession.Close();			
   145 			iSession.Close();			
   135 			}
   146 			}
   136 		}				
   147 		}
       
   148 	DP("CHttpClient::ConnectCompleteL END");
   137 	}
   149 	}
   138 
   150 
   139 void CHttpClient::Disconnected()
   151 void CHttpClient::Disconnected()
   140 	{
   152 	{
   141 	iIsActive = EFalse;
   153 	iIsActive = EFalse;
   142 	iSession.Close();
   154 	iSession.Close();
   143 	}
   155 	}
   144 
   156 
   145 void  CHttpClient::DoGetAfterConnectL()
   157 void  CHttpClient::DoGetAfterConnectL()
   146 	{	
   158 	{	
       
   159 	DP("CHttpClient::DoGetAfterConnectL BEGIN");
   147 	// since nothing should be downloading now. Delete the handler
   160 	// since nothing should be downloading now. Delete the handler
   148 	if (iHandler)
   161 	if (iHandler)
   149 		{
   162 		{
   150 		delete iHandler;
   163 		delete iHandler;
   151 		iHandler = NULL;
   164 		iHandler = NULL;
   156 
   169 
   157 	TEntry entry;
   170 	TEntry entry;
   158 	TBuf8<KTempBufferSize> rangeText;
   171 	TBuf8<KTempBufferSize> rangeText;
   159 
   172 
   160 	if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) {
   173 	if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) {
   161 		DP1("Found file, with size=%d", entry.iSize);
   174 		DP1("    Found file, with size=%d", entry.iSize);
   162 		// file exists, so we should probably resume
   175 		// file exists, so we should probably resume
   163 		rangeText.Format(_L8("bytes=%d-"), (entry.iSize-KByteOverlap > 0 ? entry.iSize-KByteOverlap : 0));
   176 		rangeText.Format(_L8("bytes=%d-"), (entry.iSize-KByteOverlap > 0 ? entry.iSize-KByteOverlap : 0));
   164 		iHandler->SetSaveFileName(iCurrentFileName, ETrue);
   177 		iHandler->SetSaveFileName(iCurrentFileName, ETrue);
   165 	} else {
   178 	} else {
   166 		// otherwise just make sure the directory exists
   179 		// otherwise just make sure the directory exists
   177 	// Add headers appropriate to all methods
   190 	// Add headers appropriate to all methods
   178 	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
   191 	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
   179 	SetHeaderL(hdr, HTTP::EAccept, KAccept);
   192 	SetHeaderL(hdr, HTTP::EAccept, KAccept);
   180 	TBuf<KTempBufferSize> range16;
   193 	TBuf<KTempBufferSize> range16;
   181 	range16.Copy(rangeText);
   194 	range16.Copy(rangeText);
   182 	DP1("range text: %S", &range16);
   195 	DP1("    range text: %S", &range16);
   183 	if (rangeText.Length() > 0) {
   196 	if (rangeText.Length() > 0) {
   184 		SetHeaderL(hdr, HTTP::ERange, rangeText);
   197 		SetHeaderL(hdr, HTTP::ERange, rangeText);
   185 	}
   198 	}
   186 	iTransactionCount++;
   199 	iTransactionCount++;
   187 	// submit the transaction
   200 	// submit the transaction
   188 	iTrans.SubmitL();
   201 	iTrans.SubmitL();
   189 	iIsActive = ETrue;	
   202 	iIsActive = ETrue;	
   190 	DP("CHttpClient::Get END");		
   203 	DP("CHttpClient::DoGetAfterConnectL END");
   191 	}
   204 	}
   192 
   205 
   193 TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName,  TBool aSilent) {
   206 TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName,  TBool aSilent) {
   194 	DP("CHttpClient::Get START");
   207 	DP("CHttpClient::Get START");
   195 	DP2("Getting '%S' to '%S'", &aUrl, &aFileName);
   208 	DP2("Getting '%S' to '%S'", &aUrl, &aFileName);
   210 		return EFalse;		
   223 		return EFalse;		
   211 		}	
   224 		}	
   212 	
   225 	
   213 	iSilentGet = aSilent;
   226 	iSilentGet = aSilent;
   214 	iCurrentFileName.Copy(aFileName);
   227 	iCurrentFileName.Copy(aFileName);
   215 	iWaitingForGet = ETrue;
       
   216 	
   228 	
   217 	if (iTransactionCount == 0) 
   229 	if (iTransactionCount == 0) 
   218 		{
   230 		{
   219 		DP("CHttpClient::GetL\t*** Opening HTTP session ***");
   231 		DP("CHttpClient::GetL\t*** Opening HTTP session ***");
   220 		iSession.Close();
   232 		iSession.Close();
   221 		iSession.OpenL();
   233 		iSession.OpenL();
       
   234 		iWaitingForGet = ETrue;
   222 		ConnectHttpSessionL();			
   235 		ConnectHttpSessionL();			
   223 		}
   236 		}
   224 	else
   237 	else
   225 		{
   238 		{
       
   239 		iWaitingForGet = EFalse;
   226 		DoGetAfterConnectL();		
   240 		DoGetAfterConnectL();		
   227 		}
   241 		}
   228 	return ETrue;
   242 	return ETrue;
   229 }
   243 }
   230 
   244 
   252 	TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected));
   266 	TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected));
   253 
   267 
   254 	}
   268 	}
   255 
   269 
   256 void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) {
   270 void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) {
       
   271 	DP1("CHttpClient::ClientRequestCompleteL, aErrorCode=%d", aErrorCode);
   257 	iIsActive = EFalse;
   272 	iIsActive = EFalse;
   258 	iObserver.CompleteL(this, aErrorCode);
   273 	iObserver.CompleteL(this, aErrorCode);
   259 	DP("CHttpClient::ClientRequestCompleteL");
   274 	DP1("    iTransactionCount=%d", iTransactionCount);
   260 	if(iTransactionCount>0)
   275 	if(iTransactionCount>0)
   261 		{
   276 		{
   262 		iTransactionCount--;
   277 		iTransactionCount--;
   263 	
   278 	
   264 		if(iTransactionCount == 0) 
   279 		if(iTransactionCount == 0)