|
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: AA login control. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <E32std.h> |
|
20 #include <CIMPSSAPSettingsStore.h> |
|
21 #include <CIMPSSAPSettings.h> |
|
22 #include <PEngWVPresenceErrors2.h> |
|
23 #include <impserrors.h> |
|
24 #include <IMPSConnectionUiNG.rsg> |
|
25 #include <CPEngNWSessionSlotID2.h> |
|
26 #include <CPEngNWSessionSlotManager2.h> |
|
27 #include <PEngPresenceEngineConsts2.h> |
|
28 |
|
29 #include "CCnUiAALoginCntrlStep.h" |
|
30 #include "CCnUiConnOpener.h" |
|
31 #include "CCnUiConnCloser.h" |
|
32 |
|
33 #include "MCnUiBaseControlContext.h" |
|
34 #include "MCnUiConnectionHandler.h" |
|
35 #include "MCnUiSignaller.h" |
|
36 #include "MCnUiGlobalNotificationUiFacade.h" |
|
37 |
|
38 #include "CnUiErrors.h" |
|
39 |
|
40 #include "CnUiClientId.h" |
|
41 |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 // Two-phased constructor. |
|
45 CCnUiAALoginCntrlStep* CCnUiAALoginCntrlStep::NewLC( MCnUiBaseControlContext& aCCntxt, |
|
46 CIMPSSAPSettings& aLoginSap, |
|
47 TBool aShowDetailedError, |
|
48 CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
49 { |
|
50 CCnUiAALoginCntrlStep* self = new ( ELeave ) CCnUiAALoginCntrlStep( aCCntxt, aLoginSap, |
|
51 aShowDetailedError, aNWSessionSlotID ); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // Destructor |
|
59 CCnUiAALoginCntrlStep::~CCnUiAALoginCntrlStep() |
|
60 { |
|
61 delete iConnOpener; |
|
62 delete iConnCloser; |
|
63 delete iLogoutPlugin; |
|
64 } |
|
65 |
|
66 |
|
67 // C++ default constructor can NOT contain any code, that |
|
68 // might leave. |
|
69 // |
|
70 CCnUiAALoginCntrlStep::CCnUiAALoginCntrlStep( MCnUiBaseControlContext& aCCntxt, |
|
71 CIMPSSAPSettings& aLoginSap, |
|
72 TBool aShowDetailedError, |
|
73 CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
74 : iCCntxt( aCCntxt ), |
|
75 iLoginSap( aLoginSap ), |
|
76 iShowDetailedError( aShowDetailedError ), |
|
77 iNWSessionSlotID( aNWSessionSlotID ) |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 // Symbian OS default constructor can leave. |
|
83 void CCnUiAALoginCntrlStep::ConstructL() |
|
84 { |
|
85 iConnOpener = CCnUiConnOpener::NewL(); |
|
86 iConnCloser = CCnUiConnCloser::NewL(); |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCnUiAALoginCntrlStep::RunStepL() |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CCnUiAALoginCntrlStep::RunStepL() |
|
95 { |
|
96 TInt mappedError = KErrNone; |
|
97 TInt errorDetail = KErrNone; |
|
98 |
|
99 switch ( DoRunStepL() ) |
|
100 { |
|
101 case KErrNone: // Login succeeded |
|
102 { |
|
103 //this is returned as is |
|
104 mappedError = KErrNone; |
|
105 break; |
|
106 } |
|
107 |
|
108 case KCnUiErrorClientAlreadyConnected: |
|
109 { |
|
110 //Current client is already logged in. (Thus not a real error.) |
|
111 mappedError = KErrAlreadyExists; |
|
112 break; |
|
113 } |
|
114 |
|
115 |
|
116 case KErrAccessDenied: |
|
117 case KCnUiErrorNetworkConnectionNotAllowed: // //network access denied |
|
118 { |
|
119 mappedError = KErrAccessDenied; |
|
120 errorDetail = R_QTN_CHAT_LOGIN_CONERROR_NOTE; |
|
121 break; |
|
122 } |
|
123 |
|
124 |
|
125 case KCnUiErrorSapMissingCompulsoryFields: |
|
126 case KCnUiErrorNoProperDefaultSap: |
|
127 { |
|
128 //Missing the whole default SAP |
|
129 //or it was missing some required fields. |
|
130 mappedError = KErrNotFound; |
|
131 errorDetail = R_QTN_CHAT_SETT_COMP_MISS; |
|
132 break; |
|
133 } |
|
134 |
|
135 |
|
136 case KPEngNwErrInvalidPassword: |
|
137 case KPEngNwErrUnknownUser: |
|
138 case KPEngNwErrInvalidOrUnSupportedUserProperties: |
|
139 case KPEngNwErrUnauthorized: |
|
140 { |
|
141 //wrong username / password |
|
142 //free first plug-in dynamic resources |
|
143 TIMPSConnectionClient clientId = iCCntxt.ControlledClient(); |
|
144 iCCntxt.ClientPluginL( clientId, iNWSessionSlotID ).ReleaseDynamicResources(); |
|
145 |
|
146 iCCntxt.GlobalNotificationUiL().ShowLoginUserDataErrorL( iLoginSap.SAPName() ); |
|
147 mappedError = KErrArgument; |
|
148 break; |
|
149 } |
|
150 |
|
151 case KCnUiErrorAlreadyConnectedToAnotherSap: |
|
152 { |
|
153 // user declined disconnect from manually logged in sap |
|
154 mappedError = KErrCouldNotDisconnect; |
|
155 break; |
|
156 } |
|
157 |
|
158 case KPEngNwErrForbidden:// 403 |
|
159 { |
|
160 errorDetail = R_QTN_CHAT_LOGIN_ACCOUNT_LOST; |
|
161 mappedError = KErrAccessDenied; |
|
162 break; |
|
163 } |
|
164 |
|
165 //flow through |
|
166 case KPEngNwErrServiceNotSupported: // 405 |
|
167 case KPEngNwErrServiceNotAgreed: // 506 |
|
168 { |
|
169 mappedError = KErrNotSupported; |
|
170 errorDetail = R_QTN_CHAT_ERROR_SERVICE_ERR; |
|
171 break; |
|
172 } |
|
173 |
|
174 // flow through |
|
175 case KPEngNwErrServiceUnavailable: // 503 |
|
176 case KPEngNwErrMessageQueueIsFull: // 507 |
|
177 { |
|
178 mappedError = KErrCouldNotConnect; |
|
179 errorDetail = R_QTN_CHAT_ERROR_SERV_BUSY; |
|
180 break; |
|
181 } |
|
182 |
|
183 case KPEngNwErrVersionNotSupported: // 505 |
|
184 { |
|
185 mappedError = KErrGeneral; |
|
186 errorDetail = R_QTN_CHAT_ERROR_GEN_ERROR; |
|
187 break; |
|
188 } |
|
189 |
|
190 // flow through |
|
191 case KPEngNwErrSessionExpired: // 600 |
|
192 case KErrTimedOut: |
|
193 case KErrCouldNotConnect: |
|
194 case KImpsErrorBearerSuspended: |
|
195 { |
|
196 mappedError = KErrCouldNotConnect; |
|
197 errorDetail = R_QTN_CHAT_LOGIN_CONERROR_NOTE; |
|
198 break; |
|
199 } |
|
200 |
|
201 default: |
|
202 { |
|
203 //General failure during login (no connection to network, etc..) |
|
204 mappedError = KErrGeneral; |
|
205 errorDetail = R_QTN_CHAT_LOGIN_CONERROR_NOTE; |
|
206 break; |
|
207 } |
|
208 } |
|
209 |
|
210 // if there was some other error than login data error, we must |
|
211 // show a detailed error note if aa plugin requested so |
|
212 if ( ( mappedError != KErrNone ) && ( mappedError != KErrArgument ) && ( iShowDetailedError ) ) |
|
213 { |
|
214 //free first plug-in dynamic resources |
|
215 TIMPSConnectionClient clientId = iCCntxt.ControlledClient(); |
|
216 iCCntxt.ClientPluginL( clientId, iNWSessionSlotID ).ReleaseDynamicResources(); |
|
217 |
|
218 iCCntxt.GlobalNotificationUiL().ShowLoginDetailedErrorL( iLoginSap.SAPName(), errorDetail ); |
|
219 } |
|
220 |
|
221 return mappedError; |
|
222 } |
|
223 |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CCnUiAALoginCntrlStep::DoRunStepL() |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CCnUiAALoginCntrlStep::DoRunStepL() |
|
230 { |
|
231 TIMPSConnectionClient clientId = iCCntxt.ControlledClient(); |
|
232 |
|
233 //First make sure that there isn't already another login |
|
234 //operation running (if there is, then no need to select SAP...) |
|
235 if ( iCCntxt.Signaller().OperationRunning() ) |
|
236 { |
|
237 return KCnUiErrorLoginOperationAlreadyInUse; |
|
238 } |
|
239 |
|
240 // Check if client is already logged to DEFAULT server |
|
241 CIMPSSAPSettings* defaultSap = CIMPSSAPSettings::NewLC(); |
|
242 LoadDefaultSapL( *defaultSap ); |
|
243 TCnUiSapCnStatus status = iCCntxt.ConnHandler().SapConnectionStatusL( *defaultSap, clientId ); |
|
244 CleanupStack::PopAndDestroy( defaultSap ); |
|
245 |
|
246 if ( status == ECnUiSCS_SapConnected ) |
|
247 { |
|
248 // connected to the same server. otherwise logout |
|
249 // |
|
250 // or different server) |
|
251 return KCnUiErrorClientAlreadyConnected; |
|
252 } |
|
253 |
|
254 //load SAP & handle its errors |
|
255 TInt loadStatus = LoadDefaultSapL( iLoginSap ); |
|
256 if ( loadStatus != KErrNone ) |
|
257 { |
|
258 iLoginSap.Reset(); |
|
259 return loadStatus; |
|
260 } |
|
261 |
|
262 //Signal to other clients that login operation is started. |
|
263 if ( iCCntxt.Signaller().SignalOperationL( iLoginSap.SAPName() ) == KErrInUse ) |
|
264 { |
|
265 //some other client has started the login during SAP load... |
|
266 return KCnUiErrorLoginOperationAlreadyInUse; |
|
267 } |
|
268 |
|
269 if ( iLoginSap.ClientId().Length() == 0 ) |
|
270 { |
|
271 iLoginSap.SetClientIdL( KClientId() ); |
|
272 } |
|
273 |
|
274 |
|
275 // set the network session slot ID |
|
276 iNWSessionSlotID.SetServiceAddressL( iLoginSap.SAPAddress() ); |
|
277 iNWSessionSlotID.SetUserIdL( iLoginSap.SAPUserId() ); |
|
278 |
|
279 if ( clientId == EIMPSConnClientIM ) |
|
280 { |
|
281 iNWSessionSlotID.SetAppIdL( KPEngAppIdIM() ); |
|
282 } |
|
283 else |
|
284 { |
|
285 iNWSessionSlotID.SetAppIdL( KPEngAppIdPEC() ); |
|
286 } |
|
287 |
|
288 // create a network session slot to PEC engine |
|
289 CPEngNWSessionSlotManager2* slotManager = CPEngNWSessionSlotManager2::NewLC(); |
|
290 |
|
291 TInt err = slotManager->CreateNWSessionSlot( iNWSessionSlotID ); |
|
292 // we can ignore KErrAlreadyExist, since if the error is that |
|
293 // we can just start using the slot |
|
294 if ( ( err != KErrNone ) && ( err != KErrAlreadyExists ) ) |
|
295 { |
|
296 User::Leave( err ); |
|
297 } |
|
298 CleanupStack::PopAndDestroy( slotManager ); |
|
299 //ok to try login |
|
300 TInt loginTrieStatus = iConnOpener->MakeLoginForClient( |
|
301 clientId, |
|
302 iLoginSap, |
|
303 iCCntxt.ClientPluginL( clientId, iNWSessionSlotID ), |
|
304 iCCntxt.ConnHandler(), |
|
305 NULL, |
|
306 iNWSessionSlotID ); |
|
307 |
|
308 |
|
309 if ( loginTrieStatus == KCnUiErrorAlreadyConnectedToAnotherSap ) |
|
310 { |
|
311 // we are already connected to another sap, so we need to logout first |
|
312 |
|
313 // create global notification ui facade for sending channel message |
|
314 MCnUiGlobalNotificationUiFacade* uiFacade = &( iCCntxt.GlobalNotificationUiL() ); |
|
315 |
|
316 RArray<TIMPSConnectionClient> loggedInClients; |
|
317 CleanupClosePushL( loggedInClients ); |
|
318 iCCntxt.ConnHandler().GetLoggedInClientsL( loggedInClients ); |
|
319 |
|
320 // ask a confirmation from the user |
|
321 if ( uiFacade->CGQActiveConnectionSuppressForScheduledConnectionL( |
|
322 iLoginSap.SAPName(), |
|
323 loggedInClients.Array() ) ) |
|
324 { |
|
325 loginTrieStatus = KErrNone; |
|
326 |
|
327 // user accepted logout of query timed out -> do the logout |
|
328 CIMPSSAPSettings* logoutSap = CIMPSSAPSettings::NewLC(); |
|
329 //get SAP from where logging out.. |
|
330 iCCntxt.ConnHandler().GetLoggedInSapL( *logoutSap, clientId ); |
|
331 |
|
332 CPEngNWSessionSlotID2* logoutID = NULL; |
|
333 logoutID = iCCntxt.GetActiveNWSessionSlotIDL( clientId ); |
|
334 CleanupStack::PushL( logoutID ); |
|
335 TInt logoutStatus( KErrNone ); |
|
336 |
|
337 delete iLogoutPlugin; |
|
338 iLogoutPlugin = NULL; |
|
339 iLogoutPlugin = CreateClientPluginL( clientId, *logoutID ); |
|
340 |
|
341 for ( TInt index = 0; index < loggedInClients.Count(); index++ ) |
|
342 { |
|
343 //close the client connection using the connection closer |
|
344 logoutStatus = iConnCloser->MakeLogoutForClient( loggedInClients.Array()[ index ], |
|
345 *logoutSap, |
|
346 *iLogoutPlugin, |
|
347 iCCntxt.ConnHandler(), |
|
348 NULL, |
|
349 *logoutID ); |
|
350 if ( logoutStatus != KErrNone ) |
|
351 { |
|
352 // logout did not succeed, exit the loop |
|
353 loginTrieStatus = logoutStatus; |
|
354 break; |
|
355 } |
|
356 } |
|
357 |
|
358 if ( loginTrieStatus == KErrNone ) |
|
359 { |
|
360 // logout(s) successful -> do the login |
|
361 loginTrieStatus = iConnOpener->MakeLoginForClient( clientId, |
|
362 iLoginSap, |
|
363 iCCntxt.ClientPluginL( clientId, iNWSessionSlotID ), |
|
364 iCCntxt.ConnHandler(), |
|
365 NULL, |
|
366 iNWSessionSlotID ); |
|
367 } |
|
368 delete iLogoutPlugin; |
|
369 iLogoutPlugin = NULL; |
|
370 CleanupStack::PopAndDestroy( logoutID ); |
|
371 CleanupStack::PopAndDestroy( logoutSap ); |
|
372 } |
|
373 CleanupStack::PopAndDestroy(); // loggedInClients |
|
374 } |
|
375 |
|
376 return loginTrieStatus; |
|
377 } |
|
378 |
|
379 |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CCnUiAALoginCntrlStep::HandleCompleteL() |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 TCnUiHandleCompleteStatus CCnUiAALoginCntrlStep::HandleCompleteL() |
|
386 { |
|
387 iCCntxt.Signaller().CancelOperationSignal(); |
|
388 return ECnUiStepContinueTeardown; |
|
389 } |
|
390 |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CCnUiAALoginCntrlStep::HandleCompleteL() |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void CCnUiAALoginCntrlStep::UndoStepL() |
|
397 { |
|
398 iCCntxt.Signaller().CancelOperationSignal(); |
|
399 } |
|
400 |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CCnUiAALoginCntrlStep::LoadDefaultSapL() |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 TInt CCnUiAALoginCntrlStep::LoadDefaultSapL( CIMPSSAPSettings& aSap ) |
|
407 { |
|
408 CIMPSSAPSettingsStore& sapStore = iCCntxt.SapStoreL(); |
|
409 |
|
410 TIMPSConnectionClient client( ConnectionClient() ); |
|
411 TIMPSAccessGroup accessGroup; |
|
412 if ( client == EIMPSConnClientIM ) |
|
413 { |
|
414 accessGroup = EIMPSIMAccessGroup; |
|
415 } |
|
416 else |
|
417 { |
|
418 accessGroup = EIMPSPECAccessGroup; |
|
419 } |
|
420 |
|
421 |
|
422 //SAP store might not have any SAP => get default leaves |
|
423 TRAPD( err, sapStore.GetDefaultL( &aSap, accessGroup ) ); |
|
424 if ( err == KErrNotFound ) |
|
425 { |
|
426 //handle not found error by returning it |
|
427 return KCnUiErrorNoProperDefaultSap; |
|
428 } |
|
429 |
|
430 //and others by leaving |
|
431 User::LeaveIfError( err ); |
|
432 return KErrNone; |
|
433 } |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CCnUiAALoginCntrlStep::DoShowLogoutOkNoteL() |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 TIMPSConnectionClient CCnUiAALoginCntrlStep::ConnectionClient() |
|
440 { |
|
441 // rvct does not support casting from TAny* to enumeration value |
|
442 TInt returnValue = ( TInt )Dll::Tls(); |
|
443 return ( TIMPSConnectionClient )returnValue; |
|
444 } |
|
445 // End of File |