49 // ================= MEMBER FUNCTIONS ======================= |
49 // ================= MEMBER FUNCTIONS ======================= |
50 |
50 |
51 // ---------------------------------------------------------------------------- |
51 // ---------------------------------------------------------------------------- |
52 // CWmDrmDlaDefaultHttpManager::NewL |
52 // CWmDrmDlaDefaultHttpManager::NewL |
53 // ---------------------------------------------------------------------------- |
53 // ---------------------------------------------------------------------------- |
54 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
54 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
55 MWmDrmDlaDefaltHttpManagerObserver& aObserver ) |
55 MWmDrmDlaDefaltHttpManagerObserver& aObserver ) |
56 { |
56 { |
57 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(1)" ); |
57 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(1)" ); |
58 CWmDrmDlaDefaultHttpManager* self = |
58 CWmDrmDlaDefaultHttpManager* self = |
59 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, 0 ); |
59 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, 0 ); |
60 CleanupStack::PushL( self ); |
60 CleanupStack::PushL( self ); |
61 self->ConstructL(); |
61 self->ConstructL(); |
62 CleanupStack::Pop( self ); |
62 CleanupStack::Pop( self ); |
63 return self; |
63 return self; |
64 } |
64 } |
65 |
65 |
66 // ---------------------------------------------------------------------------- |
66 // ---------------------------------------------------------------------------- |
67 // CWmDrmDlaDefaultHttpManager::NewL |
67 // CWmDrmDlaDefaultHttpManager::NewL |
68 // ---------------------------------------------------------------------------- |
68 // ---------------------------------------------------------------------------- |
69 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
69 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
70 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
70 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
71 TUint32 aIapNumber ) |
71 TUint32 aIapNumber ) |
72 { |
72 { |
73 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(2)" ); |
73 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(2)" ); |
74 CWmDrmDlaDefaultHttpManager* self = |
74 CWmDrmDlaDefaultHttpManager* self = |
75 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, aIapNumber ); |
75 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, aIapNumber ); |
76 CleanupStack::PushL( self ); |
76 CleanupStack::PushL( self ); |
77 self->ConstructL(); |
77 self->ConstructL(); |
78 CleanupStack::Pop( self ); |
78 CleanupStack::Pop( self ); |
79 return self; |
79 return self; |
242 // ============================== PRIVATE METHODS ============================== |
242 // ============================== PRIVATE METHODS ============================== |
243 |
243 |
244 // ---------------------------------------------------------------------------- |
244 // ---------------------------------------------------------------------------- |
245 // CWmDrmDlaDefaultHttpManager::MHFRunL |
245 // CWmDrmDlaDefaultHttpManager::MHFRunL |
246 // ---------------------------------------------------------------------------- |
246 // ---------------------------------------------------------------------------- |
247 void CWmDrmDlaDefaultHttpManager::MHFRunL( |
247 void CWmDrmDlaDefaultHttpManager::MHFRunL( |
248 RHTTPTransaction aTransaction, |
248 RHTTPTransaction aTransaction, |
249 const THTTPEvent& aEvent ) |
249 const THTTPEvent& aEvent ) |
250 { |
250 { |
251 LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunL" ); |
251 LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunL" ); |
252 RHTTPResponse response; |
252 RHTTPResponse response; |
253 TPtrC8 dataChunk; |
253 TPtrC8 dataChunk; |
254 |
254 |
255 // Either ESucceeded or EFailed will eventually occur |
255 // Either ESucceeded or EFailed will eventually occur |
256 switch ( aEvent.iStatus ) |
256 switch ( aEvent.iStatus ) |
257 { |
257 { |
258 case THTTPEvent::EGotResponseHeaders: |
258 case THTTPEvent::EGotResponseHeaders: |
259 response = aTransaction.Response(); |
259 response = aTransaction.Response(); |
260 |
260 |
261 iInCallback = ETrue; |
261 iInCallback = ETrue; |
262 iObserver.OnResponseHeadersL( |
262 iObserver.OnResponseHeadersL( |
263 response, |
263 response, |
264 response.GetHeaderCollection(), |
264 response.GetHeaderCollection(), |
265 iHttpSession.StringPool(), |
265 iHttpSession.StringPool(), |
266 response.StatusCode() ); |
266 response.StatusCode() ); |
267 |
267 |
268 break; |
268 break; |
269 |
269 |
270 case THTTPEvent::EGotResponseBodyData: |
270 case THTTPEvent::EGotResponseBodyData: |
271 // A member variable is used to store the body to avoid two |
271 // A member variable is used to store the body to avoid two |
272 // potential problems: |
272 // potential problems: |
273 // - OnResponseBodyDataL leaves |
273 // - OnResponseBodyDataL leaves |
274 // - Stop is called from within OnResponseBodyDataL |
274 // - Stop is called from within OnResponseBodyDataL |
275 iBody = aTransaction.Response().Body(); |
275 iBody = aTransaction.Response().Body(); |
276 User::LeaveIfNull( iBody ); |
276 User::LeaveIfNull( iBody ); |
277 |
277 |
278 iBody->GetNextDataPart( dataChunk ); |
278 iBody->GetNextDataPart( dataChunk ); |
279 |
279 |
280 iInCallback = ETrue; |
280 iInCallback = ETrue; |
281 iObserver.OnResponseBodyDataL( dataChunk ); |
281 iObserver.OnResponseBodyDataL( dataChunk ); |
282 |
282 |
283 // Verify that iBody wasn't already released |
283 // Verify that iBody wasn't already released |
284 // for example by calling Stop within ResponseBodyDataL |
284 // for example by calling Stop within ResponseBodyDataL |
285 if ( iBody ) |
285 if ( iBody ) |
286 { |
286 { |
287 iBody->ReleaseData(); |
287 iBody->ReleaseData(); |
288 iBody = NULL; |
288 iBody = NULL; |
289 } |
289 } |
290 |
290 |
291 break; |
291 break; |
292 |
292 |
293 case THTTPEvent::ESucceeded: |
293 case THTTPEvent::ESucceeded: |
294 case THTTPEvent::EFailed: |
294 case THTTPEvent::EFailed: |
295 // Deal with both the same as iError will either be negative or |
295 // Deal with both the same as iError will either be negative or |
296 // KErrNone |
296 // KErrNone |
297 // If the user cancelled the credentials dialog then make sure we |
297 // If the user cancelled the credentials dialog then make sure we |
298 // return KErrCancel |
298 // return KErrCancel |
299 HandleDownloadComplete( iCredentialsOk ? iError : KErrCancel ); |
299 HandleDownloadComplete( iCredentialsOk ? iError : KErrCancel ); |
300 break; |
300 break; |
301 |
301 |
302 default: |
302 default: |
303 // This will capture system and HTTP lib errors |
303 // This will capture system and HTTP lib errors |
304 // For positive codes iError will remain to KErrNone |
304 // For positive codes iError will remain to KErrNone |
305 if ( aEvent.iStatus < KErrNone ) |
305 if ( aEvent.iStatus < KErrNone ) |
306 { |
306 { |
470 iState = EInitialize; |
487 iState = EInitialize; |
471 } |
488 } |
472 |
489 |
473 // ---------------------------------------------------------------------------- |
490 // ---------------------------------------------------------------------------- |
474 // CWmDrmDlaDefaultHttpManager::OpenL |
491 // CWmDrmDlaDefaultHttpManager::OpenL |
475 // Handler for the EInitialize state. |
492 // Handler for the EInitialize state. |
476 // ---------------------------------------------------------------------------- |
493 // ---------------------------------------------------------------------------- |
477 void CWmDrmDlaDefaultHttpManager::Open() |
494 void CWmDrmDlaDefaultHttpManager::OpenL() |
478 { |
495 { |
479 LOGFN( "CWmDrmDlaDefaultHttpManager::Open" ); |
496 LOGFN( "CWmDrmDlaDefaultHttpManager::OpenL" ); |
480 // Override dialog preferences |
497 // Override dialog preferences |
481 // Use if IAP is provided, override the default one |
498 // Use if IAP is provided, override the default one |
482 if ( iIapNumber ) |
499 if ( iIapNumber ) |
483 { |
500 { |
484 iCommDbPrefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
501 iExtPrefs.SetNoteBehaviour( |
485 iCommDbPrefs.SetIapId( iIapNumber ); |
502 TExtendedConnPref::ENoteBehaviourConnSilent ); |
486 } |
503 iExtPrefs.SetIapId( iIapNumber ); |
487 |
504 } |
488 // Start RConnection using specified CommDb preferences overrides |
505 else |
489 // This is async call, thus - signal CWmDrmDlaDefaultHttpManager is active |
506 { |
490 // (SetActive()) |
507 iExtPrefs.SetSnapPurpose( CMManager::ESnapPurposeInternet ); |
491 iCommDbPrefs.SetDirection( ECommDbConnectionDirectionOutgoing ); |
508 iExtPrefs.SetNoteBehaviour( |
492 iConnection.Start( iCommDbPrefs, iStatus ); |
509 TExtendedConnPref::ENoteBehaviourDefault ); |
|
510 } |
|
511 iPrefList.AppendL( &iExtPrefs ); |
|
512 |
|
513 iConnection.Start( iPrefList, iStatus ); |
493 |
514 |
494 SetActive(); |
515 SetActive(); |
|
516 LOG1( "CWmDrmDlaDefaultHttpManager::OpenL - Socket connection started" ); |
|
517 |
495 iState = EOpen; |
518 iState = EOpen; |
496 } |
519 } |
497 |
520 |
498 // ---------------------------------------------------------------------------- |
521 // ---------------------------------------------------------------------------- |
|
522 // CHttpManager::ReconnectL |
|
523 // Handler for the EOpenFailed state. |
|
524 // ---------------------------------------------------------------------------- |
|
525 void CWmDrmDlaDefaultHttpManager::ReconnectL() |
|
526 { |
|
527 LOGFN( "CWmDrmDlaDefaultHttpManager::ReconnectL" ); |
|
528 |
|
529 // Clear values set by OpenL |
|
530 for ( TInt i( 0 ); i<iPrefList.Count(); ++i ) |
|
531 { |
|
532 iPrefList.Remove(i); |
|
533 } |
|
534 |
|
535 // Set as dialog based connection opening Any connection will do. |
|
536 iExtPrefs.SetIapId( 0 ); |
|
537 iExtPrefs.SetSnapId( 0 ); |
|
538 iExtPrefs.SetSnapPurpose( CMManager::ESnapPurposeUnknown ); |
|
539 iExtPrefs.SetConnSelectionDialog( ETrue ); |
|
540 iExtPrefs.SetNoteBehaviour( |
|
541 TExtendedConnPref::ENoteBehaviourDefault ); |
|
542 iExtPrefs.SetForcedRoaming( EFalse ); |
|
543 iExtPrefs.SetBearerSet( TExtendedConnPref::EExtendedConnBearerUnknown ); |
|
544 |
|
545 |
|
546 iPrefList.AppendL( &iExtPrefs ); |
|
547 iConnection.Start( iPrefList, iStatus ); |
|
548 |
|
549 SetActive(); |
|
550 LOG1( "CHttpManager::ReconnectL - Socket connection started" ); |
|
551 |
|
552 iState = EReconnect; |
|
553 |
|
554 } |
|
555 |
|
556 // ---------------------------------------------------------------------------- |
499 // CWmDrmDlaDefaultHttpManager::SubmitL |
557 // CWmDrmDlaDefaultHttpManager::SubmitL |
500 // Handler for the EOpen state. |
558 // Handler for the states EOpen and EReconnect. |
501 // ---------------------------------------------------------------------------- |
559 // ---------------------------------------------------------------------------- |
502 void CWmDrmDlaDefaultHttpManager::SubmitL() |
560 void CWmDrmDlaDefaultHttpManager::SubmitL() |
503 { |
561 { |
504 LOGFN( "CWmDrmDlaDefaultHttpManager::SubmitL" ); |
562 LOGFN( "CWmDrmDlaDefaultHttpManager::SubmitL" ); |
505 |
563 |
506 TConnectionInfo info; |
564 TConnectionInfo info; |
507 GetConnectionInfoL( info ); |
565 GetConnectionInfoL( info ); |
508 iIapNumber = info.iIapId; |
566 iIapNumber = info.iIapId; |
509 |
567 |
510 // Open session |
568 // Open session |
511 iHttpSession.OpenL(); |
569 iHttpSession.OpenL(); |
512 RStringPool pool = iHttpSession.StringPool(); |
570 RStringPool pool = iHttpSession.StringPool(); |
513 |
571 |
514 // Associate HTTP session with connection |
572 // Associate HTTP session with connection |
515 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
573 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
516 |
574 |
517 // Specify socket server |
575 // Specify socket server |
518 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketServ, |
576 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketServ, |
519 iSocketServer.Handle() ); |
577 iSocketServer.Handle() ); |
520 // Specify connectionn to use |
578 // Specify connectionn to use |
521 TInt connPtr = reinterpret_cast<TInt>(&iConnection); |
579 TInt connPtr = reinterpret_cast<TInt>(&iConnection); |
522 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketConnection, connPtr ); |
580 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketConnection, connPtr ); |
523 |
581 |
524 // Install HTTP authentication filter |
582 // Install HTTP authentication filter |
525 InstallAuthenticationL( iHttpSession ); |
583 InstallAuthenticationL( iHttpSession ); |
526 |
584 |
527 CHttpCookieFilter::InstallFilterL( iHttpSession ); |
585 CHttpCookieFilter::InstallFilterL( iHttpSession ); |
528 |
586 |
529 RHTTPFilterCollection filterColl = iHttpSession.FilterCollection(); |
587 RHTTPFilterCollection filterColl = iHttpSession.FilterCollection(); |
530 filterColl.RemoveFilter( |
588 filterColl.RemoveFilter( |
531 iHttpSession.StringPool().StringF( |
589 iHttpSession.StringPool().StringF( |
532 HTTP::ERedirect, RHTTPSession::GetTable() ) ); |
590 HTTP::ERedirect, RHTTPSession::GetTable() ) ); |
533 |
591 |
534 CHttpUAProfFilterInterface::InstallFilterL( iHttpSession ); |
592 CHttpUAProfFilterInterface::InstallFilterL( iHttpSession ); |
535 |
593 |
536 // Parse URI |
594 // Parse URI |
537 TUriParser8 srcAddress; |
595 TUriParser8 srcAddress; |
538 User::LeaveIfError( srcAddress.Parse( *iSrcAddress ) ); |
596 User::LeaveIfError( srcAddress.Parse( *iSrcAddress ) ); |
539 |
597 |
540 // Open HTTP transaction |
598 // Open HTTP transaction |
541 iHttpTransaction = iHttpSession.OpenTransactionL( srcAddress, *this, |
599 iHttpTransaction = iHttpSession.OpenTransactionL( srcAddress, *this, |
542 HTTP_STRING( (EGet == iOperation) ? HTTP::EGET : HTTP::EPOST ) ); |
600 HTTP_STRING( (EGet == iOperation) ? HTTP::EGET : HTTP::EPOST ) ); |
543 iTransactionOpen = ETrue; |
601 iTransactionOpen = ETrue; |
544 |
602 |
545 // Set the data supplier if a POST operation |
603 // Set the data supplier if a POST operation |
546 if ( EPost == iOperation ) |
604 if ( EPost == iOperation ) |
547 { |
605 { |
548 iHttpTransaction.Request().SetBody( *iDataSupplier ); |
606 iHttpTransaction.Request().SetBody( *iDataSupplier ); |
549 } |
607 } |
550 |
608 |
551 |
609 |
552 TInt pos = iSrcAddress->Locate( '?' ); |
610 TInt pos = iSrcAddress->Locate( '?' ); |
553 |
611 |
554 // If no query ('?') pos is rightmost character |
612 // If no query ('?') pos is rightmost character |
555 pos = (pos != KErrNotFound) ? pos : iSrcAddress->Length(); |
613 pos = (pos != KErrNotFound) ? pos : iSrcAddress->Length(); |
556 TPtrC8 ptrUrl = iSrcAddress->Left( pos ); |
614 TPtrC8 ptrUrl = iSrcAddress->Left( pos ); |
557 |
615 |
558 // Only print if there is a ('?') and something to print after it |
616 // Only print if there is a ('?') and something to print after it |
559 if ( pos < iSrcAddress->Length() ) |
617 if ( pos < iSrcAddress->Length() ) |
560 { |
618 { |
561 TPtrC8 ptrQs = iSrcAddress->Mid( pos ); |
619 TPtrC8 ptrQs = iSrcAddress->Mid( pos ); |
562 } |
620 } |