pnpmobileservices/pnpms/OnlineSupport/src/MiniBrowser.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Mini web browser for downloading settings files
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <in_sock.h>
       
    21 #include <uri8.h>
       
    22 #include <http.h>
       
    23 #include <CWPEngine.h>
       
    24 #include <commdbconnpref.h>
       
    25 #include <etelmm.h>
       
    26 #include <basched.h>            // For KLeaveExit
       
    27 #include <AknGlobalNote.h> 
       
    28 #include <avkon.rsg>            // For R_AVKON_SOFTKEYS_CLOSE
       
    29 
       
    30 #include "MiniBrowser.h"
       
    31 #include "OnlineSupportLogger.h"
       
    32 #include "NHeadWrapperParser.h"
       
    33 #include "SupportedContentTypes.h"
       
    34 #include "VersionStrings.h"
       
    35 
       
    36 // 50 secs time-out
       
    37 const TInt KTimeOut( 50000000 );
       
    38 const TInt KInitialDataBufferSize( 2048 );
       
    39 const TInt KInitialReportUrlBufferSize( 512 );
       
    40 // maximum length of the info message (currently not supported)
       
    41 //const TInt KMaxMessageLength(256);
       
    42 //_LIT( KMiniBrowserPanic, "CMiniBrowser" );
       
    43 _LIT8( KHttpProtString, "HTTP/TCP" );
       
    44 _LIT8( KNokiaHeadWrapper, "application/vnd.nokia.headwrapper" );
       
    45 
       
    46 _LIT( KAmpersand, "&" );
       
    47 _LIT( KQuestionMark, "?" );
       
    48 _LIT( KStatus, "Status=" );
       
    49 
       
    50 CMiniBrowser* CMiniBrowser::NewLC(
       
    51     MMiniBrowserObserver& aObserver,
       
    52     RSocketServ& aSockerServ,
       
    53     RConnection& aConnection )
       
    54     {
       
    55     CMiniBrowser* self = new (ELeave) CMiniBrowser( aObserver );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( aSockerServ, aConnection );
       
    58     return self;
       
    59     }
       
    60 
       
    61 CMiniBrowser* CMiniBrowser::NewL(
       
    62     MMiniBrowserObserver& aObserver,
       
    63     RSocketServ& aSockerServ,
       
    64     RConnection& aConnection )
       
    65     {
       
    66     CMiniBrowser* self = NewLC( aObserver, aSockerServ, aConnection );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 CMiniBrowser::~CMiniBrowser()
       
    72     {
       
    73     LOGSTRING( "CMiniBrowser::~CMiniBrowser" );
       
    74     if( iPeriodic->IsActive() )
       
    75         {
       
    76         iPeriodic->Cancel();
       
    77         }
       
    78 
       
    79     delete iUri;
       
    80     delete iPeriodic;
       
    81     delete iResponseData;
       
    82     delete iReportUrl;
       
    83     iTransaction.Close();
       
    84     iSession.Close();
       
    85 
       
    86     LOGSTRING( "CMiniBrowser::~CMiniBrowser - done" );
       
    87     }
       
    88 
       
    89 CMiniBrowser::CMiniBrowser( MMiniBrowserObserver& aObserver ) :
       
    90     iObserver( aObserver ),
       
    91     iContentType( EContentTypeUnknown ),
       
    92     iProvisioningStatus( THttpProvStates::EStatusUnknown )
       
    93     {
       
    94     }
       
    95 
       
    96 void CMiniBrowser::ConstructL( RSocketServ& aSockerServ, RConnection& aConnection )
       
    97     {
       
    98     LOGSTRING( "CMiniBrowser::ConstructL" );
       
    99 
       
   100     iUri = HBufC8::NewL(1);
       
   101     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   102     iResponseData = HBufC8::NewL( KInitialDataBufferSize );
       
   103     iReportUrl = HBufC8::NewL( KInitialReportUrlBufferSize );
       
   104 
       
   105     // Opens session using protocol HTTP/TCP
       
   106     LOGSTRING( "CMiniBrowser: iSession.OpenL" );
       
   107     iSession.OpenL( KHttpProtString );
       
   108     LOGSTRING( "CMiniBrowser: iSession.OpenL - done" );
       
   109     iSessionStringPool = iSession.StringPool();
       
   110 
       
   111     RHTTPConnectionInfo connectionInfo = iSession.ConnectionInfo();
       
   112 
       
   113     // Set SocketServ and Connection explicitly as we do not want to show
       
   114     // the AP selection list to the user when making submit for the request
       
   115     connectionInfo.SetPropertyL(
       
   116         iSessionStringPool.StringF( HTTP::EHttpSocketServ,
       
   117         RHTTPSession::GetTable() ),
       
   118         aSockerServ.Handle() );
       
   119     connectionInfo.SetPropertyL(
       
   120         iSessionStringPool.StringF( HTTP::EHttpSocketConnection,
       
   121         RHTTPSession::GetTable() ),
       
   122         reinterpret_cast< TInt > ( &aConnection ) );
       
   123     LOGSTRING( "CMiniBrowser::ConstructL - done" );
       
   124     }
       
   125 
       
   126 void CMiniBrowser::HttpGetL( const TDesC& aUri )
       
   127     {
       
   128     DoHttpGetL( aUri, EFalse, KNullDesC, 0 );
       
   129     }
       
   130 
       
   131 void CMiniBrowser::HttpGetL( const TDesC& aUri, const TDesC& aProxyAddress,
       
   132     const TUint aProxyPort )
       
   133     {
       
   134     DoHttpGetL( aUri, ETrue, aProxyAddress, aProxyPort );
       
   135     }
       
   136 
       
   137 void CMiniBrowser::DoHttpGetL(
       
   138     const TDesC& aUri,
       
   139     const TBool aUseProxy,
       
   140     const TDesC& aProxyAddress,
       
   141     const TUint aProxyPort )
       
   142     {
       
   143     LOGSTRING( "CMiniBrowser::DoHttpGetL" );
       
   144 
       
   145     ResetResponseDataL();
       
   146 
       
   147     delete iUri;
       
   148     iUri = 0;
       
   149     iUri = HBufC8::NewL( aUri.Length() );
       
   150     iUri->Des().Copy( aUri );
       
   151 
       
   152     TUriParser8 uriParser;
       
   153 
       
   154     // In case URL is not valid the transaction will fail with code KErrHttpInvalidUri
       
   155     // uriParser does not leave in all invalid uri cases
       
   156 #ifdef _DEBUG
       
   157     LOGSTRING( "CMiniBrowser::HttpGetL uri:" );
       
   158     //LOGTEXT( aUri );
       
   159     for( TInt i(0); i < aUri.Length(); i += 128 )
       
   160         {
       
   161         LOGTEXT( aUri.Right( aUri.Length() - i ) );
       
   162         }
       
   163 #endif
       
   164     User::LeaveIfError( uriParser.Parse( *iUri ) );
       
   165 
       
   166     RHTTPConnectionInfo connectionInfo = iSession.ConnectionInfo();
       
   167 
       
   168     // The default value is HTTP::EDoNotUseProxy
       
   169     if( aUseProxy )
       
   170         {
       
   171         LOGSTRING("CMiniBrowser: using proxy");
       
   172         connectionInfo.SetPropertyL(
       
   173             iSessionStringPool.StringF( HTTP::EProxyUsage, RHTTPSession::GetTable() ),
       
   174             iSessionStringPool.StringF( HTTP::EUseProxy, RHTTPSession::GetTable() ) );
       
   175 
       
   176         LOGSTRING("Set Proxy address")
       
   177         HBufC8* proxy = HBufC8::NewLC( aProxyAddress.Length() + 1 + 16 );
       
   178         TPtr8 proxyPtr = proxy->Des();
       
   179         proxyPtr.Copy( aProxyAddress );
       
   180         proxyPtr.Append( _L8( ":" ) );
       
   181         proxyPtr.AppendNum( aProxyPort );
       
   182         LOGTEXT( proxyPtr );
       
   183 
       
   184         RStringF proxyF = iSessionStringPool.OpenFStringL( *proxy );
       
   185         CleanupClosePushL( proxyF );
       
   186 
       
   187         connectionInfo.SetPropertyL(
       
   188             iSessionStringPool.StringF( HTTP::EProxyAddress, RHTTPSession::GetTable() ),
       
   189             proxyF );
       
   190 
       
   191         CleanupStack::PopAndDestroy(1); // proxyF.Close()
       
   192         CleanupStack::PopAndDestroy( proxy );
       
   193         }
       
   194     else
       
   195         {
       
   196         LOGSTRING("CMiniBrowser: NOT using proxy");
       
   197         connectionInfo.SetPropertyL(
       
   198             iSessionStringPool.StringF( HTTP::EProxyUsage, RHTTPSession::GetTable() ),
       
   199             iSessionStringPool.StringF( HTTP::EDoNotUseProxy, RHTTPSession::GetTable() ) );
       
   200         }
       
   201 
       
   202     LOGSTRING( "CMiniBrowser: iSession.OpenTransactionL" );
       
   203     iTransaction = iSession.OpenTransactionL( uriParser, *this,
       
   204         iSessionStringPool.StringF( HTTP::EGET, RHTTPSession::GetTable() ) );
       
   205     LOGSTRING( "CMiniBrowser: iSession.OpenTransactionL - done" );
       
   206 
       
   207 
       
   208     // Set user agent string (we have our own user agent string definition,
       
   209     // not Mozilla compatible)
       
   210     HBufC8* userAgent = NULL;
       
   211     TRAPD( err, userAgent = GetUserAgentStringL() );
       
   212     if( err != KErrNone )
       
   213         {
       
   214         LOGSTRING2( "Error in GetUserAgentStringL: %i", err );
       
   215         }
       
   216     else
       
   217         {
       
   218         CleanupStack::PushL( userAgent );
       
   219         LOGTEXT( *userAgent );
       
   220         RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();
       
   221         RStringF str = iSessionStringPool.OpenFStringL( *userAgent );
       
   222         CleanupClosePushL( str );
       
   223         headers.SetFieldL(
       
   224             iSessionStringPool.StringF( HTTP::EUserAgent, RHTTPSession::GetTable() ),
       
   225             str );
       
   226         CleanupStack::PopAndDestroy(); // str.Close()
       
   227         CleanupStack::PopAndDestroy( userAgent );
       
   228         }
       
   229 
       
   230 
       
   231     TCallBack callBack( TimeOutCallBack, this );
       
   232     if( iPeriodic->IsActive() )
       
   233         {
       
   234         iPeriodic->Cancel();
       
   235         }
       
   236     iPeriodic->Start( KTimeOut, KTimeOut, callBack );
       
   237 
       
   238     iTransaction.SubmitL();
       
   239     LOGSTRING( "CMiniBrowser::HttpGetL - done" );
       
   240     }
       
   241 
       
   242 HBufC8* CMiniBrowser::GetUserAgentStringL()
       
   243     {
       
   244     LOGSTRING("CMiniBrowser::GetUserAgentStringL");
       
   245 
       
   246     _LIT8( KUserAgentName, "OnlineSupport");
       
   247     _LIT8( KSlash, "/");
       
   248     _LIT8( KSpace, " ");
       
   249     _LIT8( KSymbianOS, "SymbianOS");
       
   250     _LIT8( KS60, "Series60");
       
   251     _LIT8( KQuestionMark, "?" );
       
   252     _LIT( KPhoneModuleName, "Phonetsy.tsy");
       
   253     _LIT( KPhoneName, "DefaultPhone");
       
   254     const TChar lineFeedChar( 0xA );
       
   255 
       
   256     RTelServer telServer;
       
   257     User::LeaveIfError( telServer.Connect() );
       
   258     CleanupClosePushL( telServer );
       
   259     User::LeaveIfError( telServer.LoadPhoneModule( KPhoneModuleName ) );
       
   260     RMobilePhone phone;
       
   261     User::LeaveIfError( phone.Open( telServer, KPhoneName ) );
       
   262     CleanupClosePushL( phone );
       
   263     LOGSTRING("CMiniBrowser::GetUserAgentStringL 2");
       
   264 
       
   265     RMobilePhone::TMobilePhoneIdentityV1 phoneIdentity;
       
   266     TRequestStatus status( KRequestPending );
       
   267     phone.GetPhoneId( status, phoneIdentity );
       
   268     User::WaitForRequest( status );
       
   269 
       
   270 
       
   271     // parse sw version from the string
       
   272     // sw version is assumed to be string between first "V" and "\n"
       
   273     LOGSTRING("Reading sw version info");
       
   274     TBuf<KSysUtilVersionTextLength> versions;
       
   275     User::LeaveIfError( SysUtil::GetSWVersion( versions ) );
       
   276     LOGTEXT( versions );
       
   277 
       
   278     // SW version
       
   279     LOGSTRING("Locating sw version from the string");
       
   280     TInt begin(0);
       
   281     TInt len(0);
       
   282     // Assume sw version is in the first row (use line feed as a token separator)
       
   283     TBuf8<KSysUtilVersionTextLength> sw;
       
   284     TVersionStrings::TokenLocationL( versions, lineFeedChar, 0, sw.MaxLength(), begin, len );
       
   285     if( len <= 2 )
       
   286         {
       
   287         User::Leave( KErrNotFound );
       
   288         }
       
   289 
       
   290     _LIT(KVerStrStart,"V ");
       
   291     TInt pos1 = versions.Find(KVerStrStart);
       
   292     if (pos1 != KErrNotFound)
       
   293         {
       
   294         sw.Copy( versions.Mid( begin + 2, len - 2 ) ); // remove "V "
       
   295         }
       
   296     else
       
   297         {
       
   298         // SW version does not always start with "V "
       
   299         sw.Copy( versions.Mid( begin, len ) );
       
   300         }
       
   301     
       
   302     LOGTEXT( sw );
       
   303 
       
   304 
       
   305     // Series 60 and Symbian OS versions
       
   306     LOGSTRING("Reading OS versions");
       
   307     TVersionBuf s60Version;
       
   308     s60Version.Copy( KQuestionMark );
       
   309     TVersionBuf symbianVersion;
       
   310     symbianVersion.Copy( KQuestionMark );
       
   311     TRAPD( err, TVersionStrings::GetUserAgentVersionsL( s60Version, symbianVersion ) );
       
   312     if( err != KErrNone )
       
   313         {
       
   314         LOGSTRING2( "Error: %i", err );
       
   315         }
       
   316 
       
   317     LOGSTRING("Series60 version");
       
   318     LOGTEXT( s60Version );
       
   319     LOGSTRING("SymbianOS version");
       
   320     LOGTEXT( symbianVersion );
       
   321 
       
   322 
       
   323     LOGSTRING("CMiniBrowser::GetUserAgentStringL 3");
       
   324     // The string is of format:
       
   325     // OnlineSupport <manufacturer><model>/<sw> SymbianOS/<symbian_os_version> S60/<S60_version>
       
   326     HBufC8* agent = HBufC8::NewLC(
       
   327         KUserAgentName().Length() +
       
   328         phoneIdentity.iManufacturer.Length() +
       
   329         phoneIdentity.iModel.Length() +
       
   330         sw.Length() +
       
   331         KSymbianOS().Length() +
       
   332         symbianVersion.Length() +
       
   333         KS60().Length() +
       
   334         s60Version.Length() +
       
   335         3 * KSlash().Length() +      /* three slasles in the string */
       
   336         3 * KSpace().Length()        /* three spaces in the string */
       
   337         );
       
   338     LOGSTRING("CMiniBrowser::GetUserAgentStringL 3.5");
       
   339     TPtr8 agentPtr = agent->Des();
       
   340     agentPtr.Append( KUserAgentName );
       
   341     agentPtr.Append( KSpace);
       
   342     agentPtr.Append( phoneIdentity.iManufacturer );
       
   343     agentPtr.Append( phoneIdentity.iModel );
       
   344     agentPtr.Append( KSlash );
       
   345     agentPtr.Append( sw );
       
   346     agentPtr.Append( KSpace);
       
   347     agentPtr.Append( KSymbianOS );
       
   348     agentPtr.Append( KSlash);
       
   349     agentPtr.Append( symbianVersion );
       
   350     agentPtr.Append( KSpace);
       
   351     agentPtr.Append( KS60 );
       
   352     agentPtr.Append( KSlash);
       
   353     agentPtr.Append( s60Version );
       
   354 
       
   355     LOGSTRING("CMiniBrowser::GetUserAgentStringL 4");
       
   356     CleanupStack::Pop( agent );
       
   357     CleanupStack::PopAndDestroy(); // phone.Close()
       
   358     CleanupStack::PopAndDestroy(); // telServer.Close()
       
   359     LOGSTRING("CMiniBrowser::GetUserAgentStringL - done");
       
   360     return agent;
       
   361     }
       
   362 
       
   363 
       
   364 TInt CMiniBrowser::TimeOutCallBack( TAny* aMiniBrowser)
       
   365     {
       
   366     TRAPD( err, ( ( CMiniBrowser* ) aMiniBrowser )->DoTimeOutCallBackL() );
       
   367     if( err == KLeaveExit )
       
   368         {
       
   369         User::Leave( KLeaveExit );
       
   370         }
       
   371     return err;
       
   372     }
       
   373 
       
   374 void CMiniBrowser::DoTimeOutCallBackL()
       
   375     {
       
   376     LOGSTRING( "CMiniBrowser::DoTimeOutCallBackL" );
       
   377     if( iPeriodic->IsActive() )
       
   378         {
       
   379         iPeriodic->Cancel();
       
   380         }
       
   381 
       
   382     TRAPD( err, iObserver.MiniBrowserErrorL( KErrTimedOut ) );
       
   383     if( err != KErrNone )
       
   384         {
       
   385         iObserver.MiniBrowserUnhandledLeave( err );
       
   386         }
       
   387     if( err == KLeaveExit )
       
   388         {
       
   389         User::Leave( err ); 
       
   390         }
       
   391 
       
   392     LOGSTRING( "CMiniBrowser::DoTimeOut - done" );
       
   393     }
       
   394 
       
   395 void CMiniBrowser::MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent &aEvent )
       
   396     {
       
   397     LOGSTRING( "CMiniBrowser::MHFRunL" );
       
   398     if( iPeriodic->IsActive() )
       
   399         {
       
   400         iPeriodic->Cancel();
       
   401         }
       
   402 
       
   403     switch( aEvent.iStatus )
       
   404         {
       
   405         case THTTPEvent::ESubmit:
       
   406             {
       
   407             LOGSTRING( "CMiniBrowser::MHFRunL:ESubmit" );
       
   408             LOGTEXT( aTransaction.Request().URI().UriDes() );
       
   409 
       
   410             LOGSTRING( "CMiniBrowser: reset ResponseData" );
       
   411             ResetResponseDataL();
       
   412             break;
       
   413             }
       
   414         case THTTPEvent::EGotResponseHeaders:
       
   415             {
       
   416             LOGSTRING( "CMiniBrowser::MHFRunL:EGotResponseHeaders" );
       
   417             THTTPHdrVal value;
       
   418             TInt err = aTransaction.Response().GetHeaderCollection().GetField(
       
   419                 iSessionStringPool.StringF( HTTP::EContentType, RHTTPSession::GetTable() ), 0, value );
       
   420 
       
   421             if( err == KErrNone )
       
   422             {
       
   423                 LOGSTRING("Content type:");
       
   424                 const TDesC8& contentType = value.StrF().DesC();
       
   425                 LOGTEXT( contentType );
       
   426                 if( contentType.Compare( KNokiaHeadWrapper ) == 0 )
       
   427                     {
       
   428                     iContentType = EContentTypeNokiaHeadWrapper;
       
   429                     }
       
   430                 else
       
   431                     {
       
   432                     iContentType = EContentTypeUnknown;
       
   433                     }
       
   434             }
       
   435 
       
   436             TCallBack callBack( TimeOutCallBack, this );
       
   437             if( iPeriodic->IsActive() )
       
   438                 {
       
   439                 iPeriodic->Cancel();
       
   440                 }
       
   441             iPeriodic->Start( KTimeOut, KTimeOut, callBack );
       
   442             break;
       
   443             }
       
   444         case THTTPEvent::EGotResponseBodyData:
       
   445             {
       
   446             LOGSTRING( "CMiniBrowser::MHFRunL:EGotResponseBodyData" );
       
   447             MHTTPDataSupplier* pBody = aTransaction.Response().Body();
       
   448             if( pBody )
       
   449                 {
       
   450                 TPtrC8 dataChunk;
       
   451                 pBody->GetNextDataPart( dataChunk );
       
   452                 // Log
       
   453                 LOGSTRING( "CMiniBrowser: MHTTPDataSupplier:" );
       
   454 #ifdef _DEBUG
       
   455                 for( TInt i(0); i < dataChunk.Length(); i += 128 )
       
   456                     {
       
   457                     LOGTEXT( dataChunk.Right( dataChunk.Length() - i ) );
       
   458                     }
       
   459 #endif
       
   460                 AppendResponseDataL( dataChunk );
       
   461                 pBody->ReleaseData();
       
   462                 }
       
   463             LOGSTRING( "CMiniBrowser::MHFRunL:EGotResponseBodyData - 2" );
       
   464 
       
   465             TCallBack callBack( TimeOutCallBack, this );
       
   466             if( iPeriodic->IsActive() )
       
   467                 {
       
   468                 iPeriodic->Cancel();
       
   469                 }
       
   470             iPeriodic->Start( KTimeOut, KTimeOut, callBack );
       
   471             break;
       
   472             }
       
   473         case THTTPEvent::EResponseComplete:
       
   474             {
       
   475             LOGSTRING( "CMiniBrowser::MHFRunL:EResponseComplete" );
       
   476             break;
       
   477             }
       
   478         case THTTPEvent::ESucceeded:
       
   479             {
       
   480             LOGSTRING( "CMiniBrowser::MHFRunL:ESucceeded" );
       
   481 
       
   482             if( iContentType == EContentTypeNokiaHeadWrapper )
       
   483                 {
       
   484                 TRAPD( err, ParseAndSaveProvisionedSettingsL() );
       
   485                 if( err != THttpProvStates::EStatusOk )
       
   486                     {
       
   487                     User::Leave( err );
       
   488                     }
       
   489                 }
       
   490             else if( iContentType == EContentTypeUnknown )
       
   491                 {
       
   492                 TRAPD( err, ParseAndSaveProvisionedSettingsL() );
       
   493                 if( err != THttpProvStates::EStatusOk )
       
   494                     {
       
   495                     User::Leave( err );
       
   496                     }
       
   497                 }
       
   498             iObserver.MiniBrowserRequestDoneL();
       
   499             }
       
   500             break;
       
   501         case THTTPEvent::EFailed:
       
   502             LOGSTRING( "CMiniBrowser::MHFRunL:EFailed" );
       
   503             ResetResponseDataL();
       
   504             User::Leave( KErrGeneral );
       
   505             break;
       
   506         default:
       
   507             {
       
   508             LOGSTRING2( "CMiniBrowser::MHFRunL:event: %i", aEvent.iStatus );
       
   509             break;
       
   510             }
       
   511         }
       
   512 
       
   513     LOGSTRING( "CMiniBrowser::MHFRunL - done" );
       
   514     }
       
   515 
       
   516 // currently not supported
       
   517 //void CMiniBrowser::ShowMessageDialogL( const TDesC8& aMessage )
       
   518 //    {
       
   519 //    LOGSTRING( "ShowMessageDialogL" );
       
   520 //    LOGTEXT( aMessage );
       
   521 //    TInt length = aMessage.Length();
       
   522 //    if( length > KMaxMessageLength )
       
   523 //        {
       
   524 //        length = KMaxMessageLength;
       
   525 //        }
       
   526 //    HBufC* message = HBufC::NewLC( length );
       
   527 //    message->Des().Copy( aMessage.Left( length ) );
       
   528 //
       
   529 //    CAknGlobalNote* globalNote = CAknGlobalNote::NewL();
       
   530 //    CleanupStack::PushL( globalNote );
       
   531 //    globalNote->SetSoftkeys( R_AVKON_SOFTKEYS_CLOSE );
       
   532 //    globalNote->ShowNoteL( EAknGlobalInformationNote , *message );
       
   533 //
       
   534 //    LOGSTRING( "deleting globalNote" );
       
   535 //    CleanupStack::PopAndDestroy( globalNote );
       
   536 //    CleanupStack::PopAndDestroy( message );
       
   537 //    LOGSTRING( "ShowMessageDialogL - done" );
       
   538 //    }
       
   539 
       
   540 
       
   541 void CMiniBrowser::ParseAndSaveProvisionedSettingsL()
       
   542     {
       
   543     LOGSTRING( "CMiniBrowser::ParseAndSaveProvisionedSettingsL - begin" );
       
   544     if( !iResponseData )
       
   545         {
       
   546         User::Leave( THttpProvStates::EStatusWrapperParsingFailed );
       
   547         }
       
   548     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - 2" );
       
   549     CNHeadWrapperParser* NHwrParser = CNHeadWrapperParser::NewL( *iResponseData );
       
   550     CleanupStack::PushL( NHwrParser );
       
   551     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - 3" );
       
   552     iProvisioningStatus = NHwrParser->Parse();
       
   553     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - 4" );
       
   554     if( iProvisioningStatus != THttpProvStates::EStatusOk )
       
   555         {
       
   556         LOGSTRING2( "status from parse:%i", iProvisioningStatus ); 
       
   557         // Try to get report url anyways, this should succeed at leat in case
       
   558         // Nokia HeadWrapper authentication failed while parsing an otherwise valid
       
   559         // HeadWrapper document
       
   560         GetReportUrlL( *NHwrParser );
       
   561         User::Leave( iProvisioningStatus );
       
   562         }
       
   563     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - 5" );
       
   564     GetReportUrlL( *NHwrParser );
       
   565     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - 6" );
       
   566     // Get provisioned data
       
   567     TPtrC8 content;
       
   568     TRAPD( err, content.Set( NHwrParser->GetContentL() ) );
       
   569     if( err != KErrNone )
       
   570         {
       
   571         LOGSTRING2( "err from GetContentL:%i", err );
       
   572         iProvisioningStatus = THttpProvStates::EStatusDocumentParsingFailed;
       
   573         User::Leave( err );
       
   574         }
       
   575 
       
   576     LOGSTRING( "Response parsed" ); 
       
   577 
       
   578     TPtrC8 contentType;
       
   579     TRAP( err, contentType.Set( NHwrParser->GetContentTypeL() ) );
       
   580     if( err != KErrNone )
       
   581         {
       
   582         LOGSTRING2( "err from GetContentTypeL:%i", err );
       
   583         iProvisioningStatus = THttpProvStates::EStatusDocumentParsingFailed;
       
   584         User::Leave( err );
       
   585         }
       
   586 
       
   587     if( contentType.Compare( KContentTypeApplicationWapConnectivityWbxml ) == 0 )
       
   588         {
       
   589         LOGSTRING( "CMiniBrowser: content type application/vnd.wap.connectivity-wbxml" );
       
   590         TRAP( err, SaveProvisionedSettingsL( content ) );
       
   591         iProvisioningStatus = (THttpProvStates::TProvisioningStatus) err;
       
   592         if( iProvisioningStatus != THttpProvStates::EStatusOk )
       
   593             {
       
   594             LOGSTRING2( "ProvisioningStatus from SaveProvisionedSettingsL:%i", iProvisioningStatus ); 
       
   595             User::Leave( iProvisioningStatus );
       
   596             }
       
   597         }
       
   598 // currently not supported
       
   599 //    else if( contentType.Compare( KContentTypeTextPlain ) == 0 )
       
   600 //        {
       
   601 //        LOGSTRING( "CMiniBrowser: content type text/plain" );
       
   602 //        ShowMessageDialogL( content );
       
   603 //        }
       
   604     else
       
   605         {
       
   606         LOGSTRING( "CMiniBrowser: Unknown content type" );
       
   607         User::Leave( THttpProvStates::EStatusWrapperParsingFailed );
       
   608         }
       
   609 
       
   610     CleanupStack::PopAndDestroy( NHwrParser );
       
   611     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL - done" );
       
   612     }
       
   613 
       
   614 void CMiniBrowser::GetReportUrlL( const CNHeadWrapperParser& aNHwrParser )
       
   615     {
       
   616     LOGSTRING( "CMiniBrowser::GetReportUrlL - begin" );
       
   617     // Store report URL for later reference
       
   618     const TDesC8& reportUrl = aNHwrParser.GetReportUrlL();
       
   619     if( iReportUrl->Des().MaxLength() < reportUrl.Length() )
       
   620         {
       
   621         delete iReportUrl;
       
   622         iReportUrl = 0;
       
   623         iReportUrl = HBufC8::NewL( reportUrl.Length() );
       
   624         }
       
   625     TPtr8 reportUrlPtr = iReportUrl->Des();
       
   626     reportUrlPtr.Copy( reportUrl );
       
   627     LOGTEXT( *iReportUrl );
       
   628     LOGSTRING( "CMiniBrowser::GetReportUrlL - end" );
       
   629     }
       
   630 
       
   631 HBufC* CMiniBrowser::GetReportUrlLC()
       
   632     {
       
   633     LOGSTRING( "CMiniBrowser::GetReportUrlLC - begin" );
       
   634     if( iReportUrl && iReportUrl->Length() )
       
   635         {
       
   636         HBufC* url = HBufC::NewLC(
       
   637             iReportUrl->Length() +
       
   638             KAmpersand().Length() +
       
   639             KQuestionMark().Length() +
       
   640             KStatus().Length() );
       
   641 
       
   642         TPtr urlPtr = url->Des();
       
   643         urlPtr.Copy( *iReportUrl );
       
   644 
       
   645         // Add provisioning status to the url if known
       
   646         if( iProvisioningStatus != THttpProvStates::EStatusUnknown )
       
   647             {
       
   648             // Assume there might already be parameters in the URL given
       
   649             if( urlPtr.Find( KQuestionMark ) != KErrNotFound )
       
   650                 {
       
   651                 urlPtr.Append( KAmpersand );
       
   652                 }
       
   653             else
       
   654                 {
       
   655                 urlPtr.Append( KQuestionMark );
       
   656                 }
       
   657             urlPtr.Append( KStatus );
       
   658             urlPtr.AppendNum( (TInt) iProvisioningStatus );
       
   659             }
       
   660         LOGSTRING( "CMiniBrowser::GetReportUrlLC - end" );
       
   661         return url;
       
   662         }
       
   663     else
       
   664         {
       
   665         LOGSTRING( "CMiniBrowser::GetReportUrlLC Leave KErrNotFound" );
       
   666         User::Leave( KErrNotFound );
       
   667         }
       
   668     return NULL; // Not possible to end up here
       
   669     }
       
   670 
       
   671 void CMiniBrowser::SaveProvisionedSettingsL( const TDesC8& aContent )
       
   672     {
       
   673     LOGSTRING( "CMiniBrowser::SaveProvisionedSettingsL" );
       
   674     TInt status = THttpProvStates::EStatusOk;
       
   675     // Create WPEngine
       
   676     CWPEngine* wpengine = CWPEngine::NewL();
       
   677     CleanupStack::PushL( wpengine );
       
   678 
       
   679     LOGSTRING( "wpengine->ImportDocumentL" );   
       
   680     TRAPD( err, wpengine->ImportDocumentL( aContent ) );
       
   681     User::LeaveIfError( err );
       
   682 
       
   683     LOGSTRING( "wpengine->PopulateL" );
       
   684     TRAP( err, wpengine->PopulateL() );
       
   685     if( err != KErrNone )
       
   686         {
       
   687         LOGSTRING2( "PopulateL err: %i", err );
       
   688         User::Leave( err );
       
   689         }
       
   690     LOGSTRING( "wpengine->PopulateL success" );
       
   691 
       
   692     TInt itemCount = wpengine->ItemCount();
       
   693     // Empty messages are not supported
       
   694     if( itemCount == 0 )
       
   695         {
       
   696         LOGSTRING("No items in provisioning message!");
       
   697         User::Leave( THttpProvStates::EStatusWrapperParsingFailed );
       
   698         }
       
   699 
       
   700     for( TInt i(0); i < itemCount; i++ )
       
   701         {
       
   702         LOGSTRING( "Saving" );
       
   703         TRAP( err, wpengine->SaveL( i ) );
       
   704         if( wpengine->CanSetAsDefault( i ) )
       
   705             {
       
   706             LOGSTRING( "Setting as default" );
       
   707             TRAP( err, wpengine->SetAsDefaultL( i ) );
       
   708             }
       
   709         else
       
   710             {
       
   711             LOGSTRING( "Cannot set as default" );
       
   712             }
       
   713         if( err != KErrNone )
       
   714             {
       
   715             LOGSTRING2( "Error while saving: %i", err );
       
   716             status = THttpProvStates::EStatusStorageFailed;
       
   717             }
       
   718         }
       
   719 
       
   720     if( status != THttpProvStates::EStatusOk )
       
   721         {
       
   722         User::Leave( status );
       
   723         }
       
   724     }
       
   725 
       
   726 TInt CMiniBrowser::MHFRunError( TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/ )
       
   727     {
       
   728     LOGSTRING2( "CMiniBrowser::MHFRunError %i", aError );
       
   729     iTransaction.Close();
       
   730     TRAPD( err, iObserver.MiniBrowserErrorL( aError ) );
       
   731     if( err != KErrNone )
       
   732         {
       
   733         iObserver.MiniBrowserUnhandledLeave( err );
       
   734         }
       
   735     LOGSTRING( "CMiniBrowser::MHFRunError - done" );
       
   736     if( err == KLeaveExit )
       
   737         {
       
   738         return err;
       
   739         }
       
   740     return KErrNone;
       
   741     }
       
   742 
       
   743 
       
   744 void CMiniBrowser::AppendResponseDataL( const TDesC8& aData )
       
   745     {
       
   746     LOGSTRING( "CMiniBrowser::AppendResponseDataL()" );
       
   747     if( ( iResponseData->Des().MaxLength() - iResponseData->Length() ) < aData.Length() )
       
   748         {
       
   749         // ReAlloc
       
   750         HBufC8* tempBuf = HBufC8::NewL( iResponseData->Length() + aData.Length() );
       
   751         TPtr8 tempBufPtr = tempBuf->Des();
       
   752         tempBufPtr.Append( *iResponseData );
       
   753         delete iResponseData;
       
   754         iResponseData = tempBuf; 
       
   755         }
       
   756 
       
   757     TPtr8 ptr = iResponseData->Des();
       
   758     ptr.Append( aData );
       
   759     LOGSTRING( "CMiniBrowser::AppendResponseDataL() - done" );
       
   760     }
       
   761 
       
   762 void CMiniBrowser::ResetResponseDataL()
       
   763     {
       
   764     LOGSTRING( "CMiniBrowser::ResetResponseDataL()" );
       
   765     if( iResponseData && iResponseData->Length() )
       
   766         {
       
   767         delete iResponseData;
       
   768         iResponseData = 0;
       
   769         iResponseData = HBufC8::NewL( KInitialDataBufferSize );
       
   770         }
       
   771     if( iReportUrl && iReportUrl->Length() )
       
   772         {
       
   773         delete iReportUrl;
       
   774         iReportUrl = 0;
       
   775         iReportUrl = HBufC8::NewL( KInitialReportUrlBufferSize );
       
   776         }
       
   777     iContentType = EContentTypeUnknown;
       
   778     iProvisioningStatus = THttpProvStates::EStatusUnknown;
       
   779     LOGSTRING( "CMiniBrowser::ResetResponseDataL() - done" );
       
   780     }
       
   781 
       
   782 TBool CMiniBrowser::GetNextDataPart( TPtrC8 &aDataPart )
       
   783     {
       
   784     _LIT8( KEmpty, "");
       
   785     aDataPart.Set( KEmpty() );
       
   786     return ETrue;
       
   787     }
       
   788 
       
   789 void CMiniBrowser::ReleaseData()
       
   790     {
       
   791     }
       
   792 
       
   793 TInt CMiniBrowser::OverallDataSize()
       
   794     {
       
   795     return KErrNotFound;
       
   796     }
       
   797 
       
   798 TInt CMiniBrowser::Reset()
       
   799     {
       
   800     return KErrNone;
       
   801     }