voipplugins/accountcreationplugin/engine/src/acphttphandler.cpp
branchRCL_3
changeset 22 d38647835c2e
child 23 755430a7d64b
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implements CAcpHttpHandler methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <http/thttpevent.h>
       
    20 #include <http/rhttpheaders.h>
       
    21 #include <httpstringconstants.h>
       
    22 #include <http/rhttptransaction.h>
       
    23 #include <http/rhttpconnectioninfo.h>
       
    24 #include <http/thttphdrval.h>
       
    25 
       
    26 
       
    27 #include <commdbconnpref.h>
       
    28 #include <es_enum.h>
       
    29 #include <escapeutils.h>
       
    30 
       
    31 #include "acphttphandler.h"
       
    32 #include "accountcreationpluginlogger.h"
       
    33 #include "macphttphandlerobserver.h"
       
    34 #include "accountcreationengineconstants.h"
       
    35 
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CAcpHttpHandler::CAcpHttpHandler
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CAcpHttpHandler::CAcpHttpHandler( MAcpHttpHandlerObserver& aObserver )
       
    43     : CActive( CActive::EPriorityStandard ), iObserver( aObserver )
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CAcpHttpHandler::ConstructL
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CAcpHttpHandler::ConstructL()
       
    53     {
       
    54     ACPLOG( "CAcpHttpHandler::ConstructL begin" );
       
    55     
       
    56     iSession.OpenL();
       
    57     
       
    58     ACPLOG( "CAcpHttpHandler::ConstructL end" );
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CAcpHttpHandler::NewL
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CAcpHttpHandler* CAcpHttpHandler::NewL( MAcpHttpHandlerObserver& aObserver )
       
    66     {
       
    67     CAcpHttpHandler* self = CAcpHttpHandler::NewLC( aObserver );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CAcpHttpHandler::NewLC
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CAcpHttpHandler* CAcpHttpHandler::NewLC( MAcpHttpHandlerObserver& aObserver )
       
    77     {
       
    78     CAcpHttpHandler* self = new ( ELeave ) CAcpHttpHandler( aObserver );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAcpHttpHandler::~CAcpHttpHandler
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CAcpHttpHandler::~CAcpHttpHandler()
       
    89     {
       
    90     ACPLOG( "CAcpHttpHandler::~CAcpHttpHandler begin" );
       
    91 
       
    92     if ( IsActive() )
       
    93         {
       
    94         Cancel();
       
    95         }
       
    96 
       
    97     // Closing the session closes all transactions.
       
    98     iSession.Close();
       
    99     
       
   100     ShutdownConnection();
       
   101 
       
   102     delete iPostData;
       
   103 
       
   104     ACPLOG( "CAcpHttpHandler::~CAcpHttpHandler end" );
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CAcpHttpHandler::GetDataL
       
   109 // Fetches data from network.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CAcpHttpHandler::GetDataL( const TDesC8& aUrl,
       
   113     const TDesC8& aContentType, const TDesC8& aBody, TBool aMimeTypeImage,
       
   114     const TDesC8& aSessionId, TBool aGetSisFile )
       
   115     {
       
   116     ACPLOG( "CAcpHttpHandler::GetDataL begin" ); 
       
   117 
       
   118     // Mime type in use.
       
   119     iMimeTypeImage = aMimeTypeImage;
       
   120 
       
   121     // Copy data to be posted into member variable.
       
   122     delete iPostData;
       
   123     iPostData = NULL;
       
   124     iPostData = aBody.AllocL();
       
   125 
       
   126     RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
       
   127     RStringPool pool = iSession.StringPool();
       
   128 
       
   129     // Start connection.
       
   130     if ( !iConnectionOpen )
       
   131         {
       
   132         iPromptShown = EFalse; // Always show connection prompt first.
       
   133         StartConnectionL();
       
   134         }
       
   135 
       
   136     connInfo.SetPropertyL(
       
   137         pool.StringF( HTTP::EHttpSocketServ, RHTTPSession::GetTable() ),
       
   138         THTTPHdrVal( iSocketServer.Handle() ) );
       
   139 
       
   140     connInfo.SetPropertyL(
       
   141         pool.StringF( HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ),
       
   142         THTTPHdrVal( reinterpret_cast<TInt>( &iConnection ) ) );
       
   143 
       
   144     TBuf8<KMaxUriLength> url;
       
   145 
       
   146     // Insert session id in URLs other than sis URLs.
       
   147     if ( aSessionId.Length() && KSisMimeType().Compare( aContentType ) )
       
   148         {
       
   149         // Change http://address?param=value to
       
   150         //        http://adress;jsessionid=[sessionid]?param=value
       
   151 
       
   152         // Find ? and insert the session id part before it.
       
   153         TInt index = aUrl.Find( KQuestionMark8 );
       
   154         if ( KErrNotFound != index )
       
   155             {
       
   156             url.Append( aUrl.Mid( 0, index ) );
       
   157             url.Append( KSessionId );
       
   158             url.Append( aSessionId );
       
   159             url.Append( aUrl.Mid( index ) );
       
   160             }
       
   161         }
       
   162     else
       
   163         {
       
   164         // Use original URL.
       
   165         url.Copy( aUrl );
       
   166         }
       
   167 
       
   168     HBufC8* encoded = EscapeUtils::EscapeEncodeL( url,
       
   169         EscapeUtils::EEscapeNormal );
       
   170     CleanupStack::PushL( encoded );
       
   171 
       
   172     TBuf<KMaxUriLength> urlTemp;
       
   173     urlTemp.Copy( *encoded );
       
   174     ACPLOG2( " - using url: %S", &urlTemp );
       
   175 
       
   176     TUriParser8 uriParser;
       
   177     User::LeaveIfError( uriParser.Parse( *encoded ) );
       
   178 
       
   179     // Use HTTP GET when downloading SIS files.
       
   180     if ( aGetSisFile )
       
   181         {
       
   182         iTransaction = iSession.OpenTransactionL( uriParser, *this,
       
   183             GetRequestMethod( HTTP::EGET ) );
       
   184         }
       
   185     else
       
   186         {
       
   187         iTransaction = iSession.OpenTransactionL( uriParser, *this,
       
   188             GetRequestMethod( HTTP::EPOST ) );
       
   189         }
       
   190 
       
   191     CleanupStack::PopAndDestroy( encoded );
       
   192 
       
   193     // Set request headers.
       
   194     RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
       
   195 
       
   196     SetHeaderL( hdr, HTTP::EUserAgent, KUserAgent );
       
   197     SetHeaderL( hdr, HTTP::EAccept, KAccept );
       
   198 
       
   199     // For POST add Content-Type header and set body.
       
   200     if ( !aGetSisFile )
       
   201         {
       
   202         SetHeaderL( hdr, HTTP::EContentType, aContentType );
       
   203         iTransaction.Request().SetBody( *this );
       
   204         }
       
   205 
       
   206     // If connection has been opened already, submit transaction.
       
   207     if ( iConnectionOpen )
       
   208         {
       
   209         iConnection.Progress( iNifProgress );
       
   210 
       
   211         if ( !iNifProgress.iError && KLinkLayerOpen == iNifProgress.iStage )
       
   212             {
       
   213             ACPLOG( " - connection still open, submit next transaction" );
       
   214             SubmitTransactionL();
       
   215             }
       
   216         else
       
   217             {
       
   218             // Connection lost or not started, restart it.
       
   219             ACPLOG( " - connection lost, reconnect" );
       
   220 
       
   221             iConnectionOpen = EFalse;
       
   222 
       
   223             if ( !IsActive() ) 
       
   224                 {
       
   225                 iConnection.Start( iStatus );
       
   226                 SetActive();
       
   227                 }
       
   228             }
       
   229         }
       
   230 
       
   231     ACPLOG( "CAcpHttpHandler::GetDataL end" );
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CAcpHttpHandler::SubmitTransactionL
       
   236 // Submits HTTP transaction.
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CAcpHttpHandler::SubmitTransactionL()
       
   240     {
       
   241     ACPLOG( "CAcpHttpHandler::SubmitTransactionL begin" );
       
   242     
       
   243     // Submit the transaction. 
       
   244     // From now on, response event comes to MHFRunL and/or MHFRunError.
       
   245     iTransaction.SubmitL();
       
   246     iTransactionRunning = ETrue;
       
   247     
       
   248     ACPLOG( "CAcpHttpHandler::SubmitTransactionL end" );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CAcpHttpHandler::GetRequestMethod
       
   253 // Returns request method based on type.
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 RStringF CAcpHttpHandler::GetRequestMethod( TInt aType ) const
       
   257     {
       
   258     return iSession.StringPool().StringF( aType, RHTTPSession::GetTable() );
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CAcpHttpHandler::StartConnectionL
       
   263 // Starts the connection asynchronously.
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void CAcpHttpHandler::StartConnectionL()
       
   267     {
       
   268     ACPLOG( "CAcpHttpHandler::StartConnectionL begin" );
       
   269     
       
   270     User::LeaveIfError( iSocketServer.Connect() );
       
   271     User::LeaveIfError( iConnection.Open( iSocketServer ) );
       
   272     
       
   273     TCommDbConnPref pref;
       
   274     pref.SetDirection( ECommDbConnectionDirectionOutgoing );
       
   275     pref.SetBearerSet( KCommDbBearerLAN | KCommDbBearerCSD |
       
   276         KCommDbBearerWcdma | KCommDbBearerWLAN );
       
   277     
       
   278     // Show connection prompt only once.
       
   279     if ( !iPromptShown )
       
   280         {
       
   281         ACPLOG( " - show connection prompt" );
       
   282         pref.SetDialogPreference( ECommDbDialogPrefPrompt );
       
   283         iPromptShown = ETrue;
       
   284         }
       
   285     else
       
   286         {
       
   287         ACPLOG3( " - set iap %d / net %d", iIapId, iNetId );
       
   288         pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
   289         pref.SetIapId( iIapId );
       
   290         pref.SetNetId( iNetId );
       
   291         }
       
   292 
       
   293     if ( !IsActive() ) 
       
   294         {
       
   295         iConnection.Start( pref, iStatus );
       
   296         SetActive();
       
   297         }
       
   298 
       
   299     ACPLOG( "CAcpHttpHandler::StartConnectionL end" );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CAcpHttpHandler::CancelTransaction
       
   304 // Cancels ongoing transaction and frees the resources.
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CAcpHttpHandler::CancelTransaction()
       
   308     {
       
   309     ACPLOG( "CAcpHttpHandler::CancelTransaction begin" );
       
   310     
       
   311     if ( !iTransactionRunning )
       
   312         {
       
   313         ACPLOG( "CAcpHttpHandler::CancelTransaction end (not running)" );
       
   314         return;
       
   315         }
       
   316     
       
   317     iTransaction.Close();
       
   318     ACPLOG( " - transaction closed" );
       
   319     
       
   320     iTransactionRunning = EFalse;
       
   321     ACPLOG( "CAcpHttpHandler::CancelTransaction end" );
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CAcpHttpHandler::ShutdownConnection
       
   326 // Shuts down connection.
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 void CAcpHttpHandler::ShutdownConnection()
       
   330     {
       
   331     ACPLOG( "CAcpHttpHandler::ShutdownConnection begin" );
       
   332     
       
   333     iConnection.Close();
       
   334     iSocketServer.Close();
       
   335     
       
   336     ACPLOG( "CAcpHttpHandler::ShutdownConnection end" );
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CAcpHttpHandler::SetHeaderL
       
   341 // Sets transaction's request headers.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CAcpHttpHandler::SetHeaderL( 
       
   345     RHTTPHeaders aHeaders, 
       
   346     TInt aHdrField, 
       
   347     const TDesC8& aHdrValue )
       
   348     {
       
   349     RStringF valStr = iSession.StringPool().OpenFStringL( aHdrValue );
       
   350     CleanupClosePushL( valStr );
       
   351     THTTPHdrVal val( valStr );
       
   352     aHeaders.SetFieldL( iSession.StringPool().StringF(
       
   353         aHdrField, RHTTPSession::GetTable() ), val );
       
   354     CleanupStack::PopAndDestroy( &valStr );
       
   355 
       
   356     ACPLOG( "CAcpHttpHandler::SetHeaderL: Request headers set." );
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CAcpHttpHandler::GetNextDataPart
       
   361 // From MHTTPDataSupplier.
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 TBool CAcpHttpHandler::GetNextDataPart( TPtrC8& aDataPart )
       
   365     {
       
   366     ACPLOG( "CAcpHttpHandler::GetNextDataPart begin" );
       
   367     
       
   368     if ( iPostData )
       
   369         {
       
   370         aDataPart.Set( iPostData->Des() );
       
   371         }
       
   372     
       
   373     ACPLOG( "CAcpHttpHandler::GetNextDataPart end" );
       
   374     return ETrue;
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // CAcpHttpHandler::ReleaseData
       
   379 // From MHTTPDataSupplier.
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 void CAcpHttpHandler::ReleaseData()
       
   383     {
       
   384     ACPLOG( "CAcpHttpHandler::ReleaseData begin" );
       
   385     
       
   386     delete iPostData;
       
   387     iPostData = NULL;
       
   388     
       
   389     ACPLOG( "CAcpHttpHandler::ReleaseData end" );
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // CAcpHttpHandler::OverallDataSize
       
   394 // From MHTTPDataSupplier.
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 TInt CAcpHttpHandler::OverallDataSize()
       
   398     {
       
   399     ACPLOG( "CAcpHttpHandler::OverallDataSize begin" );
       
   400     
       
   401     if ( iPostData )
       
   402         {
       
   403         ACPLOG2( "CAcpHttpHandler::OverallDataSize end (%d)",
       
   404             iPostData->Length() );
       
   405         return iPostData->Length();
       
   406         }
       
   407     else
       
   408         {
       
   409         ACPLOG( "CAcpHttpHandler::OverallDataSize end" );
       
   410         return KErrNotFound ;
       
   411         }
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // CAcpHttpHandler::Reset
       
   416 // From MHTTPDataSupplier.
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 TInt CAcpHttpHandler::Reset()
       
   420     {
       
   421     if ( iPostData )
       
   422         {
       
   423         // iPostData (which is used as data source) is found.
       
   424         return KErrNone;
       
   425         }
       
   426     
       
   427     return KErrNotFound;
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CAcpHttpHandler::MHFRunL
       
   432 // From MHTTPTransactionCallback.
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 void CAcpHttpHandler::MHFRunL( 
       
   436     RHTTPTransaction aTransaction, 
       
   437     const THTTPEvent& aEvent )
       
   438     {
       
   439     ACPLOG2( "CAcpHttpHandler::MHFRunL: THTTPEvent=%d", aEvent.iStatus );
       
   440 
       
   441     switch ( aEvent.iStatus )
       
   442         {
       
   443         case THTTPEvent::EGotResponseHeaders:
       
   444             {
       
   445             ProcessHeadersL( aTransaction );
       
   446             iObserver.NotifyHttpEvent( aEvent.iStatus );
       
   447             }
       
   448             break;
       
   449         case THTTPEvent::EGotResponseBodyData:
       
   450             {
       
   451             MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   452             TPtrC8 dataChunk;
       
   453 
       
   454             TBool isLast = body->GetNextDataPart( dataChunk );
       
   455             iObserver.NotifyBodyReceived( dataChunk );
       
   456 
       
   457             // Check if more data is expected.
       
   458             if ( isLast )
       
   459                 {
       
   460                 iObserver.NotifyHttpEvent( aEvent.iStatus );
       
   461                 }
       
   462 
       
   463             // Always remember to release the body data.
       
   464             body->ReleaseData();
       
   465             }           
       
   466             break;
       
   467         case THTTPEvent::EResponseComplete:
       
   468             {
       
   469             iObserver.NotifyHttpEvent( aEvent.iStatus );
       
   470             }           
       
   471             break;
       
   472         case THTTPEvent::ESucceeded:
       
   473             {
       
   474             ACPLOG( " - HTTP event: succeeded" );
       
   475             CancelTransaction();
       
   476             iObserver.NotifyHttpEvent( aEvent.iStatus );
       
   477             }           
       
   478             break;
       
   479         case THTTPEvent::EFailed:
       
   480             {
       
   481             ACPLOG( " - HTTP event: failed" );
       
   482             CancelTransaction();
       
   483             iObserver.NotifyHttpEvent( aEvent.iStatus );
       
   484             }           
       
   485             break;
       
   486         default:
       
   487             {
       
   488             // Check if some other real error received.
       
   489             if ( aEvent.iStatus != THTTPEvent::ERedirectedTemporarily )
       
   490                 {
       
   491                 CancelTransaction();
       
   492                 iObserver.NotifyHttpError( aEvent.iStatus );
       
   493                 
       
   494                 // HTTP error occurred, it's safer to restart the connection.
       
   495                 iConnectionOpen = EFalse;
       
   496                 iSession.Close();
       
   497                 iConnection.Close();
       
   498                 iSocketServer.Close();
       
   499                 // Reopen session.
       
   500                 iSession.OpenL();
       
   501                 }
       
   502             }
       
   503             break;
       
   504         }
       
   505     }
       
   506     
       
   507 // ---------------------------------------------------------------------------
       
   508 // CAcpHttpHandler::MHFRunError
       
   509 // From MHTTPTransactionCallback.
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 TInt CAcpHttpHandler::MHFRunError( 
       
   513     TInt aError, 
       
   514     RHTTPTransaction /*aTransaction*/, 
       
   515     const THTTPEvent& /*aEvent*/ )
       
   516     {
       
   517     ACPLOG2( "CAcpHttpHandler::MHFRunError: aError = %d", aError );
       
   518     iObserver.NotifyHttpError( aError );
       
   519     
       
   520     // HTTP error occurred, it's safer to restart the connection.
       
   521     iConnectionOpen = EFalse;
       
   522     iSession.Close();
       
   523     iConnection.Close();
       
   524     iSocketServer.Close();
       
   525     // Reopen session.
       
   526     TRAP_IGNORE( iSession.OpenL() );
       
   527     
       
   528     return KErrNone;
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // CAcpHttpHandler::RunL
       
   533 // From CActive.
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void CAcpHttpHandler::RunL()
       
   537     {
       
   538     ACPLOG( "CAcpHttpHandler::RunL begin" );
       
   539     
       
   540     if ( KErrNone == iStatus.Int() )
       
   541         {
       
   542         ACPLOG( " - Connection started, submit transaction" );
       
   543         TUint connCount( KErrNone );
       
   544         iConnection.EnumerateConnections( connCount );
       
   545         ACPLOG2( " - Connection count %d", connCount );
       
   546         
       
   547         if ( connCount )
       
   548             {
       
   549             TConnectionInfoBuf connInfoPckg;
       
   550             iConnection.GetConnectionInfo( 1, connInfoPckg );
       
   551             TConnectionInfo connInfo = connInfoPckg();
       
   552             
       
   553             ACPLOG3( "   - iapId: %d    netId: %d", connInfo.iIapId,
       
   554                 connInfo.iNetId );
       
   555             
       
   556             iIapId = connInfo.iIapId;
       
   557             iNetId = connInfo.iNetId;
       
   558             
       
   559             iConnectionOpen = ETrue;
       
   560             }
       
   561         
       
   562         // Submit the first transaction. Further transactions are submitted
       
   563         // in GetDataL.
       
   564         SubmitTransactionL();
       
   565         }
       
   566     else
       
   567         {
       
   568         // Error occurred, notify observer.
       
   569         iObserver.NotifyHttpError( iStatus.Int() );
       
   570         }
       
   571     
       
   572     ACPLOG( "CAcpHttpHandler::RunL end" );
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // CAcpHttpHandler::DoCancel
       
   577 // From CActive.
       
   578 // ---------------------------------------------------------------------------
       
   579 //
       
   580 void CAcpHttpHandler::DoCancel()
       
   581     {
       
   582     ACPLOG( "CAcpHttpHandler::DoCancel" );
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 // CAcpHttpHandler::ProcessHeadersL
       
   587 // Handles known HTTP headers.
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 void CAcpHttpHandler::ProcessHeadersL( RHTTPTransaction& aTransaction )
       
   591     {
       
   592     ACPLOG( "CAcpHttpHandler::ProcessHeadersL begin" );
       
   593     
       
   594     RHTTPHeaders header = aTransaction.Response().GetHeaderCollection();
       
   595     RStringPool pool = aTransaction.Session().StringPool();
       
   596     THTTPHdrFieldIter filter = header.Fields();
       
   597 
       
   598     while ( !filter.AtEnd() )
       
   599         {
       
   600         RStringTokenF fieldName = filter();
       
   601         RStringF fieldNameStr = pool.StringF( fieldName );
       
   602         THTTPHdrVal fieldVal;
       
   603         if ( KErrNone == header.GetField( fieldNameStr, 0, fieldVal ) )
       
   604             {
       
   605             TBuf<KDefaultBufferSize> tmp;
       
   606             tmp.Copy( fieldNameStr.DesC() );
       
   607             ACPLOG2( " - field: %S", &tmp );
       
   608             
       
   609             if ( THTTPHdrVal::KStrFVal == fieldVal.Type() )
       
   610                 {
       
   611                 tmp.Copy( fieldVal.StrF().DesC() );
       
   612                 ACPLOG2( " - value: %S", &tmp );
       
   613                 }
       
   614             else if ( THTTPHdrVal::KStrVal == fieldVal.Type() )
       
   615                 {
       
   616                 tmp.Copy( fieldVal.Str().DesC() );
       
   617                 ACPLOG2( " - value: %S", &tmp );
       
   618                 }
       
   619             else if ( THTTPHdrVal::KTIntVal == fieldVal.Type() )
       
   620                 {
       
   621                 ACPLOG2( " - value: %d", fieldVal.Int() );
       
   622                 }
       
   623             
       
   624             // Get image content type.
       
   625             if ( iMimeTypeImage )
       
   626                 {
       
   627                 RStringF contentType = pool.StringF(
       
   628                     HTTP::EContentType, RHTTPSession::GetTable() );
       
   629                 if ( fieldNameStr == contentType )
       
   630                     {
       
   631                     if ( fieldVal.StrF().DesC().Length() )
       
   632                         {
       
   633                         // Informs provider for content type of image.
       
   634                         iObserver.NotifyContentTypeReceived( 
       
   635                             fieldVal.StrF().DesC() );
       
   636                         }
       
   637                     }
       
   638                 }
       
   639             
       
   640             // Get session id from a cookie.
       
   641             RStringF setCookieStr = pool.StringF( HTTP::ESetCookie,
       
   642                 RHTTPSession::GetTable() );
       
   643             if ( fieldNameStr == setCookieStr )
       
   644                 {
       
   645                 ACPLOG( " - cookie field found" );
       
   646                 
       
   647                 RStringF cookieStr = pool.StringF(
       
   648                     HTTP::ECookie, RHTTPSession::GetTable() );
       
   649                 
       
   650                 if ( cookieStr == fieldVal.StrF() )
       
   651                     {
       
   652                     RStringF cookieNameStr = pool.StringF(
       
   653                         HTTP::ECookieName, RHTTPSession::GetTable() );
       
   654                     
       
   655                     THTTPHdrVal cookieName;
       
   656                     
       
   657                     if ( KErrNone == header.GetParam(
       
   658                         setCookieStr, cookieNameStr, cookieName ) )
       
   659                         {
       
   660                         RStringF cookieValueStr = pool.StringF(
       
   661                             HTTP::ECookieValue, RHTTPSession::GetTable() );
       
   662                         THTTPHdrVal cookieVal;
       
   663                     
       
   664                         if ( KErrNone == header.GetParam(
       
   665                             setCookieStr, cookieValueStr, cookieVal ) ) 
       
   666                             {
       
   667                             if ( THTTPHdrVal::KStrFVal == cookieVal.Type() )
       
   668                                 {
       
   669                                 TBuf<KDefaultBufferSize> cookieTmp;
       
   670                                 cookieTmp.Copy( cookieVal.StrF().DesC() );
       
   671                             
       
   672                                 if ( cookieTmp.Length() )
       
   673                                     {
       
   674                                     iObserver.NotifySessionIdReceivedL(
       
   675                                             cookieVal.StrF().DesC() );
       
   676                                     }
       
   677                                 ACPLOG2( " -session id set to %S", &cookieTmp );
       
   678                                 }
       
   679                             else if ( THTTPHdrVal::KStrVal == cookieVal.Type() )
       
   680                                 {
       
   681                                 TBuf<KDefaultBufferSize> cookieTmp;
       
   682                                 cookieTmp.Copy( cookieVal.Str().DesC() );
       
   683                                 
       
   684                                 if ( cookieTmp.Length() )
       
   685                                     {
       
   686                                     iObserver.NotifySessionIdReceivedL(
       
   687                                             cookieVal.Str().DesC() );
       
   688                                     }
       
   689                                 ACPLOG2( " -session id set to %S", &cookieTmp );
       
   690                                 }
       
   691                             }
       
   692                         }
       
   693                     }
       
   694                 }
       
   695             }
       
   696         // Proceed to next header.
       
   697         ++filter;
       
   698         }
       
   699     
       
   700     ACPLOG( "CAcpHttpHandler::ProcessHeadersL end" );
       
   701     }
       
   702 
       
   703 
       
   704 // End of file.