|
1 /* |
|
2 * Copyright (c) 2005 - 2009 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: Implementation of the Manager Interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <caf/caf.h> |
|
21 #include <http.h> |
|
22 #include <http/rhttpheaders.h> |
|
23 #include <stringpool.h> |
|
24 #include <utf.h> |
|
25 |
|
26 |
|
27 #include <w32std.h> |
|
28 #include <apparc.h> |
|
29 #include <apgtask.h> |
|
30 #include <apgcli.h> |
|
31 #include <apaserverapp.h> |
|
32 #include <sysutil.h> |
|
33 #include <centralrepository.h> |
|
34 |
|
35 #include "oma2agentmanager.h" |
|
36 #include "oma2agentattributes.h" |
|
37 #include "oma1dcf.h" |
|
38 #include "oma2dcf.h" |
|
39 #include "drmrightsclient.h" |
|
40 |
|
41 #include "drmutilityinternalcrkeys.h" // Cenrep extension for OmaBased |
|
42 |
|
43 using namespace ContentAccess; |
|
44 |
|
45 |
|
46 const TInt KMinimumOma1DcfLength = 16; |
|
47 |
|
48 const TInt KCenRepDataLength( 50 ); |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 LOCAL_C void DecryptL( |
|
53 const TDesC8& aContent, |
|
54 TDes8& aOutput) |
|
55 { |
|
56 COma1Dcf* dcf = NULL; |
|
57 TBuf8<KDCFKeySize> iv; |
|
58 TPtr8 input(NULL, 0); |
|
59 RDRMRightsClient client; |
|
60 TPtr8 ptr(NULL, 0); |
|
61 |
|
62 dcf = COma1Dcf::NewL(aContent.Mid(1)); |
|
63 CleanupStack::PushL(dcf); |
|
64 User::LeaveIfError(client.Connect()); |
|
65 CleanupClosePushL(client); |
|
66 User::LeaveIfError(client.Consume(aContent[0], *dcf->iContentID)); |
|
67 User::LeaveIfError(client.InitializeKey(*dcf->iContentID)); |
|
68 |
|
69 iv.Copy(aContent.Mid(dcf->iOffset + 1, KDCFKeySize)); |
|
70 aOutput.Copy(&aContent[dcf->iOffset + KDCFKeySize + 1], dcf->iDataLength - |
|
71 KDCFKeySize); |
|
72 ptr.Set(&aOutput[0], aOutput.Length(), aOutput.Length()); |
|
73 User::LeaveIfError(client.Decrypt(iv, ptr, ETrue)); |
|
74 |
|
75 dcf->iPlainTextLength = aOutput.Length(); |
|
76 dcf->iPadding = dcf->iDataLength - dcf->iPlainTextLength; |
|
77 client.Consume(EStop, *dcf->iContentID); |
|
78 CleanupStack::PopAndDestroy(2); // client, dcf |
|
79 } |
|
80 |
|
81 LOCAL_C TInt SetName( const TDesC8& aContentUri, |
|
82 const TDesC& aContentName ) |
|
83 { |
|
84 RDRMRightsClient client; |
|
85 TInt r = KErrNone; |
|
86 r = client.Connect(); |
|
87 if( !r ) |
|
88 { |
|
89 r = client.SetName( aContentUri, aContentName ); |
|
90 } |
|
91 client.Close(); |
|
92 return r; |
|
93 } |
|
94 |
|
95 |
|
96 // ============================ MEMBER FUNCTIONS =============================== |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // COma2AgentManager::COma2AgentManager |
|
100 // C++ default constructor can NOT contain any code, that |
|
101 // might leave. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 COma2AgentManager::COma2AgentManager(void): |
|
105 iNotifier(NULL), |
|
106 iWatchedId(NULL) |
|
107 { |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // COma2AgentManager::ConstructL |
|
112 // Symbian 2nd phase constructor can leave. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void COma2AgentManager::ConstructL() |
|
116 { |
|
117 User::LeaveIfError(iFs.Connect()); |
|
118 User::LeaveIfError(iFs.ShareAuto()); |
|
119 iFileManager = CFileMan::NewL(iFs); |
|
120 |
|
121 TInt err( KErrNone ); |
|
122 |
|
123 TRAP(err, FetchOmaBasedInfoL() ); |
|
124 if( err) |
|
125 { |
|
126 if( iOmaBasedMimeType ) |
|
127 { |
|
128 delete iOmaBasedMimeType; |
|
129 } |
|
130 iOmaBasedMimeType = NULL; |
|
131 } |
|
132 |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // COma2AgentManager::FetchOmaBasedInfoL |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void COma2AgentManager::FetchOmaBasedInfoL() |
|
140 { |
|
141 TInt err = KErrNone; |
|
142 CRepository* repository( NULL ); |
|
143 RBuf bOmaBasedMimeType; |
|
144 |
|
145 CleanupClosePushL(bOmaBasedMimeType); |
|
146 bOmaBasedMimeType.CreateL( KCenRepDataLength ); |
|
147 |
|
148 TRAP( err, repository = CRepository::NewL( KCRUidOmaBased ) ); |
|
149 if ( !err ) |
|
150 { |
|
151 CleanupStack::PushL( repository ); |
|
152 |
|
153 err = repository->Get( KOmaBasedMimeType, bOmaBasedMimeType ); |
|
154 if( !err ) |
|
155 { |
|
156 iOmaBasedMimeType = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bOmaBasedMimeType ); |
|
157 } |
|
158 CleanupStack::PopAndDestroy( repository ); |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(); |
|
162 |
|
163 User::LeaveIfError( err ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // COma2AgentManager::NewL |
|
168 // Two-phased constructor. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 COma2AgentManager* COma2AgentManager::NewL() |
|
172 { |
|
173 COma2AgentManager* self = NewLC(); |
|
174 CleanupStack::Pop(self); |
|
175 return self; |
|
176 } |
|
177 |
|
178 COma2AgentManager* COma2AgentManager::NewLC() |
|
179 { |
|
180 COma2AgentManager* self=new(ELeave) COma2AgentManager(); |
|
181 CleanupStack::PushL(self); |
|
182 self->ConstructL(); |
|
183 return self; |
|
184 } |
|
185 |
|
186 COma2AgentManager::~COma2AgentManager() |
|
187 { |
|
188 delete iFileManager; |
|
189 iFs.Close(); |
|
190 if (iNotifier != NULL) |
|
191 { |
|
192 if( iWatchedId ) |
|
193 { |
|
194 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
|
195 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
|
196 } |
|
197 delete iNotifier; |
|
198 } |
|
199 delete iWatchedId; |
|
200 |
|
201 delete iOmaBasedMimeType; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // COma2AgentManager::DeleteFile |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 TInt COma2AgentManager::DeleteFile(const TDesC& aFileName) |
|
209 { |
|
210 return iFs.Delete(aFileName); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // COma2AgentManager::CopyFile |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 TInt COma2AgentManager::CopyFile( |
|
218 const TDesC& aSource, |
|
219 const TDesC& aDestination) |
|
220 { |
|
221 TInt driveNumber = 0; |
|
222 TChar drive( aDestination[0] ); |
|
223 RFile file; |
|
224 TInt size = 0; |
|
225 TInt result = KErrNone; |
|
226 |
|
227 TInt err = KErrNone; |
|
228 TBool retval = KErrNone; |
|
229 |
|
230 |
|
231 // Check the destination drive letter |
|
232 result = iFs.CharToDrive(drive,driveNumber); |
|
233 |
|
234 if( result ) |
|
235 { |
|
236 return result; |
|
237 } |
|
238 |
|
239 // open the file to read the size |
|
240 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
|
241 |
|
242 if( result ) |
|
243 { |
|
244 return result; |
|
245 } |
|
246 |
|
247 // read the size |
|
248 result = file.Size( size ); |
|
249 |
|
250 // close the file |
|
251 file.Close(); |
|
252 |
|
253 if( result ) |
|
254 { |
|
255 return result; |
|
256 } |
|
257 |
|
258 // check that the drive has enough space for the copy operation |
|
259 |
|
260 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
|
261 size, |
|
262 driveNumber ) ) |
|
263 if( retval ) |
|
264 { |
|
265 return KErrDiskFull; |
|
266 } |
|
267 |
|
268 |
|
269 return iFileManager->Copy( aSource, aDestination); |
|
270 } |
|
271 |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CWmDrmAgentManager::CopyFile |
|
275 // |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 TInt COma2AgentManager::CopyFile(RFile& aSource, |
|
279 const TDesC& aDestination) |
|
280 { |
|
281 TInt driveNumber = 0; |
|
282 TChar drive( aDestination[0] ); |
|
283 TInt size = 0; |
|
284 TInt result = KErrNone; |
|
285 RFile output; |
|
286 TFileName fileName; |
|
287 |
|
288 TInt err = KErrNone; |
|
289 TBool retval = KErrNone; |
|
290 |
|
291 |
|
292 // Same file, do not even try to copy |
|
293 // And since they are the same don't return an error |
|
294 aSource.FullName( fileName ); |
|
295 |
|
296 if( !aDestination.CompareF( fileName ) ) |
|
297 { |
|
298 return KErrNone; |
|
299 } |
|
300 |
|
301 // Check the destination drive letter |
|
302 result = iFs.CharToDrive(drive,driveNumber); |
|
303 |
|
304 if( result ) |
|
305 { |
|
306 return result; |
|
307 } |
|
308 |
|
309 // read the size |
|
310 result = aSource.Size( size ); |
|
311 |
|
312 if( result ) |
|
313 { |
|
314 return result; |
|
315 } |
|
316 |
|
317 // check that the drive has enough space for the copy operation |
|
318 |
|
319 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
|
320 size, |
|
321 driveNumber ) ) |
|
322 if( retval ) |
|
323 |
|
324 { |
|
325 return KErrDiskFull; |
|
326 } |
|
327 |
|
328 // Perform the copy: |
|
329 |
|
330 // Rewind just in case: |
|
331 size = 0; |
|
332 result = aSource.Seek(ESeekStart, size); |
|
333 |
|
334 if( !result ) |
|
335 { |
|
336 result = iFileManager->Copy(aSource, aDestination); |
|
337 } |
|
338 |
|
339 return result; |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // COma2AgentManager::RenameFile |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 TInt COma2AgentManager::RenameFile( |
|
347 const TDesC& aSource, |
|
348 const TDesC& aDestination) |
|
349 { |
|
350 TInt driveNumber = 0; |
|
351 TChar drive( aDestination[0] ); |
|
352 RFile file; |
|
353 TInt size = 0; |
|
354 |
|
355 TInt err = KErrNone; |
|
356 TBool retval = KErrNone; |
|
357 |
|
358 |
|
359 TInt result( iFileManager->Rename(aSource, aDestination) ); |
|
360 // If the files are on a different drive, Rename will fail |
|
361 // Therefore we simulate the Move by doing a Copy, followed by Delete |
|
362 if ( result != KErrNone ) |
|
363 { |
|
364 // Check the destination drive letter |
|
365 result = iFs.CharToDrive(drive,driveNumber); |
|
366 |
|
367 if( result ) |
|
368 { |
|
369 return result; |
|
370 } |
|
371 |
|
372 // open the file to read the size |
|
373 result = file.Open(iFs, aSource, EFileShareReadersOrWriters|EFileRead); |
|
374 |
|
375 if( result ) |
|
376 { |
|
377 return result; |
|
378 } |
|
379 |
|
380 // read the size |
|
381 result = file.Size( size ); |
|
382 |
|
383 // close the file |
|
384 file.Close(); |
|
385 |
|
386 if( result ) |
|
387 { |
|
388 return result; |
|
389 } |
|
390 |
|
391 // check that the drive has enough space for the copy operation |
|
392 |
|
393 TRAP( err, retval = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
|
394 size, |
|
395 driveNumber ) ) |
|
396 if( retval ) |
|
397 |
|
398 { |
|
399 return KErrDiskFull; |
|
400 } |
|
401 |
|
402 |
|
403 result = iFileManager->Copy(aSource,aDestination); |
|
404 if (result == KErrNone) |
|
405 { |
|
406 // If the copy was successful try and delete the original |
|
407 result = iFileManager->Delete(aSource); |
|
408 if (result != KErrNone) |
|
409 { |
|
410 // Delete failed so try to cleanup the destination file |
|
411 // as we're going to exit with an error |
|
412 // We can safely ignore any error from this as the previous error |
|
413 // is more important to propagate, since this is just cleanup |
|
414 iFileManager->Delete(aDestination); |
|
415 } |
|
416 } |
|
417 } |
|
418 return result; |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // COma2AgentManager::MkDir |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 TInt COma2AgentManager::MkDir( |
|
426 const TDesC& aPath) |
|
427 { |
|
428 return iFs.MkDir( aPath ); |
|
429 } |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // COma2AgentManager::MkDirAll |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 TInt COma2AgentManager::MkDirAll( |
|
436 const TDesC& aPath) |
|
437 { |
|
438 return iFs.MkDirAll( aPath ); |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // COma2AgentManager::RmDir |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 TInt COma2AgentManager::RmDir( |
|
446 const TDesC& aPath) |
|
447 { |
|
448 return iFileManager->RmDir( aPath ); |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // COma2AgentManager::GetDir |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 TInt COma2AgentManager::GetDir( |
|
456 const TDesC& aName, |
|
457 TUint aEntryAttMask, |
|
458 TUint aEntrySortKey, |
|
459 CDir*& aEntryList) const |
|
460 { |
|
461 return iFs.GetDir( aName, aEntryAttMask, aEntrySortKey, aEntryList ); |
|
462 } |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // COma2AgentManager::GetDir |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 TInt COma2AgentManager::GetDir( |
|
469 const TDesC& aName, |
|
470 TUint aEntryAttMask, |
|
471 TUint aEntrySortKey, |
|
472 CDir*& aEntryList, |
|
473 CDir*& aDirList) const |
|
474 { |
|
475 return iFs.GetDir( aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList ); |
|
476 } |
|
477 |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // COma2AgentManager::GetDir |
|
481 // ----------------------------------------------------------------------------- |
|
482 // |
|
483 TInt COma2AgentManager::GetDir( |
|
484 const TDesC& aName, |
|
485 const TUidType& aEntryUid, |
|
486 TUint aEntrySortKey, |
|
487 CDir*& aFileList) const |
|
488 { |
|
489 return iFs.GetDir( aName, aEntryUid, aEntrySortKey, aFileList ); |
|
490 } |
|
491 |
|
492 // ----------------------------------------------------------------------------- |
|
493 // COma2AgentManager::GetAttribute |
|
494 // ----------------------------------------------------------------------------- |
|
495 // |
|
496 TInt COma2AgentManager::GetAttribute( |
|
497 TInt aAttribute, |
|
498 TInt& aValue, |
|
499 const TVirtualPathPtr& aVirtualPath) |
|
500 { |
|
501 TInt r = KErrNone; |
|
502 CDcfCommon* dcfFile = NULL; |
|
503 |
|
504 TRAP(r, dcfFile = CDcfCommon::NewL(aVirtualPath.URI())); |
|
505 if( r ) |
|
506 { |
|
507 return r; |
|
508 } |
|
509 aValue = TOma2AgentAttributes::GetAttribute(*dcfFile, aAttribute, aVirtualPath); |
|
510 delete dcfFile; |
|
511 return r; |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // COma2AgentManager::GetAttributeSet |
|
516 // ----------------------------------------------------------------------------- |
|
517 // |
|
518 TInt COma2AgentManager::GetAttributeSet( |
|
519 RAttributeSet& aAttributeSet, |
|
520 const TVirtualPathPtr& aVirtualPath) |
|
521 { |
|
522 TInt r = KErrNone; |
|
523 CDcfCommon *dcfFile = NULL; |
|
524 |
|
525 TRAP(r, dcfFile = CDcfCommon::NewL(aVirtualPath.URI())); |
|
526 if( r ) |
|
527 { |
|
528 return r; |
|
529 } |
|
530 r = TOma2AgentAttributes::GetAttributeSet(*dcfFile, aAttributeSet, aVirtualPath); |
|
531 delete dcfFile; |
|
532 return r; |
|
533 } |
|
534 |
|
535 // ----------------------------------------------------------------------------- |
|
536 // COma2AgentManager::GetStringAttributeSet |
|
537 // ----------------------------------------------------------------------------- |
|
538 // |
|
539 TInt COma2AgentManager::GetStringAttributeSet( |
|
540 RStringAttributeSet& aAttributeSet, |
|
541 const TVirtualPathPtr& aVirtualPath) |
|
542 { |
|
543 TInt r = KErrNone; |
|
544 CDcfCommon *dcfFile = NULL; |
|
545 |
|
546 TRAP(r, dcfFile = CDcfCommon::NewL(aVirtualPath.URI())); |
|
547 if( r ) |
|
548 { |
|
549 return r; |
|
550 } |
|
551 r = TOma2AgentAttributes::GetStringAttributeSet( |
|
552 *dcfFile, aAttributeSet, aVirtualPath); |
|
553 delete dcfFile; |
|
554 return r; |
|
555 } |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // COma2AgentManager::GetStringAttribute |
|
559 // ----------------------------------------------------------------------------- |
|
560 // |
|
561 TInt COma2AgentManager::GetStringAttribute( |
|
562 TInt aAttribute, |
|
563 TDes& aValue, |
|
564 const TVirtualPathPtr& aVirtualPath) |
|
565 { |
|
566 TInt r = KErrNone; |
|
567 CDcfCommon *dcfFile = NULL; |
|
568 |
|
569 TRAP(r, dcfFile = CDcfCommon::NewL(aVirtualPath.URI())); |
|
570 if( r ) |
|
571 { |
|
572 return r; |
|
573 } |
|
574 r = TOma2AgentAttributes::GetStringAttribute( |
|
575 *dcfFile, aAttribute, aValue, aVirtualPath); |
|
576 delete dcfFile; |
|
577 return r; |
|
578 } |
|
579 |
|
580 // ----------------------------------------------------------------------------- |
|
581 // COma2AgentManager::NotifyStatusChange |
|
582 // ----------------------------------------------------------------------------- |
|
583 // |
|
584 void COma2AgentManager::NotifyStatusChange( |
|
585 const TDesC& aUri, |
|
586 TEventMask aEventMask, |
|
587 TRequestStatus& aStatus) |
|
588 { |
|
589 CDcfCommon* dcf = NULL; |
|
590 TInt r = 0; |
|
591 |
|
592 if( iWatchedId != NULL ) |
|
593 { |
|
594 if( iNotifier ) |
|
595 { |
|
596 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
|
597 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
|
598 } |
|
599 delete iWatchedId; |
|
600 } |
|
601 iWatchedEvents = TEventMask(0); |
|
602 |
|
603 if (iNotifier == NULL) |
|
604 { |
|
605 TRAP(r, iNotifier = CDRMNotifier::NewL()); |
|
606 } |
|
607 TRAP(r, dcf = CDcfCommon::NewL(aUri)); |
|
608 if (iNotifier != NULL && dcf != NULL) |
|
609 { |
|
610 iStatus = &aStatus; |
|
611 iWatchedEvents = aEventMask; |
|
612 TRAP_IGNORE( iWatchedId = dcf->iContentID->AllocL() ); |
|
613 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
|
614 TRAP(r, iNotifier->RegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
|
615 *iStatus = KRequestPending; |
|
616 delete dcf; |
|
617 } |
|
618 if (r != KErrNone) |
|
619 { |
|
620 User::RequestComplete(iStatus, r); |
|
621 } |
|
622 } |
|
623 |
|
624 // ----------------------------------------------------------------------------- |
|
625 // COma2AgentManager::CancelNotifyStatusChange |
|
626 // ----------------------------------------------------------------------------- |
|
627 // |
|
628 TInt COma2AgentManager::CancelNotifyStatusChange( |
|
629 const TDesC& /*aUri*/, |
|
630 TRequestStatus& aStatus) |
|
631 { |
|
632 iStatus = &aStatus; |
|
633 if (iWatchedId != NULL) |
|
634 { |
|
635 if( iNotifier ) |
|
636 { |
|
637 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId)); |
|
638 TRAP_IGNORE(iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId)); |
|
639 } |
|
640 delete iWatchedId; |
|
641 iWatchedId = NULL; |
|
642 } |
|
643 iWatchedEvents = TEventMask(0); |
|
644 User::RequestComplete(iStatus, KErrCancel); |
|
645 return KErrNone; |
|
646 } |
|
647 |
|
648 // ----------------------------------------------------------------------------- |
|
649 // COma2AgentManager::SetProperty |
|
650 // ----------------------------------------------------------------------------- |
|
651 // |
|
652 TInt COma2AgentManager::SetProperty( |
|
653 TAgentProperty /*aProperty*/, |
|
654 TInt /*aValue*/) |
|
655 { |
|
656 return KErrCANotSupported; |
|
657 } |
|
658 |
|
659 // ----------------------------------------------------------------------------- |
|
660 // COma2AgentManager::DisplayInfoL |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 void COma2AgentManager::DisplayInfoL( |
|
664 TDisplayInfo /*aInfo*/, |
|
665 const TVirtualPathPtr& /*aVirtualPath*/) |
|
666 { |
|
667 User::Leave(KErrCANotSupported); |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // COma2AgentManager::IsRecognizedL |
|
672 // ----------------------------------------------------------------------------- |
|
673 // |
|
674 TBool COma2AgentManager::IsRecognizedL( |
|
675 const TDesC& aUri, |
|
676 TContentShareMode /*aShareMode*/) const |
|
677 { |
|
678 TBuf8<40> buffer; // Size increased to 40 |
|
679 TBool r = EFalse; |
|
680 |
|
681 User::LeaveIfError(iFs.ReadFileSection(aUri, 0, buffer, buffer.MaxLength())); |
|
682 if (COma1Dcf::IsValidDcf(buffer) || COma2Dcf::IsValidDcf(buffer)) |
|
683 { |
|
684 r = ETrue; |
|
685 } |
|
686 return r; |
|
687 } |
|
688 |
|
689 // ----------------------------------------------------------------------------- |
|
690 // COma2AgentManager::IsRecognizedL |
|
691 // ----------------------------------------------------------------------------- |
|
692 // |
|
693 TBool COma2AgentManager::IsRecognizedL( |
|
694 RFile& aFile) const |
|
695 { |
|
696 TBuf8<40> buffer; // Size increased to 40 |
|
697 TBool r = EFalse; |
|
698 TInt pos = 0; |
|
699 |
|
700 User::LeaveIfError(aFile.Seek(ESeekStart, pos)); |
|
701 User::LeaveIfError(aFile.Read(buffer, buffer.MaxLength())); |
|
702 if (COma1Dcf::IsValidDcf(buffer) || COma2Dcf::IsValidDcf(buffer)) |
|
703 { |
|
704 r = ETrue; |
|
705 } |
|
706 return r; |
|
707 } |
|
708 |
|
709 // ----------------------------------------------------------------------------- |
|
710 // COma2AgentManager::RecognizeFileL |
|
711 // Only check from the file in case the buffer is not large enough to give |
|
712 // a definitive answer. |
|
713 // ----------------------------------------------------------------------------- |
|
714 // |
|
715 TBool COma2AgentManager::RecognizeFileL( |
|
716 const TDesC& aFileName, |
|
717 const TDesC8& aBuffer, |
|
718 TDes8& aFileMimeType, |
|
719 TDes8& aContentMimeType) const |
|
720 { |
|
721 TBool r = EFalse; |
|
722 TInt err = KErrNone; |
|
723 CDcfCommon* dcf = NULL; |
|
724 |
|
725 #ifdef __DRM_OMA2 |
|
726 if ( !aFileName.Right(4).CompareF( KOma2DcfExtension ) || |
|
727 !aFileName.Right(4).CompareF( KOma2DcfExtensionAudio ) || |
|
728 !aFileName.Right(4).CompareF( KOma2DcfExtensionVideo ) || |
|
729 COma2Dcf::IsValidDcf(aBuffer) ) |
|
730 { |
|
731 aFileMimeType.Copy(KOma2DcfContentType); |
|
732 aContentMimeType.Copy(KCafMimeType); |
|
733 r = ETrue; // file was recognized as OMA2 DCF |
|
734 } |
|
735 else |
|
736 { |
|
737 #endif |
|
738 // Check if the given buffer if a valid buffer, or if it's too short: |
|
739 if (COma1Dcf::IsValidDcf(aBuffer) || |
|
740 aBuffer.Length() < KMinimumOma1DcfLength ) |
|
741 { |
|
742 |
|
743 // Check if we can get all the information we need from the buffer. |
|
744 TRAP(err, dcf = COma1Dcf::NewL(aBuffer)); |
|
745 |
|
746 // if we can't and we have a filename check from the file |
|
747 if (dcf == NULL && aFileName != KNullDesC) |
|
748 { |
|
749 dcf = CDcfCommon::NewL(aFileName); |
|
750 } |
|
751 |
|
752 // If the dcf object creation worked get the information needed and |
|
753 // mark the file as recognized. Check for specific mimetypes |
|
754 if (dcf != NULL) |
|
755 { |
|
756 CleanupStack::PushL(dcf); |
|
757 if ((dcf->iMimeType->Des()).CompareF(*iOmaBasedMimeType)) |
|
758 { |
|
759 aFileMimeType.Copy(KOma1DcfContentType); |
|
760 aContentMimeType.Copy(*dcf->iMimeType); |
|
761 r = ETrue; // file was recognized as OMA1 DCF |
|
762 } |
|
763 CleanupStack::PopAndDestroy(); |
|
764 } |
|
765 |
|
766 } |
|
767 #ifdef __DRM_OMA2 |
|
768 } |
|
769 #endif |
|
770 return r; |
|
771 } |
|
772 |
|
773 |
|
774 // ----------------------------------------------------------------------------- |
|
775 // COma2AgentManager::AgentSpecificCommand |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 TInt COma2AgentManager::AgentSpecificCommand( |
|
779 TInt aCommand, |
|
780 const TDesC8& aInputBuffer, |
|
781 TDes8& aOutputBuffer) |
|
782 { |
|
783 TInt r = KErrCANotSupported; |
|
784 RDRMRightsClient client; |
|
785 TInt value = 0; |
|
786 TInt size = 0; |
|
787 TTimeIntervalSeconds interval; |
|
788 TPtrC8 contentUri; |
|
789 TPtrC16 contentName; |
|
790 |
|
791 switch( aCommand ) |
|
792 { |
|
793 case EOmaDrmMethods: |
|
794 { |
|
795 aOutputBuffer.Copy(_L8("FL CD SD")); |
|
796 #ifdef __DRM_OMA2 |
|
797 aOutputBuffer.Append(_L8(" OMADRM2")); |
|
798 #endif |
|
799 } |
|
800 break; |
|
801 case ESetPendingRightsETA: |
|
802 { |
|
803 Mem::Copy( &value, aInputBuffer.Ptr(), sizeof(TInt) ); |
|
804 interval = value; |
|
805 contentUri.Set( aInputBuffer.Ptr() + sizeof(TInt), |
|
806 aInputBuffer.Size()-sizeof(TInt) ); |
|
807 |
|
808 r = client.Connect(); |
|
809 if( !r ) |
|
810 { |
|
811 r = client.SetEstimatedArrival( contentUri, |
|
812 interval ); |
|
813 } |
|
814 // close the handle: |
|
815 client.Close(); |
|
816 } |
|
817 break; |
|
818 case EBufferContainsOma1Dcf: |
|
819 if (COma1Dcf::IsValidDcf(aInputBuffer)) |
|
820 { |
|
821 r = KErrNone; |
|
822 } |
|
823 else |
|
824 { |
|
825 r = KErrNotFound; |
|
826 } |
|
827 break; |
|
828 case EDecryptOma1DcfBuffer: |
|
829 r = KErrNone; |
|
830 TRAP(r, DecryptL(aInputBuffer, aOutputBuffer)); |
|
831 break; |
|
832 case ESetContentName: |
|
833 Mem::Copy( &value, aInputBuffer.Ptr(), sizeof(TInt)); |
|
834 contentName.Set( |
|
835 reinterpret_cast<TUint16*>( |
|
836 const_cast<TUint8*>(aInputBuffer.Ptr() + sizeof(TInt))), |
|
837 value ); |
|
838 |
|
839 size = aInputBuffer.Size(); |
|
840 size -= value*2; |
|
841 size -= sizeof(TInt); |
|
842 |
|
843 contentUri.Set( aInputBuffer.Ptr() + sizeof(TInt) + value*2, |
|
844 size ); |
|
845 |
|
846 r = SetName( contentUri, contentName ); |
|
847 break; |
|
848 default: |
|
849 break; |
|
850 } |
|
851 |
|
852 return r; |
|
853 } |
|
854 |
|
855 // ----------------------------------------------------------------------------- |
|
856 // COma2AgentManager::AgentSpecificCommand |
|
857 // ----------------------------------------------------------------------------- |
|
858 // |
|
859 void COma2AgentManager::AgentSpecificCommand( |
|
860 TInt aCommand, |
|
861 const TDesC8& aInputBuffer, |
|
862 TDes8& aOutputBuffer, |
|
863 TRequestStatus& aStatus) |
|
864 { |
|
865 TRequestStatus *ptr = &aStatus; |
|
866 User::RequestComplete(ptr, AgentSpecificCommand(aCommand, aInputBuffer, |
|
867 aOutputBuffer)); |
|
868 } |
|
869 |
|
870 // ----------------------------------------------------------------------------- |
|
871 // COma2AgentManager::PrepareHTTPRequestHeaders |
|
872 // ----------------------------------------------------------------------------- |
|
873 // |
|
874 void COma2AgentManager::PrepareHTTPRequestHeaders( |
|
875 RStringPool& aStringPool, |
|
876 RHTTPHeaders& aRequestHeaders) const |
|
877 { |
|
878 TRAP_IGNORE( PrepareHTTPRequestHeadersL(aStringPool, aRequestHeaders) ); |
|
879 } |
|
880 |
|
881 // ----------------------------------------------------------------------------- |
|
882 // COma2AgentManager::PrepareHTTPRequestHeadersL |
|
883 // ----------------------------------------------------------------------------- |
|
884 // |
|
885 void COma2AgentManager::PrepareHTTPRequestHeadersL( |
|
886 RStringPool& aStringPool, |
|
887 RHTTPHeaders& aRequestHeaders) const |
|
888 { |
|
889 TBuf8<KMaxDataTypeLength> mimeType; |
|
890 RStringF string; |
|
891 THTTPHdrVal header; |
|
892 |
|
893 mimeType.Copy(KOma1DrmMessageContentType); |
|
894 string = aStringPool.OpenFStringL(mimeType); |
|
895 CleanupClosePushL(string); |
|
896 header.SetStrF(string); |
|
897 aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, |
|
898 RHTTPSession::GetTable()), header); |
|
899 CleanupStack::PopAndDestroy(); |
|
900 |
|
901 mimeType.Copy(KOma1DcfContentType); |
|
902 string = aStringPool.OpenFStringL(mimeType); |
|
903 CleanupClosePushL(string); |
|
904 header.SetStrF(string); |
|
905 aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, |
|
906 RHTTPSession::GetTable()), header); |
|
907 CleanupStack::PopAndDestroy(); |
|
908 |
|
909 mimeType.Copy(KOma2DcfContentType); |
|
910 string = aStringPool.OpenFStringL(mimeType); |
|
911 CleanupClosePushL(string); |
|
912 header.SetStrF(string); |
|
913 aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, |
|
914 RHTTPSession::GetTable()), header); |
|
915 CleanupStack::PopAndDestroy(); |
|
916 |
|
917 mimeType.Copy(KOma2RoContentType); |
|
918 string = aStringPool.OpenFStringL(mimeType); |
|
919 CleanupClosePushL(string); |
|
920 header.SetStrF(string); |
|
921 aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, |
|
922 RHTTPSession::GetTable()), header); |
|
923 CleanupStack::PopAndDestroy(); |
|
924 |
|
925 mimeType.Copy(KOma2TriggerContentType); |
|
926 string = aStringPool.OpenFStringL(mimeType); |
|
927 CleanupClosePushL(string); |
|
928 header.SetStrF(string); |
|
929 aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, |
|
930 RHTTPSession::GetTable()), header); |
|
931 CleanupStack::PopAndDestroy(); |
|
932 } |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 // ----------------------------------------------------------------------------- |
|
938 // COma2AgentContent::HandleEventL |
|
939 // Handle notifier events here. Not much logic, consider all events as rights |
|
940 // changes. |
|
941 // ----------------------------------------------------------------------------- |
|
942 // |
|
943 void COma2AgentManager::HandleEventL( |
|
944 MDRMEvent* /*aEvent*/) |
|
945 { |
|
946 RDRMRightsClient client; |
|
947 TInt r; |
|
948 TUint32 reason = 0; |
|
949 |
|
950 if (client.Connect() == KErrNone && iWatchedId != NULL) |
|
951 { |
|
952 r = client.CheckRights(EUnknown, *iWatchedId, reason); |
|
953 if (r == KErrNone && (iWatchedEvents & ERightsAvailable) || |
|
954 r != KErrNone && (iWatchedEvents & ERightsExpired)) |
|
955 { |
|
956 iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId); |
|
957 iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId); |
|
958 delete iWatchedId; |
|
959 iWatchedId = NULL; |
|
960 iWatchedEvents = TEventMask(0); |
|
961 User::RequestComplete(iStatus, KErrNone); |
|
962 } |
|
963 client.Close(); |
|
964 } |
|
965 } |
|
966 |
|
967 |
|
968 // ----------------------------------------------------------------------------- |
|
969 // COma2AgentManager::DisplayManagementInfoL |
|
970 // ----------------------------------------------------------------------------- |
|
971 // |
|
972 void COma2AgentManager::DisplayManagementInfoL() |
|
973 { |
|
974 TUid KRightsManagerUid = TUid::Uid(0x101F85C7); |
|
975 RWsSession wsSession; |
|
976 RApaLsSession appArcSession; |
|
977 TThreadId id; |
|
978 |
|
979 User::LeaveIfError(wsSession.Connect()); |
|
980 CleanupClosePushL(wsSession); |
|
981 TApaTaskList tasklist(wsSession); |
|
982 TApaTask task = tasklist.FindApp(KRightsManagerUid); |
|
983 if (task.Exists()) |
|
984 { |
|
985 task.SendMessage(TUid::Uid(KUidApaMessageSwitchOpenFileValue), |
|
986 KNullDesC8); |
|
987 } |
|
988 else |
|
989 { |
|
990 User::LeaveIfError(appArcSession.Connect()); |
|
991 appArcSession.StartDocument(_L("0"), KRightsManagerUid, id); |
|
992 appArcSession.Close(); |
|
993 } |
|
994 CleanupStack::PopAndDestroy(); |
|
995 } |
|
996 |
|
997 // End of File |