realtimenetprots/sipfw/SIP/TransactionUser/src/InviteUAS.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          : InviteUAS.cpp
       
    15 // Part of       : TransactionUser
       
    16 // Version       : SIP/6.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "siperr.h"
       
    22 #include "sipinternalerr.h"
       
    23 #include "SipAssert.h"
       
    24 #include "sipresponse.h"
       
    25 #include "sipstrings.h"
       
    26 #include "sipstrconsts.h"
       
    27 #include "MSipDialogs.h"
       
    28 #include "TransactionMgr.h"
       
    29 #include "Transmitter.h"
       
    30 
       
    31 #include "MTransactionOwner.h"
       
    32 #include "InviteUAS.h"
       
    33 #include "InviteServerTa.h"     // Leave2xxForUAS
       
    34 #include "SIPMessageUtility.h"
       
    35 #include "CTransactionStore.h"
       
    36 #include "UserAgentState.h"
       
    37 #include "UserAgentTimer.h"
       
    38 #include "TimerValues.h"
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CInviteUAS::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CInviteUAS* CInviteUAS::NewL(CUserAgentCreateParams& aParams,							
       
    46 							 MSipConnectionMgr& aConnectionMgr,
       
    47 							 MSIPRequestRouter& aRouter,
       
    48                              MSipDialogs& aDialogs)
       
    49 	{
       
    50 	CInviteUAS* self = new (ELeave) CInviteUAS(aParams, aDialogs, aRouter);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aConnectionMgr);
       
    53 	CleanupStack::Pop(self);
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CInviteUAS::CInviteUAS
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CInviteUAS::CInviteUAS(CUserAgentCreateParams& aParams,					   
       
    62                        MSipDialogs& aDialogs,
       
    63                        MSIPRequestRouter& aRouter) :
       
    64 	CUserAgentServer(aParams, aDialogs, aRouter)
       
    65 	{
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CInviteUAS::ConstructL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CInviteUAS::ConstructL(MSipConnectionMgr& aConnectionMgr)
       
    73 	{
       
    74 	CUserAgent::ConstructL(aConnectionMgr);
       
    75 	CreateTransactionL();
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CInviteUAS::~CInviteUAS
       
    80 // Transaction must clear pointers to the 2xx, as UAS will delete the 2xx.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CInviteUAS::~CInviteUAS()
       
    84 	{
       
    85 	CancelAllTimers();
       
    86 
       
    87     if (IsSending2xx() && iTransaction && !iTransaction->HasTerminated())
       
    88         {
       
    89 		CInviteServerTransaction::Ptr(*iTransaction).Leave2xxForUAS();	
       
    90 		}
       
    91 	}
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CInviteUAS::CreateTransactionL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CInviteUAS::CreateTransactionL()
       
    98 	{
       
    99 	__TEST_INVARIANT;
       
   100 	__SIP_ASSERT_LEAVE(!iTransaction && iTransmitter, KErrAlreadyExists);
       
   101 
       
   102 	iTransaction = iTransactionMgr.CreateTransactionL(
       
   103 									CTransactionBase::KServerInviteTransaction,
       
   104 									*this,
       
   105 									*iTransmitter,
       
   106 									iTimerValues);
       
   107 	__TEST_INVARIANT;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CInviteUAS::DoesDialogExistForAckL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TBool CInviteUAS::DoesDialogExistForAckL(CSIPRequest& aAck)
       
   115 	{
       
   116 	__TEST_INVARIANT;
       
   117 
       
   118 	CSIPResponse* resp(NULL);
       
   119     MTransactionOwner* taOwner = iDialogs.TransactionOwnerL(aAck, &resp);
       
   120 	if (taOwner)
       
   121 		{
       
   122         iObserver = taOwner;
       
   123 		return ETrue;
       
   124 		}
       
   125 
       
   126     // Nothing is sent after ACK
       
   127 	delete resp;
       
   128 
       
   129     __TEST_INVARIANT;
       
   130 	return EFalse;
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CInviteUAS::SendFirst2xxL
       
   135 // Clear transaction from CTransactionStore, so further INVITEs/ACKs are passed
       
   136 // to UAS, and not to transaction. INVITE UAS owns the 2xx.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CInviteUAS::SendFirst2xxL(CSIPResponse* aResp)
       
   140 	{
       
   141 	__TEST_INVARIANT;
       
   142 	__SIP_ASSERT_LEAVE(aResp, KErrArgument);
       
   143 	__SIP_ASSERT_LEAVE(aResp->Type() == CSIPResponse::E2XX, KErrArgument);
       
   144 
       
   145 	iTransactionStore.ClearTransaction(TransactionId());
       
   146 	StartTimerWaitAckL();
       
   147 	SendResponseToTransactionL(aResp);
       
   148 	iOutgoingMsg = aResp;
       
   149 
       
   150 	__TEST_INVARIANT;
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CInviteUAS::Retransmit2xxL
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CInviteUAS::Retransmit2xxL()
       
   158 	{
       
   159 	__TEST_INVARIANT;
       
   160 	__SIP_ASSERT_LEAVE(iOutgoingMsg && iTransmitter, KErrGeneral);
       
   161     __SIP_ASSERT_LEAVE(
       
   162         static_cast<CSIPResponse*>(iOutgoingMsg)->Type() == CSIPResponse::E2XX,
       
   163         KErrSIPMalformedMessage);
       
   164 
       
   165 	iTransmitter->SendResponseL(static_cast<CSIPResponse&>(*iOutgoingMsg),
       
   166 								TransportParams(),
       
   167 							    this,
       
   168 								TransactionId());
       
   169 	__TEST_INVARIANT;
       
   170 	}
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CInviteUAS::CancelInviteL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CInviteUAS::CancelInviteL()
       
   177 	{
       
   178 	__TEST_INVARIANT;
       
   179 
       
   180 	if (!iCanceled)
       
   181 		{
       
   182 		iCanceled = State().CancelL(*this);
       
   183 		}
       
   184 
       
   185 	__TEST_INVARIANT;
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CInviteUAS::HandleCancelInviteL
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CInviteUAS::HandleCancelInviteL(const CUserAgentState& aRejected)
       
   193 	{
       
   194 	__TEST_INVARIANT;
       
   195 
       
   196 	if (iTransaction)
       
   197 		{
       
   198 		SendErrorResponseL(487,
       
   199 	    	SIPStrings::StringF(SipStrConsts::EPhraseRequestTerminated),
       
   200 	    	aRejected);
       
   201 		}
       
   202 
       
   203 	if (!InformObserverAboutCancel())
       
   204 		{
       
   205 		// Waiting to get MTransactionOwner. End silently.
       
   206 		CancelGetOwnerRequest();
       
   207         StopTimerOwnerResolver();
       
   208 		}
       
   209 
       
   210 	__TEST_INVARIANT;
       
   211 	}
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CInviteUAS::InformObserverAboutCancel
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 TBool CInviteUAS::InformObserverAboutCancel()
       
   218 	{
       
   219 	if (iObserver)
       
   220 		{
       
   221 		// INVITE was passed to iObserver, run transaction silently to end
       
   222 		iObserver->TransactionEnded(iTransportParams.IapId(),
       
   223 		                            TransactionId(),
       
   224 									KInviteTransactionCancelled);
       
   225 		iObserver = NULL;
       
   226 		return ETrue;
       
   227 		}
       
   228 	return EFalse;
       
   229 	}
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CInviteUAS::IsSending2xx
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TBool CInviteUAS::IsSending2xx() const
       
   236     {
       
   237     __TEST_INVARIANT;
       
   238     return iOutgoingMsg && CSIPMessageUtility::Is2xxResponse(*iOutgoingMsg);
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CInviteUAS::StartTimerRetransmit2xxL
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CInviteUAS::StartTimerRetransmit2xxL()
       
   246 	{
       
   247 	__TEST_INVARIANT;
       
   248 	__SIP_ASSERT_LEAVE(!iTimerRetransmit2xx, KErrAlreadyExists);
       
   249 
       
   250 	iTimerValues.DoubleUptoT2(iTimerRetransmit2xxDuration);
       
   251 	iTimerRetransmit2xx =
       
   252         CTimerRetransmit2xx::NewL(iTimers,
       
   253 								  this,				
       
   254 								  iTimerRetransmit2xxDuration);
       
   255 	__TEST_INVARIANT;
       
   256 	}
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CInviteUAS::StopTimerRetransmit2xx
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CInviteUAS::StopTimerRetransmit2xx()
       
   263 	{
       
   264 	__TEST_INVARIANT;
       
   265 
       
   266 	delete iTimerRetransmit2xx;
       
   267 	iTimerRetransmit2xx = NULL;
       
   268 
       
   269 	__TEST_INVARIANT;
       
   270 	}
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CInviteUAS::StartTimerWaitAckL
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CInviteUAS::StartTimerWaitAckL()
       
   277 	{
       
   278 	__TEST_INVARIANT;
       
   279 	__SIP_ASSERT_LEAVE(!iTimerWaitAck, KErrAlreadyExists);
       
   280 	
       
   281 	iTimerWaitAck = CTimerStopUA::NewL(iTimers,
       
   282 									   this,
       
   283 									   iTimerValues.Duration64xT1(),
       
   284                                        KErrSIPNoAckReceived);
       
   285 	__TEST_INVARIANT;
       
   286 	}
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CInviteUAS::StopTimerWaitAck
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CInviteUAS::StopTimerWaitAck()
       
   293 	{
       
   294 	__TEST_INVARIANT;
       
   295 
       
   296 	delete iTimerWaitAck;
       
   297 	iTimerWaitAck = NULL;
       
   298 
       
   299 	__TEST_INVARIANT;
       
   300 	}
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CInviteUAS::DeleteTimer
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CInviteUAS::DeleteTimer(const CUserAgentTimer& aTimer)
       
   307 	{
       
   308 	__TEST_INVARIANT;
       
   309 
       
   310 	if (&aTimer == iTimerRetransmit2xx)
       
   311 		{
       
   312 		StopTimerRetransmit2xx();		
       
   313 		}
       
   314 
       
   315 	if (&aTimer == iTimerWaitAck)
       
   316 		{
       
   317 		StopTimerWaitAck();		
       
   318 		}
       
   319 
       
   320     if (&aTimer == iTimerOwnerResolver)
       
   321         {
       
   322         StopTimerOwnerResolver();
       
   323         }
       
   324 
       
   325 	__TEST_INVARIANT;
       
   326 	}
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CInviteUAS::CancelAllTimers
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CInviteUAS::CancelAllTimers()
       
   333 	{
       
   334 	__TEST_INVARIANT;
       
   335 
       
   336 	StopTimerRetransmit2xx();
       
   337 	StopTimerWaitAck();
       
   338     StopTimerOwnerResolver();
       
   339 
       
   340 	__TEST_INVARIANT;
       
   341 	}
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CInviteUAS::Ptr
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 CInviteUAS& CInviteUAS::Ptr(CUserAgent& aUserAgent)
       
   348 	{
       
   349 	return static_cast<CInviteUAS&>(aUserAgent);
       
   350 	}
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CInviteUAS::__DbgTestInvariant
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 
       
   357 void CInviteUAS::__DbgTestInvariant() const
       
   358 	{
       
   359 	if (iTimerRetransmit2xxDuration > iTimerValues.T2())
       
   360 		{	
       
   361 		User::Invariant();
       
   362 		}
       
   363 	}
       
   364