uidesigner/com.nokia.sdt.series60.componentlibrary/components/non-layout/webclient/WebClientEngine.cpp
author fturovic <frank.turovich@nokia.com>
Tue, 07 Apr 2009 13:55:47 -0500
branchRCL_2_0
changeset 69 cab50ba61335
parent 2 d760517a8095
permissions -rw-r--r--
added info on IAD custom rules
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
// INCLUDE FILES
cawthron
parents:
diff changeset
    20
#include <avkon.hrh>
cawthron
parents:
diff changeset
    21
#include <aknnotewrappers.h>
cawthron
parents:
diff changeset
    22
#include <stringloader.h>
cawthron
parents:
diff changeset
    23
#include <http.h>
cawthron
parents:
diff changeset
    24
//#include <WebClient.rsg>
cawthron
parents:
diff changeset
    25
#include "WebClientEngine.pan"
cawthron
parents:
diff changeset
    26
//#include "WebClient.hrh"
cawthron
parents:
diff changeset
    27
#include "WebClientEngine.h"
cawthron
parents:
diff changeset
    28
cawthron
parents:
diff changeset
    29
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    30
// CWebClientEngine::NewL()
cawthron
parents:
diff changeset
    31
// Creates instance of CWebClientEngine.
cawthron
parents:
diff changeset
    32
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    33
//
cawthron
parents:
diff changeset
    34
CWebClientEngine* CWebClientEngine::NewL( MWebClientObserver& aObserver )
cawthron
parents:
diff changeset
    35
    {
cawthron
parents:
diff changeset
    36
    CWebClientEngine* self = CWebClientEngine::NewLC( aObserver );
cawthron
parents:
diff changeset
    37
    CleanupStack::Pop( self );
cawthron
parents:
diff changeset
    38
    return self;
cawthron
parents:
diff changeset
    39
    }
cawthron
parents:
diff changeset
    40
cawthron
parents:
diff changeset
    41
cawthron
parents:
diff changeset
    42
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    43
// CWebClientEngine::NewLC()
cawthron
parents:
diff changeset
    44
// Creates instance of CWebClientEngine.
cawthron
parents:
diff changeset
    45
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    46
//
cawthron
parents:
diff changeset
    47
CWebClientEngine* CWebClientEngine::NewLC( MWebClientObserver& aObserver )
cawthron
parents:
diff changeset
    48
    {
cawthron
parents:
diff changeset
    49
    CWebClientEngine* self = new (ELeave) CWebClientEngine( aObserver );
cawthron
parents:
diff changeset
    50
    CleanupStack::PushL( self );
cawthron
parents:
diff changeset
    51
    self->ConstructL();
cawthron
parents:
diff changeset
    52
    return self;
cawthron
parents:
diff changeset
    53
    }
cawthron
parents:
diff changeset
    54
cawthron
parents:
diff changeset
    55
cawthron
parents:
diff changeset
    56
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    57
// CWebClientEngine::CWebClientEngine()
cawthron
parents:
diff changeset
    58
// First phase constructor.
cawthron
parents:
diff changeset
    59
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    60
//
cawthron
parents:
diff changeset
    61
CWebClientEngine::CWebClientEngine( MWebClientObserver& aObserver )
cawthron
parents:
diff changeset
    62
:    iObserver( aObserver ),
cawthron
parents:
diff changeset
    63
     iSessionOpened( EFalse ),
cawthron
parents:
diff changeset
    64
     iRunning( EFalse )
cawthron
parents:
diff changeset
    65
    {
cawthron
parents:
diff changeset
    66
    // no implementation required
cawthron
parents:
diff changeset
    67
    }
cawthron
parents:
diff changeset
    68
cawthron
parents:
diff changeset
    69
cawthron
parents:
diff changeset
    70
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    71
// CWebClientEngine::~CWebClientEngine()
cawthron
parents:
diff changeset
    72
// Destructor.
cawthron
parents:
diff changeset
    73
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    74
//
cawthron
parents:
diff changeset
    75
