realtimenetprots/sipfw/SIP/Transaction/src/NormalServerTaStates.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2006-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          : NormalServerTaStates.cpp
       
    15 // Part of       : Transaction
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "siperr.h"
       
    22 #include "SipAssert.h"
       
    23 #include "siprequest.h"
       
    24 #include "sipresponse.h"
       
    25 #include "SIPMessageUtility.h"
       
    26 
       
    27 #include "NormalServerTa.h"
       
    28 #include "NormalServerTaStates.h"
       
    29 #include "ResponseQueueItem.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CNormalServerTa_Trying::CNormalServerTa_Trying
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CNormalServerTa_Trying::CNormalServerTa_Trying()
       
    36 	{
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CNormalServerTa_Trying::~CNormalServerTa_Trying
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CNormalServerTa_Trying::~CNormalServerTa_Trying()
       
    44 	{
       
    45 	}
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CNormalServerTa_Trying::GetState
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CNormalServerTa_Trying::GetState(CSIPInternalStates::TState& aState) const
       
    52     {
       
    53     aState = CSIPInternalStates::ETransactionTrying;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CNormalServerTa_Trying::SetNeighbourStates
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CNormalServerTa_Trying::SetNeighbourStates(CTransactionState& aProceeding,
       
    61 												CTransactionState& aCompleted)
       
    62 	{
       
    63 	iProceeding = &aProceeding;
       
    64 	iCompleted = &aCompleted;
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CNormalServerTa_Trying::ReceiveL
       
    69 // Response can be sent when TimerSend100 has expired or been stopped.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CNormalServerTa_Trying::ReceiveL(CTransaction& aTransaction,
       
    73 	                                  CSIPRequest* aRequest) const
       
    74 	{
       
    75     __SIP_ASSERT_LEAVE(aRequest, KErrArgument);
       
    76 
       
    77 	CNormalServerTransaction& ta = CNormalServerTransaction::Ptr(aTransaction);
       
    78 
       
    79 	if (ta.RequestPassedToUA())
       
    80 		{
       
    81 		if (!ta.IsTimerSend100Running() && !ta.IsTransmitterSending())
       
    82 			{
       
    83 			ta.SendToTransmitterL();
       
    84 			}
       
    85 		delete aRequest;
       
    86 		}
       
    87 	else
       
    88 		{
       
    89 		__ASSERT_ALWAYS(ta.UpdateTransportProtocol(*aRequest),
       
    90 					    User::Leave(KErrSIPMalformedMessage));		
       
    91 		ta.StartTimerF2UnlessExistsL();		
       
    92 		if (!ta.IsTimerSend100Running())
       
    93 			{	
       
    94 			ta.StartTimerSend100L(*aRequest);
       
    95 			}
       
    96 		ta.PassRequestToUserAgentL(aRequest);
       
    97 		}
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CNormalServerTa_Trying::SendResponseL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CNormalServerTa_Trying::SendResponseL(CTransaction& aTransaction,
       
   105 								   CSIPResponse* aResp,
       
   106 								   RStringF aProtocol,
       
   107 								   const TSIPTransportParams& aParams) const
       
   108 	{
       
   109 	__SIP_ASSERT_LEAVE(aResp, KErrArgument);
       
   110     __SIP_ASSERT_LEAVE(CSIPMessageUtility::CheckTransport(aProtocol),
       
   111                        KErrArgument);
       
   112 
       
   113 	TBool isFinalResp = CSIPMessageUtility::IsFinalResponse(*aResp);
       
   114 	CNormalServerTransaction& ta = CNormalServerTransaction::Ptr(aTransaction);
       
   115 	CResponseQueueItem* respItem =
       
   116 		CResponseQueueItem::NewLC(aResp, aParams, EFalse);
       
   117 
       
   118 	ta.SendAndStoreResponseL(respItem, aProtocol);
       
   119 	CleanupStack::Pop(respItem);
       
   120 
       
   121 	ta.StopTimerSend100();
       
   122 	if (isFinalResp)
       
   123 		{
       
   124 		ta.StopTimerF2();
       
   125 		aTransaction.ChangeState(*iCompleted);
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		aTransaction.ChangeState(*iProceeding);
       
   130 		}
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CNormalServerTa_Trying::TimerExpiredL
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CNormalServerTa_Trying::TimerExpiredL(CTransaction& aTransaction,
       
   138 										   TTimerId aTimerId,
       
   139 										   TAny* aTimerParam) const
       
   140 	{
       
   141 	__SIP_ASSERT_LEAVE(aTimerParam, KErrArgument);
       
   142 
       
   143 	HandleTimerExpirationL(aTransaction, aTimerId, aTimerParam);
       
   144 	}
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CNormalServerTa_Proceeding::CNormalServerTa_Proceeding
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 CNormalServerTa_Proceeding::CNormalServerTa_Proceeding()
       
   151 	{
       
   152 	}
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CNormalServerTa_Proceeding::~CNormalServerTa_Proceeding
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 CNormalServerTa_Proceeding::~CNormalServerTa_Proceeding()
       
   159 	{
       
   160 	}
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CNormalServerTa_Proceeding::GetState
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void
       
   167 CNormalServerTa_Proceeding::GetState(CSIPInternalStates::TState& aState) const
       
   168     {
       
   169     aState = CSIPInternalStates::ETransactionProceeding;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CNormalServerTa_Proceeding::SetNeighbourStates
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void
       
   177 CNormalServerTa_Proceeding::SetNeighbourStates(CTransactionState& aCompleted)
       
   178 	{
       
   179 	iCompleted = &aCompleted;
       
   180 	}
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CNormalServerTa_Proceeding::SendCompleteL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CNormalServerTa_Proceeding::SendCompleteL(CTransaction& aTransaction) const
       
   187 	{
       
   188 	CNormalServerTransaction& ta = CNormalServerTransaction::Ptr(aTransaction);
       
   189 	CResponseQueueItem* respItem = ta.GetResponseFromSendQueue();
       
   190 
       
   191 	if (respItem)
       
   192 		{
       
   193 		TBool isFinalResp =
       
   194 			CSIPMessageUtility::IsFinalResponse(respItem->Response());
       
   195 
       
   196 		CleanupStack::PushL(respItem);
       
   197 		ta.SendAndStoreResponseL(respItem);
       
   198 		CleanupStack::Pop(respItem);
       
   199 
       
   200         if (isFinalResp)
       
   201 			{
       
   202 			ta.StopTimerF2();
       
   203 			aTransaction.ChangeState(*iCompleted);
       
   204 			}
       
   205 		}
       
   206 	}
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CNormalServerTa_Proceeding::SendFailedL
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CNormalServerTa_Proceeding::SendFailedL(CTransaction& aTransaction,
       
   213 											 TInt aError) const
       
   214 	{
       
   215 	aTransaction.TerminatedL(aError);
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CNormalServerTa_Proceeding::ReceiveL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CNormalServerTa_Proceeding::ReceiveL(CTransaction& aTransaction,
       
   223 	                                      CSIPRequest* aRequest) const
       
   224 	{
       
   225 	CNormalServerTransaction::Ptr(aTransaction).ReceiveRetransmissionL(aRequest);
       
   226 	}
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CNormalServerTa_Proceeding::SendResponseL
       
   230 // If sending a previous response, queue the new response.
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CNormalServerTa_Proceeding::SendResponseL(CTransaction& aTransaction,
       
   234 								   CSIPResponse* aResp,
       
   235 								   RStringF aProtocol,
       
   236 								   const TSIPTransportParams& aParams) const
       
   237 	{
       
   238 	__SIP_ASSERT_LEAVE(aResp, KErrArgument);
       
   239     __SIP_ASSERT_LEAVE(CSIPMessageUtility::CheckTransport(aProtocol),
       
   240                        KErrArgument);
       
   241 
       
   242 	CNormalServerTransaction& ta = CNormalServerTransaction::Ptr(aTransaction);
       
   243 	CResponseQueueItem* respItem =
       
   244 		CResponseQueueItem::NewLC(aResp, aParams, EFalse);
       
   245 	if (ta.IsTransmitterSending())
       
   246 		{
       
   247 		ta.AddResponseToSendQueueL(respItem);
       
   248 		}
       
   249 	else
       
   250 		{		
       
   251 		TBool isFinalResp =
       
   252 			CSIPMessageUtility::IsFinalResponse(respItem->Response());
       
   253 
       
   254 		ta.SendAndStoreResponseL(respItem, aProtocol);
       
   255 
       
   256         if (isFinalResp)
       
   257 			{
       
   258 			ta.StopTimerF2();
       
   259 			aTransaction.ChangeState(*iCompleted);
       
   260 			}
       
   261 		}
       
   262 	CleanupStack::Pop(respItem);
       
   263 	}
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CNormalServerTa_Proceeding::TimerExpiredL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CNormalServerTa_Proceeding::TimerExpiredL(CTransaction& aTransaction,
       
   270 											   TTimerId aTimerId,
       
   271 											   TAny* aTimerParam) const
       
   272 	{
       
   273 	__SIP_ASSERT_LEAVE(aTimerParam, KErrArgument);
       
   274 
       
   275 	HandleTimerExpirationL(aTransaction, aTimerId, aTimerParam);
       
   276 	}
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CNormalServerTa_Completed::CNormalServerTa_Completed
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 CNormalServerTa_Completed::CNormalServerTa_Completed()
       
   283 	{
       
   284 	}
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CNormalServerTa_Completed::~CNormalServerTa_Completed
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 CNormalServerTa_Completed::~CNormalServerTa_Completed()
       
   291 	{
       
   292 	}
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CNormalServerTa_Completed::GetState
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void
       
   299 CNormalServerTa_Completed::GetState(CSIPInternalStates::TState& aState) const
       
   300     {
       
   301     aState = CSIPInternalStates::ETransactionCompleted;
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CNormalServerTa_Completed::SendCompleteL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CNormalServerTa_Completed::SendCompleteL(CTransaction& aTransaction) const
       
   309 	{
       
   310 	CNormalServerTransaction::Ptr(aTransaction).StartTimerJUnlessExistsL();
       
   311 	}
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CNormalServerTa_Completed::SendFailedL
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CNormalServerTa_Completed::SendFailedL(CTransaction& aTransaction,
       
   318 											TInt aError) const
       
   319 	{
       
   320 	aTransaction.TerminatedL(aError);
       
   321 	}
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CNormalServerTa_Completed::ReceiveL
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CNormalServerTa_Completed::ReceiveL(CTransaction& aTransaction,
       
   328 	                                     CSIPRequest* aRequest) const
       
   329 	{
       
   330 	CNormalServerTransaction::Ptr(aTransaction).ReceiveRetransmissionL(aRequest);    
       
   331 	}
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CNormalServerTa_Completed::TimerExpiredL
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 void CNormalServerTa_Completed::TimerExpiredL(CTransaction& aTransaction,
       
   338 											  TTimerId aTimerId,
       
   339 											  TAny* aTimerParam) const
       
   340 	{	
       
   341 	__SIP_ASSERT_LEAVE(aTimerParam, KErrArgument);
       
   342 
       
   343 	HandleTimerExpirationL(aTransaction, aTimerId, aTimerParam);
       
   344 	}