30 #include <driveinfo.h> |
30 #include <driveinfo.h> |
31 #endif |
31 #endif |
32 |
32 |
33 #include <data_caging_path_literals.hrh> |
33 #include <data_caging_path_literals.hrh> |
34 |
34 |
35 #include <DownloadMgrClient.h> |
|
36 |
|
37 #include <es_enum.h> // tconnectioninfo |
35 #include <es_enum.h> // tconnectioninfo |
38 #include <es_sock.h> // rconnection rsocket |
36 #include <es_sock.h> // rconnection rsocket |
39 #include <RoapEng.h> |
37 #include <RoapEng.h> |
40 #include <RoapDef.h> |
38 #include <RoapDef.h> |
41 #include <RoapObserver.h> |
39 #include <RoapObserver.h> |
42 #include "RoapSyncWrapper.h" |
40 #include "RoapSyncWrapper.h" |
43 |
41 |
|
42 // Download manager apis |
|
43 #include <qobject.h> |
|
44 #include <downloadmanager.h> |
|
45 #include <download.h> |
|
46 |
44 #include "rohandlerdmgrwrapper.h" |
47 #include "rohandlerdmgrwrapper.h" |
45 #include "cleanupresetanddestroy.h" |
48 #include "cleanupresetanddestroy.h" |
46 #include "buffercontainers.h" |
49 #include "buffercontainers.h" |
|
50 #include "qrohandlerdmgreventhandler.h" |
47 |
51 |
48 #ifdef _DEBUG |
52 #ifdef _DEBUG |
49 #define DRMDEBUG( a ) RDebug::Print( a ) |
53 #define DRMDEBUG( a ) RDebug::Print( a ) |
50 #define DRMDEBUG2( a, b ) RDebug::Print( a, b ) |
54 #define DRMDEBUG2( a, b ) RDebug::Print( a, b ) |
51 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c ) |
55 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c ) |
306 #endif |
298 #endif |
307 UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName->iBuffer ); |
299 UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName->iBuffer ); |
308 CleanupStack::PopAndDestroy( triggerFileName ); |
300 CleanupStack::PopAndDestroy( triggerFileName ); |
309 triggerFileName=NULL; |
301 triggerFileName=NULL; |
310 |
302 |
311 // create and start download |
303 try |
312 RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result ); |
304 { |
313 // Put download for proper cleanup. |
305 // create and start download |
314 TCleanupItem item( DeleteHttpDowload, &download ); |
306 QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); |
315 CleanupStack::PushL( item ); |
307 iDownload = iDlMgr->createDownload( downloadUrl ); |
316 |
308 iRoHandlerDMgrEventHandler = q_check_ptr(new QRoHandlerDMgrEventHandler(*this, *iDownload)); |
|
309 } |
|
310 catch(const std::exception& exception) |
|
311 { |
|
312 qt_symbian_exception2LeaveL(exception); |
|
313 } |
|
314 |
317 CleanupClosePushL( roapTrigger ); |
315 CleanupClosePushL( roapTrigger ); |
318 |
316 |
319 if ( result ) |
317 |
320 { |
318 DRMDEBUG2( |
321 DRMDEBUG2( |
319 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
322 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
320 &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() ); |
323 &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() ); |
321 iDownloadSuccess = EFalse; |
324 iDownloadSuccess = EFalse; |
322 iConnectionError = EFalse; |
325 iConnectionError = EFalse; |
323 |
326 |
324 SetDefaultAccessPointL(); |
327 SetDefaultAccessPointL(); |
325 |
328 User::LeaveIfError( download.SetFileHandleAttribute( roapTrigger ) ); |
326 try |
329 User::LeaveIfError( download.SetBoolAttribute( |
327 { |
330 EDlAttrNoContentTypeCheck, ETrue ) ); |
328 RBuf fileName; |
331 User::LeaveIfError( download.Start() ); |
329 fileName.Create(KMaxFileName); |
332 |
330 CleanupClosePushL(fileName); |
333 // wait until download is finished |
331 roapTrigger.Name(fileName); |
334 iState = aNextState; |
332 const QVariant& roapTriggerValue( QString((QChar*) fileName.Ptr(), fileName.Length()) ); |
335 TRequestStatus* status( &iStatus ); |
333 CleanupStack::PopAndDestroy(&fileName); |
336 *status = KRequestPending; |
334 iDownload->setAttribute(FileName,roapTriggerValue); |
337 SetActive(); |
335 const QVariant& val(ETrue); |
338 } |
336 iDownload->setAttribute(ContentType, val); |
|
337 iDownload->start(); |
|
338 } |
|
339 catch(const std::exception& exception) |
|
340 { |
|
341 qt_symbian_exception2LeaveL(exception); |
|
342 } |
|
343 |
|
344 // wait until download is finished |
|
345 iState = aNextState; |
|
346 TRequestStatus* status( &iStatus ); |
|
347 *status = KRequestPending; |
|
348 SetActive(); |
|
349 |
339 CleanupStack::PopAndDestroy( &roapTrigger ); |
350 CleanupStack::PopAndDestroy( &roapTrigger ); |
340 CleanupStack::Pop( &download ); // Left open for DoSaveRoapTrigger |
|
341 } |
351 } |
342 // --------------------------------------------------------------------------- |
352 // --------------------------------------------------------------------------- |
343 // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL |
353 // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL |
344 // --------------------------------------------------------------------------- |
354 // --------------------------------------------------------------------------- |
345 // |
355 // |
348 // Check success of download |
358 // Check success of download |
349 DRMDEBUG2( |
359 DRMDEBUG2( |
350 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
360 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
351 &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() ); |
361 &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() ); |
352 |
362 |
353 // Fetch download created in DoDownloadRoapTriggerL |
363 try |
354 RHttpDownload* download = iDlMgr.FindDownload( *iTriggerUrl, KNullDesC8() ); |
364 { |
|
365 // Fetch download created in DoDownloadRoapTriggerL |
|
366 QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); |
|
367 //uncomment |
|
368 iDownload = NULL; //iDlMgr->findDownload( downloadUrl ); |
|
369 } |
|
370 catch(const std::exception& exception) |
|
371 { |
|
372 qt_symbian_exception2LeaveL(exception); |
|
373 } |
|
374 |
355 // Delete trigger URL so that it is possible to check |
375 // Delete trigger URL so that it is possible to check |
356 // whether or not meteringResponse has PrUrl. |
376 // whether or not meteringResponse has PrUrl. |
357 delete iTriggerUrl; |
377 delete iTriggerUrl; |
358 iTriggerUrl = NULL; |
378 iTriggerUrl = NULL; |
359 // Put download for proper cleanup. |
379 |
360 TCleanupItem item( DeleteHttpDowload, download ); |
|
361 CleanupStack::PushL( item ); |
|
362 RFile roapTrigger; |
380 RFile roapTrigger; |
363 |
381 |
364 if ( !iDownloadSuccess ) |
382 if ( !iDownloadSuccess ) |
365 { |
383 { |
366 if ( iConnectionError ) |
384 if ( iConnectionError ) |
476 |
494 |
477 // --------------------------------------------------------------------------- |
495 // --------------------------------------------------------------------------- |
478 // CRoHandlerDMgrWrapper::HandleDMgrEventL |
496 // CRoHandlerDMgrWrapper::HandleDMgrEventL |
479 // --------------------------------------------------------------------------- |
497 // --------------------------------------------------------------------------- |
480 // |
498 // |
481 void CRoHandlerDMgrWrapper::HandleDMgrEventL( RHttpDownload& aDownload, |
499 void CRoHandlerDMgrWrapper::HandleDownloadEventL( WRT::DownloadEvent* aEvent ) |
482 THttpDownloadEvent aEvent ) |
500 { |
483 { |
501 QString KDRMHelperMimeTypeROAPTrigger("application/vnd.oma.drm.roap-trigger+xml" ); |
484 _LIT8( KDRMHelperMimeTypeROAPTrigger, "application/vnd.oma.drm.roap-trigger+xml" ); |
|
485 |
502 |
486 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() ); |
503 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() ); |
487 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
504 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
488 &RoHdlrDMgrWrDebugLiterals::KMiDownLoadState(), aEvent.iDownloadState ); |
505 &RoHdlrDMgrWrDebugLiterals::KMiState(), aEvent->type() ); |
489 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
506 |
490 &RoHdlrDMgrWrDebugLiterals::KMiProgressState(), aEvent.iProgressState ); |
507 if ( aEvent->type() == DownloadEvent::HeadersReceived ) |
491 |
|
492 if ( aEvent.iProgressState == EHttpContentTypeReceived ) |
|
493 { |
508 { |
494 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
509 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
495 &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() ); |
510 &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() ); |
496 // check received mimetype |
511 // check received mimetype |
497 RBuf8 contentType; |
512 QString contentType = iDownload->attribute( ContentType).toString(); |
498 contentType.CleanupClosePushL(); |
513 if ( contentType.contains( KDRMHelperMimeTypeROAPTrigger ) == EFalse ) |
499 contentType.CreateL( KMaxContentTypeLength ); |
|
500 User::LeaveIfError( aDownload.GetStringAttribute( EDlAttrContentType, |
|
501 contentType ) ); |
|
502 if ( !contentType.FindF( KDRMHelperMimeTypeROAPTrigger ) ) |
|
503 { |
514 { |
504 // ROAP trigger found, continue download |
515 // ROAP trigger found, continue download |
505 User::LeaveIfError( aDownload.Start() ); |
516 iDownload->start(); |
506 } |
517 } |
507 else |
518 else |
508 { |
519 { |
509 // wrong MIME type?, stop download |
520 // wrong MIME type?, stop download |
510 iDownloadSuccess = EFalse; |
521 iDownloadSuccess = EFalse; |
511 User::LeaveIfError( aDownload.Delete() ); |
522 iDownload->cancel(); |
512 } |
523 } |
513 CleanupStack::PopAndDestroy( &contentType ); |
524 CleanupStack::PopAndDestroy( &contentType ); |
514 } |
525 } |
515 |
526 |
516 if ( aEvent.iDownloadState == EHttpDlCreated ) |
527 if ( aEvent->type() == DownloadEvent::Created ) |
517 { |
528 { |
518 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
529 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
519 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() ); |
530 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() ); |
520 } |
531 } |
521 else |
532 else |
522 if ( aEvent.iProgressState == EHttpProgDisconnected ) |
533 if ( aEvent->type() == DownloadEvent::NetworkLoss ) |
523 { |
534 { |
524 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
535 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
525 &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() ); |
536 &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() ); |
526 // store failure |
537 // store failure |
527 iDownloadSuccess = EFalse; |
538 iDownloadSuccess = EFalse; |
528 iConnectionError = ETrue; |
539 iConnectionError = ETrue; |
529 // finished |
540 // finished |
530 TRequestStatus* status( &iStatus ); |
541 TRequestStatus* status( &iStatus ); |
531 User::RequestComplete( status, KErrCancel ); |
542 User::RequestComplete( status, KErrCancel ); |
532 } |
543 } |
533 else |
544 else |
534 if ( aEvent.iDownloadState == EHttpDlInprogress ) |
545 if ( aEvent->type() == DownloadEvent::InProgress ) |
535 { |
546 { |
536 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
547 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
537 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() ); |
548 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() ); |
538 } |
549 } |
539 else |
550 else |
540 if ( aEvent.iDownloadState == EHttpDlCompleted ) |
551 if ( aEvent->type() == DownloadEvent::Completed ) |
541 { |
552 { |
542 // store success |
553 // store success |
543 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
554 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
544 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() ); |
555 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() ); |
545 iDownloadSuccess = ETrue; |
556 iDownloadSuccess = ETrue; |
546 |
557 |
547 // finished |
558 // finished |
548 TRequestStatus* status( &iStatus ); |
559 TRequestStatus* status( &iStatus ); |
549 User::RequestComplete( status, KErrNone ); |
560 User::RequestComplete( status, KErrNone ); |
550 } |
561 } |
551 else |
562 else |
552 if ( aEvent.iDownloadState == EHttpDlFailed ) |
563 if ( aEvent->type() == DownloadEvent::Failed ) |
553 { |
564 { |
554 TInt32 err; |
565 TInt32 err; |
555 |
566 |
556 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
567 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
557 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() ); |
568 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() ); |
558 // store failure |
569 // store failure |
559 iDownloadSuccess = EFalse; |
570 iDownloadSuccess = EFalse; |
560 User::LeaveIfError( aDownload.GetIntAttribute( |
571 err = iDownload->attribute(LastError ).toInt(); |
561 EDlAttrErrorId, err ) ); |
572 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err ); |
562 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err ); |
573 |
563 |
574 if ( err == ConnectionFailed || err == TransactionFailed ) |
564 if ( err == EConnectionFailed || err |
575 { |
565 == ETransactionFailed ) |
576 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
566 { |
577 &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() ); |
567 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
578 iConnectionError = ETrue; |
568 &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() ); |
579 } |
569 iConnectionError = ETrue; |
580 |
570 } |
581 // finished |
571 |
582 TRequestStatus* status( &iStatus ); |
572 // finished |
583 User::RequestComplete( status, KErrCancel ); |
573 TRequestStatus* status( &iStatus ); |
584 } |
574 User::RequestComplete( status, KErrCancel ); |
|
575 } |
|
576 } |
585 } |
577 |
586 |
578 |
587 |
579 // RoapObserver methods |
588 // RoapObserver methods |
580 |
589 |