CWebClientEngine::~CWebClientEngine()
cawthron
parents:
diff changeset
    76
    {
cawthron
parents:
diff changeset
    77
    iSession.Close();
cawthron
parents:
diff changeset
    78
    iConnection.Close();
cawthron
parents:
diff changeset
    79
	iSocketServ.Close();
cawthron
parents:
diff changeset
    80
    }
cawthron
parents:
diff changeset
    81
cawthron
parents:
diff changeset
    82
cawthron
parents:
diff changeset
    83
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    84
// CWebClientEngine::ConstructL()
cawthron
parents:
diff changeset
    85
// Second phase construction.
cawthron
parents:
diff changeset
    86
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
    87
//
cawthron
parents:
diff changeset
    88
void CWebClientEngine::ConstructL()
cawthron
parents:
diff changeset
    89
	{
cawthron
parents:
diff changeset
    90
	
cawthron
parents:
diff changeset
    91
	}
cawthron
parents:
diff changeset
    92
	
cawthron
parents:
diff changeset
    93
void CWebClientEngine::OpenSessionL()
cawthron
parents:
diff changeset
    94
    {
cawthron
parents:
diff changeset
    95
    if (iSessionOpened) return;
cawthron
parents:
diff changeset
    96
    
cawthron
parents:
diff changeset
    97
    // Open RHTTPSession with default protocol ("HTTP/TCP")
cawthron
parents:
diff changeset
    98
    TRAPD( err, iSession.OpenL() );
cawthron
parents:
diff changeset
    99
    if( err != KErrNone ) {
cawthron
parents:
diff changeset
   100
        // Most common error; no access point configured, and session creation
cawthron
parents:
diff changeset
   101
        // leaves with KErrNotFound.
cawthron
parents:
diff changeset
   102
    	iObserver.ClientOpenSessionFailedL( *this, err );
cawthron
parents:
diff changeset
   103
        User::Leave( err );
cawthron
parents:
diff changeset
   104
    }
cawthron
parents:
diff changeset
   105
    
cawthron
parents:
diff changeset
   106
 	User::LeaveIfError(iSocketServ.Connect());
cawthron
parents:
diff changeset
   107
	User::LeaveIfError(iConnection.Open(iSocketServ));
cawthron
parents:
diff changeset
   108
	User::LeaveIfError(iConnection.Start());
cawthron
parents:
diff changeset
   109
	
cawthron
parents:
diff changeset
   110
	RStringPool strP = iSession.StringPool();
cawthron
parents:
diff changeset
   111
	RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
cawthron
parents:
diff changeset
   112
	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
cawthron
parents:
diff changeset
   113
	TInt connPtr = REINTERPRET_CAST(TInt, &(iConnection));
cawthron
parents:
diff changeset
   114
	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );
cawthron
parents:
diff changeset
   115
cawthron
parents:
diff changeset
   116
cawthron
parents:
diff changeset
   117
    // Install this class as the callback for authentication requests. When 
cawthron
parents:
diff changeset
   118
    // page requires authentication the framework calls GetCredentialsL to get 
cawthron
parents:
diff changeset
   119
    // user name and password.
cawthron
parents:
diff changeset
   120
    InstallAuthenticationL( iSession );
cawthron
parents:
diff changeset
   121
    
cawthron
parents:
diff changeset
   122
    iSessionOpened = true;
cawthron
parents:
diff changeset
   123
    }
cawthron
parents:
diff changeset
   124
cawthron
parents:
diff changeset
   125
cawthron
parents:
diff changeset
   126
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   127
// CWebClientEngine::SetHeaderL()
cawthron
parents:
diff changeset
   128
// Used to set header value to HTTP request
cawthron
parents:
diff changeset
   129
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   130
//
cawthron
parents:
diff changeset
   131
void CWebClientEngine::SetHeaderL( RHTTPHeaders aHeaders, 
cawthron
parents:
diff changeset
   132
                                   TInt aHdrField, 
cawthron
parents:
diff changeset
   133
                                   const TDesC8& aHdrValue )
