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