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