cawthron
parents:
diff changeset
   134
    {
cawthron
parents:
diff changeset
   135
    RStringF valStr = iSession.StringPool().OpenFStringL( aHdrValue );
cawthron
parents:
diff changeset
   136
    CleanupClosePushL( valStr );
cawthron
parents:
diff changeset
   137
    THTTPHdrVal val( valStr );
cawthron
parents:
diff changeset
   138
    aHeaders.SetFieldL( iSession.StringPool().StringF( aHdrField,
cawthron
parents:
diff changeset
   139
        RHTTPSession::GetTable() ), val );
cawthron
parents:
diff changeset
   140
    CleanupStack::PopAndDestroy( &valStr );
cawthron
parents:
diff changeset
   141
    }
cawthron
parents:
diff changeset
   142
cawthron
parents:
diff changeset
   143
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   144
// CWebClientEngine::DumpRespHeadersL(RHTTPTransaction& aTransaction)
cawthron
parents:
diff changeset
   145
// Used to display HTTP header field names and values
cawthron
parents:
diff changeset
   146
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   147
//
cawthron
parents:
diff changeset
   148
void CWebClientEngine::DumpRespHeadersL( RHTTPTransaction& aTransaction )
cawthron
parents:
diff changeset
   149
    {
cawthron
parents:
diff changeset
   150
    RHTTPResponse resp = aTransaction.Response();
cawthron
parents:
diff changeset
   151
    RStringPool strP = aTransaction.Session().StringPool();
cawthron
parents:
diff changeset
   152
    RHTTPHeaders hdr = resp.GetHeaderCollection();
cawthron
parents:
diff changeset
   153
    THTTPHdrFieldIter it = hdr.Fields();
cawthron
parents:
diff changeset
   154
cawthron
parents:
diff changeset
   155
    HBufC* headerField = HBufC::NewLC( KMaxHeaderNameLength + KMaxHeaderValueLength );
cawthron
parents:
diff changeset
   156
    HBufC* fieldValBuf = HBufC::NewLC( KMaxHeaderValueLength );
cawthron
parents:
diff changeset
   157
cawthron
parents:
diff changeset
   158
    while ( it.AtEnd() == EFalse )
cawthron
parents:
diff changeset
   159
        {
cawthron
parents:
diff changeset
   160
        RStringTokenF fieldName = it();
cawthron
parents:
diff changeset
   161
        RStringF fieldNameStr = strP.StringF( fieldName );
cawthron
parents:
diff changeset
   162
        THTTPHdrVal fieldVal;
cawthron
parents:
diff changeset
   163
        if ( hdr.GetField( fieldNameStr, 0, fieldVal ) == KErrNone )
cawthron
parents:
diff changeset
   164
            {
cawthron
parents:
diff changeset
   165
            const TDesC8& fieldNameDesC = fieldNameStr.DesC();
cawthron
parents:
diff changeset
   166
            headerField->Des().Copy( fieldNameDesC.Left( KMaxHeaderNameLength ));
cawthron
parents:
diff changeset
   167
            fieldValBuf->Des().Zero();
cawthron
parents:
diff changeset
   168
            switch ( fieldVal.Type() )
cawthron
parents:
diff changeset
   169
                {
cawthron
parents:
diff changeset
   170
            // the value is an integer
cawthron
parents:
diff changeset
   171
            case THTTPHdrVal::KTIntVal:
cawthron
parents:
diff changeset
   172
                fieldValBuf->Des().Num( fieldVal.Int() );
cawthron
parents:
diff changeset
   173
                break;
cawthron
parents:
diff changeset
   174
            // the value is a case-insensitive string
cawthron
parents:
diff changeset
   175
            case THTTPHdrVal::KStrFVal:
cawthron
parents:
diff changeset
   176
                {
cawthron
parents:
diff changeset
   177
                RStringF fieldValStr = strP.StringF( fieldVal.StrF() );
cawthron
parents:
diff changeset
   178
                const TDesC8& fieldValDesC = fieldValStr.DesC();
cawthron
parents:
diff changeset
   179
                fieldValBuf->Des().Copy( fieldValDesC.Left(KMaxHeaderValueLength ));
cawthron
parents:
diff changeset
   180
                }
cawthron
parents:
diff changeset
   181
                break;
cawthron
parents:
diff changeset
   182
            // the value is a case-sensitive string
cawthron
parents:
diff changeset
   183
            case THTTPHdrVal::KStrVal:
cawthron
parents:
diff changeset
   184
                {
cawthron
parents:
diff changeset
   185
                RString fieldValStr = strP.String( fieldVal.Str() );
cawthron
parents:
diff changeset
   186
                const TDesC8& fieldValDesC = fieldValStr.DesC();
cawthron
parents:
diff changeset
   187
                fieldValBuf->Des().Copy( fieldValDesC.Left(KMaxHeaderValueLength) );
cawthron
parents:
diff changeset
   188
                }
cawthron
parents:
diff changeset
   189
                break;
cawthron
parents:
diff changeset
   190
            // the value is a date/time
cawthron
parents:
diff changeset
   191
            case THTTPHdrVal::KDateVal:
cawthron
parents:
diff changeset
   192
                {
cawthron
parents:
diff changeset
   193
                TDateTime date = fieldVal.DateTime();
cawthron
parents:
diff changeset
   194
                TBuf<KMaxDateTimeStringLength> dateTimeString;
cawthron
parents:
diff changeset
   195
                TTime t( date );
cawthron
parents:
diff changeset
   196
                t.FormatL( dateTimeString,KDateFormat );
cawthron
parents:
diff changeset
   197
                fieldValBuf->Des().Copy( dateTimeString );
cawthron
parents:
diff changeset
   198
                } 
cawthron
parents:
diff changeset
   199
                break;
cawthron
parents:
diff changeset
   200
            // the value is type is unknown
cawthron
parents:
diff changeset
   201
            default:
cawthron
parents:
diff changeset
   202
                break;
cawthron
parents:
diff changeset
   203
                }
cawthron
parents:
diff changeset
   204
cawthron
parents:
diff changeset
   205
            // Display HTTP header field name and value
cawthron
parents:
diff changeset
   206
            headerField->Des().Append( KColon );
cawthron
parents:
diff changeset
   207
            headerField->Des().Append( *fieldValBuf );
cawthron
parents:
diff changeset
   208
            iObserver.ClientHeaderReceivedL( *this, *headerField );
cawthron
parents:
diff changeset
   209
            
cawthron
parents:
diff changeset
   210
            // Display realm for WWW-Authenticate header
cawthron
parents:
diff changeset
   211
            RStringF wwwAuth = strP.StringF( HTTP::EWWWAuthenticate,RHTTPSession::GetTable() );
cawthron
parents:
diff changeset
   212
            if ( fieldNameStr == wwwAuth )
cawthron
parents:
diff changeset
   213
                {
cawthron
parents:
diff changeset
   214
                // check the auth scheme is 'basic'
cawthron
parents:
diff changeset
   215
                RStringF basic = strP.StringF( HTTP::EBasic,RHTTPSession::GetTable() );
cawthron
parents:
diff changeset
   216
                RStringF realm = strP.StringF( HTTP::ERealm,RHTTPSession::GetTable() );
cawthron
parents:
diff changeset
   217
                THTTPHdrVal realmVal;
cawthron
parents:
diff changeset
   218
                if (( fieldVal.StrF() == basic ) && 
cawthron
parents:
diff changeset
   219
                    ( !hdr.GetParam( wwwAuth, realm, realmVal )))
cawthron
parents:
diff changeset
   220
                    {
cawthron
parents:
diff changeset
   221
                    RStringF realmValStr = strP.StringF( realmVal.StrF() );
cawthron
parents:
diff changeset
   222
                    fieldValBuf->Des().Copy( realmValStr.DesC() );
cawthron
parents:
diff changeset
   223
                    headerField->Des().Copy( Krealm );
cawthron
parents:
diff changeset
   224
                    headerField->Des().Append( *fieldValBuf );
cawthron
parents:
diff changeset
   225
                    iObserver.ClientHeaderReceivedL( *this, *headerField );
cawthron
parents:
diff changeset
   226
                    }
cawthron
parents:
diff changeset
   227
                }
cawthron
parents:
diff changeset
   228
            }
cawthron
parents:
diff changeset
   229
        ++it;
cawthron
parents:
diff changeset
   230
        }
cawthron
parents:
diff changeset
   231
        CleanupStack::PopAndDestroy( fieldValBuf );
cawthron
parents:
diff changeset
   232
        CleanupStack::PopAndDestroy( headerField );
cawthron
parents:
diff changeset
   233
    }
