38 #include <DrmUtilityDmgrWrapper.rsg> |
37 #include <DrmUtilityDmgrWrapper.rsg> |
39 |
38 |
40 #include <RoapEng.h> |
39 #include <RoapEng.h> |
41 #include <RoapDef.h> |
40 #include <RoapDef.h> |
42 #include <RoapObserver.h> |
41 #include <RoapObserver.h> |
|
42 |
|
43 // including files related to qt changes |
|
44 #include <qstring.h> |
|
45 #include <downloadmanager.h> |
|
46 #include <download.h> |
|
47 #include <dmcommon.h> |
|
48 #include <downloadevent.h> |
43 |
49 |
44 #include "RoapSyncWrapper.h" |
50 #include "RoapSyncWrapper.h" |
45 #include "RoapDef.h" |
51 #include "RoapDef.h" |
46 #include "DrmUtilityDmgrWrapper.h" |
52 #include "DrmUtilityDmgrWrapper.h" |
47 #include "DrmUtilityDmgrWrapperLogger.h" |
53 #include "DrmUtilityDmgrWrapperLogger.h" |
48 #include "drmutilityconnection.h" |
54 #include "drmutilityconnection.h" |
49 #include "buffercontainers.h" //CnameContainer etc. |
55 #include "buffercontainers.h" //CnameContainer etc. |
50 #include "cleanupresetanddestroy.h" |
56 #include "cleanupresetanddestroy.h" |
51 #include "buffercontainers.h" |
57 #include "buffercontainers.h" |
|
58 #include "qdrmutilitydmgreventhandler.h" |
52 |
59 |
53 #include "OstTraceDefinitions.h" |
60 #include "OstTraceDefinitions.h" |
54 #ifdef OST_TRACE_COMPILER_IN_USE |
61 #ifdef OST_TRACE_COMPILER_IN_USE |
55 #include "DrmUtilityDmgrWrapperTraces.h" |
62 #include "DrmUtilityDmgrWrapperTraces.h" |
56 #endif |
63 #endif |
91 } |
100 } |
92 } |
101 } |
93 |
102 |
94 |
103 |
95 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
96 // DeleteHttpDowload |
105 // Calls the appropriate member function of the object during object cleanup |
97 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
98 // |
107 // |
99 LOCAL_C void DeleteHttpDowload(TAny* aDownload) |
108 template<class _Ty, class _Tf> class mem_auto_ptr |
100 { |
109 { |
101 reinterpret_cast<RHttpDownload*> (aDownload)->Delete(); |
110 public: |
102 } |
111 explicit mem_auto_ptr(_Ty _P = 0, _Tf _F = 0) |
|
112 : _Owns(_P != 0), _Ptr(_P), _Fn(_F) |
|
113 {} |
|
114 |
|
115 mem_auto_ptr(const mem_auto_ptr<_Ty,_Tf>& _Y) |
|
116 : _Owns(_Y._Owns), _Ptr(_Y.release()), _Fn(_Y.function()) |
|
117 {} |
|
118 |
|
119 mem_auto_ptr<_Ty,_Tf>& operator=(const mem_auto_ptr<_Ty,_Tf>& _Y) |
|
120 { |
|
121 if (this != &_Y) |
|
122 { |
|
123 _Fn = _Y.function(); |
|
124 if (_Ptr != _Y.get()) |
|
125 { |
|
126 if (_Owns) |
|
127 delete _Ptr; |
|
128 _Owns = _Y._Owns; |
|
129 } |
|
130 else if (_Y._Owns) |
|
131 _Owns = true; |
|
132 _Ptr = _Y.release(); |
|
133 } |
|
134 return (*this); |
|
135 } |
|
136 |
|
137 ~mem_auto_ptr() |
|
138 { |
|
139 if (_Owns) |
|
140 { |
|
141 (_Ptr->*_Fn)(); |
|
142 } |
|
143 } |
|
144 |
|
145 _Ty& operator*() const |
|
146 { |
|
147 return (*get()); |
|
148 } |
|
149 |
|
150 _Ty *operator->() const |
|
151 { |
|
152 return (get()); |
|
153 } |
|
154 |
|
155 _Ty *get() const |
|
156 { |
|
157 return (_Ptr); |
|
158 } |
|
159 |
|
160 _Ty *release() const |
|
161 { |
|
162 ((mem_auto_ptr<_Ty,_Tf> *)this)->_Owns = false; |
|
163 return (_Ptr); |
|
164 } |
|
165 |
|
166 _Tf *function() const |
|
167 { |
|
168 return (_Fn); |
|
169 } |
|
170 private: |
|
171 bool _Owns; |
|
172 _Ty _Ptr; |
|
173 _Tf _Fn; |
|
174 }; |
103 |
175 |
104 |
176 |
105 // --------------------------------------------------------------------------- |
177 // --------------------------------------------------------------------------- |
106 // UpdateBufferL |
178 // UpdateBufferL |
107 // --------------------------------------------------------------------------- |
179 // --------------------------------------------------------------------------- |
140 void CDrmUtilityDmgrWrapper::ConstructL() |
212 void CDrmUtilityDmgrWrapper::ConstructL() |
141 { |
213 { |
142 CLOG_WRITE( "DMgrWrapper::ConstructL" ); |
214 CLOG_WRITE( "DMgrWrapper::ConstructL" ); |
143 const TInt KDrmUtilityDmgrWrapperUid = 0x102830FE; |
215 const TInt KDrmUtilityDmgrWrapperUid = 0x102830FE; |
144 iConnection = DRM::CDrmUtilityConnection::NewL(ETrue); |
216 iConnection = DRM::CDrmUtilityConnection::NewL(ETrue); |
145 iDlMgr.ConnectL(TUid::Uid(KDrmUtilityDmgrWrapperUid), *this, EFalse); |
217 |
|
218 try |
|
219 { |
|
220 QString drmUtilityDmgrWrapperUid(QString::number(KDrmUtilityDmgrWrapperUid)); |
|
221 iDlMgr = q_check_ptr(new DownloadManager(drmUtilityDmgrWrapperUid)); |
|
222 } |
|
223 catch(const std::exception& exception) |
|
224 { |
|
225 qt_symbian_exception2LeaveL(exception); |
|
226 } |
146 iProgressInfo = NULL; |
227 iProgressInfo = NULL; |
147 iProgressNoteDialog = NULL; |
228 iProgressNoteDialog = NULL; |
148 iDialogDismissed = ETrue; |
229 iDialogDismissed = ETrue; |
149 User::LeaveIfError(iFs.Connect()); |
230 User::LeaveIfError(iFs.Connect()); |
150 User::LeaveIfError(iFs.ShareProtected()); |
231 User::LeaveIfError(iFs.ShareProtected()); |
316 CompleteToState(EComplete, KErrNone); |
387 CompleteToState(EComplete, KErrNone); |
317 return; |
388 return; |
318 } |
389 } |
319 |
390 |
320 TPtrC8 KNullPtr8(NULL, 0); |
391 TPtrC8 KNullPtr8(NULL, 0); |
321 RHttpDownload* downloadPtr(iDlMgr.FindDownload(*iTriggerUrl, KNullPtr8)); |
392 QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); |
322 if (downloadPtr) |
393 //uncomment |
|
394 Download* download = NULL;//iDlMgr->findDownload( downloadUrl ); |
|
395 if (download) |
323 { |
396 { |
324 // Stale download found. |
397 // Stale download found. |
325 // Remove it, and re-create a new download. |
398 // Remove it, and re-create a new download. |
326 downloadPtr->Delete(); |
399 download->cancel(); |
327 downloadPtr = NULL; |
400 download = NULL; |
328 if (iFileName) |
401 if (iFileName) |
329 { |
402 { |
330 iFs.Delete(*iFileName); |
403 iFs.Delete(*iFileName); |
331 } |
404 } |
332 } |
405 } |
333 |
|
334 triggerFileName=DRM::CFileNameContainer::NewLC(); |
406 triggerFileName=DRM::CFileNameContainer::NewLC(); |
|
407 |
335 #ifndef RD_MULTIPLE_DRIVE |
408 #ifndef RD_MULTIPLE_DRIVE |
336 |
409 |
337 User::LeaveIfError( roapTrigger.Temp( |
410 User::LeaveIfError( roapTrigger.Temp( |
338 iFs, KDrmUtilityTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) ); |
411 iFs, KDrmUtilityTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) ); |
339 |
412 |
356 |
429 |
357 #endif |
430 #endif |
358 UpdateBufferL<HBufC, TFileName> (iFileName, triggerFileName->iBuffer); |
431 UpdateBufferL<HBufC, TFileName> (iFileName, triggerFileName->iBuffer); |
359 CleanupStack::PopAndDestroy( triggerFileName ); |
432 CleanupStack::PopAndDestroy( triggerFileName ); |
360 triggerFileName=NULL; |
433 triggerFileName=NULL; |
361 |
|
362 // create and start download |
434 // create and start download |
363 RHttpDownload& download = iDlMgr.CreateDownloadL(*iTriggerUrl, result); |
435 downloadUrl = ((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); |
364 // Put download for proper cleanup. |
436 |
365 TCleanupItem item(DeleteHttpDowload, &download); |
437 iDownload = iDlMgr->createDownload(downloadUrl); |
366 CleanupStack::PushL(item); |
438 try |
367 |
439 { |
368 CleanupClosePushL(roapTrigger); |
440 iDrmUtilityDmgrEventHandler = q_check_ptr(new QDrmUtilityDmgrEventHandler(*this, *iDownload)); |
369 |
441 } |
370 if (result) |
442 catch(const std::exception& exception) |
371 { |
443 { |
372 iDownloadSuccess = EFalse; |
444 qt_symbian_exception2LeaveL(exception); |
373 iConnectionError = EFalse; |
445 } |
374 |
446 |
375 User::LeaveIfError(download.SetFileHandleAttribute(roapTrigger)); |
447 iDownloadSuccess = EFalse; |
376 User::LeaveIfError(download.SetBoolAttribute( |
448 iConnectionError = EFalse; |
377 EDlAttrNoContentTypeCheck, ETrue)); |
449 |
378 User::LeaveIfError(download.Start()); |
450 try |
379 |
451 { |
380 // wait until download is finished |
452 RBuf fileName; |
381 iState = aNextState; |
453 fileName.Create(KMaxFileName); |
382 TRequestStatus* status(&iStatus); |
454 CleanupClosePushL(fileName); |
383 *status = KRequestPending; |
455 roapTrigger.Name(fileName); |
384 SetActive(); |
456 const QVariant& roapTriggerValue( QString((QChar*) fileName.Ptr(), fileName.Length()) ); |
385 } |
457 CleanupStack::PopAndDestroy(&fileName); |
|
458 iDownload->setAttribute(FileName,roapTriggerValue); |
|
459 const QVariant& val(ETrue); |
|
460 iDownload->setAttribute(ContentType, val); |
|
461 iDownload->start(); |
|
462 } |
|
463 catch(const std::exception& exception) |
|
464 { |
|
465 qt_symbian_exception2LeaveL(exception); |
|
466 } |
|
467 // wait until download is finished |
|
468 iState = aNextState; |
|
469 TRequestStatus* status(&iStatus); |
|
470 *status = KRequestPending; |
|
471 SetActive(); |
|
472 |
386 CleanupStack::PopAndDestroy(&roapTrigger); |
473 CleanupStack::PopAndDestroy(&roapTrigger); |
387 CleanupStack::Pop(&download); // Left open for DoSaveRoapTrigger |
|
388 } |
474 } |
389 // --------------------------------------------------------------------------- |
475 // --------------------------------------------------------------------------- |
390 // CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL |
476 // CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL |
391 // --------------------------------------------------------------------------- |
477 // --------------------------------------------------------------------------- |
392 // |
478 // |
393 void CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL(TDownloadState aNextState) |
479 void CDrmUtilityDmgrWrapper::DoSaveRoapTriggerL(TDownloadState aNextState) |
394 { |
480 { |
395 // Check success of download |
481 // Check success of download |
396 |
482 |
397 // Fetch download created in DoDownloadRoapTriggerL |
483 // Fetch download created in DoDownloadRoapTriggerL |
398 RHttpDownload* download = iDlMgr.FindDownload(*iTriggerUrl, KNullDesC8()); |
484 QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); |
|
485 |
|
486 typedef void (Download::*download_cancel_fnptr) (); |
|
487 //uncomment |
|
488 Download* dwnld = NULL;//iDlMgr->findDownload( downloadUrl ); |
|
489 mem_auto_ptr<Download*, download_cancel_fnptr> downloadPtr(dwnld,&WRT::Download::cancel); |
|
490 |
399 // Delete trigger URL so that it is possible to check |
491 // Delete trigger URL so that it is possible to check |
400 // whether or not meteringResponse has PrUrl. |
492 // whether or not meteringResponse has PrUrl. |
401 delete iTriggerUrl; |
493 delete iTriggerUrl; |
402 iTriggerUrl = NULL; |
494 iTriggerUrl = NULL; |
403 iStatus = KRequestPending; |
495 iStatus = KRequestPending; |
404 // Put download for proper cleanup. |
496 |
405 TCleanupItem item(DeleteHttpDowload, download); |
|
406 CleanupStack::PushL(item); |
|
407 RFile roapTrigger; |
497 RFile roapTrigger; |
408 |
498 |
409 if (!iDownloadSuccess) |
499 if (!iDownloadSuccess) |
410 { |
500 { |
411 RemoveProgressNoteL(); |
501 RemoveProgressNoteL(); |
504 // From class MHttpDownloadMgrObserver |
593 // From class MHttpDownloadMgrObserver |
505 // |
594 // |
506 // CDrmUtilityDmgrWrapper::HandleDMgrEventL |
595 // CDrmUtilityDmgrWrapper::HandleDMgrEventL |
507 // --------------------------------------------------------------------------- |
596 // --------------------------------------------------------------------------- |
508 // |
597 // |
509 void CDrmUtilityDmgrWrapper::HandleDMgrEventL(RHttpDownload& aDownload, |
598 void CDrmUtilityDmgrWrapper::HandleDownloadEventL( WRT::DownloadEvent* aEvent ) |
510 THttpDownloadEvent aEvent) |
599 { |
511 { |
600 QString KDrmUtilityMimeTypeROAPTrigger("application/vnd.oma.drm.roap-trigger+xml"); |
512 _LIT8( KDrmUtilityMimeTypeROAPTrigger, |
601 |
513 "application/vnd.oma.drm.roap-trigger+xml" ); |
602 try |
514 |
603 { |
515 |
604 if (aEvent->type() == DownloadEvent::HeadersReceived) |
516 |
|
517 if (aEvent.iProgressState == EHttpContentTypeReceived) |
|
518 { |
605 { |
519 // check received mimetype |
606 // check received mimetype |
520 RBuf8 contentType; |
607 QString contentType = iDownload->attribute(ContentType).toString(); |
521 contentType.CleanupClosePushL(); |
608 if (!contentType.contains(KDrmUtilityMimeTypeROAPTrigger)) |
522 contentType.CreateL(KMaxContentTypeLength); |
|
523 User::LeaveIfError(aDownload.GetStringAttribute(EDlAttrContentType, |
|
524 contentType)); |
|
525 if (!contentType.FindF(KDrmUtilityMimeTypeROAPTrigger)) |
|
526 { |
609 { |
527 // ROAP trigger found, continue download |
610 // ROAP trigger found, continue download |
528 User::LeaveIfError(aDownload.Start()); |
611 iDownload->start(); |
529 } |
612 } |
530 else |
613 else |
531 { |
614 { |
532 // wrong MIME type, so stop download |
615 // wrong MIME type, so stop download |
533 iDownloadSuccess = EFalse; |
616 iDownloadSuccess = EFalse; |
534 User::LeaveIfError(aDownload.Delete()); |
617 iDownload->cancel(); |
535 } |
618 } |
536 CleanupStack::PopAndDestroy(&contentType); |
619 } |
537 } |
620 } |
538 |
621 catch(const std::exception& exception) |
539 if (aEvent.iDownloadState == EHttpDlCreated) |
622 { |
540 { |
623 qt_symbian_exception2LeaveL(exception); |
541 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlCreated" ); |
624 } |
|
625 |
|
626 if (aEvent->type() == DownloadEvent::Created) |
|
627 { |
|
628 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Created" ); |
542 if (iUseCoeEnv && iProgressInfo) |
629 if (iUseCoeEnv && iProgressInfo) |
543 { |
630 { |
544 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementMedium); |
631 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementMedium); |
545 } |
632 } |
546 } |
633 } |
547 else if (aEvent.iProgressState == EHttpProgDisconnected) |
634 else if (aEvent->type() == DownloadEvent::NetworkLoss) |
548 { |
635 { |
549 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpProgDisconnected" ); |
636 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: NetworkLoss" ); |
550 |
637 |
551 // store failure |
638 // store failure |
552 iDownloadSuccess = EFalse; |
639 iDownloadSuccess = EFalse; |
553 iConnectionError = ETrue; |
640 iConnectionError = ETrue; |
554 // finished |
641 // finished |
555 } |
642 } |
556 else if (aEvent.iDownloadState == EHttpDlInprogress) |
643 else if (aEvent->type() == DownloadEvent::InProgress) |
557 { |
644 { |
558 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlInprogress" ); |
645 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: InProgress" ); |
559 if (iUseCoeEnv) |
646 if (iUseCoeEnv) |
560 { |
647 { |
561 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementSmall); |
648 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementSmall); |
562 } |
649 } |
563 } |
650 } |
564 else if (aEvent.iDownloadState == EHttpDlCompleted) |
651 else if (aEvent->type() == DownloadEvent::Completed) |
565 { |
652 { |
566 // store success |
653 // store success |
567 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlCompleted" ); |
654 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Completed" ); |
568 iDownloadSuccess = ETrue; |
655 iDownloadSuccess = ETrue; |
569 iConnectionError = EFalse; |
656 iConnectionError = EFalse; |
570 if (iUseCoeEnv) |
657 if (iUseCoeEnv) |
571 { |
658 { |
572 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementLarge); |
659 iProgressInfo->IncrementAndDraw(KProgressInfoIncrementLarge); |
573 } |
660 } |
574 // finished |
661 // finished |
575 TRequestStatus* status(&iStatus); |
662 TRequestStatus* status(&iStatus); |
576 User::RequestComplete(status, KErrNone); |
663 User::RequestComplete(status, KErrNone); |
577 } |
664 } |
578 else if (aEvent.iDownloadState == EHttpDlFailed) |
665 else if (aEvent->type() == DownloadEvent::Failed) |
579 { |
666 { |
580 TInt32 err(KErrNone); |
667 try |
581 |
668 { |
582 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EHttpDlFailed" ); |
669 TInt32 err(KErrNone); |
583 // store failure |
670 |
584 iDownloadSuccess = EFalse; |
671 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: Failed" ); |
585 User::LeaveIfError(aDownload.GetIntAttribute(EDlAttrErrorId, err)); |
672 // store failure |
586 CLOG_WRITE_FORMAT( "EDlAttrErrorId = %d", err ); |
673 iDownloadSuccess = EFalse; |
587 |
674 err = (iDownload->attribute(LastError)).toInt(); |
588 if (err == EConnectionFailed || err == ETransactionFailed) |
675 CLOG_WRITE_FORMAT( "EDlAttrErrorId = %d", err ); |
589 { |
676 |
590 CLOG_WRITE( "DMgrWrapper::HandleDMgrEventL: EConnectionFailed" ); |
677 if (err == ConnectionFailed || err == TransactionFailed) |
591 iConnectionError = ETrue; |
678 { |
592 } |
679 CLOG_WRITE( "DMgrWrapper::ProcessDownloadEventL: ConnectionFailed" ); |
593 User::LeaveIfError(aDownload.Delete()); // remove useless download |
680 iConnectionError = ETrue; |
594 User::LeaveIfError(iDlMgr.Disconnect()); // disconnects Dmgr instantly. |
681 } |
595 // finished |
682 iDownload->cancel(); // remove useless download |
596 TRequestStatus* status(&iStatus); |
683 iDlMgr->pauseAll(); // disconnects Dmgr instantly. |
597 if ( iConnection->HasMoreConnectionAttempts() ) |
684 // finished |
598 { |
685 TRequestStatus* status(&iStatus); |
599 iState = EInit; // re-try with another conection |
686 if ( iConnection->HasMoreConnectionAttempts() ) |
600 User::RequestComplete(status, KErrNone); |
687 { |
601 } |
688 iState = EInit; // re-try with another conection |
602 else |
689 User::RequestComplete(status, KErrNone); |
603 { |
690 } |
604 User::RequestComplete(status, KErrCancel); |
691 else |
605 } |
692 { |
|
693 User::RequestComplete(status, KErrCancel); |
|
694 } |
|
695 } |
|
696 catch(const std::exception& exception) |
|
697 { |
|
698 qt_symbian_exception2LeaveL(exception); |
|
699 } |
606 } |
700 } |
607 } |
701 } |
608 |
702 |
609 // --------------------------------------------------------------------------- |
703 // --------------------------------------------------------------------------- |
610 // CDrmUtilityDmgrWrapper::ShowProgressNoteL |
704 // CDrmUtilityDmgrWrapper::ShowProgressNoteL |