|
1 /* |
|
2 * Copyright (c) 2008 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: connection service manager for im |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cicpservicemanager.h" // service manager |
|
20 |
|
21 #include <e32std.h> |
|
22 |
|
23 |
|
24 #include <ximpclient.h> |
|
25 #include <ximpcontext.h> |
|
26 #include <ximprequestcompleteevent.h> |
|
27 #include <ximpcontextstateevent.h> |
|
28 #include <ximpidentity.h> |
|
29 #include <ximpstatus.h> |
|
30 #include <ximpcontextstateevent.h> |
|
31 #include <ximpcontextstate.h> |
|
32 #include <ximperrors.hrh> |
|
33 |
|
34 #include <imconversationevent.h> // recieve message |
|
35 #include <imconversationinfo.h> |
|
36 |
|
37 #include <spsettings.h> |
|
38 #include <spentry.h> |
|
39 #include <spproperty.h> |
|
40 #include <spdefinitions.h> |
|
41 |
|
42 #include "icplogger.h" |
|
43 #include "cicpservicerequest.h" |
|
44 |
|
45 // imcache related includes |
|
46 #include <cimcachefactory.h> |
|
47 #include <mimcacheupdater.h> |
|
48 |
|
49 //xmppsettings |
|
50 #include "xmppparams.h" |
|
51 #include "xmppservicesettingsapi.h" |
|
52 |
|
53 |
|
54 /************** Consts ***************/ |
|
55 const TInt KPropertyMaxLength = 512; |
|
56 const TInt KPasswordMaxLength = 50; |
|
57 //Received message maximum length is 400 character if received message is longer than 400 character |
|
58 //Truncate it to 400 character |
|
59 //This must always be in sync with imcvuiapp KReceiveMsgMaxLength |
|
60 const TInt KReceiveMsgMaxLength = 400; |
|
61 _LIT(KAt, "@"); |
|
62 _LIT(KPercentage, "%"); |
|
63 /***********End of Consts**********************/ |
|
64 |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CIcpServiceManager::CIcpServiceManager() |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CIcpServiceManager::CIcpServiceManager( MCchServiceObserver& aServiceObserver ) : |
|
72 iServiceObserver( aServiceObserver ), |
|
73 iOngoingState( ECCHUninitialized ) |
|
74 { |
|
75 ICPLOGSTRING( "CIcpServiceManager::CIcpServiceManager"); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CIcpServiceManager::NewL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CIcpServiceManager* CIcpServiceManager::NewL( MCchServiceObserver& aServiceObserver ) |
|
83 { |
|
84 ICPLOGSTRING( "CIcpServiceManager::NewL"); |
|
85 |
|
86 CIcpServiceManager* self = new ( ELeave ) CIcpServiceManager( aServiceObserver ); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop( self ); |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CIcpServiceManager::ConstructL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CIcpServiceManager::ConstructL() |
|
98 { |
|
99 ICPLOGSTRING( "CIcpServiceManager::ConstructL"); |
|
100 iCSPSetting = CSPSettings::NewL(); |
|
101 iXmppParameters = CXmppSettingsApi::NewL(); |
|
102 |
|
103 iOwnUserId = HBufC::NewL(MAX_LENGTH); |
|
104 |
|
105 if ( iPresClient ) |
|
106 { |
|
107 delete iPresClient; |
|
108 iPresClient = NULL; |
|
109 } |
|
110 |
|
111 //XIMP Context creation |
|
112 iPresClient = MXIMPClient::NewClientL(); |
|
113 MXIMPContext* tmp = iPresClient->NewPresenceContextLC(); |
|
114 iPresenceCtx = tmp; |
|
115 CleanupStack::Pop( ); // iPresenceCtx |
|
116 |
|
117 iAcceptedEventTypes.Reset(); |
|
118 iAcceptedEventTypes.AppendL( MXIMPRequestCompleteEvent::KInterfaceId ); |
|
119 iAcceptedEventTypes.AppendL( MXIMPContextStateEvent::KInterfaceId ); |
|
120 iAcceptedEventTypes.AppendL( MImConversationEvent::KInterfaceId ); |
|
121 |
|
122 |
|
123 TArray< TInt32 > eventFilterArray = iAcceptedEventTypes.Array(); |
|
124 // register this to prsence context |
|
125 iPresenceCtx->RegisterObserverL( *this, &eventFilterArray ); |
|
126 |
|
127 tmp = NULL; |
|
128 |
|
129 ICPLOGSTRING( "CIcpServiceManager::ConstructL Done"); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CIcpServiceManager::~CIcpServiceManager |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 CIcpServiceManager::~CIcpServiceManager() |
|
137 { |
|
138 ICPLOGSTRING( "CIcpServiceManager::~CIcpServiceManager"); |
|
139 |
|
140 delete iXmppParameters; |
|
141 delete iOwnUserId; |
|
142 |
|
143 delete iCSPSetting; |
|
144 |
|
145 iAcceptedEventTypes.Reset(); |
|
146 iAcceptedEventTypes.Close(); |
|
147 |
|
148 iReqIDArray.ResetAndDestroy(); |
|
149 |
|
150 delete iPresenceCtx; |
|
151 delete iPresClient; |
|
152 |
|
153 if(iIMCacheFactory) |
|
154 { |
|
155 CIMCacheFactory::Release(); |
|
156 } |
|
157 |
|
158 if (iServiceName) |
|
159 { |
|
160 delete iServiceName; |
|
161 iServiceName = NULL; |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CIcpServiceManager::EnableServiceL |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CIcpServiceManager::EnableServiceL( TUint aServiceId, |
|
171 TCCHSubserviceType aSubServiceType ) |
|
172 { |
|
173 ICPLOGSTRING3( "CIcpServiceManager::EnableServiceL service:%i Type:%i", aServiceId, aSubServiceType ); |
|
174 |
|
175 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
176 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
177 |
|
178 if ( (iOngoingState != ECCHEnabled) && |
|
179 (iOngoingState != ECCHConnecting) ) |
|
180 { |
|
181 //Get the service |
|
182 iServiceId = aServiceId; |
|
183 |
|
184 if (iServiceName) |
|
185 { |
|
186 delete iServiceName; |
|
187 iServiceName = NULL; |
|
188 } |
|
189 |
|
190 iServiceName = HBufC::NewL(KPropertyMaxLength); |
|
191 TPtr serviceIdPtr( iServiceName->Des() ); |
|
192 |
|
193 GetServiceNameL(iServiceId, serviceIdPtr); |
|
194 |
|
195 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
196 |
|
197 //reset owndata |
|
198 delete iOwnUserId; |
|
199 iOwnUserId = NULL; |
|
200 iOwnUserId = HBufC::NewL(MAX_LENGTH); |
|
201 TPtr owndataPtr = iOwnUserId->Des(); |
|
202 |
|
203 //get the owndata from settingsapi |
|
204 CXmppSettingsApi* xmppParameters = CXmppSettingsApi::NewLC(); |
|
205 xmppParameters->GetParamL(settingsId, XmppParams::KXmppParamUsername(), owndataPtr ); |
|
206 CleanupStack::PopAndDestroy(); // xmppParameters |
|
207 |
|
208 TInt passwordSet = KErrNotFound; |
|
209 GetConnectionParameter(aServiceId,aSubServiceType,ECchPasswordSet,passwordSet); |
|
210 if(0 == iOwnUserId->Length() || !passwordSet) |
|
211 { |
|
212 // check the user name if its empty or leave with the KCCHErrorAuthenticationFailed |
|
213 // for the cch ui to show the user name and password query dialog. |
|
214 User::Leave(KCCHErrorAuthenticationFailed); |
|
215 } |
|
216 |
|
217 //bind to presence context |
|
218 BindL(iServiceId); |
|
219 iOngoingState = ECCHConnecting; |
|
220 } |
|
221 |
|
222 |
|
223 ICPLOGSTRING( "CIcpServiceManager::EnableServiceL out" ); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CIcpServiceManager::EnableServiceL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CIcpServiceManager::EnableServiceL( TUint aServiceId, |
|
231 TCCHSubserviceType aSubServiceType, |
|
232 TUint /*aIapId*/ ) |
|
233 { |
|
234 ICPLOGSTRING3( "CIcpServiceManager::EnableServiceL service:%i Type:%i", aServiceId, aSubServiceType ); |
|
235 |
|
236 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
237 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
238 |
|
239 EnableServiceL( aServiceId, aSubServiceType ); |
|
240 |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CIcpServiceManager::DisableServiceL |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CIcpServiceManager::DisableServiceL( TUint aServiceId, |
|
248 TCCHSubserviceType aSubServiceType ) |
|
249 { |
|
250 ICPLOGSTRING3( "CIcpServiceManager::DisableService service:%i Type:%i", aServiceId, aSubServiceType ); |
|
251 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
252 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
253 |
|
254 |
|
255 // just unbind the context from the oss protocol adaptation plugin |
|
256 if (iOngoingState == ECCHEnabled) |
|
257 { |
|
258 UnBindL(); |
|
259 iOngoingState = ECCHDisconnecting; |
|
260 } |
|
261 |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CIcpServiceManager::IsAvailableL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TBool CIcpServiceManager::IsAvailableL( TUint /*aServiceId*/, |
|
269 TCCHSubserviceType /*a*/, |
|
270 const RArray<TUint32>& /*aIapIdArray*/ ) const |
|
271 { |
|
272 ICPLOGSTRING( "CIcpServiceManager::IsAvailableL" ); |
|
273 |
|
274 return ETrue; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CIcpServiceManager::GetServiceState |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 TInt CIcpServiceManager::GetServiceState( TUint aServiceId, |
|
282 TCCHSubserviceType aSubServiceType , |
|
283 TCCHSubserviceState& aState ) const |
|
284 { |
|
285 ICPLOGSTRING3( "CIcpServiceManager::GetServiceState service:%i type:%i", aServiceId, aSubServiceType ); |
|
286 |
|
287 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
288 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
289 |
|
290 TInt result( KErrNone ); |
|
291 |
|
292 aState = iOngoingState; |
|
293 result = iLastReportedError; |
|
294 return result; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CIcpServiceManager::GetServiceNetworkInfo |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 TInt CIcpServiceManager::GetServiceNetworkInfoL( TUint aServiceId, |
|
302 TCCHSubserviceType aSubServiceType, |
|
303 TUint32& aSnapId, |
|
304 TUint32& aIapId, |
|
305 TBool& aSnapLocked, |
|
306 TBool& aPasswordSet) const |
|
307 { |
|
308 ICPLOGSTRING3( "CIcpServiceManager::GetServiceNetworkInfo service:%i type:%i", aServiceId, aSubServiceType ); |
|
309 |
|
310 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
311 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
312 |
|
313 //Please dont remove the below line |
|
314 //otheriwse enable service will not be called |
|
315 //assuming service is down. Hack |
|
316 aSnapId = 0; |
|
317 aIapId = 5; |
|
318 aSnapLocked = ETrue; |
|
319 // read from setting see, if it is availabe set 1 else 0 |
|
320 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
321 //get the owndata from settingsapi |
|
322 HBufC* password = HBufC::NewLC( KPasswordMaxLength ); |
|
323 TPtr passwordPtr( password->Des() ); |
|
324 |
|
325 iXmppParameters->GetParamL((TUint32)settingsId, XmppParams::KXmppParamPassword(), passwordPtr ); |
|
326 |
|
327 if( passwordPtr.Length() > 0 ) |
|
328 { |
|
329 aPasswordSet = ETrue; |
|
330 } |
|
331 else |
|
332 { |
|
333 aPasswordSet = EFalse; |
|
334 } |
|
335 CleanupStack::PopAndDestroy();// password |
|
336 return KErrNone; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CIcpServiceManager::SetSnapId |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 TInt CIcpServiceManager::SetSnapId( TUint /*aServiceId*/, |
|
344 TCCHSubserviceType /*aSubServiceType*/, |
|
345 const TUint /*aSnapId*/ ) |
|
346 { |
|
347 return KErrNotSupported; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CIcpServiceManager::SetIapId |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 TInt CIcpServiceManager::SetIapId( TUint /*aServiceId*/, |
|
355 TCCHSubserviceType /*aSubServiceType*/, |
|
356 TUint /*aIapId*/ ) |
|
357 { |
|
358 return KErrNotSupported; |
|
359 } |
|
360 |
|
361 |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CIcpServiceManager::GetServiceInfoL |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 void CIcpServiceManager::GetServiceInfoL( TUint /*aServiceId*/, |
|
367 TCCHSubserviceType /*aSubServiceType*/, |
|
368 RBuf& /*aBuffer*/ ) const |
|
369 { |
|
370 } |
|
371 |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CIcpServiceManager::ReserveService |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 TInt CIcpServiceManager::SetServiceReserved( TBool /*aReserved*/, |
|
378 TUint /*aServiceId*/, |
|
379 TCCHSubserviceType /*aSubServiceType*/ ) |
|
380 { |
|
381 return KErrNotSupported; |
|
382 } |
|
383 |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CIcpServiceManager::GetConnectionParameter |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 TInt CIcpServiceManager::GetConnectionParameter(TUint aServiceId, |
|
390 TCCHSubserviceType aSubServiceType, |
|
391 TCchConnectionParameter aParameter, |
|
392 TInt& aValue ) const |
|
393 { |
|
394 ICPLOGSTRING3( "CIcpServiceManager::GetConnectionParameter service:%i type:%i", aServiceId, aSubServiceType ); |
|
395 |
|
396 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
397 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
398 |
|
399 TInt error = KErrBadHandle; |
|
400 |
|
401 switch( aParameter ) |
|
402 { |
|
403 case ECchIapId: |
|
404 { |
|
405 aValue = iIapId; |
|
406 error = KErrNone; |
|
407 break; |
|
408 } |
|
409 case ECchSnapId: |
|
410 { |
|
411 aValue = iSnapId; |
|
412 error = KErrNone; |
|
413 break; |
|
414 } |
|
415 case ECchSnapLocked: |
|
416 { |
|
417 aValue = ETrue; |
|
418 error = KErrNone; |
|
419 break; |
|
420 } |
|
421 case ECchPasswordSet: |
|
422 { |
|
423 // dont return ETrue simply, check if password length is greater than 0, |
|
424 // only then return ETrue, else return EFalse. |
|
425 TBuf<MAX_LENGTH> password; |
|
426 TInt settingsId = KErrNotFound; |
|
427 TRAPD(err,settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId)); |
|
428 //get the owndata from settingsapi |
|
429 if(KErrNone == err) |
|
430 { |
|
431 TRAP_IGNORE(iXmppParameters->GetParamL((TUint32)settingsId, |
|
432 XmppParams::KXmppParamPassword(), password )); |
|
433 } |
|
434 if( 0 == password.Length()) |
|
435 { |
|
436 aValue = EFalse; |
|
437 } |
|
438 else |
|
439 { |
|
440 aValue = ETrue; |
|
441 } |
|
442 break; |
|
443 } |
|
444 default : |
|
445 { |
|
446 break; |
|
447 } |
|
448 |
|
449 } |
|
450 |
|
451 return error; |
|
452 |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CIcpServiceManager::GetConnectionParameter |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 void CIcpServiceManager::GetConnectionParameterL(TUint aServiceId, |
|
460 TCCHSubserviceType aSubServiceType, |
|
461 TCchConnectionParameter aParameter, |
|
462 RBuf& aValue ) const |
|
463 { |
|
464 |
|
465 ICPLOGSTRING3( "CIcpServiceManager::GetConnectionParameterL service:%i type:%i", aServiceId, aSubServiceType ); |
|
466 |
|
467 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
468 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
469 |
|
470 TInt error = KErrBadHandle; |
|
471 switch( aParameter ) |
|
472 { |
|
473 case ECchUsername: |
|
474 { |
|
475 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
476 TRAP(error,iXmppParameters->GetParamL((TUint32)settingsId, |
|
477 XmppParams::KXmppParamUsername(), aValue )); |
|
478 break; |
|
479 } |
|
480 case ECchPassword: |
|
481 { |
|
482 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
483 //get the owndata from settingsapi |
|
484 TRAP(error,iXmppParameters->GetParamL((TUint32)settingsId, |
|
485 XmppParams::KXmppParamPassword(), aValue )); |
|
486 break; |
|
487 } |
|
488 default : |
|
489 { |
|
490 break; |
|
491 } |
|
492 |
|
493 } |
|
494 |
|
495 } |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CIcpPlugin::SetConnectionParameter |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 TInt CIcpServiceManager::SetConnectionParameter( TUint aServiceId, |
|
502 TCCHSubserviceType aSubServiceType, |
|
503 TCchConnectionParameter aParameter, |
|
504 TInt aValue ) |
|
505 { |
|
506 |
|
507 ICPLOGSTRING3( "CIcpServiceManager::SetConnectionParameter service:%i type:%i", aServiceId, aSubServiceType ); |
|
508 |
|
509 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
510 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
511 |
|
512 TInt error = KErrBadHandle; |
|
513 switch( aParameter ) |
|
514 { |
|
515 case ECchIapId: |
|
516 { |
|
517 iIapId = aValue ; |
|
518 error = KErrNone; |
|
519 break; |
|
520 } |
|
521 case ECchSnapId: |
|
522 { |
|
523 iSnapId = aValue ; |
|
524 error = KErrNone; |
|
525 break; |
|
526 } |
|
527 default : |
|
528 { |
|
529 break; |
|
530 } |
|
531 |
|
532 } |
|
533 return error; |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CIcpServiceManager::SetConnectionParameter |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 void CIcpServiceManager::SetConnectionParameterL(TUint aServiceId, |
|
541 TCCHSubserviceType aSubServiceType, |
|
542 TCchConnectionParameter aParameter, |
|
543 const TDesC& aValue ) |
|
544 { |
|
545 |
|
546 ICPLOGSTRING3( "CIcpServiceManager::SetConnectionParameterL service:%i type:%i", aServiceId, aSubServiceType ); |
|
547 |
|
548 __ASSERT_DEBUG( ValidateSubService(aSubServiceType), User::Panic( KNullDesC, KErrNotFound ) ); |
|
549 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
550 |
|
551 switch( aParameter ) |
|
552 { |
|
553 case ECchUsername: |
|
554 { |
|
555 HBufC* userid = NULL; |
|
556 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
557 if(KErrNotFound == aValue.Find( KAt() ) ) |
|
558 { |
|
559 //ownUserIdPtr.Append(KAt()); |
|
560 HBufC* domainName = HBufC::NewLC(50); |
|
561 TPtr domainNamePtr = domainName->Des(); |
|
562 iXmppParameters->GetParamL((TUint32)settingsId, XmppParams::KXmppParamDomain(), domainNamePtr); |
|
563 CleanupStack::Pop();//domainName |
|
564 userid = HBufC::NewLC( aValue.Length() + domainName->Length() + KAt().Length() ); |
|
565 TPtr useridPtr = userid->Des(); |
|
566 useridPtr.Append(aValue); |
|
567 useridPtr.Append(KAt); |
|
568 useridPtr.Append(domainNamePtr); |
|
569 delete domainName; |
|
570 } |
|
571 else |
|
572 { |
|
573 userid = aValue.AllocLC(); |
|
574 } |
|
575 TChar at('@'); |
|
576 TInt loc = userid->Locate( at ); |
|
577 if ( loc<2 ) |
|
578 { |
|
579 // There must be at least @ + something in domain part |
|
580 User::Leave( KErrArgument ); |
|
581 } |
|
582 if(iOwnUserId) |
|
583 { |
|
584 delete iOwnUserId; |
|
585 iOwnUserId = NULL; |
|
586 } |
|
587 iOwnUserId = userid->AllocL(); |
|
588 iXmppParameters->SetParamL((TUint32)settingsId, |
|
589 XmppParams::KXmppParamUsername(), *userid); |
|
590 CleanupStack::PopAndDestroy();//userid |
|
591 break; |
|
592 } |
|
593 case ECchPassword: |
|
594 { |
|
595 TInt settingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
596 iXmppParameters->SetParamL((TUint32)settingsId, |
|
597 XmppParams::KXmppParamPassword(), aValue); |
|
598 break; |
|
599 } |
|
600 default : |
|
601 { |
|
602 break; |
|
603 } |
|
604 |
|
605 } |
|
606 |
|
607 |
|
608 } |
|
609 |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // CIcpServiceManager::IsReserved |
|
613 // ----------------------------------------------------------------------------- |
|
614 // |
|
615 TInt CIcpServiceManager::IsReserved( TUint aServiceId, |
|
616 TCCHSubserviceType aSubServiceType ) const |
|
617 { |
|
618 ICPLOGSTRING3( "CIcpServiceManager::IsReserved service: %d type: %d", |
|
619 aServiceId, aSubServiceType ); |
|
620 |
|
621 TBool result = EFalse; |
|
622 |
|
623 return result; |
|
624 } |
|
625 |
|
626 |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CIcpServiceManager:: |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 void CIcpServiceManager::BindL(TInt aServiceSettingId) |
|
633 { |
|
634 ICPLOGSTRING2( "CIcpServiceManager[0x%x]::BindL", this ); |
|
635 //TUid protocolUid = TUid::Uid( KProtocolUid ); |
|
636 TInt propertyId = GetSPSettingsIntPropertyL( aServiceSettingId, EPropertyPCSPluginId ); |
|
637 |
|
638 if ( KErrNotFound != propertyId ) |
|
639 { |
|
640 TUid protocolUid = TUid::Uid( propertyId ); |
|
641 |
|
642 TXIMPRequestId reqId = iPresenceCtx->BindToL( protocolUid, |
|
643 aServiceSettingId ); |
|
644 CreateRequestL(reqId, TIMConnProviderEnums::ELoginRequest); |
|
645 |
|
646 } |
|
647 |
|
648 ICPLOGSTRING( "CIcpServiceManager::BindL end" ); |
|
649 } |
|
650 |
|
651 // ----------------------------------------------------------------------------- |
|
652 // CIcpServiceManager::UnBindL |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 void CIcpServiceManager::UnBindL() |
|
656 { |
|
657 ICPLOGSTRING2( "CIcpServiceManager[0x%x]::UnBindL", this ); |
|
658 |
|
659 TXIMPRequestId reqId = iPresenceCtx->UnbindL(); |
|
660 |
|
661 CreateRequestL(reqId, TIMConnProviderEnums::ELogoutRequest); |
|
662 |
|
663 ICPLOGSTRING( "CIcpServiceManager::UnBindL end" ); |
|
664 } |
|
665 |
|
666 |
|
667 // ----------------------------------------------------------------------------- |
|
668 // CIcpServiceManager::ProfileEventOccurred |
|
669 // ----------------------------------------------------------------------------- |
|
670 // |
|
671 void CIcpServiceManager::HandlePresenceContextEvent( const MXIMPContext& /* aContext */, |
|
672 const MXIMPBase& aEvent ) |
|
673 { |
|
674 ICPLOGSTRING2( "CIcpServiceManager[0x%x]::HandlePresenceContextEvent", this ); |
|
675 |
|
676 const TInt32 eventType = aEvent.GetInterfaceId(); |
|
677 |
|
678 switch( eventType ) |
|
679 { |
|
680 case MXIMPRequestCompleteEvent::KInterfaceId: |
|
681 { |
|
682 ICPLOGSTRING( "::HandlePresenceContextEvent event MximpRequestCompleteEvent start" ); |
|
683 const MXIMPRequestCompleteEvent* event = |
|
684 TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From( aEvent, MXIMPBase::EPanicIfUnknown ); |
|
685 |
|
686 TXIMPRequestId reqId = event->RequestId(); |
|
687 |
|
688 const MXIMPStatus& status = event->CompletionResult(); |
|
689 |
|
690 TInt err = status.ResultCode(); |
|
691 |
|
692 CICPServiceRequest *req = FindRequestId( reqId ); |
|
693 |
|
694 if( req->RequestType() == TIMConnProviderEnums::ELoginRequest ) |
|
695 { |
|
696 if(KErrNone == err ) |
|
697 { |
|
698 //login successfull |
|
699 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent event bind complete" ); |
|
700 |
|
701 iOngoingState = ECCHEnabled; |
|
702 |
|
703 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHPresenceSub ), |
|
704 ECCHEnabled, err ); |
|
705 |
|
706 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHIMSub ), |
|
707 ECCHEnabled, err ); |
|
708 |
|
709 |
|
710 // create the imcache session ,since now ready to recieve message |
|
711 if(!iIMCacheFactory) |
|
712 { |
|
713 |
|
714 TRAP_IGNORE( |
|
715 iIMCacheFactory = CIMCacheFactory::InstanceL() ; |
|
716 iIMCacheUpdater = iIMCacheFactory->CreateUpdaterL(iServiceId, iOwnUserId->Des() ,EFalse) ; |
|
717 ); |
|
718 } |
|
719 |
|
720 } |
|
721 else |
|
722 { |
|
723 TRAP_IGNORE( SetIMDisabledL(iServiceId) ); |
|
724 |
|
725 TInt cchErr = ConvertXIMPErrToCChErr(err); |
|
726 iLastReportedError = cchErr; |
|
727 //login unsuccessfull |
|
728 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent event bind complete" ); |
|
729 |
|
730 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHPresenceSub ), |
|
731 ECCHDisabled, cchErr ); |
|
732 |
|
733 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHIMSub ), |
|
734 ECCHDisabled, cchErr ); |
|
735 |
|
736 iOngoingState = ECCHDisabled; |
|
737 ICPLOGSTRING2( "CIcpServiceManager::HandlePresenceContextEvent err = %d",err); |
|
738 |
|
739 |
|
740 } |
|
741 |
|
742 } |
|
743 else if( req->RequestType() == TIMConnProviderEnums::ELogoutRequest ) |
|
744 { |
|
745 //Logout is successfull |
|
746 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent status offline" ); |
|
747 |
|
748 |
|
749 |
|
750 // release the imcache, all the conversation will lost here |
|
751 if( iIMCacheFactory ) |
|
752 { |
|
753 CIMCacheFactory::Release(); |
|
754 iIMCacheFactory = NULL; // make sure factory is deleted |
|
755 iIMCacheUpdater = NULL; |
|
756 } |
|
757 |
|
758 // set the status into cenrep |
|
759 |
|
760 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent status offline end" ); |
|
761 } |
|
762 |
|
763 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent offline end 2" ); |
|
764 |
|
765 req->StopWait() ; |
|
766 RemoveRequestId(reqId); |
|
767 delete req; |
|
768 |
|
769 break; |
|
770 } |
|
771 |
|
772 case MXIMPContextStateEvent::KInterfaceId: |
|
773 { |
|
774 ICPLOGSTRING( "::HandlePresenceContextEvent event MXIMPContextStateEvent start" ); |
|
775 // what do we do with context state event |
|
776 // state of the context can be associated with the |
|
777 const MXIMPContextStateEvent* ctxtStateEvent = |
|
778 TXIMPGetInterface< const MXIMPContextStateEvent >::From( aEvent, |
|
779 MXIMPBase::EPanicIfUnknown ); |
|
780 const MXIMPStatus* fwStatus = ctxtStateEvent->StateChangeReason(); |
|
781 const MXIMPContextState& cState = ctxtStateEvent->ContextState(); |
|
782 MXIMPContextState::TState state = cState.ContextState(); |
|
783 |
|
784 if (MXIMPContextState::EBinding == state) |
|
785 { |
|
786 |
|
787 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHPresenceSub ), |
|
788 ECCHConnecting, KErrNone ); |
|
789 |
|
790 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHIMSub ), |
|
791 ECCHConnecting, KErrNone ); |
|
792 } |
|
793 else if (MXIMPContextState::EUnbinding == state) |
|
794 { |
|
795 |
|
796 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHPresenceSub ), |
|
797 ECCHDisconnecting, KErrNone ); |
|
798 |
|
799 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHIMSub ), |
|
800 ECCHDisconnecting, KErrNone ); |
|
801 } |
|
802 else if (MXIMPContextState::EInactive == state ) |
|
803 { |
|
804 // release the imcache, all the conversation will lost here |
|
805 CIMCacheFactory::Release(); |
|
806 iIMCacheFactory = NULL; // make sure factory is deleted |
|
807 iIMCacheUpdater = NULL; |
|
808 iOngoingState = ECCHDisabled; |
|
809 |
|
810 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHPresenceSub ), |
|
811 ECCHDisabled, KErrNone ); |
|
812 |
|
813 iServiceObserver.ServiceStateChanged( TServiceSelection( iServiceId, ECCHIMSub ), |
|
814 ECCHDisabled, KErrNone ); |
|
815 |
|
816 } |
|
817 |
|
818 break; |
|
819 } |
|
820 |
|
821 case MImConversationEvent::KInterfaceId: |
|
822 { |
|
823 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent new message recieved star" ); |
|
824 const MImConversationEvent* convEvent = |
|
825 TXIMPGetInterface< const MImConversationEvent >::From |
|
826 (aEvent, MXIMPBase::EPanicIfUnknown); |
|
827 if( iIMCacheUpdater ) |
|
828 { |
|
829 TInt count = convEvent->NewTextMessageCount(); |
|
830 const MImConversationInfo& convInfo = convEvent->NewTextMessage(0); |
|
831 const MXIMPIdentity& identity = convInfo.MessageId(); |
|
832 const TDesC16& msgText = convInfo.TextMessage(); |
|
833 ICPLOGSTRING2( "msg txt: %S", &msgText ); |
|
834 TInt len = msgText.Length(); |
|
835 HBufC* bigmsg = NULL; |
|
836 TRAP_IGNORE( bigmsg = HBufC::NewL(KReceiveMsgMaxLength + 1) ; // 1 for % |
|
837 if( bigmsg ) |
|
838 { |
|
839 CleanupStack::PushL(bigmsg) ; // bigmsg |
|
840 TPtr bigmsgPtr = bigmsg->Des(); |
|
841 //If message is more than 400 character take only first 400 character |
|
842 //Rest of the message will be lost and |
|
843 bigmsgPtr.Append( msgText.Left( KReceiveMsgMaxLength ) ); |
|
844 if( len > KReceiveMsgMaxLength) |
|
845 { |
|
846 //append % as 401st character to identify on UI that it is a |
|
847 //long message which is truncated |
|
848 bigmsgPtr.Append(KPercentage); |
|
849 } |
|
850 TPtrC buddyId = identity.Identity(); |
|
851 iIMCacheUpdater->AppendReceiveMessageL( buddyId, bigmsgPtr ) ; |
|
852 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent Cache updated" ); |
|
853 CleanupStack::PopAndDestroy(bigmsg); // bigmsg |
|
854 } ); //End TRAP_IGNORE( bigmsg ... |
|
855 } |
|
856 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent new message recieved end" ); |
|
857 break; |
|
858 } |
|
859 |
|
860 |
|
861 default: |
|
862 { |
|
863 break; |
|
864 } |
|
865 } |
|
866 ICPLOGSTRING( "CIcpServiceManager::HandlePresenceContextEvent end" ); |
|
867 } |
|
868 |
|
869 |
|
870 // --------------------------------------------------------- |
|
871 // CIcpServiceManager::FindRequestId |
|
872 // |
|
873 // --------------------------------------------------------- |
|
874 CICPServiceRequest* CIcpServiceManager::CreateRequestL(TXIMPRequestId& aRequestId, |
|
875 TIMConnProviderEnums::TRequestTypes aType ) |
|
876 { |
|
877 |
|
878 CICPServiceRequest* req = CICPServiceRequest::NewL(aRequestId, aType); |
|
879 CleanupStack::PushL(req); |
|
880 |
|
881 TInt status( iReqIDArray.Append( req ) ); |
|
882 User::LeaveIfError( status ); |
|
883 |
|
884 CleanupStack::Pop(req); |
|
885 |
|
886 return req; |
|
887 } |
|
888 |
|
889 |
|
890 // --------------------------------------------------------- |
|
891 // CIcpServiceManager::FindRequestId |
|
892 // |
|
893 // --------------------------------------------------------- |
|
894 CICPServiceRequest* CIcpServiceManager::FindRequestId(TXIMPRequestId& aRequestId ) |
|
895 { |
|
896 TInt count = iReqIDArray.Count() ; |
|
897 TXIMPRequestId reqId ; |
|
898 CICPServiceRequest *req = NULL; |
|
899 for (TInt i=0; i < count; i++) |
|
900 { |
|
901 req = iReqIDArray[i] ; |
|
902 |
|
903 reqId = req->GetRequestId() ; |
|
904 |
|
905 if( aRequestId == reqId ) |
|
906 { |
|
907 break ; |
|
908 } |
|
909 } |
|
910 return req ; |
|
911 } |
|
912 |
|
913 // --------------------------------------------------------- |
|
914 // CIcpServiceManager::RemoveRequestId |
|
915 // |
|
916 // --------------------------------------------------------- |
|
917 CICPServiceRequest* CIcpServiceManager::RemoveRequestId(TXIMPRequestId& aRequestId ) |
|
918 { |
|
919 TInt count = iReqIDArray.Count() ; |
|
920 CICPServiceRequest *req = NULL; |
|
921 for (TInt i=0; i < count; i++) |
|
922 { |
|
923 req = iReqIDArray[i] ; |
|
924 if(req->GetRequestId() == aRequestId) |
|
925 { |
|
926 iReqIDArray.Remove( i ); |
|
927 iReqIDArray.Compress(); |
|
928 break ; |
|
929 } |
|
930 } |
|
931 return req ; |
|
932 } |
|
933 |
|
934 |
|
935 // --------------------------------------------------------------------------- |
|
936 // CIcpServiceManager::SetIMDisabledL |
|
937 // --------------------------------------------------------------------------- |
|
938 // |
|
939 void CIcpServiceManager::SetIMDisabledL( |
|
940 TUint32 aServiceId) |
|
941 { |
|
942 ICPLOGSTRING2( "CIcpServiceManager::SetIMDisabledL serviceId = %d",aServiceId); |
|
943 |
|
944 |
|
945 { |
|
946 //Disable IM Subservice |
|
947 TSPItemType propertyType( EItemTypeIMSubProperty ); |
|
948 TServicePropertyName propertyName( ESubPropertyIMEnabled ); |
|
949 RPropertyArray subproperties; |
|
950 CleanupClosePushL( subproperties ); |
|
951 |
|
952 // Find correct subservice |
|
953 TInt err( iCSPSetting->FindSubServicePropertiesL( |
|
954 aServiceId, propertyType, subproperties ) ); |
|
955 |
|
956 for ( TInt i( 0 ); i < subproperties.Count(); i++ ) |
|
957 { |
|
958 // Read subservice's On/Off information |
|
959 if ( propertyName == subproperties[ i ]->GetName() ) |
|
960 { |
|
961 TOnOff onOff( EOff ); |
|
962 ICPLOGSTRING2( "CIcpServiceManager::SetIMDisabledL subproperties[ i ]->SetValue err = %d",err); |
|
963 subproperties[ i ]->SetValue( onOff ); |
|
964 i = subproperties.Count(); |
|
965 } |
|
966 } |
|
967 iCSPSetting->AddOrUpdatePropertiesL( aServiceId, subproperties ) ; |
|
968 subproperties.ResetAndDestroy( ); |
|
969 CleanupStack::PopAndDestroy( &subproperties ); |
|
970 } |
|
971 |
|
972 { |
|
973 TSPItemType propertyType( EItemTypePresenceSubProperty ); |
|
974 TServicePropertyName propertyName( ESubPropertyPresenceEnabled ); |
|
975 RPropertyArray subproperties; |
|
976 CleanupClosePushL( subproperties ); |
|
977 |
|
978 // Find correct subservice |
|
979 TInt err( iCSPSetting->FindSubServicePropertiesL( |
|
980 aServiceId, propertyType, subproperties ) ); |
|
981 |
|
982 for ( TInt i( 0 ); i < subproperties.Count(); i++ ) |
|
983 { |
|
984 // Read subservice's On/Off information |
|
985 if ( propertyName == subproperties[ i ]->GetName() ) |
|
986 { |
|
987 TOnOff onOff( EOff ); |
|
988 ICPLOGSTRING2( "CIcpServiceManager::SetIMDisabledL subproperties[ i ]->SetValue err = %d",err); |
|
989 subproperties[ i ]->SetValue( onOff ); |
|
990 i = subproperties.Count(); |
|
991 } |
|
992 } |
|
993 iCSPSetting->AddOrUpdatePropertiesL( aServiceId, subproperties ) ; |
|
994 subproperties.ResetAndDestroy( ); |
|
995 CleanupStack::PopAndDestroy( &subproperties ); |
|
996 } |
|
997 |
|
998 |
|
999 } |
|
1000 |
|
1001 |
|
1002 // --------------------------------------------------------------------------- |
|
1003 // CIcpServiceManager::ValidateServiceL |
|
1004 // --------------------------------------------------------------------------- |
|
1005 // |
|
1006 TBool CIcpServiceManager::ValidateServiceL( TUint32 aServiceId ) const |
|
1007 { |
|
1008 |
|
1009 TInt presenceSettingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyPresenceSettingsId); |
|
1010 TInt imSettingsId = GetSPSettingsIntPropertyL(aServiceId, ESubPropertyIMSettingsId); |
|
1011 |
|
1012 if ( (KErrNotFound != presenceSettingsId) && (presenceSettingsId == imSettingsId) ) |
|
1013 { |
|
1014 return ETrue; |
|
1015 } |
|
1016 |
|
1017 return EFalse; |
|
1018 } |
|
1019 |
|
1020 // --------------------------------------------------------------------------- |
|
1021 // CIcpServiceManager::GetSPSettingsIntPropertyL |
|
1022 // --------------------------------------------------------------------------- |
|
1023 // |
|
1024 TInt CIcpServiceManager::GetSPSettingsIntPropertyL( TUint32 aServiceId, |
|
1025 TServicePropertyName aPropertyName ) const |
|
1026 { |
|
1027 TInt tIntProperty = KErrNotFound; |
|
1028 |
|
1029 CSPProperty* property = CSPProperty::NewLC(); |
|
1030 |
|
1031 iCSPSetting->FindPropertyL( aServiceId, |
|
1032 aPropertyName, |
|
1033 *property ); |
|
1034 |
|
1035 if ( property ) |
|
1036 { |
|
1037 property->GetValue( tIntProperty ); |
|
1038 } |
|
1039 CleanupStack::PopAndDestroy( property ); |
|
1040 |
|
1041 return tIntProperty; |
|
1042 } |
|
1043 |
|
1044 // --------------------------------------------------------------------------- |
|
1045 // CIcpServiceManager::ValidateServiceL |
|
1046 // --------------------------------------------------------------------------- |
|
1047 // |
|
1048 TBool CIcpServiceManager::ValidateSubService( TCCHSubserviceType aSubServiceType ) const |
|
1049 { |
|
1050 if ( (ECCHUnknown == aSubServiceType) || |
|
1051 (ECCHPresenceSub == aSubServiceType) || |
|
1052 (ECCHIMSub == aSubServiceType) ) |
|
1053 { |
|
1054 return ETrue; |
|
1055 } |
|
1056 return EFalse; |
|
1057 } |
|
1058 |
|
1059 |
|
1060 // --------------------------------------------------------------------------- |
|
1061 // CIcpServiceManager::GetServiceNameL() |
|
1062 // --------------------------------------------------------------------------- |
|
1063 // |
|
1064 void CIcpServiceManager::GetServiceNameL( TUint32 aServiceId, TDes& aServiceName ) |
|
1065 { |
|
1066 |
|
1067 CSPEntry* entry = CSPEntry::NewLC(); |
|
1068 TRAPD( err, iCSPSetting->FindEntryL( aServiceId, *entry ) ); |
|
1069 if ( !err ) |
|
1070 { |
|
1071 aServiceName = entry->GetServiceName(); |
|
1072 } |
|
1073 |
|
1074 CleanupStack::PopAndDestroy( entry ); |
|
1075 |
|
1076 } |
|
1077 |
|
1078 |
|
1079 // --------------------------------------------------------------------------- |
|
1080 // CIcpServiceManager::ConvertXIMPErrToCChErr() |
|
1081 // --------------------------------------------------------------------------- |
|
1082 // |
|
1083 TInt CIcpServiceManager::ConvertXIMPErrToCChErr(const TInt aXimpErr) |
|
1084 { |
|
1085 |
|
1086 TInt returnValue (KErrNone); |
|
1087 |
|
1088 switch (aXimpErr) |
|
1089 { |
|
1090 case KXIMPErrServiceGeneralError: |
|
1091 case KXIMPErrServiceShutdown: |
|
1092 case KXIMPErrServiceRequestTypeNotSupported: |
|
1093 { |
|
1094 returnValue = KCCHErrorLoginFailed; |
|
1095 break; |
|
1096 } |
|
1097 |
|
1098 case KXIMPErrServiceAuthenticationFailed: |
|
1099 { |
|
1100 returnValue = KCCHErrorAuthenticationFailed; |
|
1101 break; |
|
1102 } |
|
1103 |
|
1104 default: |
|
1105 { |
|
1106 break; |
|
1107 } |
|
1108 } |
|
1109 |
|
1110 return returnValue; |
|
1111 } |
|
1112 |
|
1113 |
|
1114 // End of file |