cawthron
parents:
diff changeset
   234
cawthron
parents:
diff changeset
   235
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   236
// CWebClientEngine::HandleRunErrorL()
cawthron
parents:
diff changeset
   237
// Called from MHFRunError() when *leave* occurs in handling of transaction event.
cawthron
parents:
diff changeset
   238
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   239
//
cawthron
parents:
diff changeset
   240
void CWebClientEngine::HandleRunErrorL( TInt aError )
cawthron
parents:
diff changeset
   241
    {
cawthron
parents:
diff changeset
   242
    iObserver.ClientRunErrorL( *this, aError );
cawthron
parents:
diff changeset
   243
    }
cawthron
parents:
diff changeset
   244
cawthron
parents:
diff changeset
   245
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   246
// CWebClientEngine::IssueHTTPGetL()
cawthron
parents:
diff changeset
   247
// Start a new HTTP GET transaction.
cawthron
parents:
diff changeset
   248
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   249
//
cawthron
parents:
diff changeset
   250
void CWebClientEngine::IssueHTTPGetL( const TDesC8& aUri )
cawthron
parents:
diff changeset
   251
    {
cawthron
parents:
diff changeset
   252
    // Ensure the session is open
cawthron
parents:
diff changeset
   253
    OpenSessionL();
cawthron
parents:
diff changeset
   254
    // Parse string to URI (as defined in RFC2396)
cawthron
parents:
diff changeset
   255
    TUriParser8 uri;
cawthron
parents:
diff changeset
   256
    uri.Parse( aUri );
cawthron
parents:
diff changeset
   257
cawthron
parents:
diff changeset
   258
    // Get request method string for HTTP GET
cawthron
parents:
diff changeset
   259
    RStringF method = iSession.StringPool().StringF( HTTP::EGET,
cawthron
parents:
diff changeset
   260
        RHTTPSession::GetTable());
cawthron
parents:
diff changeset
   261
cawthron
parents:
diff changeset
   262
    // Open transaction with previous method and parsed uri. This class will
cawthron
parents:
diff changeset
   263
    // receive transaction events in MHFRunL and MHFRunError.
cawthron
parents:
diff changeset
   264
    iTransaction = iSession.OpenTransactionL( uri, *this, method );
cawthron
parents:
diff changeset
   265
cawthron
parents:
diff changeset
   266
    // Set headers for request; user agent and accepted content type
cawthron
parents:
diff changeset
   267
    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
cawthron
parents:
diff changeset
   268
    SetHeaderL( hdr, HTTP::EUserAgent, KUserAgent );
cawthron
parents:
diff changeset
   269
    SetHeaderL( hdr, HTTP::EAccept, KAccept );
cawthron
parents:
diff changeset
   270
cawthron
parents:
diff changeset
   271
    // Submit the transaction. After this the framework will give transaction
cawthron
parents:
diff changeset
   272
    // events via MHFRunL and MHFRunError.
cawthron
parents:
diff changeset
   273
    iTransaction.SubmitL();
cawthron
parents:
diff changeset
   274
cawthron
parents:
diff changeset
   275
    iRunning = ETrue;
cawthron
parents:
diff changeset
   276
cawthron
parents:
diff changeset
   277
    iObserver.ClientConnectingL( *this );
cawthron
parents:
diff changeset
   278
    }
