internetradio2.0/dataprovidersrc/irlogodownloadengine.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Engine to fetch the logos 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknnotewrappers.h> 
       
    20 
       
    21 #include "irlogodownloadengine.h"
       
    22 #include "irnetworkcontroller.h"
       
    23 #include "ircachemgmt.h"
       
    24 #include "irhttprequestdata.h"
       
    25 #include "irdebug.h"
       
    26 #include "irdataproviderconstants.h"
       
    27 #include "iractivenetworkobserver.h"
       
    28 
       
    29 
       
    30 
       
    31 _LIT(KLogoX, "?x=");
       
    32 _LIT(KLogoY, "&y=");
       
    33 const TInt KPresetsArrayMaxLength = 50;
       
    34 const TInt KLogoSize = 59;
       
    35 const TInt KParameterSize = 12;
       
    36 const TInt KTen = 10;
       
    37 const TInt KCacheAvailable = 4;
       
    38 const TInt KLogo = 4;
       
    39 const TInt KStatusOK = 200;
       
    40 const TInt KStatusMultipleChoices = 300;
       
    41 const TInt KStatusNotModified = 304;
       
    42 const TInt KStatusGatewayTimeout = 504;
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CIRLogoDownloadEngine::NewL()
       
    47 // Creates instance of CIRLogoDownloadEngine.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CIRLogoDownloadEngine* CIRLogoDownloadEngine::NewL()
       
    51 	{
       
    52 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NewL - Entering" );
       
    53     CIRLogoDownloadEngine* self = new(ELeave) CIRLogoDownloadEngine();
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop(self);
       
    57     IRLOG_DEBUG( "CIRLogoDownloadEngine::NewL - Exiting" );
       
    58     return self;
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CIRLogoDownloadEngine::CIRLogoDownloadEngine()
       
    63 // Standard C++ constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CIRLogoDownloadEngine::CIRLogoDownloadEngine()
       
    67 	{
       
    68 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CIRLogoDownloadEngine " );
       
    69 	//code here, if needed
       
    70 	}
       
    71 	
       
    72 	
       
    73 	
       
    74 // ---------------------------------------------------------------------------
       
    75 // CIRLogoDownloadEngine::~CIRLogoDownloadEngine()
       
    76 // Destructs instance of CIRLogoDownloadEngine.
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CIRLogoDownloadEngine::~CIRLogoDownloadEngine()
       
    80 	{
       
    81 	IRLOG_DEBUG( "CIRLogoDownloadEngine::~CIRLogoDownloadEngine - Entering" );
       
    82     if(iReqBody)
       
    83     	{
       
    84     	delete iReqBody;
       
    85     	iReqBody = NULL;
       
    86     	}
       
    87     if(iRespBody)
       
    88     	{
       
    89     	delete iRespBody;
       
    90     	iRespBody = NULL;
       
    91     	}
       
    92 	CancelTransaction();
       
    93 	iLogoSession.Close();
       
    94 	
       
    95 	if(iCopyPreset)
       
    96 		{
       
    97 		delete iCopyPreset;
       
    98 		}
       
    99 	if(iCacheTempPreset)
       
   100 		{
       
   101 		delete iCacheTempPreset;			
       
   102 		}
       
   103 	if(iTempPreset)
       
   104 		{
       
   105 		delete iTempPreset;			
       
   106 		}
       
   107 	if(iPresetArray)
       
   108 		{
       
   109 		iPresetArray->ResetAndDestroy();
       
   110 		}
       
   111 	delete iPresetArray;
       
   112 	if(iObserverArray)
       
   113 		{
       
   114 		delete iObserverArray;
       
   115 		iObserverArray = NULL;
       
   116 		}
       
   117 	if(iReqFromArray)
       
   118 		{
       
   119 		delete iReqFromArray;
       
   120 		iReqFromArray = NULL;
       
   121 		}
       
   122 	if(iCachePresetArray)
       
   123 		{
       
   124 		iCachePresetArray->ResetAndDestroy();
       
   125 		}
       
   126 	delete iCachePresetArray;
       
   127 	if(iCacheObserverArray)
       
   128 		{
       
   129 		delete iCacheObserverArray;
       
   130 		iCacheObserverArray = NULL;
       
   131 		}
       
   132 	if(iCacheReqFromArray)
       
   133 		{
       
   134 		delete iCacheReqFromArray;
       
   135 		iCacheReqFromArray = NULL;
       
   136 		}
       
   137 	if(iIRNetworkControllerHandle)
       
   138     	{
       
   139     	iIRNetworkControllerHandle->DeleteActiveNetworkObserver(*this);
       
   140     	iIRNetworkControllerHandle->Close();
       
   141         }		
       
   142     if (iCache)
       
   143 	    {
       
   144 	    iCache->RemoveObserver(this);
       
   145 	    iCache->Close();
       
   146 	    }
       
   147 	if( iResponseHeaders )
       
   148 		{
       
   149         delete iResponseHeaders;
       
   150 		}
       
   151 	IRLOG_DEBUG( "CIRLogoDownloadEngine::~CIRLogoDownloadEngine - Exiting" );
       
   152 	}
       
   153 
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CIRLogoDownloadEngine::ConstructL()
       
   158 // 2nd phase construction
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CIRLogoDownloadEngine::ConstructL()
       
   162 	{
       
   163 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ConstructL - Entering" );
       
   164 	iPresetArray = new (ELeave) CArrayPtrFlat<CIRIsdsPreset>(KPresetsArrayMaxLength);
       
   165 	iObserverArray = new (ELeave) CArrayPtrFlat<MLogoDownloadObserver>(KPresetsArrayMaxLength);
       
   166 	iReqFromArray = new (ELeave) CArrayFixFlat<TInt>(KPresetsArrayMaxLength);
       
   167 	iCachePresetArray = new (ELeave) CArrayPtrFlat<CIRIsdsPreset>(KPresetsArrayMaxLength);
       
   168 	iCacheObserverArray = new (ELeave) CArrayPtrFlat<MLogoDownloadObserver>(KPresetsArrayMaxLength);
       
   169 	iCacheReqFromArray = new (ELeave) CArrayFixFlat<TInt>(KPresetsArrayMaxLength);
       
   170 	
       
   171 	iPresetArrayPos = 0;
       
   172 	iReqFromArrayPos = 0;
       
   173 	iObserverArrayPos = 0;
       
   174 	iCachePresetArrayPos = 0;
       
   175 	iCacheReqFromArrayPos = 0;
       
   176 	iCacheObserverArrayPos = 0;
       
   177 	iImageIndex = 0; //using temporarily till the isds provides urls
       
   178 
       
   179 	iPresetModifiedStatus = EFalse;
       
   180 	iFirstTime = ETrue;
       
   181 	iIRNetworkControllerHandle = CIRNetworkController::OpenL();
       
   182 	iIRNetworkControllerHandle->RegisterActiveNetworkObserverL(*this);
       
   183 	iCache = CIRCacheMgmt::OpenL(*this);
       
   184 	iCache->AddObserverL(this);
       
   185 	iResponseHeaders = new ( ELeave ) CIRHttpResponseData;
       
   186 
       
   187 	//change to use the new session for logo downloading
       
   188 	TRAPD( LeaveValue, iLogoSession.OpenL() );
       
   189     if ( LeaveValue != KErrNone )
       
   190         {
       
   191         // Most common error; no access point configured, and session creation
       
   192         // leaves with KErrNotFound.
       
   193         // Load a string from the resource file and add the error code to string
       
   194         User::Leave( LeaveValue );
       
   195         }
       
   196     IRLOG_DEBUG( "CIRLogoDownloadEngine::ConstructL - Exiting" );
       
   197 	}
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CIRLogoDownloadEngine::IsRunning()
       
   202 // To know the status of downloading logo
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C TBool CIRLogoDownloadEngine::IsRunning() const
       
   206 	{
       
   207 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IsRunning" );
       
   208     return iRunning;
       
   209 	}
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CIRLogoDownloadEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   214 //                              const TDesC8& aHdrValue)
       
   215 // to set the headers of the http transaction
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CIRLogoDownloadEngine::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   219 					 const TDesC8& aHdrValue) const
       
   220 	{
       
   221 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetHeaderL - Entering" );
       
   222 	RStringF valStr = iLogoSession.StringPool().OpenFStringL(aHdrValue);
       
   223 	CleanupClosePushL(valStr);
       
   224 	THTTPHdrVal val(valStr);
       
   225 	aHeaders.SetFieldL(iLogoSession.StringPool().StringF(aHdrField, RHTTPSession::GetTable()), val);
       
   226 	CleanupStack::PopAndDestroy(&valStr); // valStr
       
   227 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SetHeaderL - Exiting" );
       
   228 	}
       
   229 
       
   230 // ----------------------------------------------------------------------------------
       
   231 // CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,TInt aXValue,TInt aYValue)
       
   232 // API is called from the SearchResultsView for to download logo while doing Add to Favorites
       
   233 // ----------------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C void CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,TInt aXValue,TInt aYValue)
       
   236 	{
       
   237 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Entering" );
       
   238 	if(!iCheckingCache)
       
   239 		{
       
   240 		++iImageIndex;
       
   241 		iCheckingCache = ETrue;
       
   242 		iCacheReqFrom = 0;
       
   243 		if(iCacheTempPreset)
       
   244 			{
       
   245 			delete iCacheTempPreset;				
       
   246 			}
       
   247 		iCacheTempPreset = NULL;
       
   248 		iCacheTempPreset = CIRIsdsPreset::NewL();
       
   249 		*iCacheTempPreset = *aPreset;
       
   250 
       
   251 		if(iCacheTempPreset->GetImgUrl().Length() != 0)
       
   252 			{
       
   253 			if((aXValue > 0)&&(aYValue > 0))
       
   254 				{
       
   255 				//Append the parameters(width,height) of the logo size to imgUrl
       
   256 				TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   257 				RBuf urlWithSize;
       
   258 				urlWithSize.Create(size);
       
   259 				urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   260 				urlWithSize.Append(KLogoX);
       
   261 				urlWithSize.AppendNum(aXValue);
       
   262 				urlWithSize.Append(KLogoY);
       
   263 				urlWithSize.AppendNum(aYValue);
       
   264 				
       
   265 				//set the imgUrl with parameters to the preset
       
   266 				iCacheTempPreset->SetImgUrl(urlWithSize);
       
   267 				urlWithSize.Close();
       
   268 				}
       
   269 			//This method checks whether the logo is available
       
   270  			// for the request made
       
   271 			iForceGet = EFalse; 			
       
   272 			CheckCacheForLogoL(0);
       
   273 			}
       
   274 		else
       
   275 			{
       
   276 			//imgUrl doesnt exist in the Preset
       
   277 		    iCheckingCache = EFalse;
       
   278 			return;			
       
   279 			}
       
   280 
       
   281 		iCheckingCache = EFalse;
       
   282 		if(!iLogoCached)	
       
   283 			{
       
   284 			FetchLogoDataL(iCacheTempPreset);				
       
   285 			}
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		CIRIsdsPreset* tempPreset;
       
   290 		tempPreset = CIRIsdsPreset::NewL();
       
   291 		*tempPreset = *aPreset;
       
   292 		if(tempPreset->GetImgUrl().Length() != 0)
       
   293 			{
       
   294 			if((aXValue > 0)&&(aYValue > 0))
       
   295 				{
       
   296 				//Append the parameters(width,height) of the logo size to imgUrl
       
   297 				TInt size = tempPreset->GetImgUrl().Length() + KParameterSize;
       
   298 				RBuf urlWithSize;
       
   299 				urlWithSize.Create(size);
       
   300 				urlWithSize.Copy(tempPreset->GetImgUrl());
       
   301 				urlWithSize.Append(KLogoX);
       
   302 				urlWithSize.AppendNum(aXValue);
       
   303 				urlWithSize.Append(KLogoY);
       
   304 				urlWithSize.AppendNum(aYValue);
       
   305 				
       
   306 				//set the imgUrl with parameters to the preset
       
   307 				tempPreset->SetImgUrl(urlWithSize);
       
   308 				urlWithSize.Close();				
       
   309 				}
       
   310 			}
       
   311 		iCachePresetArray->AppendL(tempPreset);
       
   312  		iCacheReqFromArray->AppendL(0);	
       
   313 		}	
       
   314 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Exiting" );
       
   315 	}
       
   316 
       
   317 
       
   318 EXPORT_C TBool CIRLogoDownloadEngine::isLogoCachedL(CIRIsdsPreset* aPreset, TInt aXValue, TInt aYValue)
       
   319 {
       
   320     TInt cached = 0;
       
   321     
       
   322     if(iCacheTempPreset)
       
   323     {
       
   324         delete iCacheTempPreset;
       
   325         iCacheTempPreset = NULL;
       
   326     }
       
   327     
       
   328     iCacheTempPreset = CIRIsdsPreset::NewL();
       
   329     *iCacheTempPreset = *aPreset;
       
   330     iCacheReqMade = EFalse;
       
   331     
       
   332     if (iCacheTempPreset->GetImgUrl().Length() != 0)
       
   333     {
       
   334         if ((aXValue > 0) && (aYValue > 0))
       
   335         {
       
   336             //Append the parameters(width,height) of the logo size to imgUrl
       
   337             TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   338             RBuf urlWithSize;
       
   339             urlWithSize.Create(size);
       
   340             urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   341             urlWithSize.Append(KLogoX);
       
   342             urlWithSize.AppendNum(aXValue);
       
   343             urlWithSize.Append(KLogoY);
       
   344             urlWithSize.AppendNum(aYValue);
       
   345 
       
   346             //set the imgUrl with parameters to the preset
       
   347             iCacheTempPreset->SetImgUrl(urlWithSize);
       
   348             urlWithSize.Close();
       
   349         }
       
   350     }
       
   351     
       
   352     iCache->CheckCacheL(KLogo,iCacheTempPreset->GetImgUrl(),EFalse,cached);
       
   353     
       
   354     return (CIRCacheMgmt::ECacheUseable == cached)?ETrue:EFalse;     
       
   355 }
       
   356 // ----------------------------------------------------------------------------------------------
       
   357 // CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle,
       
   358 //													TInt aNPVReq,TInt aXValue,TInt aYValue)
       
   359 // API is called from several views for to download logo 
       
   360 // ----------------------------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C void CIRLogoDownloadEngine::SendRequestL(CIRIsdsPreset* aPreset,
       
   363 			MLogoDownloadObserver* aLogoHandle,TInt aNPVReq,TInt aXValue,TInt aYValue)
       
   364 	{
       
   365 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Entering" );
       
   366 	if(aPreset->GetChannelType()==0)
       
   367 		{
       
   368 		aLogoHandle->PresetLogoDownloadedL(aPreset);
       
   369 		}
       
   370 	else if(!iCheckingCache)
       
   371 		{
       
   372 		++iImageIndex;
       
   373 		iCheckingCache = ETrue;
       
   374 		if(aNPVReq==2)
       
   375 			{
       
   376 			iCacheReqFrom=2;			
       
   377 			}
       
   378 		else
       
   379 			{
       
   380 			iCacheReqFrom=1;			
       
   381 			}
       
   382 
       
   383 		if(iCacheTempPreset)
       
   384 			{
       
   385 			delete iCacheTempPreset;
       
   386 			iCacheTempPreset = NULL;				
       
   387 			}
       
   388 		iCacheTempPreset = CIRIsdsPreset::NewL();
       
   389 		*iCacheTempPreset = *aPreset;
       
   390 		iCacheTempLogoHandle = aLogoHandle;
       
   391 		
       
   392 		if(iCacheTempPreset->GetImgUrl().Length() != 0)
       
   393 			{
       
   394 			if((aXValue > 0)&&(aYValue > 0))
       
   395 				{
       
   396 				//Append the parameters(width,height) of the logo size to imgUrl
       
   397 				TInt size = iCacheTempPreset->GetImgUrl().Length() + KParameterSize;
       
   398 				RBuf urlWithSize;
       
   399 				urlWithSize.Create(size);
       
   400 				urlWithSize.Copy(iCacheTempPreset->GetImgUrl());
       
   401 				urlWithSize.Append(KLogoX);
       
   402 				urlWithSize.AppendNum(aXValue);
       
   403 				urlWithSize.Append(KLogoY);
       
   404 				urlWithSize.AppendNum(aYValue);
       
   405 				
       
   406 				//set the imgUrl with parameters to the preset
       
   407 				iCacheTempPreset->SetImgUrl(urlWithSize);
       
   408 				urlWithSize.Close();
       
   409 				}
       
   410 			if(iCacheReqFrom==1 || iCacheReqFrom==2)
       
   411 				{
       
   412 				//This method checks whether the logo is available
       
   413 		 		// for the request made
       
   414 				iForceGet = EFalse;		 		
       
   415 				CheckCacheForLogoL(0);	
       
   416 				}
       
   417 /*			else if(iCacheReqFrom==2)
       
   418 				{
       
   419 				//the request has come from NowPlayingView(NPV)
       
   420 				//dont check for logo availability in cache
       
   421 				//download the logo freshly
       
   422 				iLogoCached=EFalse;								
       
   423 				}
       
   424 */			}
       
   425 		else
       
   426 			{
       
   427 			//imgUrl doesnt exist in the Preset
       
   428 		    iCheckingCache = EFalse;
       
   429 			return;			
       
   430 			}
       
   431 		
       
   432 		iCheckingCache = EFalse;
       
   433 		if(!iLogoCached)	
       
   434 			{
       
   435 			FetchLogoDataL(iCacheTempPreset,aLogoHandle,iCacheReqFrom);				
       
   436 			}
       
   437 		}
       
   438 	else
       
   439 		{
       
   440 		CIRIsdsPreset* tempPreset;
       
   441 		tempPreset = CIRIsdsPreset::NewL();
       
   442 		*tempPreset = *aPreset;
       
   443 		if(tempPreset->GetImgUrl().Length() != 0)
       
   444 			{
       
   445 			if((aXValue > 0)&&(aYValue > 0))
       
   446 				{
       
   447 				//Append the parameters(width,height) of the logo size to imgUrl
       
   448 				TInt size = tempPreset->GetImgUrl().Length() + KParameterSize;
       
   449 				RBuf urlWithSize;
       
   450 				urlWithSize.Create(size);
       
   451 				urlWithSize.Copy(tempPreset->GetImgUrl());
       
   452 				urlWithSize.Append(KLogoX);
       
   453 				urlWithSize.AppendNum(aXValue);
       
   454 				urlWithSize.Append(KLogoY);
       
   455 				urlWithSize.AppendNum(aYValue);
       
   456 				
       
   457 				//set the imgUrl with parameters to the preset
       
   458 				tempPreset->SetImgUrl(urlWithSize);
       
   459 				urlWithSize.Close();				
       
   460 				}
       
   461 			}
       
   462 		iCachePresetArray->AppendL(tempPreset);
       
   463  		iCacheObserverArray->AppendL(aLogoHandle);
       
   464  		if(aNPVReq == 2)
       
   465 	 		{
       
   466 	 		iCacheReqFromArray->AppendL(2);		
       
   467 	 		}
       
   468  		else
       
   469 	 		{
       
   470 	 		iCacheReqFromArray->AppendL(1);		
       
   471 	 		}
       
   472 		}
       
   473 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendRequestL - Exiting" );
       
   474 	}
       
   475 
       
   476 
       
   477 
       
   478 // ----------------------------------------------------------------------------------
       
   479 // CIRLogoDownloadEngine::GetCacheLogoL(TDesC& aUrl,TInt& aStatus)
       
   480 // takes the url as a parameter and returns the logo data which is in cache
       
   481 // this API is called form the search results for to display logo on the view
       
   482 // ----------------------------------------------------------------------------------
       
   483 //
       
   484 EXPORT_C void CIRLogoDownloadEngine::GetCacheLogoL(const TDesC& aUrl,TInt& aStatus)
       
   485 	{
       
   486 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetCacheLogoL - Entering" );
       
   487 	iSendingLogo=2;
       
   488 	iResult = 0;
       
   489 	iForceGet = EFalse;
       
   490 	//2 means, this API is called for the search results view
       
   491 	iCacheReqMade = ETrue;
       
   492 	iCache->CheckCacheL(KLogo,aUrl,iForceGet,iResult);		
       
   493 	aStatus = iResult;
       
   494 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetCacheLogoL - Exiting" );
       
   495 
       
   496 	}
       
   497 	
       
   498 	
       
   499 // ----------------------------------------------------------------------------------
       
   500 // CIRLogoDownloadEngine::SendCacheLogo()
       
   501 // sends the logo which is cached
       
   502 // ----------------------------------------------------------------------------------
       
   503 //
       
   504 EXPORT_C TDesC8& CIRLogoDownloadEngine::SendCacheLogo()
       
   505 	{
       
   506 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendCacheLogo" );
       
   507 	return iCache->iLogoData;
       
   508 	}
       
   509 
       
   510 
       
   511 
       
   512 
       
   513 // ------------------------------------------------------------------------
       
   514 // CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset)
       
   515 // API is used to download logo from isds/internet
       
   516 // called in the API SendRequestL(CIRIsdsPreset* aPreset)
       
   517 // ------------------------------------------------------------------------
       
   518 //
       
   519 void CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset)
       
   520 	{
       
   521 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Entering" );
       
   522  	if(!iRunning)
       
   523 	 	{
       
   524 
       
   525 	  	iTempReqFrom = 0;//which means the request came from SearchView while doing Add to Favorite
       
   526 	 	if( iReqBody )
       
   527 		 	{
       
   528 		 	delete iReqBody;
       
   529 		    iReqBody = NULL;
       
   530 		 	}
       
   531 	    if( iRespBody )
       
   532 		    {
       
   533 		    delete iRespBody;
       
   534 		    iRespBody = NULL;
       
   535 		    }
       
   536 		if(iTempPreset)
       
   537 			{
       
   538 			delete iTempPreset;
       
   539 			iTempPreset = NULL;				
       
   540 			}
       
   541 		iTempPreset = CIRIsdsPreset::NewL();
       
   542 	    *iTempPreset = *aPreset;
       
   543    	    if(iTempPreset->GetImgUrl().Length() != 0)
       
   544 		    {
       
   545 	    	IssueLogoDownloadRequestL();
       
   546 		   	}
       
   547 	    else /*ImgUrl doesnt exist in the iTempPreset*/
       
   548 		    {
       
   549 	    	//simply ignore it
       
   550 		    }
       
   551 	    }
       
   552  	else
       
   553 	 	{
       
   554 	 	CIRIsdsPreset* tempPreset;
       
   555 	 	tempPreset = CIRIsdsPreset::NewL();
       
   556 	 	CleanupStack::PushL(tempPreset);
       
   557 	 	*tempPreset = *aPreset;
       
   558 	 	iPresetArray->AppendL(tempPreset);
       
   559 	 	CleanupStack::Pop(tempPreset);
       
   560  		iReqFromArray->AppendL(0);
       
   561 	 	}
       
   562  	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Exiting" );
       
   563 	}
       
   564 
       
   565 
       
   566 // -------------------------------------------------------------------------------------------------
       
   567 // CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle)
       
   568 // API is used to download logo from isds/internet
       
   569 // called in the API SendRequestL(CIRIsdsPreset* aPreset,MLogoDownloadObserver* aLogoHandle)
       
   570 // -------------------------------------------------------------------------------------------------
       
   571 //
       
   572 void CIRLogoDownloadEngine::FetchLogoDataL(CIRIsdsPreset* aPreset,
       
   573 				MLogoDownloadObserver* aLogoHandle,TInt aNPVReq)
       
   574 	{
       
   575 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Entering" );
       
   576 	if(!iRunning)
       
   577 	 	{
       
   578 	 	if(aNPVReq==2)
       
   579 		 	{
       
   580 		 	iTempReqFrom = 2;//which means the request came from NowPlayingView	 		
       
   581 		 	}
       
   582 	 	else
       
   583 		 	{
       
   584 		 	iTempReqFrom = 1;//which means the request came from other than NowPlayingView	 		
       
   585 		 	}
       
   586 
       
   587 		iTempLogoHandle = aLogoHandle;
       
   588 		if( iReqBody )
       
   589 		 	{
       
   590 		 	delete iReqBody;
       
   591 		    iReqBody = NULL;
       
   592 		 	}
       
   593 	    if( iRespBody )
       
   594 		    {
       
   595 		    delete iRespBody;
       
   596 		    iRespBody = NULL;
       
   597 		    }
       
   598 		if(iTempPreset)
       
   599 			{
       
   600 			delete iTempPreset;
       
   601 			iTempPreset = NULL;				
       
   602 			}
       
   603 		iTempPreset = CIRIsdsPreset::NewL();
       
   604 	    *iTempPreset = *aPreset;
       
   605 	    if(iTempPreset->GetImgUrl().Length() != 0)
       
   606 		    {
       
   607 	    	IssueLogoDownloadRequestL();
       
   608 			}
       
   609 	    else /*ImgUrl doesnt exist in the iTempPreset*/
       
   610 		    {
       
   611 	    	//simply ignore it
       
   612 		    }
       
   613 	    }
       
   614  	else
       
   615 	 	{
       
   616 	 	CIRIsdsPreset* tempPreset;
       
   617 	 	tempPreset = CIRIsdsPreset::NewL();
       
   618 	 	CleanupStack::PushL(tempPreset);
       
   619 	 	*tempPreset = *aPreset;
       
   620 	 	iPresetArray->AppendL(tempPreset);
       
   621 	 	CleanupStack::Pop(tempPreset);
       
   622 		iObserverArray->AppendL(aLogoHandle);
       
   623 		if(aNPVReq==2)
       
   624 			{
       
   625 	 		iReqFromArray->AppendL(2);
       
   626 			}
       
   627 		else
       
   628 			{
       
   629 	 		iReqFromArray->AppendL(1);
       
   630 			}
       
   631 	 	}
       
   632 	IRLOG_DEBUG( "CIRLogoDownloadEngine::FetchLogoDataL - Exiting" );
       
   633 	}
       
   634 
       
   635 
       
   636 // ----------------------------------------------------------------------------------
       
   637 // CIRLogoDownloadEngine::CheckCacheForLogoL(TInt aValue)
       
   638 // Checks the cache whether the logo is available or not
       
   639 // ----------------------------------------------------------------------------------
       
   640 //
       
   641 void CIRLogoDownloadEngine::CheckCacheForLogoL(TInt aValue)
       
   642 	{
       
   643 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CheckCacheForLogoL - Entering" );
       
   644 	iSendingLogo=aValue;
       
   645 	iResult = 0;
       
   646 	if(iSendingLogo==0)//0 means, this API is called for the usecase of checking cache
       
   647 		{
       
   648 		iCacheReqMade = ETrue;
       
   649 		iCache->CheckCacheL(KLogo,iCacheTempPreset->GetImgUrl(),iForceGet,iResult);		
       
   650 		}
       
   651 	else if(iSendingLogo==1)//1 means, this API is called for the usecase of downloading logo
       
   652 		{
       
   653 		iCacheReqMade = ETrue;
       
   654 		iCache->CheckCacheL(KLogo,iTempPreset->GetImgUrl(),iForceGet,iResult);		
       
   655 		}
       
   656 	if((iResult == 0))//not available in the cache
       
   657 		{
       
   658 		iLogoCached = EFalse;
       
   659 		iIsConditionalGET = EFalse;
       
   660 		}
       
   661 	else if(iResult == -1)//cache is stale/not useable
       
   662 		{
       
   663 		iLogoCached = EFalse;
       
   664 		iIsConditionalGET = ETrue;			
       
   665 		}
       
   666 	else if(iResult == 1)//cache is useable
       
   667 		{
       
   668 		iLogoCached = ETrue;	
       
   669 		}
       
   670 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CheckCacheForLogoL - Exiting" );
       
   671 	}
       
   672 
       
   673 
       
   674 // ----------------------------------------------------------------------------------
       
   675 // CIRLogoDownloadEngine::IssueLogoDownloadRequest()
       
   676 // submits the transaction for to download the logo
       
   677 // ----------------------------------------------------------------------------------
       
   678 //
       
   679 void CIRLogoDownloadEngine::IssueLogoDownloadRequestL()
       
   680 	{
       
   681 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IssueLogoDownloadRequestL - Entering" );
       
   682 	///////////////////////////////////////////////////////////////////////////////////
       
   683 	//This piece of code is for selecting the access point which is already
       
   684 	//set at the begining of the application.  To download the logo the same
       
   685 	//accesse point will be used.
       
   686 	
       
   687 	
       
   688 	
       
   689 		
       
   690 	
       
   691 	if(!iIRNetworkControllerHandle->GetNetworkStatus())
       
   692 		{
       
   693 		iIRNetworkControllerHandle->ChooseAccessPointL();
       
   694 		iLogoRequestPending = ETrue;
       
   695 		}
       
   696 	
       
   697 	else
       
   698 		{
       
   699 		if( iFirstTime )
       
   700 			{
       
   701 			iLogoSession.Close();
       
   702 			TRAPD( LeaveValue, iLogoSession.OpenL() );
       
   703 	    	if ( LeaveValue != KErrNone )
       
   704 	        {
       
   705 	        // Most common error; no access point configured, and session creation
       
   706 	        // leaves with KErrNotFound.
       
   707 	        // Load a string from the resource file and add the error code to string
       
   708 	        User::Leave( LeaveValue );
       
   709 	        }
       
   710 			// Set the HTTP connection properties
       
   711 		    RStringPool strP = iLogoSession.StringPool();
       
   712 		    RHTTPConnectionInfo connInfo = iLogoSession.ConnectionInfo();
       
   713 		    // RSocketServ Handle
       
   714 		    connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketServ,
       
   715 				RHTTPSession::GetTable() ),
       
   716 				THTTPHdrVal( iIRNetworkControllerHandle->GetIRSocketServer().Handle() ) );
       
   717 
       
   718 		    // RConnection Handle
       
   719 		    TInt connPtr = REINTERPRET_CAST( TInt,
       
   720 				&( iIRNetworkControllerHandle->GetIRConnection() ) );
       
   721 		    connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketConnection,
       
   722 				RHTTPSession::GetTable() ), THTTPHdrVal( connPtr ) );
       
   723 
       
   724 		    // HTTP Version ( Specify that i am using HTTP/1.1
       
   725 			connInfo.SetPropertyL( strP.StringF( HTTP::EVersion,
       
   726 				RHTTPSession::GetTable() ),
       
   727 				THTTPHdrVal( strP.StringF( HTTP::EHttp11, RHTTPSession::GetTable() ) ) );
       
   728 
       
   729 			// Set RHttpSession into NetworkController for logo byte counter
       
   730 			iIRNetworkControllerHandle->RegisterLogoDataTransferTrackerL( iLogoSession );
       
   731 
       
   732 			iFirstTime = EFalse;
       
   733 			}
       
   734 
       
   735 
       
   736 		HBufC8* buffertmp = HBufC8::NewLC( iTempPreset->GetImgUrl().Length() + 1 );
       
   737 		TPtr8 buffertmpPtr( buffertmp->Des() );
       
   738 		buffertmpPtr.Copy( iTempPreset->GetImgUrl() );
       
   739 
       
   740 		TUriParser8 uri;
       
   741 		uri.Parse(buffertmpPtr);
       
   742 		RStringF method = iLogoSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
   743 		iTransaction = iLogoSession.OpenTransactionL(uri, *this, method);
       
   744 		RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
       
   745 	    // Set the User-Agent header to UAProf string
       
   746 	    SetHeaderL( hdr, HTTP::EUserAgent,
       
   747 			   iIRNetworkControllerHandle->GetUAProfString()->Des() );
       
   748 
       
   749 		_LIT8(KAccept,"image/jpeg,image/png,image/gif");
       
   750 		SetHeaderL(hdr, HTTP::EAccept, KAccept);
       
   751 		SetHeaderL( hdr, HTTP::EAcceptLanguage, KAcceptLanguage );
       
   752 		
       
   753 		if(iIsConditionalGET)
       
   754 			{
       
   755 			RStringF valStr = iLogoSession.StringPool().OpenFStringL(iETag);
       
   756 			CleanupClosePushL(valStr);
       
   757 			THTTPHdrVal val(valStr);
       
   758 			hdr.SetFieldL(iLogoSession.StringPool().StringF(
       
   759 						HTTP::EIfNoneMatch, RHTTPSession::GetTable()), val);
       
   760 			CleanupStack::PopAndDestroy(&valStr); // valStr
       
   761 			}
       
   762 		CleanupStack::PopAndDestroy(buffertmp); // buffertmp
       
   763 		
       
   764 		//setting the member variable to zero
       
   765 		iRespBodySize = 0;
       
   766 		iTransaction.SubmitL();
       
   767 
       
   768 		iRunning = ETrue;
       
   769 		iLogoRequestPending = ETrue;
       
   770 		iState = ESendingEvent;
       
   771 		}
       
   772 	IRLOG_DEBUG( "CIRLogoDownloadEngine::IssueLogoDownloadRequestL - Exiting" );
       
   773 	}
       
   774 
       
   775 
       
   776 // ----------------------------------------------------------------------------------
       
   777 // CIRLogoDownloadEngine::CancelTransaction()
       
   778 // cancels the current transaction
       
   779 // ----------------------------------------------------------------------------------
       
   780 //
       
   781 EXPORT_C void CIRLogoDownloadEngine::CancelTransaction()
       
   782 	{
       
   783 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CancelTransaction - Entering" );
       
   784 	if(!iRunning)
       
   785 	    {
       
   786 		return;
       
   787 	    }
       
   788 	iTransaction.Close();
       
   789 	iRunning = EFalse;
       
   790 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CancelTransaction - Exiting" );
       
   791 	}
       
   792 
       
   793 
       
   794 // ----------------------------------------------------------------------------------
       
   795 // CIRLogoDownloadEngine::SendPresetWithLogoL()
       
   796 // sends the preset with logo to the requestors
       
   797 // ----------------------------------------------------------------------------------
       
   798 //
       
   799 EXPORT_C void CIRLogoDownloadEngine::SendPresetWithLogoL()
       
   800 	{
       
   801 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendPresetWithLogoL - Entering" );
       
   802 	//Logo has downloaded, so update the status of the variable iLogoRequestPending
       
   803 	iLogoRequestPending = EFalse;
       
   804 	//Remove the imgUrl with parameters from the Preset
       
   805 	//now set imgUrl without parameters in to the Preset
       
   806 	TInt sizeImgUrlWithPar = iTempPreset->GetImgUrl().Length();
       
   807 	TBool hasParameters = EFalse;
       
   808 	RBuf urlWithPar;
       
   809 	urlWithPar.Create(sizeImgUrlWithPar);
       
   810 	urlWithPar.Copy(iTempPreset->GetImgUrl());
       
   811 	RBuf tempBuf;
       
   812 	tempBuf.Create(sizeImgUrlWithPar);
       
   813 
       
   814 	TLex urlLex(urlWithPar);
       
   815 	for(;!urlLex.Eos();)
       
   816 		{
       
   817 		tempBuf.Zero();
       
   818 		while(urlLex.Peek() != '?' && !urlLex.Eos())		
       
   819 			{
       
   820 			tempBuf.Append(urlLex.Get());
       
   821 			}
       
   822 		if(urlLex.Peek() == '?')
       
   823 			{
       
   824 			hasParameters = ETrue;			
       
   825 			}
       
   826 		urlLex.Inc();	
       
   827 		}
       
   828 	
       
   829 	RBuf imgUrl;		
       
   830 	if(hasParameters)		
       
   831 		{
       
   832 		//let say urlWithPar has the value http://www.logos.com/images/test.pngx=100&y=100
       
   833 		//now the tempBuf contains the value  x=100&y=100
       
   834 		TInt sizeUrlParameters = tempBuf.Length();
       
   835 		sizeUrlParameters++; // now this integer contains the size of x=100&y=100 
       
   836 		TInt sizeImgUrl = sizeImgUrlWithPar - sizeUrlParameters;
       
   837 		
       
   838 		//Create a buffer to store the imgUrl without parameters
       
   839 		imgUrl.Create(sizeImgUrl);
       
   840 		imgUrl.Copy(urlWithPar.Left(sizeImgUrl));
       
   841 		iTempPreset->SetImgUrl(imgUrl);
       
   842 		}
       
   843 	else
       
   844 		{
       
   845 		//nothing to be done
       
   846 		//the imgUrl present in the preset is correct, no need to change anything
       
   847 		}
       
   848 
       
   849 	//set the downloaded logo to the preset with the API SetLogoData()
       
   850 	iTempPreset->SetLogoData(*iRespBody);
       
   851 	if(iTempReqFrom == 0)//which means the request came from SearchView while doing Add to Favorite
       
   852 		{
       
   853 		iPresetModifiedStatus = ETrue;
       
   854 		}
       
   855 	else if(iTempReqFrom == 1)//which menas the request came from a view other than NowPlayingView
       
   856 		{
       
   857 		iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
   858 		}
       
   859 	else if(iTempReqFrom == 2)//which menas the request came from NowPlayingView
       
   860 		{
       
   861 		//(1)logo has downloaded freshly
       
   862 		//(2)send the logo to the NPV through PresetLogoDownloadedL
       
   863 		//(3)check whether the preset exists in favdb; if so replace that with new logo
       
   864 		iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
   865 		}
       
   866 		
       
   867     
       
   868 	iTempPreset->SetImgUrl(urlWithPar);	
       
   869 	//Cache the newly downloaded logo
       
   870 	iCache->CacheLogoL(*iRespBody,iTempPreset->GetImgUrl(),*iResponseHeaders);
       
   871 
       
   872 	//close all the buffers
       
   873 	imgUrl.Close();
       
   874 	tempBuf.Close();
       
   875 	urlWithPar.Close();
       
   876 	
       
   877 	iRunning = EFalse;
       
   878 	iState = EIdle;
       
   879 	IRLOG_DEBUG( "CIRLogoDownloadEngine::SendPresetWithLogoL - Exiting" );
       
   880 	}
       
   881 
       
   882 
       
   883 
       
   884 // ---------------------------------------------------------------------------------------
       
   885 // CIRLogoDownloadEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   886 // callback API from MHTTPTransactionCallback
       
   887 // ---------------------------------------------------------------------------------------
       
   888 //
       
   889 void CIRLogoDownloadEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   890 	{
       
   891 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunL - Entering" );
       
   892 	switch (aEvent.iStatus)
       
   893 		{
       
   894 		case THTTPEvent::EGotResponseHeaders:
       
   895 			{
       
   896 		    RHTTPResponse resp = aTransaction.Response();
       
   897 		    TInt status = resp.StatusCode();
       
   898 		    iRespCode = status;
       
   899             ExtractResponseHeadersL(aTransaction);
       
   900 	        if(status >= KStatusOK &&  status < KStatusMultipleChoices)
       
   901 		    {
       
   902 	            THTTPHdrVal headerValue(0);
       
   903 	            RHTTPHeaders headers = resp.GetHeaderCollection();
       
   904 	            TInt error = headers.GetField(iLogoSession.StringPool().StringF(HTTP::EContentLength,
       
   905 	            				 RHTTPSession::GetTable()), 0, headerValue);
       
   906 	            iRespBodySize = 0;
       
   907 	            if (KErrNone == error)
       
   908 	            {
       
   909 	                iRespBodySize = headerValue.Int();
       
   910 	            }
       
   911                 iRespBody = HBufC8::NewL(iRespBodySize+1);
       
   912 		    }
       
   913 			else if( status == KStatusNotModified )//304 means, the content has not modified
       
   914 			    {
       
   915 			    if(iIsConditionalGET)
       
   916 				    {
       
   917 				    iIsConditionalGET = EFalse;
       
   918 				    iRunning = EFalse;
       
   919 				    //update the trust period 
       
   920 					//no problem if it leaves
       
   921 					TRAP_IGNORE(iCache->UpdateTrustPeriodL(KLogo,iTempPreset->GetImgUrl(),
       
   922 												*iResponseHeaders))
       
   923 					//do a forced get because the data is notmodifed in isds and 
       
   924 					//trustable
       
   925 					iForceGet = ETrue;
       
   926 					CheckCacheForLogoL(1);
       
   927 				    }
       
   928 		        }
       
   929 	        else if( status == KStatusGatewayTimeout )
       
   930 		        {
       
   931 				//implementation, if needed
       
   932 				CancelTransaction();
       
   933 				if(iTempReqFrom == 0)
       
   934 					{
       
   935 					//do nothing	
       
   936 					}
       
   937 				else
       
   938 					{
       
   939 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
   940 					}
       
   941 				ManagePresetArrayIndexL();
       
   942 				}
       
   943 
       
   944 			}
       
   945 			break;
       
   946 
       
   947 		case THTTPEvent::EGotResponseBodyData:
       
   948 			{
       
   949 			MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   950 			TPtrC8 dataChunk;
       
   951 			body->GetNextDataPart(dataChunk);
       
   952 			if(iRespBodySize > 0)
       
   953 				{
       
   954 	            iRespBody->Des().Append((const TDesC8&)dataChunk);
       
   955 				}
       
   956 			else if(iRespBody)
       
   957 				{
       
   958 				//which means the body of the response has come
       
   959 				//but in the response headers Content-Length is missing
       
   960 				//for this usecase realloc the iRespBody with the data received					
       
   961 				HBufC8* buffertmp = HBufC8::NewLC( dataChunk.Length() + 1 );
       
   962         		TPtr8 buffertmpPtr( buffertmp->Des() );
       
   963         		buffertmpPtr.Copy( (const TDesC8&)dataChunk );
       
   964         		
       
   965    				TInt tempSize;
       
   966 				tempSize = iRespBody->Length() + dataChunk.Length();
       
   967 				
       
   968 				iRespBody = iRespBody->ReAllocL( tempSize );
       
   969 				TPtr8 ibufferPtr( iRespBody->Des() );
       
   970 				ibufferPtr.Append(buffertmpPtr);
       
   971 
       
   972 
       
   973         		
       
   974 				CleanupStack::PopAndDestroy(buffertmp); // buffertmp        		
       
   975 				}
       
   976 			body->ReleaseData();
       
   977 			}
       
   978 			break;
       
   979 
       
   980 		case THTTPEvent::EResponseComplete:
       
   981 			{
       
   982 			//No implementation
       
   983 			}
       
   984 			break;
       
   985 
       
   986 		case THTTPEvent::ESucceeded:
       
   987 	        {
       
   988 			iTransaction.Close();
       
   989 			if(iIsConditionalGET)
       
   990 				{
       
   991 				iIsConditionalGET = EFalse;					
       
   992 				}
       
   993 		 
       
   994 			iRunning = EFalse;
       
   995 			//set the downloaded logo in the preset and send it back to the requestor
       
   996 			SendPresetWithLogoL();
       
   997 			ManagePresetArrayIndexL();
       
   998 	        }
       
   999 			break;
       
  1000 
       
  1001 		case THTTPEvent::EFailed:
       
  1002 			{
       
  1003 			aTransaction.Close();
       
  1004 			iRunning = EFalse;
       
  1005 			iState = EIdle;
       
  1006 			if( iRespCode == KStatusNotModified )//304 means, the content has not modified
       
  1007 				{
       
  1008 				//do nothing;					
       
  1009 				}
       
  1010 			else
       
  1011 				{
       
  1012 				if(iTempReqFrom == 0)
       
  1013 					{
       
  1014 					//do nothing
       
  1015 					}
       
  1016 				else
       
  1017 					{
       
  1018 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
  1019 					}
       
  1020 				}
       
  1021 			ManagePresetArrayIndexL();
       
  1022 			}
       
  1023 	        break;
       
  1024 
       
  1025 		default:
       
  1026 
       
  1027 			if (aEvent.iStatus < 0)
       
  1028 				{
       
  1029 				aTransaction.Close();
       
  1030 				iRunning = EFalse;
       
  1031 				iState = EIdle;
       
  1032 				if(iTempReqFrom == 0)
       
  1033 					{
       
  1034 					//do nothing
       
  1035 					}
       
  1036 				else
       
  1037 					{
       
  1038 					iTempLogoHandle->PresetLogoDownloadError(iTempPreset);					
       
  1039 					}
       
  1040 				ManagePresetArrayIndexL();
       
  1041 		        }
       
  1042 			break;
       
  1043 		}
       
  1044 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunL - Exiting" );
       
  1045 	}
       
  1046 
       
  1047 
       
  1048 // ------------------------------------------------------------------------------------------------------------------
       
  1049 // CIRLogoDownloadEngine::MHFRunError(TInt /*aError*/, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
  1050 // callback API from MHTTPTransactionCallback
       
  1051 // ------------------------------------------------------------------------------------------------------------------
       
  1052 //
       
  1053 TInt CIRLogoDownloadEngine::MHFRunError(TInt /*aError*/, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
  1054 	{
       
  1055 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunError - Entering" );
       
  1056 	aTransaction.Close();
       
  1057 	iRunning = EFalse;
       
  1058 	iState = EIdle;
       
  1059 	if(iIsConditionalGET)
       
  1060 		{
       
  1061 		iIsConditionalGET = EFalse;	
       
  1062 		}
       
  1063 	if(iTempReqFrom == 0)
       
  1064 		{
       
  1065 		//do nothing	
       
  1066 		}
       
  1067 	else
       
  1068 		{
       
  1069 		iTempLogoHandle->PresetLogoDownloadError(iTempPreset);		
       
  1070 		}
       
  1071 	TRAP_IGNORE(ManagePresetArrayIndexL())
       
  1072 	IRLOG_DEBUG( "CIRLogoDownloadEngine::MHFRunError - Exiting" );
       
  1073 	return KErrNone;
       
  1074 	}
       
  1075 
       
  1076 // --------------------------------------------------------------------
       
  1077 // CIRLogoDownloadEngine::GetNextDataPart(TPtrC8& aDataPart)
       
  1078 // callback API from MHTTPDataSupplier
       
  1079 // --------------------------------------------------------------------
       
  1080 TBool CIRLogoDownloadEngine::GetNextDataPart(TPtrC8& aDataPart)
       
  1081 	{
       
  1082 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetNextDataPart - Entering" );
       
  1083     aDataPart.Length();
       
  1084     iReqBody->Length();
       
  1085     aDataPart.Set(*iReqBody);
       
  1086 	IRLOG_DEBUG( "CIRLogoDownloadEngine::GetNextDataPart - Exiting" );
       
  1087 	return ETrue;
       
  1088 	}
       
  1089 
       
  1090 // --------------------------------------------------------------------
       
  1091 // CIRLogoDownloadEngine::ReleaseData()
       
  1092 // callback API from MHTTPDataSupplier
       
  1093 // --------------------------------------------------------------------
       
  1094 void CIRLogoDownloadEngine::ReleaseData()
       
  1095 	{
       
  1096 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseData" );
       
  1097    //No implementaion
       
  1098 	}
       
  1099 
       
  1100 
       
  1101 // --------------------------------------------------------------------
       
  1102 // CIRLogoDownloadEngine::Reset()
       
  1103 // callback API from MHTTPDataSupplier
       
  1104 // --------------------------------------------------------------------
       
  1105 TInt CIRLogoDownloadEngine::Reset()
       
  1106 	{
       
  1107 	IRLOG_DEBUG( "CIRLogoDownloadEngine::Reset" );
       
  1108 	return KErrNone;
       
  1109 	}
       
  1110 
       
  1111 
       
  1112 // --------------------------------------------------------------------
       
  1113 // CIRLogoDownloadEngine::OverallDataSize()
       
  1114 // callback API from MHTTPDataSupplier
       
  1115 // --------------------------------------------------------------------
       
  1116 TInt CIRLogoDownloadEngine::OverallDataSize()
       
  1117 	{
       
  1118 	IRLOG_DEBUG( "CIRLogoDownloadEngine::OverallDataSize" );
       
  1119 	return iReqBody->Length();
       
  1120 	}
       
  1121 
       
  1122 // ---------------------------------------------------------------------------
       
  1123 // CIRLogoDownloadEngine::ExtractResponseHeadersL( RHTTPTransaction aTransaction )
       
  1124 // Used to Extract the response headers.
       
  1125 // ---------------------------------------------------------------------------
       
  1126 //
       
  1127 
       
  1128 void CIRLogoDownloadEngine::ExtractResponseHeadersL(const RHTTPTransaction&
       
  1129 	aTransaction )
       
  1130     {
       
  1131     IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Entering" );
       
  1132     RHTTPResponse response = aTransaction.Response();
       
  1133     RHTTPHeaders respHeader = response.GetHeaderCollection();
       
  1134     THTTPHdrFieldIter iterator = respHeader.Fields();
       
  1135     RStringPool httpStringPool = aTransaction.Session().StringPool();
       
  1136     iterator.First();
       
  1137     HBufC8 *headerField = HBufC8::NewLC( KMaxHeaderNameLength +
       
  1138 		KMaxHeaderValueLength );
       
  1139     HBufC8 *fieldValBuf = HBufC8::NewLC( KMaxHeaderValueLength );
       
  1140     while ( iterator.AtEnd() == EFalse )
       
  1141         {
       
  1142         RStringTokenF fieldName = iterator();
       
  1143         RStringF fieldNameStr = httpStringPool.StringF( fieldName );
       
  1144         THTTPHdrVal fieldVal;
       
  1145         if ( respHeader.GetField( fieldNameStr, 0, fieldVal ) == KErrNone )
       
  1146             {
       
  1147             const TDesC8 &fieldNameDesC = fieldNameStr.DesC();
       
  1148             headerField->Des().Copy( fieldNameDesC.Left(
       
  1149 				KMaxHeaderNameLength ) );
       
  1150             fieldValBuf->Des().Zero();
       
  1151             switch ( fieldVal.Type() )
       
  1152                 {
       
  1153                 // the value is an integer
       
  1154                 //lint restore -e747:Significant prototype
       
  1155                 //coercion (arg. no. 1) int to long long  :
       
  1156                 case THTTPHdrVal::KTIntVal: fieldValBuf->Des().Num(
       
  1157 					fieldVal.Int() );
       
  1158                 break;
       
  1159                 // the value is a case-insensitive string
       
  1160                 case THTTPHdrVal::KStrFVal:
       
  1161                     {
       
  1162                     RStringF fieldValStr = httpStringPool.StringF(
       
  1163 						fieldVal.StrF() );
       
  1164                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
  1165                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
  1166 						KMaxHeaderValueLength ) );
       
  1167                     }
       
  1168                 break;
       
  1169                 // the value is a case-sensitive string
       
  1170                 case THTTPHdrVal::KStrVal:
       
  1171                     {
       
  1172                     RString fieldValStr = httpStringPool.String(
       
  1173 						fieldVal.Str() );
       
  1174                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
  1175                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
  1176 						KMaxHeaderValueLength ) );
       
  1177                     }
       
  1178                 break;
       
  1179                 // the value is a date/time
       
  1180                 case THTTPHdrVal::KDateVal:
       
  1181                     {
       
  1182                     TDateTime date = fieldVal.DateTime();
       
  1183                     TTime t( date );
       
  1184 //                    if ( iSetNonUAProfUserAgent )
       
  1185 //       					{
       
  1186        		            HttpDateHeaderReceived( *headerField ,t );
       
  1187 //       					}
       
  1188                     }
       
  1189                 break;
       
  1190                 // the value is type is unknown
       
  1191                 default:
       
  1192                     break;
       
  1193                 }
       
  1194             // Display HTTP header field name and value
       
  1195             headerField->Des().Append( KDPColon );
       
  1196             headerField->Des().Append( *fieldValBuf );
       
  1197             HttpHeaderReceived( *headerField );
       
  1198             }
       
  1199         ++iterator;
       
  1200         }
       
  1201     
       
  1202     CleanupStack::PopAndDestroy( fieldValBuf );
       
  1203     CleanupStack::PopAndDestroy( headerField );
       
  1204     IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractResponseHeadersL - Exiting." );
       
  1205     }
       
  1206 
       
  1207 
       
  1208 
       
  1209 // ---------------------------------------------------------------------------
       
  1210 //  CIRLogoDownloadEngine::HttpHeaderReceived( const TDesC8& aHeaderData )
       
  1211 //  indicate that an HTTP header is received.
       
  1212 // ---------------------------------------------------------------------------
       
  1213 //
       
  1214 void CIRLogoDownloadEngine::HttpHeaderReceived( const TDesC8& aHeaderData )
       
  1215     {
       
  1216     IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpHeaderReceived - Entering." );
       
  1217 	_LIT8(KDelim,":");
       
  1218 	_LIT8(KContentType,"Content-Type");
       
  1219 	ExtractHeaderValue(aHeaderData,KContentType,KDelim,iResponseHeaders->
       
  1220 		iContentType);
       
  1221 	_LIT8(KMaxAge,"max-age");
       
  1222 	_LIT8(KDelimEqual,"=");
       
  1223 	ExtractHeaderValue(aHeaderData,KMaxAge,KDelimEqual,iResponseHeaders->
       
  1224 		iMaxAge);
       
  1225 	_LIT8(KContentLength,"Content-Length");
       
  1226 	ExtractHeaderValue(aHeaderData,KContentLength,KDelim,iResponseHeaders->
       
  1227 		iContentLength);
       
  1228 	_LIT8(KExpires,"Expires");
       
  1229 	ExtractHeaderValue(aHeaderData,KExpires,KDelim,iResponseHeaders->iExpires);
       
  1230 	_LIT8(KETag,"ETag");
       
  1231 	ExtractHeaderValue(aHeaderData,KETag,KDelim,iResponseHeaders->iETag);
       
  1232 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpHeaderReceived - Exiting." );
       
  1233     }
       
  1234 
       
  1235 // ---------------------------------------------------------------------------
       
  1236 //  CIRLogoDownloadEngine::ExtractHeaderValue(const TDesC8& aHeaderData,const
       
  1237 //	TDesC8& aHeaderName,const TDesC8& aDelimeter,TDes8& aHolder) const
       
  1238 //  Used to build the CIRHttpResponseData
       
  1239 // ---------------------------------------------------------------------------
       
  1240 //
       
  1241 void CIRLogoDownloadEngine::ExtractHeaderValue(const TDesC8& aHeaderData,const
       
  1242 	TDesC8& aHeaderName,const TDesC8& aDelimeter,TDes8& aHolder) const
       
  1243 	{
       
  1244 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractHeaderValue - Entering" );
       
  1245 	TInt position = aHeaderData.Find(aHeaderName);
       
  1246 	if( position >= 0)
       
  1247 		{
       
  1248 		TPtrC8 headerValue = aHeaderData.Mid(position);
       
  1249 		TInt delimeterPosition = headerValue.Find(aDelimeter);
       
  1250 		if( delimeterPosition != KErrNotFound )
       
  1251 			{
       
  1252 			delimeterPosition++;
       
  1253 			TPtrC8 value = headerValue.Mid(delimeterPosition);
       
  1254 			aHolder.Copy(value);
       
  1255 			aHolder.TrimAll();
       
  1256 			}
       
  1257 		}
       
  1258 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ExtractHeaderValue - Exiting." );
       
  1259 	}
       
  1260 
       
  1261 // ---------------------------------------------------------------------------
       
  1262 //  CIRLogoDownloadEngine::HttpDateHeaderReceived(const TDesC8 &aHeader,
       
  1263 //	const TTime& aTime )
       
  1264 //  Used to build the CIRHttpResponseData members
       
  1265 // ---------------------------------------------------------------------------
       
  1266 //
       
  1267 void CIRLogoDownloadEngine::HttpDateHeaderReceived(const TDesC8 &aHeader,
       
  1268 	const TTime& aTime )
       
  1269 	{
       
  1270 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpDateHeaderReceived - Entering." );
       
  1271 	_LIT8(KDate,"Date");
       
  1272 	_LIT8(KLastModified,"Last-Modified");
       
  1273 	TInt position = aHeader.Find(KDate);
       
  1274 	if( position != KErrNotFound )
       
  1275 		{
       
  1276 		iResponseHeaders->iDate = aTime;
       
  1277 		return ;
       
  1278 		}
       
  1279 	position = aHeader.Find(KLastModified);
       
  1280 	if( position != KErrNotFound )
       
  1281 		{
       
  1282 		iResponseHeaders->iLastModified = aTime;
       
  1283 		}
       
  1284 	IRLOG_DEBUG( "CIRLogoDownloadEngine::HttpDateHeaderReceived - Exiting." );
       
  1285 	}
       
  1286 
       
  1287 
       
  1288 
       
  1289 
       
  1290 
       
  1291 // --------------------------------------------------------------------
       
  1292 // CIRLogoDownloadEngine::ManagePresetArrayIndexL()
       
  1293 // To make another download request if exists in the queue
       
  1294 // To update the iPresetArray current index
       
  1295 // --------------------------------------------------------------------
       
  1296 void CIRLogoDownloadEngine::ManagePresetArrayIndexL()
       
  1297 	{
       
  1298 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManagePresetArrayIndexL - Entering" );
       
  1299 	TInt PresetArrayLength = iPresetArray->Count();
       
  1300 	if((PresetArrayLength>0) && (iPresetArrayPos < PresetArrayLength))
       
  1301 		{
       
  1302 		CIRIsdsPreset* tempPreset = CIRIsdsPreset::NewL();
       
  1303 		CleanupStack::PushL(tempPreset);
       
  1304     	*tempPreset = *(iPresetArray->At(iPresetArrayPos));
       
  1305     		if(iReqFromArrayPos < iReqFromArray->Count()  &&  iReqFromArray->At(iReqFromArrayPos) == 0 )
       
  1306         		{
       
  1307     			FetchLogoDataL(tempPreset);
       
  1308         		}
       
  1309         	else if(iObserverArrayPos < iObserverArray->Count())
       
  1310     	    	{
       
  1311     			FetchLogoDataL(tempPreset,iObserverArray->At(iObserverArrayPos),
       
  1312     							iReqFromArray->At(iReqFromArrayPos));
       
  1313     			++iObserverArrayPos;
       
  1314     	    	}
       
  1315 		++iPresetArrayPos;
       
  1316 		++iReqFromArrayPos;
       
  1317 //		delete tempPreset;
       
  1318 		CleanupStack::PopAndDestroy(tempPreset);
       
  1319 		}
       
  1320 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManagePresetArrayIndexL - Exiting" );
       
  1321 	}
       
  1322 
       
  1323 
       
  1324 // --------------------------------------------------------------------
       
  1325 // CIRLogoDownloadEngine::ManageCachePresetArrayIndexL()
       
  1326 // To make another download request if exists in the queue
       
  1327 // To update the iCachePresetArray current index
       
  1328 // --------------------------------------------------------------------
       
  1329 void CIRLogoDownloadEngine::ManageCachePresetArrayIndexL()
       
  1330 	{
       
  1331 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManageCachePresetArrayIndexL - Exiting" );
       
  1332  	TInt CachePresetArrayLength = iCachePresetArray->Count();
       
  1333 	if((CachePresetArrayLength>0) && (iCachePresetArrayPos < CachePresetArrayLength))
       
  1334 		{
       
  1335 		CIRIsdsPreset* tempPreset;
       
  1336 		tempPreset = CIRIsdsPreset::NewL();
       
  1337 		CleanupStack::PushL(tempPreset);
       
  1338 		*tempPreset = *(iCachePresetArray->At(iCachePresetArrayPos));
       
  1339 		
       
  1340 		if(iCacheReqFromArrayPos < iCacheReqFromArray->Count()  &&
       
  1341 					 iCacheReqFromArray->At(iCacheReqFromArrayPos) == 0 )
       
  1342     		{
       
  1343 			SendRequestL(tempPreset,KLogoSize,KLogoSize);
       
  1344     		}
       
  1345     	else if(iCacheObserverArrayPos < iCacheObserverArray->Count())
       
  1346 	    	{
       
  1347 			SendRequestL(tempPreset,iCacheObserverArray->At(iCacheObserverArrayPos),
       
  1348 					iCacheReqFromArray->At(iCacheReqFromArrayPos));
       
  1349 			++iCacheObserverArrayPos;
       
  1350 	    	}
       
  1351 		++iCachePresetArrayPos;
       
  1352 		++iCacheReqFromArrayPos;
       
  1353 //		delete tempPreset;
       
  1354 		CleanupStack::PopAndDestroy(tempPreset);
       
  1355  		}
       
  1356 	IRLOG_DEBUG( "CIRLogoDownloadEngine::ManageCachePresetArrayIndexL - Exiting" );
       
  1357 	}
       
  1358 
       
  1359 // -----------------------------------------------------
       
  1360 // CIRLogoDownloadEngine::CacheError()
       
  1361 // Called from cachemgmt in case of an error
       
  1362 // callback API from MIRCacheObserver
       
  1363 // -----------------------------------------------------
       
  1364 void CIRLogoDownloadEngine::CacheError()
       
  1365  	{
       
  1366 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheError" );
       
  1367 
       
  1368  	//code here, if needed
       
  1369  	}
       
  1370 
       
  1371 // -----------------------------------------------------
       
  1372 // CIRLogoDownloadEngine::CacheFailed()
       
  1373 // Called from cachemgmt in case of cache failure
       
  1374 // callback API from MIRCacheObserver
       
  1375 // -----------------------------------------------------
       
  1376 void CIRLogoDownloadEngine::CacheFailed()
       
  1377  	{
       
  1378  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheFailed" );
       
  1379  	//code here, if needed
       
  1380  	}
       
  1381 
       
  1382 // -----------------------------------------------------
       
  1383 // CIRLogoDownloadEngine::CacheInvalid()
       
  1384 // Called from cachemgmt in case cache is invalid
       
  1385 // callback API from MIRCacheObserver
       
  1386 // -----------------------------------------------------
       
  1387 void CIRLogoDownloadEngine::CacheInvalid()
       
  1388 	{
       
  1389 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheInvalid - Entering" );
       
  1390 	iETag = iCache->iETag;
       
  1391 	IRLOG_DEBUG( "CIRLogoDownloadEngine::CacheInvalid - Exiting" );
       
  1392 	}
       
  1393 
       
  1394 // -----------------------------------------------------
       
  1395 // CIRLogoDownloadEngine::CachedStructureL(TInt aChoice)
       
  1396 // Called from cachemgmt data retrival is successful
       
  1397 // callback API from MIRCacheObserver
       
  1398 // -----------------------------------------------------
       
  1399 void CIRLogoDownloadEngine::CachedStructureL(TInt aChoice)
       
  1400  	{
       
  1401  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CachedStructureL - Entering" );
       
  1402 	if(iCacheReqMade)
       
  1403 		{
       
  1404 		iCacheReqMade = EFalse;
       
  1405 		if(aChoice == KCacheAvailable)
       
  1406 			{
       
  1407 			
       
  1408 		 	TInt sizeImgUrlWithPmts = 0;
       
  1409 		 	//Remove the imgUrl with parameters from the Preset
       
  1410 			//now set imgUrl without parameters in to the Preset
       
  1411 			if(iSendingLogo==0)
       
  1412 				{
       
  1413 				sizeImgUrlWithPmts = iCacheTempPreset->GetImgUrl().Length();		
       
  1414 				}
       
  1415 			else if(iSendingLogo==1)
       
  1416 				{
       
  1417 				sizeImgUrlWithPmts = iTempPreset->GetImgUrl().Length();		
       
  1418 				}
       
  1419 			else if(iSendingLogo==2)
       
  1420 				{
       
  1421 				sizeImgUrlWithPmts = KTen;			
       
  1422 				}
       
  1423 			TBool hasParameters = EFalse;
       
  1424 			RBuf urlWithPar;
       
  1425 			urlWithPar.Create(sizeImgUrlWithPmts);
       
  1426 			if(iSendingLogo==0)
       
  1427 				{
       
  1428 				urlWithPar.Copy(iCacheTempPreset->GetImgUrl());
       
  1429 				}
       
  1430 			else if(iSendingLogo==1)
       
  1431 				{
       
  1432 				urlWithPar.Copy(iTempPreset->GetImgUrl());
       
  1433 				}
       
  1434 			else if(iSendingLogo==2)
       
  1435 				{
       
  1436 				_LIT(KNone,"");
       
  1437 				urlWithPar.Copy(KNone);
       
  1438 				}
       
  1439 				
       
  1440 			RBuf tempBuf;
       
  1441 			tempBuf.Create(sizeImgUrlWithPmts);
       
  1442 
       
  1443 			TLex urlLex(urlWithPar);
       
  1444 			for(;!urlLex.Eos();)
       
  1445 				{
       
  1446 				tempBuf.Zero();
       
  1447 				while(urlLex.Peek() != '?' && !urlLex.Eos())		
       
  1448 					{
       
  1449 					tempBuf.Append(urlLex.Get());
       
  1450 					}
       
  1451 				if(urlLex.Peek() == '?')
       
  1452 					{
       
  1453 					hasParameters = ETrue;			
       
  1454 					}
       
  1455 				urlLex.Inc();	
       
  1456 				}
       
  1457 			
       
  1458 			RBuf imgUrl;		
       
  1459 			if(hasParameters)		
       
  1460 				{
       
  1461 				//let say urlWithPar has the value http://www.logos.com/images/test.pngx=100&y=100
       
  1462 				//now the tempBuf contains the value  x=100&y=100
       
  1463 				TInt sizeUrlParameters = tempBuf.Length();
       
  1464 				sizeUrlParameters++; // now this integer contains the size of x=100&y=100 
       
  1465 				TInt sizeImgUrl = sizeImgUrlWithPmts - sizeUrlParameters;
       
  1466 				
       
  1467 				//Create a buffer to store the imgUrl without parameters
       
  1468 				imgUrl.Create(sizeImgUrl);
       
  1469 				imgUrl.Copy(urlWithPar.Left(sizeImgUrl));
       
  1470 				if(iSendingLogo==0)
       
  1471 					{
       
  1472 					iCacheTempPreset->SetImgUrl(imgUrl);			
       
  1473 					}
       
  1474 				else if(iSendingLogo==1)
       
  1475 					{
       
  1476 					iTempPreset->SetImgUrl(imgUrl);			
       
  1477 					}
       
  1478 				}
       
  1479 			else
       
  1480 				{
       
  1481 				//nothing to be done
       
  1482 				//the imgUrl present in the preset is correct, no need to change anything
       
  1483 				}
       
  1484 			
       
  1485 			
       
  1486 			
       
  1487 			if(iSendingLogo==0)
       
  1488 			 	{
       
  1489 			 	if(aChoice == KCacheAvailable)//logo is available in the cache
       
  1490 				 	{
       
  1491 					iCacheTempPreset->SetLogoData(iCache->iLogoData);	 		
       
  1492 				 	}
       
  1493 				if(iCacheReqFrom == 0)
       
  1494 					{
       
  1495 					iPresetModifiedStatus = ETrue;
       
  1496 					}
       
  1497 				else
       
  1498 					{
       
  1499 					iCacheTempLogoHandle->PresetLogoDownloadedL(iCacheTempPreset);
       
  1500 					}	
       
  1501 				
       
  1502 				
       
  1503 				ManageCachePresetArrayIndexL(); 	
       
  1504 			 	}
       
  1505 			else if(iSendingLogo==1)	
       
  1506 				{
       
  1507 			 	if(aChoice == KCacheAvailable)//logo is available in the cache
       
  1508 				 	{
       
  1509 					iTempPreset->SetLogoData(iCache->iLogoData);	 		
       
  1510 				 	}
       
  1511 				if(iTempReqFrom == 0)
       
  1512 					{
       
  1513 					iPresetModifiedStatus = ETrue;
       
  1514 					}
       
  1515 				else
       
  1516 					{
       
  1517 					iTempLogoHandle->PresetLogoDownloadedL(iTempPreset);
       
  1518 					}		 	
       
  1519 					
       
  1520 			 	ManagePresetArrayIndexL();
       
  1521 			 	}
       
  1522 			else if(iSendingLogo==2)//logo request from the search results (while displaying logo)
       
  1523 				{
       
  1524 				//code here, if needed			
       
  1525 				}
       
  1526 
       
  1527 			//close all the buffers
       
  1528 			imgUrl.Close();
       
  1529 			tempBuf.Close();
       
  1530 			urlWithPar.Close();
       
  1531 			}
       
  1532 			
       
  1533 		}
       
  1534  	IRLOG_DEBUG( "CIRLogoDownloadEngine::CachedStructureL - Exiting" );
       
  1535  	}
       
  1536  	
       
  1537 // -----------------------------------------------------
       
  1538 // CIRLogoDownloadEngine::ReleaseResources()
       
  1539 // Releases the resources held by logo download engine
       
  1540 // Used to close the Http Session if already open
       
  1541 // -----------------------------------------------------
       
  1542 void CIRLogoDownloadEngine::ReleaseResources()
       
  1543 	{
       
  1544  	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseResources - Entering" );
       
  1545 	CancelTransaction();
       
  1546 	iLogoSession.Close();
       
  1547     iFirstTime = ETrue;
       
  1548  	IRLOG_DEBUG( "CIRLogoDownloadEngine::ReleaseResources - Exiting" );
       
  1549 	} 	
       
  1550 
       
  1551 // -----------------------------------------------------------------------------
       
  1552 // Notified by network controller when network is active, to reissue the request  
       
  1553 // NotifyActiveNetworkObserversL()
       
  1554 // -----------------------------------------------------------------------------
       
  1555 
       
  1556 void CIRLogoDownloadEngine::NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent)
       
  1557 	{
       
  1558 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NotifyActiveNetworkObserversL - Entering" );
       
  1559 	switch(aEvent)
       
  1560 		{
       
  1561 		case ENetworkConnectionDisconnected:
       
  1562 			{
       
  1563 			ReleaseResources();
       
  1564 			}
       
  1565 			break;
       
  1566 		case ENetworkConnectionEstablished:
       
  1567 			{
       
  1568 			if( iLogoRequestPending )
       
  1569 				{
       
  1570 				IssueLogoDownloadRequestL();
       
  1571 				}
       
  1572 			}
       
  1573 		}
       
  1574 	IRLOG_DEBUG( "CIRLogoDownloadEngine::NotifyActiveNetworkObserversL - Exiting" );
       
  1575 	}
       
  1576 
       
  1577  	
       
  1578 // -----------------------------------------------------------------------------
       
  1579 // Notified by network controller when user cancels network connection, to reset 
       
  1580 // the pending requests  
       
  1581 // ResetPendingRequests()
       
  1582 // -----------------------------------------------------------------------------
       
  1583 void CIRLogoDownloadEngine::ResetPendingRequests(TBool /*aValue*/)
       
  1584 	{
       
  1585 		
       
  1586 	}
       
  1587