realtimenetprots/sipfw/ProfileAgent/IMS_Agent/Src/sipimsprofileagent.cpp
changeset 0 307788aac0a8
child 4 c2e8c8b73582
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-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        : sipimsprofileagent.cpp
       
    15 // Part of     : sip ims plugin
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <commsdat.h>
       
    24 #include <commsdattypesv1_1.h>
       
    25 #include <metadatabase.h>
       
    26 #include <cdblen.h>
       
    27 #include "sipimsprofileagent.h"
       
    28 #include "sipconcreteprofile.h"
       
    29 #include "sipprofileagentobserver.h"
       
    30 #include "sipconnection.h"
       
    31 #include "sipprflinitstate.h"
       
    32 #include "sipprflresolvingproxiesstate.h"
       
    33 #include "sipprflregisterrequestedstate.h"
       
    34 #include "sipprflregisterdelayrequestedstate.h"
       
    35 #include "sipprflregistrationinprogressstate.h"
       
    36 #include "sipprflregisteredstate.h"
       
    37 #include "sipprflderegistrationinprogressstate.h"
       
    38 #include "sipprflderegisterrequestedstate.h"
       
    39 #include "sipprflstatebase.h"
       
    40 #include "sipimsprofilecontext.h"
       
    41 #include "sipmanagedprofile.h"
       
    42 #include "sipgendefs.h"
       
    43 #include "SipProfileLog.h"
       
    44 #include "sipstrings.h"
       
    45 #include "sipstrconsts.h"
       
    46 #include "CSIPNotifyXmlBodyParser.h"
       
    47 #include "Sipimsprofileusimprovider.h"
       
    48 #include "Sipimsprofilesimrecord.h"
       
    49 #include "sipprofilequeuehandling.h"
       
    50 #include "sip.h"
       
    51 #include "siphttpdigest.h"
       
    52 #include "sipservertransaction.h"
       
    53 
       
    54 _LIT8(KSIPIMSProfileType, "ims");
       
    55 const TInt KAuthorizedMicroSecsInSec = 1;
       
    56 const TUint32 KRegAllowedWithUSIMandISIM = 1;
       
    57 const TUint32 KRegAllowedWithISIM = 2;
       
    58 
       
    59 #ifdef CPPUNIT_TEST
       
    60 #define CPPUNIT_MEMORYLEAVE {	if (err == KErrNoMemory) User::Leave(KErrNoMemory);}
       
    61 #else
       
    62 #define CPPUNIT_MEMORYLEAVE
       
    63 #endif
       
    64 
       
    65 // ============================ MEMBER FUNCTIONS ===============================
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSIPIMSProfileAgent::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSIPIMSProfileAgent* CSIPIMSProfileAgent::NewL(TAny* aInitParams)
       
    73 	{
       
    74 	PROFILE_DEBUG1("CSIPIMSProfileAgent::NewL")
       
    75 	
       
    76 	CSIPIMSProfileAgent* self = new (ELeave) CSIPIMSProfileAgent(
       
    77 		static_cast<TSIPProfileAgentInitParams*>(aInitParams));
       
    78 	CleanupStack::PushL(self);
       
    79 	self->ConstructL();
       
    80 	CleanupStack::Pop(self);
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSIPIMSProfileAgent::CSIPIMSProfileAgent
       
    86 // C++ default constructor can NOT contain any code, that
       
    87 // might leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CSIPIMSProfileAgent::CSIPIMSProfileAgent(
       
    91     TSIPProfileAgentInitParams* aInitParams)
       
    92 : iSIPProfileAgentObserver(aInitParams->iSIPProfileAgentObserver),
       
    93   iDeltaTimer(aInitParams->iDeltaTimer),
       
    94   iDeltaTimerCallBack(ASyncTimerExpired,this)
       
    95 	{
       
    96 	iType.iSIPProfileClass = TSIPProfileTypeInfo::EIms;
       
    97 	iType.iSIPProfileName = KSIPIMSProfileType();
       
    98 	iDeltaTimerEntry.Set(iDeltaTimerCallBack);
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSIPIMSProfileAgent::ConstructL
       
   103 // Symbian 2nd phase constructor can leave.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CSIPIMSProfileAgent::ConstructL()
       
   107     {
       
   108     PROFILE_DEBUG1("CSIPIMSProfileAgent::ConstructL")
       
   109     
       
   110     SIPStrings::OpenL();
       
   111     
       
   112 	iSIP = CSIP::NewL(TUid::Null(),*this);
       
   113 	iHttpDigest = CSIPHttpDigest::NewL(*iSIP,*this);    
       
   114     
       
   115     TBuf<KCommsDbSvrMaxFieldLength> tsyModuleName;
       
   116 	GetTsyModuleNameL( tsyModuleName );
       
   117     User::LeaveIfError(iTelServer.Connect());    
       
   118     User::LeaveIfError(iTelServer.LoadPhoneModule(tsyModuleName));
       
   119      
       
   120     TInt numPhone(0);
       
   121     User::LeaveIfError(iTelServer.EnumeratePhones(numPhone));
       
   122     TName tsyName;
       
   123     TBool found = EFalse;
       
   124     RTelServer::TPhoneInfo phoneInfo;
       
   125     TInt i(0);
       
   126     while ( !found && i < numPhone )
       
   127         {
       
   128         User::LeaveIfError( iTelServer.GetPhoneInfo( i, phoneInfo ) );
       
   129         User::LeaveIfError( iTelServer.GetTsyName( i, tsyName ) );
       
   130         if ( tsyName.CompareF( tsyModuleName ) == 0 )
       
   131             {
       
   132             found = ETrue;
       
   133             }
       
   134         i++;
       
   135         }
       
   136     __ASSERT_ALWAYS(found, User::Leave(KErrNotFound));     
       
   137     
       
   138     iXMLParser = CSIPNotifyXmlBodyParser::NewL();
       
   139 	iInit = CSIPPrflInitState::NewL(*this);
       
   140 	iResolvingProxies = CSIPPrflResolvingProxiesState::NewL(*this);
       
   141 	iRegRequested = CSIPPrflRegisterRequestedState::NewL(*this);
       
   142 	iRegInProgress = CSIPPrflRegistrationInProgressState::NewL(*this);
       
   143 	iRegistered = CSIPPrflRegisteredState::NewL(*this);
       
   144 	iDeregRequested = CSIPPrflDeregisterRequestedState::NewL(*this);
       
   145 	iDeregInProgress = CSIPPrflDeregistrationInProgressState::NewL(*this);
       
   146 	iRegDelayRequested = CSIPPrflRegisterDelayRequestedState::NewL(*this);
       
   147 	iInit->LinkStates(*iResolvingProxies, *iRegRequested, *iRegInProgress);
       
   148 	iResolvingProxies->LinkStates(*iInit, *iRegRequested, *iRegInProgress);
       
   149 	iRegRequested->LinkStates(*iInit, *iResolvingProxies, *iRegInProgress);
       
   150 	iRegInProgress->LinkStates(*iRegRequested, *iInit, *iRegistered,
       
   151 	                           *iRegDelayRequested);
       
   152 	iRegistered->LinkStates(*iDeregRequested, *iDeregInProgress,
       
   153 							 *iInit, *iRegRequested,*iRegDelayRequested);
       
   154 	iDeregRequested->LinkStates(*iInit, *iRegistered, *iDeregInProgress);
       
   155 	iDeregInProgress->LinkStates(*iInit);
       
   156 	iRegDelayRequested->LinkStates(*iInit);
       
   157 	
       
   158 	iSIMRecord = CSIPProfileSIMRecord::NewL();	
       
   159 	iProfileQueueHandling = CSIPProfileQueueHandling::NewL(*this);
       
   160 	TRAPD(err, iUsimProvider = 
       
   161 	    CSIPProfileUsimProvider::NewL(
       
   162 	        *iSIMRecord, iTelServer, phoneInfo, *this));
       
   163 	if(err == KErrNoMemory)
       
   164 		{
       
   165 		User::Leave(err);
       
   166 		}
       
   167 	iConfigExtension = NULL;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CSIPIMSProfileAgent::~CSIPIMSProfileAgent
       
   172 // Symbian 2nd phase constructor can leave.
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 CSIPIMSProfileAgent::~CSIPIMSProfileAgent()
       
   176 	{
       
   177 	PROFILE_DEBUG1("CSIPIMSProfileAgent::~CSIPIMSProfileAgent")
       
   178 	
       
   179 	delete iInit;
       
   180 	delete iResolvingProxies;
       
   181 	delete iRegRequested;
       
   182 	delete iRegistered;
       
   183 	delete iRegInProgress;
       
   184 	delete iDeregRequested;
       
   185 	delete iDeregInProgress;
       
   186 	delete iRegDelayRequested;
       
   187 	delete iProfileQueueHandling;
       
   188 	iDeltaTimer.Remove(iDeltaTimerEntry);
       
   189 	iConnectionCtxArray.ResetAndDestroy();
       
   190 	iConnectionCtxArray.Close();
       
   191 	iWaitForRegisteringArray.Reset();
       
   192 	iSIMWaitForAuthorizedArray.Reset();
       
   193 	iUSimWaitForAuthorizedArray.Reset();
       
   194 	iWaitForAuthorizedArray.Reset();
       
   195 	iFailedProfilesArray.Reset();
       
   196 	delete iXMLParser;
       
   197 	delete iUsimProvider;
       
   198 	delete iSIMRecord;
       
   199 	iTelServer.Close();
       
   200 	delete iHttpDigest;
       
   201 	delete iSIP;
       
   202 	SIPStrings::Close();	
       
   203 	}
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CSIPIMSProfileAgent::RegAllowedWithUSIMorISIML
       
   207 // (other items were commented in a header).
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 TBool CSIPIMSProfileAgent::RegAllowedWithUSIMorISIML(CSIPConcreteProfile& aProfile)
       
   211 	{
       
   212 	TBool allowed = ETrue;
       
   213 	TUint32 confValue = 0;
       
   214 	TInt result = 0;
       
   215 	result = aProfile.ExtensionParameter( KSIPAllowIMSRegistration,confValue );
       
   216 	if ( result != KErrNotFound )
       
   217 		{
       
   218 		if (confValue == KRegAllowedWithISIM && !iSIMRecord->IsISIMPresent())
       
   219 			{
       
   220 			allowed = EFalse;
       
   221 			}		
       
   222 		}
       
   223 	return allowed;
       
   224 	}
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CSIPIMSProfileAgent::RegAllowedWithSIM
       
   228 // (other items were commented in a header).
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TBool CSIPIMSProfileAgent::RegAllowedWithSIM(CSIPConcreteProfile& aProfile)
       
   232 	{
       
   233 	TBool allowed = ETrue;
       
   234 	TUint32 confValue = 0;
       
   235 	TInt result = 0;
       
   236 	result = aProfile.ExtensionParameter( KSIPAllowIMSRegistration,confValue );
       
   237 	if (result != KErrNotFound)
       
   238 		{
       
   239 		if (confValue == KRegAllowedWithISIM ||
       
   240 				 confValue == KRegAllowedWithUSIMandISIM)
       
   241 			{
       
   242 			allowed = EFalse;
       
   243 			}		
       
   244 		}
       
   245 	return allowed;
       
   246 	}
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSIPIMSProfileAgent::CheckIPSecRulesL
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CSIPIMSProfileAgent::CheckIPSecRulesL(CSIPConcreteProfile& aProfile)
       
   254 	{
       
   255 	TBool found = EFalse;
       
   256 	TBool isRegInUse = EFalse;
       
   257 		
       
   258 	found = IsIPSecAlreadyInUse(isRegInUse);	
       
   259 	if (found)
       
   260 		{
       
   261 		ResetISIMUpdateProfile( &aProfile );
       
   262 		User::Leave(KErrArgument);
       
   263 		}
       
   264 		
       
   265 	if (isRegInUse)
       
   266 		{
       
   267 		iWaitForRegisteringArray.AppendL(&aProfile);
       
   268 		}
       
   269 	else 
       
   270 		{	
       
   271 		ProfileToWaitingQueueL( &aProfile );
       
   272 		}
       
   273 	}
       
   274 	
       
   275 // -----------------------------------------------------------------------------
       
   276 // CSIPIMSProfileAgent::ResetISIMUpdateProfile
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CSIPIMSProfileAgent::ResetISIMUpdateProfile( CSIPConcreteProfile* aSIPConcreteProfile )
       
   281 	{
       
   282 	if ( iISIMUpdateProfile && (iISIMUpdateProfile->Id() == aSIPConcreteProfile->Id()) )
       
   283 		{
       
   284 		iISIMUpdateProfile = 0;
       
   285 		}
       
   286 	}
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CSIPIMSProfileAgent::IsIPSecAlreadyInUse
       
   290 // (other items were commented in a header).
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TBool CSIPIMSProfileAgent::IsIPSecAlreadyInUse( TBool& aIsRegInProgress )
       
   294 	{
       
   295 	TBool found = EFalse;
       
   296 	
       
   297 	for (TInt i=0; i < iConnectionCtxArray.Count() && !found; i++)
       
   298 		{
       
   299 		found = iConnectionCtxArray[i]->IsIPSecAlreadyInUse( aIsRegInProgress );	
       
   300 		}
       
   301 	if ( !found && !aIsRegInProgress )
       
   302 		{
       
   303 		aIsRegInProgress = iProfileQueueHandling->FoundIPSecProfileCandidate();
       
   304 		}
       
   305 	return found;
       
   306 	}
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSIPIMSProfileAgent::Type
       
   310 // (other items were commented in a header).
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 const TSIPProfileTypeInfo& CSIPIMSProfileAgent::Type() const
       
   314 	{
       
   315 	return iType;
       
   316 	}
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CSIPIMSProfileAgent::CreateL
       
   320 // (other items were commented in a header).
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 CSIPConcreteProfile* CSIPIMSProfileAgent::CreateL()
       
   324 	{
       
   325 	TSIPProfileTypeInfo type;		
       
   326 	type.iSIPProfileClass = TSIPProfileTypeInfo::EIms;
       
   327 	type.iSIPProfileName = KSIPIMSProfileType;
       
   328 
       
   329 	CSIPConcreteProfile* profile = CSIPConcreteProfile::NewLC();
       
   330 	profile->SetProfileType(type);
       
   331 
       
   332 	profile->EnableSecurityNegotiation(ETrue);
       
   333 	profile->EnableSigComp(ETrue);
       
   334 	_LIT8(KSIPDefaultProxy, "sip:0.0.0.0");
       
   335 	profile->SetServerL(KSIPOutboundProxy, KSIPDefaultProxy);
       
   336 
       
   337 	CleanupStack::Pop(profile);
       
   338 	return profile;
       
   339 	}
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CSIPIMSProfileAgent::RegisterL
       
   343 // (other items were commented in a header).
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CSIPIMSProfileAgent::RegisterL(
       
   347 	CSIPConcreteProfile& aSIPConcreteProfile)
       
   348 	{
       
   349 	PROFILE_DEBUG3("CSIPIMSProfileAgent::RegisterL", aSIPConcreteProfile.Id())
       
   350 	__ASSERT_ALWAYS (aSIPConcreteProfile.Server(KSIPOutboundProxy).Length(),
       
   351 		User::Leave(KErrArgument));
       
   352 	
       
   353 	TBool isClientConfigured = EFalse;
       
   354 	
       
   355 	if (CheckIfConfigured(aSIPConcreteProfile))
       
   356 		{
       
   357 		if (!MandatoryValuesConfigured(aSIPConcreteProfile))
       
   358 			{
       
   359 			User::Leave(KErrArgument);
       
   360 			}
       
   361 		isClientConfigured = ETrue;
       
   362 		}
       
   363 	
       
   364 	if (!iUsimProvider && !isClientConfigured)
       
   365 		{//No USIM/SIM access available
       
   366 		User::Leave(KErrArgument);
       
   367 		}
       
   368 	
       
   369 	if (!isClientConfigured)
       
   370 		{
       
   371 		TUint32 confValue = 0;
       
   372 		TInt result = 0;
       
   373 		result = aSIPConcreteProfile.ExtensionParameter( KSIPAllowIMSRegistration,confValue );
       
   374 		if (result != KErrNotFound)
       
   375 			{
       
   376 			if ((confValue == KRegAllowedWithUSIMandISIM || 
       
   377 			    confValue == KRegAllowedWithISIM )
       
   378 			    && !iUsimProvider->IsUsimSupported())
       
   379 				{
       
   380 				User::Leave(KErrNotSupported);
       
   381 				}
       
   382 			}
       
   383 		}
       
   384 	
       
   385 	// If digest settings are configured, no need to do USIM/SIM authorization	
       
   386 	if (iUsimProvider && 
       
   387 	    !CSIPIMSProfileContext::IsHttpDigestSettingsConfigured(aSIPConcreteProfile))
       
   388 	    {
       
   389 	   	if (!iUsimProvider->IsUsimSupported())
       
   390     		{
       
   391     		iSIMWaitForAuthorizedArray.AppendL(&aSIPConcreteProfile);
       
   392     		iUsimProvider->RequestL(ETrue);
       
   393     		}
       
   394 	    else
       
   395 			{
       
   396 			iUSimWaitForAuthorizedArray.AppendL(&aSIPConcreteProfile);
       
   397 			iUsimProvider->RequestL();
       
   398 			}
       
   399 	    }
       
   400     else
       
   401 		{
       
   402 		iWaitForAuthorizedArray.AppendL(&aSIPConcreteProfile);
       
   403 		AsyncDeltaTimer();
       
   404 		}
       
   405 	}
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // CSIPIMSProfileAgent::UpdateL
       
   409 // (other items were commented in a header).
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CSIPIMSProfileAgent::UpdateL(
       
   413 	CSIPConcreteProfile& aNewProfile, 
       
   414 	CSIPConcreteProfile& aOldProfile)
       
   415 	{
       
   416 	PROFILE_DEBUG3("CSIPIMSProfileAgent::UpdateL", aOldProfile.Id())
       
   417 	iProfileQueueHandling->Cleanup(aOldProfile,&aNewProfile);
       
   418 	CSIPIMSProfileContext* context = FindProfileContext(aOldProfile);
       
   419 	if (!context)
       
   420 	    {
       
   421 	    User::Leave(KErrNotFound);
       
   422 	    }
       
   423 	context->UpdateL(aNewProfile);
       
   424 	}
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CSIPIMSProfileAgent::DeregisterL
       
   428 // (other items were commented in a header).
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CSIPIMSProfileAgent::DeregisterL(
       
   432 	CSIPConcreteProfile& aSIPConcreteProfile)
       
   433 	{
       
   434 	PROFILE_DEBUG3("CSIPIMSProfileAgent::DeregisterL", aSIPConcreteProfile.Id())
       
   435 	CSIPIMSProfileContext* context = FindProfileContext(aSIPConcreteProfile);
       
   436 	if ( context )
       
   437 		{
       
   438 		if (!DeregisterToWaitingQueueL( context ))
       
   439 			{
       
   440 			context->DeregisterL();
       
   441 			}
       
   442 		}
       
   443 	else
       
   444 		{
       
   445 		PROFILE_DEBUG1("CSIPIMSProfileAgent::DeregisterL RemoveProfileFromQueue")
       
   446 		if (! iProfileQueueHandling->RemoveProfileFromRegQueueL(aSIPConcreteProfile) )
       
   447 			{
       
   448 			if (!RemoveProfileFromWaitingQueue(iWaitForRegisteringArray,
       
   449 												aSIPConcreteProfile) )
       
   450 				{
       
   451 				if (!RemoveProfileFromWaitingQueue(iUSimWaitForAuthorizedArray,
       
   452 												    aSIPConcreteProfile))
       
   453 					{
       
   454 					if (!RemoveProfileFromWaitingQueue(iSIMWaitForAuthorizedArray,
       
   455 														aSIPConcreteProfile))
       
   456 						{
       
   457 						RemoveProfileFromWaitingQueue(iWaitForAuthorizedArray,
       
   458 															aSIPConcreteProfile);
       
   459 						}
       
   460 					}
       
   461 				}
       
   462 			}
       
   463 		}	   
       
   464 	}
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // CSIPIMSProfileAgent::GetProfileState
       
   468 // (other items were commented in a header).
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 TInt CSIPIMSProfileAgent::GetProfileState(
       
   472 	CSIPConcreteProfile::TStatus& aState, 
       
   473 	CSIPConcreteProfile& aProfile) const
       
   474 	{
       
   475 	CSIPIMSProfileContext* context = FindProfileContext(aProfile);
       
   476 	if (context)
       
   477 		{
       
   478 		aState = context->CurrentMappedState();
       
   479 		return KErrNone;
       
   480 		}
       
   481 	else
       
   482 		{
       
   483 		return KErrNotFound;
       
   484 		}
       
   485 	}
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CSIPIMSProfileAgent::IsIdle
       
   489 // (other items were commented in a header).
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 TBool CSIPIMSProfileAgent::IsIdle()
       
   493 	{
       
   494 	CleanIdleConnectionContexts();
       
   495 	return (iConnectionCtxArray.Count()==0 &&
       
   496 	        iProfileQueueHandling->IsEmpty() &&
       
   497 	        iWaitForRegisteringArray.Count()==0 &&
       
   498 	        iUSimWaitForAuthorizedArray.Count()==0 &&
       
   499 	        iSIMWaitForAuthorizedArray.Count()==0 &&
       
   500 	        iWaitForAuthorizedArray.Count()==0 &&
       
   501 	        !iSIMRecord->IsISIMPresent() );
       
   502 	}
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CSIPIMSProfileAgent::RegisterPending
       
   506 // (other items were commented in a header).
       
   507 // -----------------------------------------------------------------------------
       
   508 //	
       
   509 TBool CSIPIMSProfileAgent::RegisterPending(
       
   510     CSIPConcreteProfile& aSIPProfile) const
       
   511     {
       
   512 	CSIPIMSProfileContext* context = FindProfileContext(aSIPProfile);
       
   513 	if (context)
       
   514 		{
       
   515 		return context->IsRegisterPending();
       
   516 		}
       
   517 	return EFalse;
       
   518     }
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // CSIPIMSProfileAgent::TerminateHandling
       
   522 // (other items were commented in a header).
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 TInt CSIPIMSProfileAgent::TerminateHandling(CSIPConcreteProfile& aProfile)
       
   526 	{
       
   527 	CSIPIMSProfileContext* context = FindProfileContext(aProfile);
       
   528 	if (context)
       
   529 		{
       
   530 		PROFILE_DEBUG3("CSIPIMSProfileAgent::TerminateHandling", aProfile.Id())
       
   531 		context->SetNextState(*iInit);
       
   532 		context->TerminateHandling();
       
   533 		return KErrNone;
       
   534 		}
       
   535 	else
       
   536 		{
       
   537 		return KErrNotFound;
       
   538 		}
       
   539 	}
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CSIPIMSProfileAgent::Extension
       
   543 // (other items were commented in a header).
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 TInt CSIPIMSProfileAgent::Extension(TInt aOperationCode, TAny* aParams)
       
   547     {
       
   548     TInt err(KErrNone);
       
   549     if(aParams && aOperationCode == KSipProfileAgentConfigExtension)
       
   550        	iConfigExtension = static_cast<CSipProfileAgentConfigExtension*>(aParams);
       
   551     else
       
   552       	err = KErrNotSupported;
       
   553     return err;
       
   554     }	
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CSIPIMSProfileAgent::RegisterProfileL
       
   558 // From MSIPProfileFSMUser
       
   559 // -----------------------------------------------------------------------------
       
   560 //	
       
   561 void CSIPIMSProfileAgent::RegisterProfileL(
       
   562     CSIPConcreteProfile& aSIPProfile)
       
   563     {
       
   564 	PROFILE_DEBUG3("CSIPIMSProfileAgent::RegisterProfileL", aSIPProfile.Id())    
       
   565     
       
   566     RegisterFromAuthorizedArrayL(aSIPProfile);
       
   567     }
       
   568 
       
   569 // -----------------------------------------------------------------------------
       
   570 // CSIPIMSProfileAgent::DeregisterProfileL
       
   571 // From MSIPProfileFSMUser
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 void CSIPIMSProfileAgent::DeregisterProfileL(
       
   575     CSIPConcreteProfile& aSIPProfile)
       
   576     {
       
   577     PROFILE_DEBUG3("CSIPIMSProfileAgent::DeregisterProfileL", aSIPProfile.Id())
       
   578     
       
   579     DeregisterL(aSIPProfile);
       
   580     }
       
   581 
       
   582 // -----------------------------------------------------------------------------
       
   583 // CSIPIMSProfileAgent::RetryProfileRegistrationL
       
   584 // From MSIPProfileFSMUser
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 void CSIPIMSProfileAgent::RetryProfileRegistrationL( 
       
   588     CSIPConcreteProfile& aSIPProfile)
       
   589     {
       
   590 	PROFILE_DEBUG3("CSIPIMSProfileAgent::RetryProfileRegistrationL", 
       
   591 	               aSIPProfile.Id())
       
   592 
       
   593 	if (!iProfileQueueHandling->AddRegisterToQueueL(aSIPProfile, ETrue))
       
   594 		{
       
   595         CSIPIMSProfileContext* context = FindProfileContext(aSIPProfile);
       
   596         if (!context)
       
   597 	        {
       
   598 	        User::Leave(KErrNotFound);
       
   599 	        }		
       
   600         context->RetryRegistration();
       
   601 		}     
       
   602     }
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // CSIPIMSProfileAgent::AddProfileIntoQueue
       
   606 // From MSIPProfileFSMUser
       
   607 // -----------------------------------------------------------------------------
       
   608 //
       
   609 TBool CSIPIMSProfileAgent::AddProfileIntoQueue(
       
   610     CSIPConcreteProfile& aSIPProfile) const
       
   611     {
       
   612 	PROFILE_DEBUG3("CSIPIMSProfileAgent::AddProfileIntoQueue", 
       
   613 	               aSIPProfile.Id())
       
   614 	                   
       
   615 	TBool found = EFalse;
       
   616 		    
       
   617 	for (TInt i=0; i < iConnectionCtxArray.Count() && !found; i++)
       
   618 		{
       
   619 		found = iConnectionCtxArray[i]->AddIntoQueue( 
       
   620 		    aSIPProfile.Server(KSIPRegistrar));
       
   621 		}
       
   622 	return found;
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CSIPIMSProfileAgent::RegisterProfileAfterQueueL
       
   627 // From MSIPProfileFSMUser
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 void CSIPIMSProfileAgent::RegisterProfileAfterQueueL(
       
   631     CSIPConcreteProfile& aSIPProfile)
       
   632     {
       
   633 	PROFILE_DEBUG3("CSIPIMSProfileAgent::RegisterProfileAfterQueueL", 
       
   634 	               aSIPProfile.Id())    
       
   635     
       
   636     RegisterFromAuthorizedArrayL(aSIPProfile);   
       
   637     }
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // CSIPIMSProfileAgent::DeregisterProfileAfterQueueL
       
   641 // From MSIPProfileFSMUser
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 void CSIPIMSProfileAgent::DeregisterProfileAfterQueueL(
       
   645     CSIPConcreteProfile& aSIPProfile)
       
   646     {
       
   647 	PROFILE_DEBUG3("CSIPIMSProfileAgent::DeregisterProfileAfterQueueL", 
       
   648 	               aSIPProfile.Id())    
       
   649     
       
   650 	CSIPIMSProfileContext* context = FindProfileContext(aSIPProfile);
       
   651 	__ASSERT_ALWAYS(context, User::Leave(KErrNotFound));
       
   652     context->DeregisterL();
       
   653     
       
   654     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // CSIPIMSProfileAgent::RetryProfileRegistrationAfterQueueL
       
   658 // From MSIPProfileFSMUser
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void CSIPIMSProfileAgent::RetryProfileRegistrationAfterQueueL(
       
   662     CSIPConcreteProfile& aSIPProfile)
       
   663     {
       
   664 	PROFILE_DEBUG3("CSIPIMSProfileAgent::RetryRegisterAfterQueueL", 
       
   665 	               aSIPProfile.Id())    
       
   666     
       
   667     CSIPIMSProfileContext* context = FindProfileContext(aSIPProfile);
       
   668     __ASSERT_ALWAYS(context, User::Leave(KErrNotFound));
       
   669     
       
   670     context->RetryRegistration();  
       
   671     }	
       
   672  
       
   673 // -----------------------------------------------------------------------------
       
   674 // CSIPIMSProfileAgent::IsInQueue
       
   675 // From MSIPProfileFSMUser
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 TBool CSIPIMSProfileAgent::IsInQueue(
       
   679     CSIPConcreteProfile& aSIPProfile) const
       
   680     {
       
   681 	PROFILE_DEBUG3("CSIPIMSProfileAgent::IsInQueue", 
       
   682 	               aSIPProfile.Id())    
       
   683     return iProfileQueueHandling->IsInQueue(aSIPProfile);
       
   684     } 
       
   685  
       
   686 // -----------------------------------------------------------------------------
       
   687 // CSIPIMSProfileAgent::AllowedTakeFromQueue
       
   688 // -----------------------------------------------------------------------------
       
   689 //	
       
   690 TBool CSIPIMSProfileAgent::AllowedTakeFromQueue( 
       
   691     CSIPConcreteProfile& aSIPConcreteProfile )
       
   692     {
       
   693     PROFILE_DEBUG1("CSIPIMSProfileAgent::AllowedTakeFromQueue")
       
   694 	TBool found = EFalse;   
       
   695 	for (TInt i=0; i < iConnectionCtxArray.Count() && !found; i++)
       
   696 		{
       
   697 		PROFILE_DEBUG1("CSIPIMSProfileAgent::AllowedTakeFromQueue next AddIntoQueue")
       
   698 		found = iConnectionCtxArray[i]->AddIntoQueue( 
       
   699 		    aSIPConcreteProfile.Server(KSIPRegistrar) ) ;
       
   700 		}
       
   701 	return !found;
       
   702     }
       
   703  
       
   704 // -----------------------------------------------------------------------------
       
   705 // CSIPIMSProfileAgent::CheckIfConfigured
       
   706 // (other items were commented in a header).
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 TBool CSIPIMSProfileAgent::CheckIfConfigured(CSIPConcreteProfile& aSIPProfile)
       
   710 	{
       
   711 	TBool result = EFalse;
       
   712 	if (aSIPProfile.AOR().Length())
       
   713 		{
       
   714 		return ETrue;
       
   715 		}
       
   716 	if (aSIPProfile.PrivateIdentity().Length() || 
       
   717 			aSIPProfile.ServerParameter(KSIPRegistrar, KSIPDigestUserName).Length())
       
   718 		{
       
   719 		return ETrue;
       
   720 		}
       
   721 	if (aSIPProfile.ServerParameter(KSIPRegistrar, KSIPDigestRealm).Length())
       
   722 		{
       
   723 		return ETrue;
       
   724 		}
       
   725 	if (aSIPProfile.ServerParameter(KSIPRegistrar, KSIPDigestPassword).Length())
       
   726 		{
       
   727 		return ETrue;
       
   728 		}
       
   729 
       
   730 	if (aSIPProfile.Server(KSIPRegistrar).Length())
       
   731 		{
       
   732 		return ETrue;
       
   733 		}
       
   734 
       
   735 	if (aSIPProfile.ServerParameter(KSIPOutboundProxy, KSIPDigestUserName).Length())
       
   736 		{
       
   737 		return ETrue;
       
   738 		}
       
   739 	if (aSIPProfile.ServerParameter(KSIPOutboundProxy, KSIPDigestRealm).Length())
       
   740 		{
       
   741 		return ETrue;
       
   742 		}
       
   743 	if (aSIPProfile.ServerParameter(KSIPOutboundProxy, KSIPDigestPassword).Length())
       
   744 		{
       
   745 		return ETrue;
       
   746 		}	
       
   747 	return result;
       
   748 	}
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CSIPIMSProfileAgent::MandatoryValuesConfigured
       
   752 // (other items were commented in a header).
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 TBool CSIPIMSProfileAgent::MandatoryValuesConfigured(
       
   756     CSIPConcreteProfile& aSIPProfile)
       
   757 	{
       
   758 	TBool result = ETrue;
       
   759 	if(!aSIPProfile.IapId())
       
   760 		{
       
   761 		return EFalse;
       
   762 		}
       
   763 	if (!aSIPProfile.AOR().Length())
       
   764 		{
       
   765 		return EFalse;
       
   766 		}	
       
   767 	if (!aSIPProfile.PrivateIdentity().Length() && 
       
   768 		!aSIPProfile.ServerParameter(KSIPRegistrar, KSIPDigestUserName).Length())
       
   769 		{
       
   770 		return EFalse;
       
   771 		}	
       
   772 	if (!aSIPProfile.ServerParameter(KSIPRegistrar, KSIPDigestPassword).Length())
       
   773 		{
       
   774 		return EFalse;
       
   775 		}
       
   776 	if (!aSIPProfile.Server(KSIPRegistrar).Length())
       
   777 		{
       
   778 		return EFalse;
       
   779 		}
       
   780 	return result;
       
   781 	}
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CSIPIMSProfileAgent::SIPProfileStatusEvent
       
   785 // (other items were commented in a header).
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 void CSIPIMSProfileAgent::SIPProfileStatusEvent(
       
   789 	CSIPConcreteProfile& aProfile,
       
   790 	TUint32 aContextId)
       
   791 	{
       
   792 	TUint32 profileId = aProfile.Id();
       
   793 	PROFILE_DEBUG4( "CSIPIMSProfileAgent::SIPProfileStatusEvent",\
       
   794 		profileId, aContextId )
       
   795 	TBool reportStatusToUser = ETrue;
       
   796 	CSIPIMSProfileContext* context = FindProfileContext( aProfile.Id() );
       
   797 	TRAPD( err, reportStatusToUser = 
       
   798 	    HandleISIMUpdateRegistrationEventL( aProfile, context ) );
       
   799 	if ( err == KErrNone && reportStatusToUser )
       
   800 		{
       
   801 		RegisterQueue( aProfile, ETrue );
       
   802 		HandleWaitingForRegisteringArray();
       
   803 		iSIPProfileAgentObserver.SIPProfileStatusEvent( aProfile, aContextId );
       
   804 		}
       
   805 	}
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEventL
       
   809 // (other items were commented in a header).
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 TBool CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEventL(
       
   813     CSIPConcreteProfile& aProfile, 
       
   814 	CSIPIMSProfileContext* aContext)
       
   815 	{
       
   816 	PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent")
       
   817 	TBool notIsimUpdateCase = ETrue;
       
   818 	if ( iISIMUpdateProfile && iISIMUpdateProfile->Id() == aProfile.Id() )
       
   819 		{
       
   820 		PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent ISIMUpdateProfile")
       
   821 		TUint32 contextId = 0;
       
   822 		if ( aContext )
       
   823 			{
       
   824 			PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent aContext")
       
   825 			if ( aContext->CurrentState() == MSIPProfileContext::ERegistered )
       
   826 				{
       
   827 				PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent ERegistered")
       
   828 				contextId = aContext->Registration()->ContextId();
       
   829 				DeregisterL( *iISIMUpdateProfile );
       
   830 				notIsimUpdateCase = EFalse;
       
   831 				iSIPProfileAgentObserver.SIPProfileStatusEvent( aProfile, contextId );
       
   832 				}
       
   833 			}
       
   834 		else
       
   835 			{
       
   836 			PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent no aContext")
       
   837 			FindProfileContextAndRegisterL( *iISIMUpdateProfile );
       
   838             notIsimUpdateCase = EFalse;
       
   839 			}
       
   840 		}
       
   841 	if ( iInterimProfile && 
       
   842 	     iInterimProfile->Id() == aProfile.Id() && 
       
   843 	     !aContext )
       
   844 		{
       
   845 		FindProfileContextAndRegisterL( *iInterimProfile );
       
   846         notIsimUpdateCase = EFalse;
       
   847 		}
       
   848 	PROFILE_DEBUG1("CSIPIMSProfileAgent::HandleISIMUpdateRegistrationEvent end")	
       
   849 	return notIsimUpdateCase;
       
   850 	}
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CSIPIMSProfileAgent::HandleWaitingForRegisteringArray
       
   854 // (other items were commented in a header).
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 void CSIPIMSProfileAgent::HandleWaitingForRegisteringArray()
       
   858 	{
       
   859 	if ( iWaitForRegisteringArray.Count() )
       
   860 		{
       
   861 		TBool isRegInProgress = EFalse;
       
   862 
       
   863 		if ( IsIPSecAlreadyInUse( isRegInProgress ) )
       
   864 			{
       
   865 			//delete all in the que, one by one
       
   866 			DeleteAllProfilesInWaitingQue();
       
   867 			}
       
   868 		else
       
   869 			{
       
   870 			if ( !isRegInProgress )
       
   871 				{
       
   872 				//take the first in the que and register
       
   873 				TRAP_IGNORE( RegisterFromWaitingQueL() )
       
   874 				}
       
   875 			}		
       
   876 		}
       
   877 	}
       
   878 
       
   879 // -----------------------------------------------------------------------------
       
   880 // CSIPIMSProfileAgent::DeleteAllProfilesInWaitingQue
       
   881 // (other items were commented in a header).
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 void CSIPIMSProfileAgent::DeleteAllProfilesInWaitingQue()
       
   885 	{
       
   886 	PROFILE_DEBUG1("CSIPIMSProfileAgent::DeleteAllProfilesInWaitingQue")
       
   887 	
       
   888 	CSIPConcreteProfile* profile = NULL;
       
   889 	for (TInt i=0; i< iWaitForRegisteringArray.Count();i++)
       
   890 		{
       
   891 		profile = iWaitForRegisteringArray[i];
       
   892 		if (profile)
       
   893 			{
       
   894 			TerminateAndErrorEvent(*profile, KErrArgument);
       
   895 			iWaitForRegisteringArray.Remove(i);
       
   896 			}
       
   897 		}
       
   898 	iWaitForRegisteringArray.Compress();
       
   899 	}
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // CSIPIMSProfileAgent::RegisterFromWaitingQueL
       
   903 // (other items were commented in a header).
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 void CSIPIMSProfileAgent::RegisterFromWaitingQueL()
       
   907 	{
       
   908 	PROFILE_DEBUG1("CSIPIMSProfileAgent::RegisterFromWaitingQue")
       
   909 	CSIPConcreteProfile* profile = 
       
   910         RemoveFirstProfileFromArray( iWaitForRegisteringArray );
       
   911 	if ( profile )
       
   912 		{
       
   913 		ProfileToWaitingQueueL( profile );
       
   914 		}
       
   915 	}
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CSIPIMSProfileAgent::RemoveFirstProfileFromArray
       
   919 // (other items were commented in a header).
       
   920 // -----------------------------------------------------------------------------
       
   921 //	
       
   922 CSIPConcreteProfile* CSIPIMSProfileAgent::RemoveFirstProfileFromArray( 
       
   923 							RPointerArray<CSIPConcreteProfile>& aProfileArray )
       
   924 	{
       
   925 	CSIPConcreteProfile* profile = NULL;
       
   926 	if (aProfileArray.Count() > 0)
       
   927 		{
       
   928 		profile = aProfileArray[0];
       
   929 		aProfileArray.Remove(0);
       
   930 		aProfileArray.Compress();
       
   931 		}
       
   932 	return profile;
       
   933 	}	
       
   934 	
       
   935 // ----------------------------------------------------------------------------
       
   936 // CSIPIMSProfileAgent::TerminateAndErrorEvent
       
   937 // (other items were commented in a header).
       
   938 // -----------------------------------------------------------------------------
       
   939 //	
       
   940 void CSIPIMSProfileAgent::TerminateAndErrorEvent( CSIPConcreteProfile& aProfile,
       
   941 												  TInt aError )
       
   942 	{
       
   943 	TerminateHandling(aProfile);
       
   944 	iSIPProfileAgentObserver.SIPProfileErrorEvent(aProfile,aError);	
       
   945 	}
       
   946 
       
   947 // -----------------------------------------------------------------------------
       
   948 // CSIPIMSProfileAgent::FoundIPSecProfileCandidate
       
   949 // (other items were commented in a header).
       
   950 // -----------------------------------------------------------------------------
       
   951 //	
       
   952 TBool CSIPIMSProfileAgent::FoundIPSecProfileCandidate()
       
   953 	{
       
   954 	TBool result = EFalse;
       
   955 	if ( iUsimProvider && iUsimProvider->IsUsimSupported() )
       
   956 		{
       
   957 		result = iProfileQueueHandling->FoundIPSecProfileCandidate();
       
   958 		}
       
   959 	return result;
       
   960 	}
       
   961 
       
   962 // -----------------------------------------------------------------------------
       
   963 // CSIPIMSProfileAgent::ChooseProfileTypeL
       
   964 // (other items were commented in a header).
       
   965 // -----------------------------------------------------------------------------
       
   966 //	
       
   967 void CSIPIMSProfileAgent::ChooseProfileTypeL( CSIPConcreteProfile* aProfile,
       
   968 									 CSIPIMSProfileContext* context )
       
   969 	{
       
   970 	if (CheckIfConfigured(*aProfile))	
       
   971 		{
       
   972 		context->SetConfiguredType(CSIPIMSProfileContext::EClientConfiguredType);
       
   973 		}
       
   974 	else
       
   975 		{
       
   976 		if (iUsimProvider && !iUsimProvider->IsUsimSupported())	
       
   977 			{
       
   978 			context->SetConfiguredType(CSIPIMSProfileContext::EEarlyIMSType);
       
   979 			}
       
   980 		if (iUsimProvider && iUsimProvider->IsUsimSupported())
       
   981 			{
       
   982 			context->SetConfiguredType(CSIPIMSProfileContext::EIMSReleaseType);
       
   983 			}
       
   984 		}
       
   985 	}
       
   986 
       
   987 // -----------------------------------------------------------------------------
       
   988 // CSIPIMSProfileAgent::RegisterFromAuthorizedArrayL
       
   989 // (other items were commented in a header).
       
   990 // -----------------------------------------------------------------------------
       
   991 //	
       
   992 void CSIPIMSProfileAgent::RegisterFromAuthorizedArrayL(
       
   993     CSIPConcreteProfile& aProfile)
       
   994 	{
       
   995 	PROFILE_DEBUG1("CSIPIMSProfileAgent::RegisterFromAuthorizedArrayL")
       
   996 	FindProfileContextAndRegisterL( aProfile );
       
   997 	}
       
   998 
       
   999 // -----------------------------------------------------------------------------
       
  1000 // CSIPIMSProfileAgent::ProfileToWaitingQueueL
       
  1001 // (other items were commented in a header).
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //	
       
  1004 void CSIPIMSProfileAgent::ProfileToWaitingQueueL( 
       
  1005     CSIPConcreteProfile* aProfile )
       
  1006 	{
       
  1007 	PROFILE_DEBUG1("CSIPIMSProfileAgent::ProfileToWaitingQueueL")
       
  1008 	if ( !iProfileQueueHandling->AddRegisterToQueueL( *aProfile, EFalse ) )
       
  1009 		{
       
  1010 		RegisterFromAuthorizedArrayL( *aProfile );
       
  1011 		}
       
  1012 	}
       
  1013 	
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CSIPIMSProfileAgent::DeregisterToWaitingQueueL
       
  1016 // -----------------------------------------------------------------------------
       
  1017 //	
       
  1018 TBool CSIPIMSProfileAgent::DeregisterToWaitingQueueL( 
       
  1019     CSIPIMSProfileContext* aContext )
       
  1020 	{
       
  1021 	PROFILE_DEBUG1("CSIPIMSProfileAgent::DeregisterToWaitingQueueL")
       
  1022 	return iProfileQueueHandling->AddDeregisterToQueueL( *aContext->Profile() );
       
  1023 	}	
       
  1024 
       
  1025 // -----------------------------------------------------------------------------
       
  1026 // CSIPIMSProfileAgent::SetInterimProfile
       
  1027 // (other items were commented in a header).
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //
       
  1030 void CSIPIMSProfileAgent::SetInterimProfile( CSIPConcreteProfile* aSIPConcreteProfile )
       
  1031 	{
       
  1032 	iInterimProfile = aSIPConcreteProfile;
       
  1033 	}
       
  1034 
       
  1035 // -----------------------------------------------------------------------------
       
  1036 // CSIPIMSProfileAgent::SIPProfileErrorEvent
       
  1037 // (other items were commented in a header).
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 void CSIPIMSProfileAgent::SIPProfileErrorEvent(
       
  1041     CSIPConcreteProfile& aProfile,
       
  1042     TInt aError)
       
  1043 	{
       
  1044 	PROFILE_DEBUG4("CSIPIMSProfileAgent::SIPProfileErrorEvent", 
       
  1045 	               aProfile.Id(), aError)
       
  1046 		
       
  1047 	CSIPIMSProfileContext* context = FindProfileContext( aProfile.Id() );
       
  1048 	TBool reportStatusToUser = ETrue;
       
  1049 	TRAPD( err, reportStatusToUser = 
       
  1050 	    HandleISIMUpdateRegistrationEventL( aProfile, context ) );	
       
  1051 	if ( reportStatusToUser )
       
  1052 		{
       
  1053 		if ( context && context->IgnoreErrorEvent() )
       
  1054 			{
       
  1055 			PROFILE_DEBUG4( "CSIPIMSProfileAgent::Error ignored",\
       
  1056 				aProfile.Id(), aError )	
       
  1057 			}
       
  1058 		else
       
  1059 			{
       
  1060 			if ( err == KErrNone )
       
  1061 			    {
       
  1062 			    err = aError;
       
  1063 			    }
       
  1064 			    
       
  1065 			PROFILE_DEBUG4( "CSIPIMSProfileAgent::Error sent",\
       
  1066 				aProfile.Id(), err )
       
  1067 	
       
  1068 			RegisterQueue( aProfile, EFalse );
       
  1069 			HandleWaitingForRegisteringArray();
       
  1070 			iSIPProfileAgentObserver.SIPProfileErrorEvent( aProfile, err );	
       
  1071 			}
       
  1072 		}
       
  1073 	}
       
  1074 
       
  1075 // -----------------------------------------------------------------------------
       
  1076 // CSIPIMSProfileAgent::ProceedRegistration
       
  1077 // (other items were commented in a header).
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //
       
  1080 TBool CSIPIMSProfileAgent::ProceedRegistration(
       
  1081 	CSIPConcreteProfile& aProfile,
       
  1082 	TInt aError)
       
  1083 	{
       
  1084 	PROFILE_DEBUG3("CSIPIMSProfileAgent::ProceedRegistration", aProfile.Id())
       
  1085 	return iSIPProfileAgentObserver.ProceedRegistration(aProfile, aError);
       
  1086 	}
       
  1087 	
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // CSIPIMSProfileAgent::GetFailedProfilesL
       
  1090 // (other items were commented in a header).
       
  1091 // -----------------------------------------------------------------------------
       
  1092 //
       
  1093 void CSIPIMSProfileAgent::GetFailedProfilesL(const TSIPProfileTypeInfo& /*aType*/,
       
  1094 					      RPointerArray<CSIPConcreteProfile>& /*aArray*/ ) const
       
  1095 	{
       
  1096 	}	
       
  1097 	
       
  1098 
       
  1099 // -----------------------------------------------------------------------------
       
  1100 // CSIPIMSProfileAgent::AuthorizedL
       
  1101 // (other items were commented in a header).
       
  1102 // -----------------------------------------------------------------------------
       
  1103 //
       
  1104 void CSIPIMSProfileAgent::AuthorizedL()
       
  1105 	{
       
  1106 	PROFILE_DEBUG1("CSIPIMSProfileAgent::AuthorizedL")
       
  1107 	//function called after async call to request for authorization info
       
  1108 	CSIPConcreteProfile* profile = NULL;
       
  1109 	if (iSIMRecord->PrivateIdentity().Length())
       
  1110 		{
       
  1111 		while (iUSimWaitForAuthorizedArray.Count() > 0)
       
  1112 			{
       
  1113 			profile = NULL;
       
  1114 			profile = RemoveFirstProfileFromArray( 
       
  1115 								iUSimWaitForAuthorizedArray );
       
  1116 		
       
  1117 			if (RegAllowedWithUSIMorISIML(*profile))
       
  1118 				{
       
  1119 				if (profile->IsSecurityNegotiationEnabled() &&
       
  1120 	 				!CSIPIMSProfileContext::IsHttpDigestSettingsConfigured(
       
  1121 	 									*profile))
       
  1122 					{	
       
  1123 					_LIT8(KSIPIpSec3gpp, "ipsec-3gpp");
       
  1124 					if (CSIPIMSProfileContext::IsSupportedSecurityMechanismL(
       
  1125 											*iSIP, KSIPIpSec3gpp))
       
  1126 						{
       
  1127 						TRAPD(err, CheckIPSecRulesL(*profile));
       
  1128 						CPPUNIT_MEMORYLEAVE
       
  1129 						if (err)
       
  1130 							{
       
  1131 							TerminateAndErrorEvent(*profile, KErrArgument);
       
  1132 							}
       
  1133 						}
       
  1134 					else
       
  1135 						{
       
  1136 						TerminateAndErrorEvent(*profile, KErrArgument);
       
  1137 						}
       
  1138 					}
       
  1139 				else
       
  1140 					{
       
  1141 					ProfileToWaitingQueueL( profile );
       
  1142 					}	
       
  1143 				}
       
  1144 			else
       
  1145 				{
       
  1146 				TerminateAndErrorEvent(*profile, KErrNotSupported);
       
  1147 				}
       
  1148 			}
       
  1149 		}
       
  1150 	if ( iSIMRecord->SIMPrivateIdentity().Length() )
       
  1151 		{
       
  1152 		while (iSIMWaitForAuthorizedArray.Count() > 0)
       
  1153 			{
       
  1154 			profile = RemoveFirstProfileFromArray( 
       
  1155 									iSIMWaitForAuthorizedArray );
       
  1156 			ProfileToWaitingQueueL( profile );
       
  1157 			}
       
  1158 		}
       
  1159 		
       
  1160 	while (iWaitForAuthorizedArray.Count() > 0)
       
  1161 		{
       
  1162 		profile = RemoveFirstProfileFromArray( 
       
  1163 									iWaitForAuthorizedArray );
       
  1164 		ProfileToWaitingQueueL( profile );
       
  1165 		}
       
  1166 	}
       
  1167 		
       
  1168 // -----------------------------------------------------------------------------
       
  1169 // CSIPIMSProfileAgent::AsyncDeltaTimer
       
  1170 // (other items were commented in a header).
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //	
       
  1173 void CSIPIMSProfileAgent::AsyncDeltaTimer()
       
  1174 	{
       
  1175 	PROFILE_DEBUG1("CSIPIMSProfileAgent::AsyncDeltaTimer")	
       
  1176 	if (iDeltaTimerEntryListCount == 0)
       
  1177   		{
       
  1178   		TTimeIntervalMicroSeconds32 interval(KAuthorizedMicroSecsInSec);
       
  1179   		iDeltaTimer.Queue(interval,iDeltaTimerEntry);
       
  1180   		}
       
  1181   	iDeltaTimerEntryListCount++;
       
  1182 	}
       
  1183 	
       
  1184 // ----------------------------------------------------------------------------
       
  1185 // CSIPIMSProfileAgent::ASyncTimerExpired
       
  1186 // ----------------------------------------------------------------------------
       
  1187 //     
       
  1188 TInt CSIPIMSProfileAgent::ASyncTimerExpired(TAny* aPtr)
       
  1189 	{
       
  1190 	PROFILE_DEBUG1("CSIPIMSProfileAgent::ASyncTimerExpired")
       
  1191 	CSIPIMSProfileAgent* self = reinterpret_cast<CSIPIMSProfileAgent*>(aPtr);
       
  1192   	TRAPD(err, self->AuthorizedL());
       
  1193    	CPPUNIT_MEMORYLEAVE
       
  1194     err++;
       
  1195     self->iDeltaTimerEntryListCount = 0;
       
  1196     self->iDeltaTimer.Remove(self->iDeltaTimerEntry);
       
  1197     return ETrue;
       
  1198 	}
       
  1199 	
       
  1200 // -----------------------------------------------------------------------------
       
  1201 // CSIPIMSProfileAgent::AuthorizationFailed
       
  1202 // (other items were commented in a header).
       
  1203 // -----------------------------------------------------------------------------
       
  1204 //
       
  1205 void CSIPIMSProfileAgent::AuthorizationFailed()
       
  1206 	{
       
  1207 	PROFILE_DEBUG1("CSIPIMSProfileAgent::AuthorizationFailed")
       
  1208 	TInt error = 0;
       
  1209 	//function called after async call to request for authorization info
       
  1210 	CSIPConcreteProfile* profile = NULL;
       
  1211 	while (iUSimWaitForAuthorizedArray.Count() > 0)
       
  1212 		{
       
  1213 		profile = RemoveFirstProfileFromArray( 
       
  1214 									iUSimWaitForAuthorizedArray );
       
  1215 		if (RegAllowedWithSIM(*profile))
       
  1216 			{
       
  1217 			TRAP(error, iSIMWaitForAuthorizedArray.AppendL(profile));
       
  1218 			}
       
  1219 		else
       
  1220 			{
       
  1221 			TerminateAndErrorEvent( *profile, KErrNotSupported );
       
  1222 			}
       
  1223 		}
       
  1224 	if (!error)
       
  1225 		{
       
  1226 		TRAP(error, iUsimProvider->RequestL());
       
  1227 		}
       
  1228 	if(error)
       
  1229 		{
       
  1230 		AuthorizationSIMFailed();
       
  1231 		AuthorizationUSIMFailed();
       
  1232 		}
       
  1233 	}	
       
  1234 
       
  1235 // -----------------------------------------------------------------------------
       
  1236 // CSIPIMSProfileAgent::AuthorizationSIMFailed
       
  1237 // (other items were commented in a header).
       
  1238 // -----------------------------------------------------------------------------
       
  1239 //
       
  1240 void CSIPIMSProfileAgent::AuthorizationSIMFailed()
       
  1241 	{
       
  1242 	PROFILE_DEBUG1("CSIPIMSProfileAgent::AuthorizationSIMFailed")
       
  1243 	//function called after async call to request for authorization info
       
  1244 	CSIPConcreteProfile* profile = NULL;
       
  1245 	while (iSIMWaitForAuthorizedArray.Count() > 0)
       
  1246 		{
       
  1247 		profile = RemoveFirstProfileFromArray( 
       
  1248 											iSIMWaitForAuthorizedArray );
       
  1249 		TerminateAndErrorEvent( *profile, KErrArgument );
       
  1250 		}
       
  1251 	}	
       
  1252 
       
  1253 // -----------------------------------------------------------------------------
       
  1254 // CSIPIMSProfileAgent::AuthorizationUSIMFailed
       
  1255 // (other items were commented in a header).
       
  1256 // -----------------------------------------------------------------------------
       
  1257 //
       
  1258 void CSIPIMSProfileAgent::AuthorizationUSIMFailed()
       
  1259 	{
       
  1260 	PROFILE_DEBUG1("CSIPIMSProfileAgent::AuthorizationUSIMFailed")
       
  1261 	//function called after async call to request for authorization info
       
  1262 	CSIPConcreteProfile* profile = NULL;
       
  1263 	while (iUSimWaitForAuthorizedArray.Count() > 0)
       
  1264 		{
       
  1265 		profile = RemoveFirstProfileFromArray( 
       
  1266 							iUSimWaitForAuthorizedArray );
       
  1267 		TerminateAndErrorEvent( *profile, KErrArgument );
       
  1268 		}
       
  1269 	}	
       
  1270 
       
  1271 // -----------------------------------------------------------------------------
       
  1272 // CSIPIMSProfileAgent::UpdateRegistrationsL
       
  1273 // (other items were commented in a header).
       
  1274 // -----------------------------------------------------------------------------
       
  1275 //
       
  1276 void CSIPIMSProfileAgent::UpdateRegistrationsL()
       
  1277 	{
       
  1278 	PROFILE_DEBUG1("CSIPIMSProfileAgent::UpdateRegistrationsL")
       
  1279 	//function called after ISIM OTA update notified
       
  1280 	CheckIMSReleaseTypeProfilesL();
       
  1281 	}	
       
  1282 
       
  1283 // -----------------------------------------------------------------------------
       
  1284 // CSIPIMSProfileAgent::CheckIMSReleaseTypeProfilesL
       
  1285 // (other items were commented in a header).
       
  1286 // -----------------------------------------------------------------------------
       
  1287 //
       
  1288 void CSIPIMSProfileAgent::CheckIMSReleaseTypeProfilesL()
       
  1289 	{
       
  1290 	PROFILE_DEBUG1("CSIPIMSProfileAgent::CheckIMSReleaseTypeProfilesL")
       
  1291 	//check if there is EIMSReleaseType profiles
       
  1292 	TBool found = EFalse;
       
  1293 	found = CheckRegistrationsL();
       
  1294 	CSIPConcreteProfile* profile = NULL;
       
  1295 	if ( !found )
       
  1296 		{
       
  1297 		TBool registering = EFalse;
       
  1298 		profile = iProfileQueueHandling->IPSecProfileCandidate( registering );
       
  1299 		if ( profile )
       
  1300 			{
       
  1301 			iUSimWaitForAuthorizedArray.AppendL( profile );
       
  1302 			found = ETrue;
       
  1303 			}
       
  1304 		else
       
  1305 			{
       
  1306 			profile = PreviouslyFailedIMSProfileL();
       
  1307 			if ( profile )
       
  1308 				{
       
  1309 				iISIMUpdateProfile = profile;
       
  1310 				iUSimWaitForAuthorizedArray.AppendL( profile );
       
  1311 				}
       
  1312 			}
       
  1313 		}
       
  1314 	}
       
  1315 
       
  1316 // -----------------------------------------------------------------------------
       
  1317 // CSIPIMSProfileAgent::PreviouslyFailedIMSProfileL
       
  1318 // (other items were commented in a header).
       
  1319 // -----------------------------------------------------------------------------
       
  1320 //
       
  1321 CSIPConcreteProfile* CSIPIMSProfileAgent::PreviouslyFailedIMSProfileL()
       
  1322 	{
       
  1323 	PROFILE_DEBUG1("CSIPIMSProfileAgent::PreviouslyFailedIMSProfile")
       
  1324 	iPreviouslyFailedIMSProfile = 0;
       
  1325 	iSIPProfileAgentObserver.GetFailedProfilesL(Type(), iFailedProfilesArray);
       
  1326 	for (TInt i = 0; i < iFailedProfilesArray.Count(); i++)
       
  1327         {
       
  1328         if (!CheckIfConfigured(*iFailedProfilesArray[i]))
       
  1329         	{
       
  1330         	iPreviouslyFailedIMSProfile = iFailedProfilesArray[i];
       
  1331         	iFailedProfilesArray.Reset();
       
  1332         	}
       
  1333         }
       
  1334 	return iPreviouslyFailedIMSProfile;
       
  1335 	}
       
  1336 
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // CSIPIMSProfileAgent::RemoveProfileFromWaitingQueue
       
  1339 // (other items were commented in a header).
       
  1340 // -----------------------------------------------------------------------------
       
  1341 //	
       
  1342 CSIPConcreteProfile* CSIPIMSProfileAgent::RemoveProfileFromWaitingQueue(
       
  1343 							RPointerArray<CSIPConcreteProfile>& aProfileArray,
       
  1344 							CSIPConcreteProfile& aSIPConcreteProfile )
       
  1345 	{
       
  1346 	TBool found = EFalse;
       
  1347     CSIPConcreteProfile* profile = NULL;
       
  1348 	for (TInt i=0; i< aProfileArray.Count() && !found; i++)
       
  1349 		{
       
  1350 		CSIPConcreteProfile* tmp = aProfileArray[ i ];
       
  1351 		found = ( tmp->Id() == aSIPConcreteProfile.Id() );
       
  1352 		profile = NULL;
       
  1353 		if ( found )
       
  1354 			{
       
  1355 			profile = tmp;
       
  1356 			aProfileArray.Remove( i );
       
  1357 			aProfileArray.Compress();
       
  1358 			}					
       
  1359 		}
       
  1360 	return profile;	
       
  1361 	}
       
  1362 
       
  1363 // -----------------------------------------------------------------------------
       
  1364 // CSIPIMSProfileAgent::FindProfileContextAndRegisterL
       
  1365 // (other items were commented in a header).
       
  1366 // -----------------------------------------------------------------------------
       
  1367 //
       
  1368 void CSIPIMSProfileAgent::FindProfileContextAndRegisterL( 
       
  1369 	CSIPConcreteProfile& aSIPConcreteProfile )
       
  1370 	{
       
  1371 	PROFILE_DEBUG1("CSIPIMSProfileAgent::FindProfileContextAndRegisterL")
       
  1372 	CSIPIMSProfileContext* context = FindProfileContext(aSIPConcreteProfile);
       
  1373 	if (!context)
       
  1374 		{
       
  1375 		TRAPD(err, context = &ProvideProfileContextL(aSIPConcreteProfile));
       
  1376 		CPPUNIT_MEMORYLEAVE
       
  1377 		if (err)
       
  1378 			{
       
  1379 			ResetISIMUpdateProfile( iISIMUpdateProfile );
       
  1380 			TerminateAndErrorEvent(aSIPConcreteProfile, KErrArgument);
       
  1381 			}
       
  1382 		}
       
  1383 	if (context)
       
  1384 		{
       
  1385 		ChooseProfileTypeL( &aSIPConcreteProfile , context );	
       
  1386 		TRAPD(err, context->RegisterL());
       
  1387 		CPPUNIT_MEMORYLEAVE
       
  1388 		if (err)
       
  1389 			{
       
  1390 			ResetISIMUpdateProfile( iISIMUpdateProfile );
       
  1391 			TerminateAndErrorEvent(aSIPConcreteProfile, KErrArgument);
       
  1392 			}
       
  1393 		else
       
  1394 			{
       
  1395 			if (iISIMUpdateProfile && 
       
  1396 					( iISIMUpdateProfile->Id() == aSIPConcreteProfile.Id() ))
       
  1397 				{
       
  1398 				iISIMUpdateProfile = 0;
       
  1399 				TUint32 contextId = context->Registration()->ContextId();
       
  1400 	
       
  1401 				iSIPProfileAgentObserver.SIPProfileStatusEvent(
       
  1402 				    aSIPConcreteProfile, contextId );
       
  1403 				}
       
  1404 			else
       
  1405 				{
       
  1406 				if ( iInterimProfile && 
       
  1407 				     iInterimProfile->Id() == aSIPConcreteProfile.Id() )
       
  1408 					{
       
  1409 					PROFILE_DEBUG1("CSIPIMSProfileAgent::FindProfileContextAndRegisterL iInterimProfile")
       
  1410 					iInterimProfile = 0;
       
  1411 					TUint32 contextId = context->Registration()->ContextId();
       
  1412 	
       
  1413 					iSIPProfileAgentObserver.SIPProfileStatusEvent(
       
  1414 					    aSIPConcreteProfile, contextId );
       
  1415 					}
       
  1416 				}
       
  1417 			}
       
  1418 		}
       
  1419 	PROFILE_DEBUG1("CSIPIMSProfileAgent::FindProfileContextAndRegisterL end")
       
  1420 	}
       
  1421 
       
  1422 // -----------------------------------------------------------------------------
       
  1423 // CSIPIMSProfileAgent::CheckRegistrationsL
       
  1424 // (other items were commented in a header).
       
  1425 // -----------------------------------------------------------------------------
       
  1426 //
       
  1427 TBool CSIPIMSProfileAgent::CheckRegistrationsL()
       
  1428 	{
       
  1429 	PROFILE_DEBUG1("CSIPIMSProfileAgent::CheckRegistrationsL")
       
  1430 	TBool found = EFalse;
       
  1431 	TUint32 profileId = 0;
       
  1432 	CSIPConcreteProfile* profile = NULL;
       
  1433 	for (TInt i=0; i < iConnectionCtxArray.Count() && !profileId; i++)
       
  1434 		{
       
  1435 		profileId = iConnectionCtxArray[i]->IsIPSecInUse();
       
  1436 		if (profileId)
       
  1437 			{
       
  1438 			found = ETrue;
       
  1439 			}
       
  1440 		}
       
  1441 	if ( found )
       
  1442 		{
       
  1443 		TBool registering = EFalse;
       
  1444 		iProfileQueueHandling->IPSecProfileCandidate( registering );
       
  1445 		if ( registering )
       
  1446 			{
       
  1447 			//profile is not found in deregistering que either, so new register is possible
       
  1448 			CSIPIMSProfileContext* profilecontext = FindProfileContext( profileId );
       
  1449 			MSIPProfileContext::TSIPProfileState state = 
       
  1450 			    profilecontext->CurrentState();
       
  1451 			if (state == MSIPProfileContext::EProxyResolvingInProgress ||
       
  1452 				state == MSIPProfileContext::EDelayedRegisterRequested ||
       
  1453 				state == MSIPProfileContext::ERegisterRequested)
       
  1454 				{
       
  1455 				profile = profilecontext->Profile();
       
  1456 				profilecontext->SetNextState( *iInit );
       
  1457 				CleanIdleConnectionContexts();
       
  1458 				iUSimWaitForAuthorizedArray.AppendL( profile );
       
  1459 				}
       
  1460 			if ( state == MSIPProfileContext::ERegistrationInProgress )
       
  1461 				{
       
  1462 				iISIMUpdateProfile = profilecontext->Profile();
       
  1463 				}
       
  1464 			if ( state == MSIPProfileContext::ERegistered )
       
  1465 				{
       
  1466 				iISIMUpdateProfile = profilecontext->Profile();
       
  1467 				DeregisterL( *iISIMUpdateProfile );
       
  1468 				}
       
  1469 			}
       
  1470 		}
       
  1471 	return found;
       
  1472 	}
       
  1473 
       
  1474 // -----------------------------------------------------------------------------
       
  1475 // CSIPIMSProfileAgent::IncomingRequest
       
  1476 // From MSIPObserver
       
  1477 // -----------------------------------------------------------------------------
       
  1478 //
       
  1479 void CSIPIMSProfileAgent::IncomingRequest(
       
  1480     TUint32 /*aIapId*/,
       
  1481     CSIPServerTransaction* aTransaction)
       
  1482     {
       
  1483     // Should not be called, because CSIP is created with a NULL UID
       
  1484     // Delete the transaction to prevent  amemory leak
       
  1485     delete aTransaction;
       
  1486     }
       
  1487 
       
  1488 // -----------------------------------------------------------------------------
       
  1489 // CSIPIMSProfileAgent::TimedOut
       
  1490 // From MSIPObserver
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //
       
  1493 void CSIPIMSProfileAgent::TimedOut(CSIPServerTransaction& /*aTransaction*/)
       
  1494     {
       
  1495     }
       
  1496 
       
  1497 // -----------------------------------------------------------------------------
       
  1498 // CSIPIMSProfileAgent::ChallengeReceived
       
  1499 // From MSIPHttpDigestChallengeObserver2
       
  1500 // -----------------------------------------------------------------------------
       
  1501 //
       
  1502 void CSIPIMSProfileAgent::ChallengeReceived(
       
  1503     const CSIPClientTransaction& aTransaction)
       
  1504     {
       
  1505 	TBool found = EFalse;
       
  1506 	for (TInt i=0; i < iConnectionCtxArray.Count() && !found; i++)
       
  1507 		{
       
  1508 		found = 
       
  1509 		    iConnectionCtxArray[i]->SetCredentials(aTransaction,*iHttpDigest);
       
  1510 		}
       
  1511     }
       
  1512 
       
  1513 // -----------------------------------------------------------------------------
       
  1514 // CSIPIMSProfileAgent::ChallengeReceived
       
  1515 // From MSIPHttpDigestChallengeObserver2
       
  1516 // -----------------------------------------------------------------------------
       
  1517 //
       
  1518 void CSIPIMSProfileAgent::ChallengeReceived(const CSIPRefresh& aRefresh)
       
  1519     {
       
  1520 	TBool found = EFalse;
       
  1521 	for (TInt i=0; i < iConnectionCtxArray.Count() && !found; i++)
       
  1522 		{
       
  1523 		found = iConnectionCtxArray[i]->SetCredentials(aRefresh,*iHttpDigest);
       
  1524 		}
       
  1525     }
       
  1526 
       
  1527 // -----------------------------------------------------------------------------
       
  1528 // CSIPIMSProfileAgent::FindProfileContext
       
  1529 // (other items were commented in a header).
       
  1530 // -----------------------------------------------------------------------------
       
  1531 //
       
  1532 CSIPIMSProfileContext* CSIPIMSProfileAgent::FindProfileContext(
       
  1533 	CSIPConcreteProfile& aSIPConcreteProfile) const
       
  1534 	{
       
  1535 	return FindProfileContext(aSIPConcreteProfile.Id());
       
  1536 	}
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 // CSIPIMSProfileAgent::FindProfileContext
       
  1540 // (other items were commented in a header).
       
  1541 // -----------------------------------------------------------------------------
       
  1542 //
       
  1543 CSIPIMSProfileContext* CSIPIMSProfileAgent::FindProfileContext(
       
  1544 	TUint32 aProfileId) const
       
  1545 	{
       
  1546 	for (TInt i=0; i < iConnectionCtxArray.Count(); i++)
       
  1547 		{
       
  1548 		CSIPIMSProfileContext *context = 
       
  1549 			iConnectionCtxArray[i]->FindContext(aProfileId);
       
  1550 		if (context)
       
  1551 			{
       
  1552 			return context;
       
  1553 			}
       
  1554 		}
       
  1555 	return 0;
       
  1556 	}
       
  1557 
       
  1558 // -----------------------------------------------------------------------------
       
  1559 // CSIPIMSProfileAgent::FindConnectionContext
       
  1560 // (other items were commented in a header).
       
  1561 // -----------------------------------------------------------------------------
       
  1562 //
       
  1563 CSIPIMSConnectionContext* CSIPIMSProfileAgent::FindConnectionContext(
       
  1564 	CSIPConcreteProfile& aProfile) const
       
  1565 	{
       
  1566 	CSIPIMSConnectionContext* context = 0;
       
  1567 	TBool found = EFalse;
       
  1568 	for ( TInt i=0; i < iConnectionCtxArray.Count() && !found; i++ )
       
  1569 		{
       
  1570 		if ( iConnectionCtxArray[i]->ConnectionUser( aProfile ) )
       
  1571 			{
       
  1572 			context = iConnectionCtxArray[i];
       
  1573 			found = ETrue;
       
  1574 			}
       
  1575 		}
       
  1576 	return context;
       
  1577 	}
       
  1578 
       
  1579 // -----------------------------------------------------------------------------
       
  1580 // CSIPIMSProfileAgent::FindConnectionContext
       
  1581 // (other items were commented in a header).
       
  1582 // -----------------------------------------------------------------------------
       
  1583 //
       
  1584 CSIPIMSConnectionContext* CSIPIMSProfileAgent::FindConnectionContext(
       
  1585 	TUint32 aIapId ) const
       
  1586 	{
       
  1587 	CSIPIMSConnectionContext* context =0;
       
  1588 	TBool found = EFalse;
       
  1589 	for ( TInt i=0; i < iConnectionCtxArray.Count() && !found; i++ )
       
  1590 		{
       
  1591 		if ( iConnectionCtxArray[i]->Connection()->IapId() == aIapId )
       
  1592 			{
       
  1593 			context = iConnectionCtxArray[i];
       
  1594 			found = ETrue;
       
  1595 			}
       
  1596 		}
       
  1597 	return context;
       
  1598 	}
       
  1599 
       
  1600 // -----------------------------------------------------------------------------
       
  1601 // CSIPIMSProfileAgent::ProvideProfileContextL
       
  1602 // (other items were commented in a header).
       
  1603 // -----------------------------------------------------------------------------
       
  1604 //
       
  1605 CSIPIMSProfileContext& CSIPIMSProfileAgent::ProvideProfileContextL(
       
  1606 	CSIPConcreteProfile& aProfile)
       
  1607 	{
       
  1608 	PROFILE_DEBUG1("CSIPIMSProfileAgent::ProvideProfileContextL")
       
  1609 	CSIPIMSConnectionContext* connContext = FindConnectionContext(aProfile);
       
  1610 	if (!connContext)
       
  1611 		{
       
  1612 		PROFILE_DEBUG1("CSIPIMSProfileAgent::ProvideProfileContextL create connection first")
       
  1613 
       
  1614 		connContext = CSIPIMSConnectionContext::NewLC();
       
  1615 		
       
  1616 		// If there's several profiles using the same iap, other ones need
       
  1617 		// new csip instance as once csip instance cannot contain several
       
  1618 		// csipconnections having the same iap id.
       
  1619 		//
       
  1620 		TUint32 iapId( aProfile.IapId() );	
       
  1621 		CSIPConnection* connection = NULL;
       
  1622 		if ( FindConnectionContext( iapId ) )
       
  1623 		    {
       
  1624 		    CSIP& sip = connContext->CreateSipL( *this, *this );
       
  1625 		    connection = CSIPConnection::NewLC( sip, iapId, *connContext );
       
  1626 		    }
       
  1627 		else
       
  1628 		    {
       
  1629 		    connection = CSIPConnection::NewLC( *iSIP, iapId, *connContext );
       
  1630 		    }
       
  1631 		connContext->SetConnectionL( connection );
       
  1632 		CleanupStack::Pop( connection );
       
  1633 		
       
  1634 		// Connection should be set before setting user
       
  1635 		connContext->SetConnectionUserL( aProfile );
       
  1636 		
       
  1637         iConnectionCtxArray.AppendL( connContext );
       
  1638         
       
  1639 		CleanupStack::Pop( connContext );
       
  1640 		}
       
  1641 		
       
  1642 	CSIPIMSProfileContext* profilectx = 
       
  1643 	    CSIPIMSProfileContext::NewLC(*iXMLParser, *iSIP, *connContext, *this,
       
  1644 	        *iInit, aProfile, iDeltaTimer, *iSIMRecord,*iConfigExtension);
       
  1645 	connContext->AddProfileContextL(profilectx);
       
  1646 	CleanupStack::Pop(profilectx);
       
  1647 	return *profilectx;
       
  1648 	}
       
  1649 
       
  1650 // -----------------------------------------------------------------------------
       
  1651 // CSIPIMSProfileAgent::CleanIdleConnectionContexts
       
  1652 // (other items were commented in a header).
       
  1653 // -----------------------------------------------------------------------------
       
  1654 //
       
  1655 void CSIPIMSProfileAgent::CleanIdleConnectionContexts()
       
  1656 	{
       
  1657 	PROFILE_DEBUG1("CSIPIMSProfileAgent::CleanIdleConnectionContexts")
       
  1658 	CSIPIMSConnectionContext* context = 0;
       
  1659 
       
  1660 	for (TInt i=iConnectionCtxArray.Count()-1; i>= 0;)
       
  1661 		{
       
  1662 		iConnectionCtxArray[i]->CleanIdleContexts();
       
  1663 		if (iConnectionCtxArray[i]->IsIdle())
       
  1664 			{
       
  1665 			PROFILE_DEBUG1("CSIPIMSProfileAgent::CleanIdleConnectionContexts,\
       
  1666 				ConnectionContext removed")
       
  1667 			context = iConnectionCtxArray[i];
       
  1668 			iConnectionCtxArray.Remove(i);
       
  1669 			delete context;
       
  1670 			context = NULL;
       
  1671 			}
       
  1672 		i--;
       
  1673 		}
       
  1674 		
       
  1675 	iConnectionCtxArray.Compress();
       
  1676 	}
       
  1677 	
       
  1678 // ----------------------------------------------------------------------------
       
  1679 // CSIPIMSProfileAgent::GetTsyModuleNameL
       
  1680 // ----------------------------------------------------------------------------
       
  1681 //
       
  1682 void CSIPIMSProfileAgent::GetTsyModuleNameL( TDes& aTsyModuleName ) const
       
  1683     {
       
  1684     __ASSERT_ALWAYS( aTsyModuleName.MaxSize() >= KCommsDbSvrMaxFieldLength,
       
  1685 		User::Leave( KErrArgument ) );
       
  1686 
       
  1687     using namespace CommsDat;
       
  1688 
       
  1689     CMDBSession* db = CMDBSession::NewLC(KCDVersion1_1);
       
  1690 
       
  1691     CMDBField<TUint32>* globalSettingField =
       
  1692     	new (ELeave) CMDBField<TUint32>(KCDTIdModemPhoneServicesSMS);
       
  1693     CleanupStack::PushL(globalSettingField);
       
  1694 
       
  1695     globalSettingField->SetRecordId(1);
       
  1696     globalSettingField->LoadL(*db);
       
  1697     TUint32 modemId = *globalSettingField;
       
  1698 
       
  1699     CMDBField<TDesC>* tsyField = new (ELeave) CMDBField<TDesC>(KCDTIdTsyName);
       
  1700     CleanupStack::PushL(tsyField);
       
  1701 
       
  1702     tsyField->SetRecordId(modemId);
       
  1703     tsyField->LoadL(*db);
       
  1704     aTsyModuleName = *tsyField;
       
  1705 
       
  1706     CleanupStack::PopAndDestroy(3, db); // db, tsyField & globalSettingField 
       
  1707     }
       
  1708 		
       
  1709 // ----------------------------------------------------------------------------
       
  1710 // CSIPIMSProfileAgent::RegisterQueue
       
  1711 // ----------------------------------------------------------------------------
       
  1712 //
       
  1713 TInt CSIPIMSProfileAgent::RegisterQueue( 
       
  1714     CSIPConcreteProfile& aProfile,
       
  1715     TBool aReportError )
       
  1716     {
       
  1717     PROFILE_DEBUG1("CSIPIMSProfileAgent::RegisterQueue")
       
  1718     TInt err( KErrNone );
       
  1719     
       
  1720     if ( AllowedTakeFromQueue( aProfile ) )
       
  1721         {
       
  1722         PROFILE_DEBUG1("CSIPIMSProfileAgent::RegisterQueue RegisterFromQueueL")
       
  1723         TRAP( err, iProfileQueueHandling->RegisterFromQueueL( aProfile ) );
       
  1724         }
       
  1725         
       
  1726     if ( err && aReportError )
       
  1727         {
       
  1728         PROFILE_DEBUG1("CSIPIMSProfileAgent::RegisterQueue ErrorEvent")
       
  1729         iSIPProfileAgentObserver.SIPProfileErrorEvent( aProfile, err );
       
  1730         }
       
  1731     
       
  1732     PROFILE_DEBUG3("CSIPIMSProfileAgent::RegisterQueue end, err=", err)   
       
  1733     return err;
       
  1734     }
       
  1735