satengine/SatServer/Commands/LaunchBrowserCmd/src/CLaunchBrowserHandler.cpp
changeset 0 ff3b6d0fd310
child 6 1b9ee3c7442d
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Handles LaunchBrowser command
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <MSatShellController.h>
       
    20 #include    <cmmanager.h>
       
    21 #include    <cmconnectionmethod.h>
       
    22 #include    <cmconnectionmethoddef.h>
       
    23 #include    <cmpluginpacketdatadef.h>
       
    24 #include    <cmdestination.h>
       
    25 
       
    26 #include    "MSatApi.h"
       
    27 #include    "MSatUtils.h"
       
    28 #include    "MSatUiSession.h"
       
    29 #include    "SatSOpcodes.h"
       
    30 #include    "MSatSUiClientHandler.h"
       
    31 #include    "CLaunchBrowserHandler.h"
       
    32 #include    "SatLog.h"
       
    33 #include    "MSatSystemState.h"
       
    34 
       
    35 // The pause constant for checking if BrowserApp has exited.
       
    36 // This value may be adjusted to ensure the time sequence
       
    37 const TInt KSatSShortLoopTimeout = 800000; //0.8 sec
       
    38 
       
    39 // How many times the browser status is checked, when waiting for
       
    40 // browser shutdown. Total time
       
    41 // used to check the exiting of browser app is
       
    42 // KSatSWaitCount * KSatSShortLoopTimeout.
       
    43 const TInt KSatSWaitCount = 10;
       
    44 
       
    45 // Invalid PDP type
       
    46 const TInt KSatInvalidPdpType = -1;
       
    47 
       
    48 #ifdef _DEBUG
       
    49 // Class name for error information.
       
    50 //lint -e752 Accessed in __ASSERT_DEBUG, but lint will not notice it.
       
    51 _LIT( KLaunchBrowserHandlerName, "CLaunchBrowserHandler" );
       
    52 #endif
       
    53 
       
    54 const TInt KSatMaxIPv4AddressLength( 15 );
       
    55 const TInt KSatMaxIPv6AddressLength( 39 );
       
    56 const TInt KSatMinIPv4AddressLength( 7 );
       
    57 const TInt KSatMinIPv6AddressLength( 7 );
       
    58 const TInt KSatMaxIPv4SegmentCounter( 3 );
       
    59 const TInt KSatMaxIPv4SegmentLength( 3 );
       
    60 const TInt KSatIPv4Broadcast( 255 );
       
    61 const TInt KSatIPv4Network( 0 );
       
    62 const TInt KSatMaxIPv6SegmentCounter( 7 );
       
    63 const TInt KSatMaxIPv6SegmentLength( 4 );
       
    64 const TUint32 KSatLaunchBrowserProxyPortNumber( 80 );
       
    65 const TUint32 KSatMaxProxyPortNumber( 9999 );
       
    66 const TUint32 KSatMinProxyPortNumber( 0 );
       
    67 // Granularity for getting connection methods from CM session
       
    68 const TUint32 KSatCMGranularity( 5 );
       
    69 
       
    70 _LIT( KSatAccessPointName, "SAT Launch Browser" );
       
    71 _LIT( KSatGprsAccessPointName, "internet" );
       
    72 _LIT( KSatIPv4Delimiter, "." );
       
    73 _LIT( KSatIPv6Delimiter, ":" );
       
    74 
       
    75 // ======== MEMBER FUNCTIONS ========
       
    76 // -----------------------------------------------------------------------------
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CLaunchBrowserHandler* CLaunchBrowserHandler::NewL( MSatUtils* aUtils )
       
    81     {
       
    82     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::NewL calling" )
       
    83 
       
    84     CLaunchBrowserHandler* self = new( ELeave ) CLaunchBrowserHandler;
       
    85 
       
    86     CleanupStack::PushL( self );
       
    87     self->BaseConstructL( aUtils );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90 
       
    91     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::NewL exiting" )
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // Destructor.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CLaunchBrowserHandler::~CLaunchBrowserHandler()
       
   101     {
       
   102     LOG( SIMPLE,
       
   103         "LAUNCHBROWSER: CLaunchBrowserHandler::~CSatSLaunchBrowserHandler \
       
   104         calling" )
       
   105 
       
   106     if ( iAfterWait.IsStarted() )
       
   107         {
       
   108         iAfterWait.AsyncStop();
       
   109         }
       
   110 
       
   111     if ( iAfterTimer )
       
   112         {
       
   113         iAfterTimer->Cancel();
       
   114         delete iAfterTimer;
       
   115         iAfterTimer = NULL;
       
   116         }
       
   117 
       
   118     iWsSession.Close();
       
   119 
       
   120     Cancel();
       
   121 
       
   122     LOG( SIMPLE,
       
   123         "LAUNCHBROWSER: CLaunchBrowserHandler::~CSatSLaunchBrowserHandler \
       
   124         exiting" )
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // From class MSatCommand.
       
   129 // Response from the client.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CLaunchBrowserHandler::ClientResponse()
       
   133     {
       
   134     LOG( SIMPLE,
       
   135         "LAUNCHBROWSER: CLaunchBrowserHandler::ClientResponse calling" )
       
   136 
       
   137     // TPCmdResult
       
   138     iLaunchBrowserRsp.iGeneralResult = RSat::KLaunchBrowserError;
       
   139 
       
   140     // TAdditionalInfoType
       
   141     iLaunchBrowserRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   142     iLaunchBrowserRsp.iAdditionalInfo.Zero();
       
   143     iLaunchBrowserRsp.SetPCmdNumber( iLaunchBrowserData.PCmdNumber() );
       
   144 
       
   145     // Perform the action that we just queried the user for.
       
   146     if ( iQueryRsp.iAccepted )
       
   147         {
       
   148         // Launch the Browser.
       
   149         TRAPD( err, LaunchBrowserL() );
       
   150         if ( KErrNone != err )
       
   151             {
       
   152             iLaunchBrowserRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   153             LOG2( SIMPLE, "LAUNCHBROWSER: \
       
   154                 CLaunchBrowserHandler::ClientResponse error: %i", err )
       
   155             }
       
   156         else
       
   157             {
       
   158             LOG( SIMPLE,
       
   159                 "LAUNCHBROWSER: CLBH::CR ESetUpMenuRequested registered" )
       
   160             TRAP_IGNORE( iUtils->RegisterL(
       
   161                 this, MSatUtils::ESetUpMenuRequested ) )
       
   162             }
       
   163         }
       
   164     else // User denied this action
       
   165         {
       
   166         iLaunchBrowserRsp.iGeneralResult = RSat::KPCmdNotAcceptedByUser;
       
   167         LOG( SIMPLE, "LAUNCHBROWSER: \
       
   168             CLaunchBrowserHandler::ClientResponse not accepted" )
       
   169         if ( iQueryRsp.iSessionTerminatedByUser )
       
   170             {
       
   171             LOG( SIMPLE, "LAUNCHBROWSER: \
       
   172                  CLaunchBrowserHandler::ClientResponse close ui session" )
       
   173             // Next SimSession end will close the ui session
       
   174             iUtils->NotifyEvent( MSatUtils::ESessionTerminatedByUser );
       
   175             }
       
   176         }
       
   177         
       
   178     // If command had icon data and was done succesfully, report that icon
       
   179     // was not shown
       
   180     // To be removed when icons are allowed in this command
       
   181     if ( ( RSat::KSuccess == iLaunchBrowserRsp.iGeneralResult ) &&
       
   182         iIconCommand )
       
   183         {
       
   184         LOG( SIMPLE, "LAUNCHBROWSER: \
       
   185                  CLaunchBrowserHandler::ClientResponse icon not display" )
       
   186         iLaunchBrowserRsp.iGeneralResult =
       
   187             RSat::KSuccessRequestedIconNotDisplayed;
       
   188         }
       
   189 
       
   190     TerminalRsp( RSat::ELaunchBrowser, iLaunchBrowserRspPckg );
       
   191 
       
   192     LOG( SIMPLE,
       
   193         "LAUNCHBROWSER: CLaunchBrowserHandler::ClientResponse exiting" )
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // From class CSatCommandHandler.
       
   198 // Event notification
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CLaunchBrowserHandler::Event( TInt aEvent )
       
   202     {
       
   203     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::Event calling" )
       
   204 
       
   205     switch ( aEvent )
       
   206         {
       
   207         // SetUpMenu is listening by SAT Client.
       
   208         case MSatUtils::ESetUpMenuRequested:
       
   209             {
       
   210             LOG( NORMAL,
       
   211                 "LAUNCHBROWSER::Event ESetUpMenuRequested catched and unreg" )
       
   212             iUtils->UnregisterEvent( this, MSatUtils::ESetUpMenuRequested );
       
   213             // Browser is brought to the top after short period of time.
       
   214             iUtils->SatUiHandler().ShellController().
       
   215                 BringBrowserToForegroundAfterPeriod();
       
   216             break;
       
   217             }
       
   218 
       
   219         default:
       
   220             {
       
   221             LOG2( NORMAL, "LAUNCHBROWSER:   Unexpected event: %i", aEvent )
       
   222             CSatCommandHandler::Event( aEvent );
       
   223             }
       
   224         }
       
   225 
       
   226     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::Event exiting" )
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // From class CActive.
       
   231 // Cancels the sat request.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CLaunchBrowserHandler::DoCancel()
       
   235     {
       
   236     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::DoCancel calling" )
       
   237 
       
   238     iUtils->USatAPI().NotifyLaunchBrowserCancel();
       
   239 
       
   240     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::DoCancel exiting" )
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // From class CSatCommandHandler.
       
   245 // Requests the command notification.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CLaunchBrowserHandler::IssueUSATRequest( TRequestStatus& aStatus )
       
   249     {
       
   250     LOG( SIMPLE,
       
   251         "LAUNCHBROWSER: CLaunchBrowserHandler::IssueUSATRequest calling" )
       
   252 
       
   253     // Clear the IPC package.
       
   254     new (&iLaunchBrowserData) RSat::TLaunchBrowserV2();
       
   255     iQueryRsp.iAccepted = EFalse; // default
       
   256 
       
   257     iUtils->USatAPI().NotifyLaunchBrowser( aStatus, iLaunchBrowserPckg );
       
   258 
       
   259     LOG( SIMPLE,
       
   260         "LAUNCHBROWSER: CLaunchBrowserHandler::IssueUSATRequest exiting" )
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // From class CSatCommandHandler.
       
   265 // Precheck before executing the command.
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 TBool CLaunchBrowserHandler::CommandAllowed()
       
   269     {
       
   270     LOG( SIMPLE,
       
   271         "LAUNCHBROWSER: CLaunchBrowserHandler::CommandAllowed calling" )
       
   272 
       
   273     iLaunchBrowserRsp.iGeneralResult = RSat::KLaunchBrowserError;
       
   274     iLaunchBrowserRsp.iInfoType = RSat::KNoAdditionalInfo;
       
   275     iLaunchBrowserRsp.iAdditionalInfo.Zero();
       
   276 
       
   277     RMobilePhone::TMobilePhoneRegistrationStatus registrationStatus(
       
   278         iUtils->SystemState().GetNetworkRegistrationStatus() );
       
   279 
       
   280     TBool commandAllowed( ETrue );
       
   281 
       
   282     if ( RSat::EBrowserIdNotSpecified == iLaunchBrowserData.iBrowserId )
       
   283         {
       
   284         // When get unknown browser id, such as RFU value, return
       
   285         // terminal response of command not understood.
       
   286         iLaunchBrowserRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   287         commandAllowed = EFalse;
       
   288         LOG( SIMPLE, "LAUNCHBROWSER: \
       
   289             CLaunchBrowserHandler::CommandAllowed unknown browser id" )
       
   290         }
       
   291     else if ( ( RSat::EAlphaIdProvided !=
       
   292         iLaunchBrowserData.iAlphaId.iStatus ) &&
       
   293         ( RSat::ESelfExplanatory ==
       
   294             iLaunchBrowserData.iIconId.iQualifier ||
       
   295           RSat::ENotSelfExplanatory ==
       
   296             iLaunchBrowserData.iIconId.iQualifier ) )
       
   297         {
       
   298         iLaunchBrowserRsp.iGeneralResult = RSat::KCmdDataNotUnderstood;
       
   299         commandAllowed = EFalse;
       
   300         LOG( SIMPLE, "LAUNCHBROWSER: \
       
   301             CLaunchBrowserHandler::CommandAllowed icon without alpha id" )
       
   302         }
       
   303     else if (
       
   304         ( RMobilePhone::ERegisteredOnHomeNetwork != registrationStatus ) &&
       
   305         ( RMobilePhone::ERegisteredRoaming != registrationStatus ) )
       
   306         {
       
   307         iLaunchBrowserRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   308         iLaunchBrowserRsp.iInfoType = RSat::KMeProblem;
       
   309         iLaunchBrowserRsp.iAdditionalInfo.SetLength( 1 );
       
   310         iLaunchBrowserRsp.iAdditionalInfo[0] = RSat::KNoService;
       
   311         commandAllowed = EFalse;
       
   312         LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::CommandAllowed\
       
   313              MS is out of service (Net. Reg. status wrong)" )
       
   314         }
       
   315     else if ( RSat::EBrowserSelectionNotSet == iLaunchBrowserData.iBrowserSel )
       
   316         {
       
   317         iLaunchBrowserRsp.iGeneralResult = RSat::KCmdTypeNotUnderstood;
       
   318         commandAllowed = EFalse;
       
   319         LOG( SIMPLE, "LAUNCHBROWSER: \
       
   320             CLaunchBrowserHandler::CommandAllowed selection not set" )
       
   321         }
       
   322     else if ( RSat::ELaunchBrowserIfNotAlreadyLaunched ==
       
   323         iLaunchBrowserData.iBrowserSel )
       
   324         {
       
   325         if ( BrowserExists() )
       
   326             {
       
   327             iLaunchBrowserRsp.iInfoType = RSat::KMeProblem;
       
   328             iLaunchBrowserRsp.iAdditionalInfo.Append( 
       
   329                 RSat::KBrowserUnavailable );
       
   330             commandAllowed = EFalse;
       
   331             LOG( SIMPLE, "LAUNCHBROWSER: \
       
   332                 CLaunchBrowserHandler::CommandAllowed not launched" )
       
   333             }
       
   334         }
       
   335     else
       
   336         {
       
   337         LOG( SIMPLE,
       
   338             "LAUNCHBROWSER: CLaunchBrowserHandler::CommandAllowed ok" )
       
   339         }
       
   340 
       
   341     if ( !commandAllowed )
       
   342         {
       
   343         LOG( SIMPLE,
       
   344             "CLaunchBrowserHandler::CommandAllowed commandAllowed false" )
       
   345         iLaunchBrowserRsp.SetPCmdNumber( iLaunchBrowserData.PCmdNumber() );
       
   346         TerminalRsp( RSat::ELaunchBrowser, iLaunchBrowserRspPckg );
       
   347         }
       
   348     // Set icon command flag whether icon data was received and set qualifier
       
   349     // to no icon id
       
   350     // To be removed when icons are allowed in this command
       
   351     else if ( ( RSat::ESelfExplanatory ==
       
   352         iLaunchBrowserData.iIconId.iQualifier ) ||
       
   353         ( RSat::ENotSelfExplanatory ==
       
   354         iLaunchBrowserData.iIconId.iQualifier ) )
       
   355         {
       
   356          LOG( SIMPLE,
       
   357             "CLaunchBrowserHandler::CommandAllowed commandAllowed ENoIconId" )
       
   358         iIconCommand = ETrue;
       
   359         iLaunchBrowserData.iIconId.iQualifier = RSat::ENoIconId;
       
   360         }
       
   361     else
       
   362         {
       
   363         iIconCommand = EFalse;
       
   364         }
       
   365 
       
   366     LOG2( SIMPLE,
       
   367         "LAUNCHBROWSER: CLaunchBrowserHandler::CommandAllowed exiting, \
       
   368          commandAllowed: %d", commandAllowed )
       
   369     return commandAllowed;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // From class CSatCommandHandler.
       
   374 // Answers for need of UI session.
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 TBool CLaunchBrowserHandler::NeedUiSession()
       
   378     {
       
   379     LOG( SIMPLE,
       
   380         "LAUNCHBROWSER: CLaunchBrowserHandler::NeedUiSession calling" )
       
   381 
       
   382     const RSat::TAlphaId alphaId( iLaunchBrowserData.iAlphaId );
       
   383 
       
   384     iNeedUiSession = ETrue;
       
   385 
       
   386     if ( ( ( alphaId.iStatus == RSat::EAlphaIdProvided &&
       
   387         alphaId.iAlphaId.Length() == 0 ) ||
       
   388         alphaId.iStatus == RSat::EAlphaIdNull ) &&
       
   389         ( !iUtils->SystemState().IsConfirmSatOperationsOn() ) )
       
   390         {
       
   391         iNeedUiSession = EFalse;
       
   392         LOG( NORMAL,
       
   393             "LAUNCHBROWSER: CLaunchBrowserHandler::NeedUiSession no  \
       
   394             Ui session needed" )
       
   395         }
       
   396 
       
   397     if ( iUtils->CoverUiSupported() && iNeedUiSession )
       
   398         {
       
   399         LOG( NORMAL,
       
   400             "LAUNCHBROWSER: CLaunchBrowserHandler::NeedUiSession Ui session \
       
   401             needed" )
       
   402         TSatCommandData medEventData;
       
   403         medEventData.iPCmdNumber = RSat::ELaunchBrowser;
       
   404         medEventData.iAlphaId = iLaunchBrowserData.iAlphaId;
       
   405 
       
   406         if ( iUtils->SystemState().IsConfirmSatOperationsOn() )
       
   407             {
       
   408             LOG( NORMAL,
       
   409             "LAUNCHBROWSER: CLaunchBrowserHandler::NeedUiSession \
       
   410              KSatLongDuration" )
       
   411             medEventData.iDuration.iNumOfUnits = KSatLongDuration;
       
   412             }
       
   413         else
       
   414             {
       
   415             medEventData.iDuration.iNumOfUnits = KSatDefaultDuration;
       
   416             }
       
   417 
       
   418         medEventData.iDuration.iTimeUnit = RSat::ESeconds;
       
   419         medEventData.iIconID = iLaunchBrowserData.iIconId;
       
   420         TSatCommandPckg tPckg( medEventData );
       
   421         iUtils->RaiseSatEvent( tPckg );
       
   422         }
       
   423 
       
   424     LOG2( SIMPLE,
       
   425         "LAUNCHBROWSER: CLaunchBrowserHandler::NeedUiSession exiting, \
       
   426          iNeedUiSession: %d", iNeedUiSession )
       
   427     return iNeedUiSession;
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // From class CSatCommandHandler.
       
   432 // Called when USAT API notifies that command.
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 void CLaunchBrowserHandler::HandleCommand()
       
   436     {
       
   437     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::HandleCommand calling" )
       
   438 
       
   439     // Register service request handler for LaunchBrowser command,
       
   440     // If there is already service request for query, registering
       
   441     // updates command handler, so client responses comes to this
       
   442     // command handler
       
   443     TRAPD( err, iUtils->RegisterServiceRequestL(
       
   444         ESatSProactiveQuery,
       
   445         ESatSProactiveQueryResponse,
       
   446         this ) );
       
   447 
       
   448     if ( KErrNone != err )
       
   449         {
       
   450         iLaunchBrowserRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   451         iLaunchBrowserRsp.iInfoType = RSat::KMeProblem;
       
   452         iLaunchBrowserRsp.iAdditionalInfo.SetLength( 1 );
       
   453         iLaunchBrowserRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   454         iLaunchBrowserRsp.SetPCmdNumber( iLaunchBrowserData.PCmdNumber() );
       
   455         TerminalRsp( RSat::ELaunchBrowser, iLaunchBrowserRspPckg );
       
   456 
       
   457         LOG2( SIMPLE,
       
   458         "LAUNCHBROWSER: CLaunchBrowserHandler::HandleCommand error: %i", err )
       
   459         }
       
   460     else if ( iNeedUiSession )
       
   461         {
       
   462         iQueryData.iCommand = ESatSLaunchBrowserQuery;
       
   463         iQueryData.iQueryText = iLaunchBrowserData.iAlphaId.iAlphaId;
       
   464         iQueryData.iIconId.iIdentifier =
       
   465             iLaunchBrowserData.iIconId.iIdentifier;
       
   466         LOG2( SIMPLE, "CLaunchBrowserHandler::HandleCommand \
       
   467               iLaunchBrowserData.iIconId.iQualifier: %i", 
       
   468               iLaunchBrowserData.iIconId.iQualifier )
       
   469         switch ( iLaunchBrowserData.iIconId.iQualifier )
       
   470             {
       
   471             case RSat::ESelfExplanatory:
       
   472                 {
       
   473                 // Icon qualifier is self explanatory (to display instead
       
   474                 // of the alpha id or text string).
       
   475                 iQueryData.iIconId.iIconQualifier = ESatSelfExplanatory;
       
   476                 break;
       
   477                 }
       
   478 
       
   479             case RSat::ENotSelfExplanatory:
       
   480                 {
       
   481                 // Icon qualifier is not self explanatory.
       
   482                 iQueryData.iIconId.iIconQualifier = ESatNotSelfExplanatory;
       
   483                 break;
       
   484                 }
       
   485 
       
   486             default:
       
   487                 {
       
   488                 // Icon qualifier not present
       
   489                 iQueryData.iIconId.iIconQualifier = ESatENoIconId;
       
   490                 break;
       
   491                 }
       
   492             }
       
   493 
       
   494         if ( RSat::EAlphaIdNotPresent == iLaunchBrowserData.iAlphaId.iStatus )
       
   495             {
       
   496             LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::HandleCommand \
       
   497                  EAlphaIdNotPresent" )
       
   498             iQueryData.iAlphaIdStatus = ESatAlphaIdNotProvided;
       
   499             }
       
   500         else if ( RSat::EAlphaIdProvided ==
       
   501             iLaunchBrowserData.iAlphaId.iStatus )
       
   502             {
       
   503             LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::HandleCommand \
       
   504                  EAlphaIdProvided" )
       
   505             iQueryData.iAlphaIdStatus = ESatAlphaIdNotNull;
       
   506             }
       
   507         else
       
   508             {
       
   509             iQueryData.iAlphaIdStatus = ESatAlphaIdNull;
       
   510             }
       
   511 
       
   512         iQueryData.iSimApplicationName = iUtils->SatAppName();
       
   513 
       
   514         // Ask the user permission to launch browser. Reply will come
       
   515         // to ClientResponse() method.
       
   516         iUtils->SatUiHandler().UiSession()->SendCommand(
       
   517             &iQueryPckg,
       
   518             &iQueryRspPckg,
       
   519             ESatSProactiveQuery );
       
   520         }
       
   521     else // transparent launch
       
   522         {
       
   523         // Launch the Browser.
       
   524         TRAP( err, LaunchBrowserL() );
       
   525 
       
   526         if ( KErrNone != err )
       
   527             {
       
   528             iLaunchBrowserRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   529             LOG2( SIMPLE, "LAUNCHBROWSER: \
       
   530                 CLaunchBrowserHandler::HandleCommand error: %i", err )
       
   531             }
       
   532         else
       
   533             {
       
   534             LOG( SIMPLE,
       
   535                 "LAUNCHBROWSER: CLBH::CR ESetUpMenuRequested registered" )
       
   536             TRAP_IGNORE( iUtils->RegisterL(
       
   537                 this, MSatUtils::ESetUpMenuRequested ) )
       
   538             }
       
   539 
       
   540         TerminalRsp( RSat::ELaunchBrowser, iLaunchBrowserRspPckg );
       
   541         }
       
   542 
       
   543     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::HandleCommand exiting" )
       
   544     }
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // From class CSatCommandHandler.
       
   548 // Indicates the failure of launching ui client.
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CLaunchBrowserHandler::UiLaunchFailed()
       
   552     {
       
   553     LOG( SIMPLE,
       
   554         "LAUNCHBROWSER: CLaunchBrowserHandler::UiLaunchFailed calling" )
       
   555 
       
   556     iLaunchBrowserRsp.iGeneralResult = RSat::KMeUnableToProcessCmd;
       
   557     iLaunchBrowserRsp.iInfoType = RSat::KMeProblem;
       
   558     iLaunchBrowserRsp.iAdditionalInfo.SetLength( 1 );
       
   559     iLaunchBrowserRsp.iAdditionalInfo[0] = RSat::KNoSpecificMeProblem;
       
   560     iLaunchBrowserRsp.SetPCmdNumber( iLaunchBrowserData.PCmdNumber() );
       
   561     TerminalRsp( RSat::ELaunchBrowser, iLaunchBrowserRspPckg );
       
   562 
       
   563     LOG( SIMPLE,
       
   564         "LAUNCHBROWSER: CLaunchBrowserHandler::UiLaunchFailed exiting" )
       
   565     }
       
   566     
       
   567 // -----------------------------------------------------------------------------
       
   568 // C++ default constructor can NOT contain any code, that
       
   569 // might leave.
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 //lint -e{1403, 1769} Can not be initialized, harmless.
       
   573 CLaunchBrowserHandler::CLaunchBrowserHandler() :
       
   574     CSatCommandHandler(),
       
   575     iLaunchBrowserData(),
       
   576     iLaunchBrowserPckg( iLaunchBrowserData ),
       
   577     iLaunchBrowserRsp(),
       
   578     iLaunchBrowserRspPckg( iLaunchBrowserRsp ),
       
   579     iQueryData(),
       
   580     iQueryPckg( iQueryData ),
       
   581     iQueryRsp(),
       
   582     iQueryRspPckg( iQueryRsp ),
       
   583     iUidWmlBrowser( TUid::Uid( KWmlcHandler ) ),
       
   584     iAfterTimer( NULL ),
       
   585     // To be removed when icons are allowed in this command
       
   586     iIconCommand( EFalse )
       
   587     {
       
   588     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::CLaunchBrowserHandler \
       
   589         calling - exiting" )
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // Symbian 2nd phase constructor can leave.
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 void CLaunchBrowserHandler::ConstructL()
       
   597     {
       
   598     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::ConstructL calling" )
       
   599 
       
   600     // Open the Window server session.
       
   601     User::LeaveIfError( iWsSession.Connect() );
       
   602 
       
   603     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::ConstructL exiting" )
       
   604     }
       
   605 
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // Checks if Browser application is launched.
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 TBool CLaunchBrowserHandler::BrowserExists()
       
   612     {
       
   613     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::BrowserExists calling" )
       
   614     TBool browserExists( EFalse );
       
   615 
       
   616     TApaTaskList taskList( iWsSession );
       
   617     TApaTask task = taskList.FindApp( iUidWmlBrowser );
       
   618     browserExists = task.Exists();
       
   619 
       
   620     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::BrowserExists exiting" )
       
   621     return browserExists;
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 // The Launch Browser handler.
       
   626 // -----------------------------------------------------------------------------
       
   627 //
       
   628 void CLaunchBrowserHandler::LaunchBrowserL()
       
   629     {
       
   630     LOG( SIMPLE,
       
   631         "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL calling" )
       
   632 
       
   633     // Check the URL length.
       
   634     const TInt urlLen( iLaunchBrowserData.iUrl.Length() );
       
   635 
       
   636     // ID of the accesspoint in the communications database.
       
   637     TUid accesspointID( TUid::Uid( KErrNotFound ) );
       
   638 
       
   639     // If apId is given by SIM card, then we use that, otherwise,
       
   640     // get default apId from default connection method.
       
   641     TUint32 apId( 0 );
       
   642     // GCF is supported since S60 5.0
       
   643     apId = GetAccessPointByGatewayAddressL();
       
   644     if ( apId )
       
   645         {
       
   646         LOG2( SIMPLE, 
       
   647               "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL, \
       
   648               Get gcf AP id = %d", apId )
       
   649         accesspointID.iUid = static_cast<TInt32>( apId );
       
   650         }    
       
   651     
       
   652     // Get default AP if GCF ap not found
       
   653     if ( KErrNotFound == accesspointID.iUid )
       
   654         {
       
   655         LOG( SIMPLE, 
       
   656              "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL, \
       
   657              no gcf AP id" )
       
   658         apId = GetAccessPointByDefaultL();
       
   659         if ( apId )
       
   660             {
       
   661             LOG2( SIMPLE, 
       
   662                   "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL, \
       
   663                   default AP id = %d", apId )            
       
   664             accesspointID.iUid = static_cast<TInt32>( apId );
       
   665             }
       
   666         }
       
   667     
       
   668     LOG2( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL, \
       
   669           accesspointID.iUid=%d", accesspointID.iUid )
       
   670     
       
   671     HBufC* param = NULL;
       
   672     // If the URL is given by SIM, then we use that
       
   673     if ( urlLen )
       
   674         {
       
   675         // Url is given by SIM, and we use that.
       
   676         param = HBufC::NewLC( urlLen );
       
   677         param->Des().Copy( iLaunchBrowserData.iUrl );
       
   678         LOG3( SIMPLE, 
       
   679               "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL,\
       
   680               url is given by SIM, url=%s, length=%d", 
       
   681               param, param->Des().Length() )
       
   682         }  
       
   683     // If no url from SIM, get default URL by selected access point.
       
   684     else if ( !param && accesspointID.iUid > 0 )
       
   685         {
       
   686         param = GetDefaultUrlByAccessPointLC( 
       
   687                 static_cast<TUint32>( accesspointID.iUid) );
       
   688         LOG3( SIMPLE, 
       
   689               "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL,\
       
   690               url is given by IAP, url=%s, length=%d",
       
   691               param, param->Des().Length() )
       
   692         }
       
   693     else
       
   694         {
       
   695         param = KNullDesC().AllocLC();
       
   696         LOG( SIMPLE, 
       
   697              "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL no url" )
       
   698         }
       
   699     
       
   700     switch ( iLaunchBrowserData.iBrowserSel )
       
   701         {
       
   702         case RSat::ECloseExistingLaunchNewBrowserSession:
       
   703             {
       
   704             LOG( NORMAL, "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
   705                  LaunchBrowserL, ECloseExistingLaunchNewBrowserSession" )
       
   706             CloseBrowser();  // Close Browser Session if it exists.
       
   707             LaunchWithUrlL( param->Des(), accesspointID );
       
   708             break;
       
   709             }
       
   710 
       
   711         case RSat::ELaunchBrowserIfNotAlreadyLaunched:
       
   712             {
       
   713             LOG( NORMAL, "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
   714                  LaunchBrowserL, ELaunchBrowserIfNotAlreadyLaunched" )
       
   715             if ( BrowserExists() )
       
   716                 {
       
   717                 LOG( SIMPLE,"CLaunchBrowserHandler::LaunchBrowserL \
       
   718                      BrowserExists" )
       
   719                 // Browser exists, error response returned.
       
   720                 iLaunchBrowserRsp.iGeneralResult = RSat::KLaunchBrowserError;
       
   721                 iLaunchBrowserRsp.iInfoType = RSat::KMeProblem;
       
   722                 iLaunchBrowserRsp.iAdditionalInfo.Append( 
       
   723                     RSat::KBrowserUnavailable );
       
   724                 }
       
   725             else
       
   726                 {
       
   727                 LaunchWithUrlL( param->Des(), accesspointID );
       
   728                 }
       
   729             break;
       
   730             }
       
   731 
       
   732         case RSat::EUseExistingBrowser:
       
   733             {
       
   734             // SAT Shell Controller looks if browser already exists.
       
   735             LOG( NORMAL, "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
   736                  LaunchBrowserL,EUseExistingBrowser" )
       
   737             LaunchWithUrlL( param->Des(), accesspointID );
       
   738             break;
       
   739             }
       
   740 
       
   741         case RSat::EBrowserSelectionNotSet:
       
   742         default:
       
   743             __ASSERT_DEBUG( EFalse,
       
   744                 Panic( KLaunchBrowserHandlerName, KErrBadName ) );
       
   745             break;
       
   746         }
       
   747 
       
   748     CleanupStack::PopAndDestroy( param );
       
   749 
       
   750     LOG( SIMPLE,
       
   751         "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchBrowserL exiting" )
       
   752     }
       
   753 
       
   754 // --------------------------------------------------------------------------
       
   755 // Closes the Browser application if it is active and waits until
       
   756 // closing is complete.
       
   757 // --------------------------------------------------------------------------
       
   758 //
       
   759 void CLaunchBrowserHandler::CloseBrowser()
       
   760     {
       
   761     LOG( SIMPLE, 
       
   762          "LAUNCHBROWSER: CLaunchBrowserHandler::CloseBrowser calling" )
       
   763     TApaTaskList taskList( iWsSession );
       
   764     TApaTask task = taskList.FindApp( iUidWmlBrowser );
       
   765 
       
   766     if ( task.Exists() )
       
   767         {
       
   768         task.SendSystemEvent( EApaSystemEventShutdown );
       
   769 
       
   770         TBool browserExists( ETrue );
       
   771         TInt waitCount( 0 );
       
   772         LOG2( SIMPLE, 
       
   773               "CLaunchBrowserHandler::CloseBrowser browserExists: %d",
       
   774               browserExists )
       
   775         // Make sure that closing is completed.
       
   776         while ( browserExists )
       
   777             {
       
   778             After( KSatSShortLoopTimeout );
       
   779             ++waitCount;
       
   780 
       
   781             TApaTask newTask = taskList.FindApp( iUidWmlBrowser );
       
   782             browserExists = newTask.Exists();
       
   783 
       
   784             if ( KSatSWaitCount <= waitCount )
       
   785                 {
       
   786                 newTask.KillTask();
       
   787                 browserExists = EFalse;
       
   788                 LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
   789                     CloseBrowser force kill task" )
       
   790                 }
       
   791             }
       
   792         }
       
   793 
       
   794     LOG( SIMPLE, 
       
   795          "LAUNCHBROWSER: CLaunchBrowserHandler::CloseBrowser exiting" )
       
   796     }
       
   797 
       
   798 // --------------------------------------------------------------------------
       
   799 // Launches The Browser with URL.
       
   800 // --------------------------------------------------------------------------
       
   801 //
       
   802 void CLaunchBrowserHandler::LaunchWithUrlL( const TDesC& aParam,
       
   803     const TUid& aAccessPointUid )
       
   804     {
       
   805     LOG( SIMPLE,
       
   806         "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL calling" )
       
   807     LOG3( SIMPLE,
       
   808          "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL\
       
   809           url=%s, IAP=%d", &aParam, aAccessPointUid.iUid )        
       
   810 
       
   811     // Browser launching called.
       
   812     TInt err = iUtils->SatUiHandler().ShellController().LaunchBrowserL(
       
   813         aParam, aAccessPointUid );
       
   814 
       
   815     if ( KErrNone == err )
       
   816         {
       
   817         if ( !iQueryRsp.iRequestedIconDisplayed &&
       
   818             ( ( RSat::ESelfExplanatory ==
       
   819             iLaunchBrowserData.iIconId.iQualifier ) ||
       
   820             ( RSat::ENotSelfExplanatory ==
       
   821             iLaunchBrowserData.iIconId.iQualifier ) ) )
       
   822             {
       
   823             iLaunchBrowserRsp.iGeneralResult =
       
   824                 RSat::KSuccessRequestedIconNotDisplayed;
       
   825             LOG( SIMPLE,
       
   826                 "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL \
       
   827                 no icon shown" )
       
   828             }
       
   829         else
       
   830             {
       
   831             iLaunchBrowserRsp.iGeneralResult = RSat::KSuccess;
       
   832             LOG( SIMPLE,
       
   833                 "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL \
       
   834                 command ok" )
       
   835             }
       
   836         }
       
   837     else
       
   838         {
       
   839         iLaunchBrowserRsp.iGeneralResult  = RSat::KLaunchBrowserError;
       
   840         iLaunchBrowserRsp.iInfoType       = RSat::KMeProblem;
       
   841         iLaunchBrowserRsp.iAdditionalInfo.Append( 
       
   842                 RSat::KBrowserUnavailable );
       
   843         LOG2( SIMPLE, 
       
   844         "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL error: %i", 
       
   845         err )
       
   846         }
       
   847 
       
   848     LOG( SIMPLE,
       
   849         "LAUNCHBROWSER: CLaunchBrowserHandler::LaunchWithUrlL exiting" )
       
   850     }
       
   851 
       
   852 // --------------------------------------------------------------------------
       
   853 // Starts timer. Function returns as the given time has elapsed or
       
   854 // timer is cancelled.
       
   855 // --------------------------------------------------------------------------
       
   856 void CLaunchBrowserHandler::After(
       
   857     const TTimeIntervalMicroSeconds32& aDelay,
       
   858     const TTimeIntervalMicroSeconds32& aInterval )
       
   859     {
       
   860     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::After calling" )
       
   861 
       
   862     if ( !iAfterWait.IsStarted() )
       
   863         {
       
   864         TRAPD( err, iAfterTimer = CPeriodic::NewL( EPriorityStandard ) )
       
   865         LOG2( SIMPLE, 
       
   866         "LAUNCHBROWSER: CLaunchBrowserHandler::After err: %i", err )
       
   867         if ( ( KErrNone == err ) && iAfterTimer )
       
   868             {
       
   869             iAfterTimer->Start(
       
   870                 aDelay, aInterval, TCallBack( DelayCallBack, this ) );
       
   871             iAfterWait.Start();
       
   872 
       
   873             delete iAfterTimer;
       
   874             iAfterTimer = NULL;
       
   875             }
       
   876         }
       
   877 
       
   878     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::After exiting" )
       
   879     }
       
   880 
       
   881 // --------------------------------------------------------------------------
       
   882 // Timer call back function
       
   883 // --------------------------------------------------------------------------
       
   884 TInt CLaunchBrowserHandler::DelayCallBack( TAny* aPtr )
       
   885     {
       
   886     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::DelayCallBack \
       
   887     calling" )
       
   888     CLaunchBrowserHandler* ptrThis =
       
   889         static_cast<CLaunchBrowserHandler*>( aPtr );
       
   890 
       
   891     if ( ptrThis && ( ptrThis->iAfterWait.IsStarted() ) )
       
   892         {
       
   893         LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::DelayCallBack \
       
   894              stop iAfterWait" )
       
   895         ptrThis->iAfterWait.AsyncStop();
       
   896         }
       
   897     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::DelayCallBack \
       
   898     exiting" )
       
   899     return ( EFalse );
       
   900     }
       
   901 
       
   902 // --------------------------------------------------------------------------
       
   903 // Create a new access point using the Access Point Engine.
       
   904 // --------------------------------------------------------------------------
       
   905 //
       
   906 TUint32 CLaunchBrowserHandler::CreateAccessPointL( 
       
   907         const TDesC16& aApName,
       
   908         const TDesC16& aProxyServerAddr,
       
   909         const TUint32 aProxyPortNumber,
       
   910         const RPacketContext::TProtocolType& aIPvType )
       
   911     {
       
   912     LOG( SIMPLE, 
       
   913          "LAUNCHBROWSER: CLaunchBrowserHandler::CreateAccessPointL calling" )
       
   914 
       
   915     // Connection method interface.
       
   916     RCmConnectionMethod cm;
       
   917     // Connection method manager interface.
       
   918     RCmManager cmManager;
       
   919     // Used to exit connection methods go through loop
       
   920     TBool exitConnectionMethodsLoop( EFalse );
       
   921     
       
   922     cmManager.OpenLC();
       
   923 
       
   924     // Find if the access point with the same name is already exist.
       
   925     // If such access point exists, delete it and then create a new one.
       
   926      
       
   927     // Get the Connection Methods does not belogns to any destination
       
   928     RArray<TUint32> array = RArray<TUint32>( KSatCMGranularity );
       
   929     CleanupClosePushL( array );
       
   930 
       
   931     cmManager.ConnectionMethodL( array );
       
   932 
       
   933     // Go through the Connection Method list to find if there is matched one
       
   934      
       
   935     for( TInt i = 0; 
       
   936          ( i < array.Count() ) && !exitConnectionMethodsLoop; ++i)
       
   937         {
       
   938         cm = cmManager.ConnectionMethodL( array[i] );
       
   939         CleanupClosePushL( cm );
       
   940         
       
   941         // query the access point name
       
   942         HBufC * pa = NULL;
       
   943         pa = cm.GetStringAttributeL( CMManager::ECmName );
       
   944         CleanupStack::PushL(pa);
       
   945         
       
   946         if ( *pa == aApName )
       
   947             {
       
   948             // Find the matched connection method
       
   949             LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
   950                  CreateAccessPointL, find the existing ap" )
       
   951             cm.DeleteL();
       
   952             exitConnectionMethodsLoop = ETrue;
       
   953             }
       
   954         CleanupStack::PopAndDestroy( pa );
       
   955         CleanupStack::PopAndDestroy( &cm ); 
       
   956         } 
       
   957     CleanupStack::PopAndDestroy( &array );
       
   958 
       
   959     // Create a connection method without destination.
       
   960     cm = cmManager.CreateConnectionMethodL( KUidPacketDataBearerType );
       
   961     CleanupClosePushL( cm );
       
   962     
       
   963     // Fulfill connection method params with default setting from OCC.
       
   964     // We use trap to continue following operations even if leaving from 
       
   965     // FulfillConnnectionMethodL.
       
   966     TRAPD( errCode, FulfillConnnectionMethodL( cmManager, cm ) );
       
   967     LOG3( SIMPLE, "SATENGINE: CLaunchBrowserHandler::CreateAccessPointL \
       
   968           errCode=%d ad line %d", errCode, __LINE__ )
       
   969     // Set attributes of the connection method.
       
   970     cm.SetStringAttributeL( CMManager::ECmName, aApName );
       
   971     cm.SetIntAttributeL( CMManager::EPacketDataPDPType, aIPvType );
       
   972     cm.SetStringAttributeL( CMManager::ECmWapIPGatewayAddress, 
       
   973                             TPtrC( aProxyServerAddr ) );
       
   974     cm.SetStringAttributeL( CMManager::ECmProxyServerName, 
       
   975                             TPtrC( aProxyServerAddr ) );
       
   976     cm.SetIntAttributeL( CMManager::ECmProxyPortNumber, aProxyPortNumber );
       
   977         
       
   978     // Update the access point ID for use later.
       
   979     cm.UpdateL();
       
   980 
       
   981     TUint32 apId = cm.GetIntAttributeL( CMManager::ECmIapId );
       
   982     LOG2( SIMPLE, 
       
   983           "LAUNCHBROWSER: CLaunchBrowserHandler::CreateAccessPointL apId=%d",
       
   984           apId )
       
   985 
       
   986     CleanupStack::PopAndDestroy( &cm );
       
   987     CleanupStack::PopAndDestroy( &cmManager );
       
   988     
       
   989     LOG( SIMPLE, 
       
   990          "LAUNCHBROWSER: CLaunchBrowserHandler::CreateAccessPointL exiting" )
       
   991     
       
   992     return apId;
       
   993     }
       
   994 
       
   995 // --------------------------------------------------------------------------
       
   996 // Get a AP from the Connection Method Manager.
       
   997 // --------------------------------------------------------------------------
       
   998 TUint32 CLaunchBrowserHandler::GetAccessPointByGatewayAddressL()
       
   999     {
       
  1000     LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1001         CLaunchBrowserHandler::GetAccessPointByGatewayAddressL calling" )
       
  1002     // Access Point ID.
       
  1003     TUint32 apId( 0 ); 
       
  1004     // Unknown IP address type.
       
  1005     TInt ipvType( 0 );
       
  1006     // Get the gateway address.
       
  1007     TPtrC gatewayAddrPtr( iLaunchBrowserData.iText );
       
  1008     // Get the bearer list.
       
  1009     TPtrC8 bearerListPtr( iLaunchBrowserData.iBearerList ); 
       
  1010 
       
  1011     // Proxy address.
       
  1012     HBufC* proxyAddress = NULL;
       
  1013     // Proxy port number.
       
  1014     TUint32 proxyPortNumber( 0 );
       
  1015     HBufC* pa = NULL;
       
  1016     TUint32 pn( 0 );
       
  1017 
       
  1018     // Used to exit the connection method go through loop
       
  1019     TBool exitConnectionMethodsLoop( EFalse );
       
  1020     
       
  1021     // SAT access point name.
       
  1022     TPtrC satAPN( KNullDesC );
       
  1023     
       
  1024     // Use SAT application name as SAT APN.
       
  1025     satAPN.Set( iUtils->SatAppName() );
       
  1026     // Use default SAT APN if SAT application name is not available.
       
  1027     if ( satAPN == KNullDesC )
       
  1028         {
       
  1029         LOG( SIMPLE, 
       
  1030              "CLaunchBrowserHandler::GetAccessPointByGatewayAddressL\
       
  1031              satAPN == KNullDesC" )
       
  1032         satAPN.Set( KSatAccessPointName );
       
  1033         }
       
  1034         
       
  1035     // Get the proxy address and port number
       
  1036     proxyAddress = HBufC::NewLC( gatewayAddrPtr.Length() );
       
  1037     TPtr proxyAddrPtr( proxyAddress->Des() );
       
  1038     SeparatePortNumberFromAddress( gatewayAddrPtr, proxyAddrPtr, 
       
  1039         proxyPortNumber );
       
  1040     proxyAddrPtr.TrimAll();
       
  1041     
       
  1042     // Check the launch browser package for gateway setting.
       
  1043     ipvType = ValidateGatewayAddress( proxyAddrPtr );
       
  1044     
       
  1045     if ( RPacketContext::EPdpTypeIPv4 == ipvType || \
       
  1046          RPacketContext::EPdpTypeIPv6 == ipvType )
       
  1047         {
       
  1048         LOG2( SIMPLE, 
       
  1049               "CLaunchBrowserHandler::GetAccessPointByGatewayAddressL \
       
  1050               gatewayAddrPtr.Length(): %d", gatewayAddrPtr.Length() )
       
  1051         // Check the launch browser package for bearer setting if the gateway
       
  1052         // address is valid.
       
  1053         LOG2( SIMPLE, 
       
  1054               "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
  1055               GetAccessPointByGatewayAddressL, IPvType is %d",
       
  1056               ipvType)
       
  1057         if ( gatewayAddrPtr.Length() )
       
  1058             {
       
  1059             // The bearer is GPRS.
       
  1060             if ( bearerListPtr != KNullDesC8 && bearerListPtr.Length() > 0 
       
  1061                     && RSat::KGprsBearer == bearerListPtr[0] )
       
  1062                 {
       
  1063                 
       
  1064                 // Go through the candidate connection methods to find 
       
  1065                 // the one matched the gateway address. If a matched one 
       
  1066                 // is found,using it as the access point for SIM service, 
       
  1067                 // else a new one is created.      
       
  1068                 RCmManager cmManager;
       
  1069                 cmManager.OpenLC();
       
  1070 
       
  1071                 // Get the Connection Methods does not belongs to 
       
  1072                 // any destination
       
  1073                 RArray<TUint32> array = RArray<TUint32>( 
       
  1074                                         KSatCMGranularity );
       
  1075                 CleanupClosePushL( array );
       
  1076 
       
  1077                 cmManager.ConnectionMethodL( array );
       
  1078 
       
  1079                 // Go through the Connection Method list to find 
       
  1080                 // if there is matched one
       
  1081                  
       
  1082                 for( TInt i = 0; 
       
  1083                      ( i < array.Count() ) && !exitConnectionMethodsLoop; 
       
  1084                      ++i )
       
  1085                     {
       
  1086                     RCmConnectionMethod cm = cmManager.ConnectionMethodL(
       
  1087                                                           array[i] );
       
  1088                     CleanupClosePushL( cm );
       
  1089                     
       
  1090                     // query the Gateway proxy address 
       
  1091                     // of the Connection Method
       
  1092                     pa = cm.GetStringAttributeL( 
       
  1093                          CMManager::ECmWapIPGatewayAddress );
       
  1094                     CleanupStack::PushL(pa);
       
  1095                     
       
  1096                     // query the Gateway proxy port number of the Connection 
       
  1097                     // Method
       
  1098                     pn = cm.GetIntAttributeL( 
       
  1099                             CMManager::ECmProxyPortNumber );
       
  1100                     
       
  1101                     if (( pn == proxyPortNumber ) && 
       
  1102                         ( *pa == *proxyAddress ))
       
  1103                         {
       
  1104                         // Find the matched connection method
       
  1105                         apId = cm.GetIntAttributeL( CMManager::ECmIapId );
       
  1106                         LOG2( SIMPLE, 
       
  1107                               "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1108                               GetAccessPointByGatewayAddressL, apId=%d",
       
  1109                               apId )
       
  1110                         exitConnectionMethodsLoop = ETrue;
       
  1111                         }
       
  1112                         
       
  1113                     CleanupStack::PopAndDestroy( pa );
       
  1114                     CleanupStack::PopAndDestroy( &cm );
       
  1115                     }
       
  1116             
       
  1117                 CleanupStack::PopAndDestroy( &array );
       
  1118                 CleanupStack::PopAndDestroy( &cmManager );
       
  1119                 
       
  1120                 LOG2( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler:: \
       
  1121                       GetAccessPointByGatewayAddressL apId=%d", apId )
       
  1122                            
       
  1123                 if ( !apId )
       
  1124                     {
       
  1125                     // Create a new AP if there is not a matched one.
       
  1126                     apId = CreateAccessPointL( 
       
  1127                             satAPN,
       
  1128                             proxyAddrPtr,
       
  1129                             proxyPortNumber,
       
  1130                             static_cast<RPacketContext::TProtocolType>(
       
  1131                                                               ipvType ) );
       
  1132                     }
       
  1133                 }
       
  1134             }
       
  1135         }
       
  1136     CleanupStack::PopAndDestroy( proxyAddress );
       
  1137     
       
  1138     LOG2( SIMPLE, 
       
  1139           "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1140           GetAccessPointByGatewayAddressL exiting, apId=%d", apId )
       
  1141     
       
  1142     // return the AP.
       
  1143     return apId;
       
  1144     }
       
  1145 
       
  1146 // --------------------------------------------------------------------------
       
  1147 // Get an Access Point by default.
       
  1148 // --------------------------------------------------------------------------
       
  1149 TUint32 CLaunchBrowserHandler::GetAccessPointByDefaultL()
       
  1150     {
       
  1151     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1152          GetAccessPointByDefaultL calling" )
       
  1153          
       
  1154     TUint32 apId ( KErrNone );
       
  1155     RCmManager cmManager;
       
  1156     cmManager.OpenLC();
       
  1157     RCmConnectionMethod cm;
       
  1158     CleanupClosePushL( cm );
       
  1159     
       
  1160     // Get a default connection method
       
  1161     TInt ret( KErrNotFound );
       
  1162     GetDefConnMethodL( cmManager, cm, ret );
       
  1163     if ( !ret )
       
  1164         {
       
  1165         LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1166              GetAccessPointByDefaultL default connection found" )        
       
  1167         apId = cm.GetIntAttributeL( CMManager::ECmIapId );
       
  1168         }
       
  1169     
       
  1170     CleanupStack::PopAndDestroy( &cm );
       
  1171     CleanupStack::PopAndDestroy( &cmManager );
       
  1172     
       
  1173     LOG2( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1174           GetAccessPointByDefaultL exiting, apId=%d", apId )
       
  1175     
       
  1176     return apId;
       
  1177     }
       
  1178 
       
  1179 // --------------------------------------------------------------------------
       
  1180 // Get default URL by access point
       
  1181 // --------------------------------------------------------------------------
       
  1182 HBufC* CLaunchBrowserHandler::GetDefaultUrlByAccessPointLC( TUint32 aApId )
       
  1183     {
       
  1184     LOG2( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1185          GetDefaultUrlByAccessPointLC calling, aApId=%d", aApId )
       
  1186     
       
  1187     HBufC* url = NULL;
       
  1188     if ( aApId > 0 )
       
  1189         {
       
  1190         // Create CMManager session
       
  1191         RCmManager cmManager;
       
  1192         cmManager.OpenLC();
       
  1193         
       
  1194         // get the connection method by apId
       
  1195         RCmConnectionMethod cm = cmManager.ConnectionMethodL( aApId );
       
  1196         CleanupClosePushL( cm );
       
  1197         
       
  1198         // Get the default URL from default accesspoint
       
  1199         // If the access point doesn't include the default URL,
       
  1200         // the empty string is returned.
       
  1201         url = cm.GetStringAttributeL( CMManager::ECmStartPage );
       
  1202         
       
  1203         CleanupStack::PopAndDestroy( &cm );
       
  1204         CleanupStack::PopAndDestroy( &cmManager );
       
  1205 
       
  1206         CleanupStack::PushL( url );  
       
  1207         }
       
  1208     
       
  1209     if ( !url )
       
  1210         {
       
  1211         url = KNullDesC().AllocLC();
       
  1212         }
       
  1213     
       
  1214     LOG2( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1215           GetDefaultUrlByAccessPointLC exiting, url=%s", url )
       
  1216     return url;
       
  1217     }
       
  1218 
       
  1219 // --------------------------------------------------------------------------
       
  1220 // Convert a descriptor into a integer.
       
  1221 // --------------------------------------------------------------------------
       
  1222 TInt CLaunchBrowserHandler::ConvertDesToInt( const TDesC16& aDes )
       
  1223     {
       
  1224     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1225           CLaunchBrowserHandler::ConvertDesToInt calling,length of aDes:%d",
       
  1226           aDes.Length() )
       
  1227 
       
  1228     TLex converter;
       
  1229     TInt intValue( KErrNotFound );
       
  1230     TBool digital( ETrue );
       
  1231 
       
  1232     if ( aDes != KNullDesC && aDes.Length() > 0 )
       
  1233         {
       
  1234         // The literal value of every element in the descriptor 
       
  1235         // should be numerical.
       
  1236         for ( TInt i = 0; i < aDes.Length() && digital; i++ )
       
  1237             {
       
  1238             TChar ch( aDes[i] );
       
  1239             
       
  1240             if ( !ch.IsDigit() )
       
  1241                 {
       
  1242                 LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1243                 CLaunchBrowserHandler::ConvertDesToInt not digit" )
       
  1244                 digital = EFalse;
       
  1245                 }
       
  1246             }
       
  1247             
       
  1248         if ( digital )
       
  1249             {
       
  1250             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1251             CLaunchBrowserHandler::ConvertDesToInt digit" )
       
  1252             // Converting.
       
  1253             converter.Assign( aDes );
       
  1254             converter.Val( intValue );
       
  1255             }
       
  1256         }
       
  1257 
       
  1258     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1259           CLaunchBrowserHandler::ConvertDesToInt exiting,intValue:%d", 
       
  1260           intValue )
       
  1261 
       
  1262     return intValue;
       
  1263     }
       
  1264 
       
  1265 // --------------------------------------------------------------------------
       
  1266 // Check the validity of a descriptor in hex.
       
  1267 // --------------------------------------------------------------------------
       
  1268 TBool CLaunchBrowserHandler::ValidateHexadecimal( const TDesC16& aHex )
       
  1269     {
       
  1270     LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1271         CLaunchBrowserHandler::ValidateHexadecimal calling" )
       
  1272 
       
  1273     // The hexadecimal descriptor can be null.
       
  1274     TInt length( aHex.Length() );
       
  1275     TBool retVal( ETrue );
       
  1276     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1277         CLaunchBrowserHandler::ValidateHexadecimal length:%d", length )
       
  1278 
       
  1279     // Validate characters one by one.
       
  1280     for ( TInt i = 0; i < length && retVal; i++ )
       
  1281         {
       
  1282         TChar ch( aHex[i] );
       
  1283         
       
  1284         if ( !ch.IsHexDigit() )
       
  1285             {
       
  1286             LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1287             CLaunchBrowserHandler::ValidateHexadecimal hex digit,i: %d",
       
  1288             i )
       
  1289             retVal = EFalse;
       
  1290             }
       
  1291         }
       
  1292 
       
  1293     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1294           CLaunchBrowserHandler::ValidateHexadecimal exiting, retVal:%d",
       
  1295           retVal )
       
  1296         
       
  1297     return retVal;
       
  1298     }
       
  1299 
       
  1300 // --------------------------------------------------------------------------
       
  1301 // Check the validity of a IPv4 address. For example, 210.13.246.172.
       
  1302 // --------------------------------------------------------------------------
       
  1303 TBool CLaunchBrowserHandler::ValidateIPv4Address( 
       
  1304         const TDesC16& aAddress )
       
  1305     {
       
  1306     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1307     CLaunchBrowserHandler::ValidateIPv4Address calling,aAddress: %s",
       
  1308     &aAddress )
       
  1309 
       
  1310     // Separate the address to be three segments using dot and validate
       
  1311     // each segment.
       
  1312     TPtrC segPtr( aAddress );
       
  1313     TBuf<KSatMaxIPv4SegmentLength> segment;
       
  1314     TInt posInDes( KErrNone );
       
  1315     TInt posInPtr( KErrNone );
       
  1316     TInt segCounter( KErrNone );
       
  1317     TBool first( ETrue );
       
  1318     TBool retVal( ETrue );
       
  1319     // Segment value in integer.
       
  1320     TInt intValue( KErrNone );
       
  1321         
       
  1322     // Convert each segment into integer.
       
  1323     while ( KErrNotFound != ( posInPtr = segPtr.Find( KSatIPv4Delimiter ) )
       
  1324             && retVal )
       
  1325         {
       
  1326         
       
  1327         if ( KSatMaxIPv4SegmentLength >= posInPtr && 0 < posInPtr )
       
  1328             {
       
  1329             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1330             CLaunchBrowserHandler::ValidateIPv4Address posInPtr valid" )
       
  1331             segCounter++;
       
  1332             posInDes += posInPtr;
       
  1333             segment = segPtr.Mid( 0, posInPtr );
       
  1334             
       
  1335             // The first integer should be > 0 and < 255, others should be 
       
  1336             // >=0 and < 255.
       
  1337             intValue = ConvertDesToInt( segment );
       
  1338             LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1339             CLaunchBrowserHandler::ValidateIPv4Address first:%d",first )
       
  1340             if ( first )
       
  1341                 {
       
  1342                 first = EFalse;
       
  1343                 
       
  1344                 if ( !( KSatIPv4Network < intValue && 
       
  1345                         KSatIPv4Broadcast > intValue ) )
       
  1346                     {
       
  1347                     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1348                          ValidateIPv4Address intValue valid" )
       
  1349                     retVal = EFalse;
       
  1350                     }
       
  1351                 }
       
  1352             else
       
  1353                 {
       
  1354                 
       
  1355                 if ( !( KSatIPv4Network <= intValue && 
       
  1356                         KSatIPv4Broadcast > intValue ) )
       
  1357                     {
       
  1358                     LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1359                          ValidateIPv4Address intValue range" )
       
  1360                     retVal = EFalse;
       
  1361                     }
       
  1362                 }
       
  1363             // Skip dot.
       
  1364             posInDes++;
       
  1365             segPtr.Set( aAddress.Mid( posInDes, 
       
  1366                 aAddress.Length() - posInDes ) );
       
  1367             }
       
  1368         else
       
  1369             {
       
  1370             retVal = EFalse;
       
  1371             }
       
  1372         }
       
  1373     
       
  1374     // IPv4 address is consist of 4 segment
       
  1375     if ( KSatMaxIPv4SegmentCounter == segCounter && retVal )
       
  1376         {
       
  1377         LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1378         CLaunchBrowserHandler::ValidateIPv4Address valid address" )
       
  1379         // Validate the last segment.
       
  1380         segment = segPtr;
       
  1381         
       
  1382         if ( KSatMaxIPv4SegmentLength < segment.Length() )
       
  1383             {
       
  1384             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1385             CLaunchBrowserHandler::ValidateIPv4Address address invalid" )
       
  1386             retVal = EFalse;
       
  1387             }
       
  1388             
       
  1389         intValue = ConvertDesToInt( segment );
       
  1390         
       
  1391         if ( !( KSatIPv4Network < intValue && 
       
  1392                 KSatIPv4Broadcast > intValue ) )
       
  1393             {
       
  1394             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1395             CLaunchBrowserHandler::ValidateIPv4Address intValue range" )
       
  1396             retVal = EFalse;
       
  1397             }
       
  1398         }
       
  1399     else
       
  1400         {
       
  1401         retVal = EFalse;
       
  1402         }
       
  1403         
       
  1404     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1405         CLaunchBrowserHandler::ValidateIPv4Address exiting,retVal:%d",
       
  1406         retVal )
       
  1407 
       
  1408     return retVal;
       
  1409     }
       
  1410 
       
  1411 // --------------------------------------------------------------------------
       
  1412 // Check the validity of a IPv6 address. For example,
       
  1413 // 3ffe:ffff:101::230:6eff:fe04:d9ff.
       
  1414 // --------------------------------------------------------------------------
       
  1415 TBool CLaunchBrowserHandler::ValidateIPv6Address( 
       
  1416         const TDesC16& aAddress )
       
  1417     {
       
  1418     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1419     CLaunchBrowserHandler::ValidateIPv6Address calling,aAddress: %s",
       
  1420     &aAddress )
       
  1421 
       
  1422     // Separate the address to be eight segments using colon and validate
       
  1423     // each segment.
       
  1424     TPtrC segPtr( aAddress );
       
  1425     TBuf<KSatMaxIPv6SegmentLength> segment;
       
  1426     TInt posInDes( KErrNone );
       
  1427     TInt posInPtr( KErrNone );
       
  1428     TInt segCounter( KErrNone );
       
  1429     TBool first( ETrue );
       
  1430     TBool retVal( ETrue );
       
  1431     
       
  1432     while ( KErrNotFound != ( posInPtr = segPtr.Find( KSatIPv6Delimiter ) )
       
  1433             && retVal )
       
  1434         {
       
  1435         
       
  1436         if ( KSatMaxIPv6SegmentLength >= posInPtr && 0 <= posInPtr )
       
  1437             {
       
  1438             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1439             CLaunchBrowserHandler::ValidateIPv6Address posInPtr valid" )
       
  1440             segCounter++;
       
  1441             posInDes += posInPtr;
       
  1442             segment = segPtr.Mid( 0, posInPtr );
       
  1443             LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1444             CLaunchBrowserHandler::ValidateIPv6Address first:%d",first )
       
  1445             if ( first )
       
  1446                 {
       
  1447                 first = EFalse;
       
  1448                 
       
  1449                 if ( 0 >= segment.Length() )
       
  1450                     {
       
  1451                     retVal = EFalse;
       
  1452                     }
       
  1453                 }
       
  1454                 
       
  1455             if ( KSatMaxIPv6SegmentLength < segment.Length() )
       
  1456                 {
       
  1457                 LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1458                 CLaunchBrowserHandler::ValidateIPv6Address address invalid" )
       
  1459                 retVal = EFalse;
       
  1460                 }
       
  1461                 
       
  1462             if ( !ValidateHexadecimal( segment ) )
       
  1463                 {
       
  1464                 LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1465                 ValidateIPv6Address address invalid hex" )
       
  1466                 retVal = EFalse;
       
  1467                 }
       
  1468             
       
  1469             // Skip colon.
       
  1470             posInDes++; 
       
  1471             segPtr.Set( aAddress.Mid( posInDes, 
       
  1472                 aAddress.Length() - posInDes ) );
       
  1473             }
       
  1474         else 
       
  1475             {
       
  1476             retVal = EFalse;
       
  1477             }
       
  1478         }
       
  1479 
       
  1480     // IPv6 address is consist of 8 segment
       
  1481     if ( KSatMaxIPv6SegmentCounter == segCounter && retVal )
       
  1482         {
       
  1483         LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1484         CLaunchBrowserHandler::ValidateIPv6Address valid address" )
       
  1485         // Validate the last segment.
       
  1486         segment = segPtr;
       
  1487         
       
  1488         if ( KSatMaxIPv6SegmentLength < segment.Length() )
       
  1489             {
       
  1490             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1491             CLaunchBrowserHandler::ValidateIPv6Address address invalid" )
       
  1492             retVal = EFalse;
       
  1493             }
       
  1494             
       
  1495         if ( !ValidateHexadecimal( segment ) )
       
  1496             {
       
  1497             LOG( SIMPLE, "LAUNCHBROWSER: CLaunchBrowserHandler::\
       
  1498             ValidateIPv6Address address invalid hex" )
       
  1499             retVal = EFalse;
       
  1500             }
       
  1501         }
       
  1502     else
       
  1503         {
       
  1504         retVal = EFalse;
       
  1505         }
       
  1506     
       
  1507     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1508           CLaunchBrowserHandler::ValidateIPv6Address exiting,retVal:%d", 
       
  1509           retVal )
       
  1510 
       
  1511     return retVal;
       
  1512     }
       
  1513     
       
  1514 // --------------------------------------------------------------------------
       
  1515 // Check the validity of a gateway IP address. Either it is IPv4 or IPv6. 
       
  1516 // For example, 210.13.246.172 or 3ffe:ffff:101::230:6eff:fe04:d9ff.
       
  1517 // --------------------------------------------------------------------------
       
  1518 TInt CLaunchBrowserHandler::ValidateGatewayAddress( 
       
  1519         const TDesC16& aAddress )
       
  1520     {
       
  1521     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1522           CLaunchBrowserHandler::ValidateGatewayAddress calling,length of \
       
  1523           aAddress: %d", aAddress.Length() )
       
  1524     
       
  1525     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1526     CLaunchBrowserHandler::ValidateGatewayAddress aAddress: %s", &aAddress )
       
  1527     TInt ipvType( KSatInvalidPdpType );
       
  1528     TInt length( aAddress.Length() );
       
  1529     
       
  1530     if ( &aAddress && length )
       
  1531         {
       
  1532         // The maximum length of a IP address is less than 39.
       
  1533         if ( KSatMaxIPv4AddressLength >= length && 
       
  1534                 KSatMinIPv4AddressLength <= length )
       
  1535             {
       
  1536             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1537             CLaunchBrowserHandler::ValidateGatewayAddress IPV4 address" )
       
  1538             // aAddress is a IPv4 address.
       
  1539             if ( ValidateIPv4Address( aAddress ) )
       
  1540                 {
       
  1541                 LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1542                 CLaunchBrowserHandler::ValidateGatewayAddress valid IPV4 \
       
  1543                 address" )
       
  1544                 ipvType = RPacketContext::EPdpTypeIPv4;
       
  1545                 }
       
  1546             }
       
  1547         else if ( KSatMaxIPv6AddressLength >= length && 
       
  1548                     KSatMinIPv6AddressLength <= length )
       
  1549             {
       
  1550             LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1551             CLaunchBrowserHandler::ValidateGatewayAddress IPV6 address" )
       
  1552             // aAddress is a IPv6 address.
       
  1553             if ( ValidateIPv6Address( aAddress ) )
       
  1554                 {
       
  1555                 LOG( SIMPLE, "LAUNCHBROWSER: \
       
  1556                 CLaunchBrowserHandler::ValidateGatewayAddress valid IPV6 \
       
  1557                 address" )
       
  1558                 ipvType = RPacketContext::EPdpTypeIPv6;
       
  1559                 }
       
  1560             }
       
  1561         }
       
  1562     
       
  1563     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1564         CLaunchBrowserHandler::ValidateGatewayAddress exiting,ipvType:%d",
       
  1565         ipvType )
       
  1566 
       
  1567     // Returned IP address.
       
  1568     return ipvType;
       
  1569     }
       
  1570 
       
  1571 // --------------------------------------------------------------------------
       
  1572 // Separate the port number from a address if it is existing. For example,
       
  1573 // 210.13.246.172:8080.
       
  1574 // --------------------------------------------------------------------------
       
  1575 void CLaunchBrowserHandler::SeparatePortNumberFromAddress( 
       
  1576     const TDesC16& aAddress, 
       
  1577     TDes16& aPureAddr,
       
  1578     TUint32& aPortNumber )
       
  1579     {
       
  1580     LOG2( SIMPLE, "LAUNCHBROWSER: \
       
  1581     CLaunchBrowserHandler::SeparatePortNumberFromAddress calling,\
       
  1582     aAddress: %s", &aAddress )
       
  1583 
       
  1584     // The following three variables are used to locate the port number.
       
  1585     TBool isSeparator( EFalse );
       
  1586     TBool portNumberBegin( EFalse );
       
  1587     TBool portNumberEnd( EFalse );
       
  1588     TBool pureAddrEnd( EFalse );
       
  1589     // Count delimiters in the address.
       
  1590     TInt delimiterCounter( 0 );
       
  1591     // Count symbols in a segment of the address.
       
  1592     TInt symbolCounter( 0 );
       
  1593     // Currsent position of the address descriptor.
       
  1594     TInt curPos( 0 );
       
  1595     TInt posOffset( 0 );
       
  1596     // The position of the last valid character.
       
  1597     TInt rightBound( 0 );
       
  1598     // Digital port number.
       
  1599     TUint32 portNumber( KSatLaunchBrowserProxyPortNumber );
       
  1600     // The descriptor pointer for the address.
       
  1601     TPtrC addrPtr;
       
  1602     // The length of the address.
       
  1603     TInt addrLen( 0 );
       
  1604     
       
  1605     // The address is a valid descriptor.
       
  1606     if ( NULL != &aAddress &&
       
  1607             KSatMinIPv4AddressLength <= aAddress.Length() )
       
  1608         {
       
  1609         addrPtr.Set( aAddress );
       
  1610         addrLen = aAddress.Length();
       
  1611         curPos = addrPtr.Find( KSatIPv4Delimiter );
       
  1612         
       
  1613         LOG2( SIMPLE, "CLaunchBrowserHandler::\
       
  1614         SeparatePortNumberFromAddress curPos: %i", curPos )
       
  1615         if ( KErrNotFound != curPos )
       
  1616             {
       
  1617             // Skip three delimiters in the IPv4 address.
       
  1618             delimiterCounter++;
       
  1619      
       
  1620             while ( KSatMaxIPv4SegmentCounter > delimiterCounter
       
  1621                         && curPos < addrLen )
       
  1622                 {
       
  1623                 curPos++;
       
  1624                 posOffset = addrPtr.Right( addrLen - curPos ).Find( 
       
  1625                                 KSatIPv4Delimiter );
       
  1626                 LOG2( SIMPLE, "CLaunchBrowserHandler::\
       
  1627                 SeparatePortNumberFromAddress posOffset: %i", posOffset )
       
  1628                 if ( KErrNotFound != posOffset )
       
  1629                     {
       
  1630                     delimiterCounter++;
       
  1631                     curPos += posOffset;
       
  1632                     }
       
  1633                 else
       
  1634                     {
       
  1635                     delimiterCounter = KSatMaxIPv4SegmentCounter;
       
  1636                     }
       
  1637                 }
       
  1638 
       
  1639             // Locate the separator between the pure address and 
       
  1640             // the port number.
       
  1641             curPos++;
       
  1642      
       
  1643             while ( curPos < addrLen 
       
  1644                 &&  KSatMaxIPv4SegmentLength > symbolCounter 
       
  1645                 && !isSeparator )
       
  1646                 {
       
  1647                 TChar ch( addrPtr[curPos] );
       
  1648      
       
  1649                 if ( ch.IsAlphaDigit() )
       
  1650                     {
       
  1651                     LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1652                     SeparatePortNumberFromAddress AlphaDigit" )
       
  1653                     symbolCounter++;
       
  1654                     }
       
  1655                 else
       
  1656                     {
       
  1657                     isSeparator = ETrue;
       
  1658                     }
       
  1659 
       
  1660                 curPos++;
       
  1661                 }
       
  1662             }
       
  1663         else
       
  1664             {
       
  1665             curPos = addrPtr.Find( KSatIPv6Delimiter );
       
  1666             LOG2( SIMPLE, "CLaunchBrowserHandler::\
       
  1667             SeparatePortNumberFromAddress curPos: %i", curPos )
       
  1668             if ( KErrNotFound != curPos )
       
  1669                 {
       
  1670                 // Skip seven delimiters in the IPv6 address.
       
  1671                 delimiterCounter++;
       
  1672      
       
  1673                 while ( KSatMaxIPv6SegmentCounter > delimiterCounter
       
  1674                             && curPos < addrLen )
       
  1675                     {
       
  1676                     curPos++;
       
  1677                     posOffset = addrPtr.Right( addrLen - curPos ).Find( 
       
  1678                                     KSatIPv6Delimiter );
       
  1679                     LOG2( SIMPLE, "CLaunchBrowserHandler::\
       
  1680                     SeparatePortNumberFromAddress posOffset: %i", posOffset )
       
  1681                     if ( KErrNotFound != posOffset )
       
  1682                         {
       
  1683                         delimiterCounter++;
       
  1684                         curPos += posOffset;
       
  1685                         }
       
  1686                     }
       
  1687 
       
  1688                 // Locate the separator between the pure address and 
       
  1689                 // the port number.
       
  1690                 curPos++;
       
  1691      
       
  1692                 while ( curPos < addrLen && 
       
  1693                             KSatMaxIPv6SegmentLength > symbolCounter && 
       
  1694                             !isSeparator )
       
  1695                     {
       
  1696                     TChar ch( addrPtr[curPos] );
       
  1697      
       
  1698                     if ( ch.IsAlphaDigit() )
       
  1699                         {
       
  1700                         LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1701                         SeparatePortNumberFromAddress AlphaDigit" )
       
  1702                         symbolCounter++;
       
  1703                         }
       
  1704                     else
       
  1705                         {
       
  1706                         isSeparator = ETrue;
       
  1707                         }
       
  1708 
       
  1709                     curPos++;
       
  1710                     }
       
  1711                 }
       
  1712             }
       
  1713 
       
  1714         // Extract the pure address.
       
  1715         while ( curPos < addrLen && KSatMinIPv4AddressLength < curPos 
       
  1716                 && !pureAddrEnd )
       
  1717             {
       
  1718             TChar ch( addrPtr[curPos] );
       
  1719             
       
  1720             if ( !ch.IsAlphaDigit() )
       
  1721                 {
       
  1722                 LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1723                 SeparatePortNumberFromAddress not AlphaDigit" )
       
  1724                 curPos--;
       
  1725                 }
       
  1726             else
       
  1727                 {
       
  1728                 pureAddrEnd = ETrue;
       
  1729                 }
       
  1730             }
       
  1731 
       
  1732         if ( curPos <= addrLen )
       
  1733             {
       
  1734             aPureAddr.Copy( addrPtr.Left( curPos + 1 ) );
       
  1735             }
       
  1736 
       
  1737         // Extract the port number.
       
  1738         // Locate the beginning of the port number.
       
  1739         curPos++;
       
  1740     
       
  1741         while ( curPos < addrLen && !portNumberBegin)
       
  1742             {
       
  1743             TChar ch( addrPtr[curPos] );
       
  1744 
       
  1745             if ( ch.IsDigit() )
       
  1746                 {
       
  1747                 LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1748                 SeparatePortNumberFromAddress Digit" )
       
  1749                 portNumberBegin = ETrue;
       
  1750                 }
       
  1751             else
       
  1752                 {
       
  1753                 curPos++;
       
  1754                 }
       
  1755             }
       
  1756         
       
  1757         // Locate the end of the port number.    
       
  1758         rightBound = addrLen;
       
  1759         rightBound--;
       
  1760 
       
  1761         while ( rightBound > curPos && !portNumberEnd )
       
  1762             {
       
  1763             TChar ch( addrPtr[rightBound] );
       
  1764 
       
  1765             if ( ch.IsDigit() )
       
  1766                 {
       
  1767                 LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1768                 SeparatePortNumberFromAddress Digit" )
       
  1769                 portNumberEnd = ETrue;
       
  1770                 }
       
  1771             else 
       
  1772                 {
       
  1773                 rightBound--;
       
  1774                 }
       
  1775             }
       
  1776         
       
  1777         // Convert the port number and validate it.
       
  1778         // Set the port number to default port number
       
  1779         aPortNumber = portNumber; 
       
  1780         if ( curPos < rightBound && rightBound < addrLen )
       
  1781             {
       
  1782             portNumber = ConvertDesToInt( 
       
  1783                 addrPtr.Mid( curPos, rightBound - curPos + 1 ) );
       
  1784 
       
  1785             if ( KSatMaxProxyPortNumber > portNumber &&
       
  1786                     KSatMinProxyPortNumber < portNumber )
       
  1787                 {
       
  1788                 LOG( SIMPLE, "CLaunchBrowserHandler::\
       
  1789                 SeparatePortNumberFromAddress valid portNumber" )
       
  1790                 aPortNumber = portNumber;
       
  1791                 }
       
  1792             }
       
  1793         }
       
  1794         
       
  1795     LOG( SIMPLE, 
       
  1796     "LAUNCHBROWSER: CLaunchBrowserHandler::SeparatePortNumberFromAddress \
       
  1797     exiting" )
       
  1798     }
       
  1799 
       
  1800 // --------------------------------------------------------------------------
       
  1801 // Fulfill connecion method params with default params.
       
  1802 // --------------------------------------------------------------------------
       
  1803 void CLaunchBrowserHandler::FulfillConnnectionMethodL( 
       
  1804     RCmManager& aCmManager,
       
  1805     RCmConnectionMethod& aCm )
       
  1806     {
       
  1807     LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1808         FulfillConnnectionMethodL calling" )
       
  1809     
       
  1810     // The following 3 lines are used to preset the default parameters
       
  1811     // to avoid doing nothing for them if leaving.
       
  1812     aCm.SetStringAttributeL( CMManager::EPacketDataAPName, 
       
  1813         KSatGprsAccessPointName );
       
  1814     aCm.SetBoolAttributeL( CMManager::ECmIFPromptForAuth, EFalse );
       
  1815     aCm.SetBoolAttributeL( CMManager::ECmDisablePlainTextAuth, EFalse );
       
  1816         
       
  1817     // Get default access point ID.
       
  1818     RCmConnectionMethod defCm;
       
  1819     CleanupClosePushL( defCm );
       
  1820     
       
  1821     TInt ret ( KErrNotFound );
       
  1822     GetDefConnMethodL( aCmManager, defCm, ret );
       
  1823     
       
  1824     if ( !ret )
       
  1825         {
       
  1826         // Default AP found! Copy parameters from
       
  1827         // default AP to new created AP.
       
  1828         
       
  1829         // Copy AP name.
       
  1830         HBufC* strValue = defCm.GetStringAttributeL( 
       
  1831             CMManager::EPacketDataAPName );
       
  1832         LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1833             FulfillConnnectionMethodL AP Name is %s", strValue )
       
  1834         CleanupStack::PushL( strValue );
       
  1835         aCm.SetStringAttributeL( CMManager::EPacketDataAPName, *strValue );
       
  1836         CleanupStack::PopAndDestroy( strValue );
       
  1837         
       
  1838         // Copy authentic name
       
  1839         strValue = defCm.GetStringAttributeL( CMManager::ECmIFAuthName );
       
  1840         LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1841             FulfillConnnectionMethodL Auch name is %s", strValue )
       
  1842         CleanupStack::PushL( strValue );
       
  1843         aCm.SetStringAttributeL( CMManager::ECmIFAuthName, *strValue );
       
  1844         CleanupStack::PopAndDestroy( strValue );
       
  1845         
       
  1846         // Copy authentic pass
       
  1847         strValue = defCm.GetStringAttributeL( CMManager::ECmIFAuthPass );
       
  1848         LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1849             FulfillConnnectionMethodL Auch pass is %s", strValue )
       
  1850         CleanupStack::PushL( strValue );
       
  1851         aCm.SetStringAttributeL( CMManager::ECmIFAuthPass, *strValue );
       
  1852         CleanupStack::PopAndDestroy( strValue );
       
  1853         
       
  1854         // Copy default URL
       
  1855         strValue = defCm.GetStringAttributeL( CMManager::ECmStartPage );
       
  1856         LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1857             FulfillConnnectionMethodL Start page pass is %s", strValue )
       
  1858         CleanupStack::PushL( strValue );
       
  1859         aCm.SetStringAttributeL( CMManager::ECmStartPage, *strValue );
       
  1860         CleanupStack::PopAndDestroy( strValue );
       
  1861         
       
  1862         // Copy status if prompt for auth
       
  1863         TBool bValue = defCm.GetBoolAttributeL( 
       
  1864                 CMManager::ECmIFPromptForAuth );
       
  1865         aCm.SetBoolAttributeL( CMManager::ECmIFPromptForAuth, bValue );
       
  1866         
       
  1867         // Copy security status.
       
  1868         bValue = defCm.GetBoolAttributeL( 
       
  1869                 CMManager::ECmDisablePlainTextAuth );
       
  1870         aCm.SetBoolAttributeL( CMManager::ECmIFPromptForAuth, bValue );
       
  1871         }
       
  1872         
       
  1873     CleanupStack::PopAndDestroy( &defCm );
       
  1874     
       
  1875     LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1876         FulfillConnnectionMethodL exiting" )
       
  1877     }
       
  1878 
       
  1879 // --------------------------------------------------------------------------
       
  1880 // Check the validity of offered bearer type
       
  1881 // --------------------------------------------------------------------------
       
  1882 void CLaunchBrowserHandler::ValidateBearerTypeL( RCmConnectionMethod& aCm, 
       
  1883                                                  TInt& aIsValid )
       
  1884     {
       
  1885     LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1886          ValidateBearerTypeL calling" )
       
  1887         
       
  1888     TUint32 bearerType = aCm.GetIntAttributeL( 
       
  1889         CMManager::ECmBearerType );
       
  1890     LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1891         ValidateBearerTypeL bearerType=0x%x", bearerType )
       
  1892     
       
  1893     if ( KUidPacketDataBearerType == bearerType )
       
  1894         {
       
  1895         LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1896             ValidateBearerTypeL bearer type is GPRS" )
       
  1897         aIsValid = KErrNone;
       
  1898         }
       
  1899     
       
  1900     LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1901           ValidateBearerTypeL exiting, aIsValid=%d", aIsValid )
       
  1902     }
       
  1903 
       
  1904 // --------------------------------------------------------------------------
       
  1905 // Get default connection method
       
  1906 // --------------------------------------------------------------------------
       
  1907 void CLaunchBrowserHandler::GetDefConnMethodL( RCmManager& aCmManager,
       
  1908                                                RCmConnectionMethod& aDefCm,
       
  1909                                                TInt& aIsValid )
       
  1910     {
       
  1911     LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1912          GetDefConnMethodL calling" )   
       
  1913          
       
  1914     // Go through the default connection methods to find 
       
  1915     // the one valid connection method.   
       
  1916     TCmDefConnValue defConn;
       
  1917     aCmManager.ReadDefConnL( defConn );
       
  1918     
       
  1919     LOG3( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1920       GetDefConnMethodL DefConn type=%d, id=%d", 
       
  1921       defConn.iType, defConn.iId )
       
  1922     
       
  1923     // Mark aIsFound as KErrNone if there is one valid 
       
  1924     // connection method, otherwise KErrNotFound.
       
  1925     aIsValid = KErrNotFound;
       
  1926     
       
  1927     // Default setting is a connection method
       
  1928     if ( ECmDefConnConnectionMethod == defConn.iType )
       
  1929         {
       
  1930         LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1931              GetDefConnMethodL ECmDefConnConnectionMethod" )
       
  1932         aDefCm = aCmManager.ConnectionMethodL( defConn.iId );
       
  1933         // Check bearer type, leave if not GPRS
       
  1934         ValidateBearerTypeL( aDefCm, aIsValid );
       
  1935         }
       
  1936 
       
  1937     // Default setting is a destination
       
  1938     else if ( ECmDefConnDestination == defConn.iType )
       
  1939         {
       
  1940         LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1941             GetDefConnMethodL ECmDefConnDestination" )
       
  1942         RCmDestination defDes = aCmManager.DestinationL( defConn.iId );
       
  1943         
       
  1944         TInt desCount = defDes.ConnectionMethodCount();
       
  1945         
       
  1946         LOG2( SIMPLE, "SATENGINE: CLaunchBrowserHandler::\
       
  1947             GetDefConnMethodL ECmDefConnDestination count=%d",
       
  1948             desCount )
       
  1949         
       
  1950         for ( TInt i = 0; 
       
  1951               desCount > 0 && aIsValid != KErrNone && i < desCount; i++ )
       
  1952             {
       
  1953             // Go through all the connection methods, 
       
  1954             // until find a valid one.
       
  1955             aDefCm = defDes.ConnectionMethodL( i );
       
  1956             ValidateBearerTypeL( aDefCm, aIsValid );
       
  1957             }
       
  1958         }
       
  1959     else
       
  1960         {
       
  1961         aIsValid = KErrNotFound;
       
  1962         }
       
  1963     LOG( SIMPLE, "SATENGINE: CLaunchBrowserHandler::GetDefConnMethodL exit" )
       
  1964     }
       
  1965 // End Of File