|
1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 #include <e32std.h> |
|
18 #include <escapeutils.h> |
|
19 |
|
20 #include "scpservicemanager.h" |
|
21 #include "scpsettinghandler.h" |
|
22 #include "scpservicestorage.h" |
|
23 #include "scputility.h" |
|
24 #include "scplogger.h" |
|
25 #include "scpprofilehandler.h" |
|
26 #include "scpservice.h" |
|
27 #include "scpsubservice.h" |
|
28 #include "scpsipconnection.h" |
|
29 #include "scpstatecontainer.h" |
|
30 |
|
31 const TInt KUsernameMaxLength = 255; |
|
32 const TInt KDomainMaxLength = 255; |
|
33 const TInt KTempBufMaxLength = 255; |
|
34 |
|
35 #ifdef _DEBUG |
|
36 const TInt KDebugInfoMaxLength = 255; |
|
37 #endif |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CScpServiceManager::CScpServiceManager() |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CScpServiceManager::CScpServiceManager( MCchServiceObserver& aServiceObserver ) : |
|
44 iServiceObserver( aServiceObserver ) |
|
45 { |
|
46 SCPLOGSTRING( "CScpServiceManager::CScpServiceManager"); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CScpServiceManager::NewL |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CScpServiceManager* CScpServiceManager::NewL( MCchServiceObserver& aServiceObserver ) |
|
54 { |
|
55 SCPLOGSTRING( "CScpServiceManager::NewL"); |
|
56 |
|
57 CScpServiceManager* self = new ( ELeave ) CScpServiceManager( aServiceObserver ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop( self ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CScpServiceManager::ConstructL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CScpServiceManager::ConstructL() |
|
69 { |
|
70 SCPLOGSTRING( "CScpServiceManager::ConstructL"); |
|
71 |
|
72 iProfileHandler = CScpProfileHandler::NewL(); |
|
73 iSettingHandler = CScpSettingHandler::NewL( *iProfileHandler ); |
|
74 iServiceStorage = CScpServiceStorage::NewL( *iSettingHandler ); |
|
75 |
|
76 |
|
77 iStateContainer.InitializeL(); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CScpServiceManager::~CScpServiceManager |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CScpServiceManager::~CScpServiceManager() |
|
85 { |
|
86 SCPLOGSTRING( "CScpServiceManager::~CScpServiceManager"); |
|
87 |
|
88 delete iServiceStorage; |
|
89 delete iSettingHandler; |
|
90 delete iProfileHandler; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CScpServiceManager::GetServiceL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CScpService* CScpServiceManager::GetServiceL( TUint aServiceId, |
|
98 TCCHSubserviceType aSubServiceType ) |
|
99 { |
|
100 SCPLOGSTRING2( "CScpServiceManager::GetService: %i", aServiceId ); |
|
101 |
|
102 CScpService* service( NULL ); |
|
103 |
|
104 if( iSettingHandler->ServiceExistsL( aServiceId ) ) |
|
105 { |
|
106 service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
107 |
|
108 if( service ) |
|
109 { |
|
110 TRAPD( result, iSettingHandler->UpdateSettingsL( *service, aSubServiceType ) ); |
|
111 |
|
112 if( result != KErrNone ) |
|
113 { |
|
114 #ifndef SCP_UNIT_TEST |
|
115 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrGeneral ) ); |
|
116 #endif |
|
117 service = NULL; |
|
118 } |
|
119 if ( KErrNoMemory == result ) |
|
120 { |
|
121 User::Leave( KErrNoMemory ); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 return service; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CScpServiceManager::CreateServiceL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 CScpService* CScpServiceManager::CreateServiceL( TUint aServiceId, |
|
134 TCCHSubserviceType aSubServiceType ) |
|
135 { |
|
136 SCPLOGSTRING2( "CScpServiceManager::CreateServiceL: %i", aServiceId ); |
|
137 |
|
138 if( !iSettingHandler->ServiceExistsL( aServiceId ) ) |
|
139 { |
|
140 User::Leave( KErrNotFound ); |
|
141 } |
|
142 |
|
143 // Check if it is already available |
|
144 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
145 |
|
146 if( !service ) |
|
147 { |
|
148 CScpService& createdService = |
|
149 iServiceStorage->CreateServiceL( aServiceId, |
|
150 *iProfileHandler, |
|
151 iServiceObserver ); |
|
152 |
|
153 service = &createdService; |
|
154 |
|
155 TRAPD( result, iSettingHandler->UpdateSettingsL( *service, aSubServiceType ) ); |
|
156 |
|
157 if( result != KErrNone ) |
|
158 { |
|
159 // Remove the service if something went wrong |
|
160 iServiceStorage->RemoveService( service->Id() ); |
|
161 User::Leave( result ); |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 #ifndef SCP_UNIT_TEST |
|
167 __ASSERT_DEBUG( EFalse, User::Panic( KNullDesC, KErrAlreadyExists ) ); |
|
168 #endif |
|
169 } |
|
170 |
|
171 return service; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CScpServiceManager::EnableServiceL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CScpServiceManager::EnableServiceL( TUint aServiceId, |
|
179 TCCHSubserviceType aSubServiceType ) |
|
180 { |
|
181 SCPLOGSTRING2( "CScpServiceManager::EnableServiceL service:%i", aServiceId ); |
|
182 SCPLOGSTRING2( "CScpServiceManager::EnableServiceL type:%i", aSubServiceType ); |
|
183 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
184 |
|
185 CScpService* service = GetServiceL( aServiceId, aSubServiceType ); |
|
186 |
|
187 if( !service ) |
|
188 { |
|
189 service = CreateServiceL( aServiceId, aSubServiceType ); |
|
190 } |
|
191 |
|
192 RArray< TInt > subServiceIds; |
|
193 CleanupClosePushL( subServiceIds ); |
|
194 service->GetSubServiceIds( subServiceIds ); |
|
195 |
|
196 for( TInt i=0 ;i<subServiceIds.Count(); i++ ) |
|
197 { |
|
198 CScpSubService* subService = |
|
199 service->GetSubService( subServiceIds[ i ] ); |
|
200 |
|
201 if( subService ) |
|
202 { |
|
203 SCPLOGSTRING2( "Subservice's type: %d", subService->SubServiceType() ); |
|
204 |
|
205 // Check is VoIP supported |
|
206 if ( !iSettingHandler->IsVoIPSupported() && |
|
207 ECCHVoIPSub == subService->SubServiceType() ) |
|
208 { |
|
209 SCPLOGSTRING( "No support for VoIP" ); |
|
210 subService = NULL; |
|
211 } |
|
212 |
|
213 if ( subService && |
|
214 ( aSubServiceType == subService->SubServiceType() || |
|
215 ECCHUnknown == aSubServiceType ) ) |
|
216 { |
|
217 UpdateProfileValuesL( aServiceId, aSubServiceType ); |
|
218 subService->EnableL(); |
|
219 } |
|
220 } |
|
221 } |
|
222 |
|
223 CleanupStack::PopAndDestroy( &subServiceIds ); |
|
224 |
|
225 SCPLOGSTRING( "CScpServiceManager::EnableServiceL out" ); |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CScpServiceManager::EnableServiceL |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CScpServiceManager::EnableServiceL( TUint aServiceId, |
|
233 TCCHSubserviceType aSubServiceType, |
|
234 TUint /*aIapId*/ ) |
|
235 { |
|
236 // : Change sip profiles IAP settings, but |
|
237 // If SNAP != 0 add the IAP to SNAP (CommsDB) |
|
238 EnableServiceL( aServiceId, aSubServiceType ); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CScpServiceManager::DisableServiceL |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CScpServiceManager::DisableServiceL( TUint aServiceId, |
|
246 TCCHSubserviceType aSubServiceType ) |
|
247 { |
|
248 SCPLOGSTRING2( "CScpServiceManager::DisableService service:%i", aServiceId ); |
|
249 __ASSERT_DEBUG( aServiceId > 0, User::Panic( KNullDesC, KErrNotFound ) ); |
|
250 |
|
251 CScpService* service = GetServiceL( aServiceId, aSubServiceType ); |
|
252 if( !service ) |
|
253 { |
|
254 service = CreateServiceL( aServiceId, aSubServiceType ); |
|
255 } |
|
256 |
|
257 RArray< TInt > subServiceIds; |
|
258 CleanupClosePushL( subServiceIds ); |
|
259 service->GetSubServiceIds( subServiceIds ); |
|
260 |
|
261 if( subServiceIds.Count() == 0 ) |
|
262 { |
|
263 // Nothing to disable |
|
264 User::Leave( KErrNotFound ); |
|
265 } |
|
266 |
|
267 TBool atLeastOneDisableSucceeded = EFalse; |
|
268 |
|
269 for( TInt i=0 ;i<subServiceIds.Count(); i++ ) |
|
270 { |
|
271 CScpSubService* subService = service->GetSubService( subServiceIds[ i ] ); |
|
272 if( subService && ( aSubServiceType == subService->SubServiceType() || |
|
273 aSubServiceType == ECCHUnknown ) ) |
|
274 { |
|
275 TInt result = subService->Disable(); |
|
276 if( result == KErrNone ) |
|
277 { |
|
278 atLeastOneDisableSucceeded = ETrue; |
|
279 } |
|
280 } |
|
281 } |
|
282 |
|
283 if( !atLeastOneDisableSucceeded ) |
|
284 { |
|
285 User::Leave( KErrNotSupported ); |
|
286 } |
|
287 |
|
288 CleanupStack::PopAndDestroy( &subServiceIds ); |
|
289 |
|
290 // After the disabling there might be some cleaning to do |
|
291 iServiceStorage->RemoveDisabledServices(); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CScpServiceManager::IsAvailableL |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 TBool CScpServiceManager::IsAvailableL( TUint /*aServiceId*/, |
|
299 TCCHSubserviceType /*a*/, |
|
300 const RArray<TUint32>& /*aIapIdArray*/ ) const |
|
301 { |
|
302 SCPLOGSTRING( "CScpServiceManager::IsAvailableL" ); |
|
303 // : |
|
304 return ETrue; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CScpServiceManager::GetServiceState |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 TInt CScpServiceManager::GetServiceState( TUint aServiceId, |
|
312 TCCHSubserviceType aSubServiceType, |
|
313 TCCHSubserviceState& aState ) const |
|
314 { |
|
315 SCPLOGSTRING2( "CScpServiceManager::GetServiceState service:%i", aServiceId ); |
|
316 |
|
317 TInt result( KErrNone ); |
|
318 aState = ECCHDisabled; |
|
319 |
|
320 CScpServiceManager* self = const_cast<CScpServiceManager*>(this); |
|
321 CScpService* service = NULL; |
|
322 TRAPD( err, service = self->GetServiceL( aServiceId, aSubServiceType ) ); |
|
323 if ( KErrNoMemory == err ) |
|
324 { |
|
325 return err; |
|
326 } |
|
327 |
|
328 if( service ) |
|
329 { |
|
330 result = service->State( aSubServiceType, aState ); |
|
331 } |
|
332 else |
|
333 { |
|
334 TRAP( result, service = CreateTemporaryServiceL( aServiceId, aSubServiceType ) ); |
|
335 |
|
336 if( result == KErrNone && service ) |
|
337 { |
|
338 result = service->State( aSubServiceType, aState ); |
|
339 delete service; |
|
340 } |
|
341 } |
|
342 |
|
343 return result; |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CScpServiceManager::GetServiceNetworkInfo |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 TInt CScpServiceManager::GetServiceNetworkInfo( TUint aServiceId, |
|
351 TCCHSubserviceType aSubServiceType, |
|
352 TUint32& aSnapId, |
|
353 TUint32& aIapId, |
|
354 TBool& aSnapLocked, |
|
355 TBool& aPasswordSet ) const |
|
356 { |
|
357 SCPLOGSTRING( "CScpServiceManager::GetServiceNetworkInfo" ); |
|
358 |
|
359 // Get service network info |
|
360 TRAPD( ret, GetServiceNetworkInfoL( aServiceId, |
|
361 aSubServiceType, |
|
362 aSnapId, |
|
363 aIapId, |
|
364 aSnapLocked, |
|
365 aPasswordSet) ); |
|
366 |
|
367 return ret; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CScpServiceManager::SetSnapId |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CScpServiceManager::SetSnapId( TUint aServiceId, |
|
375 TCCHSubserviceType aSubServiceType, |
|
376 const TUint aSnapId ) |
|
377 { |
|
378 SCPLOGSTRING4( "CScpServiceManager::SetSnapId service id: %d type: %d snap: %d", |
|
379 aServiceId, aSubServiceType, aSnapId ); |
|
380 |
|
381 return SetAccessPointId( aServiceId, aSubServiceType, EScpSnap, aSnapId ); |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CScpServiceManager::SetIapId |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 TInt CScpServiceManager::SetIapId( TUint aServiceId, |
|
389 TCCHSubserviceType aSubServiceType, |
|
390 TUint aIapId ) |
|
391 { |
|
392 SCPLOGSTRING4( "CScpServiceManager::SetIapId service id: %d type: %d iap: %d", |
|
393 aServiceId, aSubServiceType, aIapId ); |
|
394 |
|
395 return SetAccessPointId( aServiceId, aSubServiceType, EScpIap, aIapId ); |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // CScpServiceManager::SetAccessPointId |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 TInt CScpServiceManager::SetAccessPointId( TUint aServiceId, |
|
403 TCCHSubserviceType aSubServiceType, |
|
404 TScpAccessPointType aAccessPointType, |
|
405 TInt aAccessPointId ) |
|
406 { |
|
407 SCPLOGSTRING4( "CScpServiceManager[0x%x]::SetAccessPointId: type: %d id: %d", |
|
408 this, aSubServiceType, aAccessPointId ); |
|
409 |
|
410 TBool serviceCreated = EFalse; |
|
411 TInt result = KErrNone; |
|
412 |
|
413 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
414 |
|
415 if( !service ) |
|
416 { |
|
417 TRAP( result, service = CreateTemporaryServiceL( aServiceId, |
|
418 ECCHUnknown ) ); |
|
419 |
|
420 if( result == KErrNone ) |
|
421 { |
|
422 serviceCreated = ETrue; |
|
423 } |
|
424 } |
|
425 |
|
426 if( result == KErrNone ) |
|
427 { |
|
428 result = service->SetAccessPointId( aSubServiceType, |
|
429 aAccessPointType, |
|
430 aAccessPointId ); |
|
431 } |
|
432 |
|
433 if( serviceCreated ) |
|
434 { |
|
435 delete service; |
|
436 } |
|
437 |
|
438 return result; |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CScpServiceManager::CreateTemporaryServiceL |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 CScpService* CScpServiceManager::CreateTemporaryServiceL( TInt aServiceId, |
|
446 TCCHSubserviceType aSubServiceType ) const |
|
447 { |
|
448 SCPLOGSTRING3( "CScpServiceManager::CreateTemporaryServiceL service id: %d type: %d", |
|
449 aServiceId, |
|
450 aSubServiceType ); |
|
451 |
|
452 // Create a temporary service |
|
453 CScpService* service = CScpService::NewL( aServiceId, |
|
454 aSubServiceType, |
|
455 *iProfileHandler, |
|
456 *iServiceStorage, |
|
457 iServiceObserver ); |
|
458 |
|
459 CleanupStack::PushL( service ); |
|
460 |
|
461 service->SetServiceId( aServiceId ); |
|
462 |
|
463 iSettingHandler->UpdateSettingsL( *service, aSubServiceType ); |
|
464 |
|
465 CleanupStack::Pop( service ); |
|
466 |
|
467 return service; |
|
468 } |
|
469 |
|
470 // ----------------------------------------------------------------------------- |
|
471 // CScpServiceManager::GetServiceInfoL |
|
472 // ----------------------------------------------------------------------------- |
|
473 // |
|
474 void CScpServiceManager::GetServiceInfoL( TUint aServiceId, |
|
475 TCCHSubserviceType aSubServiceType, |
|
476 RBuf& aBuffer ) const |
|
477 { |
|
478 SCPLOGSTRING3( "CScpServiceManager::GetServiceInfoL service id: %d type: %d", |
|
479 aServiceId, aSubServiceType ); |
|
480 |
|
481 // Info request about the state of SCP for debugging purposes |
|
482 #ifdef _DEBUG |
|
483 |
|
484 TInt infoCode = 0xAAA; |
|
485 if( aServiceId == infoCode ) |
|
486 { |
|
487 aBuffer.Close(); |
|
488 HBufC* buf = HBufC::NewL( KDebugInfoMaxLength ); |
|
489 TPtr ptr = buf->Des(); |
|
490 |
|
491 iServiceStorage->GetDebugInfo( ptr ); |
|
492 iProfileHandler->GetDebugInfo( ptr ); |
|
493 |
|
494 aBuffer.Assign( buf ); |
|
495 |
|
496 return; |
|
497 } |
|
498 #endif |
|
499 |
|
500 TBool sipConnectionCreated( EFalse ); |
|
501 |
|
502 CScpSipConnection* sipConnection = GetSipConnectionL( aServiceId, |
|
503 aSubServiceType, |
|
504 sipConnectionCreated ); |
|
505 |
|
506 if( sipConnectionCreated ) |
|
507 { |
|
508 CleanupStack::PushL( sipConnection ); |
|
509 } |
|
510 |
|
511 TBuf8<KUsernameMaxLength> username; |
|
512 TBuf8<KDomainMaxLength> domain; |
|
513 TBuf16<KTempBufMaxLength> tempBuf; |
|
514 |
|
515 User::LeaveIfError( sipConnection->GetUsername( username ) ); |
|
516 User::LeaveIfError( sipConnection->GetDomain( domain ) ); |
|
517 |
|
518 _LIT16( KUsername, "username="); |
|
519 _LIT16( KDomain, "domain="); |
|
520 _LIT16( KSpace, " "); |
|
521 |
|
522 HBufC* buffer = HBufC::NewL( KUsername().Length() + |
|
523 KDomain().Length() + |
|
524 ( KSpace().Length() * 2) + |
|
525 username.Length() + |
|
526 domain.Length() ); |
|
527 |
|
528 buffer->Des().Copy( KUsername ); |
|
529 tempBuf.Copy( username ); |
|
530 buffer->Des().Append( tempBuf ); |
|
531 buffer->Des().Append( KSpace ); |
|
532 buffer->Des().Append( KDomain ); |
|
533 tempBuf.Copy( domain ); |
|
534 buffer->Des().Append( tempBuf ); |
|
535 buffer->Des().Append( KSpace ); |
|
536 |
|
537 aBuffer.Assign( buffer ); |
|
538 |
|
539 if( sipConnectionCreated ) |
|
540 { |
|
541 CleanupStack::PopAndDestroy( sipConnection ); |
|
542 } |
|
543 |
|
544 SCPLOGSTRING2( "Result: %S", &aBuffer ); |
|
545 } |
|
546 |
|
547 // ----------------------------------------------------------------------------- |
|
548 // CScpServiceManager::GetSipConnectionL |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 CScpSipConnection* CScpServiceManager::GetSipConnectionL( |
|
552 TUint aServiceId, |
|
553 TCCHSubserviceType aSubServiceType, |
|
554 TBool& aConnectionCreated ) const |
|
555 { |
|
556 SCPLOGSTRING2( "CScpServiceManager::GetSipConnectionL service:%i", |
|
557 aServiceId ); |
|
558 |
|
559 CScpSipConnection* sipConnection( NULL ); |
|
560 aConnectionCreated = EFalse; |
|
561 TUint32 profileId( 0 ); |
|
562 |
|
563 // Get SIP profile for service |
|
564 iSettingHandler->GetSipProfileIdByTypeL( aServiceId, |
|
565 aSubServiceType, |
|
566 profileId ); |
|
567 |
|
568 if( profileId != 0 ) |
|
569 { |
|
570 if( iProfileHandler->SipConnectionExists( profileId ) ) |
|
571 { |
|
572 sipConnection = iProfileHandler->GetSipConnection( profileId ); |
|
573 } |
|
574 else |
|
575 { |
|
576 if( iProfileHandler->ProfileExists( profileId ) ) |
|
577 { |
|
578 sipConnection = iProfileHandler->CreateSipConnectionL( profileId ); |
|
579 aConnectionCreated = ETrue; |
|
580 } |
|
581 } |
|
582 } |
|
583 |
|
584 if( !sipConnection ) |
|
585 { |
|
586 User::Leave( KErrNotFound ); |
|
587 } |
|
588 |
|
589 return sipConnection; |
|
590 } |
|
591 |
|
592 // ----------------------------------------------------------------------------- |
|
593 // CScpServiceManager::GetServiceNetworkInfoL |
|
594 // ----------------------------------------------------------------------------- |
|
595 // |
|
596 void CScpServiceManager::GetServiceNetworkInfoL( TUint aServiceId, |
|
597 TCCHSubserviceType aSubServiceType, |
|
598 TUint32& aSnapId, |
|
599 TUint32& aIapId, |
|
600 TBool& aSnapLocked, |
|
601 TBool& aPasswordSet ) const |
|
602 { |
|
603 SCPLOGSTRING2( "CScpServiceManager::GetServiceNetworkInfoL service:%i", |
|
604 aServiceId ); |
|
605 __ASSERT_DEBUG( (TInt)aServiceId > KErrNotFound, User::Panic( KNullDesC, KErrGeneral ) ); |
|
606 |
|
607 TBool serviceCreated = EFalse; |
|
608 |
|
609 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
610 |
|
611 if( !service ) |
|
612 { |
|
613 service = CreateTemporaryServiceL( aServiceId, ECCHUnknown ); |
|
614 |
|
615 serviceCreated = ETrue; |
|
616 CleanupStack::PushL( service ); |
|
617 } |
|
618 |
|
619 if( aSubServiceType == ECCHUnknown && |
|
620 service->SubServicesContainSameSipProfile() == EFalse ) |
|
621 { |
|
622 // We can't return any valid snap/iap values if different |
|
623 // sip profiles are in use |
|
624 User::Leave( KErrNotSupported ); |
|
625 } |
|
626 |
|
627 TBool sipConnectionCreated( EFalse ); |
|
628 CScpSipConnection* sipConnection = GetSipConnectionL( aServiceId, |
|
629 aSubServiceType, |
|
630 sipConnectionCreated ); |
|
631 |
|
632 TInt result = sipConnection->GetIap( aIapId ); |
|
633 if( result != KErrNone ) |
|
634 { |
|
635 aIapId = 0; |
|
636 } |
|
637 |
|
638 result = sipConnection->GetSnap( aSnapId ); |
|
639 if( result != KErrNone ) |
|
640 { |
|
641 aSnapId = 0; |
|
642 } |
|
643 |
|
644 if( sipConnectionCreated ) |
|
645 { |
|
646 delete sipConnection; |
|
647 } |
|
648 |
|
649 // Decide if snap is locked |
|
650 aSnapLocked = ETrue; |
|
651 |
|
652 if( aSubServiceType == ECCHUnknown || |
|
653 aSubServiceType == ECCHVoIPSub ) |
|
654 { |
|
655 aSnapLocked = EFalse; |
|
656 } |
|
657 else |
|
658 { |
|
659 CScpSubService* voipSubService = service->GetSubServiceByType( ECCHVoIPSub ); |
|
660 if( voipSubService ) |
|
661 { |
|
662 TInt sipProfileId = voipSubService->SipProfileId(); |
|
663 |
|
664 CScpSubService* subService = service->GetSubServiceByType( aSubServiceType ); |
|
665 |
|
666 if( subService ) |
|
667 { |
|
668 // If profiles are same the snap can't be changed |
|
669 if( subService->SipProfileId() != sipProfileId ) |
|
670 { |
|
671 aSnapLocked = EFalse; |
|
672 } |
|
673 } |
|
674 else |
|
675 { |
|
676 User::Leave( KErrNotFound ); |
|
677 } |
|
678 } |
|
679 else |
|
680 { |
|
681 aSnapLocked = EFalse; |
|
682 } |
|
683 } |
|
684 |
|
685 aPasswordSet = sipConnection->IsPasswordSet(); |
|
686 |
|
687 if( serviceCreated ) |
|
688 { |
|
689 CleanupStack::PopAndDestroy( service ); |
|
690 } |
|
691 |
|
692 SCPLOGSTRING2( "CScpServiceManager::ServiceNetworkInfo snap:%i", aSnapId ); |
|
693 SCPLOGSTRING2( "CScpServiceManager::ServiceNetworkInfo iap:%i", aIapId ); |
|
694 } |
|
695 |
|
696 // ----------------------------------------------------------------------------- |
|
697 // CScpServiceManager::ReserveService |
|
698 // ----------------------------------------------------------------------------- |
|
699 // |
|
700 TInt CScpServiceManager::SetServiceReserved( TBool aReserved, |
|
701 TUint aServiceId, |
|
702 TCCHSubserviceType aSubServiceType ) |
|
703 { |
|
704 SCPLOGSTRING4( "CScpServiceManager::SetServiceReserved: %d service: %d type: %d", |
|
705 aReserved, aServiceId, aSubServiceType ); |
|
706 |
|
707 TInt result = KErrNone; |
|
708 |
|
709 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
710 |
|
711 if( service ) |
|
712 { |
|
713 result = service->SetReserved( aReserved, aSubServiceType ); |
|
714 } |
|
715 else |
|
716 { |
|
717 result = KErrNotFound; |
|
718 } |
|
719 |
|
720 return result; |
|
721 } |
|
722 |
|
723 // ----------------------------------------------------------------------------- |
|
724 // CScpServiceManager::IsReserved |
|
725 // ----------------------------------------------------------------------------- |
|
726 // |
|
727 TInt CScpServiceManager::IsReserved( TUint aServiceId, |
|
728 TCCHSubserviceType aSubServiceType ) const |
|
729 { |
|
730 SCPLOGSTRING3( "CScpServiceManager::IsReserved service: %d type: %d", |
|
731 aServiceId, aSubServiceType ); |
|
732 |
|
733 TBool result = EFalse; |
|
734 |
|
735 CScpService* service = iServiceStorage->GetServiceByServiceId( aServiceId ); |
|
736 |
|
737 if( service ) |
|
738 { |
|
739 result = service->IsReserved( aSubServiceType ); |
|
740 } |
|
741 |
|
742 return result; |
|
743 } |
|
744 |
|
745 // ----------------------------------------------------------------------------- |
|
746 // CScpServiceManager::UpdateProfileValuesL |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 void CScpServiceManager::UpdateProfileValuesL( |
|
750 TUint aServiceId, |
|
751 TCCHSubserviceType aSubServiceType ) const |
|
752 { |
|
753 TUint32 sipId( KErrNone ); |
|
754 iSettingHandler->GetSipProfileIdByTypeL( aServiceId, aSubServiceType, sipId ); |
|
755 iProfileHandler->UpdateSipProfileL( sipId, |
|
756 iSettingHandler->IsUahTerminalTypeDefinedL( aServiceId ), |
|
757 iSettingHandler->IsUahWLANMacDefinedL( aServiceId ), |
|
758 iSettingHandler->UahStringLengthL( aServiceId ) ); |
|
759 } |
|
760 |
|
761 // ----------------------------------------------------------------------------- |
|
762 // CScpServiceManager::GetConnectionParameter |
|
763 // ----------------------------------------------------------------------------- |
|
764 // |
|
765 void CScpServiceManager::GetConnectionParameterL( |
|
766 const TServiceSelection& /*aServiceSelection*/, |
|
767 TCchConnectionParameter /*aParameter*/, |
|
768 TInt& /*aValue*/ ) const |
|
769 { |
|
770 SCPLOGSTRING( "CScpServiceManager::GetConnectionParameter (int return)\ |
|
771 Not supported yet. GetServiceNetworkInfoL is used at the moment." ); |
|
772 User::Leave( KErrNotSupported ); |
|
773 } |
|
774 |
|
775 // ----------------------------------------------------------------------------- |
|
776 // CScpServiceManager::GetConnectionParameter |
|
777 // ----------------------------------------------------------------------------- |
|
778 // |
|
779 void CScpServiceManager::GetConnectionParameterL( |
|
780 const TServiceSelection& aServiceSelection, |
|
781 TCchConnectionParameter aParameter, |
|
782 RBuf& aValue ) const |
|
783 { |
|
784 SCPLOGSTRING3( "CScpServiceManager::GetConnectionParameter (TBuf return) service id: %d type: %d", |
|
785 aServiceSelection.iServiceId, aServiceSelection.iType ); |
|
786 |
|
787 // check supported get values here, to avoid unnecessary object creation |
|
788 if( aParameter!=ECchUsername ) |
|
789 { |
|
790 SCPLOGSTRING2( "CScpServiceManager::GetConnectionParameter: not supported parameter:%d", aParameter ); |
|
791 User::Leave(KErrArgument ); |
|
792 } |
|
793 |
|
794 TBool sipConnectionCreated( EFalse ); |
|
795 |
|
796 CScpSipConnection* sipConnection = GetSipConnectionL( |
|
797 aServiceSelection.iServiceId, |
|
798 aServiceSelection.iType, |
|
799 sipConnectionCreated ); |
|
800 if( sipConnectionCreated ) |
|
801 { |
|
802 CleanupStack::PushL( sipConnection ); |
|
803 } |
|
804 |
|
805 |
|
806 if( aParameter==ECchUsername ) |
|
807 { |
|
808 HBufC* buffer = NULL; |
|
809 TBuf16<KTempBufMaxLength> tempBuf; |
|
810 TBuf8<KUsernameMaxLength> username; |
|
811 |
|
812 if( sipConnection->GetUsername( username ) == KErrNone ) |
|
813 { |
|
814 tempBuf.Copy( username ); |
|
815 |
|
816 // Decode encoded username (spaces to %20). |
|
817 buffer = EscapeUtils::EscapeDecodeL( tempBuf ); |
|
818 |
|
819 if ( buffer ) |
|
820 { |
|
821 aValue.Copy( buffer->Des() ); |
|
822 delete buffer; |
|
823 buffer = NULL; |
|
824 } |
|
825 else |
|
826 { |
|
827 aValue.Copy( KNullDesC ); |
|
828 } |
|
829 } |
|
830 } |
|
831 |
|
832 if( sipConnectionCreated ) |
|
833 { |
|
834 CleanupStack::PopAndDestroy( sipConnection ); |
|
835 } |
|
836 |
|
837 SCPLOGSTRING2( "Username: %S", &aValue ); |
|
838 } |
|
839 |
|
840 // ----------------------------------------------------------------------------- |
|
841 // CScpServiceManager::SetConnectionParameter |
|
842 // ----------------------------------------------------------------------------- |
|
843 // |
|
844 void CScpServiceManager::SetConnectionParameterL( |
|
845 const TServiceSelection& /*aServiceSelection*/, |
|
846 TCchConnectionParameter /*aParameter*/, |
|
847 TInt /*aValue*/ ) |
|
848 { |
|
849 SCPLOGSTRING( "CScpServiceManager::SetConnectionParameter(TInt) \ |
|
850 Not supported yet. Separate set methods used." ); |
|
851 |
|
852 // this is not implemented yet, separate functions are used. |
|
853 User::Leave( KErrNotSupported ); |
|
854 } |
|
855 |
|
856 // ----------------------------------------------------------------------------- |
|
857 // CScpServiceManager::SetConnectionParameter |
|
858 // ----------------------------------------------------------------------------- |
|
859 // |
|
860 void CScpServiceManager::SetConnectionParameterL( |
|
861 const TServiceSelection& aServiceSelection, |
|
862 TCchConnectionParameter aParameter, |
|
863 const TDesC& aValue ) |
|
864 { |
|
865 SCPLOGSTRING3( "CScpServiceManager::SetConnectionParameter (TDesC) service id: %d type: %d", |
|
866 aServiceSelection.iServiceId, aServiceSelection.iType ); |
|
867 |
|
868 if( aParameter!=ECchUsername && aParameter!=ECchPassword ) |
|
869 { |
|
870 User::Leave( KErrArgument ); |
|
871 } |
|
872 |
|
873 HBufC8* buf8 = NULL; |
|
874 buf8 = EscapeUtils::ConvertFromUnicodeToUtf8L( aValue ); |
|
875 CleanupStack::PushL( buf8 ); |
|
876 |
|
877 TBool sipConnectionCreated( EFalse ); |
|
878 |
|
879 CScpSipConnection* sipConnection = |
|
880 GetSipConnectionL( aServiceSelection.iServiceId, |
|
881 aServiceSelection.iType, |
|
882 sipConnectionCreated ); |
|
883 |
|
884 if( sipConnectionCreated ) |
|
885 { |
|
886 CleanupStack::PushL( sipConnection ); |
|
887 } |
|
888 |
|
889 // Get presence settings id. |
|
890 TInt presenceSettingsId( KErrNotFound ); |
|
891 TRAP_IGNORE( iSettingHandler->GetSPSettingsIntPropertyL( |
|
892 aServiceSelection.iServiceId, |
|
893 ESubPropertyPresenceSettingsId, |
|
894 presenceSettingsId ) ); |
|
895 |
|
896 if( aParameter == ECchUsername ) |
|
897 { |
|
898 // Use EscapeUtils to convert spaces to %20. |
|
899 HBufC8* encodedUsername = EscapeUtils::EscapeEncodeL( |
|
900 buf8->Des(), EscapeUtils::EEscapeNormal ); |
|
901 |
|
902 if ( encodedUsername ) |
|
903 { |
|
904 CleanupStack::PushL( encodedUsername ); |
|
905 |
|
906 // Set username to SIP-profile |
|
907 iProfileHandler->SetUsernameAndPasswordL( |
|
908 sipConnection->ProfileId(), |
|
909 encodedUsername->Des(), ETrue, KNullDesC8, EFalse ); |
|
910 |
|
911 // Set username to XDM-setting if setting exists |
|
912 if ( KErrNotFound != presenceSettingsId ) |
|
913 { |
|
914 SetUsernameAndPasswordToXdmL( |
|
915 aServiceSelection.iServiceId, |
|
916 *encodedUsername, |
|
917 ETrue, |
|
918 KNullDesC8, |
|
919 EFalse ); |
|
920 } |
|
921 |
|
922 CleanupStack::PopAndDestroy( encodedUsername ); |
|
923 |
|
924 SCPLOGSTRING2( "Username is set: %S", &aValue ); |
|
925 } |
|
926 } |
|
927 else if( aParameter == ECchPassword ) |
|
928 { |
|
929 // Set password to SIP-profile |
|
930 iProfileHandler->SetUsernameAndPasswordL( |
|
931 sipConnection->ProfileId(), |
|
932 KNullDesC8, EFalse, buf8->Des(), ETrue ); |
|
933 |
|
934 // Set password to XDM-setting if setting exists |
|
935 if ( KErrNotFound != presenceSettingsId ) |
|
936 { |
|
937 SetUsernameAndPasswordToXdmL( |
|
938 aServiceSelection.iServiceId, |
|
939 KNullDesC8, |
|
940 EFalse, |
|
941 buf8->Des(), |
|
942 ETrue ); |
|
943 } |
|
944 |
|
945 SCPLOGSTRING2( "Password is set: %S", &aValue ); |
|
946 } |
|
947 else |
|
948 { |
|
949 User::Leave( KErrArgument ); |
|
950 } |
|
951 |
|
952 if( sipConnectionCreated ) |
|
953 { |
|
954 CleanupStack::PopAndDestroy( sipConnection ); |
|
955 } |
|
956 |
|
957 CleanupStack::PopAndDestroy( buf8 ); |
|
958 } |
|
959 |
|
960 // ----------------------------------------------------------------------------- |
|
961 // CScpServiceManager::SetUsernameAndPasswordToXdmL |
|
962 // ----------------------------------------------------------------------------- |
|
963 // |
|
964 void CScpServiceManager::SetUsernameAndPasswordToXdmL( |
|
965 TUint aServiceId, |
|
966 const TDesC8& aUsername, |
|
967 TBool aSetUsername, |
|
968 const TDesC8& aPassword, |
|
969 TBool aSetPassword ) |
|
970 { |
|
971 CScpService* service = GetServiceL( |
|
972 aServiceId, ECCHPresenceSub ); |
|
973 |
|
974 TBool deleteTemporaryService( EFalse ); |
|
975 if ( !service ) |
|
976 { |
|
977 TRAPD( err, service = CreateTemporaryServiceL( |
|
978 aServiceId, |
|
979 ECCHPresenceSub ) ); |
|
980 |
|
981 if( err == KErrNone && service ) |
|
982 { |
|
983 deleteTemporaryService = ETrue; |
|
984 } |
|
985 } |
|
986 |
|
987 if ( aSetUsername ) |
|
988 { |
|
989 iSettingHandler->UpdateXdmUsernameL( |
|
990 *service, |
|
991 ECCHPresenceSub, |
|
992 aUsername ); |
|
993 } |
|
994 |
|
995 if ( aSetPassword ) |
|
996 { |
|
997 iSettingHandler->UpdateXdmPasswordL( |
|
998 *service, |
|
999 ECCHPresenceSub, |
|
1000 aPassword ); |
|
1001 } |
|
1002 |
|
1003 if ( deleteTemporaryService ) |
|
1004 { |
|
1005 delete service; |
|
1006 service = NULL; |
|
1007 } |
|
1008 } |
|
1009 |
|
1010 // End of file |