cawthron
parents:
diff changeset
   279
cawthron
parents:
diff changeset
   280
cawthron
parents:
diff changeset
   281
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   282
// CWebClientEngine::CancelTransactionL()
cawthron
parents:
diff changeset
   283
// Cancels currently running transaction and frees resources related to it.
cawthron
parents:
diff changeset
   284
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   285
//
cawthron
parents:
diff changeset
   286
void CWebClientEngine::CancelTransactionL()
cawthron
parents:
diff changeset
   287
    {
cawthron
parents:
diff changeset
   288
    if( !iRunning ) 
cawthron
parents:
diff changeset
   289
        return;
cawthron
parents:
diff changeset
   290
cawthron
parents:
diff changeset
   291
    // Close() also cancels transaction (Cancel() can also be used but 
cawthron
parents:
diff changeset
   292
    // resources allocated by transaction must be still freed with Close())
cawthron
parents:
diff changeset
   293
    iTransaction.Close();
cawthron
parents:
diff changeset
   294
cawthron
parents:
diff changeset
   295
    // Not running anymore
cawthron
parents:
diff changeset
   296
    iRunning = EFalse;
cawthron
parents:
diff changeset
   297
cawthron
parents:
diff changeset
   298
    iObserver.ClientConnectionCanceledL( *this );
cawthron
parents:
diff changeset
   299
    }
