realtimenetprots/sipfw/SIP/Registration/src/csipregisterupdating.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          : csipregisterupdating.cpp
       
    15 // Part of       : SIP Registration
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "csipregisterupdating.h"
       
    22 #include "csip423responsereceived.h"
       
    23 #include "sipcontactheader.h"
       
    24 #include "siprequest.h"
       
    25 #include "sipresponse.h"
       
    26 #include "CSIPRegistrar.h"
       
    27 #include "SipAssert.h"
       
    28 #include "sipminexpiresheader.h"
       
    29 #include "MRegistrationOwner.h"
       
    30 #include "CSIPResponseUtility.h"
       
    31 #include "siperr.h"
       
    32 #include "sipstrings.h"
       
    33 #include "sipstrconsts.h"
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSIPRegisterUpdating::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSIPRegisterUpdating* CSIPRegisterUpdating::NewL(
       
    41 	MRegistrationContext& aRegistration)
       
    42 	{
       
    43 	CSIPRegisterUpdating* self = CSIPRegisterUpdating::NewLC(aRegistration);
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 	
       
    48 // -----------------------------------------------------------------------------
       
    49 // CSIPRegisterUpdating::NewLC
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CSIPRegisterUpdating* CSIPRegisterUpdating::NewLC(
       
    53 	MRegistrationContext& aRegistration)
       
    54 	{
       
    55 	CSIPRegisterUpdating* self =
       
    56 		new (ELeave) CSIPRegisterUpdating(aRegistration);
       
    57 	CleanupStack::PushL(self);
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSIPRegisterUpdating::SetNeighbourStates
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CSIPRegisterUpdating::SetNeighbourStates(
       
    66 	CSIPRegistrationState* aResponse423Received,
       
    67 	CSIPRegistrationState* aRegistered,
       
    68 	CSIPRegistrationState* aUnregistered)
       
    69 	{
       
    70 	__SIP_ASSERT_RETURN(aResponse423Received, KErrArgument);
       
    71     __SIP_ASSERT_RETURN(aRegistered, KErrArgument);
       
    72 	__SIP_ASSERT_RETURN(aUnregistered, KErrArgument);
       
    73 
       
    74     iResponse423Received = aResponse423Received;
       
    75 	iRegistered = aRegistered;
       
    76 	iUnregistered = aUnregistered;
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSIPRegisterUpdating::~CSIPRegisterUpdating
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CSIPRegisterUpdating::~CSIPRegisterUpdating()
       
    84 	{
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSIPRegisterUpdating::UpdateL
       
    89 // -----------------------------------------------------------------------------
       
    90 //	
       
    91 void CSIPRegisterUpdating::UpdateL(TTransactionId& aTransactionId,
       
    92 				                   CSIPRequest*    aRequest)
       
    93 	{
       
    94 	__SIP_ASSERT_LEAVE(aRequest, KErrArgument);
       
    95 
       
    96 	CSIPContactHeader* contact = static_cast<CSIPContactHeader*>(
       
    97 		aRequest->Header(SIPStrings::StringF(SipStrConsts::EContactHeader),0));
       
    98 
       
    99 	__SIP_ASSERT_LEAVE(contact != 0, KErrArgument);
       
   100 		               
       
   101 	__SIP_ASSERT_LEAVE(contact->ExpiresParameter() > 0, KErrArgument);
       
   102 
       
   103 	// registrar must not be NULL after registering state.
       
   104 	__SIP_ASSERT_LEAVE(iRegistration.Registrar(), KErrGeneral);
       
   105 
       
   106 	// update registration expires parameter from aRequest Contact header
       
   107 	iRegistration.SetExpiresValueL(*aRequest);
       
   108 	// copy CallId and CSeq to request
       
   109 	iRegistration.Registrar()->FillCallIdAndCSeqL(*aRequest);
       
   110 	// copy To and From header to request
       
   111 	iRegistration.FillToFromL(*aRequest);
       
   112 
       
   113 	iRegistration.UpdateL(aTransactionId, aRequest);
       
   114 	}
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CSIPRegisterUpdating::ReceiveL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CSIPRegisterUpdating::ReceiveL(TTransactionId aTransactionId,
       
   121 		                            CSIPResponse*  aResponse)
       
   122 	{
       
   123 	__SIP_ASSERT_LEAVE(aResponse, KErrArgument);
       
   124 	// the expires parameter value must not be 0, other wise panic in debug
       
   125 	// mode, leaves in release mode.
       
   126 	__SIP_ASSERT_LEAVE(iRegistration.Contact().ExpiresParameter() > 0, 
       
   127 		KErrGeneral);
       
   128 
       
   129 	if (aResponse->Type() == CSIPResponse::E2XX)
       
   130 		{
       
   131 		// ConnectionMgr may have changed the the host part of the Contact
       
   132 		iRegistration.UpdateContactFromRequestL();
       
   133 		if (iRegistration.Request())
       
   134 			{
       
   135 			iRegistration.Request()->DeleteHeaders(
       
   136 				SIPStrings::StringF(SipStrConsts::ERouteHeader));
       
   137 			}
       
   138         TInt err = 
       
   139             CSIPResponseUtility::Check2XXResponse(iRegistration,*aResponse);
       
   140         if (err)
       
   141 			{
       
   142 			iRegistration.ReceivedErrorResponseL();
       
   143 			User::LeaveIfError(
       
   144 			    PassErrorToOwner(err,aTransactionId,
       
   145 			                     iRegistration.RegistrationId()));
       
   146 			delete aResponse;
       
   147 			iRegistration.SelfDetach(ETrue);
       
   148 			iRegistration.ChangeState(iUnregistered); 
       
   149 			}
       
   150 		// if there is no error, call function Received2XXResponseL,
       
   151 		// which will update bindings, start timer for non refresh binding
       
   152 		else 
       
   153 			{
       
   154 			// function update the binding from response.
       
   155 			iRegistration.Received2XXResponseL(*aResponse,aTransactionId);
       
   156 			// pass response to owner
       
   157 			PassResponseToOwnerL(aResponse, aTransactionId, 
       
   158 				iRegistration.RegistrationId());
       
   159 			iRegistration.SelfDetach(EFalse);
       
   160 			// if the binding is non refresh binding, the request is deleted
       
   161 			// after 2xx received
       
   162 			iRegistration.ClearRequest();
       
   163 			iRegistration.ChangeState(iRegistered); 
       
   164 			}
       
   165 		}
       
   166 	else if (aResponse->IsErrorResponse())
       
   167 		{
       
   168 		// if 423 response is received and there is min expires header,
       
   169 		// set min expires header from response to request and send 
       
   170 		// the request again.
       
   171         const RStringF KMinExpiresHeaderName = 
       
   172             SIPStrings::StringF(SipStrConsts::EMinExpiresHeader);		
       
   173 		
       
   174 		if (aResponse->ResponseCode() == K423Response && 
       
   175 			aResponse->HasHeader(KMinExpiresHeaderName))
       
   176 			{
       
   177 			// function set min expires header from response to request.
       
   178 			iRegistration.Received423ResponseL(*aResponse);
       
   179 			iRegistration.ChangeState(iResponse423Received);
       
   180 			static_cast<CSIP423ResponseReceived*>(iResponse423Received)->
       
   181 				SetUpdate(ETrue);
       
   182 			iRegistration.CurrentState().RegisterL(
       
   183 			    aTransactionId,iRegistration.Request(),NULL);
       
   184 			delete aResponse;
       
   185 			}
       
   186 		// either response code is 423, but no MinExpires-header in response
       
   187 		// or response code not 423
       
   188 		else
       
   189 			{
       
   190 			// ReceivedErrorResponseL, remove binding 
       
   191 			iRegistration.ReceivedErrorResponseL();
       
   192 			// pass response to owner
       
   193 			PassResponseToOwnerL(aResponse, aTransactionId, 
       
   194 				iRegistration.RegistrationId());
       
   195 			iRegistration.SelfDetach(ETrue);
       
   196 			iRegistration.ChangeState(iUnregistered);
       
   197 			}
       
   198 		}
       
   199 	// response type == 1XX
       
   200 	else
       
   201 		{
       
   202 		// pass provisional response to owner
       
   203 		PassResponseToOwnerL(aResponse, aTransactionId, 
       
   204 			iRegistration.RegistrationId());
       
   205 		}
       
   206 	}
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CSIPRegisterUpdating::TransactionEnded
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 TInt CSIPRegisterUpdating::TransactionEnded(TTransactionId aTransactionId, 
       
   213 		                                    TInt           aReason)
       
   214 	{
       
   215 	if (aReason != KErrNone)
       
   216 		{
       
   217 		iRegistration.ChangeState(iUnregistered);
       
   218 		}
       
   219 	// pass error to owner.
       
   220 	return (PassErrorToOwner(aReason, aTransactionId,
       
   221 		 iRegistration.RegistrationId()));	
       
   222 	}
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CSIPRegisterUpdating::CSIPRegisterUpdating
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 CSIPRegisterUpdating::CSIPRegisterUpdating(MRegistrationContext& aRegistration)
       
   229 	: CSIPRegistrationState (aRegistration)
       
   230 	{
       
   231 	}