multimediacommsengine/mmcesrv/mmceserver/src/mcenatsipsession.cpp
changeset 0 1bce908db942
child 11 2a28ef775f15
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 <sipprofile.h>
       
    21 #include <sipinvitedialogassoc.h>
       
    22 #include <sdpdocument.h>
       
    23 #include "mcenatsipsession.h"
       
    24 #include "mcenatsipstatemachine.h"
       
    25 #include "mcemediamanager.h"
       
    26 #include "mcenatpluginmanager.h"
       
    27 #include "mcecssession.h"
       
    28 #include "mcesipconnection.h"
       
    29 #include "mceclient.pan"
       
    30 #include "mcesrvlogs.h"
       
    31 #include "mcecomsession.h"
       
    32 
       
    33 #define PANIC( aPanic ) User::Panic( KMceServerPanic, aPanic )
       
    34 #define DEBUG_PANIC( aPanic ) __ASSERT_DEBUG( EFalse, PANIC( aPanic ) )
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMceNatSipSession::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceNatSipSession* CMceNatSipSession::NewL( CMceCsSession& aClientSession, 
       
    42                                             CMceSipConnection& aSIPConnection,
       
    43 								            CMceSipStateMachine& aStateMachine,
       
    44 								            CSIPProfile& aProfile,
       
    45 								            const CDesC8Array* aParams )
       
    46 	{
       
    47     CMceNatSipSession* self = CMceNatSipSession::NewLC( aClientSession, 
       
    48                                                         aSIPConnection, 
       
    49                                                         aStateMachine,
       
    50                                                         aProfile,
       
    51                                                         aParams );
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CMceNatSipSession::NewL
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CMceNatSipSession* CMceNatSipSession::NewL( CMceCsSession& aClientSession, 
       
    61                                             CMceSipConnection& aSIPConnection,
       
    62 								            CMceSipStateMachine& aStateMachine,
       
    63 								            const CDesC8Array* aParams )
       
    64 	{
       
    65     CMceNatSipSession* self = CMceNatSipSession::NewLC( aClientSession, 
       
    66                                                         aSIPConnection, 
       
    67                                                         aStateMachine,
       
    68                                                         aParams );
       
    69     CleanupStack::Pop(self);
       
    70     return self;
       
    71 	}
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMceNatSipSession::NewLC
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CMceNatSipSession* CMceNatSipSession::NewLC( CMceCsSession& aClientSession, 
       
    79                                              CMceSipConnection& aSIPConnection,
       
    80  								             CMceSipStateMachine& aStateMachine,
       
    81  								             CSIPProfile& aProfile,
       
    82  								             const CDesC8Array* aParams )
       
    83 	{
       
    84     CMceNatSipSession* self = new (ELeave) CMceNatSipSession( aClientSession, 
       
    85                                                               aSIPConnection, 
       
    86                                                               aStateMachine,
       
    87                                                               aProfile );
       
    88     CleanupStack::PushL(self);
       
    89     self->ConstructL( aClientSession, aSIPConnection, aParams );
       
    90     return self;
       
    91 	}
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CMceNatSipSession::NewLC
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CMceNatSipSession* CMceNatSipSession::NewLC( CMceCsSession& aClientSession, 
       
    98                                              CMceSipConnection& aSIPConnection,
       
    99  								             CMceSipStateMachine& aStateMachine,
       
   100  								             const CDesC8Array* aParams )
       
   101 	{
       
   102     CMceNatSipSession* self = new (ELeave) CMceNatSipSession( aClientSession, 
       
   103                                                               aSIPConnection, 
       
   104                                                               aStateMachine );
       
   105     CleanupStack::PushL(self);
       
   106     self->ConstructL( aClientSession, aSIPConnection, aParams );
       
   107     return self;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CMceNatSipSession::CMceNatSipSession
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CMceNatSipSession::CMceNatSipSession( CMceCsSession& aClientSession, 
       
   115 								      CMceSipConnection& aSIPConnection,
       
   116 								      CMceSipStateMachine& aStateMachine,
       
   117 								      CSIPProfile& aProfile )
       
   118     : CMceSipSession( aClientSession, aSIPConnection, aStateMachine, aProfile )
       
   119 	{
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMceNatSipSession::CMceNatSipSession
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 CMceNatSipSession::CMceNatSipSession( CMceCsSession& aClientSession, 
       
   127 								      CMceSipConnection& aSIPConnection,
       
   128 								      CMceSipStateMachine& aStateMachine )
       
   129     : CMceSipSession( aClientSession, aSIPConnection, aStateMachine )
       
   130 	{
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMceNatSipSession::ConstructL
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CMceNatSipSession::ConstructL( CMceCsSession& aClientSession,
       
   138                                     CMceSipConnection& aSIPConnection,
       
   139                                     const CDesC8Array* aParams )
       
   140 	{
       
   141     MCESRV_DEBUG( "*** CMceNatSipSession::ConstructL, Entry" )
       
   142 
       
   143 	CMceSipSession::ConstructL( aClientSession ); // base class
       
   144 
       
   145     TRAPD( error, TryNatSessionL( aSIPConnection, aParams ) );
       
   146 
       
   147     if ( KErrNone != error )
       
   148         {
       
   149         NatErrorOccurred( error );
       
   150         }
       
   151     else
       
   152     	{
       
   153     	iNatSession = ETrue;
       
   154     	}
       
   155     MCESRV_DEBUG( "*** CMceNatSipSession::ConstructL, Exit" )  
       
   156 	}
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CMceNatSipSession::TryNatSessionL
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMceNatSipSession::TryNatSessionL( CMceSipConnection& aSIPConnection,
       
   163                                         const CDesC8Array* aParams )
       
   164     {
       
   165     iNatStateMachine = CMceNatSipStateMachine::NewL();
       
   166     
       
   167     TUint32 iapId = aSIPConnection.AccessPointId();
       
   168     
       
   169     const TDesC8* userAor = NULL;
       
   170     TPtrC8 originator;
       
   171     if ( ProfileConfigured() )
       
   172         {
       
   173         MCESRV_DEBUG( "*** CMceNatSipSession::TryNatSessionL, using profile" )
       
   174         
       
   175         CSIPProfile& profile = Profile();
       
   176         User::LeaveIfError( profile.GetParameter( KSIPUserAor, userAor ) );
       
   177         }
       
   178     else
       
   179         {
       
   180         MCESRV_DEBUG( "*** CMceNatSipSession::TryNatSessionL, profile not used" )
       
   181         
       
   182         __ASSERT_ALWAYS( aParams && 
       
   183                          aParams->MdcaCount() > KMceArrayIndexOriginator, 
       
   184                          User::Leave( KErrArgument ) );
       
   185         originator.Set( aParams->MdcaPoint( KMceArrayIndexOriginator ) );
       
   186         userAor = &originator;
       
   187         }
       
   188     
       
   189     TUriParser8 uri8Parser;
       
   190     User::LeaveIfError( uri8Parser.Parse( *userAor ) );
       
   191     CUri8* cUri8 = CUri8::NewLC( uri8Parser );
       
   192     const TDesC8& domain = cUri8->Uri().Extract( EUriHost );
       
   193     
       
   194     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   195     iSessionId = manager.NewSessionL( *this, iapId, domain );
       
   196     
       
   197     CleanupStack::PopAndDestroy( cUri8 );
       
   198     
       
   199     MCESRV_DEBUG( "*** CMceNatSipSession::TryNatSessionL, Exit" )
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CMceNatSipSession::~CMceNatSipSession
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 CMceNatSipSession::~CMceNatSipSession()
       
   207 	{
       
   208 	MCESRV_DEBUG( "*** CMceNatSipSession::~CMceNatSipSession, Entry" )
       
   209 	
       
   210     delete iNatStateMachine;
       
   211     
       
   212     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   213     TRAP_IGNORE( manager.CloseSessionL( iSessionId ) )
       
   214     
       
   215     MCESRV_DEBUG( "*** CMceNatSipSession::~CMceNatSipSession, Exit" )
       
   216   	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CMceNatSipSession::UpdateMediaL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TMceReturnStatus CMceNatSipSession::UpdateMediaL()
       
   223     {
       
   224     MCESRV_DEBUG( "*** CMceNatSipSession::UpdateMediaL, Entry" )
       
   225     
       
   226     PrepareNatSessionUpdate();
       
   227     
       
   228     TMceReturnStatus status = CMceSipSession::UpdateMediaL();
       
   229     if ( KMceReady == status )
       
   230         {
       
   231         TMceNatStateTransitionEvent event( NULL, *this, EMceNatUpdated, *this,
       
   232         								   iSipEvent );
       
   233         
       
   234         if ( !iNatDisabled && iNatStateMachine->Accept( event ) )
       
   235             {
       
   236             MCESRV_DEBUG( "*** CMceNatSipSession::UpdateMediaL, processing" )
       
   237             
       
   238             iEntryPoint = ENatEntryUpdated;
       
   239             event.ParamStatus() = KMceReady;
       
   240             
       
   241             TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   242             
       
   243             if ( error != KErrNone )
       
   244                 {
       
   245                 iEntryPoint = ENatEntryNone;
       
   246                 NatErrorOccurred( error );
       
   247                 }
       
   248             else
       
   249                 {
       
   250                 status = event.ParamStatus();
       
   251                 }
       
   252             }
       
   253         }
       
   254     
       
   255     MCESRV_DEBUG( "*** CMceNatSipSession::UpdateMediaL, Exit" )
       
   256     return status;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CMceNatSipSession::ReserveL
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TMceReturnStatus CMceNatSipSession::ReserveL()
       
   264     {
       
   265     MCESRV_DEBUG("CMceNatSipSession::ReserveL, Entry")
       
   266 
       
   267     iReserveStatus = CMceSipSession::ReserveL();
       
   268     if ( iReserveStatus == KMceReady )
       
   269     	{
       
   270     	TMceReturnStatus async = 0;
       
   271     	iReserveStatus =
       
   272     		GetResourceReservationStatus() == async ? KMceAsync : KMceReady;
       
   273     	}
       
   274     
       
   275     return iReserveStatus;
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CMceNatSipSession::Updated
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CMceNatSipSession::Updated( CMceComSession& aSession )
       
   283     {
       
   284     MCESRV_DEBUG( "*** CMceNatSipSession::Updated, Entry" )
       
   285     
       
   286     TMceNatStateTransitionEvent event(
       
   287             NULL, *this, EMceNatUpdated, *this, iSipEvent );
       
   288     
       
   289     if ( !iNatDisabled &&
       
   290          iNatStateMachine->Accept( event ) )
       
   291         {
       
   292         MCESRV_DEBUG( "*** CMceNatSipSession::Updated, processing" )
       
   293 
       
   294         iEntryPoint = ENatEntryUpdated;
       
   295         event.ParamStatus() = KMceAsync;
       
   296         
       
   297         TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   298         
       
   299         if ( KErrNone != error )
       
   300             {
       
   301             iEntryPoint = ENatEntryNone;
       
   302             CMceSipSession::Updated( aSession );
       
   303             NatErrorOccurred( error );
       
   304             }
       
   305         }
       
   306     else
       
   307         {
       
   308         MCESRV_DEBUG( "*** CMceNatSipSession::Updated, passing forward" )
       
   309         CMceSipSession::Updated( aSession );
       
   310         }
       
   311 		
       
   312     MCESRV_DEBUG("*** CMceNatSipSession::Updated, Exit" )
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CMceNatSipSession::Offer
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 CSdpDocument* CMceNatSipSession::Offer()
       
   320     {
       
   321     if ( KMceNatPrevOfferSdp == iOfferedSdp )
       
   322         {
       
   323         MCESRV_DEBUG("*** CMceNatSipSession::Offer, iPrevOffer" )
       
   324         return iPrevOffer;        
       
   325         }
       
   326     else
       
   327         {
       
   328         return CMceSipSession::Offer();
       
   329         }
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CMceNatSipSession::NatSession
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 TBool CMceNatSipSession::NatSession() const
       
   337     {
       
   338     return ETrue;
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CMceNatSipSession::NatState
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 TInt CMceNatSipSession::NatState() const
       
   346     {
       
   347     return iNatStateMachine->State();
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CMceNatSipSession::IsNatDisabled
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TBool CMceNatSipSession::IsNatDisabled() const
       
   355 	{
       
   356 	return iNatDisabled;
       
   357 	}
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // CMceNatSipSession::Initialized
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CMceNatSipSession::Initialized( TUint aSessionId )
       
   364     {
       
   365     MCESRV_DEBUG( "*** CMceNatSipSession::Initialized, Entry" )
       
   366     
       
   367     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   368     
       
   369     TMceNatStateTransitionEvent event( 
       
   370             NULL, *this, EMceNatInitialized, *this, iSipEvent );
       
   371     
       
   372     if ( !iNatDisabled &&
       
   373          aSessionId == iSessionId &&
       
   374          iNatStateMachine->Accept( event ) )
       
   375         {
       
   376         MCESRV_DEBUG( "*** CMceNatSipSession::Initialized, processing" )
       
   377         
       
   378         TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   379             
       
   380         if ( KErrNone != error )
       
   381             {
       
   382             NatErrorOccurred( error );
       
   383             }        
       
   384         }
       
   385     else
       
   386         {
       
   387         DEBUG_PANIC( KErrNotReady );
       
   388         }
       
   389     
       
   390     MCESRV_DEBUG( "*** CMceNatSipSession::Initialized, Entry" )
       
   391     }
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CMceNatSipSession::OfferReady
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 void CMceNatSipSession::OfferReady( TUint aSessionId, CSdpDocument* aOffer )
       
   398     {
       
   399     MCESRV_DEBUG("*** CMceNatSipSession::OfferReady, Entry" )
       
   400     
       
   401     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   402     
       
   403     CMceNatPluginManager::WriteSdpToLog( _L("Offer"), aOffer );
       
   404     
       
   405     TMceNatStateTransitionEvent event(
       
   406             aOffer, *this, EMceNatOffer, *this, iSipEvent );
       
   407     
       
   408     if ( !iNatDisabled &&
       
   409          aSessionId == iSessionId &&
       
   410          iNatStateMachine->Accept( event ) )
       
   411         {
       
   412         MCESRV_DEBUG( "*** CMceNatSipSession::OfferReady, processing" )
       
   413         
       
   414         TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   415         
       
   416         if ( KErrNone != error )
       
   417             {
       
   418             NatErrorOccurred( error );
       
   419             }
       
   420         }
       
   421     else
       
   422         {
       
   423         SafeDelete( aOffer );
       
   424         DEBUG_PANIC( KErrNotReady );
       
   425         }
       
   426     
       
   427     MCESRV_DEBUG("*** CMceNatSipSession::OfferReady, Exit" )
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CMceNatSipSession::AnswerReady
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 void CMceNatSipSession::AnswerReady( TUint aSessionId, CSdpDocument* aAnswer )
       
   435     {
       
   436     MCESRV_DEBUG("*** CMceNatSipSession::AnswerReady, Entry" )
       
   437     
       
   438     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   439     
       
   440     CMceNatPluginManager::WriteSdpToLog( _L("Answer"), aAnswer );
       
   441     
       
   442     TMceNatStateTransitionEvent event(
       
   443             aAnswer, *this, EMceNatAnswer, *this, iSipEvent );
       
   444     
       
   445     if ( !iNatDisabled &&
       
   446          aSessionId == iSessionId &&
       
   447          iNatStateMachine->Accept( event ) )
       
   448         {
       
   449         MCESRV_DEBUG( "*** CMceNatSipSession::AnswerReady, processing" )
       
   450         
       
   451         TRAPD( error, iNatStateMachine->ProcessL( event ) );
       
   452         
       
   453         if ( KErrNone != error )
       
   454             {
       
   455             NatErrorOccurred( error );
       
   456             }
       
   457         }
       
   458     else
       
   459         {
       
   460         SafeDelete( aAnswer );
       
   461         DEBUG_PANIC( KErrNotReady );
       
   462         }
       
   463     
       
   464     MCESRV_DEBUG("*** CMceNatSipSession::AnswerReady, Exit" )
       
   465     }
       
   466     
       
   467 // -----------------------------------------------------------------------------
       
   468 // CMceNatSipSession::UpdateSdp
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void CMceNatSipSession::UpdateSdp( TUint aSessionId, CSdpDocument* aOffer )
       
   472     {
       
   473     MCESRV_DEBUG( "*** CMceNatSipSession::UpdateSdp, Entry" )
       
   474 
       
   475     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   476     
       
   477     TMceNatStateTransitionEvent event(
       
   478             aOffer, *this, EMceNatUpdateSdp, *this, iSipEvent );
       
   479     
       
   480     if ( !iNatDisabled &&
       
   481          aSessionId == iSessionId &&
       
   482          iNatStateMachine->Accept( event ) )
       
   483         {
       
   484         MCESRV_DEBUG( "*** CMceNatSipSession::UpdateSdp, processing" )
       
   485         
       
   486         TRAPD( error, iNatStateMachine->ProcessL( event ) );
       
   487         SafeDelete( aOffer );
       
   488         if ( KErrNone != error )
       
   489             {
       
   490             NatErrorOccurred( error );
       
   491             }
       
   492         }
       
   493     else
       
   494         {
       
   495         SafeDelete( aOffer );
       
   496         DEBUG_PANIC( KErrNotReady );
       
   497         }
       
   498     
       
   499     MCESRV_DEBUG( "*** CMceNatSipSession::UpdateSdp, Exit" )
       
   500     }
       
   501     
       
   502 // -----------------------------------------------------------------------------
       
   503 // CMceNatSipSession::ErrorOccurred
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CMceNatSipSession::ErrorOccurred( TUint aSessionId, TInt aError )
       
   507     {
       
   508     MCESRV_DEBUG( "*** CMceNatSipSession::ErrorOccurred, Entry" )
       
   509     MCESRV_DEBUG_DVALUE( "*** error", aError )
       
   510     
       
   511     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   512     
       
   513     TMceNatStateTransitionEvent event(
       
   514             NULL, *this, EMceNatError, *this, iSipEvent, aError );
       
   515     
       
   516     if ( !iNatDisabled &&
       
   517          aSessionId == iSessionId &&
       
   518          iNatStateMachine->Accept( event ) )
       
   519         {
       
   520         MCESRV_DEBUG( "*** CMceNatSipSession::ErrorOccurred, processing" )
       
   521         
       
   522         TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   523         
       
   524         if ( KErrNone != error )
       
   525             {
       
   526             NatErrorOccurred( error );
       
   527             }
       
   528         }
       
   529     
       
   530     MCESRV_DEBUG( "*** CMceNatSipSession::ErrorOccurred, Exit" )
       
   531     }
       
   532   
       
   533 // -----------------------------------------------------------------------------
       
   534 // CMceNatSipSession::IcmpErrorOccurred
       
   535 // -----------------------------------------------------------------------------
       
   536 //
       
   537 void CMceNatSipSession::IcmpErrorOccurred( TUint aSessionId, TInt aError )
       
   538     {
       
   539     MCESRV_DEBUG( "*** CMceNatSipSession::IcmpErrorOccurred, Entry" )
       
   540     MCESRV_DEBUG_DVALUE( "*** error", aError )
       
   541     
       
   542     __ASSERT_DEBUG( aSessionId == iSessionId, PANIC( KErrArgument ) );
       
   543        
       
   544     TMceNatStateTransitionEvent event(
       
   545             NULL, *this, EMceNatICMPError, *this, iSipEvent, aError );
       
   546     
       
   547     if ( !iNatDisabled &&
       
   548          aSessionId == iSessionId &&
       
   549          iNatStateMachine->Accept( event ) )
       
   550         {
       
   551         MCESRV_DEBUG( "*** CMceNatSipSession::IcmpErrorOccurred, processing" )
       
   552         
       
   553         TRAPD( error, iNatStateMachine->ProcessL( event ) )
       
   554         
       
   555         if ( KErrNone != error )
       
   556             {
       
   557             NatErrorOccurred( error );
       
   558             }
       
   559         }
       
   560     
       
   561     MCESRV_DEBUG( "*** CMceNatSipSession::IcmpErrorOccurred, Exit" )
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CMceNatSipSession::CreateOfferL
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 TInt CMceNatSipSession::CreateOfferL()
       
   569     {
       
   570     SetMediaQosL();
       
   571     
       
   572     CSdpDocument* offer = Offer();
       
   573     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   574     return manager.CreateOfferL( iSessionId, offer );
       
   575     }
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // CMceNatSipSession::ResolveL
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 TInt CMceNatSipSession::ResolveL()
       
   582     {
       
   583     SetMediaQosL();
       
   584     
       
   585     CSdpDocument* offer = PrevOffer();
       
   586     CSdpDocument* answer = Offer();
       
   587     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   588     return manager.ResolveL( iSessionId, offer, answer );
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CMceNatSipSession::DecodeAnswerL
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 TInt CMceNatSipSession::DecodeAnswerL()
       
   596     {
       
   597     CSdpDocument* answer = Offer();
       
   598     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   599     return manager.DecodeAnswerL( iSessionId, answer );
       
   600     }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CMceNatSipSession::UpdateL
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 void CMceNatSipSession::UpdateL()
       
   607     {
       
   608     CSdpDocument* offer = Offer();
       
   609     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   610     manager.UpdateL( iSessionId, offer );
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CMceNatSipSession::UpdateRemoteAddressL
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CMceNatSipSession::UpdateRemoteAddressL()
       
   618     {    
       
   619     CMceMediaManager& manager = Manager().MediaManager();
       
   620     RPointerArray<CMceSrvStream>& streams = ActiveBody().MccStreams();
       
   621     
       
   622     for ( TInt i = 0; i < streams.Count(); i++ )
       
   623         {
       
   624         manager.SetRemoteAddressL( *streams[i] );
       
   625         }
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CMceNatSipSession::SetOffered
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void CMceNatSipSession::SetOffered( TMceNatOfferedSdp aOffered )
       
   633     {
       
   634     iOfferedSdp = aOffered;
       
   635     }
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // CMceNatSipSession::SdpCleanup
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 void CMceNatSipSession::SdpCleanup( CSdpDocument* aPrev, CSdpDocument* aRep )
       
   642     {
       
   643     CMceSipSession::SdpCleanup( aPrev, aRep );
       
   644     }
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CMceNatSipSession::Continue
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 void CMceNatSipSession::Continue() 
       
   651     {
       
   652     switch( iEntryPoint )
       
   653         {
       
   654         case ENatEntryUpdated:
       
   655             {
       
   656             CMceSipSession::Updated( ActiveBody() );
       
   657             break;
       
   658             }
       
   659         
       
   660         case ENatEntryHandleSIPEvent:
       
   661             {
       
   662             CMceSipSession::HandleSIPEvent( iSipEvent, Dialog()->Dialog() );
       
   663             break;
       
   664             }
       
   665         
       
   666         default:
       
   667             {
       
   668             MCESRV_DEBUG( "*** CMceNatSipSession::Continue, default!" )
       
   669             DEBUG_PANIC( KErrTotalLossOfPrecision );
       
   670             }
       
   671         }
       
   672     }
       
   673 
       
   674 // -----------------------------------------------------------------------------
       
   675 // CMceNatSipSession::StateChanged
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 void CMceNatSipSession::StateChangedL( TMceNatStateTransitionEvent& aEvent,
       
   679                                        TUint aNewState )
       
   680     {
       
   681     iNatStateMachine->NewStateL( aEvent, aNewState );
       
   682     }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CMceNatSipSession::HandleSIPEvent
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 void CMceNatSipSession::HandleSIPEvent( TMceSipEventCode aEventCode, CSIPDialog& aDialog )
       
   689     {
       
   690     MCESRV_DEBUG( "*** CMceNatSipSession::HandleSIPEvent, Entry" )
       
   691     
       
   692     TMceNatStateTransitionEvent event(
       
   693             NULL, *this, EMceNatHandleSIP, *this, aEventCode );
       
   694     
       
   695     if ( !iNatDisabled && iNatStateMachine->Accept( event ) )
       
   696         {
       
   697         MCESRV_DEBUG( "*** CMceNatSipSession::HandleSIPEvent, processing" )
       
   698 
       
   699         iEntryPoint = ENatEntryHandleSIPEvent;
       
   700         iSipEvent = aEventCode;
       
   701         event.ParamStatus() = KMceAsync;
       
   702         
       
   703         TRAPD( error, iNatStateMachine->ProcessL( event ) );
       
   704         
       
   705         if ( KErrNone != error )
       
   706             {
       
   707 	        iEntryPoint = ENatEntryNone;
       
   708             CMceSipSession::HandleSIPEvent( aEventCode, aDialog );
       
   709             NatErrorOccurred( error );
       
   710             }
       
   711         }
       
   712     else
       
   713         {
       
   714         MCESRV_DEBUG( "*** CMceNatSipSession::HandleSIPEvent, passing forward" )
       
   715         CMceSipSession::HandleSIPEvent( aEventCode, aDialog );        
       
   716         }
       
   717     	
       
   718     MCESRV_DEBUG( "*** CMceNatSipSession::HandleSIPEvent, Exit" )
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CMceNatSipSession::SafeDelete
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 void CMceNatSipSession::SafeDelete( CSdpDocument* aDocument )
       
   726     {
       
   727     if ( iOffer != aDocument && iPrevOffer != aDocument )
       
   728         {
       
   729         delete aDocument;
       
   730         }
       
   731     }
       
   732 
       
   733 // -----------------------------------------------------------------------------
       
   734 // CMceNatSipSession::NatErrorOccurred
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 void CMceNatSipSession::NatErrorOccurred( TInt /*aError*/ )
       
   738     {
       
   739     MCESRV_DEBUG( "*** CMceNatSipSession::NatErrorOccurred, Entry")
       
   740 
       
   741     // Local handling
       
   742     if ( iNatStateMachine )
       
   743     	{
       
   744     	// If error occurs during creation of NatStateMachine, iNatStateMachine
       
   745     	// is NULL.
       
   746     	iNatStateMachine->ErrorOccurred();	
       
   747     	}
       
   748     
       
   749     iNatDisabled = ETrue;
       
   750     // Free resources reserved by NAT Session
       
   751     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   752     TRAP_IGNORE( manager.CloseSessionL( iSessionId ) );
       
   753     PrepareNatSessionUpdate();
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 // CMceNatSipSession::PrepareNatSessionUpdate
       
   758 // -----------------------------------------------------------------------------
       
   759 //
       
   760 void CMceNatSipSession::PrepareNatSessionUpdate()
       
   761     {
       
   762     MCESRV_DEBUG( "*** CMceNatSipSession::PrepareNatSessionUpdate, Entry" )
       
   763     
       
   764     CMceComSession* activeBody = &ActiveBody();
       
   765     if ( activeBody )
       
   766         {
       
   767 	    TBool ignorePortComparison( !iNatDisabled );
       
   768 	    RPointerArray<CMceComMediaStream>& streams = activeBody->Streams();
       
   769 	    for ( TInt i = 0; i < streams.Count(); i++ )
       
   770 	        {
       
   771 	        CMceComMediaStream* stream = streams[ i ];
       
   772 	        stream->SetIgnoreRemotePort( ignorePortComparison );
       
   773 	        if ( stream->BoundStream() )
       
   774 	            {
       
   775 	            stream->iLinkedStream->SetIgnoreRemotePort(
       
   776 	            	ignorePortComparison );
       
   777 	            }
       
   778 	        }
       
   779         }
       
   780     
       
   781     MCESRV_DEBUG( "*** CMceNatSipSession::PrepareNatSessionUpdate, Exit" )
       
   782     }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CMceNatSipSession::SetMediaQosL
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 void CMceNatSipSession::SetMediaQosL()
       
   789     {
       
   790     CMceComSession* activeBody = &ActiveBody();
       
   791     __ASSERT_ALWAYS( activeBody, User::Leave( KErrTotalLossOfPrecision ) );
       
   792     
       
   793     CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   794     User::LeaveIfError( manager.SetSessionParam( iSessionId, 
       
   795         CNSPPlugin::ENSPMediaTypeOfServiceKey,
       
   796         activeBody->iServiceType ) );
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CMceNatSipSession::SetNeedtoReceive 
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 void CMceNatSipSession::SetNeedtoReceive()
       
   804 	{
       
   805 	MCESRV_DEBUG( "*** CMceNatSipSession::SetNeedtoReceive, Entry" )	
       
   806 	iForceSDPSending = ETrue;
       
   807 	MCESRV_DEBUG( "*** CMceNatSipSession::SetNeedtoReceive, Exit" )		
       
   808 	}
       
   809 
       
   810 // -----------------------------------------------------------------------------
       
   811 // CMceNatSipSession::GetResourceReservationStatus 
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 TInt CMceNatSipSession::GetResourceReservationStatus()
       
   815 	{
       
   816 	MCESRV_DEBUG( "*** CMceNatSipSession::GetResourceReservationStatus, Entry" )	
       
   817 
       
   818 	CMceNatPluginManager& manager = Manager().MediaManager().NatPluginManager();
       
   819     TUint status = manager.GetSessionParam( iSessionId,
       
   820     							CNSPPlugin::ENSPResourseReservationStatusKey );
       
   821 
       
   822 	MCESRV_DEBUG( "*** CMceNatSipSession::GetResourceReservationStatus, Exit" )		
       
   823 	return status;
       
   824 	}
       
   825 
       
   826 // -----------------------------------------------------------------------------
       
   827 // CMceNatSipSession::GetReservationStatus 
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 TMceReturnStatus CMceNatSipSession::GetReservationStatus()
       
   831 	{
       
   832 	return iReserveStatus;
       
   833 	}
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // CMceNatSipSession::SetReservationStatus 
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 void CMceNatSipSession::SetReservationStatus( TMceReturnStatus aStatus )
       
   840 	{
       
   841 	iReserveStatus = aStatus;
       
   842 	}
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // CMceNatSipSession::ResumeNatUpdated
       
   846 // -----------------------------------------------------------------------------
       
   847 //
       
   848 void CMceNatSipSession::ResumeNatUpdated()
       
   849 	{
       
   850 	MCESRV_DEBUG( "*** CMceNatSipSession::ResumeNatUpdated, Entry" )
       
   851 
       
   852 	if( !iNatDisabled )
       
   853         {
       
   854 		TMceNatStateTransitionEvent event( NULL, *this, EMceNatUpdated, *this,
       
   855 										   iSipEvent );
       
   856         iEntryPoint = ENatEntryUpdated;
       
   857         // iComSession was already set in UpdateMediaL() or Updated()
       
   858         event.ParamStatus() = KMceAsync;
       
   859 
       
   860         TRAPD( error, iNatStateMachine->ProcessL( event ) );
       
   861 		if ( error != KErrNone )
       
   862             {
       
   863             iEntryPoint = ENatEntryNone;
       
   864             CMceSipSession::Updated( ActiveBody() );
       
   865             NatErrorOccurred( error );
       
   866             }
       
   867 		}
       
   868     else
       
   869     	{
       
   870         CMceSipSession::Updated( ActiveBody() );
       
   871         }
       
   872 
       
   873 	MCESRV_DEBUG( "*** CMceNatSipSession::ResumeNatUpdated, Exit" )
       
   874 	}
       
   875 
       
   876 // End of File