multimediacommsengine/mmcesrv/mmceserver/src/mcenatstatecreateanswer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "mcenatstatecreateanswer.h"
       
    21 #include "mcenatsipsession.h"
       
    22 #include "mcenatactions.h"
       
    23 #include "mcenatevents.h"
       
    24 #include "mceactionset.h"
       
    25 #include "mceclientserver.h"
       
    26 #include "mcesrvlogs.h"
       
    27 #include "nspplugin.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CMceNatStateCreateAnswer::CMceNatStateCreateAnswer
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CMceNatStateCreateAnswer::CMceNatStateCreateAnswer()
       
    34 	{
       
    35 	}
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMceNatStateCreateAnswer::~CMceNatStateCreateAnswer
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceNatStateCreateAnswer::~CMceNatStateCreateAnswer()
       
    42 	{
       
    43 	}
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMceNatStateCreateAnswer::Accept
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 TBool CMceNatStateCreateAnswer::Accept( TMceNatStateTransitionEvent& aEvent )
       
    50     {
       
    51     if ( EMceNatAnswer == aEvent.NatCode() ||
       
    52          ( EMceNatHandleSIP == aEvent.NatCode() &&
       
    53            EMceInvite == aEvent.Code() )||
       
    54          EMceNatError == aEvent.NatCode() ||
       
    55          EMceNatICMPError == aEvent.NatCode() )
       
    56         {
       
    57         return ETrue;
       
    58         }
       
    59     else
       
    60         {
       
    61         return EFalse;
       
    62         }
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMceNatStateCreateAnswer::EntryL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CMceNatStateCreateAnswer::EntryL( TMceNatStateTransitionEvent& aEvent )
       
    70 	{
       
    71 	MCESRV_DEBUG( "*** CMceNatStateCreateAnswer::EntryL, Entry" );
       
    72     
       
    73     aEvent.Session().Actions().EncodeL();
       
    74     TMceReturnStatus status = aEvent.NatActions().ResolveL();
       
    75         
       
    76     if ( KMceReady == status )
       
    77 	    {
       
    78 	    CMceSipSession& session = aEvent.Session();
       
    79 	    
       
    80         aEvent.NatCode() = ( KMceReady == aEvent.ParamStatus() ?
       
    81                 EMceNatSync : aEvent.NatCode() );
       
    82 	    
       
    83         aEvent.NatActions().SetOffered( KMceNatPrevOfferSdp );
       
    84         session.Actions().DecodeL(); 
       
    85         aEvent.NatActions().UpdateRemoteAddressL();
       
    86         
       
    87         CSdpDocument* previous = session.Offer();
       
    88         aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
    89         aEvent.NatActions().SdpCleanup( previous, session.Offer() );
       
    90        
       
    91 	    aEvent.NatActions().StateChangedL( aEvent, KMceNatStateConnected );
       
    92 	    	    
       
    93 	    }
       
    94     else
       
    95         {
       
    96         aEvent.ParamStatus() = status;
       
    97         }
       
    98     
       
    99 	MCESRV_DEBUG( "*** CMceNatStateCreateAnswer::EntryL, Exit" );
       
   100 	}
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CMceNatStateCreateAnswer::ExitL
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CMceNatStateCreateAnswer::ExitL( TMceNatStateTransitionEvent& aEvent )
       
   107 	{
       
   108 	MCESRV_DEBUG( "*** CMceNatStateCreateAnswer::ExitL, Entry" );
       
   109     
       
   110 	switch ( aEvent.NatCode() )
       
   111 	    {
       
   112 	    case EMceNatError:
       
   113 	    case EMceNatICMPError:
       
   114 	        {
       
   115 	        ExitErrorL( aEvent );
       
   116 	        break;
       
   117 	        }
       
   118 	    case EMceNatHandleSIP:
       
   119 	        {
       
   120 	        ExitHandleInviteL( aEvent );
       
   121 	        break;
       
   122 	        }
       
   123 	    default:
       
   124 	        {
       
   125 	        ExitDefaultL( aEvent );
       
   126 	        break;
       
   127 	        }
       
   128 	    }
       
   129     
       
   130 	MCESRV_DEBUG( "*** CMceNatStateCreateAnswer::ExitL, Exit" );	
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMceNatStateCreateAnswer::ExitErrorL
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CMceNatStateCreateAnswer::ExitErrorL( TMceNatStateTransitionEvent& aEvent )
       
   138     {
       
   139     
       
   140     TMceStateIndex sipState = aEvent.Session().CurrentState().Id();
       
   141           
       
   142     if ( aEvent.ParamStatus() > KMceNatNonFatalErrorLimit )
       
   143         {
       
   144         aEvent.Session().Actions().ClientErrorOccured( aEvent.ParamStatus() );
       
   145         }
       
   146     
       
   147     
       
   148     if (( aEvent.NatCode() == EMceNatICMPError && 
       
   149     		KMceStateEstablished == sipState ) || 
       
   150     		aEvent.NatCode() == EMceNatError )  
       
   151     	{
       
   152     	aEvent.NatActions().Continue();
       
   153     	User::Leave( aEvent.ParamStatus() );		
       
   154     	}
       
   155        
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CMceNatStateCreateAnswer::ExitHandleInviteL
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMceNatStateCreateAnswer::ExitHandleInviteL( TMceNatStateTransitionEvent& aEvent )
       
   163     {
       
   164     CMceSipSession& session = aEvent.Session();
       
   165     
       
   166     if ( MceSip::HasContent( session.Request() ) )
       
   167         {
       
   168         // Incoming INVITE contained new SDP, which can contain new candidates,
       
   169         // hence it is given to NAT FW - without state update.
       
   170         User::LeaveIfError( session.Actions().CreateSDP( session.Request() ) );
       
   171         aEvent.NatActions().UpdateL();
       
   172         }
       
   173     
       
   174     // Not consumed, done by SIP state machine
       
   175     aEvent.NatActions().Continue();
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CMceNatStateCreateAnswer::ExitDefaultL
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CMceNatStateCreateAnswer::ExitDefaultL( TMceNatStateTransitionEvent& aEvent )
       
   183     {
       
   184 	
       
   185 	// Check if plugin has flag setup if yes signall that at the session level.
       
   186 	TInt status = aEvent.NatActions().GetResourceReservationStatus();
       
   187 	
       
   188 	if ( status == CNSPPlugin::ENSPResourcesNotReserved )
       
   189 		{
       
   190 		aEvent.NatActions().SetNeedtoReceive();	
       
   191 		}
       
   192 	
       
   193     User::LeaveIfNull( aEvent.Document() );
       
   194     CMceSipSession& session = aEvent.Session();
       
   195     
       
   196     CSdpDocument* previous = session.Offer();
       
   197     aEvent.Session().SetOffer( aEvent.Document() );
       
   198     aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
   199     aEvent.NatActions().SdpCleanup( previous, session.Offer() );
       
   200     
       
   201     aEvent.NatActions().StateChangedL( aEvent, KMceNatStateDecodeOffer );
       
   202     }