codhandler/codeng/src/DrmHandler.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 CDrmHandler.   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <DRMCommon.h>
       
    22 #include <DocumentHandler.h>
       
    23 #include "DrmHandler.h"
       
    24 #include "CodLogger.h"
       
    25 #include "CodPanic.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CDrmHandler::NewL()
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 CDrmHandler* CDrmHandler::NewL( const TDesC& aFname )
       
    34     {
       
    35     CDrmHandler* handler = new (ELeave) CDrmHandler();
       
    36     CleanupStack::PushL( handler );
       
    37     handler->ConstructL( aFname );
       
    38     CleanupStack::Pop( handler );
       
    39     return handler;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CDrmHandler::~CDrmHandler()
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 CDrmHandler::~CDrmHandler()
       
    47     {
       
    48     CLOG(( ECodEng, 2, _L("-> *** CDrmHandler::~CDrmHandler") ));
       
    49     delete iDrmCommon;
       
    50     iRightsClient.Close();
       
    51     delete iContentUri;
       
    52     delete iType;
       
    53     CLOG(( ECodEng, 2, _L("<- *** CDrmHandler::~CDrmHandler") ));
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CDrmHandler::Cleanup()
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void CDrmHandler::Cleanup()
       
    61     {
       
    62     CLOG(( ECodEng, 2, _L("-> CDrmHandler::Cleanup") ));
       
    63     if ( iContentUri && iRightsClient.Handle() )
       
    64         {
       
    65 #ifdef __TEST_COD_LOG
       
    66         TInt err =  // ('Log-only' variable.)
       
    67 #endif /* def __TEST_COD_LOG */
       
    68         iRightsClient.DeleteDbEntry( *iContentUri );
       
    69         CLOG(( ECodEng, 3, _L("  err(%d)"), err ));
       
    70         delete iContentUri;
       
    71         iContentUri = NULL;
       
    72         }
       
    73     CLOG(( ECodEng, 2, _L("<- CDrmHandler::Cleanup") ));
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CDrmHandler::Type()
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 TPtrC8 CDrmHandler::Type() const
       
    81     {
       
    82     TPtrC8 ptr;
       
    83     if ( iType )
       
    84         {
       
    85         ptr.Set( *iType );
       
    86         }
       
    87     return ptr;
       
    88     }
       
    89     
       
    90 // ---------------------------------------------------------
       
    91 // CDrmHandler::CDrmHandler()
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 CDrmHandler::CDrmHandler()
       
    95     {
       
    96     CLOG(( ECodEng, 2, _L("*** CDrmHandler::CDrmHandler") ));
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CDrmHandler::ConstructL()
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 void CDrmHandler::ConstructL( const TDesC& aFname )
       
   104     {
       
   105     CLOG(( ECodEng, 2, _L("-> CDrmHandler::ConstructL") ));
       
   106     TBool isDcf( EFalse );
       
   107     iDrmCommon = DRMCommon::NewL();
       
   108     User::LeaveIfError( iDrmCommon->Connect() );
       
   109     User::LeaveIfError( iDrmCommon->IsProtectedFile( aFname, isDcf ) );
       
   110     if ( !isDcf )
       
   111         {
       
   112         CLOG(( ECodEng, 4, _L("  not DCF") ));
       
   113         User::Leave( KErrNotSupported );
       
   114         }
       
   115     DRMCommon::TContentProtection prot;
       
   116     TUint length;
       
   117     User::LeaveIfError( iDrmCommon->GetFileInfo
       
   118         ( aFname, prot, iType, iContentUri, length ) );
       
   119 #ifdef __TEST_COD_LOG
       
   120     TPtrC8 mime( iType->Des() );
       
   121     CLOG(( ECodEng, 4, \
       
   122         _L8("  inside DCF: MIME==<%S>, size(%u), prot(%d)"), \
       
   123         &mime, length, prot ));
       
   124 #endif /* def __TEST_COD_LOG */
       
   125     CheckTypeL( TDataType( *iType ) );
       
   126     delete iDrmCommon;
       
   127     iDrmCommon = NULL;    
       
   128     // For Forward-Locked and Combined Delivery messages, the
       
   129     // saved rights need to be cleaned up if something goes wrong.
       
   130     // Prepare for cleanup.
       
   131     if( prot != DRMCommon::ESuperDistributable )
       
   132         {
       
   133         CLOG(( ECodEng, 4, _L("  connect DRM Rights Client") ));
       
   134         User::LeaveIfError( iRightsClient.Connect() );
       
   135         }
       
   136     else
       
   137         {
       
   138         // No cleanup is required, delete uneeded members now.
       
   139         delete iContentUri;
       
   140         iContentUri = NULL;
       
   141         }
       
   142     CLOG(( ECodEng, 2, _L("<- CDrmHandler::ConstructL") ));
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CDrmHandler::CheckTypeL
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 void CDrmHandler::CheckTypeL( const TDataType& aType ) const
       
   150     {
       
   151 #ifdef __TEST_COD_LOG
       
   152     TPtrC8 mime( aType.Des8() );
       
   153     CLOG(( ECodEng, 4, _L8("-> CDrmHandler::CheckTypeL(%S)"), &mime ));
       
   154 #endif /* def __TEST_COD_LOG */
       
   155     __ASSERT_DEBUG( iDrmCommon, CodPanic( ECodInternal ) );
       
   156     TBool supported( EFalse );
       
   157     TDataType type;
       
   158     TInt i;
       
   159     User::LeaveIfError( iDrmCommon->DataTypesCount( i ) );
       
   160     for( i--; i >= 0; i-- )
       
   161         {
       
   162         User::LeaveIfError( iDrmCommon->SupportedDataType( i, type ) );
       
   163         if( type == aType )
       
   164             {
       
   165             supported = ETrue;
       
   166             break;
       
   167             }
       
   168         }
       
   169     if( !supported )
       
   170         {
       
   171         User::Leave( KMimeNotSupported );
       
   172         }
       
   173     CLOG(( ECodEng, 4, _L("<- CDrmHandler::CheckTypeL") ));
       
   174     }