commondrm/drmutility/src/drmutilitycommon.cpp
changeset 0 95b198f216e5
child 18 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 "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:  DRM Utility common functionality
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <drmpermission.h>
       
    21 #include <drmconstraint.h>
       
    22 
       
    23 #include "drmutilitycommon.h"
       
    24 #include "drmclockclient.h"
       
    25 #include "drmpointerarray.h"
       
    26 
       
    27 // ============================= LOCAL FUNCTIONS ===============================
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CDrmUtilityCommon::CDrmUtilityCommon
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 DRM::CDrmUtilityCommon::CDrmUtilityCommon()
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CDrmUtilityCommon::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void DRM::CDrmUtilityCommon::ConstructL()
       
    47     {
       
    48     User::LeaveIfError( iOmaClient.Connect() );
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CDrmUtilityCommon::NewLC
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C DRM::CDrmUtilityCommon* DRM::CDrmUtilityCommon::NewLC()
       
    58     {
       
    59     DRM::CDrmUtilityCommon* self( new( ELeave ) CDrmUtilityCommon() );
       
    60     
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     
       
    64     return self;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CDrmUtilityCommon::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C DRM::CDrmUtilityCommon* DRM::CDrmUtilityCommon::NewL()
       
    73     {
       
    74     DRM::CDrmUtilityCommon* self( NewLC() );
       
    75     
       
    76     CleanupStack::Pop( self );
       
    77     
       
    78     return self;
       
    79     }
       
    80 
       
    81 // Destructor
       
    82 DRM::CDrmUtilityCommon::~CDrmUtilityCommon()
       
    83     {
       
    84     iOmaClient.Close();
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CDrmUtilityCommon::GetOmaRightsStatusL
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //	
       
    92 EXPORT_C DRM::TDrmRightsInfo DRM::CDrmUtilityCommon::GetOmaRightsStatusL( 
       
    93     HBufC8*& aContentUri,
       
    94     ContentAccess::TIntent aIntent,
       
    95     CDRMConstraint* aConstraint )
       
    96     {
       
    97     CDRMPointerArray<CDRMPermission>* uriList( NULL );
       
    98     CDRMPointerArray<HBufC8>* individuals( NULL );
       
    99     RDRMClockClient clockClient;
       
   100     DRMClock::ESecurityLevel secLevel( DRMClock::KInsecure );
       
   101     TTime drmTime( Time::NullTTime() );
       
   102     TBool possiblefuture( EFalse );
       
   103     CDRMConstraint* constraint( NULL );
       
   104     CDRMConstraint* toplevel( NULL );
       
   105     TUint32 retval( 0 );
       
   106     TInt r( KErrNone );          
       
   107         
       
   108     r = clockClient.Connect();
       
   109     CleanupClosePushL( clockClient );
       
   110     if ( !r )
       
   111         {
       
   112         TInt timeZone( 0 );        
       
   113         clockClient.GetSecureTime( drmTime, timeZone, secLevel );
       
   114         }
       
   115                                       
       
   116     uriList = CDRMPointerArray<CDRMPermission>::NewLC();
       
   117     uriList->SetAutoCleanup( ETrue );
       
   118     TRAP_IGNORE( iOmaClient.GetDBEntriesL( *aContentUri, *uriList ) );                                  
       
   119                                       
       
   120     if ( !uriList->Count() )
       
   121         {
       
   122         CleanupStack::PopAndDestroy( 2, &clockClient ); //clockClient, uriList
       
   123         return DRM::EURightsInfoMissing;
       
   124         }
       
   125     
       
   126     individuals = CDRMPointerArray<HBufC8>::NewLC();
       
   127     individuals->SetAutoCleanup( ETrue );
       
   128     TRAP_IGNORE( iOmaClient.GetSupportedIndividualsL( *individuals ) );    
       
   129     
       
   130     // Now we have the time, rights and the individual constraints do the
       
   131     // checking. The rights are never valid if we get here so we don't have
       
   132     // to check for that
       
   133     for ( TInt i( 0 ); i < uriList->Count() && !possiblefuture ; i++ )
       
   134         {
       
   135         toplevel = NULL;
       
   136         constraint = NULL;
       
   137         
       
   138         // If the toplevel constraint is defined, get it:
       
   139         toplevel = (*uriList)[i]->TopLevelConstraint();
       
   140         // If constraint for the intent is defined, get it
       
   141         constraint = (*uriList)[i]->ConstraintForIntent( aIntent );
       
   142         
       
   143         // Top level constraint and constraint for intent, merge them
       
   144         if ( toplevel && constraint )
       
   145             {
       
   146             constraint->Merge( *toplevel );
       
   147             }
       
   148         // Only constraint for intent, use it
       
   149         else if ( constraint )
       
   150             {
       
   151             }
       
   152         // Only top level constraint or no constraints at all, continue
       
   153         else 
       
   154             {
       
   155             continue;
       
   156             }
       
   157                     
       
   158         // If the constraint is rejected due to non time reasons or there is no
       
   159         // time it can't be future
       
   160         constraint->Valid( drmTime, *individuals, retval );
       
   161         if ( retval & EConstraintCounter ||
       
   162              retval & EConstraintAccumulated ||
       
   163              retval & EConstraintTimedCounter ||
       
   164              retval & EConstraintIndividual ||
       
   165              retval & EConstraintNullDrmTime )
       
   166             {
       
   167             continue;
       
   168             }
       
   169         
       
   170         drmTime.HomeTime();
       
   171         
       
   172         // If the constrain has active start time and it is not valid,
       
   173         // it must be future
       
   174         if ( constraint->iActiveConstraints & EConstraintStartTime )
       
   175             {
       
   176             possiblefuture = ETrue;
       
   177             if ( aConstraint )
       
   178                 {
       
   179                 aConstraint->DuplicateL( *constraint );                       
       
   180                 }
       
   181             }
       
   182                 
       
   183         // If the constrain has active interval and itīs start time is in 
       
   184         // future, it must be future
       
   185         else if ( constraint->iActiveConstraints & EConstraintInterval &&
       
   186                   constraint->iIntervalStart > drmTime )
       
   187             {
       
   188             possiblefuture = ETrue;
       
   189             if ( aConstraint )
       
   190                 {
       
   191                 aConstraint->DuplicateL( *constraint );                     
       
   192                 }
       
   193             }
       
   194         } // End of for loop
       
   195         
       
   196 	CleanupStack::PopAndDestroy( 3, &clockClient ); //individuals, urilist, 
       
   197                                                     //clockClient
       
   198 	return possiblefuture ? DRM::EURightsInfoFuture : DRM::EURightsInfoExpired;
       
   199 	}
       
   200 	
       
   201 //  End of File