commondrm/drmutility/src/DrmUtilityDmgrWrapper.cpp
branchRCL_3
changeset 27 1481bf457703
parent 26 1221b68b8a5f
equal deleted inserted replaced
26:1221b68b8a5f 27:1481bf457703
     1 /*
     1 /*
     2  * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3 * All rights reserved.
     4  * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8 *
     9  * Initial Contributors:
     9 * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11  *
    11 *
    12  * Contributors:
    12 * Contributors:
    13  *
    13 *
    14  * Description:  Dynamically loadable wrapper for Download manager
    14 * Description:  Dynamically loadable wrapper for Download manager
    15  *
    15 *
    16  */
    16 */
       
    17 
    17 #include <centralrepository.h>
    18 #include <centralrepository.h>
    18 #include <cdblen.h>
    19 #include <cdblen.h>
    19 #include <cmconnectionmethod.h>
    20 #include <cmconnectionmethod.h>
    20 #include <cmdestination.h>
    21 #include <cmdestination.h>
    21 #include <cmconnectionmethoddef.h>
    22 #include <cmconnectionmethoddef.h>
    22 #include <cmmanager.h>
    23 #include <cmmanager.h>
       
    24 
       
    25 #ifdef __SERIES60_NATIVE_BROWSER
       
    26 #include <browseruisdkcrkeys.h>
       
    27 #endif
       
    28 
    23 #ifdef RD_MULTIPLE_DRIVE
    29 #ifdef RD_MULTIPLE_DRIVE
    24 #include <driveinfo.h>
    30 #include <driveinfo.h>
    25 #endif
    31 #endif
       
    32 
    26 #include <StringLoader.h>
    33 #include <StringLoader.h>
    27 #include <data_caging_path_literals.hrh>
    34 #include <data_caging_path_literals.hrh>
    28 
       
    29 #include <es_enum.h> // tconnectioninfo
       
    30 #include <es_enum_partner.h> // TConnectionInfoV2
       
    31 #include <es_sock.h> // rconnection rsocket
       
    32 #include <AknProgressDialog.h> // avkon classes
       
    33 #include <eikprogi.h>
       
    34 
    35 
    35 #include <ConeResLoader.h>
    36 #include <ConeResLoader.h>
    36 #include <apparc.h>
    37 #include <apparc.h>
    37 #include <DrmUtilityDmgrWrapper.rsg>
    38 #include <DrmUtilityDmgrWrapper.rsg>
    38 
    39 
    39 #include <RoapEng.h>
    40 #include "RoapEng.h"
    40 #include <RoapDef.h>
       
    41 #include <RoapObserver.h>
       
    42 
       
    43 // including files related to qt changes
       
    44 #include <qstring.h>
       
    45 #include <downloadmanager.h>
       
    46 #include <download.h>
       
    47 #include <dmcommon.h>
       
    48 #include <downloadevent.h>
       
    49 
       
    50 #include "RoapSyncWrapper.h"
    41 #include "RoapSyncWrapper.h"
    51 #include "RoapDef.h"
    42 #include "RoapDef.h"
       
    43 
    52 #include "DrmUtilityDmgrWrapper.h"
    44 #include "DrmUtilityDmgrWrapper.h"
    53 #include "DrmUtilityDmgrWrapperLogger.h"
    45 #include "DrmUtilityDmgrWrapperLogger.h"
    54 #include "drmutilityconnection.h"
    46 
    55 #include "buffercontainers.h" //CnameContainer etc.
    47 // DEBUG macros
    56 #include "cleanupresetanddestroy.h"
    48 #ifdef _DEBUG
    57 #include "buffercontainers.h"
    49 #define DRMDEBUGLIT( a, b ) \
    58 #include "qdrmutilitydmgreventhandler.h"
    50 _LIT( a , b )
    59 
    51 #define DRMDEBUG( a ) \
    60 #include "OstTraceDefinitions.h"
    52 RDebug::Print( a )
    61 #ifdef OST_TRACE_COMPILER_IN_USE
    53 #define DRMDEBUG2( a, b ) \
    62 #include "DrmUtilityDmgrWrapperTraces.h"
    54 RDebug::Print( a, b )
       
    55 #else
       
    56 #define DRMDEBUGLIT( a, b )
       
    57 #define DRMDEBUG( a )
       
    58 #define DRMDEBUG2( a, b )
       
    59 #endif
       
    60 
       
    61 // CONSTANTS
       
    62 #ifndef __SERIES60_NATIVE_BROWSER
       
    63 const TUid KCRUidBrowser = {0x10008D39};
       
    64 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E;
       
    65 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
    63 #endif
    66 #endif
    64 
    67 
    65 #ifndef RD_MULTIPLE_DRIVE
    68 #ifndef RD_MULTIPLE_DRIVE
    66 _LIT( KDriveZ, "z:" );
    69 _LIT( KDriveZ, "z:" );
    67 _LIT( KDrmUtilityTriggerFilePath, "d:\\" );
    70 _LIT( KDrmUtilityTriggerFilePath, "d:\\" );
    68 #else
    71 #else
    69 _LIT( KRomDriveFormatter, "%c:" );
    72 _LIT( KRomDriveFormatter, "%c:" );
    70 _LIT( KKDrmUtilityTriggerFilePathFormatter, "%c:\\" );
    73 _LIT( KKDrmUtilityTriggerFilePathFormatter, "%c:\\" );
    71 #endif
    74 #endif
       
    75 
    72 _LIT( KCDrmUtilityDmgrWrapperResFileName,"DrmUtilityDmgrWrapper.rsc" );
    76 _LIT( KCDrmUtilityDmgrWrapperResFileName,"DrmUtilityDmgrWrapper.rsc" );
    73 const TInt KProgressInfoFinalValue(200);
    77 const TInt KProgressInfoFinalValue( 200 );
    74 const TInt KProgressInfoIncrementSmall(5);
    78 const TInt KProgressInfoIncrementSmall( 5 );
    75 const TInt KProgressInfoIncrementMedium(10);
    79 const TInt KProgressInfoIncrementMedium( 10 );
    76 const TInt KProgressInfoIncrementLarge(30);
    80 const TInt KProgressInfoIncrementLarge( 30 );
    77 
       
    78 using namespace WRT;
       
    79 
    81 
    80 // ======== LOCAL FUNCTIONS ========
    82 // ======== LOCAL FUNCTIONS ========
    81 
    83 
    82 // ---------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------
    83 // ClearIfNotRoapTemporaryError
    85 // DeleteHttpDowload
    84 // ---------------------------------------------------------------------------
    86 // ---------------------------------------------------------------------------
    85 //
    87 //
    86 void ClearIfNotRoapTemporaryError(TInt aError, HBufC8*& aBuffer)
    88 LOCAL_C void DeleteHttpDowload( TAny* aDownload )
    87     {
    89     {
    88     // ROAP ERROR CODES
    90     reinterpret_cast< RHttpDownload* >( aDownload )->Delete();
    89     switch (aError)
    91     }
    90         {
    92 
    91         case KErrRoapGeneral:
    93 // ---------------------------------------------------------------------------
    92         case KErrRoapServer:
    94 // IapIdOfDefaultSnapL
    93         case KErrRoapDomainFull:
    95 // for trapping purposes only
    94         case KErrRoapNotRegistered:
    96 // ---------------------------------------------------------------------------
    95             break;
    97 //
    96         default:
    98 LOCAL_C TUint32 IapIdOfDefaultSnapL(
    97             delete aBuffer;
    99     RCmManager& aCmManager,
    98             aBuffer = NULL;
   100     const TUint32 aDefaultSnap )
    99             break;
   101     {
   100         }
   102     RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) );
   101     }
   103     CleanupClosePushL( dest );
   102 
   104     TUint32 iapIdOfDest( 0 );
   103 
   105 
   104 // ---------------------------------------------------------------------------
   106     if ( dest.ConnectionMethodCount() <= 0 )
   105 // Calls the appropriate member function of the object during object cleanup
   107         {
   106 // ---------------------------------------------------------------------------
   108         User::Leave( KErrNotFound );
   107 //
   109         }
   108 template<class _Ty, class _Tf>	class mem_auto_ptr 
   110 
   109 	{
   111     RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
   110 	public:
   112     CleanupClosePushL( cMeth );
   111 		explicit mem_auto_ptr(_Ty _P = 0, _Tf _F = 0) 
   113 
   112 			: _Owns(_P != 0), _Ptr(_P), _Fn(_F) 
   114     iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId );
   113 				{}
   115     CleanupStack::PopAndDestroy( &cMeth );
   114 		
   116     CleanupStack::PopAndDestroy( &dest );
   115 		mem_auto_ptr(const mem_auto_ptr<_Ty,_Tf>& _Y) 
   117     return iapIdOfDest;
   116 			: _Owns(_Y._Owns), _Ptr(_Y.release()), _Fn(_Y.function()) 
   118     }
   117 				{}
   119 
   118 		
       
   119 		mem_auto_ptr<_Ty,_Tf>& operator=(const mem_auto_ptr<_Ty,_Tf>& _Y) 
       
   120 			{
       
   121 			if (this != &_Y)
       
   122 				{
       
   123 				_Fn = _Y.function();
       
   124 				if (_Ptr != _Y.get())
       
   125 					{
       
   126 					if (_Owns)
       
   127 						delete _Ptr;
       
   128 					_Owns = _Y._Owns; 
       
   129 					}
       
   130 				else if (_Y._Owns)
       
   131 					_Owns = true;
       
   132 				_Ptr = _Y.release(); 
       
   133 				}
       
   134 			return (*this); 
       
   135 			}
       
   136 		
       
   137 		~mem_auto_ptr()
       
   138 			{
       
   139 			if (_Owns)
       
   140 				{
       
   141 				(_Ptr->*_Fn)();
       
   142 				}
       
   143 			}
       
   144 		
       
   145 		_Ty& operator*() const 
       
   146 			{
       
   147 			return (*get()); 
       
   148 			}
       
   149 		
       
   150 		_Ty *operator->() const 
       
   151 			{
       
   152 			return (get()); 
       
   153 			}
       
   154 		
       
   155 		_Ty *get() const 
       
   156 			{
       
   157 			return (_Ptr); 
       
   158 			}
       
   159 		
       
   160 		_Ty *release() const 
       
   161 			{
       
   162 			((mem_auto_ptr<_Ty,_Tf> *)this)->_Owns = false;
       
   163 			return (_Ptr); 
       
   164 			}
       
   165 		
       
   166 		_Tf *function() const
       
   167 			{
       
   168 			return (_Fn);
       
   169 			}
       
   170 	private:
       
   171 		bool _Owns;
       
   172 		_Ty _Ptr;
       
   173 		_Tf _Fn;
       
   174 	};
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // UpdateBufferL
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 template<typename bufType, typename descType>
       
   182 LOCAL_C void UpdateBufferL(bufType*& aTargetBuf, const descType& aSourceBuf)
       
   183     {
       
   184     if (aTargetBuf)
       
   185         {
       
   186         delete aTargetBuf;
       
   187         aTargetBuf = NULL;
       
   188         }
       
   189     if (aSourceBuf.Length())
       
   190         {
       
   191         aTargetBuf = aSourceBuf.AllocL();
       
   192         }
       
   193     }
       
   194 
   120 
   195 // ======== MEMBER FUNCTIONS ========
   121 // ======== MEMBER FUNCTIONS ========
   196 
   122 
   197 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   198 // CDrmUtilityDmgrWrapper::CDrmUtilityDmgrWrapper
   124 // CDrmUtilityDmgrWrapper::CDrmUtilityDmgrWrapper
   199 // ---------------------------------------------------------------------------
   125 // ---------------------------------------------------------------------------
   200 //
   126 //
   201 CDrmUtilityDmgrWrapper::CDrmUtilityDmgrWrapper() :
   127 CDrmUtilityDmgrWrapper::CDrmUtilityDmgrWrapper() :
   202             CActive(CActive::EPriorityStandard),
   128     iUseCoeEnv( EFalse )
   203             iUseCoeEnv(EFalse), iIapId(0), iState(EInit)
   129     {
   204     {
       
   205     CActiveScheduler::Add(this);
       
   206     }
   130     }
   207 
   131 
   208 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   209 // CDrmUtilityDmgrWrapper::ConstructL
   133 // CDrmUtilityDmgrWrapper::ConstructL
   210 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   211 //
   135 //
   212 void CDrmUtilityDmgrWrapper::ConstructL()
   136 void CDrmUtilityDmgrWrapper::ConstructL()
   213     {
   137     {
   214     CLOG_WRITE( "DMgrWrapper::ConstructL" );
   138     CLOG_WRITE( "DMgrWrapper::ConstructL" );
   215     const TInt KDrmUtilityDmgrWrapperUid = 0x102830FE;
   139     const TInt KDrmUtilityDmgrWrapperUid = 0x102830FE;
   216     iConnection = DRM::CDrmUtilityConnection::NewL(ETrue);
   140     iDlMgr.ConnectL( TUid::Uid(KDrmUtilityDmgrWrapperUid), *this, EFalse );
   217     
       
   218     try
       
   219 	    {
       
   220 	    QString drmUtilityDmgrWrapperUid(QString::number(KDrmUtilityDmgrWrapperUid));
       
   221 	    iDlMgr = q_check_ptr(new DownloadManager(drmUtilityDmgrWrapperUid));
       
   222 	    }
       
   223 	catch(const std::exception& exception)
       
   224 		{
       
   225 		qt_symbian_exception2LeaveL(exception);
       
   226 		}
       
   227     iProgressInfo = NULL;
   141     iProgressInfo = NULL;
   228     iProgressNoteDialog = NULL;
   142     iProgressNoteDialog = NULL;
   229     iDialogDismissed = ETrue;
   143     iDialogDismissed = ETrue;
   230     User::LeaveIfError(iFs.Connect());
   144     }
   231     User::LeaveIfError(iFs.ShareProtected());
   145 
   232     }
   146 
   233 
   147 
   234 // ---------------------------------------------------------------------------
   148 // ---------------------------------------------------------------------------
   235 // CDrmUtilityDmgrWrapper::NewL
   149 // CDrmUtilityDmgrWrapper::NewL
   236 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
   237 //
   151 //
   238 CDrmUtilityDmgrWrapper* CDrmUtilityDmgrWrapper::NewL()
   152 CDrmUtilityDmgrWrapper* CDrmUtilityDmgrWrapper::NewL()
   239     {
   153     {
   240     CLOG_WRITE( "DMgrWrapper::NewL" );
   154     CLOG_WRITE( "DMgrWrapper::NewL" );
   241     CDrmUtilityDmgrWrapper* self(CDrmUtilityDmgrWrapper::NewLC());
   155     CDrmUtilityDmgrWrapper* self( CDrmUtilityDmgrWrapper::NewLC() );
   242     CleanupStack::Pop(self);
   156     CleanupStack::Pop( self );
   243     return self;
   157     return self;
   244     }
   158     }
   245 
   159 
       
   160 
   246 // ---------------------------------------------------------------------------
   161 // ---------------------------------------------------------------------------
   247 // CDrmUtilityDmgrWrapper::NewLC
   162 // CDrmUtilityDmgrWrapper::NewLC
   248 // ---------------------------------------------------------------------------
   163 // ---------------------------------------------------------------------------
   249 //
   164 //
   250 CDrmUtilityDmgrWrapper* CDrmUtilityDmgrWrapper::NewLC()
   165 CDrmUtilityDmgrWrapper* CDrmUtilityDmgrWrapper::NewLC()
   251     {
   166     {
   252     CLOG_WRITE( "DMgrWrapper::NewLC" );
   167     CLOG_WRITE( "DMgrWrapper::NewLC" );
   253     CDrmUtilityDmgrWrapper* self(new (ELeave) CDrmUtilityDmgrWrapper());
   168     CDrmUtilityDmgrWrapper* self( new( ELeave ) CDrmUtilityDmgrWrapper() );
   254     CleanupStack::PushL(self);
   169     CleanupStack::PushL( self );
   255     self->ConstructL();
   170     self->ConstructL();
   256     return self;
   171     return self;
   257     }
   172     }
   258 
   173 
       
   174 
   259 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   260 // CDrmUtilityDmgrWrapper::~CDrmUtilityDmgrWrapper
   176 // CDrmUtilityDmgrWrapper::~CDrmUtilityDmgrWrapper
   261 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   262 //
   178 //
   263 CDrmUtilityDmgrWrapper::~CDrmUtilityDmgrWrapper()
   179 CDrmUtilityDmgrWrapper::~CDrmUtilityDmgrWrapper()
   264     {
   180     {
   265     CLOG_WRITE( "DMgrWrapper destructor" );
   181     CLOG_WRITE( "DMgrWrapper destructor" );
   266     Cancel();
   182     if ( iProgressNoteDialog )
   267     if (iProgressNoteDialog)
   183        {
   268         {
   184        // deletes the dialog
   269         // deletes the dialog
   185        TRAPD( err, iProgressNoteDialog->ProcessFinishedL() );
   270         TRAPD( err, iProgressNoteDialog->ProcessFinishedL() );
   186        if ( err )
   271         if (err)
   187            {
   272             {
   188            delete iProgressNoteDialog;
   273             delete iProgressNoteDialog;
   189            }
   274             }
   190        iProgressNoteDialog = NULL;
   275         iProgressNoteDialog = NULL;
   191        }
   276         }
       
   277     delete iErrorUrl;
   192     delete iErrorUrl;
   278 
       
   279     delete iPostResponseUrl;
   193     delete iPostResponseUrl;
   280     delete iConnection;
   194 
   281 
   195 #ifdef _DEBUG
   282     delete iTriggerUrl;
   196 
   283     delete iTriggerBuf;
   197     if ( iDlMgr.Handle() )
   284     delete iFileName;
   198         {
   285     delete iRoapEng;
   199         iDlMgr.Close();
   286     iDownload->cancel();
   200         }
   287     delete iDlMgr;
   201 
   288     delete iDrmUtilityDmgrEventHandler;
   202 #else
   289     
   203 
   290     iFs.Close();
   204     iDlMgr.Close();
       
   205 
       
   206 #endif
   291     }
   207     }
   292 
   208 
   293 
   209 
   294 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   295 // CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL
   211 // CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL
   296 // ---------------------------------------------------------------------------
   212 // ---------------------------------------------------------------------------
   297 //
   213 //
   298 void CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL(const HBufC8* aUrl)
   214 void CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL( const HBufC8* aUrl )
   299     {
   215     {
   300     CLOG_WRITE( "DMgrWrapper::DownloadAndHandleRoapTriggerL" );
   216     CLOG_WRITE( "DMgrWrapper::DownloadAndHandleRoapTriggerL" );
   301     iUseCoeEnv = EFalse;
   217     iUseCoeEnv = EFalse;
   302     if (iState != EInit || iWait.IsStarted())
   218     DoDownloadAndHandleRoapTriggerL( aUrl );
   303         {
   219     HandlePostResponseUrlL();
   304         User::Leave(KErrNotReady);
   220     }
   305         }
   221 
   306 
       
   307     UpdateBufferL<HBufC8, TDesC8> (iTriggerUrl, *aUrl);
       
   308     CompleteToState(EInit, KErrNone);
       
   309     iWait.Start();
       
   310     }
       
   311 
   222 
   312 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   313 // CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL
   224 // CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL
   314 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   315 //
   226 //
   316 void CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL(
   227 void CDrmUtilityDmgrWrapper::DownloadAndHandleRoapTriggerL(
   317         const HBufC8* aUrl, CCoeEnv& aCoeEnv)
   228     const HBufC8* aUrl, CCoeEnv& aCoeEnv )
   318     {
   229     {
   319     CLOG_WRITE( "DMgrWrapper::DownloadAndHandleRoapTriggerL" );
   230     CLOG_WRITE( "DMgrWrapper::DownloadAndHandleRoapTriggerL" );
   320     iCoeEnv = &aCoeEnv;
   231     iCoeEnv = &aCoeEnv;
   321     iUseCoeEnv = ETrue;
   232     iUseCoeEnv = ETrue;
   322     if (iState != EInit || iWait.IsStarted())
   233     DoDownloadAndHandleRoapTriggerL( aUrl );
   323         {
   234     HandlePostResponseUrlL();
   324         User::Leave(KErrNotReady);
   235     }
   325         }
   236 
   326 
   237 
   327     UpdateBufferL<HBufC8, TDesC8> (iTriggerUrl, *aUrl);
   238 // ---------------------------------------------------------------------------
   328     CompleteToState(EInit, KErrNone);
   239 // CDrmUtilityDmgrWrapper::HandlePostResponseUrlL
   329     iWait.Start();
   240 // ---------------------------------------------------------------------------
   330     }
   241 //
   331 
   242 void CDrmUtilityDmgrWrapper::HandlePostResponseUrlL()
   332 // ---------------------------------------------------------------------------
   243     {
   333 // CDrmUtilityDmgrWrapper::GetErrorUrlL
   244     if ( iPostResponseUrl )
   334 // ---------------------------------------------------------------------------
   245         {
   335 //
   246         DoDownloadAndHandleRoapTriggerL( iPostResponseUrl );
   336 HBufC8* CDrmUtilityDmgrWrapper::GetErrorUrlL()
   247         // prevent infinite post response fetches.
   337     {
   248         delete iPostResponseUrl;
   338     if (iErrorUrl)
   249         iPostResponseUrl = NULL;
   339         {
   250 
   340         return iErrorUrl->AllocL();
   251         // Ensure progress note gets deleted.
   341         }
   252         // It remains open if prUrl initialted ROAP operation has PrUrl
   342     return NULL;
   253         // (unsupported chained metering report)
   343     }
   254         RemoveProgressNoteL();
   344 
   255         }
   345 // ---------------------------------------------------------------------------
   256     }
   346 // CDrmUtilityDmgrWrapper::DoConnectL
   257 
   347 // ---------------------------------------------------------------------------
   258 
   348 //
   259 // ---------------------------------------------------------------------------
   349 void CDrmUtilityDmgrWrapper::DoConnectL(TDownloadState aNextState)
   260 // CDrmUtilityDmgrWrapper::DoDownloadAndHandleRoapTriggerL
   350     {
   261 // ---------------------------------------------------------------------------
   351     iConnection->ConnectL(&iStatus);
   262 //
   352     if (iUseCoeEnv && iProgressInfo)
   263 void CDrmUtilityDmgrWrapper::DoDownloadAndHandleRoapTriggerL(
   353         {
   264     const HBufC8* aUrl )
   354         iProgressInfo->SetAndDraw(0);
   265     {
   355         }
   266     RFs fs;
   356     iState = aNextState;
       
   357     SetActive();
       
   358     }
       
   359 
       
   360 /////
       
   361 // ---------------------------------------------------------------------------
       
   362 // CDrmUtilityDmgrWrapper::DoDownloadRoapTriggerL
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CDrmUtilityDmgrWrapper::DoDownloadRoapTriggerL(TDownloadState aNextState)
       
   366     {
       
   367     // Fetch name of opend connection to be used as part of DMGR
       
   368     // initialisation
       
   369     TUint32 iapId(0);
       
   370     if (iConnection->IsConnected(iapId))
       
   371         {
       
   372     	const QVariant qIapId( static_cast<unsigned long long>(iapId) );
       
   373 		iDlMgr->setAttribute( WRT::ClientName, qIapId );
       
   374         }
       
   375     RFile roapTrigger;
   267     RFile roapTrigger;
   376     CleanupClosePushL(roapTrigger);
   268     HBufC8* triggerBuf( NULL );
   377     DRM::CFileNameContainer* triggerFileName(NULL);
   269     TBool result( EFalse );
   378 
   270     TFileName triggerFileName;
   379     // If no Trigger URL then nothing to download. So finish transaction
   271 
   380     if (!iTriggerUrl || iTriggerUrl->Length() <= 0)
   272     CLOG_WRITE( "DMgrWrapper::DoDownloadAndHandleRoapTriggerL" );
   381         {
   273     User::LeaveIfError( fs.Connect() );
   382         if (iUseCoeEnv && iProgressInfo)
   274     CleanupClosePushL( fs );
   383             {
   275     User::LeaveIfError( fs.ShareProtected() );
   384             // No PrUrl found. Progess is complete.
   276 
   385             iProgressInfo->SetAndDraw(KProgressInfoFinalValue);
   277 #ifndef RD_MULTIPLE_DRIVE
   386             }
   278 
   387         CompleteToState(EComplete, KErrNone);
   279     User::LeaveIfError( roapTrigger.Temp(
   388         return;
   280             fs, KDrmUtilityTriggerFilePath, triggerFileName, EFileWrite ) );
   389         }
   281 
   390 
   282 #else //RD_MULTIPLE_DRIVE
   391     TPtrC8 KNullPtr8(NULL, 0);
   283 
   392     QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length());
   284     TInt driveNumber( -1 );
   393     //uncomment
   285     TChar driveLetter;
   394     Download* download = NULL;//iDlMgr->findDownload( downloadUrl );
   286     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber );
   395     if (download)
   287     fs.DriveToChar( driveNumber, driveLetter );
       
   288 
       
   289     TFileName utilityTriggerFilePath;
       
   290 
       
   291     utilityTriggerFilePath.Format( KKDrmUtilityTriggerFilePathFormatter,
       
   292         (TUint)driveLetter );
       
   293 
       
   294     User::LeaveIfError( roapTrigger.Temp(
       
   295             fs, utilityTriggerFilePath, triggerFileName, EFileWrite ) );
       
   296 
       
   297 #endif
       
   298 
       
   299 
       
   300     TPtrC8 KNullPtr8( NULL, 0 );
       
   301     RHttpDownload* downloadPtr( iDlMgr.FindDownload( *aUrl, KNullPtr8 ) );
       
   302     if ( downloadPtr )
   396         {
   303         {
   397         // Stale download found.
   304         // Stale download found.
   398         // Remove it, and re-create a new download.
   305         // Remove it, and re-create a new download.
   399 		download->cancel();
   306         downloadPtr->Delete();
   400 		download = NULL;
   307         downloadPtr = NULL;
   401         if (iFileName)
   308         }
   402             {
   309 
   403             iFs.Delete(*iFileName);
       
   404             }
       
   405         }
       
   406     triggerFileName=DRM::CFileNameContainer::NewLC();
       
   407     
       
   408 #ifndef RD_MULTIPLE_DRIVE
       
   409 
       
   410     User::LeaveIfError( roapTrigger.Temp(
       
   411                     iFs, KDrmUtilityTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) );
       
   412 
       
   413 #else //RD_MULTIPLE_DRIVE
       
   414     TInt driveNumber(-1);
       
   415     TChar driveLetter;
       
   416     DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRam, driveNumber);
       
   417     iFs.DriveToChar(driveNumber, driveLetter);
       
   418 
       
   419     DRM::CFileNameContainer*
       
   420         utilityTriggerFilePath(DRM::CFileNameContainer::NewLC());
       
   421 
       
   422     utilityTriggerFilePath->iBuffer.Format(
       
   423             KKDrmUtilityTriggerFilePathFormatter, (TUint) driveLetter);
       
   424 
       
   425     User::LeaveIfError(roapTrigger.Temp(iFs, utilityTriggerFilePath->iBuffer,
       
   426             triggerFileName->iBuffer, EFileWrite));
       
   427     CleanupStack::PopAndDestroy( utilityTriggerFilePath );
       
   428     utilityTriggerFilePath=NULL;
       
   429 
       
   430 #endif
       
   431     UpdateBufferL<HBufC, TFileName> (iFileName, triggerFileName->iBuffer);
       
   432     CleanupStack::PopAndDestroy( triggerFileName );
       
   433     triggerFileName=NULL;
       
   434     // create and start download
   310     // create and start download
   435     downloadUrl = ((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length());
   311     RHttpDownload& download = iDlMgr.CreateDownloadL( *aUrl, result );
   436     
   312     // Put download for proper cleanup.
   437     iDownload = iDlMgr->createDownload(downloadUrl);
   313     TCleanupItem item( DeleteHttpDowload, &download );
   438     try
   314     CleanupStack::PushL( item );
   439 		{
   315 
   440 		iDrmUtilityDmgrEventHandler = q_check_ptr(new QDrmUtilityDmgrEventHandler(*this, *iDownload));
   316     CleanupClosePushL( roapTrigger );
   441 		}
   317 
   442     catch(const std::exception& exception)
   318     if ( !iPostResponseUrl )
   443 		{
   319         {
   444 		qt_symbian_exception2LeaveL(exception);
   320         // No post response retieval. Note must be created.
   445 		}
   321         ShowProgressNoteL();
   446     
   322         }
   447     iDownloadSuccess = EFalse;
   323 
   448 	iConnectionError = EFalse;
   324     if ( result )
   449 
   325         {
   450 	try
   326         const TInt KReadBufSize( 512 );
   451 		{
   327         TInt triggerFileSize( 0 );
   452 		RBuf fileName;
   328 
   453 		User::LeaveIfError(fileName.Create(KMaxFileName));
   329         CLOG_WRITE(
   454 		CleanupClosePushL(fileName);
   330             "DMgrWrapper::DoDownloadAndHandleRoapTriggerL: download created" );
   455 		roapTrigger.Name(fileName);
   331         iDownloadSuccess = EFalse;
   456 		const QVariant& roapTriggerValue( QString((QChar*) fileName.Ptr(), fileName.Length()) );
   332         iConnectionError = EFalse;
   457 		CleanupStack::PopAndDestroy(&fileName);
   333 
   458 		iDownload->setAttribute(FileName,roapTriggerValue);
   334         SetDefaultAccessPointL();
   459 		const QVariant& val(ETrue);
   335 
   460 		iDownload->setAttribute(ContentType, val);
   336         User::LeaveIfError( download.SetFileHandleAttribute( roapTrigger ) );
   461 		iDownload->start();
   337         User::LeaveIfError(
   462 		}
   338             download.SetBoolAttribute( EDlAttrNoContentTypeCheck, ETrue ) );
   463 	catch(const std::exception& exception)
   339         User::LeaveIfError( download.Start() );
   464 		{
   340 
   465 		qt_symbian_exception2LeaveL(exception);
   341         // wait until download is finished
   466 		}
   342         iWait.Start();
   467 	// wait until download is finished
   343 
   468 	iState = aNextState;
   344         // Check success of download
   469 	TRequestStatus* status(&iStatus);
   345         CLOG_WRITE(
   470 	*status = KRequestPending;
   346             "DMgrWrapper::DoDownloadAndHandleRoapTriggerL: download finished" );
   471 	SetActive();
   347 
   472         
   348         CleanupStack::Pop( &roapTrigger );
   473     CleanupStack::PopAndDestroy(&roapTrigger);
   349         roapTrigger.Close();
   474     }
   350         if ( !iDownloadSuccess )
   475 // ---------------------------------------------------------------------------
   351             {
   476 // CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL
   352             RemoveProgressNoteL();
   477 // ---------------------------------------------------------------------------
   353             if ( iConnectionError )
   478 //
   354                 {
   479 void CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL(TDownloadState aNextState)
   355                 User::Leave( KErrCouldNotConnect );
   480     {
   356                 }
   481     // Check success of download
   357             else
   482 
   358                 {
   483     // Fetch download created in DoDownloadRoapTriggerL
   359                 User::Leave( KErrGeneral );
   484 	QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length());
   360                 }
   485      
   361             }
   486 	typedef void (Download::*download_cancel_fnptr) ();
   362         User::LeaveIfError( roapTrigger.Open( fs,
   487 	//uncomment
   363                                               triggerFileName,
   488 	Download* dwnld = NULL;//iDlMgr->findDownload( downloadUrl );
   364                                               EFileShareReadersOrWriters ) );
   489 	mem_auto_ptr<Download*, download_cancel_fnptr> downloadPtr(dwnld,&WRT::Download::cancel);
   365         CleanupClosePushL( roapTrigger );
   490     
   366 
   491     // Delete trigger URL so that it is possible to check
   367         // Get filehandle of ROAP trigger
   492     // whether or not meteringResponse has PrUrl.
   368         // Read file to buffer
   493     delete iTriggerUrl;
   369         User::LeaveIfError( roapTrigger.Size( triggerFileSize ) );
   494     iTriggerUrl = NULL;
   370         triggerBuf = HBufC8::NewLC( triggerFileSize );
   495     iStatus = KRequestPending;
   371 
   496     
   372         RBuf8 readBuf;
   497     RFile roapTrigger;
   373         readBuf.CleanupClosePushL();
   498 
   374         readBuf.CreateL( KReadBufSize );
   499     if (!iDownloadSuccess)
   375 
       
   376         User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) );
       
   377         triggerBuf->Des().Copy( readBuf );
       
   378         while ( readBuf.Length() == KReadBufSize )
       
   379             {
       
   380             User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) );
       
   381             triggerBuf->Des().Append( readBuf );
       
   382             }
       
   383 
       
   384         CleanupStack::PopAndDestroy( &readBuf );
       
   385 
       
   386         if ( iUseCoeEnv && iProgressInfo )
       
   387             {
       
   388             iProgressInfo->IncrementAndDraw( KProgressInfoIncrementMedium );
       
   389             }
       
   390 
       
   391         // And let ROAP handle it...
       
   392         CRoapSyncWrapper* roapWrapper( CRoapSyncWrapper::NewL() );
       
   393         CleanupStack::PushL( roapWrapper );
       
   394         TRAPD( err, roapWrapper->HandleTriggerL( *triggerBuf ) );
       
   395         if ( err )
       
   396             {
       
   397             TInt errorType( 0 );
       
   398             TRAPD( err2,
       
   399                 iErrorUrl = roapWrapper->GetErrorUrlL( err, errorType ) );
       
   400             if ( err2 )
       
   401                 {
       
   402                 RemoveProgressNoteL();
       
   403                 delete iErrorUrl;
       
   404                 iErrorUrl = NULL;
       
   405                 User::Leave( err2 );
       
   406                 }
       
   407             else if ( errorType != KErrRoapTemporary )
       
   408                 {
       
   409                 RemoveProgressNoteL();
       
   410                 delete iErrorUrl;
       
   411                 iErrorUrl = NULL;
       
   412                 User::Leave( err );
       
   413                 }
       
   414             else
       
   415                 {
       
   416                 RemoveProgressNoteL();
       
   417                 User::Leave( err );
       
   418                 }
       
   419             }
       
   420         if ( iPostResponseUrl )
       
   421             {
       
   422             delete iPostResponseUrl;
       
   423             iPostResponseUrl = NULL;
       
   424             }
       
   425         iPostResponseUrl = roapWrapper->GetPostResponseUrlL();
       
   426         CleanupStack::PopAndDestroy( 2, triggerBuf );
       
   427 
       
   428         if ( iUseCoeEnv && iProgressInfo && !iPostResponseUrl )
       
   429             {
       
   430             // No PrUrl found. Progess is complete.
       
   431             iProgressInfo->SetAndDraw( KProgressInfoFinalValue );
       
   432             }
       
   433         }
       
   434 
       
   435     // Trick to keep note open long enough during prUrl retrieval
       
   436     if ( !iPostResponseUrl )
   500         {
   437         {
   501         RemoveProgressNoteL();
   438         RemoveProgressNoteL();
   502         if (iConnectionError)
   439         }
   503             {
   440     else
   504             User::Leave(KErrCouldNotConnect);
   441         {
   505             }
   442         if ( iUseCoeEnv && iProgressInfo )
   506         else
   443             {
   507             {
   444             iProgressInfo->IncrementAndDraw( KProgressInfoIncrementMedium );
   508             User::Leave(KErrGeneral);
   445             }
   509             }
   446         }
   510         }
   447 
   511     User::LeaveIfError(roapTrigger.Open(iFs, *iFileName,
   448     CleanupStack::PopAndDestroy( &roapTrigger );
   512             EFileShareReadersOrWriters));
   449     CleanupStack::PopAndDestroy( &download );
   513     CleanupClosePushL(roapTrigger);
   450 
   514     // Get filehandle of ROAP trigger
   451     fs.Delete( triggerFileName );
   515     const TInt KReadBufSize = 512;
   452     CleanupStack::PopAndDestroy( &fs );
   516 
   453     }
   517     RBuf8 readBuf;
   454 
   518     readBuf.CleanupClosePushL();
   455 
   519     readBuf.CreateL(KReadBufSize);
   456 // ---------------------------------------------------------------------------
   520 
   457 // CDrmUtilityDmgrWrapper::SetDefaultAccessPointL
   521     // Read file to buffer
   458 // ---------------------------------------------------------------------------
   522     TInt triggerFileSize(0);
   459 //
   523     User::LeaveIfError(roapTrigger.Size(triggerFileSize));
   460 void CDrmUtilityDmgrWrapper::SetDefaultAccessPointL()
   524     if (iTriggerBuf)
   461     {
   525         {
   462     const TInt KDestinationSelectionMode( 2 );
   526         delete iTriggerBuf;
   463     CRepository* repository( NULL );
   527         iTriggerBuf = NULL;
   464     TInt ap( 0 );
   528         }
   465     TInt alwaysAsk( 0 );
   529     iTriggerBuf = HBufC8::NewL(triggerFileSize);
   466     TUint32 iapd32( 0 );
   530     User::LeaveIfError(roapTrigger.Read(readBuf, KReadBufSize));
   467     TInt defaultSnap( 0 );
   531     iTriggerBuf->Des().Copy(readBuf);
   468     TInt err( KErrNone );
   532     while (readBuf.Length() == KReadBufSize)
   469 
   533         {
   470     CLOG_WRITE( "DMgrWrapper::SetDefaultAccessPointL" );
   534         User::LeaveIfError(roapTrigger.Read(readBuf, KReadBufSize));
   471     DRMDEBUGLIT( KDuiBrApFormat,
   535         iTriggerBuf->Des().Append(readBuf);
   472         "CDrmUtilityDmgrWrapper::SetDefaultAccessPointL %d" );
   536         }
   473     DRMDEBUGLIT( KDuiBrApFormat2, " KBrowserDefaultAccessPoint = %d" );
   537 
   474     DRMDEBUGLIT( KDuiBrApFormat3, " KBrowserAccessPointSelectionMode = %d" );
   538     // And let ROAP handle it...
   475     DRMDEBUGLIT( KDuiBrApFormat4, " KBrowserNGDefaultSnapId = %d" );
   539     CleanupStack::PopAndDestroy(&readBuf);
   476 
   540     CleanupStack::PopAndDestroy(&roapTrigger);
   477     repository = CRepository::NewL( KCRUidBrowser );
   541     
   478     CleanupStack::PushL( repository );
   542     iFs.Delete(*iFileName);
   479     repository->Get( KBrowserDefaultAccessPoint, ap );
   543     delete iFileName;
   480     repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
   544     iFileName = NULL;
   481     repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
   545     if (iUseCoeEnv && iProgressInfo)
   482     DRMDEBUG2( KDuiBrApFormat(), __LINE__ );
   546         {
   483     DRMDEBUG2( KDuiBrApFormat2(), ap );
   547         iProgressInfo->IncrementAndDraw(KProgressInfoIncrementMedium);
   484     DRMDEBUG2( KDuiBrApFormat3(), alwaysAsk );
   548         }
   485     DRMDEBUG2( KDuiBrApFormat4(), defaultSnap );
   549 
   486 
   550     CompleteToState(aNextState, KErrNone);
   487     if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
   551     }
   488         {
   552 
   489         alwaysAsk = ETrue;
   553 // ---------------------------------------------------------------------------
   490         }
   554 // CDrmUtilityDmgrWrapper::DoHandleRoapTriggerL
   491     else
   555 // ---------------------------------------------------------------------------
   492         {
   556 //
   493         RCmManager cmManager;
   557 void CDrmUtilityDmgrWrapper::DoHandleRoapTriggerL(TDownloadState aNextState)
   494         cmManager.OpenLC();
   558     {
   495         if ( !alwaysAsk )
   559     Roap::TTriggerType triggerType;
   496             {
   560     Roap::TRiContextStatus contextStatus;
   497             TRAP( err, iapd32 = cmManager.GetConnectionMethodInfoIntL(
   561     Roap::TDomainOperation domainOperation;
   498                     ap, CMManager::ECmIapId ) );
   562 
   499             }
   563     RPointerArray<HBufC8> contentIds;
   500         else if ( alwaysAsk == KDestinationSelectionMode )
   564     CleanupResetAndDestroyPushL( contentIds );
   501             {
   565 
   502             TRAP( err, iapd32 =
   566     iRoapEng = Roap::CRoapEng::NewL();
   503                 IapIdOfDefaultSnapL( cmManager, defaultSnap ) );
   567 
   504             }
   568     iRoapEng->SetTriggerL(*iTriggerBuf, NULL, triggerType, contextStatus,
   505         CleanupStack::PopAndDestroy( &cmManager );
   569             domainOperation, contentIds);
   506         }
   570 
   507     if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) )
   571     CleanupStack::PopAndDestroy(&contentIds);
   508         {
   572 
   509         err = iDlMgr.SetIntAttribute( EDlMgrIap, iapd32 );
   573     iRoapEng->AcceptL(this, &iStatus);
   510         }
   574     iState = aNextState;
   511     CleanupStack::PopAndDestroy( repository );
   575     SetActive();
   512     }
   576     }
   513 
   577 
   514 
   578 // ---------------------------------------------------------------------------
   515 // ---------------------------------------------------------------------------
   579 // CDrmUtilityDmgrWrapper::CompleteToState
   516 // CDrmUtilityDmgrWrapper::GetErrorUrlL
   580 // ---------------------------------------------------------------------------
   517 // ---------------------------------------------------------------------------
   581 //
   518 //
   582 void CDrmUtilityDmgrWrapper::CompleteToState(
   519 HBufC8* CDrmUtilityDmgrWrapper::GetErrorUrlL()
   583         CDrmUtilityDmgrWrapper::TDownloadState aNextState, TInt aError)
   520     {
   584     {
   521     if( iErrorUrl )
   585     iState = aNextState;
   522         {
   586     TRequestStatus* ownStatus(&iStatus);
   523         return iErrorUrl->AllocL();
   587     User::RequestComplete(ownStatus, aError);
   524         }
   588     SetActive();
   525     return NULL;
   589     }
   526     }
   590 
   527 
   591 // MHttpDownloadMgrObserver methods
   528 
   592 // ---------------------------------------------------------------------------
   529 // ---------------------------------------------------------------------------
   593 // From class MHttpDownloadMgrObserver
   530 // From class MHttpDownloadMgrObserver
   594 //
   531 //
   595 // CDrmUtilityDmgrWrapper::HandleDMgrEventL
   532 // CDrmUtilityDmgrWrapper::HandleDMgrEventL
   596 // ---------------------------------------------------------------------------
   533 // ---------------------------------------------------------------------------
   597 //
   534 //
   598 void CDrmUtilityDmgrWrapper::HandleDownloadEventL( WRT::DownloadEvent* aEvent )
   535 void CDrmUtilityDmgrWrapper::HandleDMgrEventL(
   599     {
   536     RHttpDownload& aDownload,
   600     QString KDrmUtilityMimeTypeROAPTrigger("application/vnd.oma.drm.roap-trigger+xml");
   537     THttpDownloadEvent aEvent )
   601 	
   538     {
   602     try
   539     _LIT8( KDrmUtilityMimeTypeROAPTrigger,
   603     {
   540         "application/vnd.oma.drm.roap-trigger+xml" );
   604     if (aEvent->type() == DownloadEvent::HeadersReceived)
   541 
       
   542     CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL" );
       
   543     CLOG_WRITE_FORMAT( "iDownLoadState = %d", aEvent.iDownloadState );
       
   544     CLOG_WRITE_FORMAT( "iProgressState = %d", aEvent.iProgressState );
       
   545 
       
   546     if ( aEvent.iProgressState == EHttpContentTypeReceived )
   605         {
   547         {
   606         // check received mimetype
   548         // check received mimetype
   607         QString contentType = iDownload->attribute(ContentType).toString();
   549         RBuf8 contentType;
   608         if (!contentType.contains(KDrmUtilityMimeTypeROAPTrigger))
   550         contentType.CleanupClosePushL();
       
   551         contentType.CreateL( KMaxContentTypeLength );
       
   552         User::LeaveIfError(
       
   553             aDownload.GetStringAttribute( EDlAttrContentType, contentType ) );
       
   554         if ( !contentType.FindF( KDrmUtilityMimeTypeROAPTrigger ) )
   609             {
   555             {
   610             // ROAP trigger found, continue download
   556             // ROAP trigger found, continue download
   611 			iDownload->start();
   557             User::LeaveIfError( aDownload.Start() );
   612             }
   558             }
   613         else
   559         else
   614             {
   560             {
   615             // wrong MIME type, so stop download
   561             // wrong MIME type, so stop download
   616             iDownloadSuccess = EFalse;
   562             iDownloadSuccess = EFalse;
   617             iDownload->cancel();
   563             User::LeaveIfError( aDownload.Delete() );
   618             }
   564             }
   619         }
   565         CleanupStack::PopAndDestroy( &contentType );
   620     }
   566         }
   621     catch(const std::exception& exception)
   567 
   622     	{
   568     if ( aEvent.iDownloadState == EHttpDlCreated )
   623 		qt_symbian_exception2LeaveL(exception);
   569         {
   624     	}
   570         CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlCreated" );
   625     
   571         if ( iUseCoeEnv )
   626     if (aEvent->type() == DownloadEvent::Created)
   572             {
   627         {
   573         iProgressInfo->IncrementAndDraw( KProgressInfoIncrementMedium );
   628         CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Created" );
   574             }
   629         if (iUseCoeEnv && iProgressInfo)
   575         }
   630             {
   576     else if ( aEvent.iProgressState == EHttpProgDisconnected )
   631             iProgressInfo->IncrementAndDraw(KProgressInfoIncrementMedium);
   577         {
   632             }
   578         CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpProgDisconnected" );
   633         }
       
   634     else if (aEvent->type() == DownloadEvent::NetworkLoss)
       
   635         {
       
   636         CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: NetworkLoss" );
       
   637         
       
   638         // store failure
   579         // store failure
   639         iDownloadSuccess = EFalse;
   580         iDownloadSuccess = EFalse;
   640         iConnectionError = ETrue;
   581         iConnectionError = ETrue;
   641         // finished
   582         // finished
   642         }
   583         iWait.AsyncStop();
   643     else if (aEvent->type() == DownloadEvent::InProgress)
   584         }
   644         {
   585     else if ( aEvent.iDownloadState == EHttpDlInprogress )
   645         CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: InProgress" );
   586         {
   646         if (iUseCoeEnv)
   587         CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlInprogress" );
   647             {
   588         if ( iUseCoeEnv )
   648             iProgressInfo->IncrementAndDraw(KProgressInfoIncrementSmall);
   589             {
   649             }
   590         iProgressInfo->IncrementAndDraw( KProgressInfoIncrementSmall );
   650         }
   591             }
   651     else if (aEvent->type() == DownloadEvent::Completed)
   592         }
       
   593     else if ( aEvent.iDownloadState == EHttpDlCompleted )
   652         {
   594         {
   653         // store success
   595         // store success
   654         CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Completed" );
   596         CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlCompleted" );
   655         iDownloadSuccess = ETrue;
   597         iDownloadSuccess = ETrue;
   656         iConnectionError = EFalse;
   598         if ( iUseCoeEnv )
   657         if (iUseCoeEnv)
   599             {
   658             {
   600         iProgressInfo->IncrementAndDraw( KProgressInfoIncrementLarge );
   659             iProgressInfo->IncrementAndDraw(KProgressInfoIncrementLarge);
       
   660             }
   601             }
   661         // finished
   602         // finished
   662         TRequestStatus* status(&iStatus);
   603         iWait.AsyncStop();
   663         User::RequestComplete(status, KErrNone);
   604         }
   664         }
   605     else if ( aEvent.iDownloadState == EHttpDlFailed )
   665     else if (aEvent->type() == DownloadEvent::Failed)
   606         {
   666         {
   607         TInt32 err( KErrNone );
   667 		try
   608 
   668 			{
   609         CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlFailed" );
   669 			TInt32 err(KErrNone);
   610         // store failure
   670 	
   611         iDownloadSuccess = EFalse;
   671 			CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Failed" );
   612         User::LeaveIfError( aDownload.GetIntAttribute( EDlAttrErrorId, err ) );
   672 			// store failure
   613         CLOG_WRITE_FORMAT( "EDlAttrErrorId = %d", err );
   673 			iDownloadSuccess = EFalse;
   614 
   674 			err = (iDownload->attribute(LastError)).toInt();
   615         if ( err == EConnectionFailed ||
   675 			CLOG_WRITE_FORMAT( "EDlAttrErrorId = %d", err );
   616              err == ETransactionFailed)
   676 	
   617             {
   677 			if (err == ConnectionFailed || err == TransactionFailed)
   618             CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EConnectionFailed" );
   678 				{
   619             iConnectionError = ETrue;
   679 				CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: ConnectionFailed" );
   620             }
   680 				iConnectionError = ETrue;
   621 
   681 				}
   622         // finished
   682 			iDownload->cancel(); // remove useless download
   623         iWait.AsyncStop();
   683 			iDlMgr->pauseAll(); // disconnects Dmgr instantly.
   624         }
   684 			// finished
   625     }
   685 			TRequestStatus* status(&iStatus);
   626 
   686 			if ( iConnection->HasMoreConnectionAttempts() )
       
   687 				{
       
   688 				iState = EInit; // re-try with another conection
       
   689 				User::RequestComplete(status, KErrNone);
       
   690 				}
       
   691 			else
       
   692 				{
       
   693 				User::RequestComplete(status, KErrCancel);        
       
   694 				}
       
   695 			}
       
   696 		catch(const std::exception& exception)
       
   697 			{
       
   698 			qt_symbian_exception2LeaveL(exception);
       
   699 			}
       
   700         }
       
   701     }
       
   702 
   627 
   703 // ---------------------------------------------------------------------------
   628 // ---------------------------------------------------------------------------
   704 // CDrmUtilityDmgrWrapper::ShowProgressNoteL
   629 // CDrmUtilityDmgrWrapper::ShowProgressNoteL
   705 // ---------------------------------------------------------------------------
   630 // ---------------------------------------------------------------------------
   706 //
   631 //
   707 void CDrmUtilityDmgrWrapper::ShowProgressNoteL()
   632 void CDrmUtilityDmgrWrapper::ShowProgressNoteL()
   708     {
   633     {
   709     DRM::CFileNameContainer* resFileName(NULL);
   634     TFileName resFileName;
   710 
   635 
   711     CLOG_WRITE( "DMgrWrapper::ShowProgressNoteL" );
   636     CLOG_WRITE( "DMgrWrapper::ShowProgressNoteL" );
   712     if (iUseCoeEnv)
   637     if ( iUseCoeEnv )
   713         {
   638         {
   714         // Initialize the progress note dialog, it's values,
   639         // Initialize the progress note dialog, it's values,
   715         // and execute it
   640         // and execute it
   716         resFileName=DRM::CFileNameContainer::NewLC();
       
   717 #ifndef RD_MULTIPLE_DRIVE
   641 #ifndef RD_MULTIPLE_DRIVE
   718 
   642 
   719         resFileName->iBuffer.Copy( KDriveZ );
   643         resFileName.Copy( KDriveZ );
   720 
   644 
   721 #else //RD_MULTIPLE_DRIVE
   645 #else //RD_MULTIPLE_DRIVE
   722         TInt driveNumber(-1);
   646 
       
   647         TInt driveNumber( -1 );
   723         TChar driveLetter;
   648         TChar driveLetter;
   724         DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRom, driveNumber);
   649         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
   725 
   650 
   726         iCoeEnv->FsSession().DriveToChar(driveNumber, driveLetter);
   651         iCoeEnv->FsSession().DriveToChar( driveNumber, driveLetter );
   727 
   652 
   728         resFileName->iBuffer.Format(KRomDriveFormatter, (TUint) driveLetter);
   653         resFileName.Format( KRomDriveFormatter, (TUint)driveLetter );
   729 
   654 
   730 #endif
   655 #endif
   731 
   656 
   732         resFileName->iBuffer.Append(KDC_RESOURCE_FILES_DIR);
   657         resFileName.Append( KDC_RESOURCE_FILES_DIR );
   733         resFileName->iBuffer.Append(KCDrmUtilityDmgrWrapperResFileName);
   658         resFileName.Append( KCDrmUtilityDmgrWrapperResFileName );
   734         RConeResourceLoader loader(*iCoeEnv);
   659         RConeResourceLoader loader( *iCoeEnv );
   735         loader.OpenL(resFileName->iBuffer);
   660         loader.OpenL( resFileName );
   736         CleanupStack::PopAndDestroy( resFileName );
       
   737         resFileName=NULL;
       
   738 
   661 
   739         iProgressNoteDialog = new (ELeave) CAknProgressDialog(
   662         iProgressNoteDialog = new (ELeave) CAknProgressDialog(
   740                 reinterpret_cast<CEikDialog**> (&iProgressNoteDialog));
   663             reinterpret_cast< CEikDialog** >( &iProgressNoteDialog ) );
   741         iProgressNoteDialog->PrepareLC(R_SILENT_PROGRESS_NOTE);
   664         iProgressNoteDialog->PrepareLC( R_SILENT_PROGRESS_NOTE );
   742         iProgressNoteDialog->SetCallback(this);
   665         iProgressNoteDialog->SetCallback( this );
   743         iProgressInfo = iProgressNoteDialog->GetProgressInfoL();
   666         iProgressInfo = iProgressNoteDialog->GetProgressInfoL();
   744         iProgressInfo->SetFinalValue(KProgressInfoFinalValue);
   667         iProgressInfo->SetFinalValue( KProgressInfoFinalValue );
   745         iDialogDismissed = EFalse;
   668         iDialogDismissed = EFalse;
   746         iProgressNoteDialog->RunLD();
   669         iProgressNoteDialog->RunLD();
   747 
   670 
   748         loader.Close();
   671         loader.Close();
   749         }
   672         }
   750 
   673 
   751     }
   674     }
   752 
   675 
       
   676 
   753 // ---------------------------------------------------------------------------
   677 // ---------------------------------------------------------------------------
   754 // CDrmUtilityDmgrWrapper::RemoveProgressNoteL
   678 // CDrmUtilityDmgrWrapper::RemoveProgressNoteL
   755 // ---------------------------------------------------------------------------
   679 // ---------------------------------------------------------------------------
   756 //
   680 //
   757 void CDrmUtilityDmgrWrapper::RemoveProgressNoteL()
   681 void CDrmUtilityDmgrWrapper::RemoveProgressNoteL()
   758     {
   682     {
   759 
   683 
   760     if (iUseCoeEnv)
   684     if ( iUseCoeEnv )
   761         {
   685         {
   762         if (iProgressNoteDialog && !iDialogDismissed)
   686         if (iProgressNoteDialog && !iDialogDismissed)
   763             {
   687             {
   764             // deletes the dialog
   688             // deletes the dialog
   765             TRAPD(err, iProgressNoteDialog->ProcessFinishedL());
   689             TRAPD(err, iProgressNoteDialog->ProcessFinishedL());
   766             if (err != KErrNone)
   690             if (err != KErrNone)
   767                 {
   691                 {
   768                 iProgressNoteDialog->SetCallback(NULL);
       
   769                 delete iProgressNoteDialog;
   692                 delete iProgressNoteDialog;
   770                 iDialogDismissed = ETrue;
       
   771                 }
   693                 }
   772             iProgressNoteDialog = NULL;
   694             iProgressNoteDialog = NULL;
   773             }
   695             }
   774         }
   696         }
   775     }
   697 
       
   698     }
       
   699 
   776 
   700 
   777 // ---------------------------------------------------------------------------
   701 // ---------------------------------------------------------------------------
   778 // From class MAknProgressDialogCallback
   702 // From class MAknProgressDialogCallback
   779 //
   703 //
   780 // CDrmUtilityDmgrWrapper::DialogDismissedL
   704 // CDrmUtilityDmgrWrapper::DialogDismissedL
   781 // ---------------------------------------------------------------------------
   705 // ---------------------------------------------------------------------------
   782 //
   706 //
   783 void CDrmUtilityDmgrWrapper::DialogDismissedL(TInt aButtonId )
   707 void CDrmUtilityDmgrWrapper::DialogDismissedL( TInt /*aButtonId*/ )
   784     {
   708     {
   785     iDialogDismissed = ETrue;
   709     iDialogDismissed = ETrue;
   786 
   710 
   787     // Already freed, just set to NULL
   711     // Already freed, just set to NULL
   788     iProgressNoteDialog = NULL;
   712     iProgressNoteDialog = NULL;
   789     iProgressInfo = NULL;
   713     iProgressInfo = NULL;
   790 
   714 
   791     if (IsActive() && aButtonId == EAknSoftkeyCancel)
   715     if( iWait.IsStarted() )
   792         {
       
   793         if ((iState == EGetMeteringTrigger || iState == EGetPrUrlTrigger))
       
   794             {
       
   795             Cancel();
       
   796             }
       
   797         else
       
   798             {
       
   799             TRequestStatus* status(&iStatus);
       
   800             User::RequestComplete(status, KErrCancel);
       
   801             }
       
   802         }
       
   803     //For avoiding active object deadlock
       
   804     iDlMgr->removeAll();
       
   805 
       
   806     }
       
   807 
       
   808 // RoapObserver methods
       
   809 
       
   810 // ---------------------------------------------------------------------------
       
   811 // CDrmUtilityDmgrWrapper::PostResponseUrlL
       
   812 // ---------------------------------------------------------------------------
       
   813 //
       
   814 void CDrmUtilityDmgrWrapper::PostResponseUrlL(const TDesC8& aPostResponseUrl)
       
   815     {
       
   816     UpdateBufferL<HBufC8, TDesC8> (iTriggerUrl, aPostResponseUrl);
       
   817 
       
   818     if (iUseCoeEnv && iProgressInfo)
       
   819         {
       
   820         iProgressInfo->IncrementAndDraw(KProgressInfoIncrementMedium);
       
   821         }
       
   822     }
       
   823 
       
   824 // Trivial RoapObserver methods
       
   825 TBool CDrmUtilityDmgrWrapper::ConnectionConfL()
       
   826     {
       
   827     return ETrue;
       
   828     }
       
   829 
       
   830 TBool CDrmUtilityDmgrWrapper::ContactRiConfL()
       
   831     {
       
   832     return ETrue;
       
   833     }
       
   834 
       
   835 TBool CDrmUtilityDmgrWrapper::TransIdConfL()
       
   836     {
       
   837     return EFalse;
       
   838     }
       
   839 
       
   840 void CDrmUtilityDmgrWrapper::RightsObjectDetailsL(const RPointerArray<
       
   841         CDRMRights>& /*aRightsList*/)
       
   842     {
       
   843     // do nothing
       
   844     }
       
   845 
       
   846 void CDrmUtilityDmgrWrapper::ContentDownloadInfoL(TPath& /*aTempFolder*/,
       
   847         TFileName& /*aContentName*/, TInt& aMaxSize)
       
   848     {
       
   849     aMaxSize = -1;
       
   850     }
       
   851 
       
   852 void CDrmUtilityDmgrWrapper::ContentDetailsL(const TDesC& /*aPath*/,
       
   853         const TDesC8& /*aType*/, const TUid& /*aAppUid*/)
       
   854     {
       
   855     }
       
   856 
       
   857 void CDrmUtilityDmgrWrapper::RoapProgressInfoL(const TInt /*aProgressInfo*/)
       
   858     {
       
   859     // do nothing
       
   860     }
       
   861 
       
   862 void CDrmUtilityDmgrWrapper::ErrorUrlL(const TDesC8& aErrorUrl)
       
   863     {
       
   864     UpdateBufferL<HBufC8, TDesC8> (iErrorUrl, aErrorUrl);
       
   865     }
       
   866 
       
   867 // CActive methods
       
   868 
       
   869 // ---------------------------------------------------------------------------
       
   870 // CDrmUtilityDmgrWrapper::DoCancel
       
   871 // ---------------------------------------------------------------------------
       
   872 //
       
   873 void CDrmUtilityDmgrWrapper::DoCancel()
       
   874     {
       
   875     delete iRoapEng;
       
   876     iRoapEng = NULL;
       
   877     iConnection->Close();
       
   878     if (iWait.IsStarted())
       
   879         {
   716         {
   880         iWait.AsyncStop();
   717         iWait.AsyncStop();
   881         }
   718         }
   882     }
   719 
   883 
   720     }
   884 // ---------------------------------------------------------------------------
   721 
   885 // CDrmUtilityDmgrWrapper::RunL
       
   886 // ---------------------------------------------------------------------------
       
   887 //
       
   888 void CDrmUtilityDmgrWrapper::RunL()
       
   889     {
       
   890     TInt error(iStatus.Int());
       
   891     
       
   892     ClearIfNotRoapTemporaryError(error, iErrorUrl);
       
   893     User::LeaveIfError(error);
       
   894     switch (iState)
       
   895         {
       
   896         case EInit:
       
   897             {
       
   898             if (!iProgressNoteDialog)
       
   899                 {
       
   900                 ShowProgressNoteL();
       
   901                 }
       
   902             DoConnectL(EGetMeteringTrigger);
       
   903             }
       
   904             break;
       
   905         case EGetMeteringTrigger:
       
   906             {
       
   907             DoDownloadRoapTriggerL(ESaveMeteringTrigger);
       
   908             }
       
   909             break;
       
   910         case ESaveMeteringTrigger:
       
   911             {
       
   912             DoSaveRoapTriggerL(EMeteringReportSubmit);
       
   913             }
       
   914             break;
       
   915 
       
   916         case EMeteringReportSubmit:
       
   917             {
       
   918             DoHandleRoapTriggerL(EGetPrUrlTrigger);
       
   919             }
       
   920             break;
       
   921         case EGetPrUrlTrigger:
       
   922             {
       
   923             delete iRoapEng;
       
   924             iRoapEng = NULL;
       
   925             DoDownloadRoapTriggerL(ESavePrUrlTrigger);
       
   926             }
       
   927             break;
       
   928         case ESavePrUrlTrigger:
       
   929             {
       
   930             DoSaveRoapTriggerL(EPrRoapRequest);
       
   931             }
       
   932             break;
       
   933         case EPrRoapRequest:
       
   934             {
       
   935             DoHandleRoapTriggerL(EComplete);
       
   936             }
       
   937             break;
       
   938         case EComplete:
       
   939             {
       
   940             RemoveProgressNoteL();
       
   941             delete iRoapEng;
       
   942             iRoapEng = NULL;
       
   943             iWait.AsyncStop();
       
   944             }
       
   945             break;
       
   946 
       
   947         default:
       
   948             User::Leave(KErrNotSupported);
       
   949         }
       
   950     }
       
   951 
       
   952 // ---------------------------------------------------------------------------
       
   953 // CDrmUtilityDmgrWrapper::RunError
       
   954 // ---------------------------------------------------------------------------
       
   955 //
       
   956 TInt CDrmUtilityDmgrWrapper::RunError(TInt /* aError */)
       
   957     {
       
   958     delete iRoapEng;
       
   959     iRoapEng = NULL;
       
   960     iConnection->Close();
       
   961     if (iWait.IsStarted())
       
   962         {
       
   963         iWait.AsyncStop();
       
   964         }
       
   965 
       
   966     if (iUseCoeEnv)
       
   967         {
       
   968         if (iProgressNoteDialog && !iDialogDismissed)
       
   969             {
       
   970             iProgressNoteDialog->SetCallback(NULL);
       
   971             delete iProgressNoteDialog;
       
   972             iDialogDismissed = ETrue;
       
   973             }
       
   974         iProgressNoteDialog = NULL;
       
   975         }
       
   976     return KErrNone;
       
   977     }
       
   978 
   722 
   979 // ======== GLOBAL FUNCTIONS ========
   723 // ======== GLOBAL FUNCTIONS ========
   980 
   724 
   981 //------------------------------------------------------------------------------
   725 //------------------------------------------------------------------------------
   982 // GateFunctionDRM
   726 // GateFunctionDRM
   984 //------------------------------------------------------------------------------
   728 //------------------------------------------------------------------------------
   985 EXPORT_C TAny* GateFunctionDMgr()
   729 EXPORT_C TAny* GateFunctionDMgr()
   986     {
   730     {
   987     CDrmUtilityDmgrWrapper* launcher = NULL;
   731     CDrmUtilityDmgrWrapper* launcher = NULL;
   988     TRAPD( err, launcher = CDrmUtilityDmgrWrapper::NewL() );
   732     TRAPD( err, launcher = CDrmUtilityDmgrWrapper::NewL() );
   989     if (err != KErrNone)
   733     if( err != KErrNone )
   990         {
   734         {
   991         return NULL;
   735         return NULL;
   992         }
   736         }
   993 
   737 
   994     return launcher;
   738     return launcher;