omadrm/drmengine/server/src/drmconsume.cpp
changeset 23 493788a4a8a4
parent 0 95b198f216e5
child 48 c68061d56109
--- a/omadrm/drmengine/server/src/drmconsume.cpp	Tue Feb 02 00:21:44 2010 +0200
+++ b/omadrm/drmengine/server/src/drmconsume.cpp	Fri Apr 16 15:14:55 2010 +0300
@@ -20,16 +20,16 @@
 #include "drmconsume.h"
 #include "drmenginetypedefs.h"
 #include "drmrightsdb.h"
-#include "drmrightsserver.h"
-#include "drmdbsession.h"
+#include "DRMRightsServer.h"
+#include "DRMDbSession.h"
 #include "drmlog.h"
-#include "drmeventmodify.h"
-#include "drmnotifier.h"
+#include "DRMEventModify.h"
+#include "DRMNotifier.h"
 #ifdef RD_DRM_METERING
 #include "drmmeteringdb.h"
 #include "drmmeteringdbdata.h"
-#include "roapstorageclient.h"
-#include "drmricontext.h"
+#include "RoapStorageClient.h"
+#include "DRMRIContext.h"
 #endif
 
 // EXTERNAL DATA STRUCTURES
@@ -42,17 +42,17 @@
 
 #define DB static_cast< CDRMRightsServer* >( const_cast< CServer2* >( \
            iSession.Server() ) )->Database()
-           
+
 #define SECURETIME( a ) static_cast< CDRMRightsServer* >\
            ( const_cast< CServer2* >( \
            iSession.Server() ) )->GetSecureTime( a )
-           
+
 #define SERVER static_cast< CDRMRightsServer* >( const_cast< CServer2* >( \
            iSession.Server() ) )
-           
+
 #ifdef RD_DRM_METERING
 #define METERINGDB static_cast< CDRMRightsServer* >( const_cast< CServer2* >( \
-           iSession.Server() ) )->MeteringDatabase() 
+           iSession.Server() ) )->MeteringDatabase()
 #endif
 
 #define SETBIT( a, b ) ( a ) |= ( b )
@@ -69,7 +69,7 @@
 // These keep track whether to decrease timed counters when consuming time
 // based stuff (iTimedCounts member). A used timed count bit is set to zero.
 // In the beginning all of these are set to one.
-//static const TUint8 KParentToplevelCount =     0x01;    
+//static const TUint8 KParentToplevelCount =     0x01;
 //static const TUint8 KParentPermCount     =     0x02;
 static const TUint8 KChildToplevelCount  =     0x04;
 static const TUint8 KChildPermCount      =     0x08;
@@ -96,7 +96,7 @@
         aFirst = aSecond;
         }
     }
-    
+
 // ------------------------------------------------------------------------
 // PickSmaller (overloaded)
 //
@@ -111,7 +111,7 @@
         aFirst = aSecond;
         }
     }
-    
+
 // ============================ MEMBER FUNCTIONS ==========================
 
 // ------------------------------------------------------------------------
@@ -124,13 +124,13 @@
     {
     DRMLOG( _L( "CDRMConsume::NewLC" ) );
     CDRMConsume* self = new( ELeave ) CDRMConsume( aSession );
-    
+
     CleanupStack::PushL( self );
-    
+
     self->ConstructL( aURI, aParentId );
-    
+
     DRMLOG( _L( "CDRMConsume::NewLC ok" ) );
-    return self;    
+    return self;
     }
 
 // ------------------------------------------------------------------------
