IMPSengine/imapi/src/loginmngr.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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: Class for handling the login issues.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <Cwvsapsettingsstore.h>
       
    22 #include <Cwvsapsettings.h>
       
    23 #include <imerrors.h>
       
    24 #include "loginmngr.h"
       
    25 #include "apiutils.h"
       
    26 #include "imconnectionimpl.h"
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CLoginManager::CLoginManager
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CLoginManager::CLoginManager( RImpsEng& aEngine, CImConnectionImpl& aConnection )
       
    38         :   CActive( EPriorityStandard ),
       
    39         iState( EReady ),
       
    40         iLoggedIn( EFalse ),
       
    41         iEngine( aEngine ),
       
    42         iEngineState( EImps_NOT_LOGGED ),
       
    43         iObserver( NULL ),
       
    44         iConnection( aConnection )
       
    45     {
       
    46 #ifdef _DEBUG
       
    47     CImApiLogger::Log( _L( "CLoginManager: Construction" ) );
       
    48 #endif
       
    49     CActiveScheduler::Add( this );
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CLoginManager::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CLoginManager::ConstructL()
       
    58     {
       
    59     User::LeaveIfError( iEngine.Connect() );
       
    60     // Register to the IMPS Access Client
       
    61     iAccessClient.RegisterL( iEngine, this );
       
    62     iAccessClient.RegisterErrorObserverL( *this );
       
    63 
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CLoginManager::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CLoginManager* CLoginManager::NewL( RImpsEng& aEngine,
       
    72                                     CImConnectionImpl& aConnection )
       
    73     {
       
    74     CLoginManager* self = new( ELeave ) CLoginManager( aEngine, aConnection );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop();
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // Destructor
       
    83 CLoginManager::~CLoginManager()
       
    84     {
       
    85 #ifdef _DEBUG
       
    86     CImApiLogger::Log( _L( "CLoginManager: Destruction" ) );
       
    87 #endif
       
    88     Cancel();
       
    89     iAccessClient.Unregister();
       
    90     TRAPD( err, iAccessClient.UnregisterErrorObserverL() );
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CLoginManager::HandleLoginL
       
    96 //
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CLoginManager::HandleLoginL(
       
   101     TInt /*aId*/,
       
   102     TImpsCspIdentifier& /*aCspId*/ )
       
   103     {
       
   104 #ifdef _DEBUG
       
   105     CImApiLogger::Log( _L( "CLoginManager: HandleLogin" ) );
       
   106 #endif
       
   107 
       
   108     iLoggedIn = ETrue;
       
   109 
       
   110     TRequestStatus* status = &iStatus;
       
   111     User::RequestComplete( status, KErrNone );
       
   112     }
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CLoginManager::HandleLoginCancelL
       
   117 //
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CLoginManager::HandleLoginCancelL(
       
   121     TInt aCancelledOpId,
       
   122     TImpsCspIdentifier& /*aCspId*/ )
       
   123     {
       
   124 
       
   125     }
       
   126 // -----------------------------------------------------------------------------
       
   127 // CLoginManager::HandleLoginStatusL
       
   128 //
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 //void CLoginManager::HandleLoginStatusL(
       
   132 //                                      TInt /*aId*/,
       
   133 //                                      TInt aStatus,
       
   134 //                                      TBool aIsLoggedIn )
       
   135 //    {
       
   136 //#ifdef _DEBUG
       
   137 //    CImApiLogger::Log(_L("CLoginManager: HandleLoginStatus: %d"), aStatus);
       
   138 //    CImApiLogger::Log(_L("CLoginManager: Is logged in: %d"), aIsLoggedIn);
       
   139 //#endif
       
   140 //    iLoggedIn = aIsLoggedIn;
       
   141 //    TRequestStatus* status = &iStatus;
       
   142 //    User::RequestComplete(status, aStatus);
       
   143 //    }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CLoginManager::HandleLogoutL
       
   147 //
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CLoginManager::HandleLogoutL( TInt /*aId*/,
       
   151                                    TImpsCspIdentifier& aCspId )
       
   152     {
       
   153 #ifdef _DEBUG
       
   154     CImApiLogger::Log( _L( "CLoginManager: HandleLogoutL" ) );
       
   155 #endif
       
   156 
       
   157     iLoggedIn = EFalse;
       
   158 
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CLoginManager::HandleErrorL
       
   164 //
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CLoginManager::HandleErrorL( TInt aStatus,
       
   168                                   TInt /*aOpId*/,
       
   169                                   const TDesC* /*aDescription*/,
       
   170                                   const CImpsDetailed* /*aDetailedRes*/,
       
   171                                   TImpsCspIdentifier& aCspId )
       
   172     {
       
   173 #ifdef _DEBUG
       
   174     CImApiLogger::Log( _L( "CLoginManager: Error received: %d" ), aStatus );
       
   175 #endif
       
   176     TRequestStatus* status = &iStatus;
       
   177     User::RequestComplete( status, aStatus );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CLoginManager::HandleStatusChangeL
       
   182 //
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CLoginManager::HandleStatusChangeL( TImpsServiceStatus aStatus )
       
   186     {
       
   187 #ifdef _DEBUG
       
   188     CImApiLogger::Log( _L( "CLoginManager: Status changed: %d" ), aStatus );
       
   189 #endif
       
   190     iEngineState = aStatus;
       
   191 
       
   192     switch ( aStatus )
       
   193         {
       
   194         case EImps_NOT_LOGGED:
       
   195             iLoggedIn = EFalse;
       
   196             break;
       
   197         case EImps_ON_LINE:
       
   198             iLoggedIn = ETrue;
       
   199             break;
       
   200 
       
   201         case EImps_OFF_LINE:
       
   202         case EImps_NO_IAP:
       
   203         default:
       
   204             break;
       
   205         }
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CLoginManager::HandleNbrSessionsL
       
   210 //
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CLoginManager::HandleNbrSessionsL( TInt /*aId*/,
       
   214                                         TInt /*aNbr*/,
       
   215                                         TImpsCspIdentifier& /*aCspId*/ )
       
   216     {
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CLoginManager::StartRegistration
       
   221 //
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 TInt CLoginManager::StartLogin( MLoginObserver* aObserver )
       
   225     {
       
   226 //#ifdef _DEBUG
       
   227 //    CImApiLogger::Log(_L("CLoginManager: Login started"));
       
   228 //#endif
       
   229 //
       
   230 //    if ( IsActive() )
       
   231 //        {
       
   232 //        return KImApiErrConnectingInProgress;
       
   233 //        }
       
   234 //    iObserver = aObserver;
       
   235 //    iState = EInitializing;
       
   236 //    iStatus = KRequestPending;
       
   237 //    SetActive();
       
   238 //    TRequestStatus* status = &iStatus;
       
   239 //    User::RequestComplete(status, KErrNone);
       
   240     return KErrNone;
       
   241     }
       
   242 //
       
   243 // -----------------------------------------------------------------------------
       
   244 // CLoginManager::IsLoggedIn()
       
   245 //
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 TBool CLoginManager::IsLoggedIn() const
       
   249     {
       
   250     return iLoggedIn;
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CLoginManager::EngineStatus()
       
   255 //
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 TImpsServiceStatus CLoginManager::EngineStatus() const
       
   259     {
       
   260     return iEngineState;
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CLoginManager::CancelLogin()
       
   265 //
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 
       
   269 void CLoginManager::CancelLogin( )
       
   270     {
       
   271 #ifdef _DEBUG
       
   272     CImApiLogger::Log( _L( "CLoginManager: Login canceled" ) );
       
   273 #endif
       
   274     Cancel();
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CLoginManager::RunL
       
   279 //
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CLoginManager::RunL()
       
   283     {
       
   284 
       
   285     User::LeaveIfError( iStatus.Int() );
       
   286 
       
   287     switch ( iState )
       
   288         {
       
   289         case EInitializing:
       
   290             {
       
   291 #ifdef _DEBUG
       
   292             CImApiLogger::Log( _L( "CLoginManager: Calling IsLoggedIn()" ) );
       
   293 #endif
       
   294 //            iAccessClient.IsLoggedInL();
       
   295             iState = ELoggingIn;
       
   296             iStatus = KRequestPending;
       
   297             SetActive();
       
   298             }
       
   299         break;
       
   300 
       
   301         case ELoggingIn:
       
   302             if ( !iLoggedIn )
       
   303                 { // Do Login
       
   304                 // Get the default login params from SAP settings
       
   305                 CWVSAPSettingsStore* store = CWVSAPSettingsStore::NewLC(); // <<<
       
   306                 CWVSAPSettings* sapSettings = CWVSAPSettings::NewLC();     // <<<
       
   307                 store->GetDefaultL( *sapSettings );
       
   308                 const TDesC& server = sapSettings->SAPAddress();
       
   309                 const TDesC& user = sapSettings->SAPUserId();
       
   310                 const TDesC& passwd = sapSettings->SAPUserPassword();
       
   311                 const TDesC& clientId = sapSettings->ClientId();
       
   312                 TUint32 myAP = sapSettings->AccessPoint();
       
   313 //                const TDesC& proxy = sapSettings->HTTPProxyAddress();
       
   314                 const TDesC& key1 = sapSettings->SAPSpecificString1();
       
   315                 const TDesC& key2 = sapSettings->SAPSpecificString2();
       
   316 
       
   317 #ifdef _DEBUG
       
   318                 CImApiLogger::Log( _L( "CLoginManager: Logging in:" ) );
       
   319                 CImApiLogger::Log( _L( "    Server: %S" ), &server );
       
   320                 CImApiLogger::Log( _L( "    User: %S" ), &user );
       
   321                 CImApiLogger::Log( _L( "    Password: %S" ), &passwd );
       
   322 //                CImApiLogger::Log(_L("    ClientID: %S"),iClientID);
       
   323                 CImApiLogger::Log( _L( "    IAP: %d" ), myAP );
       
   324 //                CImApiLogger::Log(_L("    Proxy: %S"),&proxy);
       
   325 
       
   326 #endif
       
   327 
       
   328 #ifdef _DEBUG
       
   329                 CImApiLogger::Log( _L( "CLoginManager: Logging in" ) );
       
   330 #endif
       
   331 //                iAccessClient.LoginL(
       
   332 //                    server,
       
   333 //                    user,
       
   334 //                    passwd,
       
   335 //                    // because of AOL we need the client ID from SAP settings
       
   336 //                    // iConnection.ClientId(),
       
   337 //                    clientId,
       
   338 //                    myAP,
       
   339 //                    //proxy, Not used!
       
   340 //                    KNullDesC,
       
   341 //                    &key1,
       
   342 //                    &key2);
       
   343 
       
   344                 iState = EFinishing;
       
   345                 iStatus = KRequestPending;
       
   346                 SetActive();
       
   347 
       
   348                 CleanupStack::PopAndDestroy( 2 );   // >>> sapSettings, store
       
   349                 }
       
   350             else
       
   351                 {
       
   352                 // already logged in -> just finish
       
   353 #ifdef _DEBUG
       
   354                 CImApiLogger::Log( _L( "CLoginManager: Already logged in." ) );
       
   355 #endif
       
   356                 iState = EFinishing;
       
   357                 iStatus = KRequestPending;
       
   358                 SetActive();
       
   359                 TRequestStatus* s = &iStatus;
       
   360                 User::RequestComplete( s, KErrNone );
       
   361 
       
   362                 }
       
   363 
       
   364             break;
       
   365 
       
   366         case EFinishing:
       
   367             NotifyObserver( KErrNone );
       
   368             iState = EReady;
       
   369             break;
       
   370 
       
   371         case EReady:
       
   372         default:
       
   373             break;
       
   374         }
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CLoginManager::RunError
       
   379 //
       
   380 // Returns: <KErrNone>:
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 TInt CLoginManager::RunError( TInt aError )
       
   384     {
       
   385 #ifdef _DEBUG
       
   386     CImApiLogger::Log( _L( "CLoginManager: RunL leaves: %d" ), aError );
       
   387 #endif
       
   388     NotifyObserver( aError );
       
   389     return KErrNone;
       
   390     }
       
   391 
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CLoginManager::DoCancel
       
   395 //
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 void CLoginManager::DoCancel()
       
   399     {
       
   400     iState = EInitializing;
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CLoginManager::NotifyObservers
       
   405 //
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void CLoginManager::NotifyObserver( TInt aError )
       
   409     {
       
   410     iObserver->HandleLogin( aError );
       
   411     }
       
   412 
       
   413 //  End of File