browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpDownload.cpp
branchRCL_3
changeset 94 919f36ff910f
parent 93 79859ed3eea9
child 103 be5f8c9adf67
equal deleted inserted replaced
93:79859ed3eea9 94:919f36ff910f
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 //#include <platform/mw/Browser_platform_variant.hrh>
    21 #include    <browser_platform_variant.hrh>
    22 #include    <Browser_platform_variant.hrh>
       
    23 #include    "HeaderField.h"
    22 #include    "HeaderField.h"
    24 #include    "HttpDownloadManagerServerEngine.h"
    23 #include    "HttpDownloadManagerServerEngine.h"
    25 #include    "HttpClientApp.h"
    24 #include    "HttpClientApp.h"
    26 #include    "FileExt.h"
    25 #include    "FileExt.h"
    27 #include    "HttpDownload.h"
    26 #include    "HttpDownload.h"
    28 #include    "HttpStorage.h"
    27 #include    "HttpStorage.h"
    29 #include    "HttpDownloadMgrLogger.h"
    28 #include    "HttpDownloadMgrLogger.h"
    30 #include    "bautils.h"
    29 #include    "bautils.h"
    31 
    30 
    32 #include    <commdbconnpref.h>
    31 #include    <CommDbConnPref.h>
    33 #include    <uri16.h>
    32 #include    <Uri16.h>
    34 #include    <f32file.h>
    33 #include    <F32FILE.H>
    35 #include    <escapeutils.h>
    34 #include    <EscapeUtils.h>
    36 #include    <httpfiltercommonstringsext.h>
    35 #include    <httpfiltercommonstringsext.h>
    37 #include    <tinternetdate.h>
    36 #include    <tinternetdate.h>
    38 #include    <sysutil.h>
    37 #include    <SysUtil.h>
    39 
       
    40 // following line is temporary: AVKON dependency removal
       
    41 #undef BRDO_APP_GALLERY_SUPPORTED_FF
       
    42 
    38 
    43 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    39 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    44 #include    <MGXFileManagerFactory.h>
    40 #include    <MGXFileManagerFactory.h>
    45 #include    <CMGXFileManager.h>
    41 #include    <CMGXFileManager.h>
    46 #endif
    42 #endif
    48 #include    <DcfEntry.h>
    44 #include    <DcfEntry.h>
    49 #include    <DcfRep.h>
    45 #include    <DcfRep.h>
    50 
    46 
    51 #include    <pathinfo.h>
    47 #include    <pathinfo.h>
    52 
    48 
       
    49 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
    50 #include <DownloadPathHandler.h>
       
    51 #endif
    53 // EXTERNAL DATA STRUCTURES
    52 // EXTERNAL DATA STRUCTURES
    54 //extern  ?external_data;
    53 //extern  ?external_data;
    55 
    54 
    56 // EXTERNAL FUNCTION PROTOTYPES
    55 // EXTERNAL FUNCTION PROTOTYPES  
    57 //extern ?external_function( ?arg_type,?arg_type );
    56 //extern ?external_function( ?arg_type,?arg_type );
    58 
    57 
    59 // CONSTANTS
    58 // CONSTANTS
    60 const TInt32 KDMgrInfoFileId = 0x2002;      // id to check if it's really an info file
    59 const TInt32 KDMgrInfoFileId = 0x2002;      // id to check if it's really an info file
    61 const TInt32 KDmgrVersionNumber = 0x0301;   // version number of the info file
    60 const TInt32 KDmgrVersionNumber = 0x0301;   // version number of the info file
    62 const TInt   KUrlFixChar = '_';
    61 const TInt   KUrlFixChar = '_';
    63 const TInt KMaxHeaderOfMultipart = 32000;
    62 const TInt KMaxHeaderOfMultipart = 32000;
    64 const TInt KRespSizeForRecognition = 1024;  //for THttpProgressState EHttpContTypeRecognitionAvail
    63 const TInt KRespSizeForRecognition = 1024;  //for THttpProgressState EHttpContTypeRecognitionAvail
    65 const TInt KMinDataSizeToSend = (32*1024);  //for Browser Control to call NewDownloadL
    64 const TInt KMinDataSizeToSend = (32*1024);  //for Browser Control to call NewDownloadL     
    66 const TInt KErrCodHttpDownloadPaused = -20045;  //Error code set by the CodHandler if the download is paused by the client
    65 const TInt KErrCodHttpDownloadPaused = -20045;  //Error code set by the CodHandler if the download is paused by the client
    67 const TInt KHttp903LossOfService = 903; //Error code set by the CodHandler if connection is lost
    66 const TInt KHttp903LossOfService = 903; //Error code set by the CodHandler if connection is lost
    68 const TInt KHttp954LoaderError = 954; //Error code set by the CodHandler if Loader error is found
    67 const TInt KHttp954LoaderError = 954; //Error code set by the CodHandler if Loader error is found
    69 _LIT8( KHttpScheme, "http" );
    68 _LIT8( KHttpScheme, "http" );
    70 _LIT8( KHttpsScheme, "https" );
    69 _LIT8( KHttpsScheme, "https" );
   112 #define _OMADLOTA2_MULTI_DOWNLOAD	(iCodDlData && iCodDlData->Count()>1)
   111 #define _OMADLOTA2_MULTI_DOWNLOAD	(iCodDlData && iCodDlData->Count()>1)
   113 
   112 
   114 // LOCAL CONSTANTS AND MACROS
   113 // LOCAL CONSTANTS AND MACROS
   115 const TInt KDMHttpErrorBase = -25000;
   114 const TInt KDMHttpErrorBase = -25000;
   116 #define GLOBAL_HTTP_ERROR( err ) ( KDMHttpErrorBase - err )
   115 #define GLOBAL_HTTP_ERROR( err ) ( KDMHttpErrorBase - err )
   117 const TInt  KErrMultipeObjectDownloadFailed = -20046;
   116 const TInt  KErrMultipeObjectDownloadFailed = -20046;  
   118 
   117 
   119 // MODULE DATA STRUCTURES
   118 // MODULE DATA STRUCTURES
   120 //enum ?declaration
   119 //enum ?declaration
   121 //typedef ?declaration
   120 //typedef ?declaration
   122 
   121 
   204             ++iDontFireEvent;
   203             ++iDontFireEvent;
   205 
   204 
   206             TRAPD(err, PauseL() );
   205             TRAPD(err, PauseL() );
   207 
   206 
   208             --iDontFireEvent;
   207             --iDontFireEvent;
   209 
   208             
   210             User::LeaveIfError( err );
   209             User::LeaveIfError( err );
   211             }
   210             }
   212         }
   211         }
   213 
   212 
   214     if( !iStorage->CheckContentFileIntegrityL() )
   213     if( !iStorage->CheckContentFileIntegrityL() )
   215         {
   214         {
   216         if (iStorage->ProgressiveDownload() &&
   215         if (iStorage->ProgressiveDownload() && 
   217              iStorage->Length() == iStorage->DownloadedSize() )
   216              iStorage->Length() == iStorage->DownloadedSize() ) 
   218             // If it was a progressive download
   217             // If it was a progressive download 
   219             // and downloaded size = content length,
   218             // and downloaded size = content length,
   220             // it means that download was not properly closed
   219             // it means that download was not properly closed
   221             // in the previous session
   220             // in the previous session
   222             {
   221             {
   223             ReInitializeDownload();
   222             ReInitializeDownload();
   225         else
   224         else
   226             {
   225             {
   227             OnError( KErrUnknown, EContentFileIntegrity );
   226             OnError( KErrUnknown, EContentFileIntegrity );
   228             }
   227             }
   229         }
   228         }
   230 
   229         
   231         iMoveInProgress = EFalse;
   230         iMoveInProgress = EFalse;          
   232     }
   231     }
   233 
   232 
   234 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   235 // CHttpDownload::NewL
   234 // CHttpDownload::NewL
   236 // Two-phased constructor.
   235 // Two-phased constructor.
   243     {
   242     {
   244     __ASSERT_DEBUG( aId, DMPanic( KErrArgument ) );
   243     __ASSERT_DEBUG( aId, DMPanic( KErrArgument ) );
   245     CHttpDownload* self = new( ELeave ) CHttpDownload( aClientApp,
   244     CHttpDownload* self = new( ELeave ) CHttpDownload( aClientApp,
   246                                                        aId,
   245                                                        aId,
   247                                                        aClAppInstance );
   246                                                        aClAppInstance );
   248 
   247     
   249     CleanupStack::PushL( self );
   248     CleanupStack::PushL( self );
   250     self->ConstructL( aUrl );
   249     self->ConstructL( aUrl );
   251     CleanupStack::Pop();
   250     CleanupStack::Pop();
   252 
   251 
   253     return self;
   252     return self;
   254     }
   253     }
   255 
   254 
   256 
   255     
   257 // Destructor
   256 // Destructor
   258 CHttpDownload::~CHttpDownload()
   257 CHttpDownload::~CHttpDownload()
   259     {
   258     {
   260     ++iDontFireEvent;
   259     ++iDontFireEvent;
   261 
   260 
   270     delete iHttpPassword;
   269     delete iHttpPassword;
   271     delete iHttpProxyRealm;
   270     delete iHttpProxyRealm;
   272     delete iHttpProxyUsername;
   271     delete iHttpProxyUsername;
   273     delete iHttpProxyPassword;
   272     delete iHttpProxyPassword;
   274     delete iContentType;
   273     delete iContentType;
   275     delete iDDType;
   274     delete iDDType;    
   276     delete iMediaType;
   275     delete iMediaType;
   277     delete iDlName;
   276     delete iDlName;
   278 	delete iDispositionType;
   277 	delete iDispositionType;
   279     delete iFileMan;
   278     delete iFileMan;
   280 
   279     
   281 
   280     
   282     delete iHashedMsgBody;
   281     delete iHashedMsgBody;
   283     delete iDownloadInfo;
   282     delete iDownloadInfo;
   284     delete iAttachmentFileName;
   283     delete iAttachmentFileName;
   285 
   284 
   286     if( iTransValid )
   285     if( iTransValid )
   313         }
   312         }
   314 
   313 
   315     delete iStorage;
   314     delete iStorage;
   316     iStorage = NULL;
   315     iStorage = NULL;
   317     delete iHeaderOfMultipart;
   316     delete iHeaderOfMultipart;
   318 
   317     
   319     iMoveInProgress = EFalse;
   318     iMoveInProgress = EFalse;
   320 
   319     
   321     CLOG_CLOSE;
   320     CLOG_CLOSE;
   322     }
   321     }
   323 
   322 
   324 // -----------------------------------------------------------------------------
   323 // -----------------------------------------------------------------------------
   325 // CHttpDownload::Attach
   324 // CHttpDownload::Attach
   328 // -----------------------------------------------------------------------------
   327 // -----------------------------------------------------------------------------
   329 //
   328 //
   330 EXPORT_C void CHttpDownload::Attach( CHttpClientAppInstance* aClientAppInstance )
   329 EXPORT_C void CHttpDownload::Attach( CHttpClientAppInstance* aClientAppInstance )
   331     {
   330     {
   332     LOGGER_ENTERFN( "CHttpDownload::Attach" );
   331     LOGGER_ENTERFN( "CHttpDownload::Attach" );
   333 
   332     
   334     __ASSERT_DEBUG( !iPDClAppInstance, DMPanic( KErrInUse) );
   333     __ASSERT_DEBUG( !iPDClAppInstance, DMPanic( KErrInUse) );
   335     iPDClAppInstance = aClientAppInstance;
   334     iPDClAppInstance = aClientAppInstance;
   336     }
   335     }
   337 
   336 
   338 // -----------------------------------------------------------------------------
   337 // -----------------------------------------------------------------------------
   378             }
   377             }
   379         else if( iDlState == EHttpDlInprogress )
   378         else if( iDlState == EHttpDlInprogress )
   380             {
   379             {
   381             TriggerEvent( EHttpDlAlreadyRunning );
   380             TriggerEvent( EHttpDlAlreadyRunning );
   382             }
   381             }
   383 
   382             
   384         // This is the place where client already set every continue
   383         // This is the place where client already set every continue
   385         // download attribute
   384         // download attribute
   386         StoreDownloadInfoL();
   385         StoreDownloadInfoL();
   387 
   386 
   388         return;
   387         return;
   420 
   419 
   421                 ParseRequestedUrlL();   // iCurrentUrl is initialized there
   420                 ParseRequestedUrlL();   // iCurrentUrl is initialized there
   422                 ParseDownloadNameL();
   421                 ParseDownloadNameL();
   423                 StoreDownloadInfoL();
   422                 StoreDownloadInfoL();
   424                 SetDownloadStatus( EHttpStarted );
   423                 SetDownloadStatus( EHttpStarted );
   425 
   424                 
   426                if( !iConnHandler )
   425                if( !iConnHandler )
   427                     // assign download to the connhandler
   426                     // assign download to the connhandler
   428                     // connection is surely up because it was created from client side
   427                     // connection is surely up because it was created from client side
   429                     // iClAppInstance also must be valid because it's a continue download
   428                     // iClAppInstance also must be valid because it's a continue download
   430                     {
   429                     {
   458                 {
   457                 {
   459                 TriggerEvent( EHttpDlMultipleMOCompleted );
   458                 TriggerEvent( EHttpDlMultipleMOCompleted );
   460                 return;
   459                 return;
   461                 }
   460                 }
   462             else if( iRestartAction == ERestartForced )
   461             else if( iRestartAction == ERestartForced )
   463                 // doesn't matter what we have.
   462                 // doesn't matter what we have. 
   464                 // Download must be restarted from the very beginning
   463                 // Download must be restarted from the very beginning
   465                 {
   464                 {
   466                 ForcedRestartL();
   465                 ForcedRestartL();
   467                 }
   466                 }
   468             else if( iRestartAction == ERestartIfExpired )
   467             else if( iRestartAction == ERestartIfExpired )
   520         {
   519         {
   521         iClAppInstance = iPDClAppInstance;
   520         iClAppInstance = iPDClAppInstance;
   522         iPDClAppInstance = NULL;
   521         iPDClAppInstance = NULL;
   523         }
   522         }
   524     if( iClAppInstance )
   523     if( iClAppInstance )
   525         {
   524         {        
   526         if( !iConnHandler )
   525         if( !iConnHandler )
   527             {
   526             {
   528             iConnHandler = iClAppInstance->ConnHandler();
   527             iConnHandler = iClAppInstance->ConnHandler();
   529             }
   528             }
   530 
   529 
   532         }
   531         }
   533 
   532 
   534     iDlStartedByClient = ETrue;
   533     iDlStartedByClient = ETrue;
   535 
   534 
   536     SetDownloadStatus( EHttpStarted );
   535     SetDownloadStatus( EHttpStarted );
   537 
   536     
   538     }
   537     }
   539 
   538 
   540 // -----------------------------------------------------------------------------
   539 // -----------------------------------------------------------------------------
   541 // CHttpDownload::PauseL
   540 // CHttpDownload::PauseL
   542 // ?implementation_description
   541 // ?implementation_description
   634                 if( iPDClAppInstance )
   633                 if( iPDClAppInstance )
   635                     {
   634                     {
   636                     SetDownloadStatus( EHttpProgNone, EHttpDlDeleting );
   635                     SetDownloadStatus( EHttpProgNone, EHttpDlDeleting );
   637                     return;
   636                     return;
   638                     }
   637                     }
   639                 }
   638                 }        
   640             }
   639             }
   641         }
   640         }
   642 
   641 
   643     // Do not inform user about that we are in deleteing state
   642     // Do not inform user about that we are in deleteing state
   644     // This won't be reenabled at the end of this function so
   643     // This won't be reenabled at the end of this function so
   645     // don't call delete only from outside of this class.
   644     // don't call delete only from outside of this class.
   646     ++iDontFireEvent;
   645     ++iDontFireEvent;
   647 
   646     
   648     TPath folder;
   647     TPath folder;
   649     TFileName file;
   648     TFileName file;
   650 
   649 
   651     // delete info file
   650     // delete info file
   652     iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
   651     iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
   658     iClientApp->Engine()->CODDownloadInfoFolder( iClientApp, folder );
   657     iClientApp->Engine()->CODDownloadInfoFolder( iClientApp, folder );
   659     file.Format( _L("%S%d"), &folder, iId );
   658     file.Format( _L("%S%d"), &folder, iId );
   660     //delete main info file
   659     //delete main info file
   661     err = iClientApp->Engine()->Fs().Delete( file );
   660     err = iClientApp->Engine()->Fs().Delete( file );
   662     CLOG_WRITE_2( "Delete info file: %S, err : %d", &file, err );
   661     CLOG_WRITE_2( "Delete info file: %S, err : %d", &file, err );
   663 
   662     
   664     //delete subinfo file
   663     //delete subinfo file
   665     CFileMan* fileMan = CFileMan::NewL(iClientApp->Engine()->Fs() );
   664     CFileMan* fileMan = CFileMan::NewL(iClientApp->Engine()->Fs() );
   666     file.Format( _L("%S%d_*"), &folder, iId );
   665     file.Format( _L("%S%d_*"), &folder, iId );
   667     fileMan->Delete( file );
   666     fileMan->Delete( file );
   668     delete fileMan;
   667     delete fileMan;
   669 
   668         
   670 
   669 
   671     // to make sure the CHttpStorage releases the content file
   670     // to make sure the CHttpStorage releases the content file
   672     // and deletes it.
   671     // and deletes it.
   673     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EDeleteFile;
   672     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EDeleteFile;
   674 
   673     
   675     if( iStorage->DestFNameSet() && iDlState == EHttpDlMultipleMOCompleted )
   674     if( iStorage->DestFNameSet() && iDlState == EHttpDlMultipleMOCompleted )
   676         // Do NOT delete the file: if the destination filename was
   675         // Do NOT delete the file: if the destination filename was
   677         // set by the client and download completed.
   676         // set by the client and download completed.
   678 	        {
   677 	        {
   679 	        CLOG_WRITE("Keep file");
   678 	        CLOG_WRITE("Keep file");
   680 	        closeOp = CHttpStorage::EKeepFile;
   679 	        closeOp = CHttpStorage::EKeepFile;
   681 	        }
   680 	        }
   682 
   681 	        
   683 	if( iStorage->RFileSetByClient())
   682 	if( iStorage->RFileSetByClient())
   684 	    {
   683 	    {
   685 	    TBool pausable;
   684 	    TBool pausable;
   686         GetBoolAttributeL( EDlAttrPausable, pausable );
   685         GetBoolAttributeL( EDlAttrPausable, pausable );
   687         if( iDlState == EHttpDlMultipleMOCompleted || ( iDlState == EHttpDlInprogress && pausable ) )
   686         if( iDlState == EHttpDlMultipleMOCompleted || ( iDlState == EHttpDlInprogress && pausable ) )
   688             {
   687             {
   689             CLOG_WRITE("Keep file");
   688             CLOG_WRITE("Keep file");
   690 	        closeOp = CHttpStorage::EKeepFile;
   689 	        closeOp = CHttpStorage::EKeepFile;
   691             }
   690             }
   692 
   691 		
   693 	    }
   692 	    }
   694     if( iCodDlData )
   693     if( iCodDlData )
   695 	    {
   694 	    {
   696 	    // For User Delete when all the Downloads are moved to gallery
   695 	    // For User Delete when all the Downloads are moved to gallery
   697 	    if( EHttpDlMultipleMOCompleted == iDlState && closeOp == CHttpStorage::EDeleteFile )
   696 	    if( EHttpDlMultipleMOCompleted == iDlState && closeOp == CHttpStorage::EDeleteFile )
   698 		    {
   697 		    {
   699 		    for(TInt i = 1; i <= iCodDlData->Count(); i++)
   698 		    for(TInt i = 1; i <= iCodDlData->Count(); i++)
   700 		    	{
   699 		    	{
   701 		    	TPtrC fullName = ((*iCodDlData)[i])->DestFilename();
   700 		    	TPtrC fullName = ((*iCodDlData)[i])->DestFilename();
   702 		    	ClientApp()->Engine()->Fs().Delete( fullName );
   701 		    	ClientApp()->Engine()->Fs().Delete( fullName );
   703 		    	}
   702 		    	}	
   704 		    }
   703 		    }
   705 		// For User Cancel to Cancel Multiple download, Current and Queued DLs will be delete, completed ones will be kept
   704 		// For User Cancel to Cancel Multiple download, Current and Queued DLs will be delete, completed ones will be kept    
   706 		else if( EHttpDlInprogress == iDlState || EHttpDlPaused == iDlState || EHttpDlDeleting == iDlState)
   705 		else if( EHttpDlInprogress == iDlState || EHttpDlPaused == iDlState || EHttpDlDeleting == iDlState)
   707 			{
   706 			{
   708 			for(TInt i = 1; i <= iCodDlData->Count(); i++)
   707 			for(TInt i = 1; i <= iCodDlData->Count(); i++)
   709 		    	{
   708 		    	{
   710 		    	if( EInProgress == ((*iCodDlData)[i])->State() || EFailed == ((*iCodDlData)[i])->State() )	// OnGoing and Queued will be deleted
   709 		    	if( EInProgress == ((*iCodDlData)[i])->State() || EFailed == ((*iCodDlData)[i])->State() )	// OnGoing and Queued will be deleted	  
   711 			    	{
   710 			    	{
   712 			    	TPtrC fullName = ((*iCodDlData)[i])->DestFilename();
   711 			    	TPtrC fullName = ((*iCodDlData)[i])->DestFilename();
   713 			    	if(fullName.Length())
   712 			    	if(fullName.Length())
   714 			    	    {
   713 			    	    {
   715 			    	    ClientApp()->Engine()->Fs().Delete( fullName );
   714 			    	    ClientApp()->Engine()->Fs().Delete( fullName );	    
   716 			    	    }
   715 			    	    }
   717 			    	}
   716 			    	}  
   718 		    	//else if( ESucceeded == ((*iCodDlData)[i])->State() )
   717 		    	//else if( ESucceeded == ((*iCodDlData)[i])->State() ) 
   719 		    	// Completed ones will be kept and moved to Gallery
   718 		    	// Completed ones will be kept and moved to Gallery
   720 		    	else if( ESucceeded == ((*iCodDlData)[i])->State() )
   719 		    	else if( ESucceeded == ((*iCodDlData)[i])->State() )
   721 			    	{
   720 			    	{
   722 			    	MoveInDelete(i);
   721 			    	MoveInDelete(i);
   723 			    	}
   722 			    	}
   724 		    	}
   723 		    	}	
   725 			}
   724 			} 	
   726 	    }
   725 	    }
   727     else
   726     else
   728     	{
   727     	{
   729     	iStorage->CloseDestinationFile( closeOp );
   728     	iStorage->CloseDestinationFile( closeOp );
   730     	}
   729     	}
   731     // when delete there's no store -> no leave
   730     // when delete there's no store -> no leave
   732     //  aClAppInstance->ClientApp()->UnregisterDownload( this );
   731     //  aClAppInstance->ClientApp()->UnregisterDownload( this ); 
   733     }
   732     }
   734 
   733 
   735 
   734 
   736 // -----------------------------------------------------------------------------
   735 // -----------------------------------------------------------------------------
   737 // CHttpDownload::DeleteInfoFile
   736 // CHttpDownload::DeleteInfoFile
   740 // -----------------------------------------------------------------------------
   739 // -----------------------------------------------------------------------------
   741 //
   740 //
   742 EXPORT_C void CHttpDownload::DeleteInfoFile( CHttpClientAppInstance* aClAppInstance )
   741 EXPORT_C void CHttpDownload::DeleteInfoFile( CHttpClientAppInstance* aClAppInstance )
   743     {
   742     {
   744     CLOG_WRITE( "DeleteInfoFile()" );
   743     CLOG_WRITE( "DeleteInfoFile()" );
   745 
   744     
   746     // This should be called only after the completion of download
   745     // This should be called only after the completion of download
   747 	if( ! (EHttpDlMultipleMOCompleted == iDlState &&
   746 	if( ! (EHttpDlMultipleMOCompleted == iDlState && 
   748     		(
   747     		( 
   749     		EHttpProgContentFileMoved == iProgState ||
   748     		EHttpProgContentFileMoved == iProgState ||
   750     		EHttpProgContentFileMovedAndDestFNChanged == iProgState
   749     		EHttpProgContentFileMovedAndDestFNChanged == iProgState 
   751     		)
   750     		)
   752     	))
   751     	))
   753 		{
   752 		{
   754    		return;
   753    		return;
   755 		}
   754 		}
   756 
   755 
   757     // Do not inform user about that we are in deleteing state
   756     // Do not inform user about that we are in deleteing state
   758     // This won't be reenabled at the end of this function so
   757     // This won't be reenabled at the end of this function so
   759     // don't call delete only from outside of this class.
   758     // don't call delete only from outside of this class.
   760     ++iDontFireEvent;
   759     ++iDontFireEvent;
   761 
   760     
   762     TPath folder;
   761     TPath folder;
   763     TFileName file;
   762     TFileName file;
   764 
   763 
   765     // delete info file
   764     // delete info file
   766     iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
   765     iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
   770 
   769 
   771     // delete cod info file
   770     // delete cod info file
   772     iClientApp->Engine()->CODDownloadInfoFolder( iClientApp, folder );
   771     iClientApp->Engine()->CODDownloadInfoFolder( iClientApp, folder );
   773     file.Format( _L("%S%d"), &folder, iId );
   772     file.Format( _L("%S%d"), &folder, iId );
   774     CLOG_WRITE_1( "Delete info file: %S", &file );
   773     CLOG_WRITE_1( "Delete info file: %S", &file );
   775     iClientApp->Engine()->Fs().Delete( file );
   774     iClientApp->Engine()->Fs().Delete( file );    
   776 
   775     
   777     //delete subinfo file
   776     //delete subinfo file
   778     CFileMan* fileMan = CFileMan::NewL(iClientApp->Engine()->Fs() );
   777     CFileMan* fileMan = CFileMan::NewL(iClientApp->Engine()->Fs() );
   779     file.Format( _L("%S%d_*"), &folder, iId );
   778     file.Format( _L("%S%d_*"), &folder, iId );
   780     fileMan->Delete( file );
   779     fileMan->Delete( file );
   781     delete fileMan;
   780     delete fileMan;
   782 
   781     
   783 
   782 
   784     // to make sure the CHttpStorage releases the content file
   783     // to make sure the CHttpStorage releases the content file
   785     // and deletes it.
   784     // and deletes it.
   786     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EDeleteFile;
   785     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EDeleteFile;
   787 
   786     
   788     if( iStorage->DestFNameSet() && iDlState == EHttpDlMultipleMOCompleted )
   787     if( iStorage->DestFNameSet() && iDlState == EHttpDlMultipleMOCompleted )
   789         // Do NOT delete the file: if the destination filename was
   788         // Do NOT delete the file: if the destination filename was
   790         // set by the client and download completed.
   789         // set by the client and download completed.
   791         {
   790         {
   792         CLOG_WRITE("Keep file");
   791         CLOG_WRITE("Keep file");
   793         closeOp = CHttpStorage::EKeepFile;
   792         closeOp = CHttpStorage::EKeepFile;
   794         }
   793         }
   795 
   794         
   796     iStorage->CloseDestinationFile( closeOp );
   795     iStorage->CloseDestinationFile( closeOp );
   797 
   796 
   798     // when delete there's no store -> no leave
   797     // when delete there's no store -> no leave	
   799     aClAppInstance->ClientApp()->UnregisterDownload( this );
   798     aClAppInstance->ClientApp()->UnregisterDownload( this ); 
   800     }
   799     }
   801 
   800 
   802 
   801 
   803 // -----------------------------------------------------------------------------
   802 // -----------------------------------------------------------------------------
   804 // CHttpDownload::MoveL
   803 // CHttpDownload::MoveL
   807 // -----------------------------------------------------------------------------
   806 // -----------------------------------------------------------------------------
   808 //
   807 //
   809 EXPORT_C void CHttpDownload::MoveL()
   808 EXPORT_C void CHttpDownload::MoveL()
   810     {
   809     {
   811     LOGGER_ENTERFN( "MoveL" );
   810     LOGGER_ENTERFN( "MoveL" );
   812 
   811     
   813 
   812     
   814     if(iMoveInProgress)
   813     if(iMoveInProgress) 
   815     {
   814     {
   816     	CLOG_WRITE(" return MoveL  ");
   815     	CLOG_WRITE(" return MoveL  ");
   817     	return;
   816     	return;
   818     }
   817     }
   819 
   818 
   831 
   830 
   832     if( iProgState == EHttpProgMovingContentFile )
   831     if( iProgState == EHttpProgMovingContentFile )
   833         {
   832         {
   834         User::Leave( KErrInUse );
   833         User::Leave( KErrInUse );
   835         }
   834         }
   836 
   835         
   837         //File is already moved. Ignore the move
   836         //File is already moved. Ignore the move
   838     if( iProgState == EHttpProgContentFileMovedAndDestFNChanged ||
   837     if( iProgState == EHttpProgContentFileMovedAndDestFNChanged ||
   839 
   838     
   840       	iProgState ==  EHttpProgContentFileMoved )
   839       	iProgState ==  EHttpProgContentFileMoved )
   841         {
   840         {
   842         return;
   841         return;
   843         }
   842         }
   844 
   843         
   845     __ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
   844     __ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
   846     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
   845     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
   847 
   846     
   848     if(_OMADLOTA2_MULTI_DOWNLOAD)
   847     if(_OMADLOTA2_MULTI_DOWNLOAD)
   849         {
   848         {
   850 		iMOMoved = 1;
   849 		iMOMoved = 1;
   851 		SetDownloadStatus( EHttpProgMovingContentFile, iDlState );
   850 		SetDownloadStatus( EHttpProgMovingContentFile, iDlState );
   852 		MoveDownloadedMediaObjectL(iMOMoved);
   851 		MoveDownloadedMediaObjectL(iMOMoved);
   855 
   854 
   856 
   855 
   857 	RFs &rFs = iClientApp->Engine()->Fs();
   856 	RFs &rFs = iClientApp->Engine()->Fs();
   858 	if(!iFileMan)
   857 	if(!iFileMan)
   859 		{
   858 		{
   860 		iFileMan = CFileMan::NewL(rFs);
   859 		iFileMan = CFileMan::NewL(rFs);	
   861 		}
   860 		}
   862 
   861 
   863     CLOG_WRITE_1( "Src: %S", iStorage->LocalFilename() );
   862     CLOG_WRITE_1( "Src: %S", iStorage->LocalFilename() );
   864     CLOG_WRITE_1( "Dest: %S", iStorage->DestFilename() );
   863     CLOG_WRITE_1( "Dest: %S", iStorage->DestFilename() );
   865     UpdateDestFileNameL();
   864     UpdateDestFileNameL();
   873     do
   872     do
   874         {
   873         {
   875         CreateIndexedNameL(uniqueName , fileNamePtr , index);
   874         CreateIndexedNameL(uniqueName , fileNamePtr , index);
   876         if( !BaflUtils::FileExists( rFs , *uniqueName ) )
   875         if( !BaflUtils::FileExists( rFs , *uniqueName ) )
   877         //Check if file name exist in Destination path
   876         //Check if file name exist in Destination path
   878         //Generate Unique name if exist
   877         //Generate Unique name if exist 
   879             {
   878             {
   880             bFound =ETrue;
   879             bFound =ETrue;
   881             break;
   880             break;
   882             }
   881             }
   883         iDlNameChanged = ETrue;
   882         iDlNameChanged = ETrue;
   884 
   883             
   885         }while( !bFound );
   884         }while( !bFound );
   886     CleanupStack::PopAndDestroy( fileName );
   885     CleanupStack::PopAndDestroy( fileName );           
   887 
   886 
   888   	if( iDlNameChanged )
   887   	if( iDlNameChanged )
   889   	    {
   888   	    {
   890   	    HBufC16* destFileName ;
   889   	    HBufC16* destFileName ;
   891   	    destFileName = iStorage->DestFilename();
   890   	    destFileName = iStorage->DestFilename();           
   892   	    TPtr destFileNamePtr = destFileName->Des();
   891   	    TPtr destFileNamePtr = destFileName->Des();
   893   	    destFileNamePtr.Replace(0, destFileNamePtr.Length() , *uniqueName);
   892   	    destFileNamePtr.Replace(0, destFileNamePtr.Length() , *uniqueName);    
   894   	    TInt lastSlashPos = destFileNamePtr.LocateReverse( '\\' );
   893   	    TInt lastSlashPos = destFileNamePtr.LocateReverse( '\\' );
   895   	    TPtr dlName = destFileNamePtr.MidTPtr(lastSlashPos +1 );
   894   	    TPtr dlName = destFileNamePtr.MidTPtr(lastSlashPos +1 );
   896         TInt dotPos = iDlName->LocateReverse( '.' );
   895         TInt dotPos = iDlName->LocateReverse( '.' );
   897         if( dotPos == KErrNotFound )
   896         if( dotPos == KErrNotFound )
   898             {
   897             {
   899             //Remove Extension from dlName as it was not present in old iDlName
   898             //Remove Extension from dlName as it was not present in old iDlName 
   900             dotPos = dlName.LocateReverse( '.' );
   899             dotPos = dlName.LocateReverse( '.' );
   901             if(dotPos != KErrNotFound )
   900             if(dotPos != KErrNotFound )
   902                 {
   901                 {
   903                 dlName.Copy( dlName.Left(dotPos));
   902                 dlName.Copy( dlName.Left(dotPos));
   904                 }
   903                 }            
   905             }
   904             }
   906   	    //download name has changed
   905   	    //download name has changed
   907   	    ReallocateStringL( iDlName, dlName, KDownloadNameMaxSize );
   906   	    ReallocateStringL( iDlName, dlName, KDownloadNameMaxSize );
   908   	    }
   907   	    }      
   909 
   908   	    
   910   	TInt err =iFileMan->Move( *iStorage->LocalFilename(),
   909   	TInt err =iFileMan->Move( *iStorage->LocalFilename(), 
   911                                         *iStorage->DestFilename(),
   910                                         *iStorage->DestFilename(), 
   912                                         CFileMan::EOverWrite,
   911                                         CFileMan::EOverWrite,
   913                                         iStatus );
   912                                         iStatus );
   914     if(err != KErrNone)
   913     if(err != KErrNone)
   915     	{
   914     	{
   916     	iMoveInProgress = EFalse;
   915     	iMoveInProgress = EFalse;
   917     	CLOG_WRITE("setting iMoveInProgress false when move fails");
   916     	CLOG_WRITE("setting iMoveInProgress false when move fails");
   918     	}
   917     	}
   919 
   918     	
   920     User::LeaveIfError( err );
   919     User::LeaveIfError( err ); 
   921     // waiting for move to complete
   920     // waiting for move to complete
   922     SetActive();
   921     SetActive();
   923     SetDownloadStatus( EHttpProgMovingContentFile, iDlState );
   922     SetDownloadStatus( EHttpProgMovingContentFile, iDlState );
   924     }
   923     }
   925 
   924 
   927 // CHttpDownload::GetIntAttributeL
   926 // CHttpDownload::GetIntAttributeL
   928 // ?implementation_description
   927 // ?implementation_description
   929 // (other items were commented in a header).
   928 // (other items were commented in a header).
   930 // -----------------------------------------------------------------------------
   929 // -----------------------------------------------------------------------------
   931 //
   930 //
   932 EXPORT_C void CHttpDownload::GetIntAttributeL( THttpDownloadAttrib aAttribute,
   931 EXPORT_C void CHttpDownload::GetIntAttributeL( THttpDownloadAttrib aAttribute, 
   933 							                   TInt32& aValue )
   932 							                   TInt32& aValue )
   934     {
   933     {
   935     LOGGER_ENTERFN( "GetIntAttributeL" );
   934     LOGGER_ENTERFN( "GetIntAttributeL" );
   936     CLOG_WRITE_1( "Attr(%d)", aAttribute );
   935     CLOG_WRITE_1( "Attr(%d)", aAttribute );
   937 
   936 
   976 
   975 
   977         case EDlAttrMultipleMOLength:
   976         case EDlAttrMultipleMOLength:
   978             {
   977             {
   979             if ( iCodDownload )
   978             if ( iCodDownload )
   980                 {
   979                 {
   981                 aValue = iMoLength;
   980                 aValue = iMoLength;    
   982                 }
   981                 }
   983             else
   982             else
   984                 {
   983                 {
   985                 aValue = iStorage->Length();
   984                 aValue = iStorage->Length();
   986                 }
   985                 }
   989 
   988 
   990         case EDlAttrMultipleMODownloadedSize:
   989         case EDlAttrMultipleMODownloadedSize:
   991             {
   990             {
   992             if( iCodDownload )
   991             if( iCodDownload )
   993                 {
   992                 {
   994                 aValue = iStorage->MoDownloadedSize();
   993                 aValue = iStorage->MoDownloadedSize();    
   995                 }
   994                 }
   996             else
   995             else
   997                 {
   996                 {
   998                 aValue = iStorage->DownloadedSize();
   997                 aValue = iStorage->DownloadedSize();
   999                 }
   998                 }
  1000             }
   999             }
  1001             break;
  1000             break;
  1002 
  1001             
  1003         case EDlAttrLength:
  1002         case EDlAttrLength:
  1004             {
  1003             {
  1005             aValue = iStorage->Length();
  1004             aValue = iStorage->Length();
  1006             }
  1005             }
  1007             break;
  1006             break;
  1078             aValue = iMethod;
  1077             aValue = iMethod;
  1079             }
  1078             }
  1080             break;
  1079             break;
  1081 
  1080 
  1082         case EDlAttrFotaPckgId:
  1081         case EDlAttrFotaPckgId:
  1083             {
  1082             {     
  1084             aValue = iFotaPckgId;
  1083             aValue = iFotaPckgId;
  1085             }
  1084             }
  1086             break;
  1085             break;
  1087 
  1086             
  1088         case EDlAttrNumMediaObjects:
  1087         case EDlAttrNumMediaObjects:
  1089             {
  1088             {
  1090             aValue = 1;
  1089             aValue = 1;
  1091             if(iCodDlData)
  1090             if(iCodDlData)
  1092                 {
  1091                 {
  1102         case EDlAttrActivePlayedDownload:
  1101         case EDlAttrActivePlayedDownload:
  1103             {
  1102             {
  1104             aValue = iActivePlayedDownload;
  1103             aValue = iActivePlayedDownload;
  1105             }
  1104             }
  1106             break;
  1105             break;
  1107 
  1106             
       
  1107         case EDlAttrDestRemovable:
       
  1108             {
       
  1109             aValue = iStorage->RemovableDest();
       
  1110             }
       
  1111             break;            
       
  1112             
  1108         default:
  1113         default:
  1109             {
  1114             {
  1110             CLOG_WRITE_1( "Unknown int attrib: %d", aAttribute );
  1115             CLOG_WRITE_1( "Unknown int attrib: %d", aAttribute );
  1111 #ifdef __WINS__
  1116 #ifdef __WINS__
  1112             DMPanic( KErrArgument );
  1117             DMPanic( KErrArgument );
  1114             User::Leave( KErrArgument );
  1119             User::Leave( KErrArgument );
  1115 #endif
  1120 #endif
  1116             }
  1121             }
  1117             break;
  1122             break;
  1118         }
  1123         }
  1119 
  1124     
  1120     iNoRealError = EFalse;
  1125     iNoRealError = EFalse;
  1121     }
  1126     }
  1122 
  1127     
  1123 // -----------------------------------------------------------------------------
  1128 // -----------------------------------------------------------------------------
  1124 // CHttpDownload::GetIntAttributeL
  1129 // CHttpDownload::GetIntAttributeL
  1125 // ?implementation_description
  1130 // ?implementation_description
  1126 // (other items were commented in a header).
  1131 // (other items were commented in a header).
  1127 // -----------------------------------------------------------------------------
  1132 // -----------------------------------------------------------------------------
  1128 //
  1133 //
  1129 EXPORT_C void CHttpDownload::GetIntAttributeL( THttpDownloadAttrib aAttribute,
  1134 EXPORT_C void CHttpDownload::GetIntAttributeL( THttpDownloadAttrib aAttribute, 
  1130 							                   TInt32& aMoIndex,
  1135 							                   TInt32& aMoIndex,
  1131 							                   TInt32& aValue )
  1136 							                   TInt32& aValue )
  1132     {
  1137     {
  1133     LOGGER_ENTERFN( "GetIntAttributeL" );
  1138     LOGGER_ENTERFN( "GetIntAttributeL" );
  1134     CLOG_WRITE_1( "Attr(%d)", aAttribute );
  1139     CLOG_WRITE_1( "Attr(%d)", aAttribute );
  1135 
  1140     
  1136     if (!iCodDlData)
  1141     if (!iCodDlData)
  1137     	{
  1142     	{
  1138     	aValue = 0;
  1143     	aValue = 0;
  1139     	return;
  1144     	return;
  1140     	}
  1145     	}
  1141     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1146     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1142     	{
  1147     	{
  1143     	User::Leave( KErrArgument );
  1148     	User::Leave( KErrArgument );
  1144     	}
  1149     	}
  1145 
  1150     
  1146     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1151     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1147     iNoRealError = ETrue;
  1152     iNoRealError = ETrue;
  1148 
  1153 
  1149     switch( aAttribute )
  1154     switch( aAttribute )
  1150         {
  1155         {
  1163             	{
  1168             	{
  1164             	CMediaDataBase* moData = (*iCodDlData)[index+1];
  1169             	CMediaDataBase* moData = (*iCodDlData)[index+1];
  1165             	if ((moData->State() == ESucceeded) || (moData->State() == EInProgress))
  1170             	if ((moData->State() == ESucceeded) || (moData->State() == EInProgress))
  1166             		dlSize -= moData->DownloadedSize();
  1171             		dlSize -= moData->DownloadedSize();
  1167             	}
  1172             	}
  1168 
  1173             
  1169             aValue = dlSize;
  1174             aValue = dlSize;
  1170             }
  1175             }
  1171             break;
  1176             break;
  1172 
  1177             
  1173         case EDlAttrLength:
  1178         case EDlAttrLength:
  1174 	        {
  1179 	        {
  1175 	        aValue = iStorage->Length();
  1180 	        aValue = iStorage->Length();
  1176 	        }
  1181 	        }
  1177 	        break;
  1182 	        break;
  1195             break;
  1200             break;
  1196 
  1201 
  1197         case EDlAttrMethod:
  1202         case EDlAttrMethod:
  1198             {
  1203             {
  1199             aValue = mediaData->Method();
  1204             aValue = mediaData->Method();
       
  1205             }
       
  1206             break;
       
  1207             
       
  1208         case EDlAttrDestRemovable:
       
  1209             {
       
  1210             aValue = mediaData->DesRemovable();
  1200             }
  1211             }
  1201             break;
  1212             break;
  1202 
  1213 
  1203         default:
  1214         default:
  1204             {
  1215             {
  1209             User::Leave( KErrArgument );
  1220             User::Leave( KErrArgument );
  1210 #endif
  1221 #endif
  1211             }
  1222             }
  1212             break;
  1223             break;
  1213         }
  1224         }
  1214 
  1225     
  1215     iNoRealError = EFalse;
  1226     iNoRealError = EFalse;
  1216     }
  1227     }
  1217 
  1228 
  1218 // -----------------------------------------------------------------------------
  1229 // -----------------------------------------------------------------------------
  1219 // CHttpDownload::GetBoolAttributeL
  1230 // CHttpDownload::GetBoolAttributeL
  1220 // ?implementation_description
  1231 // ?implementation_description
  1221 // (other items were commented in a header).
  1232 // (other items were commented in a header).
  1222 // -----------------------------------------------------------------------------
  1233 // -----------------------------------------------------------------------------
  1223 //
  1234 //
  1224 EXPORT_C void CHttpDownload::GetBoolAttributeL( THttpDownloadAttrib aAttribute,
  1235 EXPORT_C void CHttpDownload::GetBoolAttributeL( THttpDownloadAttrib aAttribute, 
  1225 								                TBool& aValue )
  1236 								                TBool& aValue )
  1226     {
  1237     {
  1227     LOGGER_ENTERFN( "GetBoolAttributeL" );
  1238     LOGGER_ENTERFN( "GetBoolAttributeL" );
  1228     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1239     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1229 
  1240 
  1287 
  1298 
  1288         case EDlAttrCodDownload:
  1299         case EDlAttrCodDownload:
  1289             {
  1300             {
  1290             aValue = iCodDownload;
  1301             aValue = iCodDownload;
  1291             }
  1302             }
  1292             break;
  1303             break;            
  1293 
  1304    
  1294         case EDlAttrProgressive:
  1305         case EDlAttrProgressive:
  1295             {
  1306             {
  1296             aValue = iStorage->ProgressiveMode();
  1307             aValue = iStorage->ProgressiveMode();
  1297             }
  1308             }
  1298             break;
  1309             break;
  1299 
  1310    
  1300         case EDlAttrDestRemovable:
  1311         case EDlAttrDestRemovable:
  1301             {
  1312             {
  1302             aValue = iStorage->RemovableDest();
  1313             aValue = (KDriveAttRemovable == iStorage->RemovableDest()) ? ETrue : EFalse ;
  1303             }
  1314             }
  1304             break;
  1315             break;
  1305 
  1316 
  1306         case EDlAttrCodPdAvailable:
  1317         case EDlAttrCodPdAvailable:
  1307             {
  1318             {
  1318             User::Leave( KErrArgument );
  1329             User::Leave( KErrArgument );
  1319 #endif
  1330 #endif
  1320             }
  1331             }
  1321             break;
  1332             break;
  1322         }
  1333         }
  1323 
  1334     
  1324     iNoRealError = EFalse;
  1335     iNoRealError = EFalse;
  1325     }
  1336     }
  1326 
  1337 
  1327 // -----------------------------------------------------------------------------
  1338 // -----------------------------------------------------------------------------
  1328 // CHttpDownload::GetBoolAttributeL
  1339 // CHttpDownload::GetBoolAttributeL
  1329 // ?implementation_description
  1340 // ?implementation_description
  1330 // (other items were commented in a header).
  1341 // (other items were commented in a header).
  1331 // -----------------------------------------------------------------------------
  1342 // -----------------------------------------------------------------------------
  1332 //
  1343 //
  1333 EXPORT_C void CHttpDownload::GetBoolAttributeL( THttpDownloadAttrib aAttribute,
  1344 EXPORT_C void CHttpDownload::GetBoolAttributeL( THttpDownloadAttrib aAttribute, 
  1334 								                TInt32& aMoIndex,
  1345 								                TInt32& aMoIndex,
  1335 								                TBool& aValue )
  1346 								                TBool& aValue )
  1336     {
  1347     {
  1337     LOGGER_ENTERFN( "GetBoolAttributeL" );
  1348     LOGGER_ENTERFN( "GetBoolAttributeL" );
  1338     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1349     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1339 
  1350     
  1340     if (!iCodDlData)
  1351     if (!iCodDlData)
  1341     	{
  1352     	{
  1342     	aValue = 0;
  1353     	aValue = 0;
  1343     	return;
  1354     	return;
  1344     	}
  1355     	}
  1345     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1356     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1346     	{
  1357     	{
  1347     	User::Leave( KErrArgument );
  1358     	User::Leave( KErrArgument );
  1348     	}
  1359     	}
  1349 
  1360     	
  1350     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1361     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1351     iNoRealError = ETrue;
  1362     iNoRealError = ETrue;
  1352 
  1363 
  1353     switch( aAttribute )
  1364     switch( aAttribute )
  1354         {
  1365         {
  1367         case EDlAttrProgressive:
  1378         case EDlAttrProgressive:
  1368             {
  1379             {
  1369             aValue = mediaData->ProgressiveDownload();
  1380             aValue = mediaData->ProgressiveDownload();
  1370             }
  1381             }
  1371             break;
  1382             break;
  1372 
  1383    
  1373         case EDlAttrDestRemovable:
  1384         case EDlAttrDestRemovable:
  1374             {
  1385             {
  1375             aValue = mediaData->DesRemovable();
  1386             aValue = (KDriveAttRemovable == mediaData->DesRemovable()) ? ETrue : EFalse ;
  1376             }
  1387             }
  1377             break;
  1388             break;
  1378 
  1389 
  1379         default:
  1390         default:
  1380             {
  1391             {
  1386             User::Leave( KErrArgument );
  1397             User::Leave( KErrArgument );
  1387 #endif
  1398 #endif
  1388             }
  1399             }
  1389             break;
  1400             break;
  1390         }
  1401         }
  1391 
  1402     
  1392     iNoRealError = EFalse;
  1403     iNoRealError = EFalse;
  1393     }
  1404     }
  1394 
  1405 
  1395 // -----------------------------------------------------------------------------
  1406 // -----------------------------------------------------------------------------
  1396 // CHttpDownload::GetStringAttributeL
  1407 // CHttpDownload::GetStringAttributeL
  1397 // ?implementation_description
  1408 // ?implementation_description
  1398 // (other items were commented in a header).
  1409 // (other items were commented in a header).
  1399 // -----------------------------------------------------------------------------
  1410 // -----------------------------------------------------------------------------
  1400 //
  1411 //
  1401 EXPORT_C HBufC* CHttpDownload::GetStringAttributeL( THttpDownloadAttrib aAttribute,
  1412 EXPORT_C HBufC* CHttpDownload::GetStringAttributeL( THttpDownloadAttrib aAttribute, 
  1402                                                     TBool& aDelete )
  1413                                                     TBool& aDelete )
  1403     {
  1414     {
  1404     LOGGER_ENTERFN( "GetStringAttributeL" );
  1415     LOGGER_ENTERFN( "GetStringAttributeL" );
  1405     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1416     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1406 
  1417 
  1438 
  1449 
  1439         case EDlAttrDDType:
  1450         case EDlAttrDDType:
  1440             {
  1451             {
  1441             attr8 = iDDType;
  1452             attr8 = iDDType;
  1442             }
  1453             }
  1443             break;
  1454             break;            
  1444 
  1455 
  1445         case EDlAttrRealm:
  1456         case EDlAttrRealm:
  1446             {
  1457             {
  1447             attr8 = iHttpRealm;
  1458             attr8 = iHttpRealm;
  1448             }
  1459             }
  1497         case EDlAttrLocalFileName:
  1508         case EDlAttrLocalFileName:
  1498             {
  1509             {
  1499             attr = iStorage->LocalFilename();
  1510             attr = iStorage->LocalFilename();
  1500             }
  1511             }
  1501             break;
  1512             break;
  1502 
  1513             
  1503         case EDlAttrDdFileName:
  1514         case EDlAttrDdFileName:
  1504         	{
  1515         	{
  1505         	attr = iStorage->DdFileName();
  1516         	attr = iStorage->DdFileName();
  1506         	}
  1517         	}
  1507         	break;
  1518         	break;
  1607                     break;
  1618                     break;
  1608                     }
  1619                     }
  1609                 }
  1620                 }
  1610             }
  1621             }
  1611             break;
  1622             break;
  1612 
  1623         
  1613         case EDlAttrAlbumName:
  1624         case EDlAttrAlbumName:
  1614             {
  1625             {
  1615             if (iCodDlData && (iCodDlData->Name().Compare(KNullDesC)))
  1626             if (iCodDlData && (iCodDlData->Name().Compare(KNullDesC)))
  1616                 {
  1627                 {
  1617                 attr = iCodDlData->Name().AllocL();
  1628                 attr = iCodDlData->Name().AllocL();
  1621                 {
  1632                 {
  1622                 attr = iDlName;
  1633                 attr = iDlName;
  1623                 }
  1634                 }
  1624             }
  1635             }
  1625             break;
  1636             break;
  1626 
  1637             
  1627         default:
  1638         default:
  1628             {
  1639             {
  1629                 {
  1640                 {
  1630                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  1641                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  1631 #ifdef __WINS__
  1642 #ifdef __WINS__
  1672 // CHttpDownload::GetStringAttributeL
  1683 // CHttpDownload::GetStringAttributeL
  1673 // ?implementation_description
  1684 // ?implementation_description
  1674 // (other items were commented in a header).
  1685 // (other items were commented in a header).
  1675 // -----------------------------------------------------------------------------
  1686 // -----------------------------------------------------------------------------
  1676 //
  1687 //
  1677 EXPORT_C HBufC* CHttpDownload::GetStringAttributeL( THttpDownloadAttrib aAttribute,
  1688 EXPORT_C HBufC* CHttpDownload::GetStringAttributeL( THttpDownloadAttrib aAttribute, 
  1678                                                     TInt32& aMoIndex,
  1689                                                     TInt32& aMoIndex,
  1679                                                     TBool& aDelete )
  1690                                                     TBool& aDelete )
  1680     {
  1691     {
  1681     LOGGER_ENTERFN( "GetStringAttributeL" );
  1692     LOGGER_ENTERFN( "GetStringAttributeL" );
  1682     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1693     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1687     	}
  1698     	}
  1688     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1699     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  1689     	{
  1700     	{
  1690     	User::Leave( KErrArgument );
  1701     	User::Leave( KErrArgument );
  1691     	}
  1702     	}
  1692 
  1703     	
  1693     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1704     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  1694     iNoRealError = ETrue;
  1705     iNoRealError = ETrue;
  1695     HBufC* attr = NULL;
  1706     HBufC* attr = NULL;
  1696     HBufC8* attr8 = NULL;
  1707     HBufC8* attr8 = NULL;
  1697 
  1708 
  1789 // CHttpDownload::GetString8AttributeL
  1800 // CHttpDownload::GetString8AttributeL
  1790 // ?implementation_description
  1801 // ?implementation_description
  1791 // (other items were commented in a header).
  1802 // (other items were commented in a header).
  1792 // -----------------------------------------------------------------------------
  1803 // -----------------------------------------------------------------------------
  1793 //
  1804 //
  1794 EXPORT_C HBufC8* CHttpDownload::GetString8AttributeL( THttpDownloadAttrib aAttribute,
  1805 EXPORT_C HBufC8* CHttpDownload::GetString8AttributeL( THttpDownloadAttrib aAttribute, 
  1795                                                       TBool& aDelete )
  1806                                                       TBool& aDelete )
  1796     {
  1807     {
  1797     LOGGER_ENTERFN( "GetString8AttributeL" );
  1808     LOGGER_ENTERFN( "GetString8AttributeL" );
  1798     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1809     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  1799 
  1810 
  1849 
  1860 
  1850         case EDlAttrDDType:
  1861         case EDlAttrDDType:
  1851             {
  1862             {
  1852             attr = iDDType;
  1863             attr = iDDType;
  1853             }
  1864             }
  1854             break;
  1865             break;            
  1855 
  1866 
  1856         case EDlAttrRequestHeaderAddon:
  1867         case EDlAttrRequestHeaderAddon:
  1857             {
  1868             {
  1858             TChar colon( KColon );
  1869             TChar colon( KColon );
  1859             TInt32 length( 0 );
  1870             TInt32 length( 0 );
  1973                 }
  1984                 }
  1974             }
  1985             }
  1975             break;
  1986             break;
  1976 
  1987 
  1977         case EDlAttrHashedMsgBody:
  1988         case EDlAttrHashedMsgBody:
  1978             {
  1989             { 
  1979             attr = iHashedMsgBody;
  1990             attr = iHashedMsgBody;
  1980             }
  1991             }
  1981             break;
  1992             break;
  1982 
  1993    
  1983         case EDlAttrMediaType:
  1994         case EDlAttrMediaType:
  1984             {
  1995             {
  1985             attr = iMediaType;
  1996             attr = iMediaType;
  1986             }
  1997             }
  1987             break;
  1998             break;
  1988 
  1999             
  1989         case EDlAttrMediaTypeBoundary:
  2000         case EDlAttrMediaTypeBoundary:
  1990             {
  2001             {
  1991             attr = GetParamFromMediaTypeL( KBoundary() ).AllocL();
  2002             attr = GetParamFromMediaTypeL( KBoundary() ).AllocL();
  1992             aDelete = ETrue;
  2003             aDelete = ETrue;
  1993             }
  2004             }
  1994             break;
  2005             break;
  1995 
  2006             
  1996         default:
  2007         default:
  1997             {
  2008             {
  1998                 {
  2009                 {
  1999                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  2010                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  2000 #ifdef __WINS__
  2011 #ifdef __WINS__
  2040 // CHttpDownload::GetString8AttributeL
  2051 // CHttpDownload::GetString8AttributeL
  2041 // ?implementation_description
  2052 // ?implementation_description
  2042 // (other items were commented in a header).
  2053 // (other items were commented in a header).
  2043 // -----------------------------------------------------------------------------
  2054 // -----------------------------------------------------------------------------
  2044 //
  2055 //
  2045 EXPORT_C HBufC8* CHttpDownload::GetString8AttributeL( THttpDownloadAttrib aAttribute,
  2056 EXPORT_C HBufC8* CHttpDownload::GetString8AttributeL( THttpDownloadAttrib aAttribute, 
  2046                                                       TInt32& aMoIndex,
  2057                                                       TInt32& aMoIndex,
  2047                                                       TBool& aDelete )
  2058                                                       TBool& aDelete )
  2048     {
  2059     {
  2049     LOGGER_ENTERFN( "GetString8AttributeL" );
  2060     LOGGER_ENTERFN( "GetString8AttributeL" );
  2050     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  2061     CLOG_WRITE_1( "Attr(%d): %d", aAttribute );
  2055     	}
  2066     	}
  2056     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  2067     if ((aMoIndex <= KNonMoIndex) || (aMoIndex > iCodDlData->Count()))
  2057     	{
  2068     	{
  2058     	User::Leave( KErrArgument );
  2069     	User::Leave( KErrArgument );
  2059     	}
  2070     	}
  2060 
  2071     	
  2061     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  2072     CMediaDataBase* mediaData = (*iCodDlData)[aMoIndex];
  2062     iNoRealError = ETrue;
  2073     iNoRealError = ETrue;
  2063     HBufC8* attr = NULL;
  2074     HBufC8* attr = NULL;
  2064     HBufC* attr16 = NULL;
  2075     HBufC* attr16 = NULL;
  2065 
  2076 
  2085             {
  2096             {
  2086             attr = mediaData->Type().AllocL();
  2097             attr = mediaData->Type().AllocL();
  2087             aDelete = ETrue;
  2098             aDelete = ETrue;
  2088             }
  2099             }
  2089             break;
  2100             break;
  2090 
  2101             
  2091         default:
  2102         default:
  2092             {
  2103             {
  2093                 {
  2104                 {
  2094                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  2105                 CLOG_WRITE_1( "Unknown string8 attrib: %d", aAttribute );
  2095 #ifdef __WINS__
  2106 #ifdef __WINS__
  2138 // -----------------------------------------------------------------------------
  2149 // -----------------------------------------------------------------------------
  2139 //
  2150 //
  2140 EXPORT_C RFile* CHttpDownload::GetFileHandleAttributeL()
  2151 EXPORT_C RFile* CHttpDownload::GetFileHandleAttributeL()
  2141     {
  2152     {
  2142     LOGGER_ENTERFN( "GetFileHandleAttributeL" );
  2153     LOGGER_ENTERFN( "GetFileHandleAttributeL" );
  2143 
  2154     
  2144     if( !iStorage->File() )
  2155     if( !iStorage->File() )
  2145         // destination file is not opened
  2156         // destination file is not opened
  2146         {
  2157         {
  2147         User::Leave( KErrArgument );
  2158         User::Leave( KErrArgument );
  2148         }
  2159         }
  2154 // CHttpDownload::SetIntAttributeL
  2165 // CHttpDownload::SetIntAttributeL
  2155 // ?implementation_description
  2166 // ?implementation_description
  2156 // (other items were commented in a header).
  2167 // (other items were commented in a header).
  2157 // -----------------------------------------------------------------------------
  2168 // -----------------------------------------------------------------------------
  2158 //
  2169 //
  2159 EXPORT_C void CHttpDownload::SetIntAttributeL( THttpDownloadAttrib aAttribute,
  2170 EXPORT_C void CHttpDownload::SetIntAttributeL( THttpDownloadAttrib aAttribute, 
  2160                                                const TInt32 aValue )
  2171                                                const TInt32 aValue )
  2161     {
  2172     {
  2162     LOGGER_ENTERFN( "SetIntAttributeL" );
  2173     LOGGER_ENTERFN( "SetIntAttributeL" );
  2163     CLOG_WRITE_2( "Attr(%d): %d", aAttribute, aValue );
  2174     CLOG_WRITE_2( "Attr(%d): %d", aAttribute, aValue );
  2164     TBool store( ETrue );
  2175     TBool store( ETrue );
  2174             break;
  2185             break;
  2175 
  2186 
  2176         case EDlAttrAction:
  2187         case EDlAttrAction:
  2177         	{
  2188         	{
  2178             TBool PdSupported(EFalse);
  2189             TBool PdSupported(EFalse);
  2179 
  2190             
  2180             iAction = (THttpDownloadMgrAction)aValue;
  2191             iAction = (THttpDownloadMgrAction)aValue;
  2181 
  2192             
  2182             if(iClAppInstance)
  2193             if(iClAppInstance)
  2183             	{
  2194             	{
  2184             	TRAP_IGNORE(iClAppInstance->GetBoolAttributeL(EDlMgrProgressiveDownload, PdSupported));
  2195             	TRAP_IGNORE(iClAppInstance->GetBoolAttributeL(EDlMgrProgressiveDownload, PdSupported));
  2185             	}
  2196             	}
  2186 
  2197 
  2222             }
  2233             }
  2223             break;
  2234             break;
  2224 
  2235 
  2225         case EDlAttrMultipleMOLength:
  2236         case EDlAttrMultipleMOLength:
  2226             {
  2237             {
  2227             iMoLength = aValue;
  2238             iMoLength = aValue;            
  2228             }
  2239             }
  2229             break;
  2240             break;
  2230 
  2241             
  2231         case EDlAttrDownloadedSize:
  2242         case EDlAttrDownloadedSize:
  2232             {
  2243             {
  2233             if( (iCodDownload || iContinueDownload) && iDlState == EHttpDlInprogress )
  2244             if( (iCodDownload || iContinueDownload) && iDlState == EHttpDlInprogress )
  2234                 {
  2245                 {            
  2235                 iStorage->SetDownloadedSize( aValue );
  2246                 iStorage->SetDownloadedSize( aValue );
  2236                 // Calculate downloaded size of current media object from
  2247                 // Calculate downloaded size of current media object from
  2237                 // album downloaded size.
  2248                 // album downloaded size.
  2238                 TInt dlSize = iStorage->DownloadedSize();
  2249                 TInt dlSize = iStorage->DownloadedSize();
  2239                 if( iCodDlData )
  2250                 if( iCodDlData )
  2240                     {
  2251                     {
  2241                     for (TInt index = 0; index < iCodDlData->Count() ; ++index)
  2252                     for (TInt index = 0; index < iCodDlData->Count() ; ++index)
  2242                     	{
  2253                     	{               	
  2243                     	if( iActiveDownload - 1 == index )
  2254                     	if( iActiveDownload - 1 == index )
  2244                     	    {
  2255                     	    {
  2245                     	    //the size of active download has already been taken into account
  2256                     	    //the size of active download has already been taken into account
  2246                     	    continue;
  2257                     	    continue;
  2247                     	    }
  2258                     	    }
  2248                     	CMediaDataBase* moData = (*iCodDlData)[index+1];
  2259                     	CMediaDataBase* moData = (*iCodDlData)[index+1];
  2249                     	if ((moData->State() == ESucceeded) || (moData->State() == EInProgress))
  2260                     	if ((moData->State() == ESucceeded) || (moData->State() == EInProgress))
  2250                     		dlSize += moData->DownloadedSize();
  2261                     		dlSize += moData->DownloadedSize();
  2251                     	}
  2262                     	}
  2252                     iStorage->SetMoDownloadedSize(dlSize);
  2263                     iStorage->SetMoDownloadedSize(dlSize);                    	                
  2253                     }
  2264                     }                
  2254                 if( iStorage->Length() != KDefaultContentLength &&
  2265                 if( iStorage->Length() != KDefaultContentLength &&
  2255                     iStorage->DownloadedSize() > iStorage->Length() )
  2266                     iStorage->DownloadedSize() > iStorage->Length() )
  2256                     // we don't know actually how many bytes will come down.
  2267                     // we don't know actually how many bytes will come down.
  2257                     {
  2268                     {
  2258                     CLOG_WRITE( "Length modified" );
  2269                     CLOG_WRITE( "Length modified" );
  2259                     iStorage->SetLength( KDefaultContentLength );
  2270                     iStorage->SetLength( KDefaultContentLength );
  2260                     StoreDownloadInfoL();
  2271                     StoreDownloadInfoL();
  2261                     }
  2272                     }                             
  2262                 TriggerEvent( EHttpDlInprogress, EHttpProgResponseBodyReceived );
  2273                 TriggerEvent( EHttpDlInprogress, EHttpProgResponseBodyReceived );
  2263                 }
  2274                 }
  2264 
  2275                 
  2265             store = EFalse;
  2276             store = EFalse;
  2266             }
  2277             }
  2267             break;
  2278             break;
  2268 
  2279 
  2269         case EDlAttrSucceeded:
  2280         case EDlAttrSucceeded:
  2270             {
  2281             {
  2271             if(!aValue)
  2282             if(!aValue)
  2272                 DownloadSucceededL();
  2283                 DownloadSucceededL();
  2273             else
  2284             else
  2274                 iMoDownloadCompleted = ETrue;//Download of MO has been Completed so change State ,But PD is on
  2285                 iMoDownloadCompleted = ETrue;//Download of MO has been Completed so change State ,But PD is on           
  2275                                          //So MOVE will be issued by PD Client
  2286                                          //So MOVE will be issued by PD Client 
  2276 
  2287 
  2277             store = EFalse;
  2288             store = EFalse;
  2278             }
  2289             }
  2279             break;
  2290             break;
  2280 
  2291 
  2289 
  2300 
  2290         case EDlAttrDefaultEvent:
  2301         case EDlAttrDefaultEvent:
  2291             {
  2302             {
  2292             }
  2303             }
  2293             break;
  2304             break;
  2294 
  2305             
  2295         case EDlAttrMethod:
  2306         case EDlAttrMethod:
  2296             {
  2307             {
  2297             if( iContinueDownload && iDlState == EHttpDlMultipleMOStarted &&
  2308             if( iContinueDownload && iDlState == EHttpDlMultipleMOStarted &&
  2298                 ( aValue == EMethodGET ||
  2309                 ( aValue == EMethodGET ||
  2299                   aValue == EMethodPOST ||
  2310                   aValue == EMethodPOST ||
  2307                 }
  2318                 }
  2308             }
  2319             }
  2309             break;
  2320             break;
  2310 
  2321 
  2311         case EDlAttrFotaPckgId:
  2322         case EDlAttrFotaPckgId:
  2312             {
  2323             {     
  2313             iFotaPckgId = aValue;
  2324             iFotaPckgId = aValue;
  2314             store = EFalse;
  2325             store = EFalse;
  2315             }
  2326             }
  2316             break;
  2327             break;
  2317         case EDlAttrActiveDownload:
  2328         case EDlAttrActiveDownload:
  2318             {
  2329             {
  2319             iActiveDownload = aValue;
  2330             iActiveDownload = aValue;
  2320 
  2331             
  2321             // Active MO changed. Notify clients.
  2332             // Active MO changed. Notify clients.
  2322            	TriggerEvent( EHttpDlCreated, EHttpProgNone );
  2333            	TriggerEvent( EHttpDlCreated, EHttpProgNone );
  2323             }
  2334             }
  2324             break;
  2335             break;
  2325 
  2336             
  2326         case EDlAttrActivePlayedDownload:
  2337         case EDlAttrActivePlayedDownload:
  2327             {
  2338             {
  2328             iActivePlayedDownload = aValue;
  2339             iActivePlayedDownload = aValue;
  2329             }
  2340             }
  2330 
  2341             
       
  2342             break;
       
  2343             
       
  2344         case EDlAttrDestRemovable:
       
  2345             {
       
  2346             if( iCodDownload )
       
  2347                 {
       
  2348                 iStorage->SetRemovableDest( aValue );
       
  2349 
       
  2350                 if (iCodDlData)                
       
  2351                     {
       
  2352                     // Update for Active media object.
       
  2353                     TInt active = iActiveDownload;
       
  2354                     CMediaDataBase* mediaData = (*iCodDlData)[active];
       
  2355                     mediaData->SetDesRemovable( aValue );
       
  2356                     }
       
  2357                 }
       
  2358             }
  2331             break;
  2359             break;
  2332         default:
  2360         default:
  2333             {
  2361             {
  2334 #ifdef __WINS__
  2362 #ifdef __WINS__
  2335             DMPanic( KErrArgument );
  2363             DMPanic( KErrArgument );
  2341         }
  2369         }
  2342 
  2370 
  2343     UpdatePausable();
  2371     UpdatePausable();
  2344 
  2372 
  2345     iNoRealError = EFalse;
  2373     iNoRealError = EFalse;
  2346 
  2374     
  2347     if( store )
  2375     if( store )
  2348         {
  2376         {
  2349         StoreDownloadInfoL();
  2377         StoreDownloadInfoL();
  2350         }
  2378         }
  2351     }
  2379     }
  2354 // CHttpDownload::SetBoolAttributeL
  2382 // CHttpDownload::SetBoolAttributeL
  2355 // ?implementation_description
  2383 // ?implementation_description
  2356 // (other items were commented in a header).
  2384 // (other items were commented in a header).
  2357 // -----------------------------------------------------------------------------
  2385 // -----------------------------------------------------------------------------
  2358 //
  2386 //
  2359 EXPORT_C void CHttpDownload::SetBoolAttributeL( THttpDownloadAttrib aAttribute,
  2387 EXPORT_C void CHttpDownload::SetBoolAttributeL( THttpDownloadAttrib aAttribute, 
  2360 								                const TBool aValue )
  2388 								                const TBool aValue )
  2361     {
  2389     {
  2362     LOGGER_ENTERFN( "SetBoolAttributeL" );
  2390     LOGGER_ENTERFN( "SetBoolAttributeL" );
  2363     CLOG_WRITE_2( "Attr(%d): %d", aAttribute, aValue );
  2391     CLOG_WRITE_2( "Attr(%d): %d", aAttribute, aValue );
  2364     TBool store( ETrue );
  2392     TBool store( ETrue );
  2393                 }
  2421                 }
  2394             else
  2422             else
  2395                 {
  2423                 {
  2396                 User::Leave( KErrInUse );
  2424                 User::Leave( KErrInUse );
  2397                 }
  2425                 }
  2398 
  2426                 
  2399             store = EFalse;
  2427             store = EFalse;
  2400             }
  2428             }
  2401             break;
  2429             break;
  2402 
  2430 
  2403         case EDlAttrHidden:
  2431         case EDlAttrHidden:
  2415         case EDlAttrCodDownload:
  2443         case EDlAttrCodDownload:
  2416             {
  2444             {
  2417             SetCodFlag( aValue );
  2445             SetCodFlag( aValue );
  2418             }
  2446             }
  2419             break;
  2447             break;
  2420 
  2448             
  2421         case EDlAttrProgressive:
  2449         case EDlAttrProgressive:
  2422             {
  2450             {
  2423             TBool PdSupported(EFalse);
  2451             TBool PdSupported(EFalse);
  2424 
  2452             
  2425             if(iClAppInstance)
  2453             if(iClAppInstance)
  2426             	{
  2454             	{
  2427             	TRAP_IGNORE(iClAppInstance->GetBoolAttributeL(EDlMgrProgressiveDownload, PdSupported));
  2455             	TRAP_IGNORE(iClAppInstance->GetBoolAttributeL(EDlMgrProgressiveDownload, PdSupported));
  2428             	}
  2456             	}
  2429 
  2457 
  2430             if(PdSupported)
  2458             if(PdSupported)
  2431                 {
  2459                 {
  2432                 iStorage->SetProgressiveMode( aValue );
  2460                 iStorage->SetProgressiveMode( aValue );	
  2433 
  2461                 
  2434                 if(!aValue)
  2462                 if(!aValue)
  2435                     {
  2463                     {
  2436                     iActivePlayedDownload = 0;
  2464                     iActivePlayedDownload = 0;
  2437                     }
  2465                     }
  2438 
  2466 
  2439                 if (iCodDlData)
  2467                 if (iCodDlData)                
  2440                 	{
  2468                 	{
  2441                 	// Update for Active media object.
  2469                 	// Update for Active media object.
  2442 	                TInt active = iActiveDownload;
  2470 	                TInt active = iActiveDownload;
  2443 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2471 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2444 	                mediaData->SetProgressiveDownload( aValue );
  2472 	                mediaData->SetProgressiveDownload( aValue );
  2445                 	}
  2473                 	}
  2446 
  2474                 	
  2447                 if( iProgState != EHttpProgMovingContentFile )
  2475                 if( iProgState != EHttpProgMovingContentFile )
  2448                     {
  2476                     {
  2449                     if (aValue && iDlState == EHttpDlMultipleMOCompleted )
  2477                     if (aValue && iDlState == EHttpDlMultipleMOCompleted )
  2450                         {
  2478                         {
  2451                         /*
  2479                         /* 
  2452                         if the file size is small, by the time the music player is launched, DMgr already triggered EHttpDlCompleted.
  2480                         if the file size is small, by the time the music player is launched, DMgr already triggered EHttpDlCompleted.
  2453                         So if the download state is EHttpDlMultipleMOCompleted, we need to trigger EHttpDlCompleted so that music player understands download is completed already
  2481                         So if the download state is EHttpDlMultipleMOCompleted, we need to trigger EHttpDlCompleted so that music player understands download is completed already
  2454                         This is needed to ensure backward compatibility
  2482                         This is needed to ensure backward compatibility
  2455                         */
  2483                         */
  2456                         TriggerEvent( EHttpDlCompleted, EHttpDlProgProgressive);
  2484                         TriggerEvent( EHttpDlCompleted, EHttpDlProgProgressive);
  2457                         }
  2485                         }   
  2458                     else
  2486                     else
  2459                         {
  2487                         {    
  2460                         TriggerEvent( iDlState, aValue ? EHttpDlProgProgressive : EHttpDlProgNonProgressive);
  2488                         TriggerEvent( iDlState, aValue ? EHttpDlProgProgressive : EHttpDlProgNonProgressive);
  2461                         }
  2489                         }
  2462                     }
  2490                     }
  2463                 }
  2491                 }
  2464             else
  2492             else
  2465                 {
  2493                 {
  2466 				TriggerEvent( iDlState, EHttpDlProgNonProgressive);
  2494 				TriggerEvent( iDlState, EHttpDlProgNonProgressive);
  2467 				}
  2495 				}
  2468             }
  2496             }
  2469             break;
  2497             break;
  2470 
  2498             
  2471         case EDlAttrCodDescriptorAccepted:
  2499         case EDlAttrCodDescriptorAccepted:
  2472             {
  2500             {
  2473             TriggerEvent( EHttpDlInprogress, EHttpProgCodDescriptorAccepted );
  2501             TriggerEvent( EHttpDlInprogress, EHttpProgCodDescriptorAccepted );
  2474             }
  2502             }
  2475             break;
  2503             break;
  2476 
  2504             
  2477         case EDlAttrCodLoadEnd:
  2505         case EDlAttrCodLoadEnd:
  2478             {
  2506             {
  2479             SetDownloadStatus(EHttpProgCodLoadEnd,EHttpDlInprogress);
  2507             SetDownloadStatus(EHttpProgCodLoadEnd,EHttpDlInprogress);
  2480             }
  2508             }
  2481             break;
  2509             break;
  2484             {
  2512             {
  2485             iCodPdAvailable = aValue;
  2513             iCodPdAvailable = aValue;
  2486             TriggerEvent( EHttpDlInprogress, EHttpProgCodPdAvailable );
  2514             TriggerEvent( EHttpDlInprogress, EHttpProgCodPdAvailable );
  2487             }
  2515             }
  2488             break;
  2516             break;
  2489 
  2517             
  2490         case EDlAttrDestRemovable:
  2518         case EDlAttrDestRemovable:
  2491             {
  2519             {
  2492             if( iCodDownload )
  2520             if( iCodDownload )
  2493                 {
  2521                 {
  2494                 iStorage->SetRemovableDest( aValue );
  2522                 TInt32 removableDestStatus = (aValue) ? KDriveAttRemovable : KDriveAttLocal ;
  2495 
  2523                 
  2496                 if (iCodDlData)
  2524                 iStorage->SetRemovableDest( removableDestStatus );
       
  2525 
       
  2526                 if (iCodDlData)                
  2497                 	{
  2527                 	{
  2498 	                // Update for Active media object.
  2528 	                // Update for Active media object.
  2499 	                TInt active = iActiveDownload;
  2529 	                TInt active = iActiveDownload;
  2500 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2530 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2501 	                mediaData->SetDesRemovable( aValue );
  2531 	                mediaData->SetDesRemovable( removableDestStatus );
  2502                 	}
  2532                 	}
  2503                 }
  2533                 }
  2504             }
  2534             }
  2505             break;
  2535             break;
  2506 
  2536 
  2512 
  2542 
  2513 
  2543 
  2514         case EDlAttrCodPausable:
  2544         case EDlAttrCodPausable:
  2515             {
  2545             {
  2516             iPausable = aValue;
  2546             iPausable = aValue;
  2517 
  2547 			
  2518 			// Update for Active media object.
  2548 			// Update for Active media object.
  2519             TInt active = iActiveDownload;
  2549             TInt active = iActiveDownload;
  2520             CMediaDataBase* mediaData = (*iCodDlData)[active];
  2550             CMediaDataBase* mediaData = (*iCodDlData)[active];
  2521             mediaData->SetPausable( aValue );
  2551             mediaData->SetPausable( aValue );
  2522 
  2552 			
  2523             // inform client about change
  2553             // inform client about change
  2524             TriggerEvent( iPausable ? EHttpDlPausable : EHttpDlNonPausable );
  2554             TriggerEvent( iPausable ? EHttpDlPausable : EHttpDlNonPausable );
  2525 			}
  2555 			}
  2526             break;
  2556             break;
  2527 
  2557             
  2528 
  2558                     
  2529         default:
  2559         default:
  2530 #ifdef __WINS__
  2560 #ifdef __WINS__
  2531             DMPanic( KErrArgument );
  2561             DMPanic( KErrArgument );
  2532 #else
  2562 #else
  2533             User::Leave( KErrArgument );
  2563             User::Leave( KErrArgument );
  2534 #endif
  2564 #endif
  2535             break;
  2565             break;
  2536         }
  2566         }
  2537 
  2567 
  2538     UpdatePausable();
  2568     UpdatePausable();
  2539 
  2569     
  2540     iNoRealError = EFalse;
  2570     iNoRealError = EFalse;
  2541 
  2571 
  2542     if( store )
  2572     if( store )
  2543         {
  2573         {
  2544         StoreDownloadInfoL();
  2574         StoreDownloadInfoL();
  2566     switch( aAttribute )
  2596     switch( aAttribute )
  2567         {
  2597         {
  2568         case EDlAttrDestFilename:
  2598         case EDlAttrDestFilename:
  2569             {
  2599             {
  2570             TBool updateFName = EFalse;
  2600             TBool updateFName = EFalse;
  2571 
  2601             
  2572             if( iDlState == EHttpDlMultipleMOStarted ||
  2602             if( iDlState == EHttpDlMultipleMOStarted ||
  2573                 iDlState == EHttpDlMultipleMOCompleted ||
  2603                 iDlState == EHttpDlMultipleMOCompleted ||
  2574                 iCodDownload )
  2604                 iCodDownload )
  2575                 // cannot set this attribute while
  2605                 // cannot set this attribute while 
  2576                 // download is in progress
  2606                 // download is in progress
  2577                 {
  2607                 {
  2578                 if( !aValue.Length() )
  2608                 if( !aValue.Length() )
  2579                     {
  2609                     {
  2580                     updateFName = ETrue;
  2610                     updateFName = ETrue;
  2590                         {
  2620                         {
  2591                         updateFName = ETrue;
  2621                         updateFName = ETrue;
  2592                         }
  2622                         }
  2593                     else
  2623                     else
  2594                         {
  2624                         {
  2595                         User::Leave( KErrArgument );
  2625                         User::Leave( KErrArgument ); 
  2596                         }
  2626                         }
  2597                     }
  2627                     }
  2598                 else
  2628                 else
  2599                     // Invalid filename passed
  2629                     // Invalid filename passed
  2600                     {
  2630                     {
  2603                 }
  2633                 }
  2604             else
  2634             else
  2605                 {
  2635                 {
  2606                 User::Leave( KErrInUse );
  2636                 User::Leave( KErrInUse );
  2607                 }
  2637                 }
  2608 
  2638             
  2609             if (updateFName)
  2639             if (updateFName)
  2610             	{
  2640             	{
  2611                 iStorage->UpdateDestinationFilenameL( aValue, ETrue );
  2641                 iStorage->UpdateDestinationFilenameL( aValue, ETrue );
  2612                 if (iCodDlData)
  2642                 if (iCodDlData)                
  2613                 	{
  2643                 	{
  2614 	            	CMediaDataBase* mediaData = (*iCodDlData)[aMOIndex];
  2644 	            	CMediaDataBase* mediaData = (*iCodDlData)[aMOIndex];
  2615 	            	mediaData->SetDestFilenameL( aValue );
  2645 	            	mediaData->SetDestFilenameL( aValue );
  2616 	            	}
  2646 	            	}
  2617             	}
  2647             	}
  2618             }
  2648             }
  2619             break;
  2649             break;
  2620         }
  2650         }
  2621     }
  2651     }
  2622 
  2652     
  2623 
  2653     
  2624 // -----------------------------------------------------------------------------
  2654 // -----------------------------------------------------------------------------
  2625 // CHttpDownload::SetStringAttributeL
  2655 // CHttpDownload::SetStringAttributeL
  2626 // ?implementation_description
  2656 // ?implementation_description
  2627 // (other items were commented in a header).
  2657 // (other items were commented in a header).
  2628 // -----------------------------------------------------------------------------
  2658 // -----------------------------------------------------------------------------
  2629 //
  2659 //
  2630 EXPORT_C void CHttpDownload::SetStringAttributeL( THttpDownloadAttrib aAttribute,
  2660 EXPORT_C void CHttpDownload::SetStringAttributeL( THttpDownloadAttrib aAttribute, 
  2631 								                  const TDesC16& aValue )
  2661 								                  const TDesC16& aValue )
  2632     {
  2662     {
  2633     LOGGER_ENTERFN( "SetStringAttributeL" );
  2663     LOGGER_ENTERFN( "SetStringAttributeL" );
  2634     CLOG_WRITE_2( "Attr(%d - %d)", aAttribute, aValue.Length () );
  2664     CLOG_WRITE_2( "Attr(%d - %d)", aAttribute, aValue.Length () );
  2635     TBool store( ETrue );
  2665     TBool store( ETrue );
  2657             if( iDlState == EHttpDlInprogress )
  2687             if( iDlState == EHttpDlInprogress )
  2658                 {
  2688                 {
  2659                 CLOG_WRITE( "EDlAttrContentType updated" );
  2689                 CLOG_WRITE( "EDlAttrContentType updated" );
  2660                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );
  2690                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );
  2661                 TriggerEvent( EHttpDlInprogress, EHttpProgContentTypeChanged );
  2691                 TriggerEvent( EHttpDlInprogress, EHttpProgContentTypeChanged );
  2662 
  2692                 
  2663                 // Update for Active media object.
  2693                 // Update for Active media object.
  2664                 HBufC8* type8 = HBufC8::NewLC( aValue.Length() );
  2694                 HBufC8* type8 = HBufC8::NewLC( aValue.Length() );
  2665                 type8->Des().Copy( aValue );
  2695                 type8->Des().Copy( aValue );
  2666 
  2696 
  2667                 if (iCodDlData)
  2697                 if (iCodDlData)                
  2668                 	{
  2698                 	{
  2669 	                TInt active = iActiveDownload;
  2699 	                TInt active = iActiveDownload;
  2670 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2700 	                CMediaDataBase* mediaData = (*iCodDlData)[active];
  2671 	                mediaData->SetTypeL( type8->Des() );
  2701 	                mediaData->SetTypeL( type8->Des() );
  2672 	                CleanupStack::PopAndDestroy( type8 );
  2702 	                CleanupStack::PopAndDestroy( type8 );
  2679             {
  2709             {
  2680             if( iContinueDownload && iDlState == EHttpDlMultipleMOStarted )
  2710             if( iContinueDownload && iDlState == EHttpDlMultipleMOStarted )
  2681                 {
  2711                 {
  2682                 ReallocateStringL( iHttpRealm, aValue, KMaxRealmLength );
  2712                 ReallocateStringL( iHttpRealm, aValue, KMaxRealmLength );
  2683                 }
  2713                 }
  2684 
  2714                 
  2685             store = EFalse;
  2715             store = EFalse;
  2686             }
  2716             }
  2687             break;
  2717             break;
  2688 
  2718 
  2689         case EDlAttrUsername:
  2719         case EDlAttrUsername:
  2725             break;
  2755             break;
  2726 
  2756 
  2727         case EDlAttrDestFilename:
  2757         case EDlAttrDestFilename:
  2728             {
  2758             {
  2729             TBool updateFName = EFalse;
  2759             TBool updateFName = EFalse;
  2730 
  2760             
  2731             if( iDlState == EHttpDlMultipleMOStarted ||
  2761             if( iDlState == EHttpDlMultipleMOStarted ||
  2732                 iDlState == EHttpDlMultipleMOCompleted ||
  2762                 iDlState == EHttpDlMultipleMOCompleted ||
  2733                 iCodDownload )
  2763                 iCodDownload )
  2734                 // cannot set this attribute while
  2764                 // cannot set this attribute while 
  2735                 // download is in progress
  2765                 // download is in progress
  2736                 {
  2766                 {
  2737                 if( !aValue.Length() )
  2767                 if( !aValue.Length() )
  2738                     {
  2768                     {
  2739                     updateFName = ETrue;
  2769                     updateFName = ETrue;
  2749                         {
  2779                         {
  2750                         updateFName = ETrue;
  2780                         updateFName = ETrue;
  2751                         }
  2781                         }
  2752                     else
  2782                     else
  2753                         {
  2783                         {
  2754                         User::Leave( KErrArgument );
  2784                         User::Leave( KErrArgument ); 
  2755                         }
  2785                         }
  2756                     }
  2786                     }
  2757                 else
  2787                 else
  2758                     // Invalid filename passed
  2788                     // Invalid filename passed
  2759                     {
  2789                     {
  2762                 }
  2792                 }
  2763             else
  2793             else
  2764                 {
  2794                 {
  2765                 User::Leave( KErrInUse );
  2795                 User::Leave( KErrInUse );
  2766                 }
  2796                 }
  2767 
  2797             
  2768             if (updateFName)
  2798             if (updateFName)
  2769             	{
  2799             	{
  2770             	iStorage->UpdateDestinationFilenameL( aValue, ETrue );
  2800             	iStorage->UpdateDestinationFilenameL( aValue, ETrue );
  2771 
  2801             	
  2772                 if (iCodDlData)
  2802                 if (iCodDlData)                
  2773                 	{
  2803                 	{
  2774                     TInt moIndex(0);
  2804                     TInt moIndex(0);
  2775                     if( iActiveDownload != iActivePlayedDownload && iStorage->ProgressiveDownload() )
  2805                     if( iActiveDownload != iActivePlayedDownload && iStorage->ProgressiveDownload() )
  2776                         {
  2806                         {
  2777                         //MP has set the Destination File Name
  2807                         //MP has set the Destination File Name
  2778                         moIndex = iActivePlayedDownload;
  2808                         moIndex = iActivePlayedDownload;
  2779                         }
  2809                         }
  2780                     else
  2810                     else
  2781                         {
  2811                         {
  2782                         // Update for Active media object.
  2812                         // Update for Active media object.
  2783                     	moIndex = iActiveDownload;
  2813                     	moIndex = iActiveDownload;                        
  2784                         }
  2814                         }
  2785 	            	CMediaDataBase* mediaData = (*iCodDlData)[moIndex];
  2815 	            	CMediaDataBase* mediaData = (*iCodDlData)[moIndex];
  2786 	            	mediaData->SetDestFilenameL( aValue );
  2816 	            	mediaData->SetDestFilenameL( aValue );
  2787 	            	}
  2817 	            	}
  2788             	}
  2818             	}
  2828             if( iCodDownload )
  2858             if( iCodDownload )
  2829                 {
  2859                 {
  2830                 SetDownloadNameL( aValue );
  2860                 SetDownloadNameL( aValue );
  2831 
  2861 
  2832                 if (iCodDlData)
  2862                 if (iCodDlData)
  2833 	                {
  2863 	                {                
  2834 	                // Update for Active media object.
  2864 	                // Update for Active media object.
  2835 	            	TInt active = iActiveDownload;
  2865 	            	TInt active = iActiveDownload;
  2836 	            	CMediaDataBase* mediaData = (*iCodDlData)[active];
  2866 	            	CMediaDataBase* mediaData = (*iCodDlData)[active];
  2837 	            	mediaData->SetNameL( aValue );
  2867 	            	mediaData->SetNameL( aValue );
  2838 	                }
  2868 	                }
  2896 // CHttpDownload::SetStringAttributeL
  2926 // CHttpDownload::SetStringAttributeL
  2897 // ?implementation_description
  2927 // ?implementation_description
  2898 // (other items were commented in a header).
  2928 // (other items were commented in a header).
  2899 // -----------------------------------------------------------------------------
  2929 // -----------------------------------------------------------------------------
  2900 //
  2930 //
  2901 EXPORT_C void CHttpDownload::SetStringAttributeL( THttpDownloadAttrib aAttribute,
  2931 EXPORT_C void CHttpDownload::SetStringAttributeL( THttpDownloadAttrib aAttribute, 
  2902 								                  const TDesC8& aValue )
  2932 								                  const TDesC8& aValue )
  2903     {
  2933     {
  2904     LOGGER_ENTERFN( "SetStringAttributeL(8)" );
  2934     LOGGER_ENTERFN( "SetStringAttributeL(8)" );
  2905     CLOG_WRITE_2( "Attr(%d - %d)", aAttribute, aValue.Length () );
  2935     CLOG_WRITE_2( "Attr(%d - %d)", aAttribute, aValue.Length () );
  2906     TBool store( ETrue );
  2936     TBool store( ETrue );
  2930                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );
  2960                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );
  2931                 TriggerEvent( EHttpDlInprogress, EHttpProgContentTypeChanged );
  2961                 TriggerEvent( EHttpDlInprogress, EHttpProgContentTypeChanged );
  2932                 }
  2962                 }
  2933             else if (iDlState == EHttpDlMultipleMOCompleted )//Allow to change content type even if state is completed
  2963             else if (iDlState == EHttpDlMultipleMOCompleted )//Allow to change content type even if state is completed
  2934                 {
  2964                 {
  2935                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );
  2965                 ReallocateStringL( iContentType, aValue, KMaxContentTypeLength );                            
  2936                 //No need to trigger any event
  2966                 //No need to trigger any event
  2937                 }
  2967                 }                
  2938             }
  2968             }
  2939             break;
  2969             break;
  2940 
  2970 
  2941         case EDlAttrRealm:
  2971         case EDlAttrRealm:
  2942             {
  2972             {
  3032         case EDlAttrHashedMsgBody:
  3062         case EDlAttrHashedMsgBody:
  3033             {
  3063             {
  3034             ReallocateStringL( iHashedMsgBody, aValue, KHashLength );
  3064             ReallocateStringL( iHashedMsgBody, aValue, KHashLength );
  3035             }
  3065             }
  3036             break;
  3066             break;
  3037 
  3067    
  3038         case EDlAttrRedirectedPermanently:
  3068         case EDlAttrRedirectedPermanently:
  3039             {
  3069             {
  3040             RedirectedPermanentlyL( aValue );
  3070             RedirectedPermanentlyL( aValue );
  3041 
  3071             
  3042             if (iCodDlData)
  3072             if (iCodDlData)
  3043 	            {
  3073 	            {                
  3044 	            // Update for Active media object.
  3074 	            // Update for Active media object.
  3045 	            TInt active = iActiveDownload;
  3075 	            TInt active = iActiveDownload;
  3046 	            CMediaDataBase* mediaData = (*iCodDlData)[active];
  3076 	            CMediaDataBase* mediaData = (*iCodDlData)[active];
  3047 	            if (!mediaData->Redirected())
  3077 	            if (!mediaData->Redirected())
  3048 	            	mediaData->SetRedirUrlL( aValue );
  3078 	            	mediaData->SetRedirUrlL( aValue );
  3049 	            }
  3079 	            }
  3050             }
  3080             }
  3051             break;
  3081             break;
  3052 
  3082             
  3053         case EDlAttrRedirectedTemporary:
  3083         case EDlAttrRedirectedTemporary:
  3054             {
  3084             {
  3055             RedirectedTemporaryL( aValue );
  3085             RedirectedTemporaryL( aValue );
  3056 
  3086             
  3057             if (iCodDlData)
  3087             if (iCodDlData)
  3058 	            {
  3088 	            {                
  3059 	            // Update for Active media object.
  3089 	            // Update for Active media object.
  3060 	            TInt active = iActiveDownload;
  3090 	            TInt active = iActiveDownload;
  3061 	            CMediaDataBase* mediaData = (*iCodDlData)[active];
  3091 	            CMediaDataBase* mediaData = (*iCodDlData)[active];
  3062 	            mediaData->SetRedirected( ETrue );
  3092 	            mediaData->SetRedirected( ETrue );
  3063 	            }
  3093 	            }
  3064             }
  3094             }
  3065             break;
  3095             break;
  3066 
  3096  
  3067         case EDlAttrContinueBody:
  3097         case EDlAttrContinueBody:
  3068             {
  3098             {
  3069             iNoRealError = EFalse;
  3099             iNoRealError = EFalse;
  3070             ResponseBodyReceivedL( aValue );
  3100             ResponseBodyReceivedL( aValue );
  3071             store = EFalse;
  3101             store = EFalse;
  3084 #else
  3114 #else
  3085             User::Leave( KErrArgument );
  3115             User::Leave( KErrArgument );
  3086 #endif
  3116 #endif
  3087             break;
  3117             break;
  3088         }
  3118         }
  3089 
  3119     
  3090     UpdatePausable();
  3120     UpdatePausable();
  3091 
  3121     
  3092     iNoRealError = EFalse;
  3122     iNoRealError = EFalse;
  3093 
  3123 
  3094     if( store )
  3124     if( store )
  3095         {
  3125         {
  3096         StoreDownloadInfoL();
  3126         StoreDownloadInfoL();
  3104 // -----------------------------------------------------------------------------
  3134 // -----------------------------------------------------------------------------
  3105 //
  3135 //
  3106 EXPORT_C void CHttpDownload::SetFileHandleAttributeL( RFile* aFile )
  3136 EXPORT_C void CHttpDownload::SetFileHandleAttributeL( RFile* aFile )
  3107     {
  3137     {
  3108     LOGGER_ENTERFN( "SetFileHandleAttributeL" );
  3138     LOGGER_ENTERFN( "SetFileHandleAttributeL" );
  3109 
  3139     
  3110     iStorage->AdoptFileHandleL( aFile );
  3140     iStorage->AdoptFileHandleL( aFile );
  3111     }
  3141     }
  3112 
  3142 
  3113 // -----------------------------------------------------------------------------
  3143 // -----------------------------------------------------------------------------
  3114 // CHttpDownload::SetDownloadDataAttributeL
  3144 // CHttpDownload::SetDownloadDataAttributeL
  3117 // -----------------------------------------------------------------------------
  3147 // -----------------------------------------------------------------------------
  3118 //
  3148 //
  3119 EXPORT_C void CHttpDownload::SetDownloadDataAttributeL( HBufC8* dlData )
  3149 EXPORT_C void CHttpDownload::SetDownloadDataAttributeL( HBufC8* dlData )
  3120 	{
  3150 	{
  3121     LOGGER_ENTERFN( "SetDownloadDataAttributeL" );
  3151     LOGGER_ENTERFN( "SetDownloadDataAttributeL" );
  3122 
  3152     
  3123     if (iCodDlData)
  3153     if (iCodDlData)
  3124         {
  3154         {
  3125     	delete iCodDlData;
  3155     	delete iCodDlData;	
  3126         iCodDlData = NULL;
  3156         iCodDlData = NULL;
  3127         }
  3157         }
  3128 
  3158     	
  3129     iCodDlData = CDownloadDataServ::NewL(*dlData);
  3159     iCodDlData = CDownloadDataServ::NewL(*dlData);
  3130     TInt downloadedSize = 0 ;
  3160     TInt downloadedSize = 0 ;
  3131     TBool activeDownloadChanged = EFalse;
  3161     TBool activeDownloadChanged = EFalse;
  3132 
  3162     
  3133     iMoLength = 0 ;
  3163     iMoLength = 0 ;
  3134     for ( TInt i = 1; i <= iCodDlData->Count() ; ++i )
  3164     for ( TInt i = 1; i <= iCodDlData->Count() ; ++i )
  3135         {
  3165         {
  3136         downloadedSize = downloadedSize + (*iCodDlData)[i]->DownloadedSize();
  3166         downloadedSize = downloadedSize + (*iCodDlData)[i]->DownloadedSize();
  3137         iMoLength += (*iCodDlData)[i]->Size();
  3167         iMoLength += (*iCodDlData)[i]->Size();
  3144             iStorage->SetDownloadedSize( (*iCodDlData)[i]->DownloadedSize() );
  3174             iStorage->SetDownloadedSize( (*iCodDlData)[i]->DownloadedSize() );
  3145             iStorage->SetLength( (*iCodDlData)[i]->Size() );
  3175             iStorage->SetLength( (*iCodDlData)[i]->Size() );
  3146             activeDownloadChanged = ETrue;
  3176             activeDownloadChanged = ETrue;
  3147             }
  3177             }
  3148         }
  3178         }
  3149     iStorage->SetMoDownloadedSize( downloadedSize );
  3179     iStorage->SetMoDownloadedSize( downloadedSize );                
  3150     }
  3180     }
  3151 // -----------------------------------------------------------------------------
  3181 // -----------------------------------------------------------------------------
  3152 // CHttpDownload::SetTrackDataAttributeL
  3182 // CHttpDownload::SetTrackDataAttributeL
  3153 // ?implementation_description
  3183 // ?implementation_description
  3154 // (other items were commented in a header).
  3184 // (other items were commented in a header).
  3155 // -----------------------------------------------------------------------------
  3185 // -----------------------------------------------------------------------------
  3156 //
  3186 //
  3157 EXPORT_C void CHttpDownload::SetTrackDataAttributeL( TInt aIndex, HBufC8* dlData )
  3187 EXPORT_C void CHttpDownload::SetTrackDataAttributeL( TInt aIndex, HBufC8* dlData )
  3158     {
  3188     {
  3159     LOGGER_ENTERFN( "SetTrackDataAttributeL" );
  3189     LOGGER_ENTERFN( "SetTrackDataAttributeL" );
  3160 
  3190     
  3161 	if (iCodDlData)
  3191 	if (iCodDlData)
  3162     	{
  3192     	{
  3163     	CMediaDataServ* updatedMediaData = CMediaDataServ::NewL(*dlData);
  3193     	CMediaDataServ* updatedMediaData = CMediaDataServ::NewL(*dlData);
  3164     	CMediaDataBase* mediaData = (*iCodDlData)[aIndex];
  3194     	CMediaDataBase* mediaData = (*iCodDlData)[aIndex];
  3165     	mediaData->SetNameL(updatedMediaData->Name());
  3195     	mediaData->SetNameL(updatedMediaData->Name());
  3171 	    mediaData->SetState( updatedMediaData->State() );
  3201 	    mediaData->SetState( updatedMediaData->State() );
  3172 	    mediaData->SetResult( updatedMediaData->Result() );
  3202 	    mediaData->SetResult( updatedMediaData->Result() );
  3173 	    mediaData->SetDownloadedSize( updatedMediaData->DownloadedSize() );
  3203 	    mediaData->SetDownloadedSize( updatedMediaData->DownloadedSize() );
  3174 	    mediaData->SetDestFilenameL( updatedMediaData->DestFilename() );
  3204 	    mediaData->SetDestFilenameL( updatedMediaData->DestFilename() );
  3175 	    mediaData->SetTempFilenameL( updatedMediaData->DestFilename() );
  3205 	    mediaData->SetTempFilenameL( updatedMediaData->DestFilename() );
  3176 
  3206 	    	    
  3177     	mediaData->ResetTypes();
  3207     	mediaData->ResetTypes();
  3178     	for (TInt type = 0; type < updatedMediaData->TypesCount(); ++type)
  3208     	for (TInt type = 0; type < updatedMediaData->TypesCount(); ++type)
  3179         	mediaData->AddTypeL( updatedMediaData->Types().MdcaPoint(type) );
  3209         	mediaData->AddTypeL( updatedMediaData->Types().MdcaPoint(type) );
  3180         mediaData->SetStatusCode( updatedMediaData->StatusCode() );
  3210         mediaData->SetStatusCode( updatedMediaData->StatusCode() );
  3181         TInt result = updatedMediaData->Result();
  3211         TInt result = updatedMediaData->Result();
  3204 	        	    {
  3234 	        	    {
  3205 	        	    iGlobalErrorId = result;
  3235 	        	    iGlobalErrorId = result;
  3206 	        	    iLastError = EGeneral;
  3236 	        	    iLastError = EGeneral;
  3207 	           	    }
  3237 	           	    }
  3208                 }
  3238                 }
  3209 
  3239             
  3210             //if the client pauses the download, Codhandler sets error code to KErrCodHttpDownloadPaused. In that case, no need to trigger EHttpDlFailed Event
  3240             //if the client pauses the download, Codhandler sets error code to KErrCodHttpDownloadPaused. In that case, no need to trigger EHttpDlFailed Event     
  3211             if ( !( result == KErrCodHttpDownloadPaused || ( pausable && statusCode == KHttp903LossOfService ) || ( pausable && statusCode == KHttp954LoaderError ) ) )
  3241             if ( !( result == KErrCodHttpDownloadPaused || ( pausable && statusCode == KHttp903LossOfService ) || ( pausable && statusCode == KHttp954LoaderError ) ) )
  3212                 {
  3242                 {    
  3213     	        TriggerEvent( EHttpDlFailed, EHttpProgNone );
  3243     	        TriggerEvent( EHttpDlFailed, EHttpProgNone );
  3214                 }
  3244                 }
  3215             }
  3245             }
  3216     	}
  3246     	}
  3217     }
  3247     }
  3244         {
  3274         {
  3245         CLOG_WRITE( "No real error" );
  3275         CLOG_WRITE( "No real error" );
  3246         iNoRealError = EFalse;
  3276         iNoRealError = EFalse;
  3247 
  3277 
  3248         return;
  3278         return;
  3249         }
  3279         }    
  3250 
  3280     
  3251     if( iCodDlData && iCodDlData->Count() > 1 )
  3281     if( iCodDlData && iCodDlData->Count() > 1 )
  3252         {
  3282         {
  3253         if( aDlError == KErrMultipeObjectDownloadFailed )
  3283         if( aDlError == KErrMultipeObjectDownloadFailed )
  3254             {
  3284             {
  3255             //Permanently failed error in CodHandler
  3285             //Permanently failed error in CodHandler
  3256             //Delete the download
  3286             //Delete the download
  3257             SetDownloadStatus( EHttpProgNone,
  3287             SetDownloadStatus( EHttpProgNone,
  3258                    EHttpDlMultipleMOFailed,
  3288                    EHttpDlMultipleMOFailed,
  3259                    aDlError,
  3289                    aDlError,
  3260                    aError );
  3290                    aError );            
  3261             return;
  3291             return;                       
  3262             }
  3292             } 
  3263         else
  3293         else
  3264             {
  3294             {
  3265             SetDownloadStatus( EHttpProgNone,
  3295             SetDownloadStatus( EHttpProgNone,
  3266                                EHttpDlPaused,
  3296                                EHttpDlPaused,
  3267                                aDlError,
  3297                                aDlError,
  3268                                aError );
  3298                                aError );
  3269             return;
  3299             return;                                           
  3270 
  3300             
  3271             }
  3301             }
  3272         }
  3302         }
  3273 
  3303 
  3274     if( iDlState < EHttpDlCreated )
  3304     if( iDlState < EHttpDlCreated )
  3275         // error occured during download object construction -> nothing to do here
  3305         // error occured during download object construction -> nothing to do here
  3278         }
  3308         }
  3279 
  3309 
  3280 
  3310 
  3281     //For COD Downloads, the error code may be set from COD handler
  3311     //For COD Downloads, the error code may be set from COD handler
  3282     //In that case if the download is paused just set the global and download error
  3312     //In that case if the download is paused just set the global and download error
  3283 
  3313     
  3284     if( iCodDownload && iDlState == EHttpDlPaused )
  3314     if( iCodDownload && iDlState == EHttpDlPaused )  
  3285         {
  3315         {
  3286         iLastError = aDlError;
  3316         iLastError = aDlError;
  3287         iGlobalErrorId = aError;
  3317         iGlobalErrorId = aError;
  3288         TRAP_IGNORE( StoreDownloadInfoL() );
  3318         TRAP_IGNORE( StoreDownloadInfoL() );
  3289         return;
  3319         return;
  3297     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EKeepFile;
  3327     CHttpStorage::TFileCloseOperation closeOp = CHttpStorage::EKeepFile;
  3298     if ( !Pausable() && ( iCodDlData && iCodDlData->Count() == 1 ) )
  3328     if ( !Pausable() && ( iCodDlData && iCodDlData->Count() == 1 ) )
  3299         {
  3329         {
  3300         closeOp = CHttpStorage::EReplaceFile;
  3330         closeOp = CHttpStorage::EReplaceFile;
  3301         }
  3331         }
  3302 
  3332         
  3303     iStorage->CloseDestinationFile( closeOp );
  3333     iStorage->CloseDestinationFile( closeOp );
  3304     CLOG_WRITE_1( "OnError1 : iDlState : %d ", iDlState );
  3334     CLOG_WRITE_1( "OnError1 : iDlState : %d ", iDlState );
  3305 
  3335 
  3306     if( iDlState != EHttpDlMultipleMOFailed )
  3336     if( iDlState != EHttpDlMultipleMOFailed )
  3307         {
  3337         {
  3317                 }
  3347                 }
  3318             }
  3348             }
  3319 
  3349 
  3320         if( aError == KErrHttpPartialResponseReceived )
  3350         if( aError == KErrHttpPartialResponseReceived )
  3321             {
  3351             {
  3322             //Partial response has been received and connection has been disconnected. This error will be
  3352             //Partial response has been received and connection has been disconnected. This error will be 
  3323             //propagated to the client only, if the HTTP:ENotifyOnDisconnect property is set with a value
  3353             //propagated to the client only, if the HTTP:ENotifyOnDisconnect property is set with a value
  3324             //HTTP::EEnableDisconnectNotification
  3354             //HTTP::EEnableDisconnectNotification
  3325 
  3355             
  3326             //This error code was cancelling the pausable download. This error shud be ignored to keep the
  3356             //This error code was cancelling the pausable download. This error shud be ignored to keep the
  3327             //paused download.
  3357             //paused download.
  3328             //TSW Err ID : SXUU-77SRWL
  3358             //TSW Err ID : SXUU-77SRWL
  3329 
  3359             
  3330             SetDownloadStatus( EHttpProgNone,
  3360             SetDownloadStatus( EHttpProgNone,
  3331                                EHttpDlPaused,
  3361                                EHttpDlPaused,
  3332                                aDlError,
  3362                                aDlError,
  3333                                aError );
  3363                                aError );            
  3334 
  3364 
  3335             }
  3365             }
  3336         else if( aDlError == EConnectionFailed && iPausable)
  3366         else if( aDlError == EConnectionFailed && iPausable)
  3337             {
  3367             {
  3338             //Whenever connection error occurs and download can be paused.
  3368             //Whenever connection error occurs and download can be paused.
  3339             //Keep the download in paused state.
  3369             //Keep the download in paused state.
  3340             SetDownloadStatus( EHttpProgNone,
  3370             SetDownloadStatus( EHttpProgNone,
  3341                                EHttpDlPaused,
  3371                                EHttpDlPaused,
  3342                                aDlError,
  3372                                aDlError,
  3343                                aError );
  3373                                aError );               
  3344             }
  3374             }
  3345         else if ( aDlError == EMMCRemoved )
  3375         else if ( aDlError == EMMCRemoved )
  3346             {
  3376             {
  3347             // MMC removed. Pause the download.
  3377             // MMC removed. Pause the download.
  3348             SetDownloadStatus( EHttpProgNone,
  3378             SetDownloadStatus( EHttpProgNone,
  3386         }
  3416         }
  3387     else if( iPDClAppInstance == aInstance )
  3417     else if( iPDClAppInstance == aInstance )
  3388         {
  3418         {
  3389         iPDClAppInstance = NULL;
  3419         iPDClAppInstance = NULL;
  3390         }
  3420         }
  3391 
  3421         
  3392     return (iPDClAppInstance || iClAppInstance);
  3422     return (iPDClAppInstance || iClAppInstance);
  3393     }
  3423     }
  3394 
  3424     
  3395 
  3425     
  3396 // -----------------------------------------------------------------------------
  3426 // -----------------------------------------------------------------------------
  3397 // CHttpDownload::ClientApp
  3427 // CHttpDownload::ClientApp
  3398 // ?implementation_description
  3428 // ?implementation_description
  3399 // (other items were commented in a header).
  3429 // (other items were commented in a header).
  3400 // -----------------------------------------------------------------------------
  3430 // -----------------------------------------------------------------------------
  3477 // -----------------------------------------------------------------------------
  3507 // -----------------------------------------------------------------------------
  3478 //
  3508 //
  3479 void CHttpDownload::MediaRemoved( TUint aUid, TBool aDontCheckMediaUid )
  3509 void CHttpDownload::MediaRemoved( TUint aUid, TBool aDontCheckMediaUid )
  3480     {
  3510     {
  3481     LOGGER_ENTERFN( "MediaRemoved" );
  3511     LOGGER_ENTERFN( "MediaRemoved" );
  3482     CLOG_WRITE_3( "Uid: %d, dontCheck: %d, iNoMedia: %d",
  3512     CLOG_WRITE_3( "Uid: %d, dontCheck: %d, iNoMedia: %d", 
  3483                         aUid,
  3513                         aUid, 
  3484                         aDontCheckMediaUid,
  3514                         aDontCheckMediaUid, 
  3485                         iNoMedia );
  3515                         iNoMedia );
  3486 
  3516 
  3487     if( iNoMedia )
  3517     if( iNoMedia )
  3488         // it is already known for us.
  3518         // it is already known for us.
  3489         {
  3519         {
  3501     iNoMedia = ETrue;
  3531     iNoMedia = ETrue;
  3502 
  3532 
  3503     TRAP_IGNORE( InternalPauseL() );
  3533     TRAP_IGNORE( InternalPauseL() );
  3504 
  3534 
  3505     TriggerEvent( EHttpDlMediaRemoved );
  3535     TriggerEvent( EHttpDlMediaRemoved );
  3506 
  3536     
  3507     if( iDlState == EHttpDlInprogress )
  3537     if( iDlState == EHttpDlInprogress )
  3508         // it's happened during the download process
  3538         // it's happened during the download process
  3509         // in case of e.g completed download it's not error
  3539         // in case of e.g completed download it's not error
  3510         {
  3540         {
  3511         OnError( KErrGeneral, EMMCRemoved );
  3541         OnError( KErrGeneral, EMMCRemoved );
  3512         }
  3542         }
  3513 
  3543     
  3514     TRAP_IGNORE( StoreDownloadInfoL() );
  3544     TRAP_IGNORE( StoreDownloadInfoL() );
  3515     }
  3545     }
  3516 
  3546 
  3517 // -----------------------------------------------------------------------------
  3547 // -----------------------------------------------------------------------------
  3518 // CHttpDownload::MediaInserted
  3548 // CHttpDownload::MediaInserted
  3531         }
  3561         }
  3532 
  3562 
  3533     iNoMedia = EFalse;
  3563     iNoMedia = EFalse;
  3534     TriggerEvent( EHttpDlMediaInserted );
  3564     TriggerEvent( EHttpDlMediaInserted );
  3535     }
  3565     }
  3536 
  3566     
  3537 // -----------------------------------------------------------------------------
  3567 // -----------------------------------------------------------------------------
  3538 // CHttpDownload::GetDestinationDriveID
  3568 // CHttpDownload::GetDestinationDriveID
  3539 // ?implementation_description
  3569 // ?implementation_description
  3540 // (other items were commented in a header).
  3570 // (other items were commented in a header).
  3541 // -----------------------------------------------------------------------------
  3571 // -----------------------------------------------------------------------------
  3542 //
  3572 //
  3543 TInt CHttpDownload::GetDestinationDriveID() const
  3573 TInt CHttpDownload::GetDestinationDriveID() const
  3544     {
  3574     {
  3545     return (TInt)iStorage->GetDestinationDriveId();
  3575     return (TInt)iStorage->GetDestinationDriveId();
  3546     }
  3576     }
  3547 
  3577     
  3548 // -----------------------------------------------------------------------------
  3578 // -----------------------------------------------------------------------------
  3549 // CHttpDownload::SetClientInstance
  3579 // CHttpDownload::SetClientInstance
  3550 // ?implementation_description
  3580 // ?implementation_description
  3551 // (other items were commented in a header).
  3581 // (other items were commented in a header).
  3552 // -----------------------------------------------------------------------------
  3582 // -----------------------------------------------------------------------------
  3605 // -----------------------------------------------------------------------------
  3635 // -----------------------------------------------------------------------------
  3606 //
  3636 //
  3607 void CHttpDownload::SetDownloadNameL( const TDesC& aNewName )
  3637 void CHttpDownload::SetDownloadNameL( const TDesC& aNewName )
  3608     {
  3638     {
  3609     CLOG_WRITE_1( "New download name: [%S]", &aNewName );
  3639     CLOG_WRITE_1( "New download name: [%S]", &aNewName );
  3610 
  3640     
  3611     ReallocateStringL( iDlName, aNewName, KDownloadNameMaxSize );
  3641     ReallocateStringL( iDlName, aNewName, KDownloadNameMaxSize );
  3612 
  3642     
  3613     FixDownloadNameL();
  3643     FixDownloadNameL();
  3614 
  3644     
  3615     TriggerEvent( EHttpDlInprogress, EHttpProgDlNameChanged );
  3645     TriggerEvent( EHttpDlInprogress, EHttpProgDlNameChanged );
  3616     }
  3646     }
  3617 
  3647 
  3618 // -----------------------------------------------------------------------------
  3648 // -----------------------------------------------------------------------------
  3619 // CHttpDownload::MHFRunL
  3649 // CHttpDownload::MHFRunL
  3620 // ?implementation_description
  3650 // ?implementation_description
  3621 // (other items were commented in a header).
  3651 // (other items were commented in a header).
  3622 // -----------------------------------------------------------------------------
  3652 // -----------------------------------------------------------------------------
  3623 //
  3653 //
  3624 void CHttpDownload::MHFRunL( RHTTPTransaction /*aTransaction*/,
  3654 void CHttpDownload::MHFRunL( RHTTPTransaction /*aTransaction*/, 
  3625                              const THTTPEvent& aEvent )
  3655                              const THTTPEvent& aEvent )
  3626     {
  3656     {
  3627     switch ( aEvent.iStatus )
  3657     switch ( aEvent.iStatus )
  3628         {
  3658         {
  3629         case THTTPEvent::EGotResponseHeaders:
  3659         case THTTPEvent::EGotResponseHeaders:
  3630             {
  3660             {
  3631             CLOG_WRITE( "Response header received" );
  3661             CLOG_WRITE( "Response header received" );
  3632             ResponseHeaderReceivedL();
  3662             ResponseHeaderReceivedL();
  3633             }
  3663             } 
  3634             break;
  3664             break;
  3635 
  3665 
  3636         case THTTPEvent::EGotResponseBodyData:
  3666         case THTTPEvent::EGotResponseBodyData:
  3637             {
  3667             {
  3638             MHTTPDataSupplier* respBody = iTrans.Response().Body();
  3668             MHTTPDataSupplier* respBody = iTrans.Response().Body();
  3641             respBody->GetNextDataPart( buf );
  3671             respBody->GetNextDataPart( buf );
  3642 
  3672 
  3643             ResponseBodyReceivedL( buf );
  3673             ResponseBodyReceivedL( buf );
  3644 
  3674 
  3645             respBody->ReleaseData();
  3675             respBody->ReleaseData();
  3646             }
  3676             } 
  3647             break;
  3677             break;
  3648 
  3678 
  3649         case THTTPEvent::EResponseComplete:
  3679         case THTTPEvent::EResponseComplete:
  3650             {
  3680             {
  3651             CLOG_WRITE( "Response complete" );
  3681             CLOG_WRITE( "Response complete" );
  3652             }
  3682             } 
  3653             break;
  3683             break;
  3654 
  3684 
  3655         case THTTPEvent::ESucceeded:
  3685         case THTTPEvent::ESucceeded:
  3656             {
  3686             {
  3657             CLOG_WRITE( "Transaction succeeded" );
  3687             CLOG_WRITE( "Transaction succeeded" );
  3658 
  3688             
  3659             DownloadSucceededL();
  3689             DownloadSucceededL();
  3660             }
  3690             } 
  3661             break;
  3691             break;
  3662 
  3692 
  3663         case THTTPEvent::EFailed:
  3693         case THTTPEvent::EFailed:
  3664         case THTTPEvent::EMoreDataReceivedThanExpected:
  3694         case THTTPEvent::EMoreDataReceivedThanExpected:
  3665         case THTTPEvent::EUnrecoverableError:
  3695         case THTTPEvent::EUnrecoverableError:
  3670                 {
  3700                 {
  3671                 iTrans.Close();
  3701                 iTrans.Close();
  3672                 iTransValid = EFalse;
  3702                 iTransValid = EFalse;
  3673                 }
  3703                 }
  3674             iDlStartedByClient = EFalse;
  3704             iDlStartedByClient = EFalse;
  3675             }
  3705             } 
  3676             break;
  3706             break;
  3677 
  3707 
  3678         case THTTPEvent::ERedirectedPermanently:
  3708         case THTTPEvent::ERedirectedPermanently:
  3679             {
  3709             {
  3680             RedirectedPermanentlyL( iTrans.Request().URI().UriDes() );
  3710             RedirectedPermanentlyL( iTrans.Request().URI().UriDes() );
  3681             }
  3711             } 
  3682             break;
  3712             break;
  3683 
  3713 
  3684         case THTTPEvent::ERedirectedTemporarily:
  3714         case THTTPEvent::ERedirectedTemporarily:
  3685             {
  3715             {
  3686             RedirectedTemporaryL( iTrans.Request().URI().UriDes() );
  3716             RedirectedTemporaryL( iTrans.Request().URI().UriDes() );
  3687             }
  3717             } 
  3688             break;
  3718             break;
  3689 
  3719 
  3690         default:
  3720         default:
  3691             {
  3721             {
  3692             CLOG_WRITE_1( "Event: %d", aEvent.iStatus );
  3722             CLOG_WRITE_1( "Event: %d", aEvent.iStatus );
  3693             if( aEvent.iStatus < 0 )
  3723             if( aEvent.iStatus < 0 )
  3694                 // error occured -> leave will be handled in OnError()
  3724                 // error occured -> leave will be handled in OnError()
  3695                 {
  3725                 {
  3696                 User::Leave( aEvent.iStatus );
  3726                 User::Leave( aEvent.iStatus );
  3697                 }
  3727                 }
  3698             }
  3728             } 
  3699             break;
  3729             break;
  3700         }
  3730         }
  3701     }
  3731     }
  3702 
  3732 
  3703 // -----------------------------------------------------------------------------
  3733 // -----------------------------------------------------------------------------
  3704 // CHttpDownload::MHFRunError
  3734 // CHttpDownload::MHFRunError
  3705 // ?implementation_description
  3735 // ?implementation_description
  3706 // (other items were commented in a header).
  3736 // (other items were commented in a header).
  3707 // -----------------------------------------------------------------------------
  3737 // -----------------------------------------------------------------------------
  3708 //
  3738 //
  3709 TInt CHttpDownload::MHFRunError( TInt aError,
  3739 TInt CHttpDownload::MHFRunError( TInt aError, 
  3710                                  RHTTPTransaction /*aTransaction*/,
  3740                                  RHTTPTransaction /*aTransaction*/, 
  3711                                  const THTTPEvent& /*aEvent*/ )
  3741                                  const THTTPEvent& /*aEvent*/ )
  3712     {
  3742     {
  3713     CLOG_WRITE_1( "MHFRunError: %d", aError );
  3743     CLOG_WRITE_1( "MHFRunError: %d", aError );
  3714 
  3744 
  3715     OnError( aError, ETransactionFailed );
  3745     OnError( aError, ETransactionFailed );
  3769                     TriggerEvent( EHttpDlInprogress, EHttpProgCodDownloadShouldResume );
  3799                     TriggerEvent( EHttpDlInprogress, EHttpProgCodDownloadShouldResume );
  3770                     }
  3800                     }
  3771                 else
  3801                 else
  3772                     {
  3802                     {
  3773                     RequestContentL();
  3803                     RequestContentL();
  3774                     }
  3804                     }                
  3775                 }
  3805                 }
  3776 
  3806                 
  3777             }
  3807             }
  3778             break;
  3808             break;
  3779 
  3809 
  3780         case EHttpProgMovingContentFile:
  3810         case EHttpProgMovingContentFile:
  3781             // Move completed
  3811             // Move completed
  3782             // State remains in completed
  3812             // State remains in completed 
  3783             // and move result stored in error attribs
  3813             // and move result stored in error attribs
  3784             {
  3814             {
  3785             CLOG_WRITE_1( "Move result: %d", iStatus.Int() );
  3815             CLOG_WRITE_1( "Move result: %d", iStatus.Int() );
  3786             // In case of PDL for OMA2 the MP/VP moves the file after the playback is done.
  3816             // In case of PDL for OMA2 the MP/VP moves the file after the playback is done.
  3787 			// So, the download status should be changed after that
  3817 			// So, the download status should be changed after that
  3788 			//but we again send the progress state as EHttpProgContentFileMoved because we need to display
  3818 			//but we again send the progress state as EHttpProgContentFileMoved because we need to display
  3789 			//where file is saved(saved to gallery)
  3819 			//where file is saved(saved to gallery)
  3790 			//Change Dl State to Download Completed if not already
  3820 			//Change Dl State to Download Completed if not already           
  3791 
  3821           
  3792 		    if(_OMADLOTA2_MULTI_DOWNLOAD)
  3822             if( iStatus ==KErrNone )
  3793 				{
  3823                 {
  3794 				TPtrC fileNamePtr = ((*iCodDlData)[iMOMoved])->DestFilename();
  3824 		          if(_OMADLOTA2_MULTI_DOWNLOAD)
  3795 				NotifyMediaGalleryL(fileNamePtr);
  3825 				     {
  3796 
  3826 				      TPtrC fileNamePtr = ((*iCodDlData)[iMOMoved])->DestFilename();
  3797 				// Initiate async move for the next media object
  3827 				      NotifyMediaGalleryL(fileNamePtr);
  3798 				iMOMoved++;
  3828 
  3799 				if(iMOMoved <= iCodDlData->Count())
  3829              	      // Initiate async move for the next media object
  3800 					{
  3830 				      iMOMoved++;
  3801 					MoveDownloadedMediaObjectL(iMOMoved);
  3831 				      if(iMOMoved <= iCodDlData->Count())
  3802 					break;
  3832 					     {
  3803 					}
  3833 					      MoveDownloadedMediaObjectL(iMOMoved);
  3804 				}
  3834 					      break;
  3805 
  3835 					     }
  3806             SetDownloadStatus( iDlNameChanged ? EHttpProgContentFileMovedAndDestFNChanged : EHttpProgContentFileMoved,
  3836 				      }
  3807                                iDlState = EHttpDlMultipleMOCompleted,
  3837 
       
  3838                   SetDownloadStatus( iDlNameChanged ? EHttpProgContentFileMovedAndDestFNChanged : EHttpProgContentFileMoved, 
       
  3839                                iDlState = EHttpDlMultipleMOCompleted, 
  3808                                iStatus == KErrNone ? ENoError : EMoveFailed,
  3840                                iStatus == KErrNone ? ENoError : EMoveFailed,
  3809                                iStatus.Int() );
  3841                                iStatus.Int() );
  3810 
  3842             
  3811             if(iStatus == KErrNone)
  3843                   if(iStatus == KErrNone)
  3812             	{
  3844             	      {
  3813             	iMoveInProgress = EFalse;
  3845             	       iMoveInProgress = EFalse;	
  3814             	CLOG_WRITE("setting iMoveInProgress false when move is completed");
  3846             	       CLOG_WRITE("setting iMoveInProgress false when move is completed");
  3815             	}
  3847             	      }
  3816 
  3848             
  3817 
  3849                   delete iFileMan; iFileMan = NULL;
  3818             delete iFileMan; iFileMan = NULL;
  3850             
  3819 
  3851                   if( !_OMADLOTA2_MULTI_DOWNLOAD)
  3820 			if( !_OMADLOTA2_MULTI_DOWNLOAD)
  3852 				     {
  3821 				{
  3853 				      TPtr fileNamePtr(iStorage->DestFilename()->Des());
  3822 				TPtr fileNamePtr(iStorage->DestFilename()->Des());
  3854 				      NotifyMediaGalleryL(fileNamePtr);
  3823 				NotifyMediaGalleryL(fileNamePtr);
  3855 				     }
  3824 				}
  3856                 }
  3825             }
  3857             else
       
  3858                 {
       
  3859                 CLOG_WRITE("Move Operation Failed ");
       
  3860                 CLOG_WRITE("setting progress state to EHttpProgNone when move is Failing");
       
  3861                 SetDownloadStatus( EHttpProgNone, iDlState );
       
  3862                 CLOG_WRITE("setting iMoveInProgress false when move is Failing");
       
  3863                 iMoveInProgress = EFalse;
       
  3864                 }
       
  3865             } 
  3826             break;
  3866             break;
  3827 
  3867 
  3828         default:
  3868         default:
  3829             {
  3869             {
  3830             DMPanic( KErrUnknown );
  3870             DMPanic( KErrUnknown );
  3898         // we are not interested in this event,
  3938         // we are not interested in this event,
  3899         // only if the download is in progress.
  3939         // only if the download is in progress.
  3900         {
  3940         {
  3901         return;
  3941         return;
  3902         }
  3942         }
  3903 
  3943         
  3904     //Set the errors
  3944     //Set the errors 
  3905     TRAP_IGNORE( PauseL( ETrue ) );
  3945     TRAP_IGNORE( PauseL( ETrue ) );
  3906 
  3946     
  3907     iLastError = EConnectionFailed;
  3947     iLastError = EConnectionFailed;
  3908     iGlobalErrorId = KErrCommsLineFail;
  3948     iGlobalErrorId = KErrCommsLineFail;
  3909     }
  3949     }
  3910 
  3950 
  3911 
  3951 
  3958     iPausableDRM = ETrue;
  3998     iPausableDRM = ETrue;
  3959     iDrmContentLengthValid = ETrue;
  3999     iDrmContentLengthValid = ETrue;
  3960 
  4000 
  3961     // content type is unknown -> download might be pausable again
  4001     // content type is unknown -> download might be pausable again
  3962     UpdatePausable();
  4002     UpdatePausable();
  3963 
  4003     
  3964     if( !aOnDelete )
  4004     if( !aOnDelete )
  3965         {
  4005         {
  3966         TRAP_IGNORE( StoreDownloadInfoL() );
  4006         TRAP_IGNORE( StoreDownloadInfoL() );
  3967         }
  4007         }
  3968 
  4008 
  3978 // -----------------------------------------------------------------------------
  4018 // -----------------------------------------------------------------------------
  3979 //
  4019 //
  3980 void CHttpDownload::StoreDownloadInfoL()
  4020 void CHttpDownload::StoreDownloadInfoL()
  3981     {
  4021     {
  3982     LOGGER_ENTERFN( "StoreDownloadInfoL" );
  4022     LOGGER_ENTERFN( "StoreDownloadInfoL" );
  3983     TInt bufSz = KDownloadInfoIncrSize +
  4023     TInt bufSz = KDownloadInfoIncrSize + 
  3984                  (iDownloadInfo ? iDownloadInfo->Length(): 0);
  4024                  (iDownloadInfo ? iDownloadInfo->Length(): 0);
  3985     HBufC8* newInfo = HBufC8::NewLC( bufSz );
  4025     HBufC8* newInfo = HBufC8::NewLC( bufSz );
  3986     TPtr8 newInfoPtr = newInfo->Des();
  4026     TPtr8 newInfoPtr = newInfo->Des();
  3987 
  4027 
  3988     APPEND_BUF_INT( newInfoPtr, KDMgrInfoFileId );
  4028     APPEND_BUF_INT( newInfoPtr, KDMgrInfoFileId );
  4020     APPEND_BUF_INT( newInfoPtr, iExpires );
  4060     APPEND_BUF_INT( newInfoPtr, iExpires );
  4021     APPEND_BUF_INT( newInfoPtr, iMaxAge );
  4061     APPEND_BUF_INT( newInfoPtr, iMaxAge );
  4022 
  4062 
  4023     CLOG_WRITE("5");
  4063     CLOG_WRITE("5");
  4024 
  4064 
  4025 
  4065     
  4026     TInt size = GetHttpHeadersSize(iResponseHeaders)+ GetHttpHeadersSize(iRequestHeaders)+
  4066     TInt size = GetHttpHeadersSize(iResponseHeaders)+ GetHttpHeadersSize(iRequestHeaders)+
  4027                 GetHttpHeadersSize(iEntityHeaders)+ GetHttpHeadersSize(iGeneralHeaders) + newInfoPtr.Size();
  4067                 GetHttpHeadersSize(iEntityHeaders)+ GetHttpHeadersSize(iGeneralHeaders) + newInfoPtr.Size();
  4028 
  4068     
  4029 
  4069     
  4030     if(size >= bufSz)
  4070     if(size >= bufSz)
  4031         {
  4071         {
  4032     	User::LeaveIfError( KErrArgument );
  4072     	User::LeaveIfError( KErrArgument );
  4033         }
  4073         }
  4034 
  4074     
  4035     AppendHeadersL( newInfoPtr, iResponseHeaders );
  4075     AppendHeadersL( newInfoPtr, iResponseHeaders );
  4036     AppendHeadersL( newInfoPtr, iRequestHeaders );
  4076     AppendHeadersL( newInfoPtr, iRequestHeaders );
  4037     AppendHeadersL( newInfoPtr, iEntityHeaders );
  4077     AppendHeadersL( newInfoPtr, iEntityHeaders );
  4038     AppendHeadersL( newInfoPtr, iGeneralHeaders );
  4078     AppendHeadersL( newInfoPtr, iGeneralHeaders );
  4039 
  4079 
  4040     CLOG_WRITE("6");
  4080     CLOG_WRITE("6");
  4041 
  4081     
  4042     APPEND_BUF_INT( newInfoPtr, iFotaPckgId );
  4082     APPEND_BUF_INT( newInfoPtr, iFotaPckgId );
  4043 
  4083     
  4044     CLOG_WRITE("7");
  4084     CLOG_WRITE("7");
  4045 
  4085     
  4046     // check if download info is unchanged from previous update
  4086     // check if download info is unchanged from previous update
  4047     if( iDownloadInfo && ( iDownloadInfo->Compare(*newInfo) == 0 ))
  4087     if( iDownloadInfo && ( iDownloadInfo->Compare(*newInfo) == 0 ))
  4048         {
  4088         {
  4049         // no change
  4089         // no change
  4050         CLOG_WRITE("DownloadInfo unchanged - no need to update");
  4090         CLOG_WRITE("DownloadInfo unchanged - no need to update");
  4062         HBufC* fileNameBuf = HBufC::NewLC( KMaxPath );
  4102         HBufC* fileNameBuf = HBufC::NewLC( KMaxPath );
  4063         TPtr fileName = fileNameBuf->Des();
  4103         TPtr fileName = fileNameBuf->Des();
  4064         iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
  4104         iClientApp->Engine()->DownloadInfoFolder( iClientApp, folder );
  4065         fileName.Format( _L("%S%d"), &folder, iId );
  4105         fileName.Format( _L("%S%d"), &folder, iId );
  4066         CLOG_WRITE_1( "info: %S", &fileName );
  4106         CLOG_WRITE_1( "info: %S", &fileName );
  4067 
  4107     
  4068         RFile outFile;
  4108         RFile outFile;
  4069         CleanupClosePushL<RFile>( outFile );
  4109         CleanupClosePushL<RFile>( outFile );
  4070         User::LeaveIfError( outFile.Replace( iClientApp->Engine()->Fs(),
  4110         User::LeaveIfError( outFile.Replace( iClientApp->Engine()->Fs(), 
  4071                                              fileName,
  4111                                              fileName, 
  4072                                              EFileShareExclusive |
  4112                                              EFileShareExclusive | 
  4073                                              EFileStream |
  4113                                              EFileStream | 
  4074                                              EFileWrite ) );
  4114                                              EFileWrite ) );
  4075 
  4115 
  4076         outFile.Write( newInfoPtr );
  4116         outFile.Write( newInfoPtr );
  4077         User::LeaveIfError( outFile.Flush() );
  4117         User::LeaveIfError( outFile.Flush() );
  4078         CleanupStack::PopAndDestroy( 2, fileNameBuf );
  4118         CleanupStack::PopAndDestroy( 2, fileNameBuf );
  4100 
  4140 
  4101     fileName.Format( _L("%S%d"), &folder, iId );
  4141     fileName.Format( _L("%S%d"), &folder, iId );
  4102     CLOG_WRITE_1( "info: %S", &fileName );
  4142     CLOG_WRITE_1( "info: %S", &fileName );
  4103 
  4143 
  4104     RFile inFile;
  4144     RFile inFile;
  4105     User::LeaveIfError( inFile.Open( iClientApp->Engine()->Fs(),
  4145     User::LeaveIfError( inFile.Open( iClientApp->Engine()->Fs(), 
  4106                                      fileName,
  4146                                      fileName, 
  4107                                      EFileShareReadersOnly |
  4147                                      EFileShareReadersOnly | 
  4108                                      EFileRead ) );
  4148                                      EFileRead ) );
  4109 
  4149 
  4110     CLOG_WRITE("1");
  4150     CLOG_WRITE("1");
  4111     CleanupClosePushL<RFile>( inFile );
  4151     CleanupClosePushL<RFile>( inFile );
  4112 
  4152 
  4151 	    User::Leave( KErrNotSupported );
  4191 	    User::Leave( KErrNotSupported );
  4152 	   }
  4192 	   }
  4153     ReadHBufCL( inFile, iHashedMsgBody );
  4193     ReadHBufCL( inFile, iHashedMsgBody );
  4154     READ_INT_L( inFile, iCodDownload );
  4194     READ_INT_L( inFile, iCodDownload );
  4155     READ_INT_L( inFile, iNoMedia );
  4195     READ_INT_L( inFile, iNoMedia );
  4156 
  4196     
  4157 
  4197 
  4158     CLOG_WRITE("3");
  4198     CLOG_WRITE("3");
  4159     READ_INT_L( inFile, iPreferencies );
  4199     READ_INT_L( inFile, iPreferencies );
  4160     READ_INT_L( inFile, iDisconnectOnPause );
  4200     READ_INT_L( inFile, iDisconnectOnPause );
  4161     READ_INT_L( inFile, iDisconnectOnReset );
  4201     READ_INT_L( inFile, iDisconnectOnReset );
  4171 
  4211 
  4172     LoadHeadersL( inFile, iResponseHeaders );
  4212     LoadHeadersL( inFile, iResponseHeaders );
  4173     LoadHeadersL( inFile, iRequestHeaders );
  4213     LoadHeadersL( inFile, iRequestHeaders );
  4174     LoadHeadersL( inFile, iEntityHeaders );
  4214     LoadHeadersL( inFile, iEntityHeaders );
  4175     LoadHeadersL( inFile, iGeneralHeaders );
  4215     LoadHeadersL( inFile, iGeneralHeaders );
  4176 
  4216     
  4177     CLOG_WRITE("6");
  4217     CLOG_WRITE("6");
  4178 
  4218     
  4179     READ_INT_L( inFile, iFotaPckgId );
  4219     READ_INT_L( inFile, iFotaPckgId );
  4180 
  4220 
  4181     CleanupStack::PopAndDestroy(); // inFile
  4221     CleanupStack::PopAndDestroy(); // inFile
  4182     CleanupStack::PopAndDestroy( 2, folderBuf ); // also fileNameBuf
  4222     CleanupStack::PopAndDestroy( 2, folderBuf ); // also fileNameBuf
  4183 
  4223 
  4184     CLOG_WRITE("9");
  4224     CLOG_WRITE("9");
  4185 
  4225     
  4186     UpdatePausable();
  4226     UpdatePausable();
  4187     }
  4227     }
  4188 
  4228 
  4189 // -----------------------------------------------------------------------------
  4229 // -----------------------------------------------------------------------------
  4190 // CHttpDownload::IsExpired
  4230 // CHttpDownload::IsExpired
  4229 // -----------------------------------------------------------------------------
  4269 // -----------------------------------------------------------------------------
  4230 //
  4270 //
  4231 
  4271 
  4232 TBool CHttpDownload::IsContentFileStorageType()
  4272 TBool CHttpDownload::IsContentFileStorageType()
  4233     {
  4273     {
  4234 
  4274     
  4235 
  4275      
  4236      if( iCodDownload
  4276      if( iCodDownload 
  4237          && iContentType->Compare( KRoapMimeType )
  4277          && iContentType->Compare( KRoapMimeType ) 
  4238          && iContentType->Compare( KRoapPduMimeType )
  4278          && iContentType->Compare( KRoapPduMimeType ) 
  4239          && iContentType->Compare( KFotaPackageDataType)  )
  4279          && iContentType->Compare( KFotaPackageDataType)  )
  4240          {
  4280          {
  4241      	 return ETrue;
  4281      	 return ETrue;
  4242          }
  4282          }
  4243 
  4283             
  4244      return EFalse;
  4284      return EFalse;
  4245 
  4285      
  4246     }
  4286     }
  4247 
  4287 
  4248 // -----------------------------------------------------------------------------
  4288 // -----------------------------------------------------------------------------
  4249 // CHttpDownload::OnCompletedL
  4289 // CHttpDownload::OnCompletedL
  4250 // ?implementation_description
  4290 // ?implementation_description
  4267             {
  4307             {
  4268             CLOG_WRITE( "CHttpDownload::OnCompletedL(): triggering event EHttpResponseForContentType" );
  4308             CLOG_WRITE( "CHttpDownload::OnCompletedL(): triggering event EHttpResponseForContentType" );
  4269             TriggerEvent( EHttpDlInprogress, EHttpContTypeRecognitionAvail );
  4309             TriggerEvent( EHttpDlInprogress, EHttpContTypeRecognitionAvail );
  4270             iContTypeRecognitionAvailSent = ETrue;
  4310             iContTypeRecognitionAvailSent = ETrue;
  4271             }
  4311             }
  4272         //for correct display of string in download list for COD download we set progress state to moved
  4312         //for correct display of string in download list for COD download we set progress state to moved            
  4273         if(IsContentFileStorageType())
  4313         if(IsContentFileStorageType())
  4274             {
  4314             {
  4275            // Retrieve the file name from the whole paths
  4315            // Retrieve the file name from the whole paths
  4276             HBufC* fileName = iStorage->DestFilename();
  4316             HBufC* fileName = iStorage->DestFilename();
  4277             TInt lastSlashPos = fileName->LocateReverse( '\\' );
  4317             TInt lastSlashPos = fileName->LocateReverse( '\\' );
  4283             namePtr.Copy( fileName->Right(fileName->Length()-lastSlashPos-1) );
  4323             namePtr.Copy( fileName->Right(fileName->Length()-lastSlashPos-1) );
  4284 
  4324 
  4285             TInt findDot = iDlName->LocateReverse( '.' );
  4325             TInt findDot = iDlName->LocateReverse( '.' );
  4286             if( findDot == KErrNotFound )
  4326             if( findDot == KErrNotFound )
  4287                 {
  4327                 {
  4288                 //if Name displayed does not have Extension then
  4328                 //if Name displayed does not have Extension then 
  4289                 // Remove extention from retrieved name
  4329                 // Remove extention from retrieved name
  4290                 TInt dotInd = namePtr.LocateReverse( '.' );
  4330                 TInt dotInd = namePtr.LocateReverse( '.' );
  4291                  if( dotInd == KErrNotFound )
  4331                  if( dotInd == KErrNotFound )
  4292                     dotInd = namePtr.Length();
  4332                     dotInd = namePtr.Length();
  4293                 namePtr.Copy( namePtr.Left( dotInd ) );
  4333                 namePtr.Copy( namePtr.Left( dotInd ) );       
  4294 
  4334             
  4295                 }
  4335                 }
  4296 
  4336 
  4297             //we never get file moved and Download complete for Cod download becuase move is inherent
  4337             //we never get file moved and Download complete for Cod download becuase move is inherent
  4298             //to Install() state i.e  Download is in progress so display in download list is incorrect.
  4338             //to Install() state i.e  Download is in progress so display in download list is incorrect.
  4299             //related to bug  HCHA-753D6G
  4339             //related to bug  HCHA-753D6G  
  4300 
  4340              
  4301             if(namePtr.Compare(*iDlName))
  4341             if(namePtr.Compare(*iDlName))
  4302                 {
  4342                 {
  4303                 ReallocateStringL( iDlName, namePtr, KDownloadNameMaxSize );
  4343                 ReallocateStringL( iDlName, namePtr, KDownloadNameMaxSize );
  4304                 SetDownloadStatus( EHttpProgContentFileMovedAndDestFNChanged, EHttpDlMultipleMOCompleted );
  4344                 SetDownloadStatus( EHttpProgContentFileMovedAndDestFNChanged, EHttpDlMultipleMOCompleted );
  4305                 }
  4345                 }
  4306            else
  4346            else
  4307                 {
  4347                 {
  4308                 SetDownloadStatus( EHttpProgContentFileMoved, EHttpDlMultipleMOCompleted );
  4348                 SetDownloadStatus( EHttpProgContentFileMoved, EHttpDlMultipleMOCompleted );
  4309                 }
  4349                 }
  4310            CleanupStack::PopAndDestroy( name );
  4350            CleanupStack::PopAndDestroy( name );          
  4311 
  4351            
  4312             }
  4352             }
  4313         else
  4353         else            
  4314             {
  4354             {
  4315             TriggerEvent( EHttpDlCompleted, EHttpProgNone );
  4355             TriggerEvent( EHttpDlCompleted, EHttpProgNone );
  4316             SetDownloadStatus( EHttpProgNone, EHttpDlMultipleMOCompleted );
  4356             SetDownloadStatus( EHttpProgNone, EHttpDlMultipleMOCompleted );
  4317             }
  4357             }
  4318        }
  4358        }
  4321 
  4361 
  4322     Cancel();
  4362     Cancel();
  4323     Disconnect();
  4363     Disconnect();
  4324 
  4364 
  4325     iStorage->OnComplete();
  4365     iStorage->OnComplete();
  4326 
  4366     
  4327     // this is a special case because transaction don't need to be
  4367     // this is a special case because transaction don't need to be 
  4328     // canceled, only deleted
  4368     // canceled, only deleted
  4329     iContinueDownload = EFalse;
  4369     iContinueDownload = EFalse;
  4330     if( iTransValid )
  4370     if( iTransValid )
  4331         {
  4371         {
  4332         iTrans.Close();
  4372         iTrans.Close();
  4356     User::LeaveIfError( start );
  4396     User::LeaveIfError( start );
  4357     start += aAttribute.Length();
  4397     start += aAttribute.Length();
  4358     TInt end = iMediaType->Des().Mid( start, length-start ).Locate( KSemiColon );
  4398     TInt end = iMediaType->Des().Mid( start, length-start ).Locate( KSemiColon );
  4359     TInt boundaryLength = ( KErrNotFound == end ) ? length - start : end;
  4399     TInt boundaryLength = ( KErrNotFound == end ) ? length - start : end;
  4360     TPtrC8 ptr = iMediaType->Des().Mid( start, boundaryLength );
  4400     TPtrC8 ptr = iMediaType->Des().Mid( start, boundaryLength );
  4361     return ptr;
  4401     return ptr;    
  4362     }
  4402     }
  4363 
  4403 
  4364 // -----------------------------------------------------------------------------
  4404 // -----------------------------------------------------------------------------
  4365 // CHttpDownload::ReInitializeDownload
  4405 // CHttpDownload::ReInitializeDownload
  4366 // ?implementation_description
  4406 // ?implementation_description
  4401 
  4441 
  4402     if( iContinueDownload )
  4442     if( iContinueDownload )
  4403         {
  4443         {
  4404         TriggerEvent( EHttpDlCancelTransaction );
  4444         TriggerEvent( EHttpDlCancelTransaction );
  4405         }
  4445         }
  4406 
  4446         
  4407     iContinueDownload = EFalse;
  4447     iContinueDownload = EFalse;
  4408 
  4448 
  4409     iDlStartedByClient = EFalse;
  4449     iDlStartedByClient = EFalse;
  4410     }
  4450     }
  4411 
  4451 
  4517         default:
  4557         default:
  4518             {
  4558             {
  4519             DMPanic( KErrArgument );
  4559             DMPanic( KErrArgument );
  4520             }
  4560             }
  4521         }
  4561         }
  4522 
  4562         
  4523     TRAP_IGNORE( StoreDownloadInfoL() ); //saving the state
  4563     TRAP_IGNORE( StoreDownloadInfoL() ); //saving the state
  4524 
  4564 
  4525     if( !eventTriggered )
  4565     if( !eventTriggered )
  4526         {
  4566         {
  4527         TriggerEvent( iDlState, iProgState );
  4567         TriggerEvent( iDlState, iProgState );
  4586             case 404:   // Not Found
  4626             case 404:   // Not Found
  4587                 {
  4627                 {
  4588                 OnError( KErrUnknown, EObjectNotFound );
  4628                 OnError( KErrUnknown, EObjectNotFound );
  4589                 }
  4629                 }
  4590                 break;
  4630                 break;
  4591 
  4631                 
  4592             default:
  4632             default:
  4593                 {
  4633                 {
  4594                 SetDownloadStatus( EHttpProgNone,
  4634                 SetDownloadStatus( EHttpProgNone, 
  4595                                    EHttpDlFailed,
  4635                                    EHttpDlFailed, 
  4596                                    EHttpUnhandled,
  4636                                    EHttpUnhandled, 
  4597                                    GLOBAL_HTTP_ERROR( iStatusCode ) );
  4637                                    GLOBAL_HTTP_ERROR( iStatusCode ) );
  4598                 }
  4638                 }
  4599             }
  4639             }
  4600         }
  4640         }
  4601     else
  4641     else
  4710 // ?implementation_description
  4750 // ?implementation_description
  4711 // (other items were commented in a header).
  4751 // (other items were commented in a header).
  4712 // -----------------------------------------------------------------------------
  4752 // -----------------------------------------------------------------------------
  4713 //
  4753 //
  4714 void CHttpDownload::ResponseBodyReceivedL( const TDesC8& aBuf )
  4754 void CHttpDownload::ResponseBodyReceivedL( const TDesC8& aBuf )
  4715     {
  4755     {    
  4716     if( iMultiPart && !iCodDownload )
  4756     if( iMultiPart && !iCodDownload )
  4717         {
  4757         {
  4718         TBool isSupportedMultiPart( EFalse );
  4758         TBool isSupportedMultiPart( EFalse );
  4719         // If it leaves isSupportedMultiPart remains false -> does not supported!
  4759         // If it leaves isSupportedMultiPart remains false -> does not supported!
  4720         TRAP_IGNORE( isSupportedMultiPart = IsMultipartSupportedL( aBuf ) );
  4760         TRAP_IGNORE( isSupportedMultiPart = IsMultipartSupportedL( aBuf ) );
  4721         if( isSupportedMultiPart )
  4761         if( isSupportedMultiPart )
  4722             {
  4762             {
  4723             SetCodFlag( ETrue );
  4763             SetCodFlag( ETrue );
  4724             TriggerEvent( EHttpDlInprogress, EHttpProgSupportedMultiPart );
  4764             TriggerEvent( EHttpDlInprogress, EHttpProgSupportedMultiPart );
  4725             }
  4765             }
  4726         }
  4766         }          
  4727 
  4767       
  4728     TBool ret(ETrue);
  4768     TBool ret(ETrue);
  4729 
  4769     
  4730     if( iStorage->BufferingEnabled() )
  4770     if( iStorage->BufferingEnabled() )
  4731     	{
  4771     	{
  4732     	// Buffering is enabled, just pass on the data
  4772     	// Buffering is enabled, just pass on the data
  4733     	ret = iStorage->WriteOutNextBodyDataL(aBuf);
  4773     	ret = iStorage->WriteOutNextBodyDataL(aBuf);
  4734     	}
  4774     	}
  4735     else
  4775     else
  4736     	{
  4776     	{
  4737     	// Buffering not yet enabled, see how much data we still have to write without buffering
  4777     	// Buffering not yet enabled, see how much data we still have to write without buffering
  4738     	TInt bytesToWrite = aBuf.Length();
  4778     	TInt bytesToWrite = aBuf.Length();
  4739     	TInt downloadedSize = iStorage->DownloadedSize();
  4779     	TInt downloadedSize = iStorage->DownloadedSize();
  4740 
  4780     	
  4741     	if(bytesToWrite + downloadedSize < KMinDataSizeToSend)
  4781     	if(bytesToWrite + downloadedSize < KMinDataSizeToSend)
  4742     		{
  4782     		{
  4743     		// Just dump non-buffered write
  4783     		// Just dump non-buffered write
  4744     		ret = iStorage->WriteOutNextBodyDataL( aBuf );
  4784     		ret = iStorage->WriteOutNextBodyDataL( aBuf );
  4745     		}
  4785     		}
  4746     	else
  4786     	else
  4747     		{
  4787     		{
  4748     		// Necessary to switch to buffered writing
  4788     		// Necessary to switch to buffered writing
  4749 
  4789     		
  4750     		TInt leftPartSize = KMinDataSizeToSend - downloadedSize;
  4790     		TInt leftPartSize = KMinDataSizeToSend - downloadedSize;
  4751     		TInt rightPartSize = bytesToWrite - leftPartSize;
  4791     		TInt rightPartSize = bytesToWrite - leftPartSize;
  4752 
  4792     		
  4753     		TBool ret1 = ETrue;
  4793     		TBool ret1 = ETrue;
  4754     		TBool ret2 = ETrue;
  4794     		TBool ret2 = ETrue;
  4755 
  4795     		
  4756     		if(leftPartSize > 0)
  4796     		if(leftPartSize > 0)
  4757     			{
  4797     			{
  4758     			// Write left side of the block to get alignment matched
  4798     			// Write left side of the block to get alignment matched
  4759     			ret1 = iStorage->WriteOutNextBodyDataL( aBuf.Left(leftPartSize) );
  4799     			ret1 = iStorage->WriteOutNextBodyDataL( aBuf.Left(leftPartSize) );
  4760     			}
  4800     			}
  4761 
  4801     		
  4762     		// Enable buffering
  4802     		// Enable buffering
  4763     		iStorage->EnableBufferingL();
  4803     		iStorage->EnableBufferingL();
  4764 
  4804     		
  4765     		// And push the rest of this data block
  4805     		// And push the rest of this data block
  4766     		if(rightPartSize > 0)
  4806     		if(rightPartSize > 0)
  4767     			{
  4807     			{
  4768     			ret2 = iStorage->WriteOutNextBodyDataL( aBuf.Right(rightPartSize) );
  4808     			ret2 = iStorage->WriteOutNextBodyDataL( aBuf.Right(rightPartSize) );
  4769     			}
  4809     			}
  4770 
  4810     		
  4771     		if(!ret1 || !ret2)
  4811     		if(!ret1 || !ret2)
  4772     			{
  4812     			{
  4773     			ret = EFalse;
  4813     			ret = EFalse;
  4774     			}
  4814     			}
  4775     		}
  4815     		}
  4781         }
  4821         }
  4782 
  4822 
  4783     if( !iContTypeRecognitionAvailSent && (iStorage->DownloadedSize() >= KRespSizeForRecognition) )
  4823     if( !iContTypeRecognitionAvailSent && (iStorage->DownloadedSize() >= KRespSizeForRecognition) )
  4784         {
  4824         {
  4785         TriggerEvent( EHttpDlInprogress, EHttpContTypeRecognitionAvail );
  4825         TriggerEvent( EHttpDlInprogress, EHttpContTypeRecognitionAvail );
  4786         iContTypeRecognitionAvailSent = ETrue;
  4826         iContTypeRecognitionAvailSent = ETrue;        
  4787         }
  4827         }
  4788 
  4828         
  4789     TriggerEvent( EHttpDlInprogress, EHttpProgResponseBodyReceived );
  4829     TriggerEvent( EHttpDlInprogress, EHttpProgResponseBodyReceived );
  4790     }
  4830     }
  4791 
  4831 
  4792 // -----------------------------------------------------------------------------
  4832 // -----------------------------------------------------------------------------
  4793 // CHttpDownload::IsMultipartSupportedL
  4833 // CHttpDownload::IsMultipartSupportedL
  4796 // -----------------------------------------------------------------------------
  4836 // -----------------------------------------------------------------------------
  4797 //
  4837 //
  4798 TBool CHttpDownload::IsMultipartSupportedL( const TDesC8& aBuf )
  4838 TBool CHttpDownload::IsMultipartSupportedL( const TDesC8& aBuf )
  4799     {
  4839     {
  4800     TBool ret( EFalse );
  4840     TBool ret( EFalse );
  4801 
  4841     
  4802     if( !iHeaderOfMultipart )
  4842     if( !iHeaderOfMultipart )
  4803         {
  4843         {
  4804         iHeaderOfMultipart = HBufC8::NewL( KMaxHeaderOfMultipart );
  4844         iHeaderOfMultipart = HBufC8::NewL( KMaxHeaderOfMultipart );
  4805         }
  4845         }
  4806     TInt full_length = iHeaderOfMultipart->Length() + aBuf.Length();
  4846     TInt full_length = iHeaderOfMultipart->Length() + aBuf.Length();
  4811     else
  4851     else
  4812         {
  4852         {
  4813         ret = EFalse;
  4853         ret = EFalse;
  4814         return ret;
  4854         return ret;
  4815         }
  4855         }
  4816 
  4856     
  4817     TInt pos = iHeaderOfMultipart->Des().Find( KContentType() );
  4857     TInt pos = iHeaderOfMultipart->Des().Find( KContentType() );
  4818 
  4858 
  4819     User::LeaveIfError( pos );
  4859     User::LeaveIfError( pos );
  4820 
  4860 
  4821     pos = pos + KContentType().Length();
  4861     pos = pos + KContentType().Length();    
  4822 
  4862 
  4823     TPtrC8 p = iHeaderOfMultipart->Des().Mid( pos );
  4863     TPtrC8 p = iHeaderOfMultipart->Des().Mid( pos );    
  4824     TInt temp = p.Find( KDoubleEOL() );
  4864     TInt temp = p.Find( KDoubleEOL() );
  4825 
  4865     
  4826     TInt posEol = pos + temp;
  4866     TInt posEol = pos + temp;
  4827 
  4867 
  4828     TPtrC8 ptr = iHeaderOfMultipart->Des().Mid( pos, ( posEol - pos ) );
  4868     TPtrC8 ptr = iHeaderOfMultipart->Des().Mid( pos, ( posEol - pos ) );
  4829     if( 0 == ptr.Find( KDdMimeType() ) ||
  4869     if( 0 == ptr.Find( KDdMimeType() ) ||
  4830         0 == ptr.Find( KDd2MimeType() ) ||
  4870         0 == ptr.Find( KDd2MimeType() ) ||
  4831         0 == ptr.Find( KCodMimeType() ))
  4871         0 == ptr.Find( KCodMimeType() ))
  4832         {
  4872         {
  4833         ret = ETrue;
  4873         ret = ETrue;
  4834         delete iHeaderOfMultipart;
  4874         delete iHeaderOfMultipart;
  4835         iHeaderOfMultipart = NULL;
  4875         iHeaderOfMultipart = NULL;
  4836         return ret;
  4876         return ret;            
  4837         }
  4877         }
  4838 
  4878         
  4839     return ret;
  4879     return ret;  
  4840     }
  4880     }
  4841 
  4881 
  4842 // -----------------------------------------------------------------------------
  4882 // -----------------------------------------------------------------------------
  4843 // CHttpDownload::Connect
  4883 // CHttpDownload::Connect
  4844 // ?implementation_description
  4884 // ?implementation_description
  4916 
  4956 
  4917     SetRequestHeaderAddOnL( aStringPool, aHeaders );
  4957     SetRequestHeaderAddOnL( aStringPool, aHeaders );
  4918     SetCredentialsInfoL( aStringPool );
  4958     SetCredentialsInfoL( aStringPool );
  4919 
  4959 
  4920     // Find ETag in response header
  4960     // Find ETag in response header
  4921     RStringF etag = aStringPool.StringF(HTTP::EETag,
  4961     RStringF etag = aStringPool.StringF(HTTP::EETag, 
  4922                                         RHTTPSession::GetTable());
  4962                                         RHTTPSession::GetTable());
  4923     TInt fieldInd = FindHeaderField( iResponseHeaders, etag.DesC() );
  4963     TInt fieldInd = FindHeaderField( iResponseHeaders, etag.DesC() );
  4924     if( fieldInd != KErrNotFound )
  4964     if( fieldInd != KErrNotFound )
  4925         // ETag is known. ETag identifies the content. Set If-Match to see
  4965         // ETag is known. ETag identifies the content. Set If-Match to see
  4926         // that if it's changed, or a redirection goes to another url.
  4966         // that if it's changed, or a redirection goes to another url.
  4927         // Server will respond with 412 on error.
  4967         // Server will respond with 412 on error.
  4928         {
  4968         {
  4929         RStringF ifMatch = aStringPool.StringF(HTTP::EIfMatch,
  4969         RStringF ifMatch = aStringPool.StringF(HTTP::EIfMatch, 
  4930                                         RHTTPSession::GetTable());
  4970                                         RHTTPSession::GetTable());
  4931         aHeaders.RemoveField( ifMatch );
  4971         aHeaders.RemoveField( ifMatch );
  4932         aHeaders.SetRawFieldL( ifMatch,
  4972         aHeaders.SetRawFieldL( ifMatch, 
  4933                                *(*iResponseHeaders)[fieldInd]->FieldRawData(),
  4973                                *(*iResponseHeaders)[fieldInd]->FieldRawData(), 
  4934                                KHttpFieldSeparator );
  4974                                KHttpFieldSeparator );
  4935         CLOG_WRITE8_1( "ETag: %S", (*iResponseHeaders)[fieldInd]->FieldRawData() );
  4975         CLOG_WRITE8_1( "ETag: %S", (*iResponseHeaders)[fieldInd]->FieldRawData() );
  4936         }
  4976         }
  4937 
  4977 
  4938     if( aHeadMethod )
  4978     if( aHeadMethod )
  4953         RStringF field;
  4993         RStringF field;
  4954 
  4994 
  4955         if( iStorage->DownloadedSize() != iStorage->Length() )
  4995         if( iStorage->DownloadedSize() != iStorage->Length() )
  4956             // download from previous point only if the content is unmodified
  4996             // download from previous point only if the content is unmodified
  4957             {
  4997             {
  4958             field = aStringPool.StringF(HTTP::EIfUnmodifiedSince,
  4998             field = aStringPool.StringF(HTTP::EIfUnmodifiedSince, 
  4959                                         RHTTPSession::GetTable());
  4999                                         RHTTPSession::GetTable());
  4960 
  5000 
  4961             SetExpireToFieldL( field, aStringPool, aHeaders );
  5001             SetExpireToFieldL( field, aStringPool, aHeaders );
  4962             }
  5002             }
  4963         }
  5003         }
  5008 // CHttpFilterAuthentication::SetPropertyL
  5048 // CHttpFilterAuthentication::SetPropertyL
  5009 // Set property of the transaction
  5049 // Set property of the transaction
  5010 // -----------------------------------------------------------------------------
  5050 // -----------------------------------------------------------------------------
  5011 //
  5051 //
  5012 void CHttpDownload::SetPropertyL( RStringPool& aStringPool,
  5052 void CHttpDownload::SetPropertyL( RStringPool& aStringPool,
  5013                                   RStringF aPropertyName,
  5053                                   RStringF aPropertyName, 
  5014                                   const TDesC8& aToken )
  5054                                   const TDesC8& aToken )
  5015     {
  5055     {
  5016     RString tokenStr = aStringPool.OpenStringL( aToken );
  5056     RString tokenStr = aStringPool.OpenStringL( aToken );
  5017     THTTPHdrVal tokenVal = tokenStr;
  5057     THTTPHdrVal tokenVal = tokenStr;
  5018     CleanupClosePushL( tokenStr );
  5058     CleanupClosePushL( tokenStr );
  5027 // -----------------------------------------------------------------------------
  5067 // -----------------------------------------------------------------------------
  5028 // CHttpFilterAuthentication::SetPropertyL
  5068 // CHttpFilterAuthentication::SetPropertyL
  5029 // Set property of the transaction
  5069 // Set property of the transaction
  5030 // -----------------------------------------------------------------------------
  5070 // -----------------------------------------------------------------------------
  5031 //
  5071 //
  5032 void CHttpDownload::SetPropertyL( RStringF aPropertyName,
  5072 void CHttpDownload::SetPropertyL( RStringF aPropertyName, 
  5033                                   const TInt aValue )
  5073                                   const TInt aValue )
  5034     {
  5074     {
  5035     THTTPHdrVal tokenVal = aValue;
  5075     THTTPHdrVal tokenVal = aValue;
  5036 
  5076 
  5037     iTrans.PropertySet().RemoveProperty( aPropertyName );
  5077     iTrans.PropertySet().RemoveProperty( aPropertyName );
  5098     {
  5138     {
  5099     LOGGER_ENTERFN( "SetCredentialsInfoL" );
  5139     LOGGER_ENTERFN( "SetCredentialsInfoL" );
  5100 
  5140 
  5101     if( iHttpUsername )
  5141     if( iHttpUsername )
  5102         {
  5142         {
  5103         RStringF username = aStringPool.StringF( HTTP::EUsername,
  5143         RStringF username = aStringPool.StringF( HTTP::EUsername, 
  5104                                                     RHTTPSession::GetTable() );
  5144                                                     RHTTPSession::GetTable() );
  5105 
  5145 
  5106         SetPropertyL( aStringPool, username, *iHttpUsername );
  5146         SetPropertyL( aStringPool, username, *iHttpUsername );
  5107         }
  5147         }
  5108 
  5148 
  5109     if( iHttpPassword )
  5149     if( iHttpPassword )
  5110         {
  5150         {
  5111         RStringF password = aStringPool.StringF( HTTP::EPassword,
  5151         RStringF password = aStringPool.StringF( HTTP::EPassword, 
  5112                                                     RHTTPSession::GetTable() );
  5152                                                     RHTTPSession::GetTable() );
  5113 
  5153 
  5114         SetPropertyL( aStringPool, password, *iHttpPassword );
  5154         SetPropertyL( aStringPool, password, *iHttpPassword );
  5115         }
  5155         }
  5116 
  5156 
  5117     if( iHttpRealm )
  5157     if( iHttpRealm )
  5118         {
  5158         {
  5119         RStringF realm = aStringPool.StringF( HTTP::ERealm,
  5159         RStringF realm = aStringPool.StringF( HTTP::ERealm, 
  5120                                                     RHTTPSession::GetTable() );
  5160                                                     RHTTPSession::GetTable() );
  5121         SetPropertyL( aStringPool, realm, *iHttpRealm );
  5161         SetPropertyL( aStringPool, realm, *iHttpRealm );
  5122         }
  5162         }
  5123 
  5163 
  5124     if( iHttpProxyRealm )
  5164     if( iHttpProxyRealm )
  5125         {
  5165         {
  5126         RStringF proxyRealmStr = aStringPool.StringF(
  5166         RStringF proxyRealmStr = aStringPool.StringF( 
  5127                                         HttpFilterCommonStringsExt::EProxyRealm,
  5167                                         HttpFilterCommonStringsExt::EProxyRealm, 
  5128                                         HttpFilterCommonStringsExt::GetTable() );
  5168                                         HttpFilterCommonStringsExt::GetTable() );
  5129         SetPropertyL( aStringPool, proxyRealmStr, *iHttpProxyRealm );
  5169         SetPropertyL( aStringPool, proxyRealmStr, *iHttpProxyRealm );
  5130         }
  5170         }
  5131 
  5171 
  5132     if( iHttpProxyUsername )
  5172     if( iHttpProxyUsername )
  5133         {
  5173         {
  5134         RStringF proxyUsernameStr = aStringPool.StringF(
  5174         RStringF proxyUsernameStr = aStringPool.StringF( 
  5135                                     HttpFilterCommonStringsExt::EProxyUsername,
  5175                                     HttpFilterCommonStringsExt::EProxyUsername, 
  5136                                     HttpFilterCommonStringsExt::GetTable() );
  5176                                     HttpFilterCommonStringsExt::GetTable() );
  5137         SetPropertyL( aStringPool, proxyUsernameStr, *iHttpProxyUsername );
  5177         SetPropertyL( aStringPool, proxyUsernameStr, *iHttpProxyUsername );
  5138         }
  5178         }
  5139 
  5179 
  5140     if( iHttpProxyPassword )
  5180     if( iHttpProxyPassword )
  5141         {
  5181         {
  5142         RStringF proxyPasswordStr = aStringPool.StringF(
  5182         RStringF proxyPasswordStr = aStringPool.StringF( 
  5143                                         HttpFilterCommonStringsExt::EProxyPassword,
  5183                                         HttpFilterCommonStringsExt::EProxyPassword, 
  5144                                         HttpFilterCommonStringsExt::GetTable() );
  5184                                         HttpFilterCommonStringsExt::GetTable() );
  5145         SetPropertyL( aStringPool, proxyPasswordStr, *iHttpProxyPassword );
  5185         SetPropertyL( aStringPool, proxyPasswordStr, *iHttpProxyPassword );
  5146         }
  5186         }
  5147 
  5187 
  5148     if( iHttpNonce )
  5188     if( iHttpNonce )
  5149         {
  5189         {
  5150         RStringF nonce = aStringPool.StringF( HTTP::ENonce,
  5190         RStringF nonce = aStringPool.StringF( HTTP::ENonce, 
  5151                                                     RHTTPSession::GetTable() );
  5191                                                     RHTTPSession::GetTable() );
  5152 
  5192 
  5153         SetPropertyL( aStringPool, nonce, *iHttpNonce );
  5193         SetPropertyL( aStringPool, nonce, *iHttpNonce );
  5154         }
  5194         }
  5155     }
  5195     }
  5187 // CHttpDownload::SetExpireToFieldL
  5227 // CHttpDownload::SetExpireToFieldL
  5188 // ?implementation_description
  5228 // ?implementation_description
  5189 // (other items were commented in a header).
  5229 // (other items were commented in a header).
  5190 // -----------------------------------------------------------------------------
  5230 // -----------------------------------------------------------------------------
  5191 //
  5231 //
  5192 void CHttpDownload::SetExpireToFieldL( RStringF& aField,
  5232 void CHttpDownload::SetExpireToFieldL( RStringF& aField, 
  5193                                        RStringPool& aStringPool,
  5233                                        RStringPool& aStringPool,
  5194                                        RHTTPHeaders& aHeaders )
  5234                                        RHTTPHeaders& aHeaders )
  5195     {
  5235     {
  5196     LOGGER_ENTERFN( "SetExpireToFieldL" );
  5236     LOGGER_ENTERFN( "SetExpireToFieldL" );
  5197 
  5237 
  5200 
  5240 
  5201     TInt expInd( KErrNotFound );
  5241     TInt expInd( KErrNotFound );
  5202     TInt modInd( KErrNotFound );
  5242     TInt modInd( KErrNotFound );
  5203 
  5243 
  5204     for( TInt i = 0; i < iResponseHeaders->Count(); ++i )
  5244     for( TInt i = 0; i < iResponseHeaders->Count(); ++i )
  5205         // FindHeaderField, because this is double search for fieldnames
  5245         // FindHeaderField, because this is double search for fieldnames 
  5206         {
  5246         {
  5207         if( *(*iResponseHeaders)[i]->FieldName() == expires.DesC() )
  5247         if( *(*iResponseHeaders)[i]->FieldName() == expires.DesC() )
  5208             {
  5248             {
  5209             expInd = i;
  5249             expInd = i;
  5210             continue;
  5250             continue;
  5219     if( expInd != KErrNotFound )
  5259     if( expInd != KErrNotFound )
  5220         {
  5260         {
  5221         CLOG_WRITE8_1( "Expire: %S", (*iResponseHeaders)[expInd]->FieldRawData() );
  5261         CLOG_WRITE8_1( "Expire: %S", (*iResponseHeaders)[expInd]->FieldRawData() );
  5222 
  5262 
  5223         aHeaders.RemoveField( aField );
  5263         aHeaders.RemoveField( aField );
  5224         aHeaders.SetRawFieldL( aField,
  5264         aHeaders.SetRawFieldL( aField, 
  5225                                *(*iResponseHeaders)[expInd]->FieldRawData(),
  5265                                *(*iResponseHeaders)[expInd]->FieldRawData(), 
  5226                                KHttpFieldSeparator );
  5266                                KHttpFieldSeparator );
  5227         }
  5267         }
  5228     else if( modInd != KErrNotFound )
  5268     else if( modInd != KErrNotFound )
  5229         {
  5269         {
  5230         CLOG_WRITE8_1( "LastMod: %S", (*iResponseHeaders)[modInd]->FieldRawData() );
  5270         CLOG_WRITE8_1( "LastMod: %S", (*iResponseHeaders)[modInd]->FieldRawData() );
  5231 
  5271 
  5232         aHeaders.RemoveField( aField );
  5272         aHeaders.RemoveField( aField );
  5233         aHeaders.SetRawFieldL( aField,
  5273         aHeaders.SetRawFieldL( aField, 
  5234                                *(*iResponseHeaders)[modInd]->FieldRawData(),
  5274                                *(*iResponseHeaders)[modInd]->FieldRawData(), 
  5235                                KHttpFieldSeparator );
  5275                                KHttpFieldSeparator );
  5236         }
  5276         }
  5237     }
  5277     }
  5238 
  5278 
  5239 // -----------------------------------------------------------------------------
  5279 // -----------------------------------------------------------------------------
  5246     {
  5286     {
  5247     LOGGER_ENTERFN( "ParseRequestedUrlL" );
  5287     LOGGER_ENTERFN( "ParseRequestedUrlL" );
  5248 
  5288 
  5249     __ASSERT_DEBUG( iUrl->Length(), DMPanic( KErrArgument ) );
  5289     __ASSERT_DEBUG( iUrl->Length(), DMPanic( KErrArgument ) );
  5250 
  5290 
  5251     TUriParser8 uri;
  5291     TUriParser8 uri; 
  5252     uri.Parse( *iUrl );
  5292     uri.Parse( *iUrl );
  5253 
  5293 
  5254     TPtrC8 scheme( uri.Extract( EUriScheme ) );
  5294     TPtrC8 scheme( uri.Extract( EUriScheme ) );
  5255 
  5295 
  5256     if( scheme != KHttpScheme &&
  5296     if( scheme != KHttpScheme &&
  5257         scheme != KHttpsScheme )
  5297         scheme != KHttpsScheme )
  5258         // unsupported or no scheme in url.
  5298         // unsupported or no scheme in url.
  5259         // Insert 'http://' to the beginning of it.
  5299         // Insert 'http://' to the beginning of it.
  5260         {
  5300         {
  5261         HBufC8* tempBuf = HBufC8::NewL( KHttpScheme().Length() +
  5301         HBufC8* tempBuf = HBufC8::NewL( KHttpScheme().Length() + 
  5262                                         KSchemeAddon().Length() +
  5302                                         KSchemeAddon().Length() + 
  5263                                         iUrl->Length() );
  5303                                         iUrl->Length() );
  5264 
  5304 
  5265         tempBuf->Des().Append( KHttpScheme );
  5305         tempBuf->Des().Append( KHttpScheme );
  5266         tempBuf->Des().Append( KSchemeAddon );
  5306         tempBuf->Des().Append( KSchemeAddon );
  5267         tempBuf->Des().Append( *iUrl );
  5307         tempBuf->Des().Append( *iUrl );
  5279     url->SetComponentL( uri.Extract( EUriHost ), EUriHost );
  5319     url->SetComponentL( uri.Extract( EUriHost ), EUriHost );
  5280     url->SetComponentL( uri.Extract( EUriPath ), EUriPath );
  5320     url->SetComponentL( uri.Extract( EUriPath ), EUriPath );
  5281     url->SetComponentL( uri.Extract( EUriUserinfo ), EUriUserinfo );
  5321     url->SetComponentL( uri.Extract( EUriUserinfo ), EUriUserinfo );
  5282     url->SetComponentL( uri.Extract( EUriQuery ), EUriQuery );
  5322     url->SetComponentL( uri.Extract( EUriQuery ), EUriQuery );
  5283     url->SetComponentL( uri.Extract( EUriFragment ), EUriFragment );
  5323     url->SetComponentL( uri.Extract( EUriFragment ), EUriFragment );
  5284 
  5324     
  5285     if( uri.IsPresent( EUriPort ) )
  5325     if( uri.IsPresent( EUriPort ) )
  5286         {
  5326         {
  5287         url->SetComponentL( uri.Extract( EUriPort ), EUriPort );
  5327         url->SetComponentL( uri.Extract( EUriPort ), EUriPort );
  5288         }
  5328         }
  5289     else
  5329     else
  5318     LOGGER_ENTERFN( "ParseDownloadNameL" );
  5358     LOGGER_ENTERFN( "ParseDownloadNameL" );
  5319 
  5359 
  5320     // Calculate the download name from the requested URL
  5360     // Calculate the download name from the requested URL
  5321     HBufC8* parsedUrl = EscapeUtils::EscapeDecodeL( *iCurrentUrl );
  5361     HBufC8* parsedUrl = EscapeUtils::EscapeDecodeL( *iCurrentUrl );
  5322     CleanupStack::PushL( parsedUrl );
  5362     CleanupStack::PushL( parsedUrl );
  5323 
  5363     
  5324     TUriParser8 uri;
  5364     TUriParser8 uri; 
  5325     uri.Parse( *parsedUrl );
  5365     uri.Parse( *parsedUrl );
  5326 
  5366 
  5327     TPtrC8 path;
  5367     TPtrC8 path;
  5328 
  5368 
  5329     path.Set( uri.Extract( EUriPath ) );
  5369     path.Set( uri.Extract( EUriPath ) );
  5340 
  5380 
  5341         if( slash == KErrNotFound )
  5381         if( slash == KErrNotFound )
  5342             {
  5382             {
  5343             slash = path.LocateReverse( '\\' );
  5383             slash = path.LocateReverse( '\\' );
  5344             }
  5384             }
  5345 
  5385             
  5346         if( slash != KErrNotFound && slash != path.Length() )
  5386         if( slash != KErrNotFound && slash != path.Length() )
  5347             // from the last slash this is the filename
  5387             // from the last slash this is the filename
  5348             {
  5388             {
  5349             TPtrC8 temp( path.Right( path.Length() - slash - 1 ) );
  5389             TPtrC8 temp( path.Right( path.Length() - slash - 1 ) );
  5350 
  5390 
  5413         CHeaderField* field = CHeaderField::NewL( &fieldNameStr.DesC(), &rawData );
  5453         CHeaderField* field = CHeaderField::NewL( &fieldNameStr.DesC(), &rawData );
  5414         CleanupStack::PushL( field );
  5454         CleanupStack::PushL( field );
  5415 
  5455 
  5416         CLOG_WRITE8_2("%S:%S", &fieldNameStr.DesC(), &rawData);
  5456         CLOG_WRITE8_2("%S:%S", &fieldNameStr.DesC(), &rawData);
  5417         iResponseHeaders->AppendL( field );
  5457         iResponseHeaders->AppendL( field );
  5418 
  5458         
  5419         CleanupStack::Pop( field );
  5459         CleanupStack::Pop( field );
  5420 
  5460         
  5421         CHeaderField* entityField = CHeaderField::NewL( &fieldNameStr.DesC(), &rawData );
  5461         CHeaderField* entityField = CHeaderField::NewL( &fieldNameStr.DesC(), &rawData );
  5422         CleanupStack::PushL( entityField );
  5462         CleanupStack::PushL( entityField );
  5423 
  5463 
  5424         CLOG_WRITE8_2("%S:%S", &fieldNameStr.DesC(), &rawData);
  5464         CLOG_WRITE8_2("%S:%S", &fieldNameStr.DesC(), &rawData);
  5425         iEntityHeaders->AppendL( entityField );
  5465         iEntityHeaders->AppendL( entityField );
  5426 
  5466 
  5427         CleanupStack::Pop( entityField );
  5467         CleanupStack::Pop( entityField );
  5428 
  5468 
  5429         ++it;
  5469         ++it;
  5430         }
  5470         }    
  5431 
  5471 
  5432     ParseContentTypeL( strPool );
  5472     ParseContentTypeL( strPool );
  5433 
  5473     
  5434     ParseContentDispositionL( strPool);
  5474     ParseContentDispositionL( strPool);
  5435     if (!iCodDownload)
  5475     if (!iCodDownload)
  5436         {
  5476         {
  5437 		if (iUseAttachmentFileName || iUseInlineFileName)
  5477 		if (iUseAttachmentFileName || iUseInlineFileName)
  5438 	        {
  5478 	        {
  5456             }
  5496             }
  5457         else
  5497         else
  5458             //This is a partial response as Length is already set so save this new length as partial Length that needs to be Downloaded.
  5498             //This is a partial response as Length is already set so save this new length as partial Length that needs to be Downloaded.
  5459             {
  5499             {
  5460             iStorage->SetPartialContentLength( value );
  5500             iStorage->SetPartialContentLength( value );
  5461             }
  5501             }    
  5462         }
  5502         }
  5463 
  5503         
  5464     CheckRealDRMContentType();
  5504     CheckRealDRMContentType();
  5465     if( !iDrmContentLengthValid )
  5505     if( !iDrmContentLengthValid )
  5466         // Content was original encoded -> we don't know the actual content size.
  5506         // Content was original encoded -> we don't know the actual content size.
  5467         {
  5507         {
  5468         iStorage->SetLength( KDefaultContentLength );
  5508         iStorage->SetLength( KDefaultContentLength );
  5469         }
  5509         }
  5470 
  5510         
  5471 
  5511         
  5472     iMaxAge = 0;
  5512     iMaxAge = 0;
  5473     TInt parts( 0 );
  5513     TInt parts( 0 );
  5474     // this leave is trapped because we can still go on
  5514     // this leave is trapped because we can still go on
  5475     TRAPD( err, parts = headers.FieldPartsL( cacheControl ) );
  5515     TRAPD( err, parts = headers.FieldPartsL( cacheControl ) );
  5476 
  5516 
  5545     {
  5585     {
  5546     LOGGER_ENTERFN( "CheckRealDRMContentType" );
  5586     LOGGER_ENTERFN( "CheckRealDRMContentType" );
  5547 
  5587 
  5548     iPausableDRM = ETrue;
  5588     iPausableDRM = ETrue;
  5549     iDrmContentLengthValid = ETrue;
  5589     iDrmContentLengthValid = ETrue;
  5550 
  5590     
  5551     TInt index = FindHeaderField( iResponseHeaders, KDRMOldContentType );
  5591     TInt index = FindHeaderField( iResponseHeaders, KDRMOldContentType );
  5552     if( index != KErrNotFound )
  5592     if( index != KErrNotFound )
  5553         // this is an old DRM protected content
  5593         // this is an old DRM protected content
  5554         // This transaction cannot be paused.
  5594         // This transaction cannot be paused.
  5555         {
  5595         {
  5557             {
  5597             {
  5558             iPausableDRM = EFalse;
  5598             iPausableDRM = EFalse;
  5559 //            iDrmContentLengthValid = EFalse;
  5599 //            iDrmContentLengthValid = EFalse;
  5560             }
  5600             }
  5561         }
  5601         }
  5562 
  5602         
  5563     UpdatePausable();
  5603     UpdatePausable();
  5564 
  5604             
  5565     CLOG_WRITE_2( "Pausable: [%d], Length: [%d]", iPausableDRM, iDrmContentLengthValid );
  5605     CLOG_WRITE_2( "Pausable: [%d], Length: [%d]", iPausableDRM, iDrmContentLengthValid );
  5566     }
  5606     }
  5567 
  5607 
  5568 // -----------------------------------------------------------------------------
  5608 // -----------------------------------------------------------------------------
  5569 // CHttpDownload::SaveCredentialsL
  5609 // CHttpDownload::SaveCredentialsL
  5573 //
  5613 //
  5574 void CHttpDownload::SaveCredentialsL( RStringPool aStringPool )
  5614 void CHttpDownload::SaveCredentialsL( RStringPool aStringPool )
  5575     {
  5615     {
  5576     LOGGER_ENTERFN( "SaveCredentialsL" );
  5616     LOGGER_ENTERFN( "SaveCredentialsL" );
  5577 
  5617 
  5578     RStringF username = aStringPool.StringF( HTTP::EUsername,
  5618     RStringF username = aStringPool.StringF( HTTP::EUsername, 
  5579                                                 RHTTPSession::GetTable() );
  5619                                                 RHTTPSession::GetTable() );
  5580     RStringF password = aStringPool.StringF( HTTP::EPassword,
  5620     RStringF password = aStringPool.StringF( HTTP::EPassword, 
  5581                                                 RHTTPSession::GetTable() );
  5621                                                 RHTTPSession::GetTable() );
  5582     RStringF realm = aStringPool.StringF( HTTP::ERealm,
  5622     RStringF realm = aStringPool.StringF( HTTP::ERealm, 
  5583                                                 RHTTPSession::GetTable() );
  5623                                                 RHTTPSession::GetTable() );
  5584     RStringF nonce = aStringPool.StringF( HTTP::ENonce,
  5624     RStringF nonce = aStringPool.StringF( HTTP::ENonce, 
  5585                                                 RHTTPSession::GetTable() );
  5625                                                 RHTTPSession::GetTable() );
  5586 
  5626 
  5587     THTTPHdrVal hdrValue;
  5627     THTTPHdrVal hdrValue;
  5588 
  5628 
  5589     // Realm
  5629     // Realm
  5607                 {
  5647                 {
  5608                 ReallocateStringL( iHttpPassword, hdrValue.Str().DesC(), KMaxDefAttrLength );
  5648                 ReallocateStringL( iHttpPassword, hdrValue.Str().DesC(), KMaxDefAttrLength );
  5609                 CLOG_WRITE8_1( "pwd: [%S]", iHttpPassword );
  5649                 CLOG_WRITE8_1( "pwd: [%S]", iHttpPassword );
  5610                 }
  5650                 }
  5611 
  5651 
  5612             if( !iTrans.PropertySet().Property(
  5652             if( !iTrans.PropertySet().Property( 
  5613                                     aStringPool.StringF( HTTP::EBasic,
  5653                                     aStringPool.StringF( HTTP::EBasic, 
  5614                                     RHTTPSession::GetTable() ),
  5654                                     RHTTPSession::GetTable() ), 
  5615                                     hdrValue ) )
  5655                                     hdrValue ) )
  5616                 // this is a digest authentication response
  5656                 // this is a digest authentication response
  5617                 // store nonce value
  5657                 // store nonce value
  5618                 {
  5658                 {
  5619                 if( iTrans.PropertySet().Property( nonce, hdrValue ) )
  5659                 if( iTrans.PropertySet().Property( nonce, hdrValue ) )
  5637     LOGGER_ENTERFN( "RequestContentL" );
  5677     LOGGER_ENTERFN( "RequestContentL" );
  5638 
  5678 
  5639     RStringPool strPool = iConnHandler->Session().StringPool();
  5679     RStringPool strPool = iConnHandler->Session().StringPool();
  5640     RStringF method;
  5680     RStringF method;
  5641     TBool aHead = ETrue;
  5681     TBool aHead = ETrue;
  5642 
  5682     
  5643     if( (iContentType && iContentType->Length()) ||
  5683     if( (iContentType && iContentType->Length()) ||
  5644         iNoContentTypeCheck ||
  5684         iNoContentTypeCheck ||
  5645         iSilentMode )
  5685         iSilentMode )
  5646         // we know the content type -> head is already requested or
  5686         // we know the content type -> head is already requested or
  5647         // every content type is welcome
  5687         // every content type is welcome
  5653         // content type check needed -> first request HEAD
  5693         // content type check needed -> first request HEAD
  5654         {
  5694         {
  5655         method = strPool.StringF( HTTP::EHEAD,RHTTPSession::GetTable() );
  5695         method = strPool.StringF( HTTP::EHEAD,RHTTPSession::GetTable() );
  5656         }
  5696         }
  5657 
  5697 
  5658     TUriParser8 uri;
  5698     TUriParser8 uri; 
  5659     uri.Parse( *iCurrentUrl );
  5699     uri.Parse( *iCurrentUrl );
  5660 
  5700 
  5661     CLOG_WRITE8_1( "Req URL: %S", iCurrentUrl );
  5701     CLOG_WRITE8_1( "Req URL: %S", iCurrentUrl );
  5662     CLOG_WRITE8_1( "Method: %S", &method.DesC() );
  5702     CLOG_WRITE8_1( "Method: %S", &method.DesC() );
  5663 
  5703 
  5715 
  5755 
  5716     THTTPHdrVal hdrValue;
  5756     THTTPHdrVal hdrValue;
  5717     RStringPool strPool = iConnHandler->Session().StringPool();
  5757     RStringPool strPool = iConnHandler->Session().StringPool();
  5718 
  5758 
  5719     // Check authentication scheme
  5759     // Check authentication scheme
  5720     TBool basic = iTrans.PropertySet().Property( strPool.StringF( HTTP::EBasic,
  5760     TBool basic = iTrans.PropertySet().Property( strPool.StringF( HTTP::EBasic, 
  5721                                                  RHTTPSession::GetTable() ),
  5761                                                  RHTTPSession::GetTable() ), 
  5722                                                  hdrValue );
  5762                                                  hdrValue );
  5723 
  5763 
  5724     if( basic )
  5764     if( basic )
  5725         // property is set -> Basic
  5765         // property is set -> Basic
  5726         {
  5766         {
  5763 
  5803 
  5764     // Check authentication scheme
  5804     // Check authentication scheme
  5765     THTTPHdrVal hdrValue;
  5805     THTTPHdrVal hdrValue;
  5766 
  5806 
  5767     RStringPool strPool = iConnHandler->Session().StringPool();
  5807     RStringPool strPool = iConnHandler->Session().StringPool();
  5768     TInt err = iTrans.PropertySet().Property( strPool.StringF( HTTP::EBasic,
  5808     TInt err = iTrans.PropertySet().Property( strPool.StringF( HTTP::EBasic, 
  5769                                                RHTTPSession::GetTable() ),
  5809                                                RHTTPSession::GetTable() ), 
  5770                                                hdrValue );
  5810                                                hdrValue );
  5771 
  5811 
  5772     if( !err )
  5812     if( !err )
  5773         // property is set -> Basic
  5813         // property is set -> Basic
  5774         {
  5814         {
  5863 // CHttpDownload::CreateIndexedNameL
  5903 // CHttpDownload::CreateIndexedNameL
  5864 // ?implementation_description
  5904 // ?implementation_description
  5865 // (other items were commented in a header).
  5905 // (other items were commented in a header).
  5866 // -----------------------------------------------------------------------------
  5906 // -----------------------------------------------------------------------------
  5867 //
  5907 //
  5868 void CHttpDownload::CreateIndexedNameL( HBufC* &aUniqueName,
  5908 void CHttpDownload::CreateIndexedNameL( HBufC* &aUniqueName, 
  5869                                         TDesC& aOrgName,
  5909                                         TDesC& aOrgName, 
  5870                                         TInt& aIndex )
  5910                                         TInt& aIndex )
  5871     {
  5911     {
  5872     LOGGER_ENTERFN( "CreateIndexedNameL" );
  5912     LOGGER_ENTERFN( "CreateIndexedNameL" );
  5873 
  5913 
  5874     TPtrC left;
  5914     TPtrC left;
  5903         {
  5943         {
  5904         left.Set( aOrgName.Left( KDownloadNameMaxSize - indexStr.Length() ));
  5944         left.Set( aOrgName.Left( KDownloadNameMaxSize - indexStr.Length() ));
  5905         }
  5945         }
  5906 
  5946 
  5907     aUniqueName = HBufC::NewL( fullLength );
  5947     aUniqueName = HBufC::NewL( fullLength );
  5908     aUniqueName->Des().Format( _L("%S%S%S"), &left,
  5948     aUniqueName->Des().Format( _L("%S%S%S"), &left, 
  5909                                              &indexStr,
  5949                                              &indexStr,
  5910                                              &extension );
  5950                                              &extension );
  5911 
  5951 
  5912     ++aIndex;
  5952     ++aIndex;
  5913     }
  5953     }
  5916 // CHttpDownload::ContinueDownloadStoreResponseHeaderL
  5956 // CHttpDownload::ContinueDownloadStoreResponseHeaderL
  5917 // ?implementation_description
  5957 // ?implementation_description
  5918 // (other items were commented in a header).
  5958 // (other items were commented in a header).
  5919 // -----------------------------------------------------------------------------
  5959 // -----------------------------------------------------------------------------
  5920 //
  5960 //
  5921 void CHttpDownload::ContinueDownloadStoreResponseHeaderL(
  5961 void CHttpDownload::ContinueDownloadStoreResponseHeaderL( 
  5922                                                 const TDesC8& aResponseHeader )
  5962                                                 const TDesC8& aResponseHeader )
  5923     {
  5963     {
  5924     LOGGER_ENTERFN( "ContinueDownloadStoreResponseHeaderL" );
  5964     LOGGER_ENTERFN( "ContinueDownloadStoreResponseHeaderL" );
  5925 
  5965 
  5926     TInt colon( KErrNotFound );
  5966     TInt colon( KErrNotFound );
  5968 
  6008 
  5969             CLOG_WRITE8_2("%S:%S", &fieldName, &fieldValue);
  6009             CLOG_WRITE8_2("%S:%S", &fieldName, &fieldValue);
  5970             iResponseHeaders->AppendL( newField );
  6010             iResponseHeaders->AppendL( newField );
  5971 
  6011 
  5972             CleanupStack::Pop( newField );
  6012             CleanupStack::Pop( newField );
  5973 
  6013             
  5974             CHeaderField* newentField = CHeaderField::NewL( &fieldName, &fieldValue );
  6014             CHeaderField* newentField = CHeaderField::NewL( &fieldName, &fieldValue );
  5975             CleanupStack::PushL( newentField );
  6015             CleanupStack::PushL( newentField );
  5976 
  6016 
  5977             CLOG_WRITE8_2("%S:%S", &fieldName, &fieldValue);
  6017             CLOG_WRITE8_2("%S:%S", &fieldName, &fieldValue);
  5978             iEntityHeaders->AppendL( newentField );
  6018             iEntityHeaders->AppendL( newentField );
  6048 
  6088 
  6049         ReallocateStringL( iContentType, rawData, KMaxContentTypeLength );
  6089         ReallocateStringL( iContentType, rawData, KMaxContentTypeLength );
  6050         ReallocateStringL( iDDType, rawData, KMaxContentTypeLength );
  6090         ReallocateStringL( iDDType, rawData, KMaxContentTypeLength );
  6051         ReallocateStringL( iMediaType, mediaType, KMaxContentTypeLength );
  6091         ReallocateStringL( iMediaType, mediaType, KMaxContentTypeLength );
  6052         }
  6092         }
  6053 
  6093         
  6054 #ifdef __SYNCML_DM_FOTA
  6094 #ifdef __SYNCML_DM_FOTA        
  6055     if( !iContentType->Des().CompareF( KFotaMimeType ) )
  6095     if( !iContentType->Des().CompareF( KFotaMimeType ) )
  6056         {
  6096         {
  6057         iStorage->SetStorageMethod( CHttpStorage::EStoreFota );
  6097         iStorage->SetStorageMethod( CHttpStorage::EStoreFota );
  6058         }
  6098         }
  6059 #endif
  6099 #endif
  6062         ( 0 == iContentType->Des().Compare( KDdMimeType()  ) ) ||
  6102         ( 0 == iContentType->Des().Compare( KDdMimeType()  ) ) ||
  6063         ( 0 == iContentType->Des().Compare( KDd2MimeType()  ) ) )
  6103         ( 0 == iContentType->Des().Compare( KDd2MimeType()  ) ) )
  6064         {
  6104         {
  6065         SetCodFlag( ETrue );
  6105         SetCodFlag( ETrue );
  6066         }
  6106         }
  6067 
  6107         
  6068     if( 0 == iContentType->Des().Compare( KMultiPartMimeType() ) )
  6108     if( 0 == iContentType->Des().Compare( KMultiPartMimeType() ) )
  6069         {
  6109         {
  6070         iMultiPart = ETrue;
  6110         iMultiPart = ETrue;
  6071         }
  6111         }
  6072 
  6112         
  6073     }
  6113     }
  6074 
  6114 
  6075 // -----------------------------------------------------------------------------
  6115 // -----------------------------------------------------------------------------
  6076 // CHttpDownload::ParseContentDispositionL
  6116 // CHttpDownload::ParseContentDispositionL
  6077 // ?implementation_description
  6117 // ?implementation_description
  6164 		if( isFileNameParam && (0 == iDispositionType->Des().CompareC( KHttpDispositionTypeInline()) ) )
  6204 		if( isFileNameParam && (0 == iDispositionType->Des().CompareC( KHttpDispositionTypeInline()) ) )
  6165 			{
  6205 			{
  6166 			ReallocateStringL( iAttachmentFileName, fileNameParm );
  6206 			ReallocateStringL( iAttachmentFileName, fileNameParm );
  6167 			iUseInlineFileName = ETrue;
  6207 			iUseInlineFileName = ETrue;
  6168 			}
  6208 			}
  6169         }
  6209         }                        
  6170     }
  6210     }
  6171 
  6211 
  6172 // -----------------------------------------------------------------------------
  6212 // -----------------------------------------------------------------------------
  6173 // CHttpDownload::TriggerEvent
  6213 // CHttpDownload::TriggerEvent
  6174 // ?implementation_description
  6214 // ?implementation_description
  6225 
  6265 
  6226     if( !iPausableDRM )
  6266     if( !iPausableDRM )
  6227         {
  6267         {
  6228         pausable = EFalse;
  6268         pausable = EFalse;
  6229         }
  6269         }
  6230 
  6270         
  6231     if( iMethod == EMethodPOST )
  6271     if( iMethod == EMethodPOST )
  6232         {
  6272         {
  6233         pausable = EFalse;
  6273         pausable = EFalse;
  6234         }
  6274         }
  6235 
  6275 
  6236     if( pausable != iPausable )
  6276     if( pausable != iPausable )
  6237         {
  6277         {
  6238         if( !iCodDownload )
  6278         if( !iCodDownload )	
  6239             {
  6279             {
  6240         	iPausable = pausable;
  6280         	iPausable = pausable;
  6241 
  6281         	
  6242         	// inform client about change
  6282         	// inform client about change
  6243             TriggerEvent( iPausable ? EHttpDlPausable : EHttpDlNonPausable );
  6283             TriggerEvent( iPausable ? EHttpDlPausable : EHttpDlNonPausable );
  6244 
  6284 
  6245             TRAP_IGNORE( StoreDownloadInfoL() );
  6285             TRAP_IGNORE( StoreDownloadInfoL() );
  6246             }
  6286             }
  6333 // CHttpDownload::CheckAttribMaxLengthL
  6373 // CHttpDownload::CheckAttribMaxLengthL
  6334 // ?implementation_description
  6374 // ?implementation_description
  6335 // (other items were commented in a header).
  6375 // (other items were commented in a header).
  6336 // -----------------------------------------------------------------------------
  6376 // -----------------------------------------------------------------------------
  6337 //
  6377 //
  6338 void CHttpDownload::CheckAttribMaxLengthL( THttpDownloadAttrib aAttribute,
  6378 void CHttpDownload::CheckAttribMaxLengthL( THttpDownloadAttrib aAttribute, 
  6339 	                                       const TDesC16& aValue )
  6379 	                                       const TDesC16& aValue )
  6340     {
  6380     {
  6341     for( TInt i = 0; KStringAttribMaxLengths[i][0]; ++i )
  6381     for( TInt i = 0; KStringAttribMaxLengths[i][0]; ++i )
  6342         {
  6382         {
  6343         if( aAttribute == KStringAttribMaxLengths[i][0] )
  6383         if( aAttribute == KStringAttribMaxLengths[i][0] )
  6344             {
  6384             {
  6345             if( aValue.Length() > KStringAttribMaxLengths[i][1] )
  6385             if( aValue.Length() > KStringAttribMaxLengths[i][1] )
  6346                 {
  6386                 {
  6347                 CLOG_WRITE_2( "Overflow length: %d, max-length: %d", aValue.Length(),
  6387                 CLOG_WRITE_2( "Overflow length: %d, max-length: %d", aValue.Length(), 
  6348                                                     KStringAttribMaxLengths[i][1] );
  6388                                                     KStringAttribMaxLengths[i][1] );
  6349                 User::Leave( KErrOverflow );
  6389                 User::Leave( KErrOverflow );
  6350                 }
  6390                 }
  6351             }
  6391             }
  6352         }
  6392         }
  6356 // CHttpDownload::CheckAttribMaxLengthL
  6396 // CHttpDownload::CheckAttribMaxLengthL
  6357 // ?implementation_description
  6397 // ?implementation_description
  6358 // (other items were commented in a header).
  6398 // (other items were commented in a header).
  6359 // -----------------------------------------------------------------------------
  6399 // -----------------------------------------------------------------------------
  6360 //
  6400 //
  6361 void CHttpDownload::CheckAttribMaxLengthL( THttpDownloadAttrib aAttribute,
  6401 void CHttpDownload::CheckAttribMaxLengthL( THttpDownloadAttrib aAttribute, 
  6362 	                                       const TDesC8& aValue )
  6402 	                                       const TDesC8& aValue )
  6363     {
  6403     {
  6364     for( TInt i = 0; KStringAttribMaxLengths[i][0]; ++i )
  6404     for( TInt i = 0; KStringAttribMaxLengths[i][0]; ++i )
  6365         {
  6405         {
  6366         if( aAttribute == KStringAttribMaxLengths[i][0] )
  6406         if( aAttribute == KStringAttribMaxLengths[i][0] )
  6367             {
  6407             {
  6368             if( aValue.Length() > KStringAttribMaxLengths[i][1] )
  6408             if( aValue.Length() > KStringAttribMaxLengths[i][1] )
  6369                 {
  6409                 {
  6370                 CLOG_WRITE_2( "Overflow length: %d, max-length: %d", aValue.Length(),
  6410                 CLOG_WRITE_2( "Overflow length: %d, max-length: %d", aValue.Length(), 
  6371                                                     KStringAttribMaxLengths[i][1] );
  6411                                                     KStringAttribMaxLengths[i][1] );
  6372                 User::Leave( KErrOverflow );
  6412                 User::Leave( KErrOverflow );
  6373                 }
  6413                 }
  6374             }
  6414             }
  6375         }
  6415         }
  6468 
  6508 
  6469         // Find out if this is a native request header field, or not.
  6509         // Find out if this is a native request header field, or not.
  6470         // If not, fieldInd is KErrNotFound
  6510         // If not, fieldInd is KErrNotFound
  6471         for( TInt i = 0; KRequestHeaderConvTable[i][0]; ++i )
  6511         for( TInt i = 0; KRequestHeaderConvTable[i][0]; ++i )
  6472             {
  6512             {
  6473             RStringF fieldNameStr = strPool.StringF( KRequestHeaderConvTable[i][1],
  6513             RStringF fieldNameStr = strPool.StringF( KRequestHeaderConvTable[i][1], 
  6474                                                      RHTTPSession::GetTable() );
  6514                                                      RHTTPSession::GetTable() );
  6475 
  6515 
  6476             if( !fieldName.CompareF( fieldNameStr.DesC() ) )
  6516             if( !fieldName.CompareF( fieldNameStr.DesC() ) )
  6477                 // this is a native header field name
  6517                 // this is a native header field name
  6478                 {
  6518                 {
  6493 
  6533 
  6494 // -----------------------------------------------------------------------------
  6534 // -----------------------------------------------------------------------------
  6495 // CHttpDownload::LoadHeadersL
  6535 // CHttpDownload::LoadHeadersL
  6496 // -----------------------------------------------------------------------------
  6536 // -----------------------------------------------------------------------------
  6497 //
  6537 //
  6498 void CHttpDownload::LoadHeadersL( RFile& aFile,
  6538 void CHttpDownload::LoadHeadersL( RFile& aFile, 
  6499                                   CArrayPtrFlat<CHeaderField>* aHeaders )
  6539                                   CArrayPtrFlat<CHeaderField>* aHeaders )
  6500     {
  6540     {
  6501     TInt headers;
  6541     TInt headers;
  6502     READ_INT_L( aFile, headers );
  6542     READ_INT_L( aFile, headers );
  6503 
  6543 
  6519             }
  6559             }
  6520         else
  6560         else
  6521             {
  6561             {
  6522             CLOG_WRITE8( "Empty field" );
  6562             CLOG_WRITE8( "Empty field" );
  6523             }
  6563             }
  6524 */
  6564 */    
  6525         CleanupStack::Pop( field );
  6565         CleanupStack::Pop( field );
  6526         }
  6566         }
  6527     }
  6567     }
  6528 
  6568 
  6529 // -----------------------------------------------------------------------------
  6569 // -----------------------------------------------------------------------------
  6559     TInt headers = aHeaders->Count();
  6599     TInt headers = aHeaders->Count();
  6560     CLOG_WRITE_1("Headers: %d", headers);
  6600     CLOG_WRITE_1("Headers: %d", headers);
  6561 
  6601 
  6562     HBufC8* fieldName = NULL;
  6602     HBufC8* fieldName = NULL;
  6563     HBufC8* fieldRawData = NULL;
  6603     HBufC8* fieldRawData = NULL;
  6564 
  6604     
  6565     TInt size  = 0;
  6605     TInt size  = 0;
  6566 
  6606 
  6567     for( TInt i = 0; i < headers; ++i )
  6607     for( TInt i = 0; i < headers; ++i )
  6568         {
  6608         {
  6569         fieldName = (*aHeaders)[i]->FieldName();
  6609         fieldName = (*aHeaders)[i]->FieldName();
  6570         fieldRawData = (*aHeaders)[i]->FieldRawData();
  6610         fieldRawData = (*aHeaders)[i]->FieldRawData();
  6571 
  6611         
  6572         size = size + fieldName->Size() +  fieldRawData->Size();
  6612         size = size + fieldName->Size() +  fieldRawData->Size();
  6573 
  6613         
  6574         CLOG_WRITE8_1( "Size = %d:", size );
  6614         CLOG_WRITE8_1( "Size = %d:", size );
  6575         }
  6615         }
  6576 
  6616 
  6577     return size;
  6617     return size;
  6578 
  6618     
  6579     }
  6619     }
  6580 
  6620     
  6581 
  6621     
  6582 // -----------------------------------------------------------------------------
  6622 // -----------------------------------------------------------------------------
  6583 // CHttpDownload::AddHeaderL
  6623 // CHttpDownload::AddHeaderL
  6584 // -----------------------------------------------------------------------------
  6624 // -----------------------------------------------------------------------------
  6585 //
  6625 //
  6586 void CHttpDownload::AddHeaderL( THttpDownloadAttrib aAttribute,
  6626 void CHttpDownload::AddHeaderL( THttpDownloadAttrib aAttribute, 
  6587 								const TDesC8& aValue,
  6627 								const TDesC8& aValue,
  6588                                 const TInt aConversionTable[][2],
  6628                                 const TInt aConversionTable[][2],
  6589                                 CArrayPtrFlat<CHeaderField>* aHeaders )
  6629                                 CArrayPtrFlat<CHeaderField>* aHeaders )
  6590     {
  6630     {
  6591     TInt index( KErrNotFound );
  6631     TInt index( KErrNotFound );
  6592 
  6632 
  6593     // search for if this field is already in the
  6633     // search for if this field is already in the 
  6594     for( index = 0; aConversionTable[index][0]; ++index )
  6634     for( index = 0; aConversionTable[index][0]; ++index )
  6595         {
  6635         {
  6596         if( aConversionTable[index][0] == aAttribute )
  6636         if( aConversionTable[index][0] == aAttribute )
  6597             {
  6637             {
  6598             break;
  6638             break;
  6600         }
  6640         }
  6601 
  6641 
  6602     __ASSERT_DEBUG( index != KErrNotFound, DMPanic( KErrCorrupt ) );
  6642     __ASSERT_DEBUG( index != KErrNotFound, DMPanic( KErrCorrupt ) );
  6603 
  6643 
  6604     RStringPool strPool = iClAppInstance->ConnHandler()->Session().StringPool();
  6644     RStringPool strPool = iClAppInstance->ConnHandler()->Session().StringPool();
  6605     RStringF fieldName = strPool.StringF( aConversionTable[index][1],
  6645     RStringF fieldName = strPool.StringF( aConversionTable[index][1], 
  6606                                           RHTTPSession::GetTable() );
  6646                                           RHTTPSession::GetTable() );
  6607     CleanupClosePushL( fieldName );
  6647     CleanupClosePushL( fieldName );
  6608 
  6648 
  6609     // make a copy of the raw data
  6649     // make a copy of the raw data
  6610     HBufC8* value = HBufC8::NewLC( aValue.Length() );
  6650     HBufC8* value = HBufC8::NewLC( aValue.Length() );
  6617 
  6657 
  6618     aHeaders->AppendL( newField );
  6658     aHeaders->AppendL( newField );
  6619 
  6659 
  6620     CleanupStack::Pop( 2 ); // newField, fieldName
  6660     CleanupStack::Pop( 2 ); // newField, fieldName
  6621     }
  6661     }
  6622 
  6662     
  6623 // -----------------------------------------------------------------------------
  6663 // -----------------------------------------------------------------------------
  6624 // CHttpDownload::RedirectedPermanentlyL
  6664 // CHttpDownload::RedirectedPermanentlyL
  6625 // -----------------------------------------------------------------------------
  6665 // -----------------------------------------------------------------------------
  6626 //
  6666 //
  6627 void CHttpDownload::RedirectedPermanentlyL( const TDesC8& aNewUrl )
  6667 void CHttpDownload::RedirectedPermanentlyL( const TDesC8& aNewUrl )
  6633         ReallocateStringL( iRedirUrl, aNewUrl, KMaxUrlLength );
  6673         ReallocateStringL( iRedirUrl, aNewUrl, KMaxUrlLength );
  6634         ReallocateStringL( iCurrentUrl, *iRedirUrl, KMaxUrlLength );
  6674         ReallocateStringL( iCurrentUrl, *iRedirUrl, KMaxUrlLength );
  6635         }
  6675         }
  6636     else
  6676     else
  6637         // there has already been a temporary redirection
  6677         // there has already been a temporary redirection
  6638         // this permanent is not used on next submitted request
  6678         // this permanent is not used on next submitted request 
  6639         {
  6679         {
  6640         ReallocateStringL( iCurrentUrl, aNewUrl, KMaxUrlLength );
  6680         ReallocateStringL( iCurrentUrl, aNewUrl, KMaxUrlLength );
  6641         }
  6681         }
  6642     ParseDownloadNameL();
  6682     ParseDownloadNameL();
  6643     StoreDownloadInfoL();   // to store new url
  6683     StoreDownloadInfoL();   // to store new url
  6657     ParseDownloadNameL();
  6697     ParseDownloadNameL();
  6658     StoreDownloadInfoL();   // to store iRedirect
  6698     StoreDownloadInfoL();   // to store iRedirect
  6659 
  6699 
  6660     TriggerEvent( EHttpDlInprogress, EHttpProgRedirectedTemporarily );
  6700     TriggerEvent( EHttpDlInprogress, EHttpProgRedirectedTemporarily );
  6661     }
  6701     }
  6662 
  6702     
  6663 // -----------------------------------------------------------------------------
  6703 // -----------------------------------------------------------------------------
  6664 // CHttpDownload::FixDownloadNameL
  6704 // CHttpDownload::FixDownloadNameL
  6665 // -----------------------------------------------------------------------------
  6705 // -----------------------------------------------------------------------------
  6666 //
  6706 //
  6667 void CHttpDownload::FixDownloadNameL()
  6707 void CHttpDownload::FixDownloadNameL()
  6668     {
  6708     {
  6669     if( !iCodDownload )
  6709     if( !iCodDownload )
  6670         {
  6710         {
  6671         TPtr name( iDlName->Des() );
  6711         TPtr name( iDlName->Des() );
  6672 
  6712         
  6673         for( TInt i = 0; i < name.Length(); ++i )
  6713         for( TInt i = 0; i < name.Length(); ++i )
  6674             {
  6714             {
  6675             TChar currChar = (*iDlName)[i];
  6715             TChar currChar = (*iDlName)[i];
  6676 
  6716             
  6677             if( currChar.IsAlphaDigit() ||
  6717             if( currChar.IsAlphaDigit() ||
  6678                 currChar.IsGraph() ||
  6718                 currChar.IsGraph() || 
  6679                 currChar == 0x20 )  // space
  6719                 currChar == 0x20 )  // space
  6680                 {
  6720                 {
  6681                 continue;
  6721                 continue;
  6682                 }
  6722                 }
  6683             else
  6723             else
  6684                 {
  6724                 {
  6685                 name[i] = KUrlFixChar;
  6725                 name[i] = KUrlFixChar;
  6686                 }
  6726                 }
  6687             }
  6727             }
  6688 
  6728             
  6689         ConvertDownloadNameUniqueL();
  6729         ConvertDownloadNameUniqueL();
  6690         }
  6730         }
  6691     }
  6731     }
  6692 
  6732 
  6693 // -----------------------------------------------------------------------------
  6733 // -----------------------------------------------------------------------------
  6696 //
  6736 //
  6697 void CHttpDownload::SetCodFlag( TBool aValue )
  6737 void CHttpDownload::SetCodFlag( TBool aValue )
  6698     {
  6738     {
  6699     if( aValue && iCodDownload )
  6739     if( aValue && iCodDownload )
  6700         {
  6740         {
  6701         // this case we will not overwrite
  6741         // this case we will not overwrite 
  6702         // the value of iCodDownload. iCodDownload might be > 1
  6742         // the value of iCodDownload. iCodDownload might be > 1
  6703         return;
  6743         return;
  6704         }
  6744         }
  6705     iCodDownload = aValue;
  6745     iCodDownload = aValue;
  6706     }
  6746     }
  6742     TInt drive( EDriveC );
  6782     TInt drive( EDriveC );
  6743     TBool criticalSpace( EFalse );
  6783     TBool criticalSpace( EFalse );
  6744     TBool needToUpdatePath( ETrue );
  6784     TBool needToUpdatePath( ETrue );
  6745 
  6785 
  6746     CLOG_WRITE_1( " entering fileName: %S", fileName );
  6786     CLOG_WRITE_1( " entering fileName: %S", fileName );
       
  6787 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
  6788     CDownloadPathHandler* downloadPathPlugin = NULL;
       
  6789     downloadPathPlugin = GetDownloadPathPluginInstanceL();
       
  6790     if( downloadPathPlugin )
       
  6791        {
       
  6792         CleanupStack::PushL( downloadPathPlugin );
       
  6793        }
       
  6794 #endif
  6747 #ifdef RD_MULTIPLE_DRIVE
  6795 #ifdef RD_MULTIPLE_DRIVE
  6748     HBufC8* drivesDynList = iClientApp->Engine()->QueryDynDriveListLC();
  6796     HBufC8* drivesDynList = iClientApp->Engine()->QueryDynDriveListLC();
  6749     TPtrC8 drives( *drivesDynList );
  6797     TPtrC8 drives( *drivesDynList ); 
  6750 #else
  6798 #else
  6751     TPtrC drives( iClientApp->Engine()->iDriveLettersCenRep );
  6799     TPtrC drives( iClientApp->Engine()->iDriveLettersCenRep );
  6752 #endif
  6800 #endif
  6753     // drive letters are separated by semicolons
  6801     // drive letters are separated by semicolons
  6754     for( TInt i = 0; i < drives.Length() && (err || !criticalSpace); i = i + 2 )
  6802     for( TInt i = 0; i < drives.Length() && (err || !criticalSpace); i = i + 2 )
  6755         {
  6803         {
  6756         if( ( err = fs.CharToDrive( drives[i], drive )) != KErrNone )
  6804         if( ( err = fs.CharToDrive( drives[i], drive )) != KErrNone )
  6757             {
  6805             {
  6758             continue;
  6806             continue;
  6759             }
  6807             }
  6760         if( drive == currentDrive )//if the current path is same as the path in cenrep then no need to update.The diff is because we must have not known size before hand
  6808         if( drive == currentDrive || iStorage->DestFNameSet())//if the current path is same as the path in cenrep then no need to update.The diff is because we must have not known size before hand
  6761             {
  6809             {
       
  6810 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
  6811             if( !downloadPathPlugin )
       
  6812                 {
       
  6813                 needToUpdatePath = EFalse;
       
  6814                 }
       
  6815 #else
  6762             needToUpdatePath = EFalse;
  6816             needToUpdatePath = EFalse;
       
  6817 #endif 
  6763             break;
  6818             break;
  6764             }
  6819             }
  6765         else
  6820         else
  6766             {
  6821             {
  6767             TInt bytesToWrite = downloadedSize;
  6822             TInt bytesToWrite = downloadedSize;
  6768             if (bytesToWrite < 0)
  6823             if (bytesToWrite < 0)
  6769                 bytesToWrite = 0;
  6824                 bytesToWrite = 0;
  6770 
  6825             
  6771             TRAP( err, criticalSpace = !SysUtil::DiskSpaceBelowCriticalLevelL(
  6826             TRAP( err, criticalSpace = !SysUtil::DiskSpaceBelowCriticalLevelL(
  6772                                                              &fs, bytesToWrite, drive ));
  6827                                                              &fs, bytesToWrite, drive ));
  6773             }
  6828             }             
  6774         }
  6829         }
  6775     if( needToUpdatePath )
  6830     if( needToUpdatePath )
  6776         {
  6831         {
  6777         iDlNameChanged = ETrue;
  6832         iDlNameChanged = ETrue;
  6778 #ifdef RD_MULTIPLE_DRIVE
  6833 #ifdef RD_MULTIPLE_DRIVE
  6790             if( lastSlashPos != KErrNotFound )
  6845             if( lastSlashPos != KErrNotFound )
  6791                 {
  6846                 {
  6792                 fileNamePtr.Delete( 0, lastSlashPos );
  6847                 fileNamePtr.Delete( 0, lastSlashPos );
  6793                 }
  6848                 }
  6794             }
  6849             }
  6795 
  6850     
  6796         // Setting RootPath for new Destination file
  6851         // Setting RootPath for new Destination file
  6797         fileNamePtr.Insert( 0, rootPath );
  6852         fileNamePtr.Insert( 0, rootPath );
       
  6853 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
  6854         if( downloadPathPlugin )
       
  6855             {
       
  6856              GetUpdatedPathFromPluginL(downloadPathPlugin,rootPath,fileNamePtr);
       
  6857             }
       
  6858          else 
       
  6859            {
       
  6860            // Setting KDownloadPath
       
  6861            fileNamePtr.Insert( rootPath.Length(), KDownloadPath );
       
  6862            }   
       
  6863 #else
  6798         // Setting KDownloadPath
  6864         // Setting KDownloadPath
  6799         fileNamePtr.Insert( rootPath.Length(), KDownloadPath );
  6865         fileNamePtr.Insert( rootPath.Length(), KDownloadPath );
       
  6866           
       
  6867 #endif
       
  6868         
  6800 #else
  6869 #else
  6801         TChar driveChar;
  6870         TChar driveChar;
  6802         fs.DriveToChar(drive, driveChar);
  6871         fs.DriveToChar(drive, driveChar);
  6803         TBuf<2> buf;
  6872         TBuf<2> buf;
  6804         buf.Append(driveChar);
  6873         buf.Append(driveChar);
  6810             User::Leave( err );
  6879             User::Leave( err );
  6811             }
  6880             }
  6812         }
  6881         }
  6813     CLOG_WRITE_1( " exiting fileName: %S", fileName );
  6882     CLOG_WRITE_1( " exiting fileName: %S", fileName );
  6814 #ifdef RD_MULTIPLE_DRIVE
  6883 #ifdef RD_MULTIPLE_DRIVE
  6815     CleanupStack::PopAndDestroy( drivesDynList );
  6884     CleanupStack::PopAndDestroy( drivesDynList ); 
       
  6885 #endif
       
  6886 
       
  6887 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
  6888     if(downloadPathPlugin)
       
  6889     {
       
  6890      CleanupStack::PopAndDestroy( downloadPathPlugin );
       
  6891     }
  6816 #endif
  6892 #endif
  6817     CleanupStack::PopAndDestroy( &fs );
  6893     CleanupStack::PopAndDestroy( &fs );
  6818     }
  6894     }    
  6819 
  6895 
  6820 // ---------------------------------------------------------
  6896 // ---------------------------------------------------------
  6821 // CHttpDownload::UpdateDCFRepositoryL()
  6897 // CHttpDownload::UpdateDCFRepositoryL()
  6822 // Update saved file to DCFRepository
  6898 // Update saved file to DCFRepository  
  6823 // ---------------------------------------------------------
  6899 // ---------------------------------------------------------
  6824 //
  6900 // 
  6825 void CHttpDownload::UpdateDCFRepositoryL(
  6901 void CHttpDownload::UpdateDCFRepositoryL(
  6826     const TDesC& aFileName )
  6902     const TDesC& aFileName )
  6827     {
  6903     {
  6828     LOGGER_ENTERFN( "UpdateDCFRepositoryL" );
  6904     LOGGER_ENTERFN( "UpdateDCFRepositoryL" );
  6829     CLOG_WRITE_1( " :UpdateDCFRepositoryL() for: %S", &aFileName );
  6905     CLOG_WRITE_1( " :UpdateDCFRepositoryL() for: %S", &aFileName );
  6830     CDcfEntry* dcfEntry = NULL;
  6906     CDcfEntry* dcfEntry = NULL;
  6831     dcfEntry = CDcfEntry::NewL();
  6907     dcfEntry = CDcfEntry::NewL();    
  6832     CleanupStack::PushL( dcfEntry );
  6908     CleanupStack::PushL( dcfEntry );
  6833 
  6909     
  6834     CDcfRep* dcfRep = NULL;
  6910     CDcfRep* dcfRep = NULL;
  6835     dcfRep = CDcfRep::NewL();
  6911     dcfRep = CDcfRep::NewL();
  6836     CleanupStack::PushL( dcfRep );
  6912     CleanupStack::PushL( dcfRep );
  6837 
  6913 
  6838     dcfEntry->SetLocationL( aFileName, 0 );
  6914     dcfEntry->SetLocationL( aFileName, 0 );    
  6839     CLOG_WRITE(" : SetLocationL OK");
  6915     CLOG_WRITE(" : SetLocationL OK");
  6840     dcfRep->UpdateL( dcfEntry );
  6916     dcfRep->UpdateL( dcfEntry );
  6841     CLOG_WRITE(" :UpdateL OK");
  6917     CLOG_WRITE(" :UpdateL OK");
  6842     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
  6918     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
  6843     }
  6919     }                 
  6844 
  6920 
  6845 // -----------------------------------------------------------------------------
  6921 // -----------------------------------------------------------------------------
  6846 // CHttpDownload::MoveInDeleteL
  6922 // CHttpDownload::MoveInDeleteL
  6847 // ?implementation_description
  6923 // ?implementation_description
  6848 // (other items were commented in a header).
  6924 // (other items were commented in a header).
  6858 		{
  6934 		{
  6859 		TRAP_IGNORE(MoveDownloadedMediaObjectSyncL(mediaObjectIndex));
  6935 		TRAP_IGNORE(MoveDownloadedMediaObjectSyncL(mediaObjectIndex));
  6860 		TPtrC filenamePtr = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6936 		TPtrC filenamePtr = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6861 		if(filenamePtr.Length())
  6937 		if(filenamePtr.Length())
  6862     		{
  6938     		{
  6863     		TRAP_IGNORE(NotifyMediaGalleryL( filenamePtr ));
  6939     		TRAP_IGNORE(NotifyMediaGalleryL( filenamePtr ));    
  6864     		}
  6940     		}
  6865 		}
  6941 		}
  6866 	return err;
  6942 	return err;
  6867 	}
  6943 	}
  6868 
  6944 
  6877     {
  6953     {
  6878     LOGGER_ENTERFN( "MoveDownloadedMediaObjectsL" );
  6954     LOGGER_ENTERFN( "MoveDownloadedMediaObjectsL" );
  6879 
  6955 
  6880     if( iDlState != EHttpDlMultipleMOCompleted && !iMoDownloadCompleted )
  6956     if( iDlState != EHttpDlMultipleMOCompleted && !iMoDownloadCompleted )
  6881         {
  6957         {
  6882         iStorage->SetProgressiveMode( EFalse );
  6958         iStorage->SetProgressiveMode( EFalse );	
  6883         TriggerEvent( iDlState, EHttpDlProgNonProgressive);
  6959         TriggerEvent( iDlState, EHttpDlProgNonProgressive);
  6884         return;//Move will be Done by COD as MO Completed has not happened
  6960         return;//Move will be Done by COD as MO Completed has not happened
  6885         }
  6961         }
  6886 
  6962 
  6887     //__ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
  6963     //__ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
  6888     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
  6964     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
  6889 
  6965 
  6890 #if 0
  6966 #if 0
  6891 
  6967     
  6892 #else
  6968 #else
  6893 
  6969 
  6894     HBufC* filename = HBufC::NewLC(KMaxFileName);
  6970     HBufC* filename = HBufC::NewLC(KMaxFileName);
  6895 	TPtr filenamePtr1 = filename->Des();
  6971 	TPtr filenamePtr1 = filename->Des();
  6896 
  6972 	
  6897     RFs &fs = iClientApp->Engine()->Fs();
  6973     RFs &fs = iClientApp->Engine()->Fs();
  6898 	if(!iFileMan)
  6974 	if(!iFileMan)
  6899 		{
  6975 		{
  6900 		iFileMan = CFileMan::NewL(fs);
  6976 		iFileMan = CFileMan::NewL(fs);	
  6901 		}
  6977 		}
  6902 
  6978 
  6903     TPtrC filenamePtr2 = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6979     TPtrC filenamePtr2 = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6904     if(!filenamePtr2.Length())
  6980     if(!filenamePtr2.Length())
  6905     	{
  6981     	{
  6906         CleanupStack::PopAndDestroy(filename);
  6982         CleanupStack::PopAndDestroy(filename);
  6907         return;
  6983         return;
  6908     	}
  6984     	}
  6909 
  6985     
  6910     TInt firstSlashPos = filenamePtr2.Locate( '\\' );
  6986     TInt firstSlashPos = filenamePtr2.Locate( '\\' );
  6911 
  6987 
  6912     if(firstSlashPos < 0)
  6988     if(firstSlashPos < 0)
  6913 	    {
  6989 	    {
  6914 	    CleanupStack::PopAndDestroy(filename);
  6990 	    CleanupStack::PopAndDestroy(filename);
  6915 	    return;
  6991 	    return;	
  6916 	    }
  6992 	    }
  6917   	TPtrC dlName = filenamePtr2.Left(firstSlashPos);
  6993   	TPtrC dlName = filenamePtr2.Left(firstSlashPos);
  6918 
  6994 
  6919     TInt drive;
  6995     TInt drive;
  6920 
  6996     
  6921     User::LeaveIfError( fs.CharToDrive( dlName[0], drive ));
  6997     User::LeaveIfError( fs.CharToDrive( dlName[0], drive ));
  6922 
  6998 
  6923 
  6999 
  6924     // Getting RootPath for selected Drive
  7000     // Getting RootPath for selected Drive
  6925     TFileName rootPath;
  7001     TFileName rootPath;
  6932     filenamePtr1.Append(_L("\\"));
  7008     filenamePtr1.Append(_L("\\"));
  6933 
  7009 
  6934     TInt error = fs.MkDirAll(filenamePtr1);
  7010     TInt error = fs.MkDirAll(filenamePtr1);
  6935     if (error!=KErrNone && error!=KErrAlreadyExists)
  7011     if (error!=KErrNone && error!=KErrAlreadyExists)
  6936        {
  7012        {
  6937         User::Leave(error);
  7013         User::Leave(error);   
  6938        }
  7014        }
  6939 	if( mediaObjectIndex == iActivePlayedDownload )
  7015 	if( mediaObjectIndex == iActivePlayedDownload )
  6940 	    {
  7016 	    {	    
  6941 
  7017 	           	
  6942 	    iFname = ((*iCodDlData)[mediaObjectIndex])->TempFilename();
  7018 	    iFname = ((*iCodDlData)[mediaObjectIndex])->TempFilename();
  6943 	    }
  7019 	    }
  6944 
  7020 
  6945 	else
  7021 	else
  6946 		{
  7022 		{	    
  6947 
  7023 	    
  6948 	    iFname = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  7024 	    iFname = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6949 		}
  7025 		}   
  6950     // Find a unique name to avoid any conflict.
  7026     // Find a unique name to avoid any conflict.
  6951     // Here iFname has full path of current location of file
  7027     // Here iFname has full path of current location of file
  6952     // and filename has destination path.
  7028     // and filename has destination path.
  6953     FindUniqueDestinationFileNameL( iFname, filename );
  7029     FindUniqueDestinationFileNameL( iFname, filename );
  6954 
  7030     
  6955     filenamePtr1 = filename->Des();
  7031     filenamePtr1 = filename->Des();
  6956 
  7032 
  6957     User::LeaveIfError( iFileMan->Move( iFname, filenamePtr1, CFileMan::EOverWrite, iStatus ) );
  7033     User::LeaveIfError( iFileMan->Move( iFname, filenamePtr1, CFileMan::EOverWrite, iStatus ) );
  6958     // waiting for move to complete
  7034     // waiting for move to complete
  6959     SetActive();
  7035     SetActive();
  6960     iFname = filenamePtr1;
  7036     iFname = filenamePtr1;
  6961     ((*iCodDlData)[mediaObjectIndex])->SetDestFilenameL(filenamePtr1);
  7037     ((*iCodDlData)[mediaObjectIndex])->SetDestFilenameL(filenamePtr1);
  6962 
  7038 
  6963     CleanupStack::PopAndDestroy(filename);
  7039     CleanupStack::PopAndDestroy(filename);
  6964 
  7040  
  6965 #endif
  7041 #endif
  6966     }
  7042     }
  6967 
  7043 
  6968 // -----------------------------------------------------------------------------
  7044 // -----------------------------------------------------------------------------
  6969 // CHttpDownload::MoveDownloadedMediaObjectSyncL
  7045 // CHttpDownload::MoveDownloadedMediaObjectSyncL
  6982 
  7058 
  6983     //__ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
  7059     //__ASSERT_DEBUG( !IsActive(), DMPanic( KErrInUse ) );
  6984     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
  7060     //__ASSERT_DEBUG( !iFileMan, DMPanic( KErrInUse ) );
  6985 
  7061 
  6986 
  7062 
  6987 
  7063     
  6988 	RFs &fs = iClientApp->Engine()->Fs();
  7064 	RFs &fs = iClientApp->Engine()->Fs();
  6989 	if(!iFileMan)
  7065 	if(!iFileMan)
  6990 		{
  7066 		{
  6991 		iFileMan = CFileMan::NewL(fs);
  7067 		iFileMan = CFileMan::NewL(fs);	
  6992 		}
  7068 		}
  6993 
  7069 
  6994     HBufC* filename = HBufC::NewLC(KMaxFileName);
  7070     HBufC* filename = HBufC::NewLC(KMaxFileName);
  6995     TPtr filenamePtr = filename->Des();
  7071     TPtr filenamePtr = filename->Des();
  6996 
  7072     
  6997     TPtrC fileNamePtr = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  7073     TPtrC fileNamePtr = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  6998     TInt firstSlashPos = fileNamePtr.Locate( '\\' );
  7074     TInt firstSlashPos = fileNamePtr.Locate( '\\' );
  6999     if(firstSlashPos < 0)
  7075     if(firstSlashPos < 0)
  7000 	    {
  7076 	    {
  7001 	    CleanupStack::PopAndDestroy(filename);
  7077 	    CleanupStack::PopAndDestroy(filename);
  7002 	    return;
  7078 	    return;	
  7003 	    }
  7079 	    }
  7004   	TPtrC dlName = fileNamePtr.Left(firstSlashPos);
  7080   	TPtrC dlName = fileNamePtr.Left(firstSlashPos);
  7005     TInt drive;
  7081     TInt drive;
  7006 
  7082     
  7007     User::LeaveIfError( fs.CharToDrive( dlName[0], drive ));
  7083     User::LeaveIfError( fs.CharToDrive( dlName[0], drive ));
  7008 
  7084 
  7009 
  7085 
  7010     // Getting RootPath for selected Drive
  7086     // Getting RootPath for selected Drive
  7011     TFileName rootPath;
  7087     TFileName rootPath;
  7014     // Setting KDownloadPath
  7090     // Setting KDownloadPath
  7015     rootPath.Append( KDownloadPath );
  7091     rootPath.Append( KDownloadPath );
  7016 
  7092 
  7017     filenamePtr.Copy(rootPath);
  7093     filenamePtr.Copy(rootPath);
  7018     filenamePtr.Append(_L("\\"));
  7094     filenamePtr.Append(_L("\\"));
  7019 
  7095     
  7020     TInt error = fs.MkDirAll(filenamePtr);
  7096     TInt error = fs.MkDirAll(filenamePtr);
  7021     if (error!=KErrNone && error!=KErrAlreadyExists)
  7097     if (error!=KErrNone && error!=KErrAlreadyExists)
  7022        {
  7098        {
  7023         User::Leave(error);
  7099         User::Leave(error);   
  7024        }
  7100        }
  7025     iFname = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  7101     iFname = ((*iCodDlData)[mediaObjectIndex])->DestFilename();
  7026 
  7102     
  7027     // Find a unique name to avoid any conflict.
  7103     // Find a unique name to avoid any conflict.
  7028     // Here iFname has full path of current location of file
  7104     // Here iFname has full path of current location of file
  7029     // and filename has destination path.
  7105     // and filename has destination path.
  7030     FindUniqueDestinationFileNameL( iFname, filename );
  7106     FindUniqueDestinationFileNameL( iFname, filename );
  7031 
  7107     
  7032     filenamePtr = filename->Des();
  7108     filenamePtr = filename->Des();
  7033 
  7109 
  7034     TInt err = iFileMan->Move(iFname, filenamePtr, CFileMan::EOverWrite);
  7110     TInt err = iFileMan->Move(iFname, filenamePtr, CFileMan::EOverWrite);
  7035     if(err != KErrNone)
  7111     if(err != KErrNone)
  7036     	{
  7112     	{
  7038     	}
  7114     	}
  7039     iFname = filenamePtr;
  7115     iFname = filenamePtr;
  7040     ((*iCodDlData)[mediaObjectIndex])->SetDestFilenameL(filenamePtr);
  7116     ((*iCodDlData)[mediaObjectIndex])->SetDestFilenameL(filenamePtr);
  7041 
  7117 
  7042     CleanupStack::PopAndDestroy(filename);
  7118     CleanupStack::PopAndDestroy(filename);
  7043 
  7119  
  7044 
  7120 
  7045     }
  7121     }
  7046 
  7122 
  7047 // -----------------------------------------------------------------------------
  7123 // -----------------------------------------------------------------------------
  7048 // CHttpDownload::FindUniqueDestinationFileNameL
  7124 // CHttpDownload::FindUniqueDestinationFileNameL
  7080         destPath->Des().Append( *fileExtention );
  7156         destPath->Des().Append( *fileExtention );
  7081 
  7157 
  7082         CleanupStack::PopAndDestroy( fileName );
  7158         CleanupStack::PopAndDestroy( fileName );
  7083         CleanupStack::PopAndDestroy( fileExtention );
  7159         CleanupStack::PopAndDestroy( fileExtention );
  7084     }
  7160     }
  7085 
  7161     
  7086 
  7162  
  7087 // ---------------------------------------------------------
  7163 // ---------------------------------------------------------
  7088 // CHttpDownload::NotifyMediaGalleryL()
  7164 // CHttpDownload::NotifyMediaGalleryL()
  7089 // Notify media gallery about the new file.
  7165 // Notify media gallery about the new file.
  7090 // ---------------------------------------------------------
  7166 // ---------------------------------------------------------
  7091 //
  7167 // 
  7092 void CHttpDownload::NotifyMediaGalleryL( const TDesC& aFileName )
  7168 void CHttpDownload::NotifyMediaGalleryL( const TDesC& aFileName )
  7093     {
  7169     {
  7094 
  7170 
  7095 	LOGGER_ENTERFN( "CHttpDownload::NotifyMediaGalleryL" );
  7171 	LOGGER_ENTERFN( "CHttpDownload::NotifyMediaGalleryL" );
  7096     CLOG_WRITE_1(" notifying Gallery and DcfReposory about move for: %S",&aFileName);
  7172     CLOG_WRITE_1(" notifying Gallery and DcfReposory about move for: %S",&aFileName);
  7097 
  7173 
  7098 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
  7174 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF    
  7099 
  7175     
  7100     //
  7176     //
  7101     // Notify Media Gallery about new media file
  7177     // Notify Media Gallery about new media file
  7102     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL(
  7178     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL(
  7103         iClientApp->Engine()->Fs() );
  7179         iClientApp->Engine()->Fs() );
  7104     CleanupStack::PushL( mgFileManager );
  7180     CleanupStack::PushL( mgFileManager );
  7109     else
  7185     else
  7110         {
  7186         {
  7111         TRAP_IGNORE( mgFileManager->UpdateL() );
  7187         TRAP_IGNORE( mgFileManager->UpdateL() );
  7112         }
  7188         }
  7113     CleanupStack::PopAndDestroy( mgFileManager );
  7189     CleanupStack::PopAndDestroy( mgFileManager );
  7114 
  7190     
  7115 #endif
  7191 #endif    
  7116     //
  7192     //
  7117     // Notify DCF repository
  7193     // Notify DCF repository
  7118     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
  7194     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
  7119 	}
  7195 	}
  7120 // -----------------------------------------------------------------------------
  7196 // -----------------------------------------------------------------------------
  7154 
  7230 
  7155         }while( bFound );
  7231         }while( bFound );
  7156 
  7232 
  7157     CleanupStack::PopAndDestroy(&rFs);
  7233     CleanupStack::PopAndDestroy(&rFs);
  7158     CleanupStack::PopAndDestroy(fullNameTemp);
  7234     CleanupStack::PopAndDestroy(fullNameTemp);
  7159 
  7235     
  7160     // This is the unique name that we were looking for.
  7236     // This is the unique name that we were looking for.
  7161     CleanupStack::PopAndDestroy(fileName);
  7237     CleanupStack::PopAndDestroy(fileName);
  7162     fileName = uniqueName;
  7238     fileName = uniqueName;
  7163     CleanupStack::PushL(fileName);
  7239     CleanupStack::PushL(fileName);
  7164     }
  7240     }
  7165 
  7241 
       
  7242 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
  7243 
       
  7244 // -----------------------------------------------------------------------------
       
  7245 // CHttpDownload::GetDownloadPathPluginInstanceL
       
  7246 // -----------------------------------------------------------------------------
       
  7247 //
       
  7248 CDownloadPathHandler* CHttpDownload::GetDownloadPathPluginInstanceL()
       
  7249     {
       
  7250     CDownloadPathHandler* downloadPathPlugin = NULL;
       
  7251     if ( iContentType )
       
  7252         {
       
  7253         TRAPD( kErr, downloadPathPlugin = CDownloadPathHandler::NewL( *iContentType ) );
       
  7254         if( kErr != KErrNone )
       
  7255             {
       
  7256             downloadPathPlugin = NULL;
       
  7257             }
       
  7258         }
       
  7259     return downloadPathPlugin;    
       
  7260 
       
  7261     }
       
  7262 
       
  7263 // -----------------------------------------------------------------------------
       
  7264 // CHttpDownload::GetUpdatedPathFromPluginL
       
  7265 // -----------------------------------------------------------------------------
       
  7266 //
       
  7267 void CHttpDownload::GetUpdatedPathFromPluginL(CDownloadPathHandler* downloadPathPlugin,TFileName& rootPath, TPtr& fileNamePtr)
       
  7268     {
       
  7269     HBufC16* locFileName ;
       
  7270     locFileName = iStorage->LocalFilename();
       
  7271     
       
  7272     // Gets the updated path for the music content from Plugin
       
  7273     TRAPD( kErr, downloadPathPlugin->GetUpdatedPathL( *locFileName, fileNamePtr ) );
       
  7274     if( kErr != KErrNone )
       
  7275         {
       
  7276         // Setting to KDownloadPath
       
  7277         fileNamePtr.Insert( rootPath.Length(), KDownloadPath );
       
  7278         }
       
  7279     }
       
  7280 #endif
  7166 //  End of File
  7281 //  End of File