realtimenetprots/sipfw/SIP/Refreshes/src/CSipRegisterRefresh.cpp
changeset 0 307788aac0a8
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          : CSipRegisterRefresh.cpp
       
    15 // Part of       : SIPRefreshes
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "SipStackServerDefs.h"
       
    22 #include "MTransactionUser.h"
       
    23 #include "MRefreshOwner.h"
       
    24 #include "CSipRefreshMgr.h"
       
    25 #include "siprequest.h"
       
    26 #include "sipresponse.h"
       
    27 #include "sipcontactheader.h"
       
    28 #include "sipaddress.h"
       
    29 #include "sipcseqheader.h"
       
    30 #include "siptoheader.h"
       
    31 #include "sipfromheader.h"
       
    32 #include "SipLogs.h"
       
    33 #include "sipcallidheader.h"
       
    34 #include "sipuri.h"
       
    35 #include "siprouteheader.h"
       
    36 #include "siprecordrouteheader.h"
       
    37 #include "SipAssert.h"
       
    38 #include "CSipRegisterRefresh.h"
       
    39 #include "sipstrings.h"
       
    40 #include "sipstrconsts.h"
       
    41 #include "CSIPResponseUtility.h"
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSipRegisterRefresh::NewLC
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CSipRegisterRefresh* CSipRegisterRefresh::NewLC(
       
    49 	MTransactionUser& aTU,
       
    50     MTimerManager& aTimerMgr,
       
    51     CSIPSec& aSIPSec,
       
    52 	CSipRefreshMgr& aRefreshMgr,
       
    53 	TRegistrationId aRegistrationId,
       
    54 	CSIPRequest* aRequest,
       
    55     MRefreshOwner* aOwner,
       
    56     MSIPSecUser& aSIPSecUser,
       
    57 	CURIContainer& aRemoteTarget)
       
    58 	{
       
    59 	__SIP_ASSERT_LEAVE (aOwner, KErrArgument);
       
    60 
       
    61 	CSipRegisterRefresh* self = 
       
    62 	    new(ELeave)CSipRegisterRefresh(aTU, aTimerMgr, aSIPSec, aRefreshMgr,
       
    63 	                                   aRegistrationId, aOwner, aSIPSecUser);
       
    64 
       
    65 	CleanupStack::PushL (self);
       
    66 	self->ConstructL(aRequest, aRemoteTarget);
       
    67 	return self;
       
    68 	}
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSipRegisterRefresh::~CSipRegisterRefresh
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CSipRegisterRefresh::~CSipRegisterRefresh ()
       
    75 	{
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSipRegisterRefresh::CSipRegisterRefresh
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CSipRegisterRefresh::CSipRegisterRefresh (MTransactionUser& aTU,
       
    83                                           MTimerManager& aTimerMgr,
       
    84                                           CSIPSec& aSIPSec,
       
    85                                           CSipRefreshMgr& aRefreshMgr,
       
    86                                           TRegistrationId aRegistrationId,
       
    87                                           MRefreshOwner* aOwner,
       
    88                                           MSIPSecUser& aSIPSecUser)
       
    89  : CSipRefreshBase (aTU, aTimerMgr, aSIPSec, aRefreshMgr, 
       
    90                     aRegistrationId, aOwner, aSIPSecUser)
       
    91 	{
       
    92 	iContactHeaderName = SIPStrings::StringF(SipStrConsts::EContactHeader);
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSipRegisterRefresh::ConstructL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CSipRegisterRefresh::ConstructL (CSIPRequest* aRequest, 
       
   100 									  CURIContainer& aRemoteTarget)
       
   101 	{
       
   102 	__SIP_ASSERT_LEAVE (aRequest, KErrArgument);
       
   103 
       
   104 	__SIP_ASSERT_LEAVE (
       
   105 	    aRequest->Method() == SIPStrings::StringF(SipStrConsts::ERegister),
       
   106 	    KErrArgument);
       
   107 
       
   108 	CSIPContactHeader* contact = 
       
   109 	    static_cast<CSIPContactHeader*>(aRequest->Header(iContactHeaderName,0));
       
   110 
       
   111 	__SIP_ASSERT_LEAVE (contact, KErrArgument);
       
   112 	
       
   113 	CSipRefreshBase::BaseConstructL(aRemoteTarget,*aRequest);
       
   114 	}
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CSipRegisterRefresh::SIPSecUser
       
   118 // From MTransactionOwner
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 const MSIPSecUser* CSipRegisterRefresh::SIPSecUser() const
       
   122     {
       
   123     // In case of REGISTER, the refresh must not act as a middle man.
       
   124     // This is to make the MSIPSecUser::TrustedUser() work correctly.
       
   125     return &iSIPSecUser;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CSipRegisterRefresh::Forward2xxResponseToCallerL
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CSipRegisterRefresh::Forward2xxResponseToCallerL (CSIPResponse* aResponse)
       
   133 	{
       
   134 	RefreshReceivedL(iCurrentTransactionId, aResponse);
       
   135 	}
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CSipRegisterRefresh::SetExpirationTimeToRequestL 
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CSipRegisterRefresh::SetExpirationTimeToRequestL (
       
   142     CSIPRequest& aRequest,
       
   143 	TUint aExpirationTimeInSeconds)
       
   144 	{
       
   145 	CSIPContactHeader* contact = static_cast<CSIPContactHeader*>(
       
   146         aRequest.Header(iContactHeaderName,0));
       
   147 
       
   148 	__SIP_ASSERT_LEAVE (contact, KErrArgument);	
       
   149 	
       
   150 	contact->SetExpiresParameterL(aExpirationTimeInSeconds);
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSipRegisterRefresh::ExpirationTimeFromResponseContact
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CSipRegisterRefresh::ExpirationTimeFromResponseContact (
       
   158 	CSIPResponse& aResponse)
       
   159 	{
       
   160 	TSglQueIter<CSIPHeaderBase> iter = 
       
   161         iRequest->Headers(iContactHeaderName);
       
   162 	if (iter != 0)
       
   163 		{
       
   164 		CSIPHeaderBase* header = iter;
       
   165 		CSIPContactHeader* reqContact = static_cast<CSIPContactHeader*>(header);
       
   166 		
       
   167 		// search the contact header of the response which match to one 
       
   168 		// defined in the request
       
   169 		CSIPContactHeader* resContact = 
       
   170 		    CSIPResponseUtility::ContactHeader( *reqContact, aResponse );
       
   171 		
       
   172 		if ( resContact && resContact->ExpiresParameter() >= 0 )
       
   173 		    {
       
   174 		    return resContact->ExpiresParameter();
       
   175 		    }
       
   176 		}
       
   177 
       
   178 	return KErrNotFound;
       
   179 	}
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CSipRegisterRefresh::SetExpirationTimeToResponseL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CSipRegisterRefresh::SetExpirationTimeToResponseL(
       
   186 	CSIPResponse& aResponse, 
       
   187 	TUint         aExpirationTimeInSeconds)
       
   188 	{
       
   189 	TBool setExpiresInContact = EFalse;
       
   190 
       
   191 	if (aResponse.HasHeader(iContactHeaderName))
       
   192 		{
       
   193 		__SIP_ASSERT_LEAVE (
       
   194 		    iRequest->HasHeader(iContactHeaderName), KErrGeneral);
       
   195 		    
       
   196 		CSIPContactHeader* reqContact = 
       
   197 		    static_cast<CSIPContactHeader*>(
       
   198 		        iRequest->Header(iContactHeaderName,0));
       
   199 	
       
   200 	    CSIPContactHeader* resContact = 
       
   201 		    CSIPResponseUtility::ContactHeader( *reqContact, aResponse );
       
   202 		
       
   203 		if ( resContact )
       
   204 		    {
       
   205 		    resContact->SetExpiresParameterL(aExpirationTimeInSeconds);
       
   206 		    setExpiresInContact = ETrue;
       
   207 		    }
       
   208 		}
       
   209 
       
   210 	if (!setExpiresInContact)
       
   211 		{
       
   212 		SetExpireTimeToResponseExpiresHeaderL(aResponse, 
       
   213 			                                  aExpirationTimeInSeconds);
       
   214 		}
       
   215 	}
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CSipRegisterRefresh::ExpirationTimeFromRequestL
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TInt CSipRegisterRefresh::ExpirationTimeFromRequestL(CSIPRequest& /*aRequest*/)
       
   222 	{
       
   223 	return iOwner->RefreshDurationL();
       
   224 	}
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CSipRegisterRefresh::ExpirationTimeFromResponse
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TInt CSipRegisterRefresh::ExpirationTimeFromResponse (CSIPResponse& aResponse)
       
   231 	{
       
   232 	TInt time = 0;
       
   233 	
       
   234 	time = ExpirationTimeFromResponseContact(aResponse);
       
   235 		
       
   236 	if(time == KErrNotFound) 
       
   237 		{
       
   238 		time = ExpireTimeFromResponseExpiresHeader(aResponse);
       
   239 		}
       
   240 
       
   241 	return time;
       
   242 	}
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CSipRegisterRefresh::CheckUpdateRequestExpiresValueL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CSipRegisterRefresh::CheckUpdateRequestExpiresValueL(
       
   249     CSIPRequest& aRequest)
       
   250 	{
       
   251 	CSIPContactHeader* contact = static_cast<CSIPContactHeader*>(
       
   252         aRequest.Header(iContactHeaderName,0));
       
   253 
       
   254 	__SIP_ASSERT_LEAVE (contact, KErrArgument);
       
   255 	}
       
   256  
       
   257 // -----------------------------------------------------------------------------
       
   258 // CSipRegisterRefresh::CheckTerminateRequestExpiresValueL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CSipRegisterRefresh::CheckTerminateRequestExpiresValueL(
       
   262 	CSIPRequest& aRequest)
       
   263 	{
       
   264 	CSIPContactHeader* contact = static_cast<CSIPContactHeader*>(
       
   265         aRequest.Header(iContactHeaderName,0));
       
   266 
       
   267 	__SIP_ASSERT_LEAVE (contact, KErrGeneral);
       
   268 
       
   269 	contact->SetExpiresParameterL(0);
       
   270 	}