@@ -141,10 +141,10 @@
     {
     DRMLOG( _L( "CDRMConsume::~" ) );
     TInt error( KErrNone );
-    
-    if( IsActive() ) 
+
+    if( IsActive() )
         {
-        Cancel();        
+        Cancel();
         }
     else
         {
@@ -156,7 +156,7 @@
     #endif
     // ignore errors
     //TRAP( error, UpdateDBL() );
-    
+
     delete iURI; iURI = NULL;
     delete iParentId; iParentId = NULL;
     delete iChild; iChild = NULL;
@@ -185,7 +185,7 @@
     iCumulativeDelayTop( 0 ),
     iCumulativeDelayChild( 0 ),
     iTotalCumulativeTime( 0 ),
-	iUsingTimedCount( 0 )
+    iUsingTimedCount( 0 )
     {
     }
 
@@ -201,7 +201,7 @@
     iURI = aURI.AllocL();
     if( aParentId )
         {
-        iParentId = aParentId->AllocL();        
+        iParentId = aParentId->AllocL();
         }
     }
 
@@ -212,11 +212,11 @@
 void CDRMConsume::HandleL( ContentAccess::TIntent aIntent )
     {
     DRMLOG( _L( "CDRMConsume::HandleL" ) );
-    
+
     TTime time;
     TBool secure( SECURETIME( time ) );
     InitializeL( aIntent, secure, time );
-    
+
     DRMLOG( _L( "CDRMConsume::HandleL ok" ) );
     }
 
@@ -227,9 +227,9 @@
 void CDRMConsume::Pause()
     {
     DRMLOG( _L( "CDRMConsume::Pause" ) );
-    
+
     Cancel();
-    
+
     DRMLOG( _L( "CDRMConsume::Pause ok" ) );
     }
 
@@ -240,15 +240,15 @@
 void CDRMConsume::ContinueL()
     {
     DRMLOG( _L( "CDRMConsume::ContinueL" ) );
-    
+
     Cancel();
-    
+
     TInt error = KErrNone;
     TUint32 reason = 0;
-                    
+
     CDRMPermission* child = NULL;
     HBufC8* parent = NULL;
-    
+
     // This got removed by Pause()
     if( iCountConstraintActive )
         {
@@ -256,48 +256,48 @@
         DoContinueL();
         return;
         }
-    
-    /* Fetch the RO again in order to manage a situation when another 
+
+    /* Fetch the RO again in order to manage a situation when another
        instance has used the same RO (content has been consumed) while the
-       other instance has not been used (player is paused) but will be 
-       used again (content consumption is to be continued). */   
+       other instance has not been used (player is paused) but will be
+       used again (content consumption is to be continued). */
     error = iSession.FindRightsObject( iIntent, *iURI, child, parent, reason );
-    
+
     /* Check if the RO found from the database matches with the one that was used
        in the original consumption of the content. If the ROs match, use the
        (possibly updated) one from the database. */
-    if ( !error && child && iChild && 
+    if ( !error && child && iChild &&
          ( iChild->iUniqueID == child->iUniqueID ) &&
          ( iChild->iOriginalInsertTime == child->iOriginalInsertTime ) )
         {
         if ( iParentId )
             {
-            delete iParentId; 
+            delete iParentId;
             iParentId = parent;
             }
-            
+
         delete iChild;
         iChild = child;
-        }      
-    else 
+        }
+    else
         {
         /* The original RO was not found. Delete temporary objects and also
            delete the iChild and iCombined because the RO is no longer valid and
-           need to be re-fetched using InitializeL method (in DoContinueL).   
-           (in DoContinueL). */  
+           need to be re-fetched using InitializeL method (in DoContinueL).
+           (in DoContinueL). */
         if ( iChild )
             {
             delete iChild;
             iChild = NULL;
             }
-        
+
         if ( iCombined )
             {
             delete iCombined;
             iCombined = NULL;
             }
-        
-        if ( child ) 
+
+        if ( child )
             {
             delete child;
             child = NULL;
@@ -307,12 +307,12 @@
             delete parent;
             parent = NULL;
             }
-        } 
-          
+        }
+
     DoContinueL();
-    
+
     //HandleL( iIntent );
-    
+
     DRMLOG( _L( "CDRMConsume::ContinueL ok" ) );
     }
 
@@ -323,16 +323,16 @@
 void CDRMConsume::Stop()
     {
     DRMLOG( _L( "CDRMConsume::Stop" ) );
-    
+
     Cancel();
-    
+
     DRMLOG( _L( "CDRMConsume::Stop ok" ) );
-    }   
+    }
 
 // ------------------------------------------------------------------------
 // CDRMConsume:: ActivateL
 //
-// Calculate the smallest end time based on interval, end time, 
+// Calculate the smallest end time based on interval, end time,
 // accumulated time & timed count.
 // ------------------------------------------------------------------------
 //
