realtimenetprots/sipfw/SIP/TransactionUser/src/UserAgent.cpp
changeset 0 307788aac0a8
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          : UserAgent.cpp
       
    15 // Part of       : TransactionUser
       
    16 // Version       : SIP/6.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "siperr.h"
       
    22 #include "SipAssert.h"
       
    23 #include "siprequest.h"
       
    24 #include "sipresponse.h"
       
    25 #include "sipuri.h"
       
    26 #include "uricontainer.h"
       
    27 #include "siphostport.h"
       
    28 #include "sipaddress.h"
       
    29 #include "sipfromtoheaderbase.h"
       
    30 #include "sipcontactheader.h"
       
    31 #include "sipstrings.h"
       
    32 #include "sipstrconsts.h"
       
    33 #include "SipLogs.h"
       
    34 #include "DeleteMgr.h"
       
    35 #include "Transmitter.h"
       
    36 
       
    37 #include "MSipRegistrationContact.h"
       
    38 #include "MTransactionOwner.h"
       
    39 #include "CUserAgent.h"
       
    40 #include "UserAgentState.h"
       
    41 #include "UserAgentCreateParams.h"
       
    42 #include "CTransactionStore.h"
       
    43 #include "SIPMessageUtility.h"
       
    44 #include "MTransactionUser.h"
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CUserAgent::CUserAgent
       
    49 // aObserver is NULL for UAS
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CUserAgent::CUserAgent(const CUserAgentCreateParams& aParams) :	
       
    53 	iObserver(aParams.iObserver),	
       
    54 	iTimers(aParams.iTimers),
       
    55 	iRegistrations(aParams.iRegistrations),
       
    56     iRegistrationContact(aParams.iRegistrationContact),
       
    57     iSigComp(aParams.iSigComp),
       
    58 	iTransactionStore(aParams.iTransactionStore),
       
    59 	iTransactionMgr(aParams.iTransactionMgr),	
       
    60 	iTransportProtocol(SIPStrings::StringF(SipStrConsts::EUDP)),
       
    61 	iTransportParams(aParams.iTransportParams),
       
    62 	iTimerValues(aParams.iTimerValues),
       
    63 	iOwnsOutgoingMsg(aParams.iOwnsOutgoingMsg),
       
    64 	iDeleteMgr(aParams.iDeleteMgr),
       
    65 	iSIPMsgUtility(aParams.iSIPMsgUtility),    
       
    66 	iState(aParams.iInitialUaState),
       
    67 	iTransactionId(aParams.iTransactionId)
       
    68 	{
       
    69 	__SIP_ASSERT_RETURN(iTransactionId != KEmptyTransactionId, KErrArgument);
       
    70     __SIP_ASSERT_RETURN(iState != NULL, KErrArgument);
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CUserAgent::ConstructL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CUserAgent::ConstructL(MSipConnectionMgr& aConnectionMgr)
       
    78 	{
       
    79 	iTransmitter = CTransmitter::NewL(aConnectionMgr);
       
    80 	}
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CUserAgent::~CUserAgent
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CUserAgent::~CUserAgent()
       
    87 	{
       
    88 	delete iTransmitter;
       
    89 	delete iTransaction;
       
    90 
       
    91 	if (iOwnsOutgoingMsg)
       
    92 		{
       
    93 		delete iOutgoingMsg;
       
    94 		}
       
    95 
       
    96 	delete iIncomingMsg;
       
    97 	iTransportProtocol.Close();	
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CUserAgent::TransportParams
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 const TSIPTransportParams& CUserAgent::TransportParams() const
       
   105     {
       
   106     __TEST_INVARIANT;
       
   107     return iTransportParams;
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CUserAgent::CleanupSilently
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CUserAgent::CleanupSilently(TAny* aUserAgent)
       
   115 	{
       
   116 	__SIP_ASSERT_RETURN(aUserAgent, KErrArgument);
       
   117 
       
   118 	CUserAgent* ua = reinterpret_cast<CUserAgent*>(aUserAgent);
       
   119 	ua->ClearTransactionOwner(); // Prevent MTransactionOwner::TransactionEnded
       
   120 	ua->Stop(KErrGeneral); 		 // End silently, error code doesn't matter
       
   121 	}
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CUserAgent::SendRequestL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CUserAgent::SendRequestL(CSIPRequest* aReq,
       
   128 							  TRegistrationId aRegisterId,
       
   129 							  const CURIContainer& aRemoteTarget)
       
   130 	{
       
   131 	__TEST_INVARIANT;
       
   132 	__SIP_ASSERT_LEAVE(aReq, KErrArgument);
       
   133     __ASSERT_ALWAYS(!iStopped, User::Leave(KErrSIPInvalidTransactionState));
       
   134 
       
   135 	iState->SendRequestL(*this, aReq, aRegisterId, aRemoteTarget);
       
   136 
       
   137 	__TEST_INVARIANT;
       
   138 	}
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CUserAgent::SendResponseL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CUserAgent::SendResponseL(CSIPResponse* aResp,
       
   145 							   const TSIPTransportParams& aParams)
       
   146 	{
       
   147 	__TEST_INVARIANT;
       
   148 	__SIP_ASSERT_LEAVE(aResp, KErrArgument);
       
   149     __ASSERT_ALWAYS(!iStopped, User::Leave(KErrSIPInvalidTransactionState));
       
   150 	
       
   151     iState->SendResponseL(*this, aResp, aParams);	
       
   152 
       
   153 	__TEST_INVARIANT;
       
   154 	}
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CUserAgent::SendCancelL
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CUserAgent::SendCancelL(TTransactionId aInviteTaId)
       
   161 	{
       
   162 	__TEST_INVARIANT;
       
   163     __ASSERT_ALWAYS(!iStopped, User::Leave(KErrSIPInvalidTransactionState));
       
   164 
       
   165 	iState->SendCancelL(*this, aInviteTaId);
       
   166 	
       
   167 	__TEST_INVARIANT;
       
   168 	}
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CUserAgent::TransactionOwner
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 const MTransactionOwner* CUserAgent::TransactionOwner() const
       
   175 	{
       
   176 	__TEST_INVARIANT;
       
   177 	return iObserver;
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CUserAgent::ClearTransactionOwner
       
   182 // Detach iOutgoingMsg unless owned, as the upper layer can delete it.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CUserAgent::ClearTransactionOwner()
       
   186 	{
       
   187 	__TEST_INVARIANT;
       
   188 
       
   189 	iObserver = NULL;
       
   190 
       
   191 	if (!iOwnsOutgoingMsg)
       
   192         {
       
   193         DetachOutgoingMsg();
       
   194         }
       
   195 
       
   196 	if (iState->ShouldUASStop())
       
   197 		{
       
   198 		Stop(KErrNone);
       
   199 		}
       
   200 
       
   201 	__TEST_INVARIANT;
       
   202 	}
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CUserAgent::DetachOutgoingMsg
       
   206 // No action.
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CUserAgent::DetachOutgoingMsg()
       
   210 	{
       
   211 	}
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CUserAgent::ReceiveL
       
   215 // Write request to log, if it came directly from ConnectionMgr.
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CUserAgent::ReceiveL(CSIPRequest* aRequest)
       
   219     {
       
   220     __TEST_INVARIANT;
       
   221 	__SIP_ASSERT_LEAVE(aRequest, KErrArgument);
       
   222 
       
   223 	if (iStopped)
       
   224 		{
       
   225 		delete aRequest;
       
   226 		}
       
   227 	else
       
   228         {
       
   229 		if (!iTransaction)
       
   230 			{
       
   231 			__SIP_MESSAGE_LOG("TransactionUser", *aRequest)
       
   232 			}
       
   233 
       
   234 		iState->ReceiveL(*this, aRequest);
       
   235 		}
       
   236 
       
   237 	__TEST_INVARIANT;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CUserAgent::ReceiveL
       
   242 // Write response to log, if it came directly from ConnectionMgr.
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CUserAgent::ReceiveL(CSIPResponse* aResponse)
       
   246     {
       
   247     __TEST_INVARIANT;
       
   248 	__SIP_ASSERT_LEAVE(aResponse, KErrArgument);
       
   249 
       
   250 	if (iStopped)
       
   251 		{
       
   252 		delete aResponse;
       
   253 		}
       
   254 	else
       
   255 		{
       
   256 		if (!iTransaction)
       
   257 			{
       
   258 			__SIP_MESSAGE_LOG("TransactionUser", *aResponse)
       
   259 			}
       
   260 
       
   261 		iState->ReceiveL(*this, aResponse);
       
   262 		}
       
   263 
       
   264 	__TEST_INVARIANT;
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CUserAgent::LeaveOccurred
       
   269 // If Dialog drops a response, it leaves with KErrSIPInvalidDialogResponse.
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CUserAgent::LeaveOccurred(TInt aReason)
       
   273 	{
       
   274 	__TEST_INVARIANT;
       
   275 	
       
   276 	__SIP_INT_LOG1( "CUser Agent :: LeaveOccured with reason", 
       
   277    			                aReason )
       
   278 
       
   279 	if (aReason != KErrSIPInvalidDialogResponse)
       
   280 		{
       
   281 		Stop(aReason);
       
   282 		}
       
   283 
       
   284 	__TEST_INVARIANT;
       
   285 	}
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CUserAgent::SendCompleteL
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CUserAgent::SendCompleteL()
       
   292 	{
       
   293 	__TEST_INVARIANT;
       
   294 
       
   295 	if (!iStopped)
       
   296 		{
       
   297 		iState->SendCompleteL(*this);
       
   298 		}
       
   299 
       
   300 	__TEST_INVARIANT;
       
   301 	}
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CUserAgent::SendFailedL
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CUserAgent::SendFailedL(TInt aError)
       
   308 	{
       
   309 	__TEST_INVARIANT;
       
   310 	__SIP_INT_LOG1( "CUserAgent Sending failed with Error",
       
   311 					aError )
       
   312 
       
   313 	if (!iStopped)
       
   314         {
       
   315         iState->SendFailedL(*this, aError);
       
   316 		}
       
   317 
       
   318 	__TEST_INVARIANT;
       
   319 	}
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CUserAgent::LeaveFromTransmitter
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CUserAgent::LeaveFromTransmitter(TInt aReason)
       
   326 	{
       
   327 	__TEST_INVARIANT;
       
   328 	__ASSERT_DEBUG(aReason != KErrNone,
       
   329 				   User::Panic(_L("UA:LeaveFromTransmitter"), KErrArgument));
       
   330 	Stop(aReason);
       
   331 
       
   332 	__TEST_INVARIANT;
       
   333 	}
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CUserAgent::TimerExpiredL
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void CUserAgent::TimerExpiredL(TTimerId aTimerId, TAny* aTimerParam)
       
   340 	{
       
   341 	__TEST_INVARIANT;
       
   342 
       
   343 	if (!iStopped)
       
   344 		{
       
   345 		iState->TimerExpiredL(*this, aTimerId, aTimerParam);
       
   346 		}
       
   347 
       
   348 	__TEST_INVARIANT;
       
   349 	}
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CUserAgent::DeleteTimer
       
   353 // The concrete UA must implement DeleteTimer.
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CUserAgent::DeleteTimer(const CUserAgentTimer& /*aTimer*/) 
       
   357 	{
       
   358 	__TEST_INVARIANT;
       
   359     __SIP_ASSERT_RETURN(EFalse, KErrGeneral);
       
   360 	}
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CUserAgent::StoreOutgoingMsg
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CUserAgent::StoreOutgoingMsg(CSIPMessage* aMsg)
       
   367 	{
       
   368 	__TEST_INVARIANT;
       
   369 	__SIP_ASSERT_RETURN(aMsg, KErrArgument);
       
   370 
       
   371 	if (iOwnsOutgoingMsg)
       
   372 		{
       
   373 		delete iOutgoingMsg;
       
   374 		}
       
   375 
       
   376 	iOutgoingMsg = aMsg;
       
   377 
       
   378 	__TEST_INVARIANT;
       
   379 	}
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CUserAgent::IsInviteUAC
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 TBool CUserAgent::IsInviteUAC() const
       
   386 	{
       
   387 	__TEST_INVARIANT;
       
   388 	return EFalse;
       
   389 	}
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CUserAgent::IsSubInviteUAC
       
   393 // Don't call __TEST_INVARIANT here to avoid recursion
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 TBool CUserAgent::IsSubInviteUAC() const
       
   397 	{
       
   398 	return EFalse;
       
   399 	}
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CUserAgent::State
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 const CUserAgentState& CUserAgent::State() const
       
   406     {
       
   407     __TEST_INVARIANT;
       
   408     return *iState;
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CUserAgent::ChangeState
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CUserAgent::ChangeState(const CUserAgentState& aNewState)
       
   416 	{
       
   417 	__TEST_INVARIANT;
       
   418 
       
   419 	iState = &aNewState;
       
   420 
       
   421 	__TEST_INVARIANT;
       
   422 	}
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CUserAgent::IsResolving
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 TBool CUserAgent::IsResolving() const
       
   429 	{
       
   430 	__TEST_INVARIANT;
       
   431 	return iState->IsResolving(); 
       
   432 	}
       
   433 	
       
   434 // -----------------------------------------------------------------------------
       
   435 // CUserAgent::UpdateTransactionOwner
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CUserAgent::UpdateTransactionOwner(MTransactionOwner* aNewObserver)
       
   439 	{
       
   440 	__TEST_INVARIANT;
       
   441 	__SIP_ASSERT_RETURN(aNewObserver, KErrArgument);
       
   442 
       
   443 	iObserver = aNewObserver;
       
   444 
       
   445 	__TEST_INVARIANT;
       
   446 	}
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CUserAgent::TransactionEndsL
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CUserAgent::TransactionEndsL(TInt aReason)
       
   453 	{
       
   454 	__TEST_INVARIANT;
       
   455 
       
   456 	iState->TransactionEndsL(*this, aReason);
       
   457 
       
   458 	__TEST_INVARIANT;
       
   459 	}
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CUserAgent::PassMsgToTransactionOwnerL
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 void CUserAgent::PassMsgToTransactionOwnerL(CSIPMessage* aMsg) const
       
   466 	{
       
   467 	__TEST_INVARIANT;
       
   468 	__SIP_ASSERT_LEAVE(aMsg, KErrArgument);
       
   469 
       
   470 	if (iObserver)
       
   471 		{
       
   472 		__SIP_INT_LOG1( "TU passes SIP message to owner, transaction ID", 
       
   473 		                 iTransactionId )
       
   474 
       
   475 		if (aMsg->IsRequest())
       
   476 			{
       
   477 			CSIPRequest* request = static_cast<CSIPRequest*>(aMsg);
       
   478 
       
   479 			__SIP_DES8_LOG( "TU SIP request method", 
       
   480 			                request->Method().DesC() )
       
   481 			iObserver->ReceiveL(iTransportParams.IapId(),
       
   482                                 iTransactionId,
       
   483 								request);
       
   484 			}
       
   485 		else
       
   486 			{
       
   487 			CSIPResponse* response = static_cast<CSIPResponse*>(aMsg);
       
   488 
       
   489 			__SIP_INT_LOG1( "TU SIP response code", 
       
   490 			                response->ResponseCode() )
       
   491 			iObserver->ReceiveL(iTransactionId, response);
       
   492 			}
       
   493 		}
       
   494 	else
       
   495         {
       
   496     	__SIP_INT_LOG1(
       
   497     	    "TU msg not passed to owner, iObserver==NULL, transaction ID",
       
   498     	    iTransactionId )
       
   499 
       
   500 		delete aMsg;
       
   501 		}
       
   502 	}
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CUserAgent::UpdateTransportProtocol
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 TBool CUserAgent::UpdateTransportProtocol(CSIPMessage& aMsg)
       
   509 	{
       
   510 	__TEST_INVARIANT;
       
   511 	return CSIPMessageUtility::TransportProtocol(aMsg, iTransportProtocol);
       
   512 	}
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CUserAgent::AddTagL
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CUserAgent::AddTagL(CSIPFromToHeaderBase& aToFromHeader) const
       
   519 	{
       
   520 	__TEST_INVARIANT;
       
   521 
       
   522 	TBuf8<MTransactionUser::KTagLength> tagBuf;
       
   523 	AddRandomStringL(tagBuf, MTransactionUser::KTagLength, EFalse);
       
   524 	
       
   525 	RStringF tag = SIPStrings::Pool().OpenFStringL(tagBuf);
       
   526 	CleanupClosePushL(tag);
       
   527 	aToFromHeader.SetParamL(SIPStrings::StringF(SipStrConsts::ETag), tag);
       
   528 	CleanupStack::PopAndDestroy(); // tag
       
   529 	}
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CUserAgent::AddRandomStringL
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 void CUserAgent::AddRandomStringL(TDes8& aBuf,
       
   536 								  TInt aLength,
       
   537 								  TBool aCaseSensitive) const
       
   538 	{
       
   539 	__TEST_INVARIANT;
       
   540 	__SIP_ASSERT_LEAVE(aLength <= aBuf.MaxLength() - aBuf.Length(),
       
   541                        KErrArgument);
       
   542 
       
   543 	iSIPMsgUtility.AddRandomStringL(aBuf,
       
   544 									aLength,
       
   545 									aCaseSensitive,
       
   546 									iOutgoingMsg,
       
   547 									iTransactionId,
       
   548 									this);
       
   549 	}
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CUserAgent::IcmpErrorL
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 void CUserAgent::IcmpErrorL(const TInetAddr& aAddress,
       
   556 							CSipConnectionMgr::TICMPError aError)
       
   557 	{
       
   558 	__TEST_INVARIANT;
       
   559 
       
   560 	if (!iStopped)
       
   561 		{
       
   562 		iState->IcmpErrorL(*this, aAddress, aError);
       
   563 		}
       
   564 
       
   565 	__TEST_INVARIANT;
       
   566 	}
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CUserAgent::CheckContactHeadersL
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CUserAgent::CheckContactHeadersL(CSIPMessage& aMsg,
       
   573                               const CSIPFromToHeaderBase* aFromToHeader) const
       
   574 	{
       
   575 	__TEST_INVARIANT;
       
   576     __SIP_ASSERT_LEAVE(aFromToHeader != NULL, KErrArgument);
       
   577 
       
   578 	const RStringF KContact = SIPStrings::StringF(SipStrConsts::EContactHeader);
       
   579 	if (aMsg.HasHeader(KContact))
       
   580 		{
       
   581 		TSglQueIter<CSIPHeaderBase> iter = aMsg.Headers(KContact);
       
   582 		for (CSIPHeaderBase* header = iter++; header; header = iter++)
       
   583 			{
       
   584 			CSIPContactHeader* contact =
       
   585 				static_cast<CSIPContactHeader*>(header);
       
   586 			if (!contact->Star())
       
   587                 {
       
   588                 __SIP_ASSERT_LEAVE(contact->SIPAddress(), KErrArgument);
       
   589 				if (contact->SIPAddress()->URI().IsSIPURI())
       
   590 					{
       
   591 					CSIPURI* sipUri = contact->SIPAddress()->URI().SIPURI();
       
   592 					if (sipUri->HostPort().Host().CompareF(
       
   593 						SIPStrings::StringF(SipStrConsts::ELocalHost).DesC())
       
   594 						== 0)
       
   595 						{
       
   596 						iRegistrationContact.ContactL(iTransportParams.IapId(),
       
   597                                     RegistrationId(),
       
   598                                     aFromToHeader,
       
   599 						            static_cast<CSIPContactHeader&>(*header));
       
   600 						}
       
   601 	                CheckSigCompL(contact->SIPAddress()->URI());
       
   602 					}
       
   603 				}
       
   604 			}
       
   605 		}
       
   606 	}
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CUserAgent::RemoveFromStore
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void CUserAgent::RemoveFromStore() const
       
   613 	{
       
   614 	__TEST_INVARIANT;
       
   615 
       
   616 	iTransactionStore.Remove(iTransactionId);
       
   617 	}
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CUserAgent::RequestDeletionOfTransactionL
       
   621 // Leave if AddDeleteRequest fails. Don't change TransactionId, to avoid using
       
   622 // RequestDeletionOfUserAgent after changing id. Changing id twice fails causing
       
   623 // "delete this" and call stack likely has UA/transaction code, causing a crash.
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CUserAgent::RequestDeletionOfTransactionL()
       
   627     {
       
   628     __TEST_INVARIANT;
       
   629 
       
   630 	if (iTransaction)
       
   631 		{
       
   632 		User::LeaveIfError(iDeleteMgr.AddDeleteRequest(iTransaction));		
       
   633 		iTransaction = NULL;
       
   634 		iTransactionStore.ClearTransaction(iTransactionId);
       
   635 		}
       
   636 
       
   637     __TEST_INVARIANT;
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // CUserAgent::RequestDeletionOfUserAgent
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 TInt CUserAgent::RequestDeletionOfUserAgent()
       
   645 	{
       
   646 	__TEST_INVARIANT;
       
   647 
       
   648     TInt status = iDeleteMgr.AddDeleteRequest(this);
       
   649 	if (status == KErrNone)
       
   650         {
       
   651         // DeleteMgr took UA's ownership
       
   652 		RemoveFromStore();
       
   653 		}
       
   654 	else
       
   655 		{
       
   656         // Other errors mean e.g. trying to delete object twice
       
   657         if (status == KErrNoMemory)
       
   658             {
       
   659 			// Set id empty, to be freed later. Fails if UA isn't stored, but it
       
   660 			// occurs only in CTransactionUser::SendL/SendAndGetHeadersL/
       
   661 			// SendCancelL so UA isn't in call stack, and can "delete this".
       
   662 			status = iTransactionStore.UpdateTransactionId(iTransactionId,
       
   663 				            						       KEmptyTransactionId);
       
   664             if (status != KErrNone)
       
   665                 {
       
   666                 delete this;
       
   667                 return KErrDied; // Skip __TEST_INVARIANT
       
   668                 }
       
   669             }
       
   670         }
       
   671 
       
   672 	__TEST_INVARIANT;
       
   673 	return status;
       
   674 	}
       
   675 
       
   676 // -----------------------------------------------------------------------------
       
   677 // CUserAgent::Stop
       
   678 // "sub InviteUAC" doesn't use observer or request its own deletion.
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 void CUserAgent::Stop(TInt aReason)
       
   682 	{
       
   683 	__TEST_INVARIANT;
       
   684 
       
   685 	if (!iStopped)
       
   686 		{
       
   687 		iStopped = ETrue;
       
   688 
       
   689 		if (!IsSubInviteUAC())
       
   690 			{
       
   691 			if (iObserver)
       
   692 				{
       
   693 				if (IsInviteUAC() && IsCanceled() && aReason == KErrTimedOut)
       
   694 					{
       
   695 					aReason = KErrCancel;
       
   696 					}
       
   697 				__SIP_INT_LOG2( "TU TransactionEnded (reason, transaction ID)",
       
   698 				                aReason, iTransactionId )
       
   699 				iObserver->TransactionEnded(iTransportParams.IapId(), 
       
   700 				                            iTransactionId,
       
   701 				                            aReason);
       
   702 				}
       
   703 			else
       
   704 				{
       
   705 				__SIP_INT_LOG1( "TU UA:Stop(), iObserver==NULL, transaction ID",
       
   706 				                iTransactionId )
       
   707 				}
       
   708 
       
   709             if (RequestDeletionOfUserAgent() == KErrDied)
       
   710                 {
       
   711                 // Skip __TEST_INVARIANT as UA was deleted synchronously
       
   712                 return;
       
   713                 }
       
   714 			}
       
   715 		}
       
   716 
       
   717     __TEST_INVARIANT;
       
   718 	}
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CUserAgent::TransactionId
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 TTransactionId CUserAgent::TransactionId() const
       
   725 	{
       
   726     __TEST_INVARIANT;
       
   727 	return iTransactionId;
       
   728 	}
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CUserAgent::Transaction
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 CTransactionBase* CUserAgent::Transaction()
       
   735 	{
       
   736     __TEST_INVARIANT;
       
   737 	return iTransaction;
       
   738 	}
       
   739 
       
   740 // -----------------------------------------------------------------------------
       
   741 // CUserAgent::CheckSigCompL
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CUserAgent::CheckSigCompL(const CURIContainer& aUri) const
       
   745     {
       
   746     __TEST_INVARIANT;
       
   747 	
       
   748 	if (CSIPMessageUtility::HasSigCompParam(aUri) && !iSigComp.IsSupported())
       
   749         {
       
   750         User::Leave(KErrNotSupported);
       
   751         }
       
   752     }
       
   753 
       
   754 // -----------------------------------------------------------------------------
       
   755 // CUserAgent::HasStopped
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 TBool CUserAgent::HasStopped() const
       
   759 	{
       
   760 	__TEST_INVARIANT;
       
   761 	return iStopped;	
       
   762 	}
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CUserAgent::IsCanceled
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 TBool CUserAgent::IsCanceled() const
       
   769 	{
       
   770 	__TEST_INVARIANT;
       
   771 	return EFalse;
       
   772 	}
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CUserAgent::__DbgTestInvariant
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 
       
   779 void CUserAgent::__DbgTestInvariant() const
       
   780 	{
       
   781 	if (!iState || !iTransmitter || (IsUAS() && !iOwnsOutgoingMsg))
       
   782 		{	
       
   783 		User::Invariant();
       
   784 		}
       
   785 	}
       
   786