codhandler/codeng/src/RoapSaver.cpp
changeset 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of class CRoapSaver.   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <RoapEng.h>
       
    22 #include <roaptrigger.h>
       
    23 #include "RoapSaver.h"
       
    24 #include "RoapData.h"
       
    25 #include "CodLoadObserver.h"
       
    26 #include "CodLogger.h"
       
    27 #include "CodError.h"
       
    28 #include "CodPanic.h"
       
    29 #include "CodProgress.h"
       
    30 #include "CodData.h"
       
    31 #include <AiwGenericParam.h>
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CRoapSaver::NewL()
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 CRoapSaver* CRoapSaver::NewL
       
    40         (
       
    41         const TDesC8& aType,
       
    42         CRoapData*& aData,
       
    43         TCodProgress* aProgress,
       
    44         TInt aProgressBytes,
       
    45         const TFileName& aTempPath,
       
    46         const TFileName& aRootPath,
       
    47         const TFileName& aFname
       
    48         )
       
    49     {
       
    50     CRoapSaver* saver = new (ELeave) CRoapSaver
       
    51         ( aType, aData, aProgress, aProgressBytes, aTempPath, aRootPath, aFname );
       
    52     CleanupStack::PushL( saver );
       
    53     saver->ConstructL();
       
    54     CleanupStack::Pop( saver );
       
    55     return saver;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CRoapSaver::~CRoapSaver()
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 CRoapSaver::~CRoapSaver()
       
    63     {
       
    64     CLOG(( ECodEng, 2, _L("-> CRoapSaver::~CRoapSaver") ));
       
    65     delete iEng;
       
    66     delete iBuf;
       
    67     CLOG(( ECodEng, 2, _L("<- CRoapSaver::~CRoapSaver") ));
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CRoapSaver::OpenStoreL()
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 void CRoapSaver::OpenStoreL()
       
    75     {
       
    76     CLOG(( ECodEng, 2, _L("-> CRoapSaver::OpenStoreL") ));
       
    77     __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
       
    78     __ASSERT_DEBUG( !iBuf, CodPanic( ECodInternal ) );
       
    79     iSize = 0;
       
    80     iState = EStoreOpen;
       
    81     CLOG(( ECodEng, 2, _L("<- CRoapSaver::OpenStoreL") ));
       
    82     }
       
    83     
       
    84 // ---------------------------------------------------------
       
    85 // CRoapSaver::AppendData()
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 TInt CRoapSaver::AppendData( const TDesC8& aData )
       
    89     {
       
    90     CLOG(( ECodEng, 4, \
       
    91         _L("-> CRoapSaver::AppendData (%d) bytes"), aData.Length() ));
       
    92 //TODO: iState = EInstalling for dd2    __ASSERT_DEBUG( iState == EStoreOpen, CodPanic( ECodInternal ) );
       
    93     TInt err = CheckMaxSize( aData.Size() );
       
    94     if ( !err )
       
    95         {
       
    96         TInt needed = iSize + aData.Length();
       
    97         if ( !iBuf )
       
    98             {
       
    99             iBuf = HBufC8::New( needed );
       
   100             if ( !iBuf )
       
   101                 {
       
   102                 err = KErrNoMemory;
       
   103                 }
       
   104             }
       
   105         if ( !err && needed > iBuf->Des().MaxLength() )
       
   106             {
       
   107             HBufC8* buf = iBuf->ReAlloc( needed );
       
   108             if ( buf )
       
   109                 {
       
   110                 iBuf = buf;
       
   111                 }
       
   112             else
       
   113                 {
       
   114                 err = KErrNoMemory;
       
   115                 }
       
   116             }
       
   117         if ( !err )
       
   118             {
       
   119             iBuf->Des().Append( aData );
       
   120             iSize += aData.Length();
       
   121             }
       
   122         }
       
   123     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
       
   124     return err;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CRoapSaver::CloseStore()
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CRoapSaver::CloseStore()
       
   132     {
       
   133     CLOG(( ECodEng, 2, _L("CRoapSaver::CloseStore") ));
       
   134     iState = EStoreClosed;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CRoapSaver::CheckResponseAttributesL()
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 void CRoapSaver::CheckResponseAttributesL( const CCodData& /*aData*/ )
       
   142     {
       
   143     CLOG(( ECodEng, 2, _L("-> CRoapSaver::CheckResponseAttributesL") ));
       
   144 //TODO: tmp EInstalling for dd2    __ASSERT_DEBUG( iState == EStoreClosed, CodPanic( ECodInternal ) );
       
   145 #ifdef __TEST_COD_LOG
       
   146     TPtrC8 mime( iType.Des8() );
       
   147     CLOG(( ECodEng, 4, _L8("  MIME==<%S>, size(%d)"), &mime, iSize ));
       
   148 #endif /* def __TEST_COD_LOG */
       
   149 
       
   150     if ( !iSize )
       
   151         {
       
   152         CLOG(( ECodEng, 4, _L("  0 bytes data") ));
       
   153         User::Leave( KErrCodAttributeMismatch );
       
   154         }
       
   155 
       
   156     // Compare content MIME type against descriptor.
       
   157 
       
   158     // Size is not checked, no exact match is required. Quote form spec:
       
   159     // "The storage size and the execution size are dependent on the
       
   160     // environment and may be different from the value of the size attribute.
       
   161     // The transport size may also be different, if compression or some
       
   162     // packaging format is used."
       
   163     //
       
   164     // There is a safety upper bound on the transaction size, that is already
       
   165     // applied. See SetMaxSize().
       
   166 
       
   167 
       
   168 // TODO (??) type not checked, ROAP Trigger is always accepted.
       
   169 // HACK HACK DRM HACK
       
   170 //    if( iType != TDataType( aData.Type() ) )
       
   171 //        {
       
   172 //        CLOG(( ECodEng, 4, _L("  mismatch") ));
       
   173 //        User::Leave( KErrCodAttributeMismatch );
       
   174 //        }
       
   175 
       
   176     iState = ERespChecked;
       
   177     CLOG(( ECodEng, 2, _L("<- CRoapSaver::CheckResponseAttributesL (match)") ));
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CRoapSaver::InstallL()
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 void CRoapSaver::InstallL( TRequestStatus* aStatus, const TDesC& aName, const TBool /*aAttached*/ )
       
   185     {
       
   186     CLOG(( ECodEng, 2, _L("-> CRoapSaver::InstallL") ));
       
   187 //TODO:    __ASSERT_DEBUG( iState == ERespChecked, CodPanic( ECodInternal ) );
       
   188     __ASSERT_ALWAYS( aStatus, CodPanic( ECodInternal ) );
       
   189     __ASSERT_DEBUG( iBuf, CodPanic( ECodInternal ) );
       
   190 //TODO:    __ASSERT_DEBUG( iType == TDataType( KOma2TriggerContentType ), \
       
   191 //        CodPanic( ECodInternal ) );
       
   192 
       
   193 #ifdef __TEST_COD_LOG
       
   194     TPtrC8 ptr( iBuf->Des() );
       
   195     CDUMP(( ECodEng, 2, _S("Trigger:"), _S("        "), \
       
   196         (const TUint8*)ptr.Ptr(), ptr.Size() ));
       
   197 #endif /* def __TEST_COD_LOG */
       
   198 
       
   199     iContentName.Set( aName );  // TODO, must presist - use CodData instead?
       
   200     __ASSERT_DEBUG( !iEng, CodPanic( ECodInternal ) );
       
   201     iEng = Roap::CRoapEng::NewL();
       
   202     if ( iData )
       
   203         {
       
   204         iData->Reset();
       
   205         }
       
   206     else
       
   207         {
       
   208         iData = CRoapData::NewL();
       
   209         }
       
   210     iEng->SetTriggerL
       
   211         (
       
   212         *iBuf,
       
   213         iParams,
       
   214         iData->iType,
       
   215         iData->iContextStatus,
       
   216         iData->iDomainOperation,
       
   217         iData->iContentIdList
       
   218         );
       
   219 
       
   220 //TODO:    __ASSERT_DEBUG( !iData->iRiAlias, CodPanic( ECodInternal ) );
       
   221     if ( iEng->Trigger().iRiAlias )
       
   222         {
       
   223         iData->iRiAlias = iEng->Trigger().iRiAlias->AllocL();
       
   224         }
       
   225 
       
   226 #ifdef __TEST_COD_LOG
       
   227     CLOG(( ECodEng, 3, _L("  Type(%d)"), iData->iType ));
       
   228     CLOG(( ECodEng, 3, _L("  ContextStatus(%d)"), iData->iContextStatus ));
       
   229     CLOG(( ECodEng, 3, _L("  DomainOp(%d)"), iData->iDomainOperation ));
       
   230     for ( TInt i = 0; i < iData->iContentIdList.Count(); i++ )
       
   231         {
       
   232         ptr.Set( iData->iContentIdList[i]->Des() );
       
   233         CLOG(( ECodEng, 3, _L8("  ContentId #%d <%S>"), i, &ptr ));
       
   234         }
       
   235     if ( iData->iRiAlias )
       
   236         {
       
   237         ptr.Set( iData->iRiAlias->Des() );
       
   238         CLOG(( ECodEng, 3, _L8("  RiAlias <%S>"), &ptr ));
       
   239         }
       
   240     else
       
   241         {
       
   242         CLOG(( ECodEng, 3, _L8("  RiAlias NULL") ));
       
   243         }
       
   244 #endif /* def __TEST_COD_LOG */
       
   245     
       
   246     if ( iObserver )
       
   247         {
       
   248         CLOG(( ECodEng, 3, \
       
   249             _L("CRoapSaver::StartRoapL notify RoapTriggerParsedL") ));
       
   250         iObserver->RoapTriggerParsedL( *iData );
       
   251         }
       
   252 
       
   253     // CodHandler implements 'auto-accept' for ROAP Trigger.
       
   254     // ROAP is initiated without user interaction.
       
   255     iEng->AcceptL( this, aStatus );
       
   256     iState = EInstalling;
       
   257 
       
   258     CLOG(( ECodEng, 2, _L("<- CRoapSaver::InstallL") ));
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // CRoapSaver::CancelInstall()
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void CRoapSaver::CancelInstall()
       
   266     {
       
   267     CLOG(( ECodEng, 2, _L("-> CRoapSaver::CancelInstall") ));
       
   268     if ( iEng )
       
   269         {
       
   270         iEng->Cancel();
       
   271         }
       
   272     CLOG(( ECodEng, 2, _L("<- CRoapSaver::CancelInstall") ));
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CRoapSaver::ReleaseContent()
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 void CRoapSaver::ReleaseContent( TFileName& aFname, TUid& aHandler )
       
   280     {
       
   281     CLOG(( ECodEng, 2, _L("CRoapSaver::ReleaseContent") ));
       
   282     // Note: assert EInstalling state, not EInstalled. This object never gets
       
   283     // EInstalled as the request status is not ours -> it does not know
       
   284     // when installing is completed.
       
   285 //TODO: EStoreClose for dd2    __ASSERT_DEBUG( iState == EInstalling, CodPanic( ECodInternal ) );
       
   286     aFname = iFname;
       
   287     aHandler = iHandler;
       
   288     iFname = KNullDesC;
       
   289     iHandler = KNullUid;
       
   290     iContentName.Set( KNullDesC );
       
   291     delete iEng;
       
   292     iEng = NULL;
       
   293     iState = EInit;
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------
       
   297 // CRoapSaver::ReleaseFileName()
       
   298 // ---------------------------------------------------------
       
   299 //
       
   300 void CRoapSaver::ReleaseFileName( TFileName& /*aFname*/)
       
   301 {
       
   302 }
       
   303 
       
   304 // ---------------------------------------------------------
       
   305 // CRoapSaver::Cleanup()
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 void CRoapSaver::Cleanup( TBool /* aDeleteFile */)
       
   309     {
       
   310     CLOG(( ECodEng, 2, _L("-> CRoapSaver::Cleanup") ));
       
   311     if ( iEng )
       
   312         {
       
   313         iEng->Cancel();
       
   314 #ifdef __TEST_COD_LOG
       
   315         TInt err =  // ('Log-only' variable.)
       
   316 #endif /* def __TEST_COD_LOG */
       
   317         iEng->DoCleanup();
       
   318         CLOG(( ECodEng, 2, _L("  CRoapSaver::Cleanup err(%d)"), err ));
       
   319         delete iEng;
       
   320         iEng = NULL;
       
   321         }
       
   322     iContentName.Set( KNullDesC );
       
   323     iState = EInit;
       
   324     CLOG(( ECodEng, 2, _L("<- CRoapSaver::Cleanup") ));
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------
       
   328 // CRoapSaver::CRoapSaver()
       
   329 // ---------------------------------------------------------
       
   330 //
       
   331 CRoapSaver::CRoapSaver
       
   332     (
       
   333     const TDesC8& aType,
       
   334     CRoapData*& aData,
       
   335     TCodProgress* aProgress,
       
   336     TInt aProgressBytes,
       
   337     const TFileName& aTempPath,
       
   338     const TFileName& aRootPath,
       
   339     const TFileName& aFname
       
   340     )
       
   341 : CCodSaver( aType ),
       
   342   iData( aData ),
       
   343   iProgress( aProgress ),
       
   344   iProgressBytes( aProgressBytes ),
       
   345   iTempPath( aTempPath ),
       
   346   iRootPath( aRootPath ),
       
   347   iFname( aFname)
       
   348     {
       
   349     CLOG(( ECodEng, 2, _L("*** CRoapSaver::CRoapSaver") ));
       
   350     }
       
   351 
       
   352 // ----------------------------------------------------------
       
   353 // CRoapSaver::ConnectionConfL()
       
   354 // ----------------------------------------------------------
       
   355 //
       
   356 TBool CRoapSaver::ConnectionConfL()
       
   357     {
       
   358     CLOG(( ECodEng, 2, _L("-> CRoapSaver::ConnectionConfL") ));
       
   359     TBool conf( EFalse );
       
   360     if ( iObserver )
       
   361         {
       
   362         CLOG(( ECodEng, 3, \
       
   363             _L("CRoapSaver::ConnectionConfL notify ConnectionConfL") ));
       
   364         conf = iObserver->ConfirmConnectL();
       
   365         }
       
   366     CLOG(( ECodEng, 2, _L("<- CRoapSaver::ConnectionConfL (%d)"), conf ));
       
   367     return conf;
       
   368     }
       
   369     
       
   370 // ----------------------------------------------------------
       
   371 // CRoapSaver::ContactRiConfL()
       
   372 // ----------------------------------------------------------
       
   373 //
       
   374 TBool CRoapSaver::ContactRiConfL()
       
   375     {
       
   376     CLOG(( ECodEng, 2, _L("CRoapSaver::ContactRiConfL") ));
       
   377     // CodHandler implements 'auto-accept' for ROAP Trigger.
       
   378     return ETrue;
       
   379     }
       
   380     
       
   381 // ----------------------------------------------------------
       
   382 // CRoapSaver::TransIdConfL()
       
   383 // ----------------------------------------------------------
       
   384 //
       
   385 TBool CRoapSaver::TransIdConfL()
       
   386     {
       
   387     CLOG(( ECodEng, 2, _L("CRoapSaver::TransIdConfL") ));
       
   388     return EFalse;
       
   389     }
       
   390     
       
   391 // ----------------------------------------------------------
       
   392 // CRoapSaver::RightsObjectDetailsL()
       
   393 // ----------------------------------------------------------
       
   394 //
       
   395 void CRoapSaver::RightsObjectDetailsL
       
   396 ( const RPointerArray<CDRMRights>& /*aRightsList*/ )
       
   397     {
       
   398     CLOG(( ECodEng, 2, _L("CRoapSaver::RightsObjectDetailsL") ));
       
   399     }
       
   400 		    
       
   401 // ----------------------------------------------------------
       
   402 // CRoapSaver::ContentDownloadInfoL()
       
   403 // ----------------------------------------------------------
       
   404 //
       
   405 void CRoapSaver::ContentDownloadInfoL
       
   406 ( TPath& aTempFolder, TFileName& aContentName, TInt& aMaxSize )
       
   407     {
       
   408     aTempFolder = iTempPath;
       
   409     aContentName = iContentName;
       
   410     aMaxSize = iMaxSize;        // TODO must to be set.
       
   411     }
       
   412 
       
   413 // ----------------------------------------------------------
       
   414 // CRoapSaver::ContentDetailsL()
       
   415 // ----------------------------------------------------------
       
   416 //
       
   417 void CRoapSaver::ContentDetailsL
       
   418 ( const TDesC& aPath, const TDesC8& aType, const TUid& aAppUid )
       
   419     {
       
   420     iFname = aPath;
       
   421     iType = aType;
       
   422     iHandler = aAppUid;
       
   423     }
       
   424                                       
       
   425 // ----------------------------------------------------------
       
   426 // CRoapSaver::HandleDCFPartL()
       
   427 // ----------------------------------------------------------
       
   428 //
       
   429 void CRoapSaver::HandleDCFPartL( const TDesC8& /*aFilename*/ )
       
   430     {
       
   431     CLOG(( ECodEng, 2, _L("CRoapSaver::HandleDCFPartL") ));
       
   432     // DRM Engine does not support multipart ROAP response yet.
       
   433     // This method will never be called.
       
   434     User::Leave( KErrNotSupported );
       
   435     }
       
   436         
       
   437 // ----------------------------------------------------------
       
   438 // CRoapSaver::RoapProgressInfoL()
       
   439 // ----------------------------------------------------------
       
   440 //
       
   441 void CRoapSaver::RoapProgressInfoL( const TInt aProgressInfo )
       
   442     {
       
   443     CLOG(( ECodEng, 2, _L("CRoapSaver::RoapProgressInfoL (%d)"), \
       
   444         aProgressInfo ));
       
   445     if ( iProgress )
       
   446         {
       
   447         iProgress->SetAmountL( aProgressInfo );
       
   448         }
       
   449     }
       
   450 
       
   451 
       
   452 // ----------------------------------------------------------
       
   453 // CRoapSaver::ErrorUrlL()
       
   454 // ----------------------------------------------------------
       
   455 //
       
   456 void CRoapSaver::ErrorUrlL( const TDesC8& /* aErrorUrl */)
       
   457 {
       
   458 	
       
   459 }
       
   460 // ----------------------------------------------------------
       
   461 // CRoapSaver::PostResponseUrlL()
       
   462 // ----------------------------------------------------------
       
   463 //
       
   464 void CRoapSaver::PostResponseUrlL( const TDesC8& aPrUrl )
       
   465     {
       
   466     CLOG(( ECodEng, 2, _L("-> CRoapSaver::PostResponseUrlL") ));
       
   467     CLOG(( ECodEng, 2, _L("aPrUrl = '%S'"), &aPrUrl ));
       
   468 
       
   469     //Send an event to MCodLoadObserver which sends an event to DownloadMgr, which handles the 
       
   470     // PostResponse URL like NextUriL.
       
   471     if ( iObserver )
       
   472         {
       
   473         iObserver->HandleRoapPostResponseUrlL( aPrUrl );
       
   474         }
       
   475 
       
   476     CLOG(( ECodEng, 2, _L("<- CRoapSaver::PostResponseUrlL") ));
       
   477 
       
   478     }
       
   479 
       
   480