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 } |
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 { |
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 { |
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 |
|