@@ -340,33 +340,33 @@
                              const TTime& aTrustedTime  )
     {
     DRMLOG( _L( "CDRMConsume::ActivateL" ) );
-    
+
     __ASSERT_DEBUG( iChild && iCombined, User::Invariant() );
     TTime endTime( Time::MaxTTime() );
     TTimeIntervalSeconds timed( KMaxTInt32 );
     TBool timeUsed( EFalse );
     TBool endTimeUsed( EFalse );
-    
+
     iCurrentDelay = 0;
-    
+
     if ( iCombined->iActiveConstraints & EConstraintTimedCounter )
         {
-        // Take this, even if timed counts have been updated. 
-        // This might cause unnecessary RunL's to be called, but it 
+        // Take this, even if timed counts have been updated.
+        // This might cause unnecessary RunL's to be called, but it
         // ensures both child & parent will be consumed when needed.
-        // If e.g. it would be checked that iTimedCounts == 0xf, 
+        // If e.g. it would be checked that iTimedCounts == 0xf,
         // either one (child or parent) might not get updated in case of
-        // "Child expired, but parent didn't -> find new child".        
+        // "Child expired, but parent didn't -> find new child".
         PickSmaller( timed, iCombined->iTimedInterval );
         timeUsed = ETrue;
         }
-    
+
     if ( iCombined->iActiveConstraints & EConstraintAccumulated )
         {
         PickSmaller( timed, iCombined->iAccumulatedTime );
         timeUsed = ETrue;
         }
-        
+
     if ( iCombined->iActiveConstraints & EConstraintInterval )
         {
         if ( iCombined->iIntervalStart != Time::NullTTime() )
@@ -378,46 +378,46 @@
         else
             {
             TInt64 tmp( iCombined->iInterval.Int() );
-            
+
             PickSmaller( timed, tmp );
             timeUsed = ETrue;
             }
         }
-     
+
     if ( iCombined->iActiveConstraints & EConstraintEndTime )
         {
         PickSmaller( endTime, iCombined->iEndTime );
         endTimeUsed = ETrue;
         }
-        
+
     // Put the "smallest time" information to "endTime".
     if ( timeUsed )
         {
         TTime current( aTrustedTime );
-        
+
         current += timed;
-        
+
         PickSmaller( endTime, current );
         endTimeUsed = ETrue;
         }
-        
+
      // Interval gets initialised immediately, and so do count constraints.
-     // Timed/accumulated won't: those are consumed after the 
+     // Timed/accumulated won't: those are consumed after the
      // interval if secure time exists.
      Consume( ETrue, ETrue, EFalse, 0,
               aSecureTime,
               aTrustedTime );
-    
+
      // In case something was modified, update the db also.
      UpdateDBL();
-              
+
      if ( endTimeUsed )
-        {     
+        {
         // Something exists.
         TTimeIntervalSeconds secs( 0 );
         TTime current( aTrustedTime );
         TInt err( KErrNone );
-        
+
         // SecondsFrom returns an error if the difference is too great.
         err = endTime.SecondsFrom( current, secs );
         if ( err )
@@ -436,45 +436,45 @@
             {
             iCurrentDelay = KConsumeDefaultTimer;
             }
-           
+
         if ( !IsAdded() )
             {
             CActiveScheduler::Add( this );
             }
-        
-        DRMLOG2( _L( "CDRMConsume::ActivateL: using interval %d" ), 
+
+        DRMLOG2( _L( "CDRMConsume::ActivateL: using interval %d" ),
                   ( TInt )iCurrentDelay );
-                  
+
         // secs -> microsecs. The method sets the AO active.
         After( TTimeIntervalMicroSeconds32( iCurrentDelay * 1000000 ) );
-        
+
         iTime = current;
-      
-        // If we see timed things here, we also have secure time.  
+
+        // If we see timed things here, we also have secure time.
         //SETBIT( iMask, KConsumeHasSecureTime );
         }
     else    // For metering we always need to have this:
         {
         iCurrentDelay = KConsumeDefaultTimer;
         iTime = aTrustedTime;
- 
+
         if ( !IsAdded() )
             {
             CActiveScheduler::Add( this );
             }
-                
-        DRMLOG2( _L( "CDRMConsume::ActivateL: using interval %d" ), 
+
+        DRMLOG2( _L( "CDRMConsume::ActivateL: using interval %d" ),
                   ( TInt )iCurrentDelay );
-                  
+
         // secs -> microsecs. The method sets the AO active.
-        After( TTimeIntervalMicroSeconds32( iCurrentDelay * 1000000 ) );              
-        }    
-        
-    // If we see timed things here, we also have secure time.  
+        After( TTimeIntervalMicroSeconds32( iCurrentDelay * 1000000 ) );
+        }
+
+    // If we see timed things here, we also have secure time.
     if( aTrustedTime != Time::NullTTime())
         {
-        SETBIT( iMask, KConsumeHasSecureTime );        
-        }      
+        SETBIT( iMask, KConsumeHasSecureTime );
+        }
     DRMLOG( _L( "CDRMConsume::ActivateL ok" ) );
     }
 
@@ -482,7 +482,7 @@
 // CDRMConsume:: Consume
 //
 // Consume child & parent. Whether to consume parent's explicit
-// usage permission: the information is returned earlier by 
+// usage permission: the information is returned earlier by
 // FindRightsObjectL.
 // ------------------------------------------------------------------------
 //
@@ -494,22 +494,22 @@
                            const TTime& aTrustedTime )
     {
     DRMLOG( _L( "CDRMConsume::Consume" ) );
-    
+
     __ASSERT_DEBUG( iChild && iCombined, User::Invariant() );
-    
+
     // Decrease timed counters & regular counters only once.
-    // In the beginning the bitmasks are both 0xF.     
+    // In the beginning the bitmasks are both 0xF.
     if ( iChild->TopLevelConstraint() )
         {
         if ( ConsumeConstraint( *( iChild->TopLevelConstraint() ),
-                                ( aUpdateCounter && 
+                                ( aUpdateCounter &&
                                   ISSET( iCounters, KChildToplevelCount ) ),
                                 aInitInterval,
-                                ( aUpdateTimedCount && 
-                                  ISSET( iTimedCounts, 
+                                ( aUpdateTimedCount &&
+                                  ISSET( iTimedCounts,
                                          KChildToplevelCount ) ),
                                 aElapsedTime,
-                                aSecureTime, 
+                                aSecureTime,
                                 aTrustedTime,
                                 iCumulativeDelayTop ) )
             {
@@ -524,12 +524,12 @@
                 }
             }
         }
-        
+
     if ( ConsumeConstraint( *( iChild->ConstraintForIntent( iIntent ) ),
-                            ( aUpdateCounter && 
+                            ( aUpdateCounter &&
                               ISSET( iCounters, KChildPermCount ) ),
                             aInitInterval,
-                            ( aUpdateTimedCount && 
+                            ( aUpdateTimedCount &&
                               ISSET( iTimedCounts, KChildPermCount ) ),
                             aElapsedTime,
                             aSecureTime,
@@ -546,7 +546,7 @@
             CLRBIT( iCounters, KChildPermCount );
             }
         }
-    
+
     DRMLOG( _L( "CDRMConsume::Consume ok" ) );
     }
 
@@ -557,15 +557,15 @@
 void CDRMConsume::RunL()
     {
     DRMLOG2( _L( "CDRMConsume::RunL with %d" ), iStatus.Int() );
-    
+
     switch ( iStatus.Int() )
         {
         case KErrNone:
             // Normal completition.
-            
+
         case KErrUnderflow:
             // Time already passed.
-            
+
         case KErrAbort:
             // System time changed ==> consume.
             DoContinueL();
@@ -576,7 +576,7 @@
             // Handled in RunError.
             User::Leave( iStatus.Int() );
         };
-        
+
     DRMLOG( _L( "CDRMConsume::RunL ok" ) );
     }
 
@@ -591,9 +591,9 @@
 #endif
     {
     DRMLOG2( _L( "CDRMConsume::RunError: %d" ), aError );
-     
+
     Deque();
-    
+
     DRMLOG( _L( "CDRMConsume::RunError ok" ) );
     return 0;
     }
@@ -605,10 +605,10 @@
 void CDRMConsume::DoCancel()
     {
     DRMLOG( _L( "CDRMConsume::DoCancel" ) );
-    
+
     TInt error( KErrNone );
     TRAP( error, DoCancelL() );
-    
+
     DRMLOG2( _L( "CDRMConsume::DoCancel: %d" ), error );
     }
 
@@ -619,51 +619,51 @@
 void CDRMConsume::DoCancelL()
     {
     DRMLOG( _L( "CDRMConsume::DoCancelL" ) );
-    
+
     if ( iCurrentDelay )
         {
         TTimeIntervalSeconds secs;
         TTime trustedTime;
         TBool secureTime;
-                        
+
         CTimer::DoCancel();
-                
+
         secureTime = SECURETIME( trustedTime );
         trustedTime.SecondsFrom( iTime, secs );
-        
+
         #ifdef RD_DRM_METERING
             // Update total cumulative time for content metering purposes
             iTotalCumulativeTime = iTotalCumulativeTime.Int() + secs.Int();
         #endif
-             
+
         // If the top level timed counter has not been activated yet
         // increment the counter
         if( ISSET( iTimedCounts, KChildToplevelCount ) )
             {
-            iCumulativeDelayTop = iCumulativeDelayTop.Int() + secs.Int();            
+            iCumulativeDelayTop = iCumulativeDelayTop.Int() + secs.Int();
             }
 
         // If the child timed counter has not been activated yet
-        // increment the counter            
+        // increment the counter
         if( ISSET( iTimedCounts, KChildPermCount ) )
             {
             iCumulativeDelayChild = iCumulativeDelayChild.Int() + secs.Int();
             }
-            
+
         // Always >= 0.
         ConsumeTimedItemsL( secs,
-                            secureTime, 
+                            secureTime,
                             trustedTime );
         iCurrentDelay = 0;
         }
-    
+
     UpdateDBL();
-    
+
     if ( SERVER->HasActiveCountConstraint( *iURI ) )
         {
         SERVER->RemoveActiveCountConstraint( *iURI );
         }
-    
+
     DRMLOG( _L( "CDRMConsume::DoCancel ok" ) );
     }
 
@@ -677,20 +677,20 @@
 void CDRMConsume::CombinePermissionsL()
     {
     DRMLOG( _L( "CDRMConsume::CombinePermissions" ) );
-    
+
     __ASSERT_DEBUG( iChild, User::Invariant() );
-    
+
     // Reset
     delete iCombined; iCombined = NULL;
     iCombined = CDRMConstraint::NewL();
-    
+
     if ( iChild->TopLevelConstraint() )
         {
         iCombined->Merge( *( iChild->TopLevelConstraint() ) );
         }
-        
+
     iCombined->Merge( *( iChild->ConstraintForIntent( iIntent ) ) );
-    
+
     DRMLOG( _L( "CDRMConsume::CombinePermissions ok" ) );
     }
 
@@ -704,20 +704,20 @@
     {
     DRMLOG( _L( "CDRMConsume::UpdateDBL" ) );
     // __ASSERT_DEBUG( iChild, User::Invariant() );
-        
+
     CDRMEventModify* event = NULL;
     TRequestStatus status;
-        
-    if( ISSET( iMask, KConsumeChildModified ) ) 
+
+    if( ISSET( iMask, KConsumeChildModified ) )
         {
         event = CDRMEventModify::NewL();
         }
-    CleanupStack::PushL( event );    
+    CleanupStack::PushL( event );
 
     if ( ISSET( iMask, KConsumeChildModified ) )
         {
         DRMLOG( _L( "CDRMConsume: commiting child to DB" ) );
-        
+
         if( iParentId )
             {
             DB.UpdateDBEntryL( *iParentId, *iChild );
@@ -727,30 +727,30 @@
             }
         else
             {
-            DB.UpdateDBEntryL( *iURI, *iChild );            
+            DB.UpdateDBEntryL( *iURI, *iChild );
             // Notify
             event->SetContentIDL(*iURI);
             event->SetUniqueID(iChild->iUniqueID);
-            }    
-        
+            }
+
         // Notify
         event->SetContentIDL(*iURI);
         event->SetUniqueID(iChild->iUniqueID);
-        
+
         NOTIFIER.SendEventL(*event,status);
-        User::WaitForRequest(status);           
-        
+        User::WaitForRequest(status);
+
         CLRBIT( iMask, KConsumeChildModified );
         }
-    
-    CleanupStack::PopAndDestroy();    
+
+    CleanupStack::PopAndDestroy();
     DRMLOG( _L( "CDRMConsume::UpdateDBL ok" ) );
     }
 // ------------------------------------------------------------------------
 // CDRMConsume::ConsumeConstraint
 //
 // Consume child & parent. Whether to consume parent's explicit
-// usage permission: the information is returned earlier by 
+// usage permission: the information is returned earlier by
 // FindRightsObjectL.
 // ------------------------------------------------------------------------
 //
@@ -764,18 +764,18 @@
                                       TTimeIntervalSeconds& aCumulativeTime )
     {
     DRMLOG( _L( "CDRMConsume::ConsumeConstraints" ) );
-    
+
     TBool res( EFalse );
-    
-    if ( aUpdateCounter && 
+
+    if ( aUpdateCounter &&
          ( aConstraint.iActiveConstraints & EConstraintCounter ) )
         {
         --( aConstraint.iCounter);
         res = ETrue;
         iCountConstraintActive = ETrue;
-        TRAP_IGNORE( SERVER->AddActiveCountConstraintL( *iURI ) ); 
+        TRAP_IGNORE( SERVER->AddActiveCountConstraintL( *iURI ) );
         }
-        
+
     if ( aInitInterval &&
          ( aConstraint.iActiveConstraints & EConstraintInterval ) &&
          aSecureTime &&
@@ -784,10 +784,10 @@
         aConstraint.iIntervalStart = aTrustedTime;
         res = ETrue;
         }
-        
+
     /* change to timed counter, we don't check the latest time, we check the
-    cumulated time */    
-        
+    cumulated time */
+
     if ( aUpdateTimedCount &&
          ( aConstraint.iActiveConstraints & EConstraintTimedCounter &&
            ( aCumulativeTime >= aConstraint.iTimedInterval ||
@@ -796,7 +796,7 @@
         --( aConstraint.iTimedCounter );
         res = ETrue;
         iCountConstraintActive = ETrue;
-        TRAP_IGNORE( SERVER->AddActiveCountConstraintL( *iURI ) ); 
+        TRAP_IGNORE( SERVER->AddActiveCountConstraintL( *iURI ) );
         aCumulativeTime = TTimeIntervalSeconds( 0 );
         }
     else if ( aUpdateTimedCount &&
@@ -804,26 +804,26 @@
         {
         iUsingTimedCount = ETrue;
         }
-        
-    
+
+
     if ( aElapsedTime.Int() != 0 &&
          ( aConstraint.iActiveConstraints & EConstraintAccumulated ) )
         {
         __ASSERT_DEBUG( aElapsedTime.Int() > 0, User::Invariant() );
-        
+
         if ( aConstraint.iAccumulatedTime < aElapsedTime )
             {
             aConstraint.iAccumulatedTime = 0;
             }
         else
             {
-            aConstraint.iAccumulatedTime = aConstraint.iAccumulatedTime.Int() - 
-            	aElapsedTime.Int();
+            aConstraint.iAccumulatedTime = aConstraint.iAccumulatedTime.Int() -
+                aElapsedTime.Int();
             }
-        
+
         res = ETrue;
         }
-        
+
     if ( !iCountConstraintActive && aConstraint.Expired( aTrustedTime ) )
         {
         iExpired = ETrue;
@@ -832,11 +832,11 @@
         {
         iExpired = EFalse;
         }
-    
-    DRMLOG2( 
-        _L( "CDRMConsume::ConsumeConstraints ok, returning %d" ), 
+
+    DRMLOG2(
+        _L( "CDRMConsume::ConsumeConstraints ok, returning %d" ),
         ( TInt )res );
-        
+
     return res;
     }
 
@@ -849,7 +849,7 @@
                                       const TTime& aTrustedTime )
     {
     DRMLOG( _L( "CDRMConsume::ConsumeTimedItemsL" ) );
-    
+
     // Update accumulated constraints & timed count.
     Consume( EFalse,
              ETrue,
@@ -857,7 +857,7 @@
              aDelay,
              aSecureTime,
              aTrustedTime );
-    
+
     DRMLOG( _L( "CDRMConsume::ConsumeTimedItems ok" ) );
     }
 
@@ -868,29 +868,29 @@
 void CDRMConsume::DoContinueL()
     {
     DRMLOG( _L( "CDRMConsume::DoContinueL" ) );
-    
+
     TTime time;
     TBool secureTime( EFalse );
     secureTime = SECURETIME( time );
-    
+
     if ( !iChild || !iCombined )
         {
         InitializeL( iIntent, secureTime, time );
         // User::Leave( KErrCANoRights );
         return;
         }
-   
+
     ConsumeTimedItemsL( iCurrentDelay, secureTime, time );
     UpdateDBL();
     iCurrentDelay = 0;
-    
+
     CombinePermissionsL();
-    
+
     // If the content has expired, find new permissions, unless the expired
     // constraint was a timed count. In that case, the constraint
     // did not really expire.
     if ( SecurityLevelChanged( secureTime ) ||
-         ( iCombined->Expired( time ) && 
+         ( iCombined->Expired( time ) &&
            !SERVER->HasActiveCountConstraint( *iURI ) ) )
         {
         InitializeL( iIntent, secureTime, time );
@@ -899,7 +899,7 @@
         {
         ActivateL( secureTime, time );
         }
-        
+
     DRMLOG( _L( "CDRMConsume::DoContinueL ok" ) );
     }
 
@@ -910,13 +910,13 @@
 TBool CDRMConsume::SecurityLevelChanged( TBool aSecureTime ) const
     {
     DRMLOG( _L( "CDRMConsume::SecurityLevelChanged" ) );
-    
+
     if ( ( ISSET( iMask, KConsumeHasSecureTime ) && aSecureTime ) ||
          !( ISSET( iMask, KConsumeHasSecureTime ) || aSecureTime ) )
         {
         return EFalse;
         }
-        
+
     return ETrue;
     }
 
@@ -929,73 +929,73 @@
                                const TTime& aTrustedTime )
     {
     DRMLOG( _L( "CDRMConsume::InitializeL" ) );
-    
+
     // aIntent is either EPlay, EView, EExecute or EPrint.
-    // Store the old  consumption information in case this is 
+    // Store the old  consumption information in case this is
     // called in case of "ran out of permissions, find new ones"
     CDRMPermission* child( iChild );
     TUint8 timedCounts( iTimedCounts );
     TUint8 counters( iCounters );
     TUint32 reason = 0;
-    
+
     // Reset.
     iTimedCounts = 0xf;
     iCounters = 0xf;
     iMask = 0x0;
     iCurrentDelay = 0;
-    
+
     iExpired = ETrue;
-    
+
     delete iCombined; iCombined = NULL;
-    
-    // Previous child & parent need to be stored in case the internal 
+
+    // Previous child & parent need to be stored in case the internal
     // counter states need to be restored.
     if ( child )
         {
         CleanupStack::PushL( child );
         iChild = NULL;
         }
-    
+
     // If the next call won't leave, we have permissions.
-    User::LeaveIfError( iSession.FindRightsObject( aIntent, 
+    User::LeaveIfError( iSession.FindRightsObject( aIntent,
                                                    *iURI,
                                                    iChild,
                                                    iParentId,
                                                    reason ) );
-                                
+
     User::LeaveIfError( iSession.VerifyCredentials( iURI, iChild, aIntent ) );
-                                
+
     iExpired = EFalse;
 
     // Check whether to restore the internal state.
-    if ( iIntent == aIntent ) 
+    if ( iIntent == aIntent )
         {
-        if ( child && 
+        if ( child &&
              ( child->iUniqueID == iChild->iUniqueID ) )
             {
             DRMLOG( _L( "CDRMConsume: using the previous child" ) );
-            
-            CLRBIT( iTimedCounts, 
+
+            CLRBIT( iTimedCounts,
                     ( KChildToplevelCount | KChildPermCount ) & ~timedCounts );
-                    
+
             CLRBIT( iCounters,
                     ( KChildToplevelCount | KChildPermCount ) & ~counters );
             }
         }
-    
+
     if ( child )
         {
         CleanupStack::PopAndDestroy();
         }
-    
+
     iIntent = aIntent;
-    
+
     CombinePermissionsL();
     ActivateL( aSecureTime, aTrustedTime );
 
     DRMLOG( _L( "CDRMConsume::InitializeL ok" ) );
     }
-    
+
 // ------------------------------------------------------------------------
 // CDRMConsume::CountConstraintActive
 // ------------------------------------------------------------------------
@@ -1031,65 +1031,65 @@
 //
 void CDRMConsume::UpdateMeteringDbL()
     {
-    DRMLOG( _L( "CDRMConsume::UpdateMeteringDbL" ) ); 
+    DRMLOG( _L( "CDRMConsume::UpdateMeteringDbL" ) );
     TTimeIntervalSeconds graceTime = 0;
     CDRMConstraint* constraint = NULL;
-             
+
     if ( iChild )
         {
-        constraint = iChild->ConstraintForIntent( iIntent ); 
-        if ( constraint && constraint->iDrmMeteringInfo )  
-            { 
-            
+        constraint = iChild->ConstraintForIntent( iIntent );
+        if ( constraint && constraint->iDrmMeteringInfo )
+            {
+
             graceTime = constraint->iDrmMeteringInfo->iGraceTime;
-            
-            // Grace time exceeded, increase metering count and metering 
-            // accumulated time    
-            if ( iTotalCumulativeTime >= graceTime )  
+
+            // Grace time exceeded, increase metering count and metering
+            // accumulated time
+            if ( iTotalCumulativeTime >= graceTime )
                 {
                 // Check Rights Issuer rights from Roap storage
-                if ( !CheckRiContextRightsL( iChild->iRiId ) )    
+                if ( !CheckRiContextRightsL( iChild->iRiId ) )
                     {
                     return;
                     }
-                
+
                 // Update database only if Rights Issuer Id is available
-                if ( ( iChild->iRiId.Length() > 0 ) && 
-                     ( iChild->iRiId.Length() <= KRiIdSize ) ) 
+                if ( ( iChild->iRiId.Length() > 0 ) &&
+                     ( iChild->iRiId.Length() <= KRiIdSize ) )
                     {
-                    
+
                     if ( iURI )
                         {
-                        CDrmMeteringDbData* meteringData = 
+                        CDrmMeteringDbData* meteringData =
                             CDrmMeteringDbData::NewLC();
                         meteringData->iContentId = iURI->AllocL();
-                        meteringData->iRiId = iChild->iRiId; 
-                        if( iUsingTimedCount && !iCountConstraintActive ) 
+                        meteringData->iRiId = iChild->iRiId;
+                        if( iUsingTimedCount && !iCountConstraintActive )
                             {
-                            meteringData->iCount = 0;                            
+                            meteringData->iCount = 0;
                             }
                         else
                             {
                         meteringData->iCount = 1;
                             }
-                            
+
                         meteringData->iAccumulatedTime = iTotalCumulativeTime;
-                        
-                        if ( iParentId ) 
+
+                        if ( iParentId )
                             {
                             meteringData->iParentUid = iParentId->AllocL();
                             }
-                 
+
                         METERINGDB.AddL( meteringData );
                         CleanupStack::PopAndDestroy(); // meteringData
-                        }            
+                        }
                     }
-                } 
-            }             
+                }
+            }
         }
         DRMLOG( _L( "CDRMConsume::UpdateMeteringDbL ok" ) );
     }
-    
+
 // ------------------------------------------------------------------------
 // CDRMConsume::CheckRiContextRightsL
 // ------------------------------------------------------------------------
@@ -1097,40 +1097,40 @@
 
 TBool CDRMConsume::CheckRiContextRightsL( const TDesC8& aRiId )
     {
-    
+
     DRMLOG( _L( "CDRMConsume::CheckRiContextRightsL" ) );
-    
+
     CDRMRIContext* riContext = NULL;
-    TBool haveRights = EFalse; 
-  
-    // Connect to the storage of the registered Rights Issuers 
-    
+    TBool haveRights = EFalse;
+
+    // Connect to the storage of the registered Rights Issuers
+
     if( iSession.ConnectRoapClient() == KErrNone )
         {
     riContext = iSession.RoapClient().GetRIContextL( aRiId );
-     
+
     if ( riContext == NULL )
         {
         DRMLOG( _L ( "RI not registered" ) );
         User::Leave( KErrRightsServerRiNotRegistered );
         }
-        
-    // Check (via the Rights Issuer context) whether Rights Issuer 
+
+    // Check (via the Rights Issuer context) whether Rights Issuer
     // is allowed to use metering or not
     if ( riContext->IsMeteringAllowed() )
         {
         haveRights = ETrue;
         }
-        
-    if ( riContext ) 
+
+    if ( riContext )
         {
         delete riContext;
-        riContext = NULL;    
+        riContext = NULL;
         }
         }
-        
+
     return haveRights;
-    
+
     }
 
 #endif