internetradio2.0/irdataprovider/src/irhttpdataprovider.cpp
changeset 14 896e9dbc5f19
child 16 5723da102db1
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <httpstringconstants.h>
       
    20 #include <rhttpheaders.h>
       
    21 #include <mmfcontrollerpluginresolver.h> //to get the supported MIME types
       
    22 #ifdef ENABLE_USAGE_REPORT_TEST
       
    23 #include <bautils.h>
       
    24 #include "irreportsettings.h"
       
    25 #endif
       
    26 
       
    27 #include "irdataprovider.h"
       
    28 #include "irdebug.h"
       
    29 #include "irhttpdataprovider.h"
       
    30 #include "irhttppost.h"
       
    31 #include "irhttprequestdata.h"
       
    32 #include "irnetworkcontroller.h"
       
    33 #include "irdatatransferobserver.h"
       
    34 #include "irlogodownloadengine.h"
       
    35 #include "irfavoritesdb.h"
       
    36 #include "irsettings.h"
       
    37 
       
    38 //Added for ALR/SNAP
       
    39 const TInt KBufflengthMaxLength = 255;
       
    40 const TInt KWapProfileMaxLength = 20;
       
    41 const TInt KNokiaIrAppAcceptMaxLength = 25;
       
    42 const TInt KSize = 1024;
       
    43 const TInt KMaxSize = 2048;
       
    44 const TInt KBufSize = 10;
       
    45 const TUid KUidHelixController        = { 0x101F8514 }; // Helix Video controller UID
       
    46 const TInt KLogbufferLenth = KLogBufferSize/2 - 1;
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CIRHttpDataProvider::CIRHttpDataProvider(MIRHttpDataProviderObserver&
       
    50 // aObserver):iObserver(aObserver),iRunning(EFalse)
       
    51 // Creates instance of CIRHttpDataProvider.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CIRHttpDataProvider::CIRHttpDataProvider( MIRHttpDataProviderObserver
       
    55     &aObserver ): iRunning( EFalse ), iObserver( aObserver )
       
    56     {
       
    57     IRLOG_DEBUG( "CIRHttpDataProvider::CIRHttpDataProvider" );
       
    58     // Definition not required
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CIRHttpDataProvider::~CIRHttpDataProvider()
       
    63 // Destructs instance of CIRHttpDataProvider.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CIRHttpDataProvider::~CIRHttpDataProvider()
       
    67     {
       
    68     IRLOG_DEBUG( "CIRHttpDataProvider::~CIRHttpDataProvider - Entering" );
       
    69     // remove E32USER-CBase-66
       
    70 #ifdef _DEBUG
       
    71     TRAP_IGNORE( iHttpSession.Close() );
       
    72 #else
       
    73     iHttpSession.Close();
       
    74 #endif
       
    75     delete iLogMessage;
       
    76     if ( iIRNetworkControllerHandle )
       
    77         {
       
    78         iIRNetworkControllerHandle->Close();
       
    79         }
       
    80     if(iLogoDownloadEngine)
       
    81     	{
       
    82 	    delete iLogoDownloadEngine;
       
    83 	    iLogoDownloadEngine = NULL;
       
    84     	}
       
    85     IRLOG_DEBUG( "CIRHttpDataProvider::~CIRHttpDataProvider - Exiting." );
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CIRHttpDataProvider::NewL()
       
    91 // Creates instance of CIRHttpDataProvider.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CIRHttpDataProvider *CIRHttpDataProvider::NewL( 
       
    95                                       MIRHttpDataProviderObserver &aObserver )
       
    96     {
       
    97     IRLOG_DEBUG( "CIRHttpDataProvider::NewL - Entering" );
       
    98     CIRHttpDataProvider *self = NewLC( aObserver );
       
    99     CleanupStack::Pop(self);
       
   100     IRLOG_DEBUG( "CIRHttpDataProvider::NewL - Exiting" );
       
   101     return self;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CIRHttpDataProvider::NewLC()
       
   106 // Creates instance of CIRHttpDataProvider.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CIRHttpDataProvider *CIRHttpDataProvider::NewLC( 
       
   110                                       MIRHttpDataProviderObserver &aObserver )
       
   111     {
       
   112     IRLOG_DEBUG( "CIRHttpDataProvider::NewLC - Entering" );
       
   113     CIRHttpDataProvider *self = new( ELeave )CIRHttpDataProvider( aObserver );
       
   114     CleanupStack::PushL( self );
       
   115     self->ConstructL();
       
   116     IRLOG_DEBUG( "CIRHttpDataProvider::NewLC - Exiting" );
       
   117     return self;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CIRHttpDataProvider::ConstructL()
       
   122 // 2nd phase construction
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CIRHttpDataProvider::ConstructL()
       
   126     {
       
   127     IRLOG_DEBUG( "CIRHttpDataProvider::ConstructL - Entering" );
       
   128     iFirstTime = ETrue;
       
   129     iIRNetworkControllerHandle = CIRNetworkController::OpenL();
       
   130     iLogMessage = CIRHttpPost::NewL(iHttpTransaction);
       
   131     iLogoDownloadEngine = CIRLogoDownloadEngine::NewL();
       
   132     IRLOG_DEBUG( "CIRHttpDataProvider::ConstructL - Exiting" );
       
   133     }
       
   134 
       
   135 EXPORT_C CIRLogoDownloadEngine* CIRHttpDataProvider::GetLogoDownloadEngine()
       
   136 {
       
   137 IRLOG_DEBUG( "CIRHttpDataProvider::GetLogoDownloadEngine" );
       
   138 	return iLogoDownloadEngine;
       
   139 }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CIRHttpDataProvider::CancelTransactionL()
       
   143 // Cancel the issued Http transaction
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CIRHttpDataProvider::CancelTransaction()
       
   147     {
       
   148     IRLOG_DEBUG( "CIRHttpDataProvider::CancelTransaction  - Entering" );
       
   149     // Make sure that logfile is closed
       
   150     CloseLogFile ();
       
   151     if ( !iRunning )
       
   152         {
       
   153         return ;
       
   154         }
       
   155     // Close() also cancels transaction (Cancel() can also be used but
       
   156     // resources allocated by transaction must be still freed with Close())
       
   157     iHttpTransaction.Close();
       
   158     // Not running anymore
       
   159     iRunning = EFalse;
       
   160     IRLOG_DEBUG( "CIRHttpDataProvider::CancelTransaction - Exiting." );
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CIRHttpDataProvider::CloseLogFile()
       
   165 // Used to Close the log file LogUsage.gz externally from other sources (bug-fixing)
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CIRHttpDataProvider::CloseLogFile ()
       
   169     {
       
   170     IRLOG_DEBUG( "CIRHttpDataProvider::CloseLogFile  - Entering" );
       
   171     if ( iLogMessage )
       
   172         {
       
   173         iLogMessage->CloseLogFile();
       
   174         }
       
   175     IRLOG_DEBUG( "CIRHttpDataProvider::CloseLogFile  - Exiting" );
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CIRHttpDataProvider::IssueHttpRequestL()
       
   180 // Used to issue the request.
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 TInt CIRHttpDataProvider::IssueHttpRequestL( CIRHttpRequestData &aRequestInfo )
       
   184     {
       
   185     IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - Entering" );
       
   186     iNotModified = EFalse;
       
   187     
       
   188     if ( !( iIRNetworkControllerHandle->GetNetworkStatus() ) )
       
   189         {
       
   190         // Error Network connection inactive
       
   191         return KErrCouldNotConnect;
       
   192         }
       
   193     if ( iFirstTime )
       
   194         {
       
   195         InitializeHttpDataProviderL();
       
   196         iIRNetworkControllerHandle->InitializeHttpSessionL( iHttpSession,
       
   197                             MIRDataTransferTracker::EIRTransferCategoryIsds );
       
   198         iFirstTime = EFalse;
       
   199         }
       
   200     // Parse string to URI (as defined in RFC2396)
       
   201     TUriParser8 uri;
       
   202     uri.Parse( aRequestInfo.iUri );
       
   203     // Get request method string
       
   204     RStringF method;
       
   205     switch ( aRequestInfo.iMethod )
       
   206         {
       
   207         case EIRHttpGET:
       
   208             {
       
   209             method = iHttpSession.StringPool().StringF( HTTP::EGET,
       
   210                                                    RHTTPSession::GetTable() );
       
   211             }
       
   212             break;
       
   213         case EIRHttpPOST:
       
   214             {
       
   215             method = iHttpSession.StringPool().StringF( HTTP::EPOST,
       
   216                                                    RHTTPSession::GetTable() );
       
   217             }
       
   218             break;
       
   219         default:
       
   220             {
       
   221             }
       
   222             break;
       
   223         }
       
   224     CleanupClosePushL( method );
       
   225 
       
   226     IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - Opening transaction" );
       
   227     // Open transaction with previous method and parsed uri. This class will
       
   228     // receive transaction events in MHFRunL and MHFRunError.
       
   229     iHttpTransaction = iHttpSession.OpenTransactionL( uri,  *this, method );
       
   230 
       
   231 #ifdef ENABLE_USAGE_REPORT_TEST
       
   232     RFs iFs;
       
   233     User::LeaveIfError(iFs.Connect());
       
   234     
       
   235     TTime timeStamp;
       
   236     //timeStamp.UniversalTime();
       
   237     timeStamp.HomeTime();
       
   238     TDateTime dateTime =  timeStamp.DateTime();
       
   239     
       
   240     _LIT(KFormatTime,"-%d-%d-%d %d.%d.%d.xml.gz\n");
       
   241     TBuf<32>    sendTime;
       
   242     sendTime.Format(KFormatTime,dateTime.Year(),TInt(dateTime.Month()+1),dateTime.Day()+1,
       
   243                                 dateTime.Hour(),dateTime.Minute(),dateTime.Second());
       
   244 
       
   245     _LIT( KDstFilePath, "c:\\data\\IR_Log\\");
       
   246     TFileName dstFileName(KDstFilePath);
       
   247     dstFileName.Append(KGZipLogFileName);
       
   248     dstFileName.Append(sendTime);
       
   249     
       
   250     iFs.MkDirAll(dstFileName);
       
   251     
       
   252     if ( aRequestInfo.iMethod == EIRHttpPOST )
       
   253         {
       
   254         CIRSettings * settings = CIRSettings::OpenL();
       
   255         if ( NULL != settings )
       
   256             {
       
   257             TFileName filePath = settings->PrivatePath();
       
   258             filePath.Append( KGZipLogFileName );                   
       
   259 
       
   260             BaflUtils::CopyFile( iFs, filePath, dstFileName );
       
   261             settings->Close();
       
   262             }
       
   263         }
       
   264 #endif
       
   265     
       
   266     if ( aRequestInfo.iMethod == EIRHttpPOST )
       
   267         {
       
   268         IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - POST method" );
       
   269         // Close the LogFile
       
   270         iLogMessage->CloseLogFile ();
       
   271         iLogMessage->SetTransaction( iHttpTransaction );
       
   272         TInt FileSize(KErrNone);
       
   273         TRAPD(err, iLogMessage->GetFileToPostL(&FileSize));
       
   274         if ( err )
       
   275             {
       
   276             // failed to open the file to be posted hence cancel the request
       
   277             CleanupStack::PopAndDestroy( &method );
       
   278             iHttpTransaction.Close();
       
   279             return KErrCouldNotConnect;
       
   280             }
       
   281         TBuf8<KBufflengthMaxLength> bufflength;
       
   282         _LIT8(KFormat,"%d");
       
   283         bufflength.Format(KFormat,FileSize);
       
   284         aRequestInfo.iContentType.Copy(KPostContentType);
       
   285         RHTTPRequest LogRequest;
       
   286         LogRequest = iHttpTransaction.Request();
       
   287         LogRequest.SetBody((MHTTPDataSupplier&) *iLogMessage);
       
   288         RHTTPHeaders header = iHttpTransaction.Request().GetHeaderCollection();
       
   289         SetHeaderL(header,HTTP::EContentType,aRequestInfo.iContentType );
       
   290         SetHeaderL(header,HTTP::EContentLength,bufflength);
       
   291         }
       
   292     
       
   293      // Setup the headers for the HTTP request
       
   294     BuildHeadersL(aRequestInfo);
       
   295   
       
   296     // Submit the transaction. After this the framework will give transaction
       
   297     // events via MHFRunL and MHFRunError.
       
   298     iHttpTransaction.SubmitL();
       
   299    
       
   300 #ifdef ENABLE_USAGE_REPORT_TEST  
       
   301     if ( aRequestInfo.iMethod == EIRHttpPOST )
       
   302         {
       
   303         _LIT( KSentPrefix, "X__");
       
   304         TFileName sentLogFileName(KDstFilePath);
       
   305         sentLogFileName.Append(KSentPrefix);
       
   306         sentLogFileName.Append(KGZipLogFileName);
       
   307         sentLogFileName.Append(sendTime);
       
   308         BaflUtils::RenameFile(iFs, dstFileName, sentLogFileName);      
       
   309         }
       
   310     iFs.Close();
       
   311 #endif    
       
   312     
       
   313     CleanupStack::PopAndDestroy( &method );
       
   314     iRunning = ETrue;
       
   315     IRLOG_INFO( "CIRHttpDataProvider::IssueHttpRequestL - Submitted HTTP request" );
       
   316     return KErrNone;
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CIRHttpDataProvider::SetHttpContentType()
       
   321 // Set the Http content type
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CIRHttpDataProvider::SetHttpContentType( const TDesC &aContentType,
       
   325                                               const TDesC &aCharSet )
       
   326     {
       
   327     IRLOG_DEBUG( "CIRHttpDataProvider::SetHttpContentType - Entering" );
       
   328     iContentType.Copy( aContentType );
       
   329     iCharSet.Copy( aCharSet );
       
   330     IRLOG_DEBUG( "CIRHttpDataProvider::SetHttpContentType - Exiting." );
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CIRHttpDataProvider::InitializeHttpDataProviderL()
       
   335 // Initialize the data provider component
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CIRHttpDataProvider::InitializeHttpDataProviderL()
       
   339     {
       
   340     IRLOG_DEBUG( "CIRHttpDataProvider::InitializeHttpDataProviderL - Entering" );
       
   341     iHttpSession.Close();
       
   342     TRAPD( LeaveValue, iHttpSession.OpenL() );
       
   343     if ( LeaveValue != KErrNone )
       
   344         {
       
   345         // Most common error; no access point configured, and session creation
       
   346         // leaves with KErrNotFound.
       
   347         // Load a string from the resource file and add the error code to string
       
   348         User::Leave( LeaveValue );
       
   349         }
       
   350     // Set the HTTP connection properties
       
   351     RStringPool strP = iHttpSession.StringPool();
       
   352     RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo();
       
   353     // RSocketServ Handle
       
   354     connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketServ,
       
   355                     RHTTPSession::GetTable() ), THTTPHdrVal(
       
   356                     iIRNetworkControllerHandle->GetIRSocketServer().Handle() ) );
       
   357     // RConnection Handle
       
   358     TInt connPtr = REINTERPRET_CAST( TInt, &( iIRNetworkControllerHandle->GetIRConnection() ) );
       
   359 
       
   360     connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketConnection,
       
   361                     RHTTPSession::GetTable() ), THTTPHdrVal( connPtr ) );
       
   362     // HTTP Version ( Specify that i am using HTTP/1.1
       
   363     connInfo.SetPropertyL( strP.StringF( HTTP::EVersion,
       
   364                     RHTTPSession::GetTable() ), THTTPHdrVal( strP.StringF(
       
   365                     HTTP::EHttp11, RHTTPSession::GetTable() ) ) );
       
   366 
       
   367     RStringF temp = strP.OpenFStringL( KAccept );
       
   368     CleanupClosePushL( temp );
       
   369     connInfo.SetPropertyL( strP.StringF( HTTP::EAccept,
       
   370                     RHTTPSession::GetTable() ), THTTPHdrVal( temp ) );
       
   371 
       
   372     CleanupStack::PopAndDestroy( &temp );
       
   373     iContentType.Copy( KDefaultContentType );
       
   374     iCharSet.Copy( KDefaultCharSet );
       
   375 
       
   376     IRLOG_DEBUG( "CIRHttpDataProvider::InitializeHttpDataProviderL - Exiting." );
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CIRHttpDataProvider::MHFRunL()
       
   381 // Inherited from MHTTPTransactionCallback
       
   382 // Called by framework to pass transaction events.
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 void CIRHttpDataProvider::MHFRunL( RHTTPTransaction aTransaction,
       
   386     const THTTPEvent &aEvent )
       
   387     {
       
   388     IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunL - Entering." );
       
   389     
       
   390     switch ( aEvent.iStatus )
       
   391         {
       
   392         case THTTPEvent::EGotResponseHeaders:
       
   393             {
       
   394             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - EGotResponseHeaders" );
       
   395             // HTTP response headers have been received. Use
       
   396             // aTransaction.Response() to get the response. However, it's not
       
   397             // necessary to do anything with the response when this event occurs.
       
   398             // Get HTTP status code from header (e.g. 200)
       
   399             RHTTPResponse resp = aTransaction.Response();
       
   400             iStatusCode = resp.StatusCode();
       
   401             // Get status text (e.g. "OK")
       
   402             iStatusText.Copy(
       
   403                     (const unsigned short int*)resp.StatusText().DesC().Ptr(),
       
   404                     iStatusText.MaxLength() );
       
   405             // Extract header field names and value
       
   406             ExtractResponseHeadersL( aTransaction );
       
   407             // Validate the status code
       
   408             ValidateStatusCode( iStatusCode );
       
   409             }
       
   410             break;
       
   411         case THTTPEvent::EGotResponseBodyData:
       
   412             {
       
   413             // Part  of response's body data received. Use
       
   414             // aTransaction.Response().Body()->GetNextDataPart() to get the actual
       
   415             // body data.
       
   416             // Get the body data supplier
       
   417             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - EGotResponseBodyData" );
       
   418             MHTTPDataSupplier *body = aTransaction.Response().Body();
       
   419             TPtrC8 dataChunk;
       
   420             body->GetNextDataPart( dataChunk );
       
   421             iObserver.HttpBodyReceived( dataChunk );
       
   422             // To release the body data.
       
   423             body->ReleaseData();
       
   424             }
       
   425             break;
       
   426         case THTTPEvent::ESucceeded:
       
   427             {
       
   428             IRLOG_INFO( "CIRHTTPDATAPROVIDER::MHFRUNL - ESucceeded" );
       
   429             // Transaction can be closed now. It's not needed anymore.
       
   430             aTransaction.Close();
       
   431             iRunning = EFalse;
       
   432             iObserver.HttpEventComplete();
       
   433             }
       
   434             break;
       
   435         case THTTPEvent::EFailed:
       
   436             {
       
   437             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - EFailed" );
       
   438             IRLOG_INFO2( "CIRHttpDataProvider::MHFRunL aEvent.iStatus= %d", aEvent.iStatus );
       
   439             IRLOG_INFO2( "CIRHttpDataProvider::MHFRunL iStatusCode= %d", iStatusCode );
       
   440             // Transaction completed with failure.
       
   441             aTransaction.Close();
       
   442             iRunning = EFalse;
       
   443             iObserver.HttpTransactionError( iStatusCode );
       
   444             }
       
   445             break;
       
   446        case THTTPEvent::ENotifyNewRequestBodyPart:
       
   447             {
       
   448             iLogMessage->ReleaseData();
       
   449             }
       
   450             break;
       
   451         case KServiceUnavailable:
       
   452             {
       
   453             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - KServiceUnavailable" );
       
   454             aTransaction.Close();
       
   455             iRunning = EFalse;
       
   456             iObserver.HttpTransactionError( KServiceUnavailable );
       
   457             }
       
   458             break;
       
   459         case KDndTimedOut:
       
   460             {
       
   461             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - KDndTimedOut" );
       
   462             // Just close the transaction on errors
       
   463             aTransaction.Close();
       
   464             iRunning = EFalse;
       
   465             iObserver.HttpTransactionError( KDndTimedOut );
       
   466             }
       
   467             break;      
       
   468         default:
       
   469             // There are more events in THTTPEvent,
       
   470             // Which is needed can be implemented incase required
       
   471             // by the HTTP Data Provider
       
   472             {
       
   473             IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - default" );
       
   474             if ( aEvent.iStatus < 0 )
       
   475                 {
       
   476                 IRRDEBUG2( "CIRHttpDataProvider::MHFRunL aEvent.iStatus= %d", aEvent.iStatus );
       
   477                 // Just close the transaction on errors
       
   478                 aTransaction.Close();
       
   479                 iRunning = EFalse;
       
   480                 iObserver.HttpTransactionError( aEvent.iStatus );
       
   481                 }
       
   482             // Other events are not errors
       
   483             // (e.g. permanent and temporary redirections)
       
   484             // ignore such errors
       
   485             }
       
   486             break;
       
   487         }
       
   488     IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunL - Exiting." );
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CIRHttpDataProvider::MHFRunError()
       
   493 // Inherited from MHTTPTransactionCallback
       
   494 // Called by framework to pass transaction errors
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 TInt CIRHttpDataProvider::MHFRunError( TInt /* aError*/,
       
   498     RHTTPTransaction /*aTransaction*/, const THTTPEvent & /*aEvent*/ )
       
   499     {
       
   500     IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunError - Entering" );
       
   501     // Handle error and return KErrNone.
       
   502     IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunError - Exiting." );
       
   503     return KErrNone;
       
   504     }
       
   505 
       
   506 // ---------------------------------------------------------------------------
       
   507 // CIRHttpDataProvider::ExtractResponseHeadersL()
       
   508 // Used to Extract the response headers.
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 void CIRHttpDataProvider::ExtractResponseHeadersL(
       
   512                                         const RHTTPTransaction& aTransaction )
       
   513     {
       
   514     IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Entering" );
       
   515     RHTTPResponse response = aTransaction.Response();
       
   516     RHTTPHeaders respHeader = response.GetHeaderCollection();
       
   517     THTTPHdrFieldIter iterator = respHeader.Fields();
       
   518     RStringPool httpStringPool = aTransaction.Session().StringPool();
       
   519     iterator.First();
       
   520     HBufC8 *headerField = HBufC8::NewLC( KMaxHeaderNameLength +
       
   521                                          KMaxHeaderValueLength );
       
   522     HBufC8 *fieldValBuf = HBufC8::NewLC( KMaxHeaderValueLength );
       
   523     while ( iterator.AtEnd() == EFalse )
       
   524         {
       
   525         RStringTokenF fieldName = iterator();
       
   526         RStringF fieldNameStr = httpStringPool.StringF( fieldName );
       
   527         THTTPHdrVal fieldVal;
       
   528         if ( respHeader.GetField( fieldNameStr, 0, fieldVal ) == KErrNone )
       
   529             {
       
   530             const TDesC8 &fieldNameDesC = fieldNameStr.DesC();
       
   531             headerField->Des().Copy(
       
   532                             fieldNameDesC.Left( KMaxHeaderNameLength ) );
       
   533             fieldValBuf->Des().Zero();
       
   534             switch ( fieldVal.Type() )
       
   535                 {
       
   536                 // the value is an integer
       
   537                 //lint restore -e747:Significant prototype
       
   538                 //coercion (arg. no. 1) int to long long  :
       
   539                 case THTTPHdrVal::KTIntVal:
       
   540                     fieldValBuf->Des().Num( fieldVal.Int() );
       
   541                     break;
       
   542                     // the value is a case-insensitive string
       
   543                 case THTTPHdrVal::KStrFVal:
       
   544                     {
       
   545                     RStringF fieldValStr = httpStringPool.StringF(
       
   546                                                             fieldVal.StrF() );
       
   547                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
   548                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
   549                                                     KMaxHeaderValueLength ) );
       
   550                     }
       
   551                     break;
       
   552                     // the value is a case-sensitive string
       
   553                 case THTTPHdrVal::KStrVal:
       
   554                     {
       
   555                     RString fieldValStr = httpStringPool.String(
       
   556                                     fieldVal.Str() );
       
   557                     const TDesC8 &fieldValDesC = fieldValStr.DesC();
       
   558                     fieldValBuf->Des().Copy( fieldValDesC.Left(
       
   559                                     KMaxHeaderValueLength ) );
       
   560                     }
       
   561                     break;
       
   562                     // the value is a date/time
       
   563                 case THTTPHdrVal::KDateVal:
       
   564                     {
       
   565                     TDateTime date = fieldVal.DateTime();
       
   566                     TTime t( date );
       
   567                     if ( !iSetNonUAProfUserAgent )
       
   568                         {
       
   569                         iObserver.HttpDateHeaderReceived( *headerField, t );
       
   570                         }
       
   571                     }
       
   572                     break;
       
   573                     // the value is type is unknown
       
   574                 default:
       
   575                     break;
       
   576                 }
       
   577             // Display HTTP header field name and value
       
   578             headerField->Des().Append( KDPColon );
       
   579             headerField->Des().Append( *fieldValBuf );
       
   580             iObserver.HttpHeaderReceived( *headerField );
       
   581             }
       
   582         ++iterator;
       
   583         }
       
   584     
       
   585     CleanupStack::PopAndDestroy( fieldValBuf );
       
   586     CleanupStack::PopAndDestroy( headerField );
       
   587     IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Exiting." );
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // CIRHttpDataProvider::SetHeaderL()
       
   592 // Used to set the Http header
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 void CIRHttpDataProvider::SetHeaderL( RHTTPHeaders aHeaders,
       
   596                          TInt aHeaderField, const TDesC8 &aHeaderValue ) const
       
   597     {
       
   598     IRLOG_DEBUG( "CIRHttpDataProvider::SetHeaderL - Entering" );
       
   599     RStringF valStr = iHttpSession.StringPool().OpenFStringL( aHeaderValue );
       
   600     CleanupClosePushL( valStr );
       
   601     THTTPHdrVal val( valStr );
       
   602     aHeaders.SetFieldL( iHttpSession.StringPool().StringF( aHeaderField,
       
   603                                             RHTTPSession::GetTable() ), val );
       
   604     CleanupStack::PopAndDestroy( &valStr );
       
   605     IRLOG_DEBUG( "CIRHttpDataProvider::SetHeaderL - Exiting." );
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // CIRHttpDataProvider::BuildHeadersL()
       
   610 //  Build the headers for the request
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 void CIRHttpDataProvider::BuildHeadersL(const CIRHttpRequestData &aRequestInfo)
       
   614     {
       
   615     IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - Entering" );
       
   616     RBuf logstr;
       
   617     logstr.CreateL(KMaxSize);
       
   618     logstr.CleanupClosePushL();
       
   619      // Set headers for request; user agent and accepted content type
       
   620     RHTTPHeaders header = iHttpTransaction.Request().GetHeaderCollection();
       
   621 
       
   622     SetHeaderL( header, HTTP::EAccept, KAccept );
       
   623      logstr.Copy(KAccept);
       
   624     IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAccept = %S", &logstr );
       
   625 
       
   626     // Set the User-Agent header to UAProf string
       
   627     SetHeaderL( header, HTTP::EUserAgent,
       
   628                 iIRNetworkControllerHandle->GetUAProfString()->Des() );
       
   629        logstr.Copy(iIRNetworkControllerHandle->GetUAProfString()->Des());
       
   630     IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - HTTP::EUserAgent =");		   
       
   631     TInt logstrLenth = logstr.Length();
       
   632     TBuf<KLogbufferLenth> tempStr;
       
   633     TInt index = 0;
       
   634     while( logstrLenth > 0 )
       
   635       {
       
   636       if( logstrLenth > KLogbufferLenth )
       
   637           {
       
   638           tempStr.Copy( &logstr[index], KLogbufferLenth );
       
   639           }
       
   640       else
       
   641           {
       
   642           tempStr.Copy( &logstr[index], logstrLenth );
       
   643           }
       
   644       IRLOG_DEBUG2( "%S", &tempStr ); 
       
   645       index += KLogbufferLenth;
       
   646       logstrLenth -= KLogbufferLenth;
       
   647       }  
       
   648     // Set the Accept Character set header
       
   649     SetHeaderL( header, HTTP::EAcceptCharset, KAcceptCharset );
       
   650    logstr.Copy(KAcceptCharset);
       
   651     IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptCharset = %S", &logstr );
       
   652 
       
   653     // Set the Accept-Language header as specified in aRequestInfo
       
   654     if ( aRequestInfo.iAcceptLanguage.Length() != 0 )
       
   655         {
       
   656         SetHeaderL( header, HTTP::EAcceptLanguage,
       
   657                         aRequestInfo.iAcceptLanguage );
       
   658         logstr.Copy(aRequestInfo.iAcceptLanguage);
       
   659 	    IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptLanguage = %S", &logstr );
       
   660         }
       
   661     // If not specified then set the default accept language as "en"
       
   662     else
       
   663         {
       
   664         SetHeaderL( header, HTTP::EAcceptLanguage, KAcceptLanguage );
       
   665         logstr.Copy(KAcceptLanguage);
       
   666         IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptLanguage = %S", &logstr );
       
   667         }
       
   668 
       
   669 #ifdef REQUEST_ZIP_RESPONSE
       
   670     // Add Accept-Encoding: gzip HTTP request header. The server will use compression to improve data
       
   671 	// transfer speed.
       
   672     SetHeaderL( header, HTTP::EAcceptEncoding, KAcceptEncoding );
       
   673     logstr.Copy(KAcceptEncoding);
       
   674     IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptEncoding = %S", &logstr );
       
   675 #endif
       
   676 
       
   677     // Set the If-Modified-Since header if required
       
   678     if ( aRequestInfo.isIfModifiedSet )
       
   679         {
       
   680         THTTPHdrVal val( aRequestInfo.iIfModifiedSince );
       
   681         header.SetFieldL( iHttpSession.StringPool().StringF(
       
   682                     HTTP::EIfModifiedSince, RHTTPSession::GetTable() ), val );
       
   683         }
       
   684 
       
   685     // Set the x-wap-profile header
       
   686 
       
   687     TBuf8<KWapProfileMaxLength> xWapProfile;
       
   688     _LIT(KXWapProfile,"x-wap-profile");
       
   689     xWapProfile.Copy( KXWapProfile );
       
   690     RStringF xWapProfileString = iHttpSession.StringPool().OpenFStringL(
       
   691                     xWapProfile );
       
   692     RStringF xWapProfileValueString = iHttpSession.StringPool().OpenFStringL(
       
   693                     iIRNetworkControllerHandle->GetWapProfString()->Des() );
       
   694    logstr.Copy(iIRNetworkControllerHandle->GetWapProfString()->Des());
       
   695    IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - x-wap-profile =");   
       
   696    logstrLenth = logstr.Length();
       
   697    index = 0;
       
   698    while( logstrLenth > 0 )
       
   699       {
       
   700       if( logstrLenth > KLogbufferLenth )
       
   701           {
       
   702           tempStr.Copy( &logstr[index], KLogbufferLenth );
       
   703           }
       
   704       else
       
   705           {
       
   706           tempStr.Copy( &logstr[index], logstrLenth );
       
   707           }
       
   708       IRLOG_DEBUG2( "%S", &tempStr ); 
       
   709       index += KLogbufferLenth;
       
   710       logstrLenth -= KLogbufferLenth;
       
   711       }  
       
   712    
       
   713     THTTPHdrVal xWapProfileHeader( xWapProfileValueString );
       
   714     header.SetFieldL( xWapProfileString, xWapProfileHeader );
       
   715     xWapProfileString.Close();
       
   716     xWapProfileValueString.Close();
       
   717    
       
   718     //this piece of code is to get the MIME types supported by a device
       
   719     TInt i,ii,j;
       
   720     CMMFControllerPluginSelectionParameters *cs = 
       
   721                              CMMFControllerPluginSelectionParameters::NewLC();
       
   722     CMMFFormatSelectionParameters * fs = 
       
   723                                        CMMFFormatSelectionParameters::NewLC();
       
   724     cs->SetRequiredPlayFormatSupportL( *fs );
       
   725     cs->SetRequiredRecordFormatSupportL( *fs );
       
   726 
       
   727     RMMFControllerImplInfoArray controllers;
       
   728     CleanupResetAndDestroyPushL( controllers );
       
   729     cs->ListImplementationsL( controllers );
       
   730 
       
   731     TInt contrCount = controllers.Count();
       
   732     RBuf8 audioMIMEs;
       
   733 	CleanupClosePushL (audioMIMEs);
       
   734     audioMIMEs.CreateL( KSize );
       
   735     RBuf audioBuf;
       
   736 	CleanupClosePushL (audioBuf);
       
   737     audioBuf.CreateL( KBufSize );
       
   738     _LIT(KAudio,"audio");
       
   739     audioBuf.Copy( KAudio );
       
   740     for ( i = 0; i < controllers.Count(); i++ )
       
   741         {
       
   742         if( KUidHelixController == controllers[i]->Uid() )
       
   743             {
       
   744             //supported play formats
       
   745             const RMMFFormatImplInfoArray &pf = controllers[i]->PlayFormats();
       
   746             TInt pfCount = pf.Count();
       
   747             for ( ii = 0; ii < pf.Count(); ii++ )
       
   748                 {
       
   749                 RBuf z;
       
   750                 RBuf z1;
       
   751                 TBool first;
       
   752                 //file extensions
       
   753                 const CDesC8Array &fe = pf[ii]->SupportedFileExtensions();
       
   754                 first = TRUE;
       
   755                 z.CreateL(KSize);
       
   756                 z.CleanupClosePushL();
       
   757                 z1.CreateL(KSize);
       
   758                 z1.CleanupClosePushL();
       
   759                 z1.Zero();
       
   760                 for ( j = 0; j < fe.Count(); j++ )
       
   761                     {
       
   762                     _LIT(KNone,", ");
       
   763                     if ( !first )
       
   764                         z1.Append( KNone );
       
   765                     first = FALSE;
       
   766                     z.Copy( fe[j] );
       
   767                     z1.Append( z );
       
   768                     };
       
   769     
       
   770                 //MIME types
       
   771                 const CDesC8Array &mt = pf[ii]->SupportedMimeTypes();
       
   772                 first = TRUE;
       
   773                 z1.Zero();
       
   774                 TInt tempD = 0;
       
   775                 for ( j = 0; j < mt.Count(); j++ )
       
   776                     {
       
   777                     z.Copy( mt[j] );
       
   778                     TInt res = z.Find( audioBuf );
       
   779                     if ( res != KErrNotFound )
       
   780                         {
       
   781                         if ( !first )
       
   782                             {
       
   783                             _LIT(KNone,", ");
       
   784                             z1.Append( KNone );
       
   785                             }
       
   786                         first = FALSE;
       
   787                         z1.Append( z );
       
   788                         audioMIMEs.Append( z );
       
   789                         if ( j == mt.Count() && ii == pf.Count() && 
       
   790                              i == controllers.Count() )
       
   791                             {
       
   792                             //do nothing
       
   793                             }
       
   794                         else
       
   795                             {
       
   796                             _LIT(KComma,",");
       
   797                             audioMIMEs.Append( KComma );
       
   798                             }
       
   799                         tempD++;
       
   800                         }
       
   801                     };
       
   802                 CleanupStack::PopAndDestroy(2);
       
   803                 };// for play formats
       
   804             }
       
   805         };
       
   806     
       
   807     // Set the X-Nokia-iRAPP-Accept header
       
   808     TBuf8<KNokiaIrAppAcceptMaxLength> xNokiaIrAppAccept;
       
   809     _LIT(KXNokiaIrAppAccept,"X-Nokia-iRAPP-Accept");
       
   810     xNokiaIrAppAccept.Copy( KXNokiaIrAppAccept );
       
   811     RStringF xNokiaIrAppAcceptString = 
       
   812                   iHttpSession.StringPool().OpenFStringL( xNokiaIrAppAccept );
       
   813     RStringF xNokiaIrAppAcceptValueString =
       
   814                          iHttpSession.StringPool().OpenFStringL( audioMIMEs );
       
   815    logstr.Copy(audioMIMEs);
       
   816    IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - X-Nokia-iRAPP-Accept =" );
       
   817    logstrLenth = logstr.Length();
       
   818    index = 0;
       
   819    while( logstrLenth > 0 )
       
   820       {
       
   821       if( logstrLenth > KLogbufferLenth )
       
   822           {
       
   823           tempStr.Copy( &logstr[index], KLogbufferLenth );
       
   824           }
       
   825       else
       
   826           {
       
   827           tempStr.Copy( &logstr[index], logstrLenth );
       
   828           }
       
   829       IRLOG_DEBUG2( "%S", &tempStr ); 
       
   830       index += KLogbufferLenth;
       
   831       logstrLenth -= KLogbufferLenth;
       
   832       }     
       
   833     THTTPHdrVal xNokiaIrAppAcceptHeader( xNokiaIrAppAcceptValueString );
       
   834     header.SetFieldL(xNokiaIrAppAcceptString, xNokiaIrAppAcceptHeader);
       
   835     xNokiaIrAppAcceptString.Close();
       
   836     xNokiaIrAppAcceptValueString.Close();
       
   837  
       
   838     CleanupStack::PopAndDestroy( 3 );  // audioMIMEs + audioBuf + RMMFControllerImplInfoArray controllers;
       
   839     CleanupStack::PopAndDestroy( fs );
       
   840     CleanupStack::PopAndDestroy( cs );
       
   841     
       
   842    
       
   843     CleanupStack::PopAndDestroy(&logstr);
       
   844     IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - Exiting." );
       
   845     }
       
   846 
       
   847 // ---------------------------------------------------------------------------
       
   848 // CIRHttpDataProvider::ValidateStatusCode()
       
   849 // Validate the status code returned
       
   850 // ---------------------------------------------------------------------------
       
   851 //
       
   852 void CIRHttpDataProvider::ValidateStatusCode( TInt aStatusCode )
       
   853     { 
       
   854     IRLOG_DEBUG( "CIRHttpDataProvider::ValidateStatusCode- Entering" );
       
   855     // Callbacks will be provided as and when the call handling in UI is ready
       
   856     switch ( aStatusCode )
       
   857         {
       
   858         case KOk:
       
   859             {
       
   860             }
       
   861             break;
       
   862         case KCreated:
       
   863             {
       
   864             }
       
   865             break;
       
   866         case KAccepted:
       
   867             {
       
   868             }
       
   869             break;
       
   870         case KNonAuthoritativeInformation:
       
   871             {
       
   872             }
       
   873             break;
       
   874         case KNoContent:
       
   875             {
       
   876             }
       
   877             break;
       
   878         case KResetContent:
       
   879             {
       
   880             }
       
   881             break;
       
   882         case KPartialContent:
       
   883             {
       
   884             }
       
   885             break;
       
   886         // Redirection 3xx status codes
       
   887         case KMultipleChoices:
       
   888             {
       
   889             }
       
   890             break;
       
   891         case KMovedPermanently:
       
   892             {
       
   893             }
       
   894             break;
       
   895         case KFound:
       
   896             {
       
   897             }
       
   898             break;
       
   899         case KSeeOther:
       
   900             {
       
   901             }
       
   902             break;
       
   903         case KNotModified:
       
   904             {
       
   905             iNotModified = ETrue;
       
   906             iObserver.HttpResponseCodeRecieved( KNotModified );
       
   907             }
       
   908             break;
       
   909         case KUseProxy:
       
   910             {
       
   911             }
       
   912             break;
       
   913         // This status code is not used as per RFC 2616 
       
   914         // const TInt KUnused = 306
       
   915         case KTemporaryRedirect:
       
   916             {
       
   917             }
       
   918             break;
       
   919         // Client Error 4xx status codes
       
   920         case KBadRequest:
       
   921             {
       
   922             }
       
   923             break;
       
   924         case KUnauthorized:
       
   925             {
       
   926             }
       
   927             break;
       
   928         case KPaymentRequired:
       
   929             {
       
   930             }
       
   931             break;
       
   932         case KForbidden:
       
   933             {
       
   934             }
       
   935             break;
       
   936         case KNotFound:
       
   937             {
       
   938             iObserver.HttpResponseCodeRecieved( KNotFound );
       
   939             }
       
   940             break;
       
   941         case KMethodNotAllowed:
       
   942             {
       
   943             }
       
   944             break;
       
   945         case KNotAcceptable:
       
   946             {
       
   947             }
       
   948             break;
       
   949         case KProxyAuthenticationRequired:
       
   950             {
       
   951             }
       
   952             break;
       
   953         case KRequestTimeout:
       
   954             {
       
   955             }
       
   956             break;
       
   957         case KConflict:
       
   958             {
       
   959             }
       
   960             break;
       
   961         case KGone:
       
   962             {
       
   963             }
       
   964             break;
       
   965         case KLengthRequired:
       
   966             {
       
   967             }
       
   968             break;
       
   969         case KPreconditionFailed:
       
   970             {
       
   971             }
       
   972             break;
       
   973         case KRequestEntityTooLarge:
       
   974             {
       
   975             }
       
   976             break;
       
   977         case KRequestURITooLong:
       
   978             {
       
   979             }
       
   980             break;
       
   981         case KUnsupportedMediaType:
       
   982             {
       
   983             }
       
   984             break;
       
   985         case KRequestedRangeNotSatisfiable:
       
   986             {
       
   987             }
       
   988             break;
       
   989         case KExpectationFailed:
       
   990             {
       
   991             }
       
   992             break;
       
   993         // Server Error 5xx status codes
       
   994         case KInternalServerError:
       
   995             {
       
   996             }
       
   997             break;
       
   998         case KNotImplemented:
       
   999             {
       
  1000             }
       
  1001             break;
       
  1002         case KBadGateway:
       
  1003             {
       
  1004             }
       
  1005             break;
       
  1006         case KServiceUnavailable:
       
  1007             {
       
  1008             }
       
  1009             break;
       
  1010         case KGatewayTimeout:
       
  1011             {
       
  1012             }
       
  1013             break;
       
  1014         case KHTTPVersionNotSupported:
       
  1015             {
       
  1016             }
       
  1017             break;
       
  1018         default:
       
  1019             break;
       
  1020         } // End of switch(aStatusCode)
       
  1021     IRLOG_DEBUG( "CIRHttpDataProvider::ValidateStatusCode - Exiting." );
       
  1022     }
       
  1023 
       
  1024 // ---------------------------------------------------------------------------
       
  1025 // CIRHttpDataProvider::ReleaseResources()
       
  1026 // Used to free all resources
       
  1027 // ---------------------------------------------------------------------------
       
  1028 //
       
  1029 void CIRHttpDataProvider::ReleaseResources()
       
  1030     {
       
  1031     IRLOG_DEBUG( "CIRHttpDataProvider::ReleaseResources - Entering" );
       
  1032 	iLogoDownloadEngine->ReleaseResources();
       
  1033     CancelTransaction();
       
  1034     iHttpSession.Close();
       
  1035     iFirstTime = ETrue;
       
  1036     IRLOG_DEBUG( "CIRHttpDataProvider::ReleaseResources - Exiting." );
       
  1037     }