realtimenetprots/sipfw/SIP/SIPSec/IpSecPlugin/src/CStateInUse.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          : CStateInUse.cpp
       
    15 // Part of       : SIPSec, IpSec Plugin
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipsecurityverifyheader.h"
       
    22 #include "sipsecurityclientheader.h"
       
    23 #include "siprequest.h"
       
    24 #include "TSIPTransportParams.h"
       
    25 #include "CSipSecAgreeRecord.h"
       
    26 #include "MIpSecAgreeContextParams.h"
       
    27 #include "CStateInUse.h"	
       
    28 #include "MIpSecMechanismParams.h"
       
    29 #include "CleanupResetAndDestroy.h"
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // CInUse::CInUse
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CInUse::CInUse()
       
    36     {
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CInUse::State
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CState::TSecAgreeRecordState CInUse::State()
       
    44 	{
       
    45 	return EInUse;
       
    46 	}
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CInUse::TimerExpiredL
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 void CInUse::TimerExpiredL( CSipSecAgreeRecord& aRec,
       
    53 							TTimerId /* aTimerId */,
       
    54 							TAny* /* aTimerParam */ )
       
    55 	{
       
    56 	DeleteSasL( aRec );
       
    57 	}
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CInUse::RegisterL
       
    61 // ----------------------------------------------------------------------------
       
    62 //			
       
    63 void CInUse::RegisterL( CSipSecAgreeRecord& aRec,
       
    64 						CSIPRequest& aRequest,
       
    65 						TSIPTransportParams& aTransportParams,
       
    66 						const TDesC8& aOutboundProxy )
       
    67 	{
       
    68     // If other record is already in temporal state, this record is not used
       
    69     // for registration
       
    70 	if ( aRec.iParams.HasRecordInState( ETemporal ) )
       
    71 		{	
       
    72 		return;
       
    73 		}
       
    74 	
       
    75 	// Create temporary sec client headers
       
    76     RPointerArray<CSIPSecurityHeaderBase> clientHdrs;
       
    77     
       
    78     CleanupResetAndDestroyPushL( clientHdrs );
       
    79     
       
    80     for ( TInt i = 0; i < aRec.iSecClientHeaders.Count(); i++ )
       
    81         {
       
    82         CSIPSecurityClientHeader* header = 
       
    83             static_cast<CSIPSecurityClientHeader*>( 
       
    84                 aRec.iSecClientHeaders[ i ]->CloneL() );
       
    85         CleanupStack::PushL( header );
       
    86         clientHdrs.AppendL( header );
       
    87         CleanupStack::Pop( header );
       
    88         }
       
    89     
       
    90 	aRec.iParams.MechParams().UpdateSecCliL( clientHdrs );	
       
    91 	
       
    92 	// Copy updated sec client headers to the request
       
    93 	CSipSecAgreeRecord::CopyHeadersToMessageL( clientHdrs, aRequest, ETrue );
       
    94 
       
    95 	// Temporary client headers are not needed anymore 
       
    96 	CleanupStack::PopAndDestroy( 1 ); // clientHdrs
       
    97 
       
    98     // Use still existing SAs
       
    99 	aTransportParams.SetTransportId( aRec.iTransportParams.TransportId() );
       
   100 
       
   101 	// Make sure that SigComp usage is not disabled
       
   102     aTransportParams.SetIgnoreCompartmentId( EFalse );
       
   103 
       
   104 	// Add port_ps to next hop address
       
   105 	aRec.UpdateNextHopPort( aRequest, aOutboundProxy );
       
   106 	}
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CInUse::ReguestL
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 void CInUse::ReguestL( CSipSecAgreeRecord& aRec,
       
   113 					   CSIPRequest& aRequest,
       
   114 					   TSIPTransportParams& aTransportParams,
       
   115 					   const TDesC8& aOutboundProxy )
       
   116 	{
       
   117 	// Set transport id for outgoing request so that protected transports
       
   118 	// are used
       
   119 	aTransportParams.SetTransportId( aRec.iTransportParams.TransportId() );
       
   120 
       
   121 	// Make sure that SigComp usage is not disabled
       
   122     aTransportParams.SetIgnoreCompartmentId( EFalse );
       
   123     
       
   124 	// Add port_ps to next hop address
       
   125 	aRec.UpdateNextHopPort( aRequest, aOutboundProxy );
       
   126 	}	      
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // CInUse::Resp2xxL
       
   130 // ----------------------------------------------------------------------------
       
   131 //		
       
   132 void CInUse::Resp2xxL( CSipSecAgreeRecord& aRec, CSIPResponse& aResponse )
       
   133 	{
       
   134 	// Check whether 200 OK was received directly for re-registration
       
   135 	if ( aRec.iParams.HasOnlyOneRecord() )
       
   136 	    {
       
   137 	    UpdateExpirationTimeL( aRec, aResponse );
       
   138 	    }
       
   139 	else
       
   140 	    {
       
   141 	    // There are now two SA records, the second record was created when a
       
   142 	    // 401 was received earlier. The new record enters "in use" state when
       
   143 	    // it gets the 2xx and this record, which already is "in use" enters
       
   144 	    // "old" state.
       
   145     	aRec.NextState( EOld );
       
   146 	    }
       
   147 	}
       
   148 
       
   149 // ----------------------------------------------------------------------------
       
   150 // CInUse::ProcessSecVerifyL
       
   151 // ----------------------------------------------------------------------------
       
   152 // 	
       
   153 void CInUse::ProcessSecVerifyL( 
       
   154     CSipSecAgreeRecord& aRec,
       
   155 	RPointerArray<CSIPSecurityVerifyHeader>& aSecurityVerify )
       
   156     {
       
   157     // If two records exist but more recent is not yet in "temporal" state,
       
   158     // old sec verify hdrs should be used
       
   159     if ( !aRec.iParams.HasOnlyOneRecord() &&
       
   160          !aRec.iParams.HasRecordInState( ETemporal ) )
       
   161         {
       
   162 	    aSecurityVerify.ResetAndDestroy();
       
   163 	    RPointerArray<CSIPSecurityHeaderBase>& secVerifys = 
       
   164 			aRec.SecurityHeaders( EFalse );
       
   165 	    for ( TInt i = 0; i < secVerifys.Count(); i++ )
       
   166 	        {
       
   167 	        CSIPSecurityVerifyHeader* secHdr = 
       
   168 	            static_cast<CSIPSecurityVerifyHeader*>(
       
   169 					secVerifys[ i ]->CloneL() );
       
   170 	        CleanupStack::PushL( secHdr );
       
   171 	        aSecurityVerify.AppendL( secHdr );
       
   172 	        CleanupStack::Pop( secHdr );
       
   173 	        }
       
   174 		}
       
   175     }
       
   176 
       
   177 // End of File