|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: EXPORT_C implementation of drm media WMA agent |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <caf/rightsinfo.h> |
|
20 #include "mpxmedia.h" |
|
21 #include "mpxmediadrmdefs.h" |
|
22 #include "mpxdrmmediawmaagent.h" |
|
23 #include "mpxlog.h" |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT(KMPXWmaDrmDelLicensesType, "licensetype="); |
|
27 _LIT(KMPXWmaDrmDelUnlimited, "unlimited"); |
|
28 _LIT(KMPXWmaDrmDelTime, "time"); |
|
29 _LIT(KMPXWmaDrmDelCount, "count"); |
|
30 _LIT(KMPXWmaDrmDelDuration, "duration"); |
|
31 _LIT(KMPXWmaDrmDelTimeCount, "time-count"); |
|
32 _LIT(KMPXWmaDrmDelDurationLeft, "duration="); |
|
33 _LIT(KMPXWmaDrmDelCountLeft, "countleft="); |
|
34 _LIT(KMPXWmaDrmDelStartTime, "starttime="); |
|
35 _LIT(KMPXWmaDrmDelEndTime, "endtime="); |
|
36 _LIT(KMPXWmaDrmDelColon, ":"); |
|
37 _LIT(KMPXWmaDrmDelSemiColon, ";"); |
|
38 _LIT(KMPXWmaDrmTimeFill, "0"); |
|
39 |
|
40 const TInt KMPXWmaDrmMaxLicenseTypeBufSize = 30; |
|
41 const TInt KMPXWmaDrmDashCount = 2; |
|
42 const TInt KMPXWmaDrmMaxTimeBufSize = 3; |
|
43 const TInt KMPXWmaDrmMinutesHourMinSize = 2; |
|
44 |
|
45 const TText KMPXWmaDrmSemiColonChar = ';'; |
|
46 const TText KMPXWmaDrmDashChar = '-'; |
|
47 const TText KMPXWmaDrmTChar = 'T'; |
|
48 const TText KMPXWmaDrmColonChar = ':'; |
|
49 const TText KMPXWmaDrmPeriodChar = '.'; |
|
50 const TText KMPXWmaDrmZChar = 'Z'; |
|
51 const TText KMPXWmaDrmPlusChar = '+'; |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CMPXDrmMediaWmaAgent* CMPXDrmMediaWmaAgent::NewL() |
|
59 { |
|
60 MPX_FUNC("CMPXDrmMediaWmaAgent::NewL()"); |
|
61 CMPXDrmMediaWmaAgent* p = CMPXDrmMediaWmaAgent::NewLC(); |
|
62 CleanupStack::Pop(p); |
|
63 return p; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CMPXDrmMediaWmaAgent* CMPXDrmMediaWmaAgent::NewLC() |
|
71 { |
|
72 MPX_FUNC("CMPXDrmMediaWmaAgent::NewLC()"); |
|
73 CMPXDrmMediaWmaAgent* p = new (ELeave) CMPXDrmMediaWmaAgent(); |
|
74 CleanupStack::PushL(p); |
|
75 p->ConstructL(); |
|
76 return p; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // Destructor |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CMPXDrmMediaWmaAgent::~CMPXDrmMediaWmaAgent() |
|
84 { |
|
85 MPX_FUNC("CMPXDrmMediaWmaAgent::~CMPXDrmMediaWmaAgent()"); |
|
86 Close(); |
|
87 delete iRightsManager; |
|
88 delete iManager; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // Default constructor |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CMPXDrmMediaWmaAgent::CMPXDrmMediaWmaAgent() |
|
96 { |
|
97 MPX_FUNC("CMPXDrmMediaWmaAgent::CMPXDrmMediaWmaAgent()"); |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // 2nd phase constructor. |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void CMPXDrmMediaWmaAgent::ConstructL() |
|
105 { |
|
106 MPX_FUNC("CMPXDrmMediaWmaAgent::ConstructL()"); |
|
107 |
|
108 RArray< TAgent > agents; |
|
109 CleanupClosePushL( agents ); |
|
110 |
|
111 iManager = CManager::NewL(); |
|
112 iManager->ListAgentsL( agents ); |
|
113 |
|
114 if ( agents.Count() > 0) |
|
115 { |
|
116 TInt i( 0 ); |
|
117 for ( i = 0; i < agents.Count(); i++ ) |
|
118 { |
|
119 // break if we find the agent we want |
|
120 // CAF UID |
|
121 const TDesC& name( agents[i].Name() ); |
|
122 if ( name.Compare( KMPXWDRMCafAgentName ) == 0 || |
|
123 name.Compare( KMPXS60WMDRMCafAgent ) == 0 ) |
|
124 { |
|
125 break; |
|
126 } |
|
127 } |
|
128 if ( i < agents.Count() ) |
|
129 { |
|
130 // We found the CAF agent |
|
131 MPX_DEBUG2("CMPXDrmMediaWmaAgent::ConstructL(): CAF agent=%d", i); |
|
132 iRightsManager = iManager->CreateRightsManagerL( agents[i] ); |
|
133 } |
|
134 } |
|
135 |
|
136 CleanupStack::PopAndDestroy( &agents ); |
|
137 } |
|
138 |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // Initialize utility using a filename |
|
142 // ---------------------------------------------------------------------------- |
|
143 // |
|
144 void CMPXDrmMediaWmaAgent::InitL( const TDesC& aFileName ) |
|
145 { |
|
146 MPX_DEBUG2("CMPXDrmMediaWmaAgent::InitL(%S) entering", &aFileName ); |
|
147 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::InitL(aFileName)"); |
|
148 |
|
149 Close(); |
|
150 CreateMediaL(); |
|
151 iData = CData::NewL( |
|
152 (TVirtualPathPtr) aFileName, |
|
153 EPeek, |
|
154 EContentShareReadOnly ); |
|
155 iFileName = aFileName.AllocL(); |
|
156 |
|
157 MPX_DEBUG1("CMPXDrmMediaWmaAgent::InitL() exiting" ); |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // Initialize utility using a file handle |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 void CMPXDrmMediaWmaAgent::InitL( RFile& aFile ) |
|
165 { |
|
166 MPX_DEBUG1("CMPXDrmMediaWmaAgent::InitL(RFile) entering" ); |
|
167 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::InitL(aFile)"); |
|
168 |
|
169 Close(); |
|
170 CreateMediaL(); |
|
171 iData = CData::NewL( |
|
172 aFile, |
|
173 KDefaultContentObject(), |
|
174 EPeek ); |
|
175 TFileName filename; |
|
176 aFile.FullName( filename ); |
|
177 iFileName = filename.AllocL(); |
|
178 MPX_DEBUG1("CMPXDrmMediaWmaAgent::InitL(RFile) exiting" ); |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // Gets media object with the given attributes |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 const CMPXMedia& CMPXDrmMediaWmaAgent::GetMediaL( TUint aAttributes ) |
|
186 { |
|
187 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetMediaL(%d) entering", aAttributes ); |
|
188 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::GetRightsTypeL()"); |
|
189 |
|
190 if ( iMedia ) |
|
191 { |
|
192 if ( aAttributes & KMPXMediaDrmProtected.iAttributeId ) |
|
193 { |
|
194 GetProtectedL(); |
|
195 } |
|
196 if ( aAttributes & KMPXMediaDrmRightsStatus.iAttributeId ) |
|
197 { |
|
198 GetRightsStatusL(); |
|
199 } |
|
200 if ( aAttributes & KMPXMediaDrmRightsType.iAttributeId ) |
|
201 { |
|
202 GetRightsTypeL(); |
|
203 } |
|
204 if ( aAttributes & KMPXMediaDrmCount.iAttributeId ) |
|
205 { |
|
206 GetCountL(); |
|
207 } |
|
208 if ( aAttributes & KMPXMediaDrmStartTime.iAttributeId ) |
|
209 { |
|
210 GetStartTimeL(); |
|
211 } |
|
212 if ( aAttributes & KMPXMediaDrmEndTime.iAttributeId ) |
|
213 { |
|
214 GetEndTimeL(); |
|
215 } |
|
216 if ( aAttributes & KMPXMediaDrmInterval.iAttributeId ) |
|
217 { |
|
218 GetIntervalL(); |
|
219 } |
|
220 if ( aAttributes & KMPXMediaDrmIntervalStartTime.iAttributeId ) |
|
221 { |
|
222 // Not Supported for WMA DRM |
|
223 } |
|
224 if ( aAttributes & KMPXMediaDrmAccumulatedTime.iAttributeId ) |
|
225 { |
|
226 // Not Supported for WMA DRM |
|
227 } |
|
228 if ( aAttributes & KMPXMediaDrmSendingAllowed.iAttributeId ) |
|
229 { |
|
230 GetSendingAllowedL(); |
|
231 } |
|
232 if ( aAttributes & KMPXMediaDrmCanSetAutomated.iAttributeId ) |
|
233 { |
|
234 GetCanSetAutomatedL(); |
|
235 } |
|
236 if ( aAttributes & KMPXMediaDrmHasInfoUrl.iAttributeId ) |
|
237 { |
|
238 // Not Supported for WMA DRM |
|
239 } |
|
240 if ( aAttributes & KMPXMediaDrmHasPreviewUrl.iAttributeId ) |
|
241 { |
|
242 // Not Supported for WMA DRM |
|
243 } |
|
244 if ( aAttributes & KMPXMediaDrmAboutToExpire.iAttributeId ) |
|
245 { |
|
246 GetAboutToExpireL(); |
|
247 } |
|
248 } |
|
249 |
|
250 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetMediaL() exiting" ); |
|
251 return *iMedia; |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------------------------- |
|
255 // Consumes the rights for the current media according |
|
256 // to the specified consume type |
|
257 // ---------------------------------------------------------------------------- |
|
258 // |
|
259 void CMPXDrmMediaWmaAgent::ConsumeL(TDrmConsumeType /*aType*/) |
|
260 { |
|
261 MPX_DEBUG1("CMPXDrmMediaWmaAgent::ConsumeL() entering"); |
|
262 |
|
263 // WMA DRM does not have ability to manually control consumption |
|
264 |
|
265 MPX_DEBUG1("CMPXDrmMediaWmaAgent::ConsumeL() exiting" ); |
|
266 } |
|
267 |
|
268 // ---------------------------------------------------------------------------- |
|
269 // Cleans up member variables |
|
270 // ---------------------------------------------------------------------------- |
|
271 // |
|
272 void CMPXDrmMediaWmaAgent::Close() |
|
273 { |
|
274 MPX_DEBUG1("CMPXDrmMediaWmaAgent::Close() entering"); |
|
275 |
|
276 CMPXDrmMediaAgent::Close(); |
|
277 delete iFileName; |
|
278 iFileName = NULL; |
|
279 delete iRightsDescription; |
|
280 iRightsDescription = NULL; |
|
281 |
|
282 MPX_DEBUG1("CMPXDrmMediaWmaAgent::Close() exiting"); |
|
283 } |
|
284 |
|
285 // ---------------------------------------------------------------------------- |
|
286 // Creates a new media object |
|
287 // ---------------------------------------------------------------------------- |
|
288 // |
|
289 void CMPXDrmMediaWmaAgent::CreateMediaL() |
|
290 { |
|
291 MPX_DEBUG1("CMPXDrmMediaWmaAgent::CreateMediaL() entering"); |
|
292 |
|
293 CMPXDrmMediaAgent::CreateMediaL(); |
|
294 |
|
295 // Set the type to WMA |
|
296 iMedia->SetTObjectValueL( KMPXMediaDrmType, |
|
297 EMPXDrmTypeWMA ); |
|
298 |
|
299 MPX_DEBUG1("CMPXDrmMediaWmaAgent::CreateMediaL() exiting"); |
|
300 } |
|
301 |
|
302 // ---------------------------------------------------------------------------- |
|
303 // Gets the rights status |
|
304 // ---------------------------------------------------------------------------- |
|
305 // |
|
306 void CMPXDrmMediaWmaAgent::GetRightsStatusL() |
|
307 { |
|
308 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsStatusL() entering"); |
|
309 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::GetRightsStatusL()"); |
|
310 |
|
311 if ( !iMedia->IsSupported( KMPXMediaDrmRightsStatus )) |
|
312 { |
|
313 // Check to make sure it's protected first |
|
314 if ( !iMedia->IsSupported( KMPXMediaDrmProtected )) |
|
315 { |
|
316 GetProtectedL(); |
|
317 } |
|
318 TBool prot( iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected )); |
|
319 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetRightsStatusL(): prot = %d", prot); |
|
320 TInt rightsStatus( EMPXDrmRightsFull ); |
|
321 if ( prot ) |
|
322 { |
|
323 TBool canPlay( ETrue ); |
|
324 #ifndef _DEBUG |
|
325 User::LeaveIfError( iData->GetAttribute( ECanPlay, canPlay )); |
|
326 #else |
|
327 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsStatusL(): Getting ECanPlay"); |
|
328 TInt playErr( iData->GetAttribute( ECanPlay, canPlay )); |
|
329 MPX_DEBUG3("CMPXDrmMediaWmaAgent::GetRightsStatusL(): err = %d, canPlay = %d", playErr, canPlay ); |
|
330 User::LeaveIfError( playErr ); |
|
331 #endif |
|
332 if ( !canPlay ) |
|
333 { |
|
334 rightsStatus = EMPXDrmRightsExpired; |
|
335 } |
|
336 else |
|
337 { |
|
338 TBool rightsStateless( ETrue ); |
|
339 TBool rightsConsumable( EFalse ); |
|
340 #ifndef _DEBUG |
|
341 User::LeaveIfError( iData->GetAttribute( |
|
342 ERightsStateless, |
|
343 rightsStateless )); |
|
344 User::LeaveIfError( iData->GetAttribute( |
|
345 ERightsConsumable, |
|
346 rightsConsumable )); |
|
347 #else |
|
348 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsStatusL(): Getting ERightsStateless"); |
|
349 TInt statusErr( iData->GetAttribute( |
|
350 ERightsStateless, |
|
351 rightsStateless )); |
|
352 MPX_DEBUG3("CMPXDrmMediaWmaAgent::GetRightsStatusL(): err = %d, rightsStateless = %d", statusErr, rightsStateless ); |
|
353 User::LeaveIfError( statusErr ); |
|
354 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsStatusL(): Getting ERightsConsumable"); |
|
355 TInt conumeableErr( iData->GetAttribute( |
|
356 ERightsConsumable, |
|
357 rightsConsumable )); |
|
358 MPX_DEBUG3("CMPXDrmMediaWmaAgent::GetRightsStatusL(): err = %d, rightsConsumable = %d", conumeableErr, rightsConsumable ); |
|
359 User::LeaveIfError( conumeableErr ); |
|
360 #endif |
|
361 if ( !rightsStateless || rightsConsumable ) |
|
362 { |
|
363 rightsStatus = EMPXDrmRightsRestricted; |
|
364 } |
|
365 else |
|
366 { |
|
367 if ( !iMedia->IsSupported( KMPXMediaDrmRightsType )) |
|
368 { |
|
369 GetRightsTypeL(); |
|
370 } |
|
371 TInt rightsType( iMedia->ValueTObjectL<TInt>( |
|
372 KMPXMediaDrmRightsType )); |
|
373 if ( EMPXDrmRightsTypeNoRestriction == rightsType ) |
|
374 { |
|
375 rightsStatus = EMPXDrmRightsFull; |
|
376 } |
|
377 else |
|
378 { |
|
379 rightsStatus = EMPXDrmRightsRestricted; |
|
380 } |
|
381 } |
|
382 } |
|
383 } |
|
384 iMedia->SetTObjectValueL( KMPXMediaDrmRightsStatus, |
|
385 rightsStatus ); |
|
386 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetRightsStatusL(): setting status = %d", rightsStatus); |
|
387 } |
|
388 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsStatusL() exiting"); |
|
389 } |
|
390 |
|
391 // ---------------------------------------------------------------------------- |
|
392 // Gets the rights type attribute if not already obtained |
|
393 // ---------------------------------------------------------------------------- |
|
394 // |
|
395 void CMPXDrmMediaWmaAgent::GetRightsTypeL() |
|
396 { |
|
397 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsTypeL() entering"); |
|
398 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::GetRightsTypeL()"); |
|
399 |
|
400 if ( !iMedia->IsSupported( KMPXMediaDrmRightsType )) |
|
401 { |
|
402 TInt rightsType( EMPXDrmRightsTypeNoRestriction ); |
|
403 |
|
404 if ( GetWmdrmRightsDescriptionL() == KErrNone ) |
|
405 { |
|
406 TPtr strPtr( iRightsDescription->Des() ); |
|
407 TInt end( strPtr.FindF( KMPXWmaDrmDelSemiColon )); |
|
408 HBufC* licensetype( HBufC::NewLC( KMPXWmaDrmMaxLicenseTypeBufSize )); |
|
409 TPtr licensetypePtr( licensetype->Des()); |
|
410 licensetypePtr = strPtr.Mid( |
|
411 KMPXWmaDrmDelLicensesType().Length(), |
|
412 end - KMPXWmaDrmDelLicensesType().Length() ); |
|
413 |
|
414 if ( licensetypePtr == KMPXWmaDrmDelUnlimited ) |
|
415 { |
|
416 rightsType = EMPXDrmRightsTypeNoRestriction; |
|
417 } |
|
418 else if ( licensetypePtr == KMPXWmaDrmDelTime ) |
|
419 { |
|
420 rightsType = EMPXDrmRightsTypeTime; |
|
421 } |
|
422 else if ( licensetypePtr == KMPXWmaDrmDelCount ) |
|
423 { |
|
424 rightsType = EMPXDrmRightsTypeCount; |
|
425 } |
|
426 else if ( licensetypePtr == KMPXWmaDrmDelDuration ) |
|
427 { |
|
428 rightsType = EMPXDrmRightsTypeInterval; |
|
429 } |
|
430 else if ( licensetypePtr == KMPXWmaDrmDelTimeCount ) |
|
431 { |
|
432 rightsType = EMPXDrmRightsTypeTimeCount; |
|
433 } |
|
434 CleanupStack::PopAndDestroy( licensetype ); |
|
435 } |
|
436 |
|
437 iMedia->SetTObjectValueL( KMPXMediaDrmRightsType, |
|
438 rightsType ); |
|
439 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetRightsTypeL() setting type = %d", rightsType); |
|
440 } |
|
441 |
|
442 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetRightsTypeL() exiting"); |
|
443 } |
|
444 |
|
445 // ---------------------------------------------------------------------------- |
|
446 // Gets the count attribute if not already obtained |
|
447 // ---------------------------------------------------------------------------- |
|
448 // |
|
449 void CMPXDrmMediaWmaAgent::GetCountL() |
|
450 { |
|
451 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetCountL() entering"); |
|
452 |
|
453 // Do not need to check if it already supported, we |
|
454 // just overwrite the old value if possible |
|
455 TUint32 count( 0 ); |
|
456 if ( GetWmdrmRightsDescriptionL() == KErrNone ) |
|
457 { |
|
458 TPtr strPtr( iRightsDescription->Des() ); |
|
459 if ( strPtr.FindF( KMPXWmaDrmDelLicensesType ) == KErrNone ) |
|
460 { |
|
461 TInt begin( strPtr.FindF( KMPXWmaDrmDelCountLeft )); |
|
462 if ( begin != KErrNotFound ) |
|
463 { |
|
464 TPtrC countPtr( strPtr.Mid( begin )); |
|
465 TInt semiLoc( countPtr.Locate( KMPXWmaDrmSemiColonChar )); |
|
466 TInt countLen( KMPXWmaDrmDelCountLeft().Length() ); |
|
467 TLex lex( strPtr.MidTPtr( begin + countLen, semiLoc - countLen ) ); |
|
468 User::LeaveIfError( lex.Val( count, EDecimal ) ); |
|
469 iMedia->SetTObjectValueL( KMPXMediaDrmCount, |
|
470 count ); |
|
471 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetCountL(): setting count = %d", count); |
|
472 } |
|
473 } |
|
474 } |
|
475 |
|
476 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetCountL() exiting"); |
|
477 } |
|
478 |
|
479 // ---------------------------------------------------------------------------- |
|
480 // Gets the start time attribute if not already obtained |
|
481 // ---------------------------------------------------------------------------- |
|
482 // |
|
483 void CMPXDrmMediaWmaAgent::GetStartTimeL() |
|
484 { |
|
485 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetStartTimeL() entering"); |
|
486 |
|
487 if ( !iMedia->IsSupported( KMPXMediaDrmStartTime )) |
|
488 { |
|
489 TTime startTime; |
|
490 if ( GetWmdrmTimeL( KMPXWmaDrmDelStartTime, startTime ) == |
|
491 KErrNone ) |
|
492 { |
|
493 iMedia->SetTObjectValueL( KMPXMediaDrmStartTime, |
|
494 startTime.Int64() ); |
|
495 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetStartTimeL(): setting start time"); |
|
496 } |
|
497 } |
|
498 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetStartTimeL() exiting"); |
|
499 } |
|
500 |
|
501 // ---------------------------------------------------------------------------- |
|
502 // Gets the end time attribute if not already obtained |
|
503 // ---------------------------------------------------------------------------- |
|
504 // |
|
505 void CMPXDrmMediaWmaAgent::GetEndTimeL() |
|
506 { |
|
507 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetEndTimeL() entering"); |
|
508 |
|
509 if ( !iMedia->IsSupported( KMPXMediaDrmEndTime )) |
|
510 { |
|
511 TTime endTime; |
|
512 if ( GetWmdrmTimeL( KMPXWmaDrmDelEndTime, endTime ) == |
|
513 KErrNone ) |
|
514 { |
|
515 iMedia->SetTObjectValueL( KMPXMediaDrmEndTime, |
|
516 endTime.Int64() ); |
|
517 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetEndTimeL(): setting end time"); |
|
518 } |
|
519 } |
|
520 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetEndTimeL() exiting"); |
|
521 } |
|
522 |
|
523 // ---------------------------------------------------------------------------- |
|
524 // Gets the interval attribute if not already obtained |
|
525 // ---------------------------------------------------------------------------- |
|
526 // |
|
527 void CMPXDrmMediaWmaAgent::GetIntervalL() |
|
528 { |
|
529 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetIntervalL() entering"); |
|
530 |
|
531 if ( !iMedia->IsSupported( KMPXMediaDrmInterval )) |
|
532 { |
|
533 if ( GetWmdrmRightsDescriptionL() == KErrNone ) |
|
534 { |
|
535 TPtr strPtr( iRightsDescription->Des() ); |
|
536 if ( strPtr.FindF( KMPXWmaDrmDelLicensesType ) == KErrNone ) |
|
537 { |
|
538 TInt begin = strPtr.FindF( KMPXWmaDrmDelDurationLeft ); |
|
539 if ( begin != KErrNotFound ) |
|
540 { |
|
541 TPtrC countPtr = strPtr.Mid( begin ); |
|
542 TInt semiLoc = countPtr.Locate( KMPXWmaDrmSemiColonChar ); |
|
543 TInt countLen = KMPXWmaDrmDelDurationLeft().Length(); |
|
544 TLex lex( strPtr.MidTPtr( begin + countLen, semiLoc - countLen ) ); |
|
545 TInt interval; |
|
546 User::LeaveIfError( lex.Val( interval ) ); |
|
547 TTimeIntervalSeconds intervalSeconds( interval ); |
|
548 iMedia->SetTObjectValueL( KMPXMediaDrmInterval, |
|
549 intervalSeconds ); |
|
550 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetIntervalL(): setting interval"); |
|
551 } |
|
552 } |
|
553 } |
|
554 } |
|
555 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetIntervalL() exiting"); |
|
556 } |
|
557 |
|
558 // ---------------------------------------------------------------------------- |
|
559 // Gets the sending allowed attribute if not already obtained |
|
560 // ---------------------------------------------------------------------------- |
|
561 // |
|
562 void CMPXDrmMediaWmaAgent::GetSendingAllowedL() |
|
563 { |
|
564 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetSendingAllowedL() entering"); |
|
565 |
|
566 if ( !iMedia->IsSupported( KMPXMediaDrmSendingAllowed )) |
|
567 { |
|
568 TBool sendingAllowed( ETrue ); |
|
569 #ifndef _DEBUG |
|
570 User::LeaveIfError( |
|
571 iData->GetAttribute( EIsForwardable, sendingAllowed )); |
|
572 #else |
|
573 TInt sendErr( iData->GetAttribute( EIsForwardable, sendingAllowed )); |
|
574 MPX_DEBUG3("CMPXDrmMediaWmaAgent::GetSendingAllowedL(): err = %d, sendingAllowed = %d", sendErr, sendingAllowed); |
|
575 User::LeaveIfError( sendErr ); |
|
576 #endif |
|
577 iMedia->SetTObjectValueL( KMPXMediaDrmSendingAllowed, |
|
578 sendingAllowed ); |
|
579 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetSendingAllowedL(): setting sending allowed = %d", sendingAllowed); |
|
580 } |
|
581 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetSendingAllowedL() exiting"); |
|
582 } |
|
583 |
|
584 // ---------------------------------------------------------------------------- |
|
585 // Gets the can set automated attribute if not already obtained |
|
586 // ---------------------------------------------------------------------------- |
|
587 // |
|
588 void CMPXDrmMediaWmaAgent::GetCanSetAutomatedL() |
|
589 { |
|
590 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetCanSetAutomatedL() entering"); |
|
591 |
|
592 if ( !iMedia->IsSupported( KMPXMediaDrmCanSetAutomated )) |
|
593 { |
|
594 TBool automated( ETrue ); |
|
595 // For WMA DRM files, they can only be set automated if not protected |
|
596 TBool prot( EFalse ); |
|
597 if ( !iMedia->IsSupported( KMPXMediaDrmProtected )) |
|
598 { |
|
599 GetProtectedL(); |
|
600 } |
|
601 prot = iMedia->ValueTObjectL<TBool>( KMPXMediaDrmProtected ); |
|
602 if ( prot ) |
|
603 { |
|
604 automated = EFalse; |
|
605 } |
|
606 |
|
607 iMedia->SetTObjectValueL( KMPXMediaDrmCanSetAutomated, |
|
608 automated ); |
|
609 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetCanSetAutomatedL(): setting automated = %d", automated); |
|
610 } |
|
611 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetCanSetAutomatedL() exiting"); |
|
612 } |
|
613 |
|
614 // ----------------------------------------------------------------------------- |
|
615 // Get Rights Description String for WMDRM protected files |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 TInt CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL() |
|
619 { |
|
620 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL() entering"); |
|
621 MPX_DEBUG_THREAD("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL()"); |
|
622 TInt error( KErrNotFound ); |
|
623 |
|
624 if ( iRightsDescription ) |
|
625 { |
|
626 error = KErrNone; |
|
627 } |
|
628 else |
|
629 { |
|
630 // Currently software is that if no rights available, getting |
|
631 // rights string will panic PVWMCaf server. To be removed |
|
632 // if fixed in PV server later |
|
633 TBool canPlay( ETrue ); |
|
634 #ifndef _DEBUG |
|
635 User::LeaveIfError( iData->GetAttribute( ECanPlay, canPlay )); |
|
636 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL(): canPlay = %d", canPlay); |
|
637 #else |
|
638 TInt playErr( iData->GetAttribute( ECanPlay, canPlay )); |
|
639 MPX_DEBUG3("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL(): err = %d, canPlay = %d", playErr, canPlay ); |
|
640 User::LeaveIfError( playErr ); |
|
641 #endif |
|
642 if ( iRightsManager && canPlay ) |
|
643 { |
|
644 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL(): iFileName = %S", iFileName); |
|
645 RStreamablePtrArray<ContentAccess::CRightsInfo> rightsArray; |
|
646 CleanupClosePushL( rightsArray ); |
|
647 TRAPD( err, iRightsManager->ListRightsL( rightsArray, *iFileName )); |
|
648 if ( KErrNone == err ) |
|
649 { |
|
650 if ( rightsArray.Count() > 0 ) |
|
651 { |
|
652 ContentAccess::CRightsInfo* rightInfo = rightsArray[0]; |
|
653 iRightsDescription = rightInfo->Description().AllocL(); |
|
654 error = KErrNone; |
|
655 } |
|
656 } |
|
657 CleanupStack::PopAndDestroy( &rightsArray ); |
|
658 } |
|
659 } |
|
660 #ifdef _DEBUG |
|
661 if (!error) |
|
662 { |
|
663 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL(): %S", iRightsDescription); |
|
664 } |
|
665 #endif |
|
666 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetWmdrmRightsDescriptionL() exiting"); |
|
667 return error; |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CMPXDrmMediaWmaAgent::GetWmdrmTimeL |
|
672 // ----------------------------------------------------------------------------- |
|
673 // |
|
674 TInt CMPXDrmMediaWmaAgent::GetWmdrmTimeL( |
|
675 const TDesC& aTimeTypeDelimeter, |
|
676 TTime& aTime ) |
|
677 { |
|
678 MPX_DEBUG2("CMPXDrmMediaWmaAgent::GetWmdrmTimeL(%S) entering", &aTimeTypeDelimeter); |
|
679 TInt err( KErrNone ); |
|
680 |
|
681 if ( GetWmdrmRightsDescriptionL() == KErrNone ) |
|
682 { |
|
683 TPtr strPtr( iRightsDescription->Des() ); |
|
684 err = KErrNotFound; |
|
685 if ( strPtr.FindF( KMPXWmaDrmDelLicensesType ) == KErrNone ) |
|
686 { |
|
687 TInt begin = strPtr.FindF( aTimeTypeDelimeter ); |
|
688 if ( begin != KErrNotFound ) |
|
689 { |
|
690 err = KErrNone; |
|
691 TPtrC countPtr = strPtr.Mid( begin ); |
|
692 TInt semiLoc = countPtr.Locate( KMPXWmaDrmSemiColonChar ); |
|
693 TPtrC timePtr = strPtr.Mid( begin, semiLoc ); |
|
694 |
|
695 TInt finddash = timePtr.Locate( KMPXWmaDrmDashChar ); |
|
696 TInt dashcount = 0; |
|
697 while ( finddash != KErrNotFound && dashcount < KMPXWmaDrmDashCount ) |
|
698 { |
|
699 // after the first dash, subtract 1 from both day and time |
|
700 // as Jan 01 is represented by 00, 00 in TTime. |
|
701 ++dashcount; |
|
702 // convert buffer to TInt and decrement |
|
703 TLex lex( timePtr.Mid( finddash + 1, KMPXWmaDrmDashCount ) ); |
|
704 TInt dateInt; |
|
705 User::LeaveIfError( lex.Val( dateInt ) ); |
|
706 --dateInt; |
|
707 // convert back to buffer |
|
708 HBufC* datebuf = HBufC::NewLC( KMPXWmaDrmMaxTimeBufSize ); |
|
709 TPtr datebufPtr = datebuf->Des(); |
|
710 |
|
711 datebufPtr.Num( dateInt ); |
|
712 if ( datebufPtr.Length() < KMPXWmaDrmMinutesHourMinSize ) |
|
713 { |
|
714 datebufPtr.Insert( 0, KMPXWmaDrmTimeFill ); |
|
715 } |
|
716 strPtr.Replace( ( begin + finddash + 1 ), |
|
717 KMPXWmaDrmMinutesHourMinSize, datebufPtr ); |
|
718 strPtr.Delete( ( begin + finddash ), 1 ); |
|
719 finddash = timePtr.Locate( KMPXWmaDrmDashChar ); |
|
720 CleanupStack::PopAndDestroy( datebuf ); |
|
721 } |
|
722 |
|
723 // Format time to correspond TTime time |
|
724 TInt findTdelim = timePtr.Locate( KMPXWmaDrmTChar ); |
|
725 if ( findTdelim != KErrNone ) |
|
726 { |
|
727 TInt findcolon = timePtr.Locate( KMPXWmaDrmColonChar ); |
|
728 while ( findcolon != KErrNotFound ) |
|
729 { |
|
730 strPtr.Delete( ( begin + findcolon ), 1 ); |
|
731 findcolon = timePtr.Locate( KMPXWmaDrmColonChar ); |
|
732 } |
|
733 } |
|
734 |
|
735 strPtr.Replace( ( begin + findTdelim), 1, KMPXWmaDrmDelColon ); |
|
736 |
|
737 // have removed desired characters from time, now isolate them. |
|
738 TInt end = timePtr.Locate( KMPXWmaDrmPeriodChar ); |
|
739 if ( end == KErrNotFound ) |
|
740 { |
|
741 // no milliseconds, look for time zone indicator +, -, or Z |
|
742 end = timePtr.Locate( KMPXWmaDrmZChar ); |
|
743 if ( end == KErrNotFound ) |
|
744 { |
|
745 end = timePtr.Locate( KMPXWmaDrmDashChar ); |
|
746 if ( end == KErrNotFound ) |
|
747 { |
|
748 end = timePtr.Locate( KMPXWmaDrmPlusChar ); |
|
749 } |
|
750 } |
|
751 } |
|
752 TInt delimLen = aTimeTypeDelimeter.Length(); |
|
753 aTime.Set( strPtr.MidTPtr( begin + delimLen , end - delimLen ) ); |
|
754 } |
|
755 } |
|
756 } |
|
757 else |
|
758 { |
|
759 err = KErrNotFound; |
|
760 } |
|
761 |
|
762 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetWmdrmTimeL() exiting"); |
|
763 return err; |
|
764 } |
|
765 |
|
766 // ---------------------------------------------------------------------------- |
|
767 // Gets whether the DRM object is about to expire or not |
|
768 // ---------------------------------------------------------------------------- |
|
769 // |
|
770 void CMPXDrmMediaWmaAgent::GetAboutToExpireL() |
|
771 { |
|
772 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetAboutToExpireL() entering"); |
|
773 |
|
774 TBool aboutToExpire( EFalse ); |
|
775 |
|
776 // Currently WMDRM does not use about to expire |
|
777 |
|
778 iMedia->SetTObjectValueL( KMPXMediaDrmAboutToExpire, |
|
779 aboutToExpire ); |
|
780 |
|
781 MPX_DEBUG1("CMPXDrmMediaWmaAgent::GetAboutToExpireL() exiting"); |
|
782 } |
|
783 |
|
784 // end of file |