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