cawthron
parents:
diff changeset
   300
cawthron
parents:
diff changeset
   301
cawthron
parents:
diff changeset
   302
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   303
// CWebClientEngine::MHFRunL()
cawthron
parents:
diff changeset
   304
// Inherited from MHTTPTransactionCallback
cawthron
parents:
diff changeset
   305
// Called by framework to pass transaction events.
cawthron
parents:
diff changeset
   306
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   307
//
cawthron
parents:
diff changeset
   308
void CWebClientEngine::MHFRunL( RHTTPTransaction aTransaction, 
cawthron
parents:
diff changeset
   309
                                const THTTPEvent& aEvent )
cawthron
parents:
diff changeset
   310
    {
cawthron
parents:
diff changeset
   311
cawthron
parents:
diff changeset
   312
    switch ( aEvent.iStatus ) 
cawthron
parents:
diff changeset
   313
        {
cawthron
parents:
diff changeset
   314
        case THTTPEvent::EGotResponseHeaders:
cawthron
parents:
diff changeset
   315
            {
cawthron
parents:
diff changeset
   316
            // HTTP response headers have been received. Use
cawthron
parents:
diff changeset
   317
            // aTransaction.Response() to get the response. However, it's not
cawthron
parents:
diff changeset
   318
            // necessary to do anything with the response when this event occurs.
cawthron
parents:
diff changeset
   319
cawthron
parents:
diff changeset
   320
            // Get HTTP status code from header (e.g. 200)
cawthron
parents:
diff changeset
   321
            RHTTPResponse resp = aTransaction.Response();
cawthron
parents:
diff changeset
   322
            TInt status = resp.StatusCode();
cawthron
parents:
diff changeset
   323
cawthron
parents:
diff changeset
   324
            // Get status text (e.g. "OK")
cawthron
parents:
diff changeset
   325
            TBuf<KMaxStatusTextLength> statusText;
cawthron
parents:
diff changeset
   326
            statusText.Copy( resp.StatusText().DesC() );
cawthron
parents:
diff changeset
   327
cawthron
parents:
diff changeset
   328
            // Display header field names and value
cawthron
parents:
diff changeset
   329
            DumpRespHeadersL( aTransaction );
cawthron
parents:
diff changeset
   330
cawthron
parents:
diff changeset
   331
            }
cawthron
parents:
diff changeset
   332
            break;
cawthron
parents:
diff changeset
   333
cawthron
parents:
diff changeset
   334
        case THTTPEvent::EGotResponseBodyData:
cawthron
parents:
diff changeset
   335
            {
cawthron
parents:
diff changeset
   336
            // Part (or all) of response's body data received. Use 
cawthron
parents:
diff changeset
   337
            // aTransaction.Response().Body()->GetNextDataPart() to get the actual
cawthron
parents:
diff changeset
   338
            // body data.
cawthron
parents:
diff changeset
   339
cawthron
parents:
diff changeset
   340
            // Get the body data supplier
cawthron
parents:
diff changeset
   341
            MHTTPDataSupplier* body = aTransaction.Response().Body();
cawthron
parents:
diff changeset
   342
            TPtrC8 dataChunk;
cawthron
parents:
diff changeset
   343
cawthron
parents:
diff changeset
   344
            // GetNextDataPart() returns ETrue, if the received part is the last 
cawthron
parents:
diff changeset
   345
            // one.
cawthron
parents:
diff changeset
   346
            TBool isLast = body->GetNextDataPart( dataChunk );
cawthron
parents:
diff changeset
   347
            iObserver.ClientBodyReceivedL( *this, dataChunk );
cawthron
parents:
diff changeset
   348
cawthron
parents:
diff changeset
   349
            // Always remember to release the body data.
cawthron
parents:
diff changeset
   350
            body->ReleaseData();
cawthron
parents:
diff changeset
   351
            }
cawthron
parents:
diff changeset
   352
            break;
cawthron
parents:
diff changeset
   353
cawthron
parents:
diff changeset
   354
        case THTTPEvent::EResponseComplete:
cawthron
parents:
diff changeset
   355
            {
cawthron
parents:
diff changeset
   356
            // Indicates that header & body of response is completely received.
cawthron
parents:
diff changeset
   357
            // No further action here needed.
cawthron
parents:
diff changeset
   358
            iObserver.ClientResponseCompleteL( *this );
cawthron
parents:
diff changeset
   359
            }
cawthron
parents:
diff changeset
   360
            break;
cawthron
parents:
diff changeset
   361
cawthron
parents:
diff changeset
   362
        case THTTPEvent::ESucceeded:
cawthron
parents:
diff changeset
   363
            {
cawthron
parents:
diff changeset
   364
            // Indicates that transaction succeeded. 
cawthron
parents:
diff changeset
   365
            iObserver.ClientTransactionSucceededL( *this );
cawthron
parents:
diff changeset
   366
cawthron
parents:
diff changeset
   367
            // Transaction can be closed now. It's not needed anymore.
cawthron
parents:
diff changeset
   368
            aTransaction.Close();
cawthron
parents:
diff changeset
   369
            iRunning = EFalse;
cawthron
parents:
diff changeset
   370
            }
cawthron
parents:
diff changeset
   371
            break;
cawthron
parents:
diff changeset
   372
cawthron
parents:
diff changeset
   373
        case THTTPEvent::EFailed:
cawthron
parents:
diff changeset
   374
            {
cawthron
parents:
diff changeset
   375
            // Transaction completed with failure. 
cawthron
parents:
diff changeset
   376
            iObserver.ClientTransactionFailedL( *this );
cawthron
parents:
diff changeset
   377
            aTransaction.Close();
cawthron
parents:
diff changeset
   378
            iRunning = EFalse;
cawthron
parents:
diff changeset
   379
            }
cawthron
parents:
diff changeset
   380
            break;
cawthron
parents:
diff changeset
   381
cawthron
parents:
diff changeset
   382
        default:
cawthron
parents:
diff changeset
   383
            // There are more events in THTTPEvent, but they are not usually 
cawthron
parents:
diff changeset
   384
            // needed. However, event status smaller than zero should be handled 
cawthron
parents:
diff changeset
   385
            // correctly since it's error.
cawthron
parents:
diff changeset
   386
            {
cawthron
parents:
diff changeset
   387
            iObserver.ClientUnknownEventL( *this, aEvent.iStatus );
cawthron
parents:
diff changeset
   388
            if ( aEvent.iStatus < 0 )
cawthron
parents:
diff changeset
   389
                {
cawthron
parents:
diff changeset
   390
                // Just close the transaction on errors
cawthron
parents:
diff changeset
   391
                aTransaction.Close();
cawthron
parents:
diff changeset
   392
                iRunning = EFalse;
cawthron
parents:
diff changeset
   393
                }
cawthron
parents:
diff changeset
   394
            }
cawthron
parents:
diff changeset
   395
            break;
cawthron
parents:
diff changeset
   396
        }
cawthron
parents:
diff changeset
   397
    }
cawthron
parents:
diff changeset
   398
cawthron
parents:
diff changeset
   399
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   400
// CWebClientEngine::MHFRunError()
cawthron
parents:
diff changeset
   401
// Inherited from MHTTPTransactionCallback
cawthron
parents:
diff changeset
   402
// Called by framework when *leave* occurs in handling of transaction event.
cawthron
parents:
diff changeset
   403
// These errors must be handled, or otherwise HTTP-CORE 6 panic is thrown.
cawthron
parents:
diff changeset
   404
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   405
//
cawthron
parents:
diff changeset
   406
TInt CWebClientEngine::MHFRunError( TInt aError, 
cawthron
parents:
diff changeset
   407
                                    RHTTPTransaction /*aTransaction*/, 
cawthron
parents:
diff changeset
   408
                                    const THTTPEvent& /*aEvent*/)
cawthron
parents:
diff changeset
   409
    {
cawthron
parents:
diff changeset
   410
    // Handle error and return KErrNone.
cawthron
parents:
diff changeset
   411
    TRAPD( err, HandleRunErrorL( aError ) );
cawthron
parents:
diff changeset
   412
    if( err )
cawthron
parents:
diff changeset
   413
        Panic( EClientEngine );
cawthron
parents:
diff changeset
   414
    return KErrNone;
cawthron
parents:
diff changeset
   415
    }
cawthron
parents:
diff changeset
   416
cawthron
parents:
diff changeset
   417
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   418
// CWebClientEngine::GetCredentialsL()
cawthron
parents:
diff changeset
   419
//
cawthron
parents:
diff changeset
   420
// Inherited from MHTTPAuthenticationCallback
cawthron
parents:
diff changeset
   421
// Called by framework when we requested authenticated page and framework 
cawthron
parents:
diff changeset
   422
// needs to know username and password.
cawthron
parents:
diff changeset
   423
// ----------------------------------------------------------------------------
cawthron
parents:
diff changeset
   424
TBool CWebClientEngine::GetCredentialsL( const TUriC8& aUri,
cawthron
parents:
diff changeset
   425
                                               RString aRealm, 
cawthron
parents:
diff changeset
   426
                                               RStringF /*aAuthenticationType*/,
cawthron
parents:
diff changeset
   427
                                               RString& aUsername, 
cawthron
parents:
diff changeset
   428
                                               RString& aPassword) 
cawthron
parents:
diff changeset
   429
    {
cawthron
parents:
diff changeset
   430
    TBuf<KMaxUserNameLength> userName;
cawthron
parents:
diff changeset
   431
    TBuf<KMaxPasswordLength> password;
cawthron
parents:
diff changeset
   432
 
cawthron
parents:
diff changeset
   433
    TBool haveCredentials = iObserver.ClientGetCredentialsL( *this, aUri, aRealm.DesC(), userName, password);
cawthron
parents:
diff changeset
   434
    if (haveCredentials)
cawthron
parents:
diff changeset
   435
    	{
cawthron
parents:
diff changeset
   436
	    // Set aUsername and aPassword
cawthron
parents:
diff changeset
   437
	    TBuf8<KMaxUserNameLength> temp;
cawthron
parents:
diff changeset
   438
	    temp.Copy( userName );
cawthron
parents:
diff changeset
   439
	    TRAPD( err, aUsername = aRealm.Pool().OpenStringL( temp ));
cawthron
parents:
diff changeset
   440
	    if ( !err ) 
cawthron
parents:
diff changeset
   441
	        {
cawthron
parents:
diff changeset
   442
	        temp.Copy( password );
cawthron
parents:
diff changeset
   443
	        TRAP( err, aPassword = aRealm.Pool().OpenStringL( temp ));
cawthron
parents:
diff changeset
   444
	        if ( !err ) return ETrue;
cawthron
parents:
diff changeset
   445
	        }
cawthron
parents:
diff changeset
   446
    	
cawthron
parents:
diff changeset
   447
    	}
cawthron
parents:
diff changeset
   448
    return EFalse;
cawthron
parents:
diff changeset
   449
    }
cawthron
parents:
diff changeset
   450