diff -r e16d72588c28 -r 8a03a285ab14 commondrm/drmutility/src/drmutilitywmdrmutilities.cpp --- a/commondrm/drmutility/src/drmutilitywmdrmutilities.cpp Fri Mar 12 15:43:46 2010 +0200 +++ b/commondrm/drmutility/src/drmutilitywmdrmutilities.cpp Mon Mar 15 12:41:43 2010 +0200 @@ -19,9 +19,9 @@ #include #include -#include "drmclockclient.h" +#include "DRMClockClient.h" #include "drmutilitywmdrmutilities.h" -#include "drmrights.h" +#include "DRMRights.h" // CONSTANTS _LIT( KLicenseType, "licensetype=" ); @@ -63,7 +63,7 @@ { TBool found( EFalse ); aLex.Mark(); - + while ( !aLex.Eos() && found == EFalse ) { TChar ch; @@ -77,7 +77,7 @@ aPtr.Set( aLex.MarkedToken() ); aLex.Get(); } - else + else { aPtr.Set( aLex.MarkedToken() ); } @@ -98,134 +98,134 @@ TTime localTime( Time::NullTTime() ); TTime universalTime( Time::NullTTime() ); TTimeIntervalSeconds timeDifference( 0 ); // local time - secure time - TInt years, months, days, hours, minutes, secs; + TInt years, months, days, hours, minutes, secs; TChar ch; TLex lex; TTime drmTime; TInt timeZone; - + DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure; - + // The format of the start and end time strings is the following: // "starttime=yy-mm-ddThh:mins:ssZ // "endtime=yy-mm-ddThh:mins:ssZ - // where yy = years, mm = months, dd = days, hh = hours, - // mins = minutes and ss = seconds, "-", "T", ":" and "Z" - // are separators. + // where yy = years, mm = months, dd = days, hh = hours, + // mins = minutes and ss = seconds, "-", "T", ":" and "Z" + // are separators. while ( !aLex.Eos() && ( aLex.Peek() != 0 ) ) { // The next string should be start time, end time or then // it does not exist. ParseString( '=', aLex, token ); - + if ( token.CompareF( KStartTime ) == 0 ) { times |= KFoundStartTime; - } + } else if ( token.CompareF( KEndTime ) == 0 ) { times |= KFoundEndTime; } - else + else { - // No start time ("starttime=") or end time ("endtime=") - // string was found -> return + // No start time ("starttime=") or end time ("endtime=") + // string was found -> return return; } - + if ( ( times & KFoundStartTime ) || ( times & KFoundEndTime ) ) - { - // Search for years, months, days, hours, minutes, secs + { + // Search for years, months, days, hours, minutes, secs if ( ParseString( '-', aLex, token ) ) { TLex lexYear( token ); User::LeaveIfError( lexYear.Val( years ) ); } - else + else { - User::Leave( KErrNotFound ); + User::Leave( KErrNotFound ); } - + if ( ParseString( '-', aLex, token ) ) { TLex lexMonths( token ); User::LeaveIfError( lexMonths.Val( months ) ); } - else + else { - User::Leave( KErrNotFound ); + User::Leave( KErrNotFound ); } - + if ( ParseString( 'T', aLex, token ) ) { TLex lexDays( token ); User::LeaveIfError( lexDays.Val( days ) ); } - else + else { - User::Leave( KErrNotFound ); + User::Leave( KErrNotFound ); } - + if( ParseString( ':', aLex, token ) ) { TLex lexHours( token ); User::LeaveIfError( lexHours.Val( hours ) ); } - else + else { User::Leave( KErrNotFound ); } - + if ( ParseString( ':', aLex, token ) ) { TLex lexMinutes( token ); User::LeaveIfError( lexMinutes.Val( minutes ) ); } - else + else { User::Leave( KErrNotFound ); } - + if( ParseString( 'Z', aLex, token ) ) { TLex lexSeconds( token ); User::LeaveIfError( lexSeconds.Val( secs ) ); } - else + else { User::Leave( KErrNotFound ); - } - + } + ParseString( ';', aLex, token ); token.Set( NULL, 0 ); - - TDateTime date( years, (TMonth)( months - 1 ), days - 1, hours, + + TDateTime date( years, (TMonth)( months - 1 ), days - 1, hours, minutes, secs, 0 ); TTime dateTime( date ); - - // Get secure time from DRM clock + + // Get secure time from DRM clock RDRMClockClient client; - + User::LeaveIfError( client.Connect() ); client.GetSecureTime( drmTime, timeZone, secLevel ); client.Close(); - - localTime.HomeTime(); - - if ( secLevel == DRMClock::KSecure ) - { - // Calculate the difference between local time and secure time - localTime.SecondsFrom( drmTime, timeDifference ); - } - else - { - // Calculate the difference between local and universal time - universalTime.UniversalTime(); - localTime.SecondsFrom( universalTime, timeDifference ); - } - - dateTime += timeDifference; - + + localTime.HomeTime(); + + if ( secLevel == DRMClock::KSecure ) + { + // Calculate the difference between local time and secure time + localTime.SecondsFrom( drmTime, timeDifference ); + } + else + { + // Calculate the difference between local and universal time + universalTime.UniversalTime(); + localTime.SecondsFrom( universalTime, timeDifference ); + } + + dateTime += timeDifference; + if ( times & KFoundStartTime ) { aStartTime = dateTime; @@ -248,12 +248,12 @@ TUint32& aCounts ) { TPtrC16 token( NULL, 0 ); - TInt counts( 0 ); + TInt counts( 0 ); TChar ch; TLex lex; - + ParseString( '=', aLex, token ); - + if ( token.CompareF( KCountLeft ) == 0 ) { ParseString( ';', aLex, token ); @@ -261,8 +261,8 @@ User::LeaveIfError( lexCount.Val( counts ) ); aCounts = counts; return ETrue; - } - else + } + else { // No counts left ("countleft=") string was found. // -> No count information was found, return EFalse @@ -274,15 +274,15 @@ // DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL // ---------------------------------------------------------------------------- // -EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL( TLex& aLex, +EXPORT_C TBool DrmUtilityWmDrmUtilities::ParseWmDrmDurationRightsL( TLex& aLex, TTimeIntervalSeconds& aDuration ) { TPtrC16 token( NULL, 0 ); TChar ch; TInt duration( 0 ); - + ParseString( '=', aLex, token ); - + if ( token.CompareF( KDurationLeft ) == 0 ) { ParseString( ';', aLex, token ); @@ -291,12 +291,12 @@ aDuration = duration; return ETrue; } - else + else { // No duration left ("durationleft=") string was found. // -> No duration information was found, return EFalse return EFalse; - } + } } // ---------------------------------------------------------------------------- @@ -307,49 +307,49 @@ ContentAccess::CRightsInfo& aRights, CDRMRightsConstraints*& aRightsConstraint ) { - - __ASSERT_DEBUG( !aRightsConstraint, + + __ASSERT_DEBUG( !aRightsConstraint, User::Panic( KWmDrmUtilitiesDebugPanicMessage, KWmDrmUtilitiesDebugPanicCode ) ); - + TChar ch; TTime startTime( Time::NullTTime() ); TTime endTime( Time::NullTTime() ); TTimeIntervalSeconds duration( 0 ); TUint32 counter( 0 ); - + TPtrC16 token( NULL, 0 ); - + // Parse the WM DRM rights string TLex lex( aRights.Description() ); - - // First, find the license type format string ("licensetype=") + + // First, find the license type format string ("licensetype=") ParseString( '=', lex, token ); - + if ( token.CompareF( KLicenseType ) != 0 ) { - // License type format string was not found + // License type format string was not found User::Leave( KErrArgument ); } - - // Peek for the end of string (eos) in case of (licensetype="") + + // Peek for the end of string (eos) in case of (licensetype="") ch = lex.Peek(); - if ( ch == 0 ) + if ( ch == 0 ) { return; } - + // Check the license type ParseString( ';', lex, token ); - + aRightsConstraint = CDRMRightsConstraints::NewL(); CleanupStack::PushL( aRightsConstraint ); - + // Check what kind of rights are in question by parsing the string // onward. The possible rights are date time (start time and/or end time), // count, duration, time count (count and/or date time) and unlimited // rights. The substrings for certain rights are further parsed in - // specific methods. + // specific methods. if ( token.CompareF( KTime ) == 0 ) { ParseWmDrmTimeRightsL( lex, startTime, endTime ); @@ -395,24 +395,24 @@ } else if ( token.CompareF( KUnlimited ) != 0 ) { - // Unknown license type + // Unknown license type User::Leave( KErrArgument ); } - + CleanupStack::Pop( aRightsConstraint ); - + } // ----------------------------------------------------------------------------- // DrmUtilityWmDrmUtilities::CheckWmDrmRightsL // ----------------------------------------------------------------------------- // -EXPORT_C void DrmUtilityWmDrmUtilities::CheckWmDrmRightsL( TBool& aUnconstrained, +EXPORT_C void DrmUtilityWmDrmUtilities::CheckWmDrmRightsL( TBool& aUnconstrained, TTimeIntervalSeconds& aTime, - TInt& aCounts, + TInt& aCounts, ContentAccess::CRightsInfo& aRights ) { - + TChar ch; TPtrC16 token( NULL, 0 ); TInt constraints( 0 ); @@ -424,34 +424,34 @@ // End time of rights when duration is taken into account. TTime durationEndTime( Time::NullTTime() ); TTimeIntervalSeconds secondsLeft( 0 ); // seconds to end of time based rights - - // Parse WM DRM rights string + + // Parse WM DRM rights string TLex lex( aRights.Description() ); - - // First, find the license type format string ("licensetype=") + + // First, find the license type format string ("licensetype=") ParseString( '=', lex, token ); - + if ( token.CompareF( KLicenseType ) != 0 ) { - // License type format string was not found + // License type format string was not found User::Leave( KErrArgument ); } - - // Peek for the end of string (Eos) in case of (licensetype="") + + // Peek for the end of string (Eos) in case of (licensetype="") ch = lex.Peek(); - if ( ch == 0 ) + if ( ch == 0 ) { return; } - + // Check the license type ParseString( ';', lex, token ); - + // Check what kind of rights are in question by parsing the string // onward. The possible rights are date time (start time and/or end time), // count, duration, time count (count and/or date time) and unlimited // rights. The substrings for certain rights are further parsed in - // specific methods. + // specific methods. if ( token.CompareF( KTime ) == 0 ) { ParseWmDrmTimeRightsL( lex, startTime, endTime ); @@ -470,7 +470,7 @@ { aCounts = counter; constraints |= KWmDrmConstraintCount; - } + } } else if ( token.CompareF( KDuration ) == 0 ) { @@ -499,69 +499,69 @@ { constraints |= KWmDrmConstraintEndTime; } - } - else if ( token.CompareF( KUnlimited ) == 0 ) + } + else if ( token.CompareF( KUnlimited ) == 0 ) { aUnconstrained = ETrue; return; } - else + else { // Unknown license type User::Leave( KErrArgument ); } - + // Get current time now.HomeTime(); - + // The rights are not constrained if ( !constraints ) { aUnconstrained = ETrue; } - + if ( constraints & KWmDrmConstraintStartTime ) { // The start time is in the past or the current time - if ( ( now >= startTime ) && + if ( ( now >= startTime ) && !( constraints & KWmDrmConstraintEndTime ) && !( constraints & KWmDrmConstraintCount ) ) { aUnconstrained = ETrue; } - + // This use case is unclear and should be specified later. // There are counts for the content, but the start time has - // not been reached. + // not been reached. if ( ( constraints & KWmDrmConstraintCount ) && - ( now < startTime ) ) + ( now < startTime ) ) { aCounts = 0; - } + } } - + // Find out the amount of time that the rights have left in // case the rights have end time constraint. if ( constraints & KWmDrmConstraintEndTime ) { error = endTime.SecondsFrom( now, secondsLeft ); - + // The difference between current time and the end time does not // fit to 32-bit number, the start time has been reached and there // are no count constraints defined. - if ( ( error == KErrOverflow ) && - ( !( constraints & KWmDrmConstraintStartTime ) || + if ( ( error == KErrOverflow ) && + ( !( constraints & KWmDrmConstraintStartTime ) || ( now >= startTime ) ) && !( constraints & KWmDrmConstraintCount ) ) { aUnconstrained = ETrue; } - + // End time has not been reached and start time has been reached if ( ( secondsLeft > (TTimeIntervalSeconds)0 ) && ( now >= startTime ) ) { aTime = secondsLeft; } - + // This use case is unclear and should be specified later. // There are counts for the content, but the end time has // been reached. @@ -571,10 +571,9 @@ aCounts = 0; } } - + return; - + } - + // End of File - \ No newline at end of file