realtimenetprots/sipfw/SIP/Registration/src/CSIPRegistrationRefreshBinding.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          : CSIPRegistrationRefreshBinding.cpp
       
    15 // Part of       : Registration
       
    16 // Version       : SIP/5.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "CSIPRegistrationRefreshBinding.h"
       
    23 #include "CSIPRegistrar.h"
       
    24 #include "CSIPRegistrationBindingStore.h"
       
    25 #include "CSIPResponseUtility.h"
       
    26 #include "MRegistrationOwner.h"
       
    27 #include "csipregistered.h"
       
    28 #include "csipregistering.h"
       
    29 #include "sipresponse.h"
       
    30 #include "uricontainer.h"
       
    31 #include "MSipRefreshMgr.h"
       
    32 #include "SipLogs.h" 
       
    33 #include "SipAssert.h"
       
    34 #include "sipcontactheader.h"
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CSIPRegistrationRefreshBinding::NewLC
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSIPRegistrationRefreshBinding* CSIPRegistrationRefreshBinding::NewLC(
       
    42 	CSIPRequest*                  aSIPRequest,
       
    43 	MTransactionUser&             aTransactionUser,
       
    44 	MSigComp&                     aSigComp,
       
    45 	CSIPSec&                      aSIPSec,
       
    46 	MSipRefreshMgr&               aRefreshMgr,
       
    47 	CSIPRegistrationBindingStore& aBindingStore,
       
    48 	MRegistrationOwner*           aRegistrationOwner,
       
    49 	MSIPSecUser&                  aSIPSecUser,
       
    50 	MSIPTransportMgr&             aTransportMgr,
       
    51 	CURIContainer&                aRemoteTarget,
       
    52 	TBool 						  aSendWithExpires,
       
    53 	TBool						  aCacheOutboundProxyIP)
       
    54 	{
       
    55     CSIPRegistrationRefreshBinding* self =
       
    56 		new (ELeave) CSIPRegistrationRefreshBinding(aTransactionUser,
       
    57 		                                            aSigComp,
       
    58 		                                            aSIPSec,
       
    59 		                                            aBindingStore, 
       
    60 											        aRegistrationOwner,
       
    61 											        aSIPSecUser,
       
    62 											        aTransportMgr,
       
    63 													aRefreshMgr,
       
    64 													aSendWithExpires,
       
    65 													aCacheOutboundProxyIP);
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL(aSIPRequest, aRemoteTarget);
       
    68 	return self;
       
    69 	}
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CSIPRegistrationRefreshBinding::CSIPRegistrationRefreshBinding
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CSIPRegistrationRefreshBinding::CSIPRegistrationRefreshBinding(
       
    76     MTransactionUser&             aTransactionUser,
       
    77 	MSigComp&                     aSigComp,
       
    78 	CSIPSec&                      aSIPSec,
       
    79 	CSIPRegistrationBindingStore& aBindingStore,
       
    80 	MRegistrationOwner*           aRegistrationOwner,
       
    81 	MSIPSecUser&                  aSIPSecUser,
       
    82 	MSIPTransportMgr&             aTransportMgr,
       
    83 	MSipRefreshMgr&               aRefreshMgr,
       
    84 	TBool						  aSendWithExpires,
       
    85 	TBool						  aCacheOutboundProxyIP) 
       
    86 	: CSIPRegistrationBindingBase (aTransactionUser, aSigComp, aSIPSec, 
       
    87 	                               aBindingStore, aRegistrationOwner, 
       
    88 	                               aSIPSecUser, aTransportMgr,aSendWithExpires,
       
    89 	                               aCacheOutboundProxyIP),
       
    90     iRefreshMgr(aRefreshMgr),
       
    91     iIsSubsequentResponse(EFalse)
       
    92 	{
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSIPRegistrationRefreshBinding::~CSIPRegistrationRefreshBinding
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CSIPRegistrationRefreshBinding::~CSIPRegistrationRefreshBinding()
       
   100 	{
       
   101 	iRefreshMgr.RemoveRefreshesFor (this);
       
   102 	}
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSIPRegistrationRefreshBinding::RequestCredentialsL
       
   106 // From MSIPSecUser
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CSIPRegistrationRefreshBinding::RequestCredentialsL(
       
   110     CSIPResponse& aResponse,
       
   111     TTransactionId aTransactionId,
       
   112     TRefreshId /*aRefreshId*/)
       
   113     {
       
   114     iSIPSecUser.RequestCredentialsL(aResponse,aTransactionId,iRefreshId);
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSIPRegistrationRefreshBinding::RefreshId
       
   119 // -----------------------------------------------------------------------------
       
   120 //	
       
   121 TRefreshId CSIPRegistrationRefreshBinding::RefreshId() const
       
   122     {
       
   123     return iRefreshId;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CSIPRegistrationRefreshBinding::IsRefresh
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TBool CSIPRegistrationRefreshBinding::IsRefresh() const
       
   131 	{
       
   132 	return ETrue;
       
   133 	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSIPRegistrationRefreshBinding::RefreshReceivedL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CSIPRegistrationRefreshBinding::RefreshReceivedL (
       
   140 	TTransactionId aTransactionId, 
       
   141 	TRefreshId     aRefreshId,
       
   142 	CSIPResponse*  aSIPResponse)
       
   143 	{
       
   144 	__SIP_ASSERT_LEAVE(aSIPResponse, KErrArgument);
       
   145 	__SIP_ASSERT_LEAVE(aTransactionId != KEmptyTransactionId, KErrArgument);  
       
   146 	__SIP_ASSERT_LEAVE(aRefreshId != KEmptyRefreshId, KErrArgument);  
       
   147 	__SIP_ASSERT_LEAVE(aSIPResponse->To(), KErrArgument);
       
   148 	
       
   149     __SIP_MESSAGE_LOG("Registration::RefreshReceivedL", *aSIPResponse)
       
   150 
       
   151 	if (iCurrentState == iRegistered)
       
   152 		{
       
   153 		// update the transaction id for subsequent received response.
       
   154 		iTransactionId = aTransactionId;
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		// when unregister, updating or subsequent response received, 
       
   159 		// transaction id must be same.
       
   160 		__SIP_ASSERT_LEAVE(aTransactionId == iTransactionId || 
       
   161 						   aTransactionId == iRetryTransactionId, KErrArgument);
       
   162 		}
       
   163 
       
   164 	__TEST_INVARIANT;
       
   165 
       
   166 	iCurrentState->ReceiveL(iTransactionId, aSIPResponse); 
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CSIPRegistrationRefreshBinding::RefreshError
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TInt CSIPRegistrationRefreshBinding::RefreshError (
       
   174 	TRefreshId     /*aRefreshId*/,
       
   175 	TTransactionId aTransactionId,
       
   176 	TInt           aReason)
       
   177 	{
       
   178 	__TEST_INVARIANT;
       
   179  
       
   180 	if (iCurrentState == iRegistered)
       
   181 		{
       
   182 		// update the transaction id for subsequent received response.
       
   183 		iTransactionId = aTransactionId;
       
   184 		}
       
   185 	else
       
   186 		{
       
   187 		// when unregister, updating or subsequent response received, 
       
   188 		// transaction id must be same.
       
   189 		__SIP_ASSERT_RETURN_VALUE(aTransactionId==iTransactionId,KErrArgument);
       
   190 		}
       
   191 
       
   192 	TInt res = KErrNone;
       
   193 	if (aReason != KErrNone)
       
   194 		{
       
   195 	    res = RemoveBinding ();
       
   196 		}
       
   197 	if(res != KErrNone)
       
   198 		{
       
   199 		return res;
       
   200 		}
       
   201 
       
   202 	return iCurrentState->TransactionEnded(aTransactionId, aReason);
       
   203 	}
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CSIPRegistrationRefreshBinding::NextRefreshCSeq
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CSIPRegistrationRefreshBinding::NextRefreshCSeq (TUint& aCSeq)
       
   210 	{
       
   211 	if (iRegistrar)
       
   212 		{
       
   213 		iRegistrar->IncreaseCSeqNumber();
       
   214 		aCSeq = iRegistrar->CSeqNumber();
       
   215 		}
       
   216 	else
       
   217 		{
       
   218 		aCSeq++;
       
   219 		}
       
   220 
       
   221 	return KErrNone;
       
   222 	}
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CSIPRegistrationRefreshBinding::TransportParams
       
   226 // From MRefreshOwner
       
   227 // -----------------------------------------------------------------------------
       
   228 //	
       
   229 TSIPTransportParams CSIPRegistrationRefreshBinding::TransportParams(
       
   230     const TRegistrationId& /*aRegistrationId*/)
       
   231     {
       
   232     return FillTransportParams();  
       
   233     }
       
   234     
       
   235 // -----------------------------------------------------------------------------
       
   236 // CSIPRegistrationRefreshBinding::SIPSecUser
       
   237 // From MRefreshOwner
       
   238 // -----------------------------------------------------------------------------
       
   239 //	
       
   240 const MSIPSecUser* CSIPRegistrationRefreshBinding::SIPSecUser(
       
   241     const TRegistrationId& /*aRegistrationId*/)
       
   242     {
       
   243     // Don't return a this-pointer. 
       
   244     // It could cause cyclic dependecies elsewhere in the code.
       
   245     return NULL; 
       
   246     }    
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSIPRegistrationRefreshBinding::RefreshDurationL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TUint CSIPRegistrationRefreshBinding::RefreshDurationL()
       
   253 	{
       
   254 	return Contact().ExpiresParameter();
       
   255 	}
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CSIPRegistrationRefreshBinding::DoRegisterL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CSIPRegistrationRefreshBinding::DoRegisterL(
       
   262 	TTransactionId&  aTransactionId, 
       
   263 	CSIPRequest*     aRequest,
       
   264 	CSIPRouteHeader* aOutboundProxy)
       
   265 	{
       
   266 	if (aOutboundProxy)
       
   267 		{
       
   268 		SetOutboundProxyL(aOutboundProxy); 
       
   269 		// If SendL fails the aOutboundProxy is detached from binding
       
   270 		CleanupStack::PushL(TCleanupItem(DetachOutboundProxy, this));
       
   271 		}
       
   272 			
       
   273 	if (iRegistrar)
       
   274 		{
       
   275 		// send refresh registration request, 
       
   276 		// the ownership of request is not passed
       
   277 		iRefreshMgr.RefreshL(aTransactionId,iRefreshId,iRegistrationId,
       
   278 		                     aRequest,this,*this, 
       
   279 		                     const_cast<CURIContainer&>(iRegistrar->Registrar()),
       
   280 		                     EFalse,ETrue);
       
   281 		}
       
   282 	else
       
   283 		{
       
   284 		// the ownership of the request is not passed.
       
   285 		iRefreshMgr.RefreshL(aTransactionId,iRefreshId,iRegistrationId,aRequest, 
       
   286 		                     this,*this,*iRemoteTarget,EFalse,ETrue);
       
   287 		}
       
   288 
       
   289 	if (aOutboundProxy)
       
   290 		{
       
   291 		CleanupStack::Pop(); // TCleanupItem
       
   292 		}
       
   293 	
       
   294 	
       
   295 	if ( iCurrentState->Retrying() )
       
   296 		{
       
   297 		iRetryTransactionId = aTransactionId;
       
   298 		}
       
   299 		
       
   300 	else 
       
   301 		{
       
   302 		iTransactionId = aTransactionId;
       
   303 		}
       
   304 		
       
   305 	
       
   306 	}
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSIPRegistrationRefreshBinding::DoUpdateL
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CSIPRegistrationRefreshBinding::DoUpdateL(
       
   313 	TTransactionId& aTransactionId, CSIPRequest* aRequest)
       
   314 	{
       
   315 	// send update refresh registration request, 
       
   316 	// the ownership of request is not passed.
       
   317 	iRefreshMgr.UpdateRefreshL(iTransactionId, iRefreshId, aRequest, 
       
   318 	                           this, EFalse);
       
   319 
       
   320 	aTransactionId = iTransactionId;
       
   321 	}
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CSIPRegistrationRefreshBinding::DoUnregisterL
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CSIPRegistrationRefreshBinding::DoUnregisterL(
       
   328 	TTransactionId& aTransactionId, CSIPRequest* aRequest)
       
   329 	{
       
   330 	// the ownership of the request is not passed
       
   331 	iRefreshMgr.TerminateRefreshL(iTransactionId, iRefreshId, aRequest, 
       
   332 	                              this, EFalse);
       
   333 
       
   334 	aTransactionId = iTransactionId;
       
   335 	}
       
   336 	
       
   337 // -----------------------------------------------------------------------------
       
   338 // CSIPRegistrationRefreshBinding::SetOutboundProxyL
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CSIPRegistrationRefreshBinding::SetOutboundProxyL(
       
   342 	CSIPRouteHeader* aOutboundProxy)
       
   343 	{
       
   344 	__SIP_ASSERT_LEAVE (aOutboundProxy, KErrArgument);
       
   345 
       
   346     if (iRouteSet.Count() > 0)
       
   347         {
       
   348         iRefreshMgr.UpdateRouteSetsL(this,iRouteSet);
       
   349         }
       
   350     else
       
   351         {
       
   352         iRefreshMgr.RemoveRouteSets(this);    
       
   353         }
       
   354     CreateProxyTransportResourcesL(*aOutboundProxy);
       
   355     SetOutboundProxy(aOutboundProxy);
       
   356 	}
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CSIPRegistrationRefreshBinding::ClearRefreshOwner
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CSIPRegistrationRefreshBinding::ClearRefreshOwner ()
       
   363 	{
       
   364 	iRefreshMgr.TerminateRefresh(iRefreshId,this);
       
   365 	}
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CSIPRegistrationRefreshBinding::SetRefreshId
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CSIPRegistrationRefreshBinding::SetRefreshId(TRefreshId aRefreshId)
       
   372 	{
       
   373 	iRefreshId = aRefreshId;
       
   374 	}
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CSIPRegistrationRefreshBinding::__DbgTestInvariant
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 
       
   381 void CSIPRegistrationRefreshBinding::__DbgTestInvariant() const
       
   382 	{
       
   383 	if (!iOwner)
       
   384 		{	
       
   385 		User::Invariant();
       
   386 		}
       
   387 	}
       
   388