realtimenetprots/sipfw/ProfileAgent/Server/Src/SipProfileCSSession.cpp
changeset 0 307788aac0a8
child 9 1e1cc61f56c3
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : sipprofilecssession
       
    15 // Part of     : SIP Profile Server
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "SipProfileCSServer.h"
       
    24 #include "SipProfileCSSession.h"
       
    25 #include "sipconcreteprofile.h"
       
    26 #include "sipconcreteprofileholder.h"
       
    27 #include "sipprofileslots.h"
       
    28 #include "sipprofileplugins.h"
       
    29 #include "SipProfileLog.h"
       
    30 #include "sipprofile.h"
       
    31 #include "sipmanagedprofile.h"
       
    32 #include <s32mem.h>
       
    33 
       
    34 const TUint KBufferSize = 100;
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSIPProfileCSSession::NewL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSIPProfileCSSession* CSIPProfileCSSession::NewL(CSIPProfileCSServer& aServer,
       
    43 												 CSIPProfileServerCore& aCore)
       
    44 	{
       
    45     CSIPProfileCSSession* self = CSIPProfileCSSession::NewLC(aServer, aCore);
       
    46     CleanupStack::Pop(self);
       
    47     return self;
       
    48 	}
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSIPProfileCSSession::NewLC
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CSIPProfileCSSession* CSIPProfileCSSession::NewLC(CSIPProfileCSServer& aServer,
       
    55 									 			  CSIPProfileServerCore& aCore)
       
    56 	{
       
    57     CSIPProfileCSSession* self =
       
    58     	new (ELeave) CSIPProfileCSSession(aServer, aCore);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     return self;
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CSIPProfileCSSession::CSIPProfileCSSession
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68  CSIPProfileCSSession::CSIPProfileCSSession(CSIPProfileCSServer& aServer,
       
    69 							  				CSIPProfileServerCore& aCore) :
       
    70 	iProfileServer(aServer),
       
    71   	iCore(aCore),
       
    72   	iClientReadyToReceive(EFalse),
       
    73   	iSessionTerminated(EFalse),
       
    74   	iALRObserverExists(EFalse)
       
    75 	{
       
    76     iProfileServer.IncrementSessions();
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSIPProfileCSSession::ConstructL
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CSIPProfileCSSession::ConstructL()
       
    84 	{
       
    85 	iCore.SessionRegisterL(*this);
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSIPProfileCSSession::~CSIPProfileCSSession
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CSIPProfileCSSession::~CSIPProfileCSSession()
       
    93 	{
       
    94 	iCore.SessionCleanup(*this);
       
    95 	iEventQueue.Close();
       
    96     iProfileServer.DecrementSessions();
       
    97 	}
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CSIPProfileCSSession::PanicClient
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CSIPProfileCSSession::PanicClient(TInt aError)
       
   104 	{
       
   105     if (iClientReadyToReceive)
       
   106         {
       
   107 		iEventMessage.Panic(KSipProfileServerName, aError);
       
   108 		}
       
   109 	iSessionTerminated = ETrue;	
       
   110 	}
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSIPProfileCSSession::ServiceL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CSIPProfileCSSession::ServiceL(const RMessage2& aMessage)
       
   117 	{
       
   118 	TInt function = iHelper.ServiceFunction(aMessage);
       
   119     __ASSERT_ALWAYS (!(iSessionTerminated &&
       
   120 		function != ESipProfileItcOpCancelReceive), 
       
   121 		aMessage.Panic (KSipProfileServerName, EBadSipSessionHandle));
       
   122 		
       
   123 #ifndef PLAT_SEC_TEST
       
   124 	PROFILE_DEBUG3("ProfileCSSession::ServiceL", function)
       
   125 	
       
   126     switch (function)
       
   127 		{
       
   128         case ESipProfileItcOpPluginsSize: ProfilePluginsSizeL(aMessage); break;
       
   129 
       
   130         case ESipProfileItcOpPlugins: ProfilePluginsL(aMessage); break;
       
   131 
       
   132         case ESipProfileItcOpAddProfile: AddProfileL(aMessage); break;
       
   133 
       
   134         case ESipProfileItcOpUpdateProfile: UpdateProfileL(aMessage); break;
       
   135 
       
   136         case ESipProfileItcOpRemoveProfile: RemoveProfileL(aMessage); break;
       
   137 
       
   138         case ESipProfileItcOpEnable: EnableL(aMessage); break;
       
   139 
       
   140         case ESipProfileItcOpDisable: DisableL(aMessage); break;
       
   141 
       
   142         case ESipProfileItcOpUsage: UsageL(aMessage); break;
       
   143 
       
   144         case ESipProfileItcOpProfileSize: SipProfileSizeL (aMessage); break;
       
   145 
       
   146         case ESipProfileItcOpProfileSizeDefault: SipProfileSizeDefaultL (aMessage); break;
       
   147 
       
   148         case ESipProfileItcOpProfile: SipProfileL (aMessage); break;
       
   149 
       
   150         case ESipProfileItcOpProfileRefresh: SipProfileRefreshL (aMessage); break;
       
   151 
       
   152         case ESipProfileItcOpProfilesSize: SipProfilesSizeL (aMessage); break;
       
   153 
       
   154         case ESipProfileItcOpProfiles: SipProfilesL (aMessage); break;
       
   155 
       
   156         case ESipProfileItcOpProfilesSizeByAOR: SipProfilesSizeByAORL (aMessage); break;
       
   157 
       
   158         case ESipProfileItcOpProfilesByAOR: SipProfilesByAORL (aMessage); break;
       
   159 
       
   160         case ESipProfileItcOpProfilesSizeByType: SipProfilesSizeByTypeL (aMessage); break;
       
   161 
       
   162         case ESipProfileItcOpProfilesByType: SipProfilesByTypeL (aMessage); break;
       
   163 
       
   164         case ESipProfileItcOpDeleteProfile: DeleteSipProfileL (aMessage); break;
       
   165 
       
   166         case ESipProfileItcOpCancelReceive: CancelClientReceiveL (); break;
       
   167 
       
   168         case ESipProfileItcOpCreateProfileSize: CreateProfileSizeL (aMessage); break;
       
   169 
       
   170         case ESipProfileItcOpCreateProfile: CreateProfileL (aMessage); break;
       
   171  
       
   172         case ESipProfileItcOpRegisteredAORs: RegisteredAORsL (aMessage); break;
       
   173 
       
   174         case ESipProfileItcOpRegisteredAORsSize: RegisteredAORsSizeL (aMessage); break;
       
   175 
       
   176         case ESipProfileItcOpNegotiatedSecurity: NegotiatedSecurityL (aMessage); break;
       
   177 
       
   178         case ESipProfileItcOpNegotiatedSecuritySize: NegotiatedSecuritySizeL (aMessage); break;
       
   179 
       
   180 		case ESipProfileItcOpAllowMigration: AllowMigrationL (aMessage); break;
       
   181 		
       
   182 		case ESipProfileItcOpDisallowMigration: DisallowMigrationL (aMessage); break;
       
   183 		
       
   184 		case ESipProfileItcOpAddALRObserver: iALRObserverExists = ETrue; break;
       
   185 		
       
   186 		case ESipProfileItcOpRemoveALRObserver: iALRObserverExists = EFalse; break;
       
   187 		
       
   188 		case ESipProfileItcOpRefreshIapAvailability: RefreshIapAvailabilityL (aMessage); break;
       
   189 
       
   190 		case ESipProfileItcOpForceDisable: ForceDisableL(aMessage); break;
       
   191 
       
   192         case ESipProfileItcOpReadyToReceive: // Asynchronous. Do not complete yet!
       
   193             ClientReadyToReceiveL (aMessage); return;
       
   194 
       
   195 
       
   196         default: aMessage.Panic (KSipProfileServerName, EBadRequest); break;
       
   197 		}
       
   198 #endif	
       
   199 	iHelper.CompleteService(aMessage, KErrNone);
       
   200 	}
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CSIPProfileCSSession::ProfilePluginsSizeL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CSIPProfileCSSession::ProfilePluginsSizeL(const RMessage2& aMessage)
       
   207 	{
       
   208 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   209 	const CSIPProfilePlugins& plugins = iCore.ProfilePluginsL();
       
   210 	ids.iSlot1 = plugins.ExternalizedSize(); 
       
   211 	iHelper.WriteL(aMessage, ids);
       
   212 	}
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CSIPProfileCSSession::ProfilePluginsL
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CSIPProfileCSSession::ProfilePluginsL(const RMessage2& aMessage)
       
   219     {
       
   220 	const CSIPProfilePlugins& plugins = iCore.ProfilePluginsL();
       
   221 	CBufFlat* buf = ExternalizeLC (plugins);
       
   222 	TPtr8 externalized = buf->Ptr(0);
       
   223 	iHelper.WriteL(ESipProfileItcArgPlugins, aMessage, externalized);
       
   224 	CleanupStack::PopAndDestroy(buf);
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CSIPProfileCSSession::AddProfileL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CSIPProfileCSSession::AddProfileL(const RMessage2& aMessage)
       
   232     {
       
   233 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   234 	HBufC8* profileBuf = iHelper.ReadLC(ESipProfileItcArgProfile,aMessage);
       
   235 	CSIPConcreteProfile* profile = InternalizeProfileLC(*profileBuf);
       
   236 	iCore.AddProfileL(profile, *this);
       
   237 	CleanupStack::Pop(profile);
       
   238 	CleanupStack::PopAndDestroy(profileBuf);
       
   239 	ids.iProfileId = profile->Id(); 
       
   240 	iHelper.WriteL(aMessage, ids);
       
   241 	iCore.UpdateRegistrationL(profile->Id(), *this);
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CSIPProfileCSSession::UpdateProfileL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CSIPProfileCSSession::UpdateProfileL(const RMessage2& aMessage)
       
   249     {
       
   250 	HBufC8* profileBuf = iHelper.ReadLC(ESipProfileItcArgProfile,aMessage);
       
   251 	CSIPConcreteProfile* profile = InternalizeProfileLC(*profileBuf);
       
   252     TBool canProceed = iCore.UpdateProfileToStoreL(profile, *this);
       
   253     CleanupStack::Pop(profile);
       
   254     CleanupStack::PopAndDestroy(profileBuf);
       
   255     if (canProceed)
       
   256     	{
       
   257     	iCore.UpdateRegistrationL(profile->Id(), *this);
       
   258     	}
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CSIPProfileCSSession::RemoveProfileL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CSIPProfileCSSession::RemoveProfileL(const RMessage2& aMessage)
       
   266     { 
       
   267 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   268 	iCore.RemoveProfileL(id);
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CSIPProfileCSSession::EnableL
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CSIPProfileCSSession::EnableL(const RMessage2& aMessage)
       
   276 	{
       
   277 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   278 	ids.iSlot1 = iCore.EnableProfileL(ids.iProfileId, *this);
       
   279 	iHelper.WriteL(aMessage, ids);
       
   280 	}
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CSIPProfileCSSession::DisableL
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CSIPProfileCSSession::DisableL(const RMessage2& aMessage)
       
   287 	{
       
   288 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   289 	ids.iSlot1 = iCore.DisableProfileL(ids.iProfileId, *this);
       
   290 	iHelper.WriteL(aMessage, ids);	
       
   291 	}
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CSIPProfileCSSession::ForceDisableL
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CSIPProfileCSSession::ForceDisableL(const RMessage2& aMessage)
       
   298 	{
       
   299 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   300 	ids.iSlot1 = iCore.ForceDisableProfileL(ids.iProfileId, *this);
       
   301 	iHelper.WriteL(aMessage, ids);	
       
   302 	}
       
   303 
       
   304 // CSIPProfileCSSession::UsageL
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CSIPProfileCSSession::UsageL(const RMessage2& aMessage)
       
   308 	{
       
   309 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   310 	ids.iSlot1 = iCore.ProfileUsageL(ids.iProfileId);
       
   311 	iHelper.WriteL(aMessage, ids);
       
   312 	}
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CSIPProfileCSSession::SipProfileSizeL
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CSIPProfileCSSession::SipProfileSizeL(const RMessage2& aMessage)
       
   319 	{
       
   320 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   321 	const CSIPConcreteProfile* profile = iCore.Profile(ids.iProfileId);
       
   322 	if (profile) 
       
   323 		{
       
   324 		CSIPConcreteProfile* clonedProfile = 
       
   325 			CloneProfileWithoutPasswordsLC(profile);
       
   326 		ids.iSlot1 = clonedProfile->ExternalizedSizeL(); 
       
   327 		CleanupStack::PopAndDestroy(clonedProfile);
       
   328 		
       
   329 		iHelper.WriteL(aMessage, ids);
       
   330 		
       
   331 		}
       
   332 	}
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CSIPProfileCSSession::SipProfileSizeDefaultL
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CSIPProfileCSSession::SipProfileSizeDefaultL(const RMessage2& aMessage)
       
   339 	{
       
   340 	const CSIPConcreteProfile* profile = iCore.ProfileDefaultL();
       
   341 	if (profile)
       
   342 		{
       
   343 		TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   344 
       
   345 		CSIPConcreteProfile* clonedProfile = 
       
   346 			CloneProfileWithoutPasswordsLC(profile);
       
   347 		ids.iProfileId = clonedProfile->Id();
       
   348 		ids.iSlot1 = clonedProfile->ExternalizedSizeL(); 
       
   349 		CleanupStack::PopAndDestroy(clonedProfile);
       
   350 
       
   351 		iHelper.WriteL(aMessage, ids);
       
   352 		}
       
   353 	}
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CSIPProfileCSSession::SipProfileL
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CSIPProfileCSSession::SipProfileL(const RMessage2& aMessage)
       
   360 	{
       
   361 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   362 	CSIPConcreteProfile* profile = 
       
   363 		CloneProfileWithoutPasswordsLC(&iCore.ProfileL(id, *this));
       
   364 	WriteProfileL( aMessage, profile ) ;
       
   365 	CleanupStack::PopAndDestroy (profile);
       
   366 	}
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CSIPProfileCSSession::SipProfileRefreshL
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void CSIPProfileCSSession::SipProfileRefreshL(const RMessage2& aMessage)
       
   373 	{
       
   374 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   375 	CSIPConcreteProfile* profile = 
       
   376 		CloneProfileWithoutPasswordsLC( &iCore.ProfileRefreshL(id, *this) );
       
   377 
       
   378 	WriteProfileL( aMessage, profile );
       
   379 
       
   380 	CleanupStack::PopAndDestroy (profile);	
       
   381 	}
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CSIPProfileCSSession::SipProfilesSizeL
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CSIPProfileCSSession::SipProfilesSizeL(const RMessage2& aMessage)
       
   388 	{
       
   389 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   390 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   391 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   392 	iCore.ProfilesL(NULL, array);
       
   393 	ids.iSlot1 = holder->ExternalizedSizeL();
       
   394 	array.Reset();
       
   395 	CleanupStack::PopAndDestroy(holder);
       
   396 	iHelper.WriteL(aMessage, ids);
       
   397 	}
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CSIPProfileCSSession::SipProfilesL
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CSIPProfileCSSession::SipProfilesL(const RMessage2& aMessage)
       
   404 	{
       
   405 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   406 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   407 	iCore.ProfilesL(this, array);
       
   408 	CBufFlat* buf = ExternalizeLC (*holder);
       
   409 	TPtr8 externalized = buf->Ptr(0);
       
   410 	iHelper.WriteL(ESipProfileItcArgProfiles, aMessage, externalized);
       
   411 	array.Reset();
       
   412 	CleanupStack::PopAndDestroy(buf);
       
   413 	CleanupStack::PopAndDestroy(holder);
       
   414 	}
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CSIPProfileCSSession::SipProfilesSizeByAORL
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 void CSIPProfileCSSession::SipProfilesSizeByAORL(const RMessage2& aMessage)
       
   421 	{
       
   422 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   423 	HBufC8* aor = iHelper.ReadLC(ESipProfileItcArgNarrator,aMessage);
       
   424 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   425 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   426 
       
   427 	iCore.ProfilesByAORL(*aor, NULL, array);
       
   428 
       
   429 	ids.iSlot1 = holder->ExternalizedSizeL();
       
   430 	array.Reset();
       
   431 	CleanupStack::PopAndDestroy(holder);
       
   432 	CleanupStack::PopAndDestroy(aor);
       
   433 	iHelper.WriteL(aMessage, ids);
       
   434 	}
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CSIPProfileCSSession::SipProfilesByAORL
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CSIPProfileCSSession::SipProfilesByAORL(const RMessage2& aMessage)
       
   441 	{
       
   442 	HBufC8* aor = iHelper.ReadLC(ESipProfileItcArgNarrator,aMessage);
       
   443 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   444 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   445 
       
   446 	iCore.ProfilesByAORL(*aor, this, array);
       
   447 
       
   448 	CBufFlat* buf = ExternalizeLC(*holder);
       
   449 	TPtr8 externalized = buf->Ptr(0);
       
   450 	iHelper.WriteL(ESipProfileItcArgProfiles, aMessage, externalized);
       
   451 	array.Reset();
       
   452 	CleanupStack::PopAndDestroy(buf);
       
   453 	CleanupStack::PopAndDestroy(holder);
       
   454 	CleanupStack::PopAndDestroy(aor);
       
   455 	}
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CSIPProfileCSSession::SipProfilesSizeByTypeL
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CSIPProfileCSSession::SipProfilesSizeByTypeL(const RMessage2& aMessage)
       
   462 	{
       
   463 	TSIPProfileTypeInfo info;
       
   464 	iHelper.ReadSIPProfileTypeInfoL(aMessage,info);
       
   465 	
       
   466 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   467 	
       
   468 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   469 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   470 
       
   471 	iCore.ProfilesByTypeL(info, NULL, array);
       
   472 
       
   473 	ids.iSlot1 = holder->ExternalizedSizeL();
       
   474 	array.Reset();
       
   475 	CleanupStack::PopAndDestroy(holder);
       
   476 	iHelper.WriteL(aMessage, ids);
       
   477 	}
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CSIPProfileCSSession::SipProfilesByTypeL
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CSIPProfileCSSession::SipProfilesByTypeL(const RMessage2& aMessage)
       
   484 	{	
       
   485 	TSIPProfileTypeInfo info;
       
   486 	iHelper.ReadSIPProfileTypeInfoL(aMessage,info);
       
   487 	
       
   488 	CSIPConcreteProfileHolder* holder = CSIPConcreteProfileHolder::NewLC();
       
   489 	RPointerArray<CSIPConcreteProfile>& array = holder->SIPProfiles();
       
   490 
       
   491 	iCore.ProfilesByTypeL(info, this, array);
       
   492 
       
   493 	CBufFlat* buf = ExternalizeLC(*holder);
       
   494 	TPtr8 externalized = buf->Ptr(0);
       
   495 	iHelper.WriteL(ESipProfileItcArgProfiles, aMessage, externalized);
       
   496 	array.Reset();
       
   497 	CleanupStack::PopAndDestroy(buf);
       
   498 	CleanupStack::PopAndDestroy(holder);
       
   499 	}
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CSIPProfileCSSession::DeleteSipProfileL
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CSIPProfileCSSession::DeleteSipProfileL(const RMessage2& aMessage)
       
   506 	{
       
   507 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   508 
       
   509 	iCore.DeleteProfileL(id, *this);
       
   510 	}
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CSIPProfileCSSession::CancelClientReceiveL
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 void CSIPProfileCSSession::CancelClientReceiveL()
       
   517 	{
       
   518     __ASSERT_ALWAYS (iClientReadyToReceive, User::Leave (KErrNotFound));
       
   519 
       
   520     iClientReadyToReceive = EFalse;
       
   521     iHelper.CompleteService(iEventMessage, KErrCancel);
       
   522 	}
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CSIPProfileCSSession::CreateProfileSizeL
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CSIPProfileCSSession::CreateProfileSizeL(const RMessage2& aMessage)
       
   529 	{
       
   530 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   531 
       
   532 	TSIPProfileTypeInfo info;
       
   533 	iHelper.ReadSIPProfileTypeInfoL(aMessage,info);
       
   534 
       
   535 	CSIPConcreteProfile* profile = iCore.CreateProfileL(info);
       
   536 	CleanupStack::PushL(profile);
       
   537 	ids.iSlot1 = profile->ExternalizedSizeL(); 
       
   538 	iHelper.WriteL(aMessage, ids);
       
   539 	CleanupStack::PopAndDestroy(profile);
       
   540 	}
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CSIPProfileCSSession::NegotiatedSecuritySizeL
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 void CSIPProfileCSSession::NegotiatedSecuritySizeL(const RMessage2& aMessage)
       
   547 	{
       
   548 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   549 	const CSIPConcreteProfile* profile = iCore.Profile(ids.iProfileId);
       
   550 	if (profile)
       
   551 		{
       
   552 		ids.iSlot1 = profile->NegotiatedSecurityMechanism().Length(); 
       
   553 		iHelper.WriteL(aMessage, ids);
       
   554 		}
       
   555 	}
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // CSIPProfileCSSession::NegotiatedSecurityL
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 void CSIPProfileCSSession::NegotiatedSecurityL(const RMessage2& aMessage)
       
   562 	{
       
   563 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   564 	const CSIPConcreteProfile* profile = iCore.Profile(id);
       
   565 	if (profile)
       
   566 		{
       
   567 		iHelper.WriteL(ESipProfileItcArgNegotiated, aMessage,
       
   568 			profile->NegotiatedSecurityMechanism());
       
   569 		}
       
   570 	}
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CSIPProfileCSSession::RegisteredAORsSizeL
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CSIPProfileCSSession::RegisteredAORsSizeL(const RMessage2& aMessage)
       
   577 	{
       
   578 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   579 	const CSIPConcreteProfile* profile = iCore.Profile(ids.iProfileId);
       
   580 	if (profile)
       
   581 		{
       
   582 		ids.iSlot1 = profile->ExternalizedRegisteredAORsSizeL(); 
       
   583 		iHelper.WriteL(aMessage, ids);
       
   584 		}
       
   585 	}
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CSIPProfileCSSession::RegisteredAORsL
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 void CSIPProfileCSSession::RegisteredAORsL(const RMessage2& aMessage)
       
   592 	{
       
   593 	TUint id = iHelper.IPCArgTUintL(ESipProfileItcArgProfileId, aMessage);
       
   594 	const CSIPConcreteProfile* profile = iCore.Profile(id);
       
   595 	if (profile)
       
   596 		{
       
   597 		CBufFlat* buf = CBufFlat::NewL(KBufferSize);
       
   598 		CleanupStack::PushL(buf);
       
   599 		RBufWriteStream writeStream(*buf, 0);
       
   600 		writeStream.PushL();
       
   601 		profile->ExternalizeRegisteredAORsL(writeStream);
       
   602 		CleanupStack::Pop(1); // writeStream
       
   603 		writeStream.Close();
       
   604 
       
   605 		TPtr8 externalized = buf->Ptr(0);
       
   606 		iHelper.WriteL(ESipProfileItcArgAORs, aMessage, externalized);
       
   607 		CleanupStack::PopAndDestroy(buf);
       
   608 		}
       
   609 	}
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CSIPProfileCSSession::CreateProfileL
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CSIPProfileCSSession::CreateProfileL(const RMessage2& aMessage)
       
   616 	{
       
   617 	TSIPProfileTypeInfo info;
       
   618 	iHelper.ReadSIPProfileTypeInfoL(aMessage,info);
       
   619 
       
   620 	CSIPConcreteProfile* profile = iCore.CreateProfileL(info);
       
   621 	CleanupStack::PushL(profile);
       
   622 	WriteProfileL(aMessage, profile);
       
   623 	CleanupStack::PopAndDestroy(profile);
       
   624 	}
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // CSIPProfileCSSession::InternalizeProfileLC
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 CSIPConcreteProfile*
       
   631 CSIPProfileCSSession::InternalizeProfileLC(const TDesC8& aProfile)
       
   632 	{
       
   633 	RDesReadStream readStream(aProfile);
       
   634 	readStream.PushL();
       
   635 	CSIPConcreteProfile* profile =
       
   636 		static_cast<CSIPConcreteProfile*>(
       
   637 			CSIPConcreteProfile::InternalizeL(readStream));
       
   638 	readStream.Pop();
       
   639 	readStream.Close();
       
   640 	CleanupStack::PushL(profile);
       
   641 	return profile;
       
   642 	}
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 // CSIPProfileCSSession::RegistrationStatusChangedL
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 void CSIPProfileCSSession::RegistrationStatusChangedL(TUint32 aProfileId, 
       
   649 													  TInt aStatus,
       
   650 													  TUint32 aStatusId)
       
   651 	{
       
   652 	switch (aStatus)
       
   653 		{
       
   654 	case CSIPConcreteProfile::ERegistered:
       
   655 		SendEvent(aProfileId, ESipProfileItcOpRegistered, aStatusId);
       
   656 		break;
       
   657 	case CSIPConcreteProfile::EUnregistered:
       
   658 		{
       
   659 			if(ESipProfileItcOpProfileForciblyDisabled == aStatusId)
       
   660 				SendEvent(aProfileId, ESipProfileItcOpProfileForciblyDisabled, 0);
       
   661             else
       
   662 				SendEvent(aProfileId, ESipProfileItcOpDeregistered, 0);
       
   663 		}
       
   664 		break;
       
   665 	default:
       
   666 		break;
       
   667 		}
       
   668 	}
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // CSIPProfileCSSession::AddedL
       
   672 // -----------------------------------------------------------------------------
       
   673 //
       
   674 void CSIPProfileCSSession::AddedL(TUint32 aProfileId)
       
   675 	{
       
   676 	SendEventL(aProfileId, ESipProfileItcOpProfileAdded);
       
   677 	}
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CSIPProfileCSSession::RemovedL
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 void CSIPProfileCSSession::RemovedL(TUint32 aProfileId)
       
   684 	{
       
   685 	SendEvent(aProfileId, ESipProfileItcOpProfileRemoved);
       
   686 	}
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // CSIPProfileCSSession::UpdatedL
       
   690 // -----------------------------------------------------------------------------
       
   691 //
       
   692 void CSIPProfileCSSession::UpdatedL(TUint32 aProfileId, TUint aSize)
       
   693 	{
       
   694 	SendEventL(aProfileId, ESipProfileItcOpProfileUpdated, aSize);
       
   695 	}
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CSIPProfileCSSession::ErrorOccurredL
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CSIPProfileCSSession::ErrorOccurredL(TUint32 aProfileId,
       
   702 										  TInt aStatus,
       
   703 										  TInt aError)
       
   704 	{
       
   705 	TInt event(ESipProfileItcOpUnregistrationError);
       
   706 	if (aStatus == CSIPConcreteProfile::ERegistrationInProgress)
       
   707 		{
       
   708 		event = ESipProfileItcOpRegistrationError;
       
   709 		}
       
   710 
       
   711     SendEventL(aProfileId, event, aError);
       
   712 	}
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CSIPProfileCSSession::IapAvailableL
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 TBool CSIPProfileCSSession::IapAvailableL(TUint32 aProfileId,
       
   719 										  TUint32 aSnapId,
       
   720 										  TUint32 aIapId)
       
   721 	{
       
   722 	if (iALRObserverExists)
       
   723 		{
       
   724 		SendEventL(aProfileId, ESipProfileItcOpIapAvailable, aSnapId, aIapId);
       
   725 		return ETrue;
       
   726 		}
       
   727 	return EFalse;
       
   728 	}
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CSIPProfileCSSession::MigrationStartedL
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 void CSIPProfileCSSession::MigrationStartedL(TUint32 aProfileId,
       
   735 										   	 TUint32 aSnapId,
       
   736 										   	 TUint32 aIapId)
       
   737 	{
       
   738 	if (iALRObserverExists)
       
   739 		{
       
   740 		SendEventL(aProfileId,
       
   741 				   ESipProfileItcOpMigrationStarted,
       
   742 				   aSnapId,
       
   743 				   aIapId);
       
   744 		}
       
   745 	}
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CSIPProfileCSSession::MigrationCompletedL
       
   749 // -----------------------------------------------------------------------------
       
   750 //
       
   751 void CSIPProfileCSSession::MigrationCompletedL(TUint32 aProfileId,
       
   752 										   	   TUint32 aSnapId,
       
   753 										   	   TUint32 aIapId)
       
   754 	{
       
   755 	if (iALRObserverExists)
       
   756 		{
       
   757 		SendEventL(aProfileId,
       
   758 				   ESipProfileItcOpMigrationCompleted,
       
   759 				   aSnapId,
       
   760 				   aIapId);
       
   761 		}
       
   762 	}
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CSIPProfileCSSession::AlrError
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 TInt CSIPProfileCSSession::AlrError(TInt aError,
       
   769 									TUint32 aProfileId,
       
   770 									TUint32 aSnapId,
       
   771 									TUint32 aIapId)
       
   772 	{
       
   773 	TInt err(KErrNone);
       
   774 	if (iALRObserverExists)
       
   775 		{
       
   776 		err = SendEvent(aProfileId,
       
   777 				        ESipProfileItcOpALRError,
       
   778 				        aSnapId,
       
   779 				        aIapId,
       
   780 				        aError);
       
   781 		}
       
   782     return err;
       
   783 	}
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CSIPProfileCSSession::SendEvent
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 TInt CSIPProfileCSSession::SendEvent(TUint aProfileId,
       
   790 									 TUint aEventId,
       
   791 									 TInt aSlot,
       
   792 									 TInt aSlot2,
       
   793 									 TInt aError)
       
   794 	{
       
   795 	TRAPD(err, SendEventL(aProfileId, aEventId, aSlot, aSlot2, aError));
       
   796 	return err;
       
   797 	}
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CSIPProfileCSSession::SendEventL
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 void CSIPProfileCSSession::SendEventL(TUint aProfileId,
       
   804 									  TUint aEventId,
       
   805 									  TInt aSlot,
       
   806 									  TInt aSlot2,
       
   807 									  TInt aError)
       
   808 	{
       
   809     if (iClientReadyToReceive)
       
   810         {
       
   811 		TSIPProfileSlots ids = iHelper.ReadSipIdsL(iEventMessage);
       
   812 		SetProfileSlots(ids, aProfileId, aEventId, aSlot, aSlot2, aError);
       
   813 
       
   814 		iHelper.WriteL(iEventMessage, ids);
       
   815 		iHelper.CompleteService(iEventMessage, KErrNone);
       
   816         iClientReadyToReceive = EFalse;
       
   817 		}
       
   818 	else
       
   819 		{
       
   820 		TSIPProfileSlots ids;
       
   821 		SetProfileSlots(ids, aProfileId, aEventId, aSlot, aSlot2, aError);
       
   822 
       
   823 		iEventQueue.AppendL(ids);
       
   824 		}
       
   825 	}
       
   826 	
       
   827 // -----------------------------------------------------------------------------
       
   828 // CSIPProfileCSSession::ClientReadyToReceiveL
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 void CSIPProfileCSSession::ClientReadyToReceiveL(const RMessage2& aMessage)
       
   832 	{
       
   833     __ASSERT_ALWAYS(!iClientReadyToReceive, User::Leave(KErrNotFound));
       
   834 
       
   835     iEventMessage = aMessage;
       
   836     if (iEventQueue.Count() == 0)
       
   837 		{
       
   838         iClientReadyToReceive = ETrue;
       
   839 		}
       
   840     else
       
   841 		{
       
   842 		const TSIPProfileSlots& stored = iEventQueue[0];
       
   843 		TSIPProfileSlots ids = iHelper.ReadSipIdsL(iEventMessage);
       
   844 		ids.iProfileId = stored.iProfileId; 
       
   845 		ids.iEventId = stored.iEventId; 
       
   846 		ids.iSlot1 = stored.iSlot1; 
       
   847 		iHelper.WriteL(iEventMessage, ids);
       
   848 		iHelper.CompleteService(iEventMessage, KErrNone);
       
   849 		iEventQueue.Remove(0);
       
   850         iClientReadyToReceive = EFalse;
       
   851 		}
       
   852 	}
       
   853 
       
   854 // -----------------------------------------------------------------------------
       
   855 // CSIPProfileCSSession::WriteProfileL
       
   856 // -----------------------------------------------------------------------------
       
   857 //
       
   858 void CSIPProfileCSSession::WriteProfileL(const RMessage2& aMessage, 
       
   859 	CSIPConcreteProfile* aProfile)
       
   860 	{
       
   861 	CBufFlat* buf = ExternalizeLC (*aProfile);
       
   862 	TPtr8 externalized = buf->Ptr(0);
       
   863 	iHelper.WriteL(ESipProfileItcArgProfile, aMessage, externalized);
       
   864 	CleanupStack::PopAndDestroy(buf);
       
   865 	}
       
   866 
       
   867 // -----------------------------------------------------------------------------
       
   868 // CSIPProfileCSSession::ExternalizeLC
       
   869 // -----------------------------------------------------------------------------
       
   870 //
       
   871 template<class T> CBufFlat*
       
   872 CSIPProfileCSSession::ExternalizeLC(const T& aElements)
       
   873 	{
       
   874 	CBufFlat* buf = CBufFlat::NewL(KBufferSize);
       
   875 	CleanupStack::PushL(buf);
       
   876 	RBufWriteStream writeStream(*buf, 0);
       
   877 	writeStream.PushL();
       
   878 	aElements.ExternalizeL(writeStream);
       
   879 	CleanupStack::Pop(1); // writeStream
       
   880 	writeStream.Close();
       
   881     return buf;
       
   882 	}
       
   883 	
       
   884 // -----------------------------------------------------------------------------
       
   885 // CSIPProfileCSSession::AllowMigrationL
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 void CSIPProfileCSSession::AllowMigrationL(const RMessage2& aMessage)
       
   889 	{
       
   890 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   891 	iCore.AllowMigrationL(ids.iProfileId, ids.iSlot1, *this);
       
   892 	}
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CSIPProfileCSSession::DisallowMigrationL
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 void CSIPProfileCSSession::DisallowMigrationL(const RMessage2& aMessage)
       
   899 	{
       
   900 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   901 	iCore.DisallowMigrationL(ids.iProfileId, ids.iSlot1, *this);		
       
   902 	}
       
   903 	
       
   904 // -----------------------------------------------------------------------------
       
   905 // CSIPProfileCSSession::RefreshIapAvailabilityL
       
   906 // -----------------------------------------------------------------------------
       
   907 //
       
   908 void CSIPProfileCSSession::RefreshIapAvailabilityL (const RMessage2& aMessage)
       
   909 	{
       
   910 	TSIPProfileSlots ids = iHelper.ReadSipIdsL(aMessage);
       
   911 	iCore.RefreshIapAvailabilityL(ids.iProfileId);		
       
   912 	}
       
   913 
       
   914 // -----------------------------------------------------------------------------
       
   915 // CSIPProfileCSSession::SetProfileSlots
       
   916 // -----------------------------------------------------------------------------
       
   917 //
       
   918 void CSIPProfileCSSession::SetProfileSlots(TSIPProfileSlots& aSlots,
       
   919 										   TUint aProfileId,
       
   920 										   TUint aEventId,
       
   921 										   TInt aSlot,
       
   922 										   TInt aSlot2,
       
   923 										   TInt aError) const
       
   924 	{
       
   925 	aSlots.iProfileId = aProfileId; 
       
   926 	aSlots.iEventId = aEventId; 
       
   927 	aSlots.iSlot1 = aSlot;
       
   928 	aSlots.iSlot2 = aSlot2;
       
   929 	aSlots.iError = aError;
       
   930 	}
       
   931 
       
   932 // -----------------------------------------------------------------------------
       
   933 // CSIPProfileCSSession::CloneProfileWithoutPasswordsLC
       
   934 // -----------------------------------------------------------------------------
       
   935 //
       
   936 CSIPConcreteProfile* CSIPProfileCSSession::CloneProfileWithoutPasswordsLC(
       
   937 		const CSIPConcreteProfile* aProfile)
       
   938 	{
       
   939 	CSIPConcreteProfile* clonedProfile = 
       
   940 		aProfile->CloneWithDynamicValuesL();
       
   941 
       
   942 	// Remove password from cloned profile
       
   943 	CleanupStack::PushL(clonedProfile);
       
   944 	clonedProfile->SetServerParameterL(
       
   945 		KSIPOutboundProxy, KSIPDigestPassword, KNullDesC8 );
       
   946 	clonedProfile->SetServerParameterL( 
       
   947 		KSIPRegistrar, KSIPDigestPassword, KNullDesC8 );	
       
   948 
       
   949 	return clonedProfile;
       
   950 	}