commondrm/drmutility/src/drmutilitywmdrmutilities.cpp
changeset 23 493788a4a8a4
parent 0 95b198f216e5
equal deleted inserted replaced
5:79d62d1d7957 23:493788a4a8a4
    17 
    17 
    18 
    18 
    19 #include <e32std.h>
    19 #include <e32std.h>
    20 #include <DRMRights.h>
    20 #include <DRMRights.h>
    21 
    21 
    22 #include "drmclockclient.h"
    22 #include "DRMClockClient.h"
    23 #include "drmutilitywmdrmutilities.h"
    23 #include "drmutilitywmdrmutilities.h"
    24 #include "drmrights.h"
    24 #include "DRMRights.h"
    25 
    25 
    26 // CONSTANTS
    26 // CONSTANTS
    27 _LIT( KLicenseType, "licensetype=" );
    27 _LIT( KLicenseType, "licensetype=" );
    28 _LIT( KTime, "time" );
    28 _LIT( KTime, "time" );
    29 _LIT( KCount, "count" );
    29 _LIT( KCount, "count" );
    61 
    61 
    62 LOCAL_C TBool ParseString( TChar aChar, TLex& aLex, TPtrC16& aPtr )
    62 LOCAL_C TBool ParseString( TChar aChar, TLex& aLex, TPtrC16& aPtr )
    63     {
    63     {
    64     TBool found( EFalse );
    64     TBool found( EFalse );
    65     aLex.Mark();
    65     aLex.Mark();
    66     
    66 
    67     while ( !aLex.Eos() && found == EFalse )
    67     while ( !aLex.Eos() && found == EFalse )
    68         {
    68         {
    69         TChar ch;
    69         TChar ch;
    70         ch = aLex.Get();
    70         ch = aLex.Get();
    71         if ( ch == aChar )
    71         if ( ch == aChar )
    75                 // Remove char from the token string and read it from the lex.
    75                 // Remove char from the token string and read it from the lex.
    76                 aLex.UnGet();
    76                 aLex.UnGet();
    77                 aPtr.Set( aLex.MarkedToken() );
    77                 aPtr.Set( aLex.MarkedToken() );
    78                 aLex.Get();
    78                 aLex.Get();
    79                 }
    79                 }
    80             else 
    80             else
    81                 {
    81                 {
    82                 aPtr.Set( aLex.MarkedToken() );
    82                 aPtr.Set( aLex.MarkedToken() );
    83                 }
    83                 }
    84             found = ETrue;
    84             found = ETrue;
    85             }
    85             }
    96     TPtrC16 token( NULL, 0 );
    96     TPtrC16 token( NULL, 0 );
    97     TUint8 times( 0 );
    97     TUint8 times( 0 );
    98     TTime localTime( Time::NullTTime() );
    98     TTime localTime( Time::NullTTime() );
    99     TTime universalTime( Time::NullTTime() );
    99     TTime universalTime( Time::NullTTime() );
   100     TTimeIntervalSeconds timeDifference( 0 ); // local time - secure time
   100     TTimeIntervalSeconds timeDifference( 0 ); // local time - secure time
   101     TInt years, months, days, hours, minutes, secs; 
   101     TInt years, months, days, hours, minutes, secs;
   102     TChar ch;
   102     TChar ch;
   103     TLex lex;
   103     TLex lex;
   104     TTime drmTime;
   104     TTime drmTime;
   105     TInt timeZone;
   105     TInt timeZone;
   106     
   106 
   107     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
   107     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
   108     
   108 
   109     // The format of the start and end time strings is the following:
   109     // The format of the start and end time strings is the following:
   110     // "starttime=yy-mm-ddThh:mins:ssZ
   110     // "starttime=yy-mm-ddThh:mins:ssZ
   111     // "endtime=yy-mm-ddThh:mins:ssZ
   111     // "endtime=yy-mm-ddThh:mins:ssZ
   112     // where yy = years, mm = months, dd = days, hh = hours, 
   112     // where yy = years, mm = months, dd = days, hh = hours,
   113     // mins = minutes and ss = seconds, "-", "T", ":" and "Z" 
   113     // mins = minutes and ss = seconds, "-", "T", ":" and "Z"
   114     // are separators.     
   114     // are separators.
   115     while ( !aLex.Eos() && ( aLex.Peek() != 0 ) )
   115     while ( !aLex.Eos() && ( aLex.Peek() != 0 ) )
   116         {
   116         {
   117         // The next string should be start time, end time or then
   117         // The next string should be start time, end time or then
   118         // it does not exist.
   118         // it does not exist.
   119         ParseString( '=', aLex, token );
   119         ParseString( '=', aLex, token );
   120         
   120 
   121         if ( token.CompareF( KStartTime ) == 0 )
   121         if ( token.CompareF( KStartTime ) == 0 )
   122             {
   122             {
   123             times |= KFoundStartTime;
   123             times |= KFoundStartTime;
   124             } 
   124             }
   125         else if ( token.CompareF( KEndTime ) == 0 )
   125         else if ( token.CompareF( KEndTime ) == 0 )
   126             {
   126             {
   127             times |= KFoundEndTime;
   127             times |= KFoundEndTime;
   128             }
   128             }
   129         else 
   129         else
   130             {
   130             {
   131             // No start time ("starttime=") or end time ("endtime=")  
   131             // No start time ("starttime=") or end time ("endtime=")
   132             // string was found -> return   
   132             // string was found -> return
   133             return;
   133             return;
   134             }
   134             }
   135                
   135 
   136         if ( ( times & KFoundStartTime ) || ( times & KFoundEndTime ) )
   136         if ( ( times & KFoundStartTime ) || ( times & KFoundEndTime ) )
   137             {     
   137             {
   138             // Search for years, months, days, hours, minutes, secs     
   138             // Search for years, months, days, hours, minutes, secs
   139             if ( ParseString( '-', aLex, token ) )
   139             if ( ParseString( '-', aLex, token ) )
   140                 {
   140                 {
   141                 TLex lexYear( token );
   141                 TLex lexYear( token );
   142                 User::LeaveIfError( lexYear.Val( years ) );
   142                 User::LeaveIfError( lexYear.Val( years ) );
   143                 }
   143                 }
   144             else 
   144             else
   145                 {
   145                 {
   146                 User::Leave( KErrNotFound );    
   146                 User::Leave( KErrNotFound );
   147                 }
   147                 }
   148             
   148 
   149             if ( ParseString( '-', aLex, token ) )
   149             if ( ParseString( '-', aLex, token ) )
   150                 {
   150                 {
   151                 TLex lexMonths( token );
   151                 TLex lexMonths( token );
   152                 User::LeaveIfError( lexMonths.Val( months ) );
   152                 User::LeaveIfError( lexMonths.Val( months ) );
   153                 }
   153                 }
   154             else 
   154             else
   155                 {
   155                 {
   156                 User::Leave( KErrNotFound );    
   156                 User::Leave( KErrNotFound );
   157                 }
   157                 }
   158             
   158 
   159             if ( ParseString( 'T', aLex, token ) )
   159             if ( ParseString( 'T', aLex, token ) )
   160                 {
   160                 {
   161                 TLex lexDays( token );
   161                 TLex lexDays( token );
   162                 User::LeaveIfError( lexDays.Val( days ) );
   162                 User::LeaveIfError( lexDays.Val( days ) );
   163                 }
   163                 }
   164             else 
   164             else
   165                 {
   165                 {
   166                 User::Leave( KErrNotFound );    
   166                 User::Leave( KErrNotFound );
   167                 }
   167                 }
   168             
   168 
   169             if( ParseString( ':', aLex, token ) )
   169             if( ParseString( ':', aLex, token ) )
   170                 {
   170                 {
   171                 TLex lexHours( token );
   171                 TLex lexHours( token );
   172                 User::LeaveIfError( lexHours.Val( hours ) );
   172                 User::LeaveIfError( lexHours.Val( hours ) );
   173                 }
   173                 }
   174             else 
   174             else
   175                 {
   175                 {
   176                 User::Leave( KErrNotFound );
   176                 User::Leave( KErrNotFound );
   177                 }
   177                 }
   178             
   178 
   179             if ( ParseString( ':', aLex, token ) )
   179             if ( ParseString( ':', aLex, token ) )
   180                 {
   180                 {
   181                 TLex lexMinutes( token );
   181                 TLex lexMinutes( token );
   182                 User::LeaveIfError( lexMinutes.Val( minutes ) );
   182                 User::LeaveIfError( lexMinutes.Val( minutes ) );
   183                 }
   183                 }
   184             else 
   184             else
   185                 {
   185                 {
   186                 User::Leave( KErrNotFound );
   186                 User::Leave( KErrNotFound );
   187                 }
   187                 }
   188             
   188 
   189             if( ParseString( 'Z', aLex, token ) )
   189             if( ParseString( 'Z', aLex, token ) )
   190                 {
   190                 {
   191                 TLex lexSeconds( token );
   191                 TLex lexSeconds( token );
   192                 User::LeaveIfError( lexSeconds.Val( secs ) );
   192                 User::LeaveIfError( lexSeconds.Val( secs ) );
   193                 }
   193                 }
   194             else 
   194             else
   195                 {
   195                 {
   196                 User::Leave( KErrNotFound );
   196                 User::Leave( KErrNotFound );
   197                 }    
   197                 }
   198             
   198 
   199             ParseString( ';', aLex, token );
   199             ParseString( ';', aLex, token );
   200             token.Set( NULL, 0 );
   200             token.Set( NULL, 0 );
   201             
   201 
   202             TDateTime date( years, (TMonth)( months - 1 ), days - 1, hours, 
   202             TDateTime date( years, (TMonth)( months - 1 ), days - 1, hours,
   203                 minutes, secs, 0 );
   203                 minutes, secs, 0 );
   204             TTime dateTime( date );
   204             TTime dateTime( date );
   205             
   205 
   206             // Get secure time from DRM clock 
   206             // Get secure time from DRM clock
   207             RDRMClockClient client;
   207             RDRMClockClient client;
   208             
   208 
   209             User::LeaveIfError( client.Connect() );
   209             User::LeaveIfError( client.Connect() );
   210             client.GetSecureTime( drmTime, timeZone, secLevel );
   210             client.GetSecureTime( drmTime, timeZone, secLevel );
   211             client.Close();
   211             client.Close();
   212             
   212 
   213 			localTime.HomeTime();
   213             localTime.HomeTime();
   214 			        	
   214 
   215           	if ( secLevel == DRMClock::KSecure ) 
   215             if ( secLevel == DRMClock::KSecure )
   216           		{
   216                 {
   217 				// Calculate the difference between local time and secure time
   217                 // Calculate the difference between local time and secure time
   218             	localTime.SecondsFrom( drmTime, timeDifference );
   218                 localTime.SecondsFrom( drmTime, timeDifference );
   219             	}
   219                 }
   220 			else 
   220             else
   221 				{
   221                 {
   222 				// Calculate the difference between local and universal time	
   222                 // Calculate the difference between local and universal time
   223 				universalTime.UniversalTime();	
   223                 universalTime.UniversalTime();
   224 				localTime.SecondsFrom( universalTime, timeDifference ); 	
   224                 localTime.SecondsFrom( universalTime, timeDifference );
   225 				}
   225                 }
   226           	
   226 
   227 			dateTime += timeDifference;
   227             dateTime += timeDifference;
   228 			               
   228 
   229             if ( times & KFoundStartTime )
   229             if ( times & KFoundStartTime )
   230                 {
   230                 {
   231                 aStartTime = dateTime;
   231                 aStartTime = dateTime;
   232                 times &= ~KFoundStartTime;
   232                 times &= ~KFoundStartTime;
   233                 }
   233                 }
   246 //
   246 //
   247 EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmCountRightsL( TLex& aLex,
   247 EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmCountRightsL( TLex& aLex,
   248     TUint32& aCounts )
   248     TUint32& aCounts )
   249     {
   249     {
   250     TPtrC16 token( NULL, 0 );
   250     TPtrC16 token( NULL, 0 );
   251     TInt counts( 0 ); 
   251     TInt counts( 0 );
   252     TChar ch;
   252     TChar ch;
   253     TLex lex;
   253     TLex lex;
   254         
   254 
   255     ParseString( '=', aLex, token );
   255     ParseString( '=', aLex, token );
   256         
   256 
   257     if ( token.CompareF( KCountLeft ) == 0 )
   257     if ( token.CompareF( KCountLeft ) == 0 )
   258         {
   258         {
   259         ParseString( ';', aLex, token );
   259         ParseString( ';', aLex, token );
   260         TLex lexCount( token );
   260         TLex lexCount( token );
   261         User::LeaveIfError( lexCount.Val( counts ) );
   261         User::LeaveIfError( lexCount.Val( counts ) );
   262         aCounts = counts;
   262         aCounts = counts;
   263         return ETrue;
   263         return ETrue;
   264         }    
   264         }
   265     else 
   265     else
   266         {
   266         {
   267         // No counts left ("countleft=") string was found.
   267         // No counts left ("countleft=") string was found.
   268         // -> No count information was found, return EFalse
   268         // -> No count information was found, return EFalse
   269         return EFalse;
   269         return EFalse;
   270         }
   270         }
   272 
   272 
   273 // ----------------------------------------------------------------------------
   273 // ----------------------------------------------------------------------------
   274 // DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL
   274 // DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL
   275 // ----------------------------------------------------------------------------
   275 // ----------------------------------------------------------------------------
   276 //
   276 //
   277 EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL( TLex& aLex, 
   277 EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL( TLex& aLex,
   278     TTimeIntervalSeconds& aDuration )
   278     TTimeIntervalSeconds& aDuration )
   279     {
   279     {
   280     TPtrC16 token( NULL, 0 );
   280     TPtrC16 token( NULL, 0 );
   281     TChar ch;
   281     TChar ch;
   282     TInt duration( 0 );
   282     TInt duration( 0 );
   283         
   283 
   284     ParseString( '=', aLex, token );
   284     ParseString( '=', aLex, token );
   285         
   285 
   286     if ( token.CompareF( KDurationLeft ) == 0 )
   286     if ( token.CompareF( KDurationLeft ) == 0 )
   287         {
   287         {
   288         ParseString( ';', aLex, token );
   288         ParseString( ';', aLex, token );
   289         TLex lexDuration( token );
   289         TLex lexDuration( token );
   290         User::LeaveIfError( lexDuration.Val( duration ) );
   290         User::LeaveIfError( lexDuration.Val( duration ) );
   291         aDuration = duration;
   291         aDuration = duration;
   292         return ETrue;
   292         return ETrue;
   293         }
   293         }
   294     else 
   294     else
   295         {
   295         {
   296         // No duration left ("durationleft=") string was found.
   296         // No duration left ("durationleft=") string was found.
   297         // -> No duration information was found, return EFalse
   297         // -> No duration information was found, return EFalse
   298         return EFalse;
   298         return EFalse;
   299         }         
   299         }
   300     }
   300     }
   301 
   301 
   302 // ----------------------------------------------------------------------------
   302 // ----------------------------------------------------------------------------
   303 // DrmUtilityWmDrmUtilities::ParseWmDrmStringL
   303 // DrmUtilityWmDrmUtilities::ParseWmDrmStringL
   304 // ----------------------------------------------------------------------------
   304 // ----------------------------------------------------------------------------
   305 //
   305 //
   306 EXPORT_C void DrmUtilityWmDrmUtilities::ParseWmDrmStringL(
   306 EXPORT_C void DrmUtilityWmDrmUtilities::ParseWmDrmStringL(
   307     ContentAccess::CRightsInfo& aRights,
   307     ContentAccess::CRightsInfo& aRights,
   308     CDRMRightsConstraints*& aRightsConstraint )
   308     CDRMRightsConstraints*& aRightsConstraint )
   309     {
   309     {
   310     
   310 
   311     __ASSERT_DEBUG( !aRightsConstraint, 
   311     __ASSERT_DEBUG( !aRightsConstraint,
   312                     User::Panic( KWmDrmUtilitiesDebugPanicMessage,
   312                     User::Panic( KWmDrmUtilitiesDebugPanicMessage,
   313                                  KWmDrmUtilitiesDebugPanicCode ) );
   313                                  KWmDrmUtilitiesDebugPanicCode ) );
   314        
   314 
   315     TChar ch;
   315     TChar ch;
   316     TTime startTime( Time::NullTTime() );
   316     TTime startTime( Time::NullTTime() );
   317     TTime endTime( Time::NullTTime() );
   317     TTime endTime( Time::NullTTime() );
   318     TTimeIntervalSeconds duration( 0 );
   318     TTimeIntervalSeconds duration( 0 );
   319     TUint32 counter( 0 );
   319     TUint32 counter( 0 );
   320     
   320 
   321     TPtrC16 token( NULL, 0 );
   321     TPtrC16 token( NULL, 0 );
   322     
   322 
   323     // Parse the WM DRM rights string
   323     // Parse the WM DRM rights string
   324     TLex lex( aRights.Description() );
   324     TLex lex( aRights.Description() );
   325     
   325 
   326     // First, find the license type format string ("licensetype=") 
   326     // First, find the license type format string ("licensetype=")
   327     ParseString( '=', lex, token );
   327     ParseString( '=', lex, token );
   328     
   328 
   329     if ( token.CompareF( KLicenseType ) != 0 )
   329     if ( token.CompareF( KLicenseType ) != 0 )
   330         {
   330         {
   331         // License type format string was not found  
   331         // License type format string was not found
   332         User::Leave( KErrArgument );
   332         User::Leave( KErrArgument );
   333         }
   333         }
   334  
   334 
   335     // Peek for the end of string (eos) in case of (licensetype="") 
   335     // Peek for the end of string (eos) in case of (licensetype="")
   336     ch = lex.Peek();
   336     ch = lex.Peek();
   337     if ( ch == 0 ) 
   337     if ( ch == 0 )
   338         {
   338         {
   339         return;
   339         return;
   340         }
   340         }
   341     
   341 
   342     // Check the license type
   342     // Check the license type
   343     ParseString( ';', lex, token );
   343     ParseString( ';', lex, token );
   344     
   344 
   345     aRightsConstraint = CDRMRightsConstraints::NewL();
   345     aRightsConstraint = CDRMRightsConstraints::NewL();
   346     CleanupStack::PushL( aRightsConstraint );
   346     CleanupStack::PushL( aRightsConstraint );
   347     
   347 
   348     // Check what kind of rights are in question by parsing the string
   348     // Check what kind of rights are in question by parsing the string
   349     // onward. The possible rights are date time (start time and/or end time),
   349     // onward. The possible rights are date time (start time and/or end time),
   350     // count, duration, time count (count and/or date time) and unlimited
   350     // count, duration, time count (count and/or date time) and unlimited
   351     // rights. The substrings for certain rights are further parsed in
   351     // rights. The substrings for certain rights are further parsed in
   352     // specific methods. 
   352     // specific methods.
   353     if ( token.CompareF( KTime ) == 0 )
   353     if ( token.CompareF( KTime ) == 0 )
   354         {
   354         {
   355         ParseWmDrmTimeRightsL( lex, startTime, endTime );
   355         ParseWmDrmTimeRightsL( lex, startTime, endTime );
   356         if ( Time::NullTTime() != startTime )
   356         if ( Time::NullTTime() != startTime )
   357             {
   357             {
   393             aRightsConstraint->SetEndTime( endTime );
   393             aRightsConstraint->SetEndTime( endTime );
   394             }
   394             }
   395         }
   395         }
   396     else if ( token.CompareF( KUnlimited ) != 0 )
   396     else if ( token.CompareF( KUnlimited ) != 0 )
   397         {
   397         {
   398         // Unknown license type  
   398         // Unknown license type
   399         User::Leave( KErrArgument );
   399         User::Leave( KErrArgument );
   400         }
   400         }
   401           
   401 
   402     CleanupStack::Pop( aRightsConstraint );
   402     CleanupStack::Pop( aRightsConstraint );
   403         
   403 
   404     }
   404     }
   405 
   405 
   406 // -----------------------------------------------------------------------------
   406 // -----------------------------------------------------------------------------
   407 // DrmUtilityWmDrmUtilities::CheckWmDrmRightsL
   407 // DrmUtilityWmDrmUtilities::CheckWmDrmRightsL
   408 // -----------------------------------------------------------------------------
   408 // -----------------------------------------------------------------------------
   409 //
   409 //
   410 EXPORT_C void DrmUtilityWmDrmUtilities::CheckWmDrmRightsL( TBool& aUnconstrained, 
   410 EXPORT_C void DrmUtilityWmDrmUtilities::CheckWmDrmRightsL( TBool& aUnconstrained,
   411     TTimeIntervalSeconds& aTime,
   411     TTimeIntervalSeconds& aTime,
   412     TInt& aCounts,  
   412     TInt& aCounts,
   413     ContentAccess::CRightsInfo& aRights )
   413     ContentAccess::CRightsInfo& aRights )
   414     {
   414     {
   415     
   415 
   416     TChar ch;
   416     TChar ch;
   417     TPtrC16 token( NULL, 0 );
   417     TPtrC16 token( NULL, 0 );
   418     TInt constraints( 0 );
   418     TInt constraints( 0 );
   419     TInt error( KErrNone );
   419     TInt error( KErrNone );
   420     TTime startTime( Time::NullTTime() );
   420     TTime startTime( Time::NullTTime() );
   422     TUint32 counter( 0 );
   422     TUint32 counter( 0 );
   423     TTime now( Time::NullTTime() ); // current time
   423     TTime now( Time::NullTTime() ); // current time
   424     // End time of rights when duration is taken into account.
   424     // End time of rights when duration is taken into account.
   425     TTime durationEndTime( Time::NullTTime() );
   425     TTime durationEndTime( Time::NullTTime() );
   426     TTimeIntervalSeconds secondsLeft( 0 ); // seconds to end of time based rights
   426     TTimeIntervalSeconds secondsLeft( 0 ); // seconds to end of time based rights
   427     
   427 
   428     // Parse WM DRM rights string  
   428     // Parse WM DRM rights string
   429     TLex lex( aRights.Description() );
   429     TLex lex( aRights.Description() );
   430     
   430 
   431     // First, find the license type format string ("licensetype=") 
   431     // First, find the license type format string ("licensetype=")
   432     ParseString( '=', lex, token );
   432     ParseString( '=', lex, token );
   433     
   433 
   434     if ( token.CompareF( KLicenseType ) != 0 )
   434     if ( token.CompareF( KLicenseType ) != 0 )
   435         {
   435         {
   436         // License type format string was not found  
   436         // License type format string was not found
   437         User::Leave( KErrArgument );
   437         User::Leave( KErrArgument );
   438         }
   438         }
   439     
   439 
   440     // Peek for the end of string (Eos) in case of (licensetype="") 
   440     // Peek for the end of string (Eos) in case of (licensetype="")
   441     ch = lex.Peek();
   441     ch = lex.Peek();
   442     if ( ch == 0 ) 
   442     if ( ch == 0 )
   443         {
   443         {
   444         return;
   444         return;
   445         }
   445         }
   446     
   446 
   447     // Check the license type
   447     // Check the license type
   448     ParseString( ';', lex, token );
   448     ParseString( ';', lex, token );
   449     
   449 
   450     // Check what kind of rights are in question by parsing the string
   450     // Check what kind of rights are in question by parsing the string
   451     // onward. The possible rights are date time (start time and/or end time),
   451     // onward. The possible rights are date time (start time and/or end time),
   452     // count, duration, time count (count and/or date time) and unlimited
   452     // count, duration, time count (count and/or date time) and unlimited
   453     // rights. The substrings for certain rights are further parsed in
   453     // rights. The substrings for certain rights are further parsed in
   454     // specific methods. 
   454     // specific methods.
   455     if ( token.CompareF( KTime ) == 0 )
   455     if ( token.CompareF( KTime ) == 0 )
   456         {
   456         {
   457         ParseWmDrmTimeRightsL( lex, startTime, endTime );
   457         ParseWmDrmTimeRightsL( lex, startTime, endTime );
   458         if ( Time::NullTTime() != startTime )
   458         if ( Time::NullTTime() != startTime )
   459             {
   459             {
   468         {
   468         {
   469         if ( ParseWmDrmCountRightsL( lex, counter ) )
   469         if ( ParseWmDrmCountRightsL( lex, counter ) )
   470             {
   470             {
   471             aCounts = counter;
   471             aCounts = counter;
   472             constraints |= KWmDrmConstraintCount;
   472             constraints |= KWmDrmConstraintCount;
   473             }    
   473             }
   474         }
   474         }
   475     else if ( token.CompareF( KDuration ) == 0 )
   475     else if ( token.CompareF( KDuration ) == 0 )
   476         {
   476         {
   477         if ( ParseWmDrmDurationRightsL( lex, aTime ) )
   477         if ( ParseWmDrmDurationRightsL( lex, aTime ) )
   478             {
   478             {
   497             }
   497             }
   498         if ( Time::NullTTime() != endTime )
   498         if ( Time::NullTTime() != endTime )
   499             {
   499             {
   500             constraints |= KWmDrmConstraintEndTime;
   500             constraints |= KWmDrmConstraintEndTime;
   501             }
   501             }
   502         }        
   502         }
   503     else if ( token.CompareF( KUnlimited ) == 0 ) 
   503     else if ( token.CompareF( KUnlimited ) == 0 )
   504         {
   504         {
   505         aUnconstrained = ETrue;
   505         aUnconstrained = ETrue;
   506         return;
   506         return;
   507         }
   507         }
   508     else 
   508     else
   509         {
   509         {
   510         // Unknown license type
   510         // Unknown license type
   511         User::Leave( KErrArgument );
   511         User::Leave( KErrArgument );
   512         }
   512         }
   513     
   513 
   514     // Get current time
   514     // Get current time
   515     now.HomeTime();
   515     now.HomeTime();
   516         
   516 
   517     // The rights are not constrained
   517     // The rights are not constrained
   518     if ( !constraints )
   518     if ( !constraints )
   519         {
   519         {
   520         aUnconstrained = ETrue;
   520         aUnconstrained = ETrue;
   521         }
   521         }
   522     
   522 
   523     if ( constraints & KWmDrmConstraintStartTime )
   523     if ( constraints & KWmDrmConstraintStartTime )
   524         {
   524         {
   525         // The start time is in the past or the current time
   525         // The start time is in the past or the current time
   526         if ( ( now >= startTime ) && 
   526         if ( ( now >= startTime ) &&
   527             !( constraints & KWmDrmConstraintEndTime ) &&
   527             !( constraints & KWmDrmConstraintEndTime ) &&
   528             !( constraints & KWmDrmConstraintCount ) )
   528             !( constraints & KWmDrmConstraintCount ) )
   529             {
   529             {
   530             aUnconstrained = ETrue;
   530             aUnconstrained = ETrue;
   531             }
   531             }
   532         
   532 
   533         // This use case is unclear and should be specified later.
   533         // This use case is unclear and should be specified later.
   534         // There are counts for the content, but the start time has
   534         // There are counts for the content, but the start time has
   535         // not been reached.    
   535         // not been reached.
   536         if ( ( constraints & KWmDrmConstraintCount ) &&
   536         if ( ( constraints & KWmDrmConstraintCount ) &&
   537             ( now < startTime ) ) 
   537             ( now < startTime ) )
   538             {
   538             {
   539             aCounts = 0;
   539             aCounts = 0;
   540             }               
   540             }
   541         }
   541         }
   542     
   542 
   543     // Find out the amount of time that the rights have left in
   543     // Find out the amount of time that the rights have left in
   544     // case the rights have end time constraint.
   544     // case the rights have end time constraint.
   545     if ( constraints & KWmDrmConstraintEndTime )
   545     if ( constraints & KWmDrmConstraintEndTime )
   546         {
   546         {
   547         error = endTime.SecondsFrom( now, secondsLeft );
   547         error = endTime.SecondsFrom( now, secondsLeft );
   548         
   548 
   549         // The difference between current time and the end time does not
   549         // The difference between current time and the end time does not
   550         // fit to 32-bit number, the start time has been reached and there
   550         // fit to 32-bit number, the start time has been reached and there
   551         // are no count constraints defined.
   551         // are no count constraints defined.
   552         if ( ( error == KErrOverflow ) && 
   552         if ( ( error == KErrOverflow ) &&
   553             ( !( constraints & KWmDrmConstraintStartTime ) || 
   553             ( !( constraints & KWmDrmConstraintStartTime ) ||
   554             ( now >= startTime ) ) && !( constraints & KWmDrmConstraintCount ) )
   554             ( now >= startTime ) ) && !( constraints & KWmDrmConstraintCount ) )
   555             {
   555             {
   556             aUnconstrained = ETrue;
   556             aUnconstrained = ETrue;
   557             }
   557             }
   558         
   558 
   559         // End time has not been reached and start time has been reached
   559         // End time has not been reached and start time has been reached
   560         if ( ( secondsLeft > (TTimeIntervalSeconds)0 ) && ( now >= startTime ) )
   560         if ( ( secondsLeft > (TTimeIntervalSeconds)0 ) && ( now >= startTime ) )
   561             {
   561             {
   562             aTime = secondsLeft;
   562             aTime = secondsLeft;
   563             }
   563             }
   564        
   564 
   565         // This use case is unclear and should be specified later.
   565         // This use case is unclear and should be specified later.
   566         // There are counts for the content, but the end time has
   566         // There are counts for the content, but the end time has
   567         // been reached.
   567         // been reached.
   568         if ( ( constraints & KWmDrmConstraintCount ) &&
   568         if ( ( constraints & KWmDrmConstraintCount ) &&
   569             ( now > endTime ) )
   569             ( now > endTime ) )
   570             {
   570             {
   571             aCounts = 0;
   571             aCounts = 0;
   572             }
   572             }
   573         }
   573         }
   574         
   574 
   575     return;
   575     return;
   576     
   576 
   577     }
   577     }
   578     
   578 
   579 // End of File
   579 // End of File
   580