multimediacommsengine/mmcesrv/mmceserver/src/mcesipsession.cpp
changeset 0 1bce908db942
child 3 513a8b745b2f
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 
       
    21 #include <sipinvitedialogassoc.h>
       
    22 #include <sipprofile.h>
       
    23 #include <sdpdocument.h>
       
    24 #include <siptoheader.h>
       
    25 #include <sipdialog.h>
       
    26 #include <sipcontactheader.h>
       
    27 #include "mcesipsession.h"
       
    28 #include "mcecssession.h"
       
    29 #include "mceservercore.h"
       
    30 #include "fcpluginengine.h"
       
    31 #include "mcesipconnection.h"
       
    32 #include "mcesipstatemachine.h"
       
    33 #include "mcestate.h"
       
    34 #include "mceactionset.h"
       
    35 #include "mcefcactionset.h"
       
    36 #include "mceclient.pan"
       
    37 #include "mcesrvlogs.h"
       
    38 #include "mcecomsession.h"
       
    39 #include "mcecomaudiocodec.h"
       
    40 #include "mcesipextensions.h"
       
    41 #include "mcereliablesender.h" 
       
    42 #include "mcemediamanager.h"
       
    43 #include "mcesdpsession.h"
       
    44 #include "mcetimermanager.h"
       
    45 #include "mcemediastate.h"
       
    46 
       
    47 #define MCE_IGNORE_MEDIA_ERROR ( ( defined __WINSCW__ ) || ( defined __WINS__ ) )\
       
    48                             && ( !defined MCESRV_UNIT_TESTING ) 
       
    49     
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMceSipSession::NewL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMceSipSession* CMceSipSession::NewL( CMceCsSession& aClientSession, 
       
    55                                       CMceSipConnection& aSIPConnection,
       
    56 								      CMceSipStateMachine& aStateMachine,
       
    57 								      CSIPProfile& aProfile )
       
    58 	{
       
    59     CMceSipSession* self = CMceSipSession::NewLC( aClientSession, 
       
    60                                                   aSIPConnection, 
       
    61                                                   aStateMachine,
       
    62                                                   aProfile );
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMceSipSession::NewLC
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CMceSipSession* CMceSipSession::NewLC ( CMceCsSession& aClientSession, 
       
    72                                         CMceSipConnection& aSIPConnection,
       
    73  								        CMceSipStateMachine& aStateMachine,
       
    74  								        CSIPProfile& aProfile )
       
    75 	{
       
    76     CMceSipSession* self = new (ELeave) CMceSipSession( aClientSession, 
       
    77                                                         aSIPConnection, 
       
    78                                                         aStateMachine,
       
    79                                                         aProfile );
       
    80     CleanupStack::PushL(self);
       
    81     self->ConstructL( aClientSession );
       
    82     return self;
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CMceSipSession::NewLC
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CMceSipSession* CMceSipSession::NewLC ( CMceCsSession& aClientSession, 
       
    90                                         CMceSipConnection& aSIPConnection,
       
    91  								        CMceSipStateMachine& aStateMachine )
       
    92 	{
       
    93     CMceSipSession* self = new (ELeave) CMceSipSession( aClientSession, 
       
    94                                                         aSIPConnection, 
       
    95                                                         aStateMachine );
       
    96     CleanupStack::PushL(self);
       
    97     self->ConstructL( aClientSession );
       
    98     return self;
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMceSipSession::CMceSipSession
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CMceSipSession::CMceSipSession ( CMceCsSession& aClientSession, 
       
   106 								 CMceSipConnection& aSIPConnection,
       
   107 								 CMceSipStateMachine& aStateMachine,
       
   108 								 CSIPProfile& aProfile )
       
   109 : CMceCsSubSession( KMceCSSIPSession, aClientSession, aSIPConnection, \
       
   110 					aProfile ),
       
   111   iStateMachine( &aStateMachine ),
       
   112   iSubState( ENone ),
       
   113   iUseFC( EFalse )
       
   114 	{
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CMceSipSession::CMceSipSession
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 CMceSipSession::CMceSipSession ( CMceCsSession& aClientSession, 
       
   122 								 CMceSipConnection& aSIPConnection,
       
   123 								 CMceSipStateMachine& aStateMachine )
       
   124 : CMceCsSubSession( KMceCSSIPSession, aClientSession, aSIPConnection ),
       
   125   iStateMachine( &aStateMachine ),
       
   126   iSubState( ENone ),
       
   127   iUseFC( EFalse )
       
   128 	{
       
   129 	}
       
   130 	
       
   131 	
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMceSipSession::ConstructL
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CMceSipSession::ConstructL ( CMceCsSession& aClientSession )
       
   137 	{
       
   138     MCESRV_DEBUG("CMceSipSession::ConstructL, Entry");
       
   139 	
       
   140 	CMceCsSubSession::ConstructL( aClientSession );
       
   141 	
       
   142 	iTimer = CMceTimerManager::KNoSuchTimer;
       
   143 	
       
   144 	iPendingTimer = CMceTimerManager::KNoSuchTimer;
       
   145 	
       
   146 	iCurrentState = &iStateMachine->State( KMceStateIdle );
       
   147 
       
   148     iExtensions= CMceSipExtensions::NewL();
       
   149     
       
   150     iReliableSender = CMceReliableSender::NewL( *this );
       
   151     
       
   152     iRSeq = KErrNone;
       
   153     
       
   154     iPreviousState = KMceStateIdle;
       
   155     
       
   156     iForceSDPSending = EFalse;
       
   157     
       
   158     iNatSession = EFalse;
       
   159                 		
       
   160     MCESRV_DEBUG("CMceSipSession::ConstructL, Exit");
       
   161 	}
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CMceSipSession::~CMceSipSession
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 CMceSipSession::~CMceSipSession()
       
   168 	{
       
   169     MCESRV_DEBUG("CMceSipSession::~CMceSipSession, Entry");
       
   170     
       
   171     CloseMedia( ETrue );
       
   172     CMceComSession::Delete( iNewBodyCandidate, Manager().MediaManager() );
       
   173     
       
   174     PrevOfferSafeDelete();	
       
   175 
       
   176 	delete iOffer;
       
   177     Manager().TimerManager().Stop( iTimer );
       
   178 	
       
   179 	if ( iFCSession )
       
   180 		{
       
   181 		ServerCore().DeregisterFCSession( *this, *iFCSession );	 
       
   182 		ServerCore().FCPluginEngine().ReleaseSession( *iFCSession); 
       
   183 		}
       
   184 	iForkedDialogs.ResetAndDestroy(); 
       
   185 	delete iMediaAuthorizationToken;
       
   186 	delete iExtensions;
       
   187 	delete iReliableSender;
       
   188 	iRemoteUri.ResetAndDestroy();
       
   189 
       
   190     MCESRV_DEBUG("CMceSipSession::~CMceSipSession, Exit");
       
   191   	}
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CMceSipSession::CloseMedia         
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CMceSipSession::CloseMedia( TBool aDelete )
       
   198 	{
       
   199     MCESRV_DEBUG("CMceSipSession::CloseMedia, Entry");
       
   200 
       
   201     if ( aDelete )
       
   202         {
       
   203         CMceComSession::Delete( iBody, Manager().MediaManager() );
       
   204         }
       
   205     else
       
   206         {
       
   207         Manager().MediaManager().CloseSession( *iBody );
       
   208         }
       
   209 
       
   210     CloseBodyBucket();
       
   211     
       
   212     MCESRV_DEBUG("CMceSipSession::CloseMedia, Exit");
       
   213 	}
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CMceSipSession::CloseBodyBucket         
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CMceSipSession::CloseBodyBucket()
       
   220 	{
       
   221     MCESRV_DEBUG("CMceSipSession::CloseBodyBucket, Entry");
       
   222 	
       
   223     while( iBodyBucket.Count() > 0 )
       
   224         {
       
   225         CMceComSession* body = iBodyBucket[ 0 ];
       
   226         if ( &body->SdpSession() )
       
   227             {
       
   228             body->SdpSession().AttachContext( NULL );
       
   229             }
       
   230         CMceComSession::Delete( body, Manager().MediaManager() );
       
   231         iBodyBucket.Remove( 0 );
       
   232         }
       
   233     
       
   234     iBodyBucket.ResetAndDestroy();
       
   235     
       
   236     MCESRV_DEBUG("CMceSipSession::CloseBodyBucket, Exit");
       
   237 	}
       
   238 	
       
   239 // -----------------------------------------------------------------------------
       
   240 // CMceSipSession::ReliableSender         
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 CMceReliableSender& CMceSipSession::ReliableSender()
       
   244     {
       
   245     return *iReliableSender;
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CMceSipSession::DoInitializeIncomingDialogL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CMceSipSession::DoInitializeIncomingDialogL( 
       
   253     CSIPServerTransaction& /*aTransaction*/ )
       
   254     {
       
   255     MCESRV_DEBUG("CMceSipSession::DoInitializeIncomingDialogL, Entry");
       
   256     
       
   257     FCActions().InitializeFCL();
       
   258     
       
   259     SetBodyL();
       
   260     
       
   261     MCESRV_DEBUG("DoInitializeIncomingDialogL: new session body:");
       
   262     MCESRV_DEBUG_COMSESSION( iBody );
       
   263     
       
   264     MCESRV_DEBUG("CMceSipSession::DoInitializeIncomingDialogL, Exit");    
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CMceSipSession::CanDispose
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 TBool CMceSipSession::CanDispose()
       
   272     {
       
   273     return ( CurrentState().Id() == KMceStateTerminated &&
       
   274              HasInitialInviteTransactionBeenCompleted() ); 
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CMceSipSession::Actions
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TMceActionSet CMceSipSession::Actions()
       
   282     {
       
   283     return TMceActionSet( *this );
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CMceSipSession::FCActions
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 TMceFCActionSet CMceSipSession::FCActions()
       
   291     {
       
   292     return TMceFCActionSet( *this );
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CMceSipSession::CurrentState
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 CMceState& CMceSipSession::CurrentState( TBool aMarkExit )
       
   300     {
       
   301     if ( aMarkExit )
       
   302         {
       
   303         iExitState = iCurrentState;
       
   304         }
       
   305     return *iCurrentState;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CMceSipSession::Body
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 CMceComSession* CMceSipSession::Body()
       
   313     {
       
   314     CMceComSession* body = iBody;
       
   315 
       
   316     if ( iBodyBucket.Count() > 0 )
       
   317         {
       
   318         body = &iBody->SdpSession() && iBody->SdpSession().Context() == Dialog() ? 
       
   319                iBody : NULL;
       
   320         TInt index = 0;
       
   321         while( !body && index < iBodyBucket.Count() )
       
   322             {
       
   323             body = iBodyBucket[ index++ ];
       
   324             body = &body->SdpSession() && body->SdpSession().Context() == Dialog() ? body : NULL;
       
   325             }
       
   326 
       
   327         body = !body ? iBody : body;
       
   328         
       
   329         }
       
   330     
       
   331     return body;    
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CMceSipSession::BodyCandidate
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 CMceComSession* CMceSipSession::BodyCandidate()
       
   339     {
       
   340     return iNewBodyCandidate;
       
   341     }
       
   342     
       
   343 // -----------------------------------------------------------------------------
       
   344 // CMceSipSession::SetOffer
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CMceSipSession::SetOffer( CSdpDocument* aSdpDocument )
       
   348     {
       
   349     if ( aSdpDocument != iOffer )
       
   350         {
       
   351         delete iOffer;
       
   352         iOffer = aSdpDocument;
       
   353         }
       
   354     }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CMceSipSession::Offer
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 CSdpDocument* CMceSipSession::Offer()
       
   361     {
       
   362     return iOffer;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CMceSipSession::SetPrevOffer
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CMceSipSession::SetPrevOffer( CSdpDocument* aSdpDocument )
       
   370     {
       
   371     if ( aSdpDocument != iPrevOffer )
       
   372         {
       
   373         PrevOfferSafeDelete();
       
   374         iPrevOffer = aSdpDocument;
       
   375         }
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CMceSipSession::PrevOffer
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 CSdpDocument* CMceSipSession::PrevOffer()
       
   383     {
       
   384     return iPrevOffer;
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CMceSipSession::StorePrevOffer
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CMceSipSession::StorePrevOffer()
       
   392     {
       
   393     MCESRV_DEBUG( "*** CMceSipSession::StorePrevOfferL, Entry" );
       
   394     
       
   395     // If refreshing, existing prev offer is going to be taken in use and
       
   396     // we don't want to override it with offer.
       
   397     if ( iOffer && SubState() != ERefreshing )
       
   398         {
       
   399         MCESRV_DEBUG( "*** CMceSipSession::StorePrevOfferL, Copy" );
       
   400         CSdpDocument* clonedOffer = NULL;
       
   401         TRAP_IGNORE( ( clonedOffer = iOffer->CloneL() ) );
       
   402         SetPrevOffer( clonedOffer );
       
   403         }
       
   404     
       
   405     MCESRV_DEBUG( "*** CMceSipSession::StorePrevOfferL, Exit" ); 
       
   406     }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // CMceSipSession::IncrementSentSdpCount
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CMceSipSession::IncrementSentSdpCount()
       
   413     {
       
   414     iSentSdpCount++;
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CMceSipSession::IncrementReceivedSdpCount
       
   419 // -----------------------------------------------------------------------------
       
   420 //   
       
   421 void CMceSipSession::IncrementReceivedSdpCount()
       
   422     {
       
   423     iReceivedSdpCount++;
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CMceSipSession::ResetSdpCounts
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CMceSipSession::ResetSdpCounts()
       
   431     {
       
   432     iSentSdpCount = 0;
       
   433     iReceivedSdpCount = 0; 
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CMceSipSession::DoesMediaManagerNeedToNegotiate
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TBool CMceSipSession::DoesMediaManagerNeedToNegotiate( 
       
   441     CSdpDocument* aSdpDocument )
       
   442     {
       
   443     CMceMediaManager& mediaManager = Manager().MediaManager();
       
   444     return mediaManager.NeedToNegotiate( ActiveBody(), aSdpDocument );
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CMceSipSession::NatSession
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TBool CMceSipSession::NatSession() const
       
   452     {
       
   453     return EFalse;
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // CMceSipSession::NatState
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 TInt CMceSipSession::NatState() const
       
   461     {
       
   462     return KErrNotFound;
       
   463     }
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CMceSipSession::IsNatDisabled
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 TBool CMceSipSession::IsNatDisabled() const
       
   470 	{
       
   471 	return EFalse;
       
   472 	}
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CMceSipSession::StartSessionTimerL
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CMceSipSession::StartSessionTimerL()
       
   479     {
       
   480     MCESRV_DEBUG("CMceSipSession::StartSessionTimerL, Entry");
       
   481     
       
   482     const TUint KTwo = 2;
       
   483     
       
   484     CMceTimerManager& timerManager = Manager().TimerManager();
       
   485     
       
   486     if( iBody->iTimeout > 0 )
       
   487     	{
       
   488     	TUint32 interval;
       
   489     	
       
   490 	    if( iBody->iRefresh )
       
   491 	    	{
       
   492 	    	// if this end should perform refreshes then the reccommended
       
   493 	    	// time is half the session interval
       
   494 	    	interval = ( iBody->iTimeout * KMceSecToMillisec ) / KTwo;
       
   495 	    	}
       
   496 	    else
       
   497 	    	{
       
   498 	    	// the other end is performing refreshes, so set the timeout
       
   499 	    	// to full session interval and send bye in case of no refresh
       
   500 	    	interval = iBody->iTimeout * KMceSecToMillisec;
       
   501 	    	}
       
   502 
       
   503         if ( timerManager.IsRunning( iTimer ) )
       
   504             {
       
   505     		timerManager.Stop( iTimer );
       
   506             }
       
   507             
       
   508         iTimer = timerManager.StartL( this, interval );
       
   509         }
       
   510     MCESRV_DEBUG("CMceSipSession::StartSessionTimerL, Exit");
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CMceSipSession::StartPendingTimerL
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CMceSipSession::StartPendingTimerL( TUint aInterval )
       
   518     {
       
   519     MCESRV_DEBUG("CMceSipSession::StartPendingTimerL, Entry");
       
   520     
       
   521     CMceTimerManager& timerManager = Manager().TimerManager();
       
   522     
       
   523     iPendingTimer = timerManager.StartL( this, aInterval );
       
   524     
       
   525     MCESRV_DEBUG("CMceSipSession::StartPendingTimerL, Exit");
       
   526     }
       
   527     
       
   528 // -----------------------------------------------------------------------------
       
   529 // CMceSipSession::NextState
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 void CMceSipSession::NextState( TUint aNextStateId )
       
   533     {
       
   534     MCESRV_DEBUG("CMceSipSession::NextState, Entry");
       
   535     
       
   536     iPreviousState = iCurrentState->Id();
       
   537     
       
   538     MCESRV_DEBUG_STATE("old state", iPreviousState );
       
   539     MCESRV_DEBUG_STATE("new state", aNextStateId );
       
   540     
       
   541     ClearRemoteUri( aNextStateId );
       
   542     iCurrentState = &iStateMachine->State( aNextStateId );
       
   543     
       
   544     // Automatic event generation
       
   545     //
       
   546     TMceStateTransitionEvent* autoEvent = StoredAutoEvent();
       
   547     if ( AutoEvent() && autoEvent && iCurrentlyProcessedAutoEvent != autoEvent )
       
   548         {
       
   549         // Remember what event is processed at the moment in order to avoid
       
   550         // multiple generations of same event if nested state changes occur.
       
   551         iCurrentlyProcessedAutoEvent = autoEvent;
       
   552         
       
   553         TRAPD( err, DoAutoEventL( *autoEvent ) );
       
   554         if ( err )
       
   555             {
       
   556             MCESRV_DEBUG("CMceSipSession::NextState, automatic event failed");
       
   557             err++;
       
   558             }
       
   559             
       
   560         // Do it just once
       
   561         SetAutoEvent( EFalse );
       
   562         iCurrentlyProcessedAutoEvent = NULL;
       
   563         }
       
   564 
       
   565     MCESRV_DEBUG("CMceSipSession::NextState, Exit");
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CMceSipSession::MethodCode
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 TMceSipEventCode CMceSipSession::MethodCode( RStringF method )
       
   573     {
       
   574     TMceSipEventCode eventCode = (TMceSipEventCode)KErrNotFound;
       
   575     
       
   576     if ( method == SIPStrings::StringF( SipStrConsts::EInvite ) )
       
   577         {
       
   578         eventCode = EMceInvite;
       
   579         }
       
   580     else if ( method == SIPStrings::StringF( SipStrConsts::ECancel ) )
       
   581         {
       
   582         eventCode = EMceCancel;
       
   583         }
       
   584     else if ( method == SIPStrings::StringF( SipStrConsts::EAck ) )
       
   585         {
       
   586         eventCode = EMceAck;
       
   587         }
       
   588     else if ( method == SIPStrings::StringF( SipStrConsts::EBye ) )
       
   589         {
       
   590         eventCode = EMceBye;
       
   591         }
       
   592     else if ( method == SIPStrings::StringF( SipStrConsts::EPrack ) )
       
   593         {
       
   594         eventCode = EMcePrack;
       
   595         }
       
   596     else if ( method == SIPStrings::StringF( SipStrConsts::EUpdate ) )
       
   597         {
       
   598         eventCode = EMceUpdate;
       
   599         }
       
   600     else if ( Actions().IsExtensionRequest( method ))
       
   601     	{
       
   602     	eventCode = EMceRequest;	
       
   603     	}
       
   604     return eventCode;
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CMceSipSession::ActiveBody
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 CMceComSession& CMceSipSession::ActiveBody()
       
   612     {
       
   613     TSubState subState = SubState();
       
   614     
       
   615     CMceComSession* body = NULL;
       
   616     
       
   617     if ( subState != EUpdating )
       
   618         {
       
   619         body = Body();
       
   620         }
       
   621     else
       
   622         {
       
   623         // If session is already accepted/rejected, body candidate does not
       
   624         // exist anymore but the session is still in updating substate.
       
   625         body = BodyCandidate() ? BodyCandidate() : Body();
       
   626         }
       
   627         
       
   628     return *body;
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // CMceSipSession::UpdateMediaL
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 TMceReturnStatus CMceSipSession::UpdateMediaL()
       
   636     {
       
   637     MCESRV_DEBUG("CMceSipSession::UpdateMediaL, Entry");
       
   638 
       
   639     TMceReturnStatus status = Manager().MediaManager().UpdateL( ActiveBody() );
       
   640     
       
   641     TUint signallingTos = ActiveBody().Modifier( KMceSignallingTypeOfService );
       
   642     if ( signallingTos != KMaxTUint16 )
       
   643         {
       
   644         SIPConnection().UpdateConnectionL( signallingTos );
       
   645         }
       
   646     
       
   647     MCESRV_DEBUG("CMceSipSession::UpdateMediaL, Exit");
       
   648     
       
   649     return status;
       
   650     }
       
   651         
       
   652 // -----------------------------------------------------------------------------
       
   653 // CMceSipSession::ReserveL
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 TMceReturnStatus CMceSipSession::ReserveL()
       
   657     {
       
   658     MCESRV_DEBUG("CMceSipSession::ReserveL, Entry");
       
   659     
       
   660     TMceReturnStatus status = KMceReady;
       
   661     HBufC8* token = MediaAuthorizationToken();
       
   662     if ( token )
       
   663         {
       
   664         // session has received a media authorization token    
       
   665         CMceMediaManager& mediaManager = Manager().MediaManager();   
       
   666         status = mediaManager.ReserveL( ActiveBody(), *token );
       
   667         }
       
   668     
       
   669     MCESRV_DEBUG_DVALUE( "ReserveL: status", status);
       
   670         
       
   671     MCESRV_DEBUG("CMceSipSession::ReserveL, Exit");
       
   672     
       
   673     return status;
       
   674     }
       
   675 
       
   676 // -----------------------------------------------------------------------------
       
   677 // CMceSipSession::NeedToSend
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 TBool CMceSipSession::NeedToSend( CSdpDocument* aSdpDocument )
       
   681     {
       
   682     MCESRV_DEBUG( "CMceSipSession::NeedToSend, Entry" )
       
   683 	
       
   684 	CMceMediaManager& mediaManager = Manager().MediaManager();
       
   685 
       
   686     TBool needToSend = 
       
   687         ( DoesMediaManagerNeedToNegotiate( aSdpDocument ) || 
       
   688           (( iSentSdpCount < iReceivedSdpCount ) && 
       
   689           	( mediaManager.GetRole( ActiveBody()) == EMceRoleAnswerer )));
       
   690      
       
   691     MCESRV_DEBUG_DVALUE( "CMceSipSession::NeedToSend, Exit", needToSend )
       
   692     
       
   693     return needToSend;
       
   694     }
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // CMceSipSession::NeedToReceive
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 TBool CMceSipSession::NeedToReceive()
       
   701     {
       
   702     MCESRV_DEBUG( "CMceSipSession::NeedToReceive, Entry" );
       
   703     
       
   704     CMceMediaManager& mediaManager = Manager().MediaManager();
       
   705     TBool confirmationNeeded = mediaManager.ConfirmationNeeded( ActiveBody() );
       
   706     
       
   707     MCESRV_DEBUG( "CMceSipSession::NeedToReceive, Exit" );
       
   708     
       
   709     return confirmationNeeded;
       
   710     }
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CMceSipSession::AcceptMethod
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 TBool CMceSipSession::AcceptMethod( RStringF aMethod )
       
   717     {
       
   718     return MethodCode( aMethod ) != (TMceSipEventCode)KErrNotFound;
       
   719     }
       
   720 
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CMceSipSession::RequestReceived
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CMceSipSession::RequestReceived( TBool aInsideDialog, CSIPDialog& aDialog  )
       
   727     {
       
   728     MCESRV_DEBUG("CMceSipSession::RequestReceived, Entry");
       
   729     
       
   730     if ( Request().Type() == SIPStrings::StringF( SipStrConsts::EInvite ) )
       
   731         {
       
   732         MCESRV_DEBUG("CMceSipSession::RequestReceived, invite");
       
   733         if ( aInsideDialog && iCurrentState->Id() == KMceStateAnswering )
       
   734             {
       
   735             MCESRV_DEBUG("CMceSipSession::RequestReceived, ack missing, fake it");
       
   736             
       
   737             HandleSIPEvent( EMceAck, aDialog ); 
       
   738             }
       
   739         else if ( iCurrentState->Id() != KMceStateEstablished && 
       
   740                   iCurrentState->Id() != KMceStateIdle )
       
   741             {
       
   742             
       
   743             MCESRV_DEBUG("there is pending request");
       
   744             // Send 491
       
   745             MceSip::DiscardRequest( Request(), KMceSipRequestPending );
       
   746             delete PopRequest();
       
   747             return;
       
   748             }
       
   749         else
       
   750             {
       
   751             // NOP
       
   752             }
       
   753         }
       
   754         
       
   755     MCESRV_DEBUG("Handle new request");
       
   756     TMceSipEventCode eventCode = MethodCode( MceSip::Method( Request() ) );
       
   757     
       
   758     HandleSIPEvent( eventCode, aDialog );
       
   759     
       
   760     MCESRV_DEBUG("CMceSipSession::RequestReceived, Exit");
       
   761     }
       
   762 
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CMceSipSession::HandleSIPEvent
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 void CMceSipSession::HandleSIPEvent( TMceSipEventCode aEventCode, CSIPDialog& aDialog )
       
   769     {
       
   770     MCESRV_DEBUG("CMceSipSession::HandleSIPEvent, Entry");
       
   771     
       
   772     if ( Body() && &Body()->SdpSession() )
       
   773         {
       
   774         Body()->SdpSession().AttachContext( Dialog() );
       
   775         }
       
   776 
       
   777     TMceStateTransitionEvent event( *this, aEventCode, aDialog );
       
   778     
       
   779     if ( iStateMachine->Consumes( event ) )
       
   780         {
       
   781         TRAPD( error, iStateMachine->ProcessL( event ) );
       
   782         if ( error != KErrNone )
       
   783             {
       
   784             MCESRV_DEBUG_DVALUE(
       
   785                 "HandleSIPEvent: state machine causes ERROR", error );
       
   786              
       
   787             TRAPD( handleError, HandleSIPEventErrorL( aEventCode, error ) );
       
   788             if ( handleError != KErrNone )
       
   789                 {
       
   790                 LocalErrorOccured( KMceStateError, error );
       
   791                 }
       
   792             }
       
   793         }
       
   794     else
       
   795         {
       
   796         MceSip::DiscardRequest( Request(), KMceSipNotImplemented );
       
   797         }
       
   798         
       
   799     MCESRV_DEBUG("CMceSipSession::HandleSIPEvent, Exit");
       
   800     }
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // CMceSipSession::HandleSIPEventErrorL
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 void CMceSipSession::HandleSIPEventErrorL( TMceSipEventCode aEventCode,
       
   807                                            TInt aError )
       
   808     {
       
   809     switch( aEventCode )
       
   810         {
       
   811         case EMceProvisionalResponse:
       
   812         case EMceRedirectionResponse:
       
   813         case EMceResponse:
       
   814         case EMceErrorResponse:
       
   815             { 
       
   816             if ( SubState() == EUpdating )
       
   817                 {
       
   818                 Actions().StopUpdatingMedia();
       
   819                 Actions().UpdateFailed(); 
       
   820                 Actions().StateChanged( KMceStateEstablished );
       
   821                 Actions().ClientStateChangedL( CMceSession::EEstablished, *iBody, aError );                               
       
   822                 }
       
   823             else
       
   824                 {
       
   825                 Actions().StopMedia();
       
   826                 FCActions().ReleaseFC();
       
   827                 CSIPDialog::TState dialogState = Dialog()->Dialog().State();
       
   828                 if ( dialogState == CSIPDialog::EConfirmed )
       
   829                     {
       
   830                     // ACK is already sent, terminate session with BYE
       
   831                     Actions().SendBYEL();
       
   832                     Actions().StateChanged( KMceStateTerminating );
       
   833                     Actions().ClientStateChangedL( CMceSession::ETerminating );                
       
   834                     }
       
   835                 else if ( dialogState == CSIPDialog::EEarly )
       
   836                     {
       
   837                     Actions().SendCancelL();
       
   838                     Actions().StateChanged( KMceStateCanceled );
       
   839                     Actions().ClientStateChangedL( CMceSession::ECancelling );                
       
   840                     }
       
   841                 // for 3xx response error situation
       
   842                 else if ( dialogState == CSIPDialog::ETerminated )
       
   843                     {
       
   844                     Actions().StateChanged( KMceStateTerminated );
       
   845                     Actions().ClientStateChangedL( 
       
   846                         CMceSession::ETerminated, *Body(), Response() );                         
       
   847                     }
       
   848                 else
       
   849                     {
       
   850                     // NOP
       
   851                     }   
       
   852                 }
       
   853             
       
   854             break;
       
   855             }
       
   856         default:
       
   857             {
       
   858             if ( aError == KErrTotalLossOfPrecision )
       
   859                 {
       
   860                 // unexpected request is rejected, but does not
       
   861                 // affect on session.
       
   862                 if ( Request().Type() == SIPStrings::StringF( 
       
   863                     SipStrConsts::EPrack ) )
       
   864                     {
       
   865                     // unexpected PRACK
       
   866                     MceSip::DiscardRequest( Request(), 
       
   867                         KMceSipCallOrTransactionDoesNotExist );
       
   868                     }
       
   869                 else
       
   870                     {
       
   871                     // Default handling for other methods
       
   872                     MceSip::DiscardRequest( Request() );
       
   873                     }
       
   874                 }
       
   875             else
       
   876                 {
       
   877                 Actions().StopMedia();
       
   878                 FCActions().ReleaseFC();
       
   879             
       
   880                 // other errors cause session to be terminated
       
   881                 MceSip::DiscardRequest( Request(), aError );
       
   882                 if ( aEventCode == EMcePrack || 
       
   883                      aEventCode == EMceUpdate )
       
   884                     {
       
   885                     //reject also invite
       
   886                     DiscardInvite();
       
   887                     }
       
   888                 CSIPDialog::TState dialogState = Dialog()->Dialog().State();
       
   889                 if ( dialogState == CSIPDialog::EConfirmed )
       
   890                     {
       
   891                     // terminate established session with BYE
       
   892                     Actions().SendBYEL();
       
   893                     Actions().StateChanged( KMceStateTerminating );
       
   894                     Actions().ClientStateChangedL( CMceSession::ETerminating );                
       
   895                     }
       
   896                 else
       
   897                     {
       
   898                     Actions().StateChanged( KMceStateTerminated );
       
   899                     Actions().ClientStateChangedL( CMceSession::ETerminated );
       
   900                     }
       
   901                 }
       
   902             break;
       
   903             }
       
   904         }
       
   905     }
       
   906 
       
   907 // -----------------------------------------------------------------------------
       
   908 // CMceSipSession::SdpCleanup
       
   909 // -----------------------------------------------------------------------------
       
   910 //
       
   911 void CMceSipSession::SdpCleanup( CSdpDocument* aPrevious, CSdpDocument* aReplacement )
       
   912     {   
       
   913     if ( iBody )
       
   914         {
       
   915         iBody->SdpCleanup( aPrevious, aReplacement );
       
   916         }
       
   917         
       
   918     if ( iNewBodyCandidate )
       
   919         {
       
   920         iNewBodyCandidate->SdpCleanup( aPrevious, aReplacement );
       
   921         }
       
   922     }
       
   923     
       
   924 // -----------------------------------------------------------------------------
       
   925 // CMceSipSession::CreateIncomingDialogL
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 CSIPDialogAssocBase* CMceSipSession::CreateIncomingDialogL( 
       
   929     CSIPServerTransaction& aInitialRequest )
       
   930     {
       
   931     MCESRV_DEBUG("CMceSipSession::CreateIncomingDialogL, Entry");
       
   932     __ASSERT_ALWAYS( ProfileConfigured(), User::Leave( KErrArgument ) );
       
   933         
       
   934     CSIPInviteDialogAssoc* dialog = 
       
   935             CSIPInviteDialogAssoc::NewL( aInitialRequest, Profile() );
       
   936         
       
   937     MCESRV_DEBUG("CMceSipSession::CreateIncomingDialogL, Exit");
       
   938     
       
   939     return dialog;
       
   940     }
       
   941 
       
   942 // -----------------------------------------------------------------------------
       
   943 // CMceSipSession::CreateOutgoingDialogL
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 CSIPDialogAssocBase* CMceSipSession::CreateOutgoingDialogL( 
       
   947                                                     TMceDialogType aDialogType,
       
   948                                                     CDesC8Array& /*aParams*/,
       
   949                                                     CSIPDialog& aExistingDialog )
       
   950     {
       
   951     MCESRV_DEBUG("CMceSipSession::CreateOutgoingDialogL( existing dlg ), Entry");
       
   952     
       
   953     __ASSERT_ALWAYS( aDialogType == KMceDlgTypeInvite, User::Leave( KErrArgument ) );
       
   954     
       
   955     
       
   956     CSIPInviteDialogAssoc* dialog = 
       
   957         CSIPInviteDialogAssoc::NewL( aExistingDialog );
       
   958         
       
   959     MCESRV_DEBUG("CMceSipSession::CreateOutgoingDialogL( existing dlg ), Exit");
       
   960     
       
   961     return dialog;   
       
   962     }
       
   963 
       
   964 // -----------------------------------------------------------------------------
       
   965 // CMceSipSession::CreateOutgoingDialogL
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 CSIPDialogAssocBase* CMceSipSession::CreateOutgoingDialogL( 
       
   969                                                     TMceDialogType aDialogType,
       
   970                                                     CDesC8Array& aParams )
       
   971     {
       
   972     MCESRV_DEBUG("CMceSipSession::CreateOutgoingDialogL( new dlg ), Entry");
       
   973     
       
   974     __ASSERT_ALWAYS( aDialogType == KMceDlgTypeInvite, 
       
   975         User::Leave( KErrArgument ) );
       
   976 
       
   977 	CSIPInviteDialogAssoc* inviteDialog = NULL;   
       
   978     CSIPConnection& connection = SIPConnection().Connection();
       
   979     if ( ProfileConfigured() )
       
   980 	    {
       
   981 	    const CSIPProfile& profile = Profile();
       
   982 		TPtrC8 originator = aParams.MdcaPoint( KMceArrayIndexOriginator );
       
   983 	    TPtrC8 recipient  = aParams.MdcaPoint( KMceArrayIndexRecipient );
       
   984 	    CSIPToHeader* toHeader = CSIPToHeader::DecodeL( recipient );
       
   985 	    CleanupStack::PushL( toHeader );
       
   986 	    CUri8* remoteUri = CUri8::NewLC( toHeader->SIPAddress().Uri8().Uri() );
       
   987 	    
       
   988 	    // create targetset with remoteUri of the request
       
   989 	    AddRemoteUriL( *remoteUri );
       
   990 	    CSIPFromHeader* fromHeader = NULL;
       
   991 	    if ( originator.Length() > 0 )
       
   992 	        {
       
   993 	        fromHeader = MceSip::ToFromHeaderL( originator );
       
   994 	        CleanupStack::PushL( fromHeader );
       
   995 	        }
       
   996 
       
   997 	    //create dialog
       
   998 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: originator",originator);
       
   999 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: recipient",recipient);
       
  1000 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: remote uri",
       
  1001 	        remoteUri->Uri().UriDes() );
       
  1002 	    
       
  1003 	    inviteDialog = 
       
  1004 	      CSIPInviteDialogAssoc::NewL( connection, 
       
  1005 	                                   remoteUri, 
       
  1006 	                                   profile, 
       
  1007 	                                   fromHeader, 
       
  1008 	                                   toHeader );
       
  1009 	    if ( fromHeader )
       
  1010 	        {
       
  1011 	        CleanupStack::Pop( fromHeader );
       
  1012 	        }
       
  1013 	    CleanupStack::Pop( remoteUri );
       
  1014 	    CleanupStack::Pop( toHeader );
       
  1015 	    }
       
  1016 	else
       
  1017 		{
       
  1018 		TPtrC8 originator = aParams.MdcaPoint( KMceArrayIndexOriginator );
       
  1019 	    TPtrC8 recipient  = aParams.MdcaPoint( KMceArrayIndexRecipient );
       
  1020 	    CSIPToHeader* toHeader = CSIPToHeader::DecodeL( recipient );
       
  1021 	    CleanupStack::PushL( toHeader );
       
  1022 	    CUri8* remoteUri = CUri8::NewLC( toHeader->SIPAddress().Uri8().Uri() );
       
  1023 	    
       
  1024 	    // Add remote uri of the request to an array
       
  1025 	    AddRemoteUriL( *remoteUri );
       
  1026 	    
       
  1027 	    CSIPFromHeader* fromHeader = NULL;
       
  1028 	    if ( originator.Length() > 0 )
       
  1029 	        {
       
  1030 	        fromHeader = MceSip::ToFromHeaderL( originator );
       
  1031 	        CleanupStack::PushL( fromHeader );
       
  1032 	        }
       
  1033 
       
  1034 	    //create dialog
       
  1035 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: originator",originator);
       
  1036 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: recipient",recipient);
       
  1037 	    MCESRV_DEBUG_SVALUE("CreateOutgoingDialogL: remote uri",
       
  1038 	        remoteUri->Uri().UriDes() );
       
  1039 	    
       
  1040 	    inviteDialog = 
       
  1041 	      CSIPInviteDialogAssoc::NewL( connection,
       
  1042 	      							   fromHeader, 
       
  1043 	                                   remoteUri, 
       
  1044 	                                   toHeader );
       
  1045 	    if ( fromHeader )
       
  1046 	        {
       
  1047 	        CleanupStack::Pop( fromHeader );
       
  1048 	        }
       
  1049 	    CleanupStack::Pop( remoteUri );
       
  1050 	    CleanupStack::Pop( toHeader );
       
  1051 		
       
  1052 		}    
       
  1053 	MCESRV_DEBUG("CMceSipSession::CreateOutgoingDialogL( new dlg ), Exit");
       
  1054     return inviteDialog;    
       
  1055     }
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 // CMceSipSession::ReCreateOutgoingDialogL
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 void CMceSipSession::ReCreateOutgoingDialogL()
       
  1062     {
       
  1063     RStringF tagT = SIPStrings::StringF( SipStrConsts::ETag );
       
  1064     MCESRV_DEBUG("CMceSipSession::ReCreateOutgoingDialogL, Entry");
       
  1065     CSIPClientTransaction& response = Response();
       
  1066         
       
  1067     const CSIPResponseElements* respElements = response.ResponseElements(); 
       
  1068                
       
  1069     const CSIPToHeader*  toHdr  = respElements->ToHeader();
       
  1070       
       
  1071     CSIPToHeader* newToHdr = static_cast<CSIPToHeader *>( toHdr->CloneL() );
       
  1072    
       
  1073     newToHdr->DeleteParam( tagT );
       
  1074     
       
  1075     CleanupStack::PushL( newToHdr ); 
       
  1076          
       
  1077     CUri8* remoteUri = CUri8::NewLC( toHdr->SIPAddress().Uri8().Uri() ); 
       
  1078     
       
  1079     CSIPInviteDialogAssoc* newSipBaseDialog = 
       
  1080         DoCreateOutgoingDialogL( remoteUri, newToHdr );
       
  1081         
       
  1082     CleanupStack::Pop( remoteUri );
       
  1083     CleanupStack::Pop( newToHdr );
       
  1084                               
       
  1085     TUint32 oldDialogId = DialogId();
       
  1086   
       
  1087     MCE_DELETE( iDialog ); 
       
  1088     SetDialog( CMceCsSubSession::EOutSession, newSipBaseDialog, oldDialogId );
       
  1089     
       
  1090     ResetInitialInvite();
       
  1091     MCESRV_DEBUG("CMceSipSession::ReCreateOutgoingDialogL, Exit");
       
  1092     }
       
  1093 
       
  1094 // -----------------------------------------------------------------------------
       
  1095 // CMceSipSession::CreateDialogFrom3XXResponseL
       
  1096 // -----------------------------------------------------------------------------
       
  1097 //
       
  1098 void CMceSipSession::CreateDialogFrom3XXResponseL()
       
  1099     {
       
  1100     MCESRV_DEBUG("CMceSipSession::CreateDialogFrom3XXResponseL, Entry");
       
  1101     TInt count = iRemoteUri.Count(); 
       
  1102     RDebug::Print( _L("CMceSipSession::CreateDialogFrom3XXResponseL, iRemoteUri.Count()= %d"), count );
       
  1103     __ASSERT_ALWAYS( count > 0, User::Leave( KErrArgument ) );
       
  1104 
       
  1105     const CUri8* nextUri = iRemoteUri[count-1]; 
       
  1106    
       
  1107     // create CSIPToHeader 
       
  1108     CSIPToHeader* newToHdr = CSIPToHeader::DecodeL( nextUri->Uri().UriDes() );
       
  1109     // remove tag    
       
  1110     RStringF tagT = SIPStrings::StringF( SipStrConsts::ETag );
       
  1111     newToHdr->DeleteParam( tagT );
       
  1112     CleanupStack::PushL( newToHdr ); 
       
  1113     
       
  1114     // create new remote uri
       
  1115     TUriParser8 uri8Parser;
       
  1116     User::LeaveIfError( uri8Parser.Parse( nextUri->Uri().UriDes() ) );
       
  1117     
       
  1118     CUri8* remoteUri = CUri8::NewLC( uri8Parser );
       
  1119     
       
  1120     // create new dialog association
       
  1121     CSIPInviteDialogAssoc* newSipBaseDialog = 
       
  1122         DoCreateOutgoingDialogL( remoteUri, newToHdr );
       
  1123         
       
  1124     CleanupStack::Pop( remoteUri );
       
  1125     CleanupStack::Pop( newToHdr );
       
  1126     
       
  1127     TUint32 oldDialogId = DialogId();
       
  1128   
       
  1129     MCE_DELETE( iDialog ); 
       
  1130     SetDialog( CMceCsSubSession::EOutSession, newSipBaseDialog, oldDialogId );
       
  1131     
       
  1132     ResetInitialInvite();  
       
  1133     
       
  1134     if ( Body() && &Body()->SdpSession() )
       
  1135         {
       
  1136         Body()->SdpSession().AttachContext( NULL ); // Clear first
       
  1137         Body()->SdpSession().AttachContext( Dialog() );
       
  1138         }
       
  1139     
       
  1140     MCESRV_DEBUG("CMceSipSession::CreateDialogFrom3XXResponseL, Exit");
       
  1141     }
       
  1142   
       
  1143 // -----------------------------------------------------------------------------
       
  1144 // CMceSipSession::ReUseDialog
       
  1145 // -----------------------------------------------------------------------------
       
  1146 //
       
  1147 TInt CMceSipSession::ReUseDialog()
       
  1148 	{
       
  1149 	return iDialog->Dialog().ReuseInitialRequestData();
       
  1150 	}
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // CMceSipSession::DoCreateOutgoingDialogL
       
  1154 // -----------------------------------------------------------------------------
       
  1155 //
       
  1156 CSIPInviteDialogAssoc* CMceSipSession::DoCreateOutgoingDialogL( 
       
  1157                                                     CUri8* remoteURI, 
       
  1158                                                     CSIPToHeader* to )
       
  1159     {
       
  1160     __ASSERT_ALWAYS( ProfileConfigured(), User::Leave( KErrArgument ) );
       
  1161 
       
  1162     CSIPConnection& connection = SIPConnection().Connection();
       
  1163     const CSIPProfile& profile = Profile();
       
  1164           
       
  1165     return CSIPInviteDialogAssoc::NewL( connection, remoteURI, profile,
       
  1166     									NULL, to );
       
  1167     }
       
  1168 
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // CMceSipSession::Dialog
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //
       
  1173 CSIPDialogAssocBase* CMceSipSession::Dialog() const
       
  1174     {
       
  1175     CSIPDialogAssocBase* dialog = NULL;
       
  1176     if ( iForkedDialogs.Count() == 0 )
       
  1177         {
       
  1178         dialog = CMceCsSubSession::Dialog();
       
  1179         }
       
  1180     else
       
  1181         {
       
  1182         dialog = iCurrentDialog;
       
  1183         }
       
  1184 
       
  1185     return dialog;    
       
  1186     }
       
  1187     
       
  1188     
       
  1189 
       
  1190 // -----------------------------------------------------------------------------
       
  1191 // CMceSipSession::Consumes
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //
       
  1194 
       
  1195 TBool CMceSipSession::Consumes( CSIPDialog& aDialog, 
       
  1196    			    				CSIPServerTransaction& aTransaction, 
       
  1197                	 				TBool& aAssociatesWithDialog )
       
  1198                	 
       
  1199 	{
       
  1200     
       
  1201     TBool consumes = CMceCsSubSession::Consumes( aDialog, aTransaction,
       
  1202                                                  aAssociatesWithDialog );
       
  1203     
       
  1204     if ( !aAssociatesWithDialog && 
       
  1205          CMceCsSubSession::Dialog()->Dialog() == aDialog ) 
       
  1206         //dialog might be forked and current dialog is the forked one
       
  1207         {
       
  1208         aAssociatesWithDialog = ETrue;
       
  1209         consumes = AcceptMethod( MceSip::Method( aTransaction ) );
       
  1210         }
       
  1211     else if ( !aAssociatesWithDialog )
       
  1212         {
       
  1213         //dialog might be forked and current dialog is the original one
       
  1214         CSIPInviteDialogAssoc* forkedDlg = NULL;
       
  1215         TInt index = 0;
       
  1216         while( !aAssociatesWithDialog && index < iForkedDialogs.Count() )
       
  1217             {
       
  1218             forkedDlg = iForkedDialogs[ index++ ];
       
  1219             if ( forkedDlg->Dialog() == aDialog )
       
  1220                 {
       
  1221                 aAssociatesWithDialog = ETrue;
       
  1222                 consumes = AcceptMethod( MceSip::Method( aTransaction ) );
       
  1223                 }
       
  1224             }
       
  1225         }
       
  1226     else
       
  1227         {
       
  1228         //NOP
       
  1229         }
       
  1230 
       
  1231     return consumes;
       
  1232     
       
  1233 	}               	 
       
  1234 
       
  1235 
       
  1236 // -----------------------------------------------------------------------------
       
  1237 // CMceSipSession::InviteCompleted
       
  1238 // -----------------------------------------------------------------------------
       
  1239 //
       
  1240 void CMceSipSession::InviteCompleted( CSIPClientTransaction& aTransaction )
       
  1241     {
       
  1242     CMceCsSubSession::InviteCompleted( aTransaction );
       
  1243     iForkedDialogs.ResetAndDestroy();
       
  1244     }
       
  1245 
       
  1246 // -----------------------------------------------------------------------------
       
  1247 // CMceSipSession::ResponseReceived
       
  1248 // -----------------------------------------------------------------------------
       
  1249 //
       
  1250 void CMceSipSession::ResponseReceived()
       
  1251     {
       
  1252     MCESRV_DEBUG("CMceSipSession::ResponseReceived, Entry");
       
  1253        
       
  1254     if ( iCurrentState->Id() == KMceStateEstablished &&
       
  1255          Response().Type() == SIPStrings::StringF( SipStrConsts::EInvite ) )
       
  1256         {
       
  1257         //Send ACK for signaling integrality
       
  1258         TRAP_IGNORE( Actions().SendACKL( Response() ) );
       
  1259         // If the 2xx response in the same dialog that established current session
       
  1260         // Just reply ACK for it, otherwise, send bye to terminate the dialog
       
  1261         if ( iDialog != iCurrentDialog )
       
  1262             {   
       
  1263             // Send BYE to end forked dialog
       
  1264             TRAP_IGNORE( Actions().SendBYEL() );
       
  1265             // Set the original dialog back as the current dialog
       
  1266             iCurrentDialog = iDialog;
       
  1267             }        
       
  1268         }
       
  1269     else
       
  1270         {
       
  1271         if ( Response().Type() == SIPStrings::StringF( SipStrConsts::EInvite ) )
       
  1272             {
       
  1273             // If one of the forked dialogs generated 200 OK response 
       
  1274             // for a session that is not in established state,
       
  1275             // replace the actual dialog with that
       
  1276             HandleForkedDialogs();
       
  1277             }
       
  1278         else
       
  1279             {
       
  1280             iCurrentDialog = iDialog;
       
  1281             }
       
  1282         HandleSIPEvent( EMceResponse, Dialog()->Dialog() );  
       
  1283         }
       
  1284     
       
  1285     MCESRV_DEBUG("CMceSipSession::ResponseReceived, Exit");
       
  1286     }
       
  1287 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // CMceSipSession::ProvisionalResponseReceived
       
  1290 // -----------------------------------------------------------------------------
       
  1291 //
       
  1292 void CMceSipSession::ProvisionalResponseReceived()
       
  1293     {
       
  1294     MCESRV_DEBUG("CMceSipSession::ProvisionalResponseReceived, Entry");
       
  1295     
       
  1296     HandleSIPEvent( EMceProvisionalResponse, Dialog()->Dialog() );
       
  1297     
       
  1298     MCESRV_DEBUG("CMceSipSession::ProvisionalResponseReceived, Exit");
       
  1299     }
       
  1300 
       
  1301 // -----------------------------------------------------------------------------
       
  1302 // CMceSipSession::RedirectionResponseReceived
       
  1303 // -----------------------------------------------------------------------------
       
  1304 //
       
  1305 void CMceSipSession::RedirectionResponseReceived()
       
  1306     {
       
  1307     MCESRV_DEBUG("CMceSipSession::RedirectionResponseReceived, Entry");
       
  1308     
       
  1309     HandleForkedDialogs();
       
  1310     
       
  1311     HandleSIPEvent( EMceRedirectionResponse, Dialog()->Dialog());
       
  1312     
       
  1313     iForkedDialogs.ResetAndDestroy();
       
  1314     
       
  1315     MCESRV_DEBUG("CMceSipSession::RedirectionResponseReceived, Exit");
       
  1316     }
       
  1317  
       
  1318 // -----------------------------------------------------------------------------
       
  1319 // CMceSipSession::ErrorResponseReceived
       
  1320 // -----------------------------------------------------------------------------
       
  1321 //
       
  1322 void CMceSipSession::ErrorResponseReceived()
       
  1323     {
       
  1324     MCESRV_DEBUG("CMceSipSession::ErrorResponseReceived, Entry");
       
  1325     
       
  1326     HandleForkedDialogs();
       
  1327 
       
  1328     HandleSIPEvent( EMceErrorResponse, Dialog()->Dialog()  );
       
  1329     
       
  1330     iForkedDialogs.ResetAndDestroy();
       
  1331     
       
  1332     MCESRV_DEBUG("CMceSipSession::ErrorResponseReceived, Exit");
       
  1333     }
       
  1334 
       
  1335 // -----------------------------------------------------------------------------
       
  1336 // CMceSipSession::StandAloneRequestReceived
       
  1337 // -----------------------------------------------------------------------------
       
  1338 //
       
  1339 void CMceSipSession::StandAloneRequestReceived()
       
  1340     {
       
  1341     MCESRV_DEBUG("CMceSipSession::StandAloneRequestReceived, Entry");
       
  1342     // Method is acceptable for session, but receiving them outside session
       
  1343     // is not acceptable. 
       
  1344     MceSip::DiscardRequest( Request() );
       
  1345     
       
  1346     MCESRV_DEBUG("CMceSipSession::StandAloneRequestReceived, Exit");
       
  1347     }
       
  1348 
       
  1349 // -----------------------------------------------------------------------------
       
  1350 // CMceSipSession::SubState
       
  1351 // -----------------------------------------------------------------------------
       
  1352 //
       
  1353 void CMceSipSession::SetSubState( CMceSipSession::TSubState aSubState )
       
  1354     {
       
  1355     MCESRV_DEBUG("CMceSipSession::SetSubState, Entry");
       
  1356     MCESRV_DEBUG_SUBSTATE("SetSubState: old sub state", iSubState );
       
  1357     
       
  1358     iSubState = aSubState;
       
  1359     
       
  1360     MCESRV_DEBUG_SUBSTATE("SetSubState: new sub state", iSubState );
       
  1361     MCESRV_DEBUG("CMceSipSession::SetSubState, Exit");
       
  1362     }
       
  1363     
       
  1364 // -----------------------------------------------------------------------------
       
  1365 // CMceSipSession::SubState
       
  1366 // -----------------------------------------------------------------------------
       
  1367 //
       
  1368 CMceSipSession::TSubState CMceSipSession::SubState()
       
  1369     {
       
  1370     return iSubState;
       
  1371     }
       
  1372 
       
  1373 // -----------------------------------------------------------------------------
       
  1374 // CMceSipSession::UpdateAccepted
       
  1375 // -----------------------------------------------------------------------------
       
  1376 //
       
  1377 void CMceSipSession::UpdateAccepted()
       
  1378     {
       
  1379     CMceComSession::Delete( iBody, Manager().MediaManager() );
       
  1380     iBody = BodyCandidate();
       
  1381     iBody->iCloneOrigin = NULL;
       
  1382     iNewBodyCandidate = NULL;
       
  1383     iBody->iFcSignallingRequired = EFalse;
       
  1384     iBody->iRequireSignalling = EFalse;
       
  1385     iBody->iPullModeUpdate = EFalse;
       
  1386     }
       
  1387 
       
  1388 // -----------------------------------------------------------------------------
       
  1389 // CMceSipSession::UpdateRejected
       
  1390 // -----------------------------------------------------------------------------
       
  1391 //
       
  1392 void CMceSipSession::UpdateRejected()
       
  1393     {
       
  1394     if ( iBody && &iBody->SdpSession() && iBody->SdpSession().iOOldSchool )
       
  1395         {
       
  1396         if ( iBody->SdpSession().iOOldSchoolProceeding )  
       
  1397             {
       
  1398             iBody->SdpSession().iOOldSchool = 0;
       
  1399             iBody->SdpSession().iOOldSchoolProceeding = 0;
       
  1400             iBody->SdpSession().iOOldSchoolCompleted = 1;  
       
  1401             }
       
  1402         else
       
  1403             {
       
  1404             iBody->SdpSession().iOOldSchoolProceeding = 1; 
       
  1405             iBody->SdpSession().iOOldSchoolCompleted = 0;    
       
  1406             }
       
  1407         }     
       
  1408     // reset the remoteUri Array if updated failed
       
  1409     iRemoteUri.ResetAndDestroy();
       
  1410  
       
  1411     CMceComSession::Delete( iNewBodyCandidate, Manager().MediaManager() ); 
       
  1412     }
       
  1413 
       
  1414 // -----------------------------------------------------------------------------
       
  1415 // CMceSipSession::SetBodyL
       
  1416 // -----------------------------------------------------------------------------
       
  1417 //
       
  1418 void CMceSipSession::SetBodyL( CMceComSession* aSession )
       
  1419     {
       
  1420     __ASSERT_ALWAYS( !iBody, User::Leave( KErrArgument ) );
       
  1421     TInetAddr nextHop;
       
  1422     
       
  1423     TInetAddr localIpAddress = SIPConnection().LocalIPAddressL( NextHopL( nextHop ) );
       
  1424     
       
  1425     if ( !aSession )
       
  1426         {
       
  1427         iBody = CMceComSession::NewL( CMceComSession::EInSession );
       
  1428         SetSubState( EAnswering );
       
  1429         }
       
  1430     else
       
  1431         {
       
  1432         __ASSERT_ALWAYS( aSession->iType == CMceComSession::EOutSession, 
       
  1433                          User::Leave( KErrArgument ) );
       
  1434         iBody = aSession;
       
  1435         SetSubState( EOffering );
       
  1436         
       
  1437         }
       
  1438     
       
  1439 	iBody->SetObserver( *this );
       
  1440 	MCE_SET_LOCAL_IP_ADDR( iBody, localIpAddress );
       
  1441 	iBody->iIapId = SIPConnection().AccessPointId();
       
  1442 	iBody->iDialogId = DialogId();
       
  1443 	
       
  1444 	iExtensions->Update( *iBody );
       
  1445     }
       
  1446 
       
  1447 // -----------------------------------------------------------------------------
       
  1448 // CMceSipSession::PrepareIdsL
       
  1449 // -----------------------------------------------------------------------------
       
  1450 //
       
  1451 void CMceSipSession::PrepareIdsL( TMceIds& aIds ) const
       
  1452     {    
       
  1453     aIds.iMsgType = EMceItcMsgTypeSession;
       
  1454     aIds.iManagerType = KMceCSSIPSession;
       
  1455     aIds.iDialogType = KMceDlgTypeInvite;
       
  1456     aIds.iDialogID = DialogId();
       
  1457     
       
  1458     if ( ProfileConfigured() )
       
  1459     	{
       
  1460 		TUint32 profileId;
       
  1461 	    User::LeaveIfError( Profile().GetParameter( KSIPProfileId, profileId ) );
       
  1462 	    
       
  1463 	    aIds.iProfileID = profileId;    	
       
  1464     	}    
       
  1465     
       
  1466 	aIds.iSecureFlag =  iBody->iIsSecureSession;
       
  1467     }
       
  1468 
       
  1469 // -----------------------------------------------------------------------------
       
  1470 // CMceSipSession::InviteTransaction
       
  1471 // -----------------------------------------------------------------------------
       
  1472 //
       
  1473 CSIPClientTransaction* CMceSipSession::InviteTransaction()
       
  1474     {
       
  1475     CSIPClientTransaction* trx = NULL;
       
  1476     TInt index = 0;
       
  1477     
       
  1478     while( !trx && index < PendingTransactions().Count() )
       
  1479         {
       
  1480         trx = PendingTransactions()[ index++ ];
       
  1481         TBool isInvite = 
       
  1482             trx->Type() == SIPStrings::StringF( SipStrConsts::EInvite );
       
  1483         TBool isCompleted = MceSip::TrxCompleted( *trx );
       
  1484         
       
  1485         trx = isInvite && !isCompleted ? trx : NULL;
       
  1486         }
       
  1487 
       
  1488     return trx;
       
  1489     }
       
  1490     
       
  1491 // -----------------------------------------------------------------------------
       
  1492 // CMceSipSession::StandAloneResponseReceived
       
  1493 // -----------------------------------------------------------------------------
       
  1494 //
       
  1495 void CMceSipSession::StandAloneResponseReceived( 
       
  1496                                         TMceSipResponseType /*aResponseType*/ )
       
  1497     {
       
  1498     MCESRV_DEBUG("CMceSipSession::StandAloneResponseReceived, Entry");
       
  1499     
       
  1500     //if response to CANCEL
       
  1501     if ( MceSip::IsResponseTo( Response(), 
       
  1502          SIPStrings::StringF( SipStrConsts::ECancel ) ) )
       
  1503         {
       
  1504         ResponseReceived();
       
  1505         }
       
  1506     else
       
  1507         {
       
  1508         MCESRV_DEBUG("StandAloneResponseReceived: NOT CANCEL. IGNORED");
       
  1509         //NOP
       
  1510         }
       
  1511         
       
  1512     MCESRV_DEBUG("CMceSipSession::StandAloneResponseReceived, Exit");
       
  1513     }
       
  1514 
       
  1515 // -----------------------------------------------------------------------------
       
  1516 // CMceSipSession::ErrorOccured
       
  1517 // -----------------------------------------------------------------------------
       
  1518 //
       
  1519 void CMceSipSession::ErrorOccured( TInt aError )
       
  1520     {
       
  1521     MCESRV_DEBUG("CMceSipSession::ErrorOccured, Entry")
       
  1522     
       
  1523     TUint newState( KMceStateError );
       
  1524     CMceSession::TState newClientState( CMceSession::ETerminated );
       
  1525         
       
  1526     if ( CurrentState().Id() == KMceStateTerminating )
       
  1527         {
       
  1528         // Failed to send BYE. ignore and set the state to terminated.
       
  1529         newState = KMceStateTerminated;
       
  1530         }
       
  1531     else if ( ( aError == KErrSIPNoAckReceived && ( SubState() == EAnswering || SubState() == EUpdating ) ) ||
       
  1532               ( CurrentState().Id() == KMceStateOffering ) ||
       
  1533               ( CurrentState().Id() == KMceStateConfirming ) )
       
  1534         {
       
  1535         if ( Dialog() )
       
  1536             {
       
  1537             CSIPDialog::TState dialogState = Dialog()->Dialog().State();
       
  1538             switch ( dialogState )
       
  1539                 {
       
  1540                 case CSIPDialog::EEarly:
       
  1541                     {
       
  1542                     TRAP_IGNORE( Actions().SendCancelL() )
       
  1543                     newState = KMceStateCanceled;
       
  1544                     newClientState = CMceSession::ECancelling;
       
  1545                     break; 
       
  1546                     }
       
  1547                 case CSIPDialog::EConfirmed:
       
  1548                     {
       
  1549                     TRAP_IGNORE( Actions().SendBYEL() )
       
  1550                     newState = KMceStateTerminating;
       
  1551                     newClientState = CMceSession::ETerminating;
       
  1552                     break;
       
  1553                     }
       
  1554                 default:
       
  1555                     {
       
  1556                     newState = KMceStateTerminated;
       
  1557                     break;
       
  1558                     }
       
  1559                 }
       
  1560             }
       
  1561         }
       
  1562     
       
  1563     if ( CurrentState().Id() != KMceStateTerminating )
       
  1564         {
       
  1565         Actions().StopMedia();
       
  1566         FCActions().ReleaseFC();
       
  1567         }
       
  1568     
       
  1569     Actions().StateChanged( newState );
       
  1570     TRAP_IGNORE( Actions().ClientStateChangedL( newClientState, aError ) )
       
  1571     MCESRV_DEBUG("CMceSipSession::ErrorOccured, Exit")
       
  1572     }
       
  1573 
       
  1574 // -----------------------------------------------------------------------------
       
  1575 // CMceSipSession::DoErrorOccured
       
  1576 // -----------------------------------------------------------------------------
       
  1577 //
       
  1578 void CMceSipSession::DoErrorOccured( TInt aError, 
       
  1579                                      CSIPTransactionBase& aTransaction )
       
  1580     {
       
  1581 	// If Error is for Extension Request    
       
  1582     if ( Actions().IsExtensionRequest( aTransaction.Type()) )
       
  1583     	{
       
  1584     	Actions().ReceiveExtensionError( aTransaction, aError );
       
  1585     	}
       
  1586     else
       
  1587     	{
       
  1588     	ErrorOccured( aError );    		
       
  1589     	}
       
  1590     }
       
  1591 
       
  1592 // -----------------------------------------------------------------------------
       
  1593 // CMceSipSession::ErrorOccured
       
  1594 // -----------------------------------------------------------------------------
       
  1595 //
       
  1596 void CMceSipSession::LocalErrorOccured( TMceStateIndex aNewState, TInt aWithError )
       
  1597     {
       
  1598     MCESRV_DEBUG("CMceSipSession::LocalErrorOccured( state, error), Entry");
       
  1599     MCESRV_DEBUG_DVALUE("ERROR", aWithError );
       
  1600     
       
  1601     if ( aNewState == KMceStateError )
       
  1602         {
       
  1603         Actions().StopMedia();
       
  1604         FCActions().ReleaseFC();
       
  1605         }
       
  1606         
       
  1607     Actions().StateChanged( aNewState );
       
  1608     Actions().ClientErrorOccured( aWithError );
       
  1609     
       
  1610     MCESRV_DEBUG("CMceSipSession::LocalErrorOccured( state, error), Exit");
       
  1611     }
       
  1612 
       
  1613 // -----------------------------------------------------------------------------
       
  1614 // CMceSipSession::Terminate
       
  1615 // -----------------------------------------------------------------------------
       
  1616 //
       
  1617 TBool CMceSipSession::Terminate()
       
  1618     {
       
  1619     MCESRV_DEBUG( "CMceSipSession::Terminate, Entry" );
       
  1620     TRAPD( error, DoTerminateL() );
       
  1621     if ( error )
       
  1622         {
       
  1623         MCESRV_DEBUG_DVALUE( "CMceSipSession::Terminate, ERROR:", error );
       
  1624         Actions().StateChanged( KMceStateTerminated );
       
  1625         }
       
  1626     MCESRV_DEBUG( "CMceSipSession::Terminate, Exit" );
       
  1627     return CanDispose();
       
  1628     }
       
  1629 
       
  1630 // -----------------------------------------------------------------------------
       
  1631 // CMceSipSession::DiscardInvite
       
  1632 // -----------------------------------------------------------------------------
       
  1633 //
       
  1634 void CMceSipSession::DiscardInvite()
       
  1635     {
       
  1636     CSIPServerTransaction* invite = FIRST_REQUEST();
       
  1637     if ( MceSip::TrxType( *invite ) == SipStrConsts::EInvite )
       
  1638         {
       
  1639         MceSip::DiscardRequest( *invite );
       
  1640         }
       
  1641     }
       
  1642 
       
  1643 // -----------------------------------------------------------------------------
       
  1644 // CMceSipSession::DoTerminateL
       
  1645 // -----------------------------------------------------------------------------
       
  1646 //
       
  1647 void CMceSipSession::DoTerminateL()
       
  1648     {
       
  1649     TMceStateIndex currentState = CurrentState().Id();
       
  1650     
       
  1651     MCESRV_DEBUG_STATE("DoTerminateL: current state", currentState );
       
  1652     
       
  1653     Actions().StopMedia();
       
  1654     FCActions().ReleaseFC();
       
  1655     
       
  1656     switch( currentState )
       
  1657         {
       
  1658         case KMceStateAnswering:
       
  1659             {
       
  1660             MCESRV_DEBUG("DoTerminateL: KMceStateAnswering -> BYE");
       
  1661             Actions().SendBYEL();
       
  1662             //going to still wait ACK or error that ACK not received
       
  1663             break;
       
  1664             }
       
  1665         case KMceStateEstablished:
       
  1666             {
       
  1667             MCESRV_DEBUG("DoTerminateL: KMceStateEstablished -> BYE");
       
  1668             Actions().SendBYEL();
       
  1669             Actions().StateChanged( KMceStateTerminating );
       
  1670             break;
       
  1671             }
       
  1672         case KMceStateError:
       
  1673             {
       
  1674             MCESRV_DEBUG("DoTerminateL: KMceStateError:");
       
  1675             
       
  1676             TMceStateIndex nextState = KMceStateTerminated;
       
  1677             if ( iExitState )
       
  1678                 {
       
  1679                 TMceStateIndex exitStateId = iExitState->Id();
       
  1680                 MCESRV_DEBUG_STATE("from state", exitStateId );
       
  1681                 
       
  1682                 if ( iExitState->Id() == KMceStateEstablished || 
       
  1683                      iExitState->Id() == KMceStateAnswering )
       
  1684                     {
       
  1685                     MCESRV_DEBUG("DoTerminateL: KMceStateError -> BYE");
       
  1686                     Actions().SendBYEL();
       
  1687                     nextState = KMceStateTerminating;
       
  1688                     }
       
  1689                 }
       
  1690             Actions().StateChanged( nextState );
       
  1691             break;
       
  1692             }
       
  1693         case KMceStateUpdated:
       
  1694             {
       
  1695             MCESRV_DEBUG("DoTerminateL: KMceStateUpdated -> DECLINE");
       
  1696             if ( &Request() )
       
  1697                 {
       
  1698                 CMceMsgSIPData msg;
       
  1699                 Actions().SendDeclineL(Request(), msg );
       
  1700                 }
       
  1701             Actions().StateChanged( KMceStateTerminated );
       
  1702             break;
       
  1703             }
       
  1704         case KMceStateIdle:
       
  1705         case KMceStateServerInitializing:
       
  1706         case KMceStateTerminating:
       
  1707             {
       
  1708             MCESRV_DEBUG("DoTerminateL: KMceStateUpdated, KMceStateIdle");
       
  1709             Actions().StateChanged( KMceStateTerminated );
       
  1710             break;
       
  1711             }
       
  1712         case KMceStateOffering:
       
  1713             {
       
  1714             MCESRV_DEBUG("DoTerminateL: KMceStateOffering");
       
  1715             if ( SubState() == EOffering )
       
  1716                 {
       
  1717                 CSIPClientTransaction* lastResponse = &Response();
       
  1718     
       
  1719                 if ( lastResponse && MceSip::TrxCompleted( *lastResponse ) 
       
  1720                 && ( PendingTransaction(SIPStrings::StringF( 
       
  1721                 		SipStrConsts::EInvite )) == NULL ))
       
  1722                     {
       
  1723                     // 200 OK already received and waiting for media, bye can be sent
       
  1724                     MCESRV_DEBUG("DoTerminateL: KMceStateOffering -> BYE");
       
  1725                     Actions().SendBYEL();
       
  1726                     Actions().StateChanged( KMceStateTerminating );
       
  1727                     }
       
  1728                 else
       
  1729                     {
       
  1730                     MCESRV_DEBUG("DoTerminateL: KMceStateOffering -> CANCEL");
       
  1731                     Actions().SendCancelL();
       
  1732                     Actions().StateChanged( KMceStateCanceled );
       
  1733                     }
       
  1734                 }
       
  1735             break;
       
  1736             }
       
  1737         case KMceStateServerEstablishing:
       
  1738             {
       
  1739             MCESRV_DEBUG("DoTerminateL: KMceStateServerEstablishing -> DECLINE");
       
  1740             if ( &Request() && Dialog() )
       
  1741                 {
       
  1742                 MceSip::DiscardRequest( Request(), KMceSipDecline );
       
  1743                 if ( Dialog()->Dialog().State() == CSIPDialog::EConfirmed )
       
  1744                     {
       
  1745                     Actions().SendBYEL();
       
  1746                     Actions().StateChanged( KMceStateTerminating );
       
  1747                     }
       
  1748                 else
       
  1749                     {
       
  1750                     Actions().StateChanged( KMceStateTerminated );
       
  1751                     }
       
  1752                 }
       
  1753             else
       
  1754                 {
       
  1755                 Actions().StateChanged( KMceStateTerminated );
       
  1756                 }
       
  1757             break;
       
  1758             }
       
  1759         default:
       
  1760             {
       
  1761             //NOP
       
  1762             }
       
  1763             
       
  1764         }
       
  1765     }
       
  1766 
       
  1767 // -----------------------------------------------------------------------------
       
  1768 // CMceSipSession::DoConnectionStateChanged
       
  1769 // -----------------------------------------------------------------------------
       
  1770 //
       
  1771 void CMceSipSession::DoConnectionStateChanged( TBool aIsActive )
       
  1772     {
       
  1773     MCESRV_DEBUG("CMceSipSession::ConnectionStateChanged, Entry");
       
  1774     
       
  1775     if ( iBody )
       
  1776         {
       
  1777         iBody->iIsConnectionActive = aIsActive;
       
  1778         }
       
  1779         
       
  1780     MCESRV_DEBUG("CMceSipSession::ConnectionStateChanged, Exit");
       
  1781     }
       
  1782 
       
  1783 // -----------------------------------------------------------------------------
       
  1784 // CMceSipSession::Canceled
       
  1785 // -----------------------------------------------------------------------------
       
  1786 //
       
  1787 void CMceSipSession::Canceled()
       
  1788     {
       
  1789     MCESRV_DEBUG("CMceSipSession::Canceled, Entry");
       
  1790     
       
  1791     if ( IsSipDialogConfirmed() )
       
  1792         {
       
  1793         // cancel the reinvite shouldn't terminate original session.
       
  1794         Actions().StopUpdatingMedia();
       
  1795         Actions().UpdateFailed(); 
       
  1796         Actions().StateChanged( KMceStateEstablished );
       
  1797         TRAP_IGNORE( Actions().ClientStateChangedL( 
       
  1798             CMceSession::EEstablished, *Body(), KErrCancel ) );                               
       
  1799         }
       
  1800     else
       
  1801         {
       
  1802         Actions().StopMedia();
       
  1803         FCActions().ReleaseFC();
       
  1804         Actions().StateChanged( KMceStateTerminated );
       
  1805         TRAP_IGNORE( Actions().ClientStateChangedL( CMceSession::ETerminated ) );
       
  1806         }
       
  1807     
       
  1808     MCESRV_DEBUG("CMceSipSession::Canceled, Exit");
       
  1809     }
       
  1810 
       
  1811 // -----------------------------------------------------------------------------
       
  1812 // CMceSipSession::DoServiceL
       
  1813 // -----------------------------------------------------------------------------
       
  1814 //
       
  1815 HBufC8* CMceSipSession::DoServiceL( TMceIds& aIds, 
       
  1816                                     TMceItcFunctions aFunction )
       
  1817     {
       
  1818     MCESRV_DEBUG("CMceSipSession::DoServiceL( no message ), Entry");
       
  1819     MCESRV_DEBUG_EVENT("ITC function", aFunction );
       
  1820     
       
  1821     HBufC8* returnMessage = NULL;
       
  1822     
       
  1823     TMceStateTransitionEvent event( *this, aFunction, aIds );
       
  1824     if ( iStateMachine->Consumes( event ) )
       
  1825         {
       
  1826         MCESRV_DEBUG("handler: state machine");
       
  1827         iStateMachine->ProcessL( event );
       
  1828         }
       
  1829     else
       
  1830         {
       
  1831         switch ( aFunction )
       
  1832             {
       
  1833             case EMceItcFCGetMediaLines:
       
  1834             	{
       
  1835                 MCESRV_DEBUG("handler: floor control");
       
  1836                 returnMessage = FCActions().FCGetMediaLinesL();
       
  1837                 break;		    
       
  1838             	} 
       
  1839             case EMceItcGetSession:
       
  1840             	{
       
  1841                 MCESRV_DEBUG("handler: session");
       
  1842                 returnMessage = Actions().BodyToTextL();
       
  1843                 break;		    
       
  1844             	} 
       
  1845             //rtp sink
       
  1846             case EMceItcSendSR:
       
  1847             case EMceItcSendRR:
       
  1848             case EMceItcSetFastForward:
       
  1849             case EMceItcSetFastRewind:
       
  1850             case EMceItcDisableInactivityTimer:
       
  1851             //dtmf
       
  1852             case EMceItcIsDtmfActive:
       
  1853             case EMceItcStartDtmfTone:
       
  1854             case EMceItcStopDtmfTone:
       
  1855             case EMceItcSendDtmfTone:
       
  1856             case EMceItcCancelSendDtmfToneSequence:
       
  1857                 {
       
  1858                 MCESRV_DEBUG("handler: media");
       
  1859                 returnMessage = Actions().ControlMediaL( aIds, aFunction );
       
  1860                 break;
       
  1861                 }
       
  1862             default:
       
  1863                 {
       
  1864                 MCESRV_DEBUG("NOT SUPPORTED");
       
  1865                 User::Leave( KErrNotSupported );
       
  1866                 break;
       
  1867                 }
       
  1868             }
       
  1869         }
       
  1870         
       
  1871     MCESRV_DEBUG("CMceSipSession::DoServiceL( no message ), Exit");
       
  1872     
       
  1873     return returnMessage;    
       
  1874     }
       
  1875     
       
  1876 // -----------------------------------------------------------------------------
       
  1877 // CMceSipSession::DoServiceL
       
  1878 // -----------------------------------------------------------------------------
       
  1879 //
       
  1880 void CMceSipSession::DoServiceL( TMceIds& aIds, 
       
  1881                                  TMceItcFunctions aFunction, 
       
  1882                                  const TDesC8& aMessage )
       
  1883     {
       
  1884     MCESRV_DEBUG("CMceSipSession::DoServiceL( write data ), Entry");
       
  1885     MCESRV_DEBUG_EVENT("ITC function", aFunction );
       
  1886     
       
  1887     switch ( aFunction )
       
  1888         {
       
  1889         case EMceItcInitFC:
       
  1890         	{
       
  1891             MCESRV_DEBUG("handler: floor control");
       
  1892             iUseFC = ETrue;
       
  1893             FCActions().InitializeFCL ( aIds, aMessage );
       
  1894             break;		    
       
  1895         	} 
       
  1896         case EMceItcUpdateFC:
       
  1897         	{
       
  1898             MCESRV_DEBUG("handler: floor control");
       
  1899             iUseFC = ETrue;
       
  1900             FCActions().UpdateFCL( aIds, aMessage );
       
  1901             break;		    
       
  1902         	} 
       
  1903         case EMceItcSendFCMsg:
       
  1904         	{
       
  1905             MCESRV_DEBUG("handler: floor control");
       
  1906             FCActions().SendFCMsgL ( aMessage );
       
  1907             break;		    
       
  1908         	} 
       
  1909         //speaker sink
       
  1910         case EMceItcSetVolume:
       
  1911         case EMceItcSetAudioRouting:
       
  1912         //mic source
       
  1913         case EMceItcSetGain:
       
  1914         //rtp source
       
  1915         case EMceItcEnableInactivityTimer:
       
  1916         //camera source
       
  1917         case EMceItcSetZoomFactor:
       
  1918         case EMceItcSetDigitalZoomFactor:
       
  1919         case EMceItcSetContrast:
       
  1920         case EMceItcSetBrightness:
       
  1921         case EMceItcSetExposure:
       
  1922         case EMceItcSetWhiteBalance:
       
  1923         //display sink
       
  1924         case EMceItcSetDisplayIndex:
       
  1925         case EMceItcSetDisplayPriority:
       
  1926         case EMceItcSetDisplayRect:
       
  1927         case EMceItcSetDisplayRotation:
       
  1928         //file source
       
  1929         case EMceItcSetFilePosition:
       
  1930         case EMceItcSetFileInfo:
       
  1931         //dtmf
       
  1932         case EMceItcSendDtmfToneSequence:
       
  1933             {
       
  1934             MCESRV_DEBUG("handler: media");
       
  1935             Actions().ControlMediaL( aIds, aFunction, aMessage );
       
  1936             break;
       
  1937             }
       
  1938         default:
       
  1939             {
       
  1940             MCESRV_DEBUG("NOT SUPPORTED");
       
  1941             User::Leave( KErrNotSupported );
       
  1942             break;
       
  1943             }
       
  1944         }
       
  1945         
       
  1946     MCESRV_DEBUG("CMceSipSession::DoServiceL( write data ), Exit");
       
  1947     }
       
  1948 
       
  1949 // -----------------------------------------------------------------------------
       
  1950 // CMceSipSession::DoServiceL
       
  1951 // -----------------------------------------------------------------------------
       
  1952 //
       
  1953 void CMceSipSession::DoServiceL( TMceIds& aIds, 
       
  1954                                  TMceItcFunctions aFunction, 
       
  1955                                  TPtr8& aMessage )
       
  1956     {
       
  1957     MCESRV_DEBUG("CMceSipSession::DoServiceL( read data ), Entry");
       
  1958     MCESRV_DEBUG_EVENT("ITC function", aFunction );
       
  1959     
       
  1960     switch ( aFunction )
       
  1961         {
       
  1962         case EMceItcVolume:
       
  1963         case EMceItcAudioRouting:
       
  1964         case EMceItcGain:
       
  1965         case EMceItcZoomFactor:
       
  1966         case EMceItcDigitalZoomFactor:
       
  1967         case EMceItcContrast:
       
  1968         case EMceItcBrightness:
       
  1969         case EMceItcExposure:
       
  1970         case EMceItcWhiteBalance:
       
  1971         case EMceItcDisplayRect:
       
  1972         case EMceItcDisplayPriority:
       
  1973         case EMceItcDisplayRotation:
       
  1974         case EMceItcFileInfo:
       
  1975         case EMceItcFilePosition:
       
  1976         case EMceItcSetCameraIndex:
       
  1977             {
       
  1978             MCESRV_DEBUG("handler: media");
       
  1979             Actions().ControlMediaL( aIds, aFunction, aMessage );
       
  1980             break;
       
  1981             }
       
  1982         default:
       
  1983             {
       
  1984             MCESRV_DEBUG("NOT SUPPORTED");
       
  1985             User::Leave( KErrNotSupported );
       
  1986             break;
       
  1987             }
       
  1988         }
       
  1989         
       
  1990     MCESRV_DEBUG("CMceSipSession::DoServiceL( read data ), Exit");
       
  1991     }
       
  1992 
       
  1993 // -----------------------------------------------------------------------------
       
  1994 // CMceSipSession::DoServiceL
       
  1995 // -----------------------------------------------------------------------------
       
  1996 //
       
  1997 void CMceSipSession::DoServiceL( TMceIds& aIds, 
       
  1998                                  TMceItcFunctions aFunction, 
       
  1999                                  CMceMsgBase& aMessage )
       
  2000     {
       
  2001     MCESRV_DEBUG("CMceSipSession::DoServiceL( message ), Entry");
       
  2002     MCESRV_DEBUG_EVENT("ITC function", aFunction );
       
  2003     
       
  2004 
       
  2005     TMceStateTransitionEvent event( *this, aFunction, aIds, aMessage );
       
  2006     if ( iStateMachine->Consumes( event ) )
       
  2007         {
       
  2008         MCESRV_DEBUG("handler: state machine");
       
  2009         iStateMachine->ProcessL( event );
       
  2010         }
       
  2011     else
       
  2012         {
       
  2013         switch ( aFunction )
       
  2014             {
       
  2015             case EMceItcFCSetMediaLines:
       
  2016             	{
       
  2017                 MCESRV_DEBUG("handler: floor control");
       
  2018                 FCActions().FCSetMediaLinesL ( aMessage );
       
  2019                 break;		    
       
  2020             	} 
       
  2021             default:
       
  2022                 {
       
  2023                 MCESRV_DEBUG("NOT SUPPORTED");
       
  2024                 User::Leave( KErrNotSupported );
       
  2025                 break;
       
  2026                 }
       
  2027             }
       
  2028         }
       
  2029             
       
  2030     MCESRV_DEBUG("CMceSipSession::DoServiceL( message ), Exit");
       
  2031     }
       
  2032 
       
  2033 // -----------------------------------------------------------------------------
       
  2034 // CMceSipSession::Updated
       
  2035 // -----------------------------------------------------------------------------
       
  2036 // 	       
       
  2037 void CMceSipSession::Updated( CMceComSession& aSession )
       
  2038     {
       
  2039     MCESRV_DEBUG("CMceSipSession::Updated, Entry");
       
  2040     
       
  2041     __ASSERT_ALWAYS( &aSession == iBody || &aSession == iNewBodyCandidate, 
       
  2042         User::Panic( KMceServerPanic, KErrArgument ) );
       
  2043     
       
  2044     TMceStateTransitionEvent event( *this, EMceMediaUpdated );
       
  2045     TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2046     if ( error != KErrNone )
       
  2047         {
       
  2048         MCESRV_DEBUG_DVALUE("Updated: state machine causes ERROR", error );
       
  2049         LocalErrorOccured( KMceStateError, error );
       
  2050         }
       
  2051     
       
  2052     MCESRV_DEBUG("CMceSipSession::Updated, Exit");
       
  2053     }
       
  2054 
       
  2055 // -----------------------------------------------------------------------------
       
  2056 // CMceSipSession::Reserved
       
  2057 // -----------------------------------------------------------------------------
       
  2058 // 	       
       
  2059 void CMceSipSession::Reserved( CMceComSession& aSession )
       
  2060     {
       
  2061     MCESRV_DEBUG("CMceSipSession::Reserved, Entry");
       
  2062     
       
  2063     __ASSERT_ALWAYS( &aSession == iBody || &aSession == iNewBodyCandidate, 
       
  2064         User::Panic( KMceServerPanic, KErrArgument ) );
       
  2065     
       
  2066     TMceStateTransitionEvent event( *this, EMceMediaReserved );
       
  2067     TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2068     if ( error != KErrNone )
       
  2069         {
       
  2070         MCESRV_DEBUG_DVALUE("Reserved: state machine causes ERROR", error );
       
  2071         LocalErrorOccured( KMceStateError, error );
       
  2072         }
       
  2073     
       
  2074     MCESRV_DEBUG("CMceSipSession::Reserved, Exit");
       
  2075     }
       
  2076 
       
  2077 // -----------------------------------------------------------------------------
       
  2078 // CMceSipSession::SessionClosed
       
  2079 // -----------------------------------------------------------------------------
       
  2080 //
       
  2081 void CMceSipSession::SessionClosed( CMceComSession& aSession )
       
  2082     {
       
  2083     MCESRV_DEBUG("CMceSipSession::SessionClosed, Entry");
       
  2084     
       
  2085     __ASSERT_ALWAYS( &aSession == iBody || &aSession == iNewBodyCandidate, 
       
  2086         User::Panic( KMceServerPanic, KErrArgument ) );
       
  2087     
       
  2088     TMceStateTransitionEvent event( *this, EMceMediaSessionStopped );
       
  2089     TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2090     if ( error != KErrNone )
       
  2091         {
       
  2092         MCESRV_DEBUG_DVALUE(
       
  2093             "SessionClosed: state machine causes ERROR", error );
       
  2094         LocalErrorOccured( KMceStateTerminated, error );
       
  2095         }
       
  2096         
       
  2097     MCESRV_DEBUG("CMceSipSession::SessionClosed, Exit");
       
  2098     }
       
  2099 
       
  2100 // -----------------------------------------------------------------------------
       
  2101 // CMceSipSession::EventReceived
       
  2102 // -----------------------------------------------------------------------------
       
  2103 //
       
  2104 void CMceSipSession::EventReceived( TMceMccComEvent& aEvent )
       
  2105     {
       
  2106     MCESRV_DEBUG("CMceSipSession::EventReceived, Entry");
       
  2107 
       
  2108     if ( aEvent.iItcEvent == EMceItcFCMsgReceived &&
       
  2109          FCSession() && 
       
  2110          aEvent.iItcDataDesC )
       
  2111         {
       
  2112         HBufC8* data = NULL;
       
  2113         TRAPD( err, data = aEvent.iItcDataDesC->AllocL() );
       
  2114         if( err == KErrNone )
       
  2115             {
       
  2116             FCReceivedData( data, FCSession() );    
       
  2117             }
       
  2118         else
       
  2119             {
       
  2120             MCESRV_DEBUG("RtcpSignalReceived, Alloc failed");
       
  2121             }
       
  2122         }
       
  2123     else
       
  2124         {
       
  2125         TRAPD( err, Actions().ClientMediaStateChangedL( &aEvent ) );
       
  2126         if( err != KErrNone )
       
  2127         	{
       
  2128             MCESRV_DEBUG("RtcpSignalReceived, ClientMediaStateChanged failed");
       
  2129             }
       
  2130         }
       
  2131         
       
  2132     MCESRV_DEBUG("CMceSipSession::EventReceived, Exit");
       
  2133     }
       
  2134 
       
  2135 // -----------------------------------------------------------------------------
       
  2136 // CMceSipSession::MediaError
       
  2137 // -----------------------------------------------------------------------------
       
  2138 //
       
  2139 void CMceSipSession::MediaError( TMceMccComEvent& aEvent )
       
  2140     {
       
  2141 #if MCE_IGNORE_MEDIA_ERROR
       
  2142 
       
  2143     if ( aEvent.iError < 0 )
       
  2144         {
       
  2145         MCESRV_DEBUG_DVALUE("error", aEvent.iError );
       
  2146         MCESRV_DEBUG("CMceSipSession::MediaError, Exit");
       
  2147         return;
       
  2148         }
       
  2149 
       
  2150 #else
       
  2151 
       
  2152     TMceStateTransitionEvent event( *this, aEvent, EMceMediaError );
       
  2153 	CMceState& currentState = CurrentState();
       
  2154 	currentState.MediaErrorOccured( event );
       
  2155 	   
       
  2156 #endif
       
  2157     }
       
  2158     
       
  2159 // -----------------------------------------------------------------------------
       
  2160 // CMceSipSession::SessionCreatedL
       
  2161 // -----------------------------------------------------------------------------
       
  2162 //
       
  2163 void CMceSipSession::SessionCreatedL( CMceComSession* aSession )
       
  2164     {
       
  2165     MCESRV_DEBUG("CMceSipSession::SessionCreated, Entry");
       
  2166     
       
  2167     __ASSERT_ALWAYS( iBody, User::Leave( KErrArgument ) );
       
  2168     __ASSERT_ALWAYS( aSession, User::Leave( KErrArgument ) );
       
  2169     aSession->SdpSession().AttachContext( Dialog() );
       
  2170     
       
  2171     iBodyBucket.AppendL( iBody );
       
  2172     iBody = aSession;
       
  2173 
       
  2174     MCESRV_DEBUG("CMceSipSession::SessionCreated, Exit");
       
  2175     }
       
  2176 
       
  2177 // -----------------------------------------------------------------------------
       
  2178 // CMceSipSession::TimerExpiredL
       
  2179 // -----------------------------------------------------------------------------
       
  2180 //
       
  2181 void CMceSipSession::TimerExpiredL( TMceTimerId aTimerId, TAny* /*aTimerParam*/ )
       
  2182     {
       
  2183     MCESRV_DEBUG("CMceSipSession::TimerExpiredL, Entry");
       
  2184     TMceStateIndex currentState = CurrentState().Id();
       
  2185     
       
  2186     if( aTimerId == iTimer && iBody->iRefresh )
       
  2187     	{
       
  2188         TMceStateTransitionEvent event( *this, EMceSessionRefresh );
       
  2189         TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2190         if ( error != KErrNone )
       
  2191             {
       
  2192             MCESRV_DEBUG_DVALUE(
       
  2193                 "TimerExpiredL: state machine causes ERROR", error );
       
  2194             LocalErrorOccured( currentState, error );
       
  2195             }
       
  2196     	}
       
  2197     else if( aTimerId == iPendingTimer )
       
  2198         {
       
  2199         TMceStateTransitionEvent event( *this, EMceSessionPending );
       
  2200         TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2201         if ( error != KErrNone )
       
  2202             {
       
  2203             MCESRV_DEBUG_DVALUE(
       
  2204                 "TimerExpiredL: state machine causes ERROR", error );
       
  2205             LocalErrorOccured( currentState, error );
       
  2206             }
       
  2207         }
       
  2208     else
       
  2209     	{
       
  2210     	// session has expired, terminate
       
  2211     	TMceStateTransitionEvent event( *this, EMceSessionExpired );
       
  2212     	TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2213         if ( error != KErrNone )
       
  2214             {
       
  2215             MCESRV_DEBUG_DVALUE(
       
  2216                 "TimerExpiredL: state machine causes ERROR", error );
       
  2217 	        LocalErrorOccured( KMceStateTerminated, error );
       
  2218             }
       
  2219     	}
       
  2220     	
       
  2221     if ( aTimerId == iTimer )
       
  2222         {
       
  2223         iTimer = CMceTimerManager::KNoSuchTimer;
       
  2224         }
       
  2225         
       
  2226     MCESRV_DEBUG("CMceSipSession::TimerExpiredL, Exit");
       
  2227     }
       
  2228 
       
  2229 // -----------------------------------------------------------------------------
       
  2230 // CMceSipSession::UseFC
       
  2231 // -----------------------------------------------------------------------------
       
  2232 //
       
  2233 TBool CMceSipSession::UseFC()
       
  2234     {
       
  2235     return iUseFC;
       
  2236     }
       
  2237 
       
  2238 // -----------------------------------------------------------------------------
       
  2239 // CMceSipSession::FCReceivedData
       
  2240 // -----------------------------------------------------------------------------
       
  2241 //
       
  2242 void CMceSipSession::FCReceivedData( HBufC8* aData, 
       
  2243                                      const CFCSession* /*aFCSession*/ )
       
  2244     {
       
  2245 
       
  2246     MCESRV_DEBUG("CMceSipSession::FCReceivedData, Entry");
       
  2247     
       
  2248     TMceIds ids;
       
  2249     ids.iCallbackID = EMceItcFCMsgReceived;
       
  2250 	            
       
  2251     TRAPD( error, SendToClientL( ids, aData, NULL ) );
       
  2252     if ( error != KErrNone )
       
  2253         {
       
  2254         delete aData;
       
  2255         }
       
  2256 
       
  2257     MCESRV_DEBUG("CMceSipSession::FCReceivedData, Exit");
       
  2258     }
       
  2259 
       
  2260 // -----------------------------------------------------------------------------
       
  2261 // CMceSipSession::FCErrorNotify
       
  2262 // -----------------------------------------------------------------------------
       
  2263 //
       
  2264 void CMceSipSession::FCErrorNotify( TInt aErrCode, 
       
  2265                                     const CFCSession* /*aFCSession*/ )
       
  2266     {
       
  2267     TMceIds ids;
       
  2268     ids.iCallbackID = EMceItcFCErrorReceived;
       
  2269     ids.iStatus = aErrCode;
       
  2270     SendToClient( ids );
       
  2271     }
       
  2272 
       
  2273 // -----------------------------------------------------------------------------
       
  2274 // CMceSipSession::InviteForkedL
       
  2275 // -----------------------------------------------------------------------------
       
  2276 //
       
  2277 void CMceSipSession::InviteForkedL( CSIPClientTransaction& aTransaction,
       
  2278           		                    CSIPInviteDialogAssoc* aDialogAssoc )
       
  2279     {
       
  2280     __ASSERT_ALWAYS( aDialogAssoc, User::Leave( KErrArgument ) );
       
  2281     iForkedDialogs.AppendL( aDialogAssoc );
       
  2282     ResponseReceivedWithinDialog( aTransaction, *aDialogAssoc );
       
  2283     }
       
  2284 
       
  2285 // -----------------------------------------------------------------------------
       
  2286 // CMceSipSession::HandleForkedDialogs
       
  2287 // -----------------------------------------------------------------------------
       
  2288 //
       
  2289 void CMceSipSession::HandleForkedDialogs()
       
  2290     {
       
  2291     
       
  2292     // If one of the forked dialogs generated final response,
       
  2293     // replace the actual dialog with that
       
  2294     CSIPInviteDialogAssoc* forkedDlg = NULL;
       
  2295     CSIPDialog::TState forkedDlgState = ( CSIPDialog::TState )( KErrNotFound );
       
  2296     for ( TInt ind = 0; ind < iForkedDialogs.Count(); ind++ )
       
  2297         {
       
  2298         forkedDlg = iForkedDialogs[ ind ];
       
  2299         forkedDlgState = forkedDlg->Dialog().State();
       
  2300         if ( forkedDlgState == CSIPDialog::EConfirmed || 
       
  2301              forkedDlgState == CSIPDialog::ETerminated )
       
  2302             {
       
  2303             CSIPInviteDialogAssoc* origDlg = static_cast<CSIPInviteDialogAssoc*>( iDialog );
       
  2304             iDialog = forkedDlg;
       
  2305             iForkedDialogs.Remove( ind );
       
  2306             iForkedDialogs.Insert( origDlg,ind );
       
  2307             }
       
  2308         }
       
  2309     }
       
  2310 
       
  2311 // -----------------------------------------------------------------------------
       
  2312 // CMceSipSession::WaitingMediaCallback
       
  2313 // -----------------------------------------------------------------------------
       
  2314 //
       
  2315 TBool CMceSipSession::WaitingMediaCallback() const
       
  2316     {
       
  2317     return iWaitingMediaCallback;
       
  2318     }
       
  2319 
       
  2320 // -----------------------------------------------------------------------------
       
  2321 // CMceSipSession::SetWaitingMediaCallback
       
  2322 // -----------------------------------------------------------------------------
       
  2323 //
       
  2324 void CMceSipSession::SetWaitingMediaCallback( TBool aWaiting )
       
  2325     {
       
  2326     iWaitingMediaCallback = aWaiting;
       
  2327     }
       
  2328 
       
  2329 // -----------------------------------------------------------------------------
       
  2330 // CMceSipSession::SetMediaAuthorizationToken
       
  2331 // -----------------------------------------------------------------------------
       
  2332 //
       
  2333 void CMceSipSession::SetMediaAuthorizationToken( HBufC8* aToken )
       
  2334     {
       
  2335     delete iMediaAuthorizationToken;
       
  2336     iMediaAuthorizationToken = aToken;
       
  2337     }
       
  2338 
       
  2339 // -----------------------------------------------------------------------------
       
  2340 // CMceSipSession::Extensions
       
  2341 // -----------------------------------------------------------------------------
       
  2342 //
       
  2343 CMceSipExtensions& CMceSipSession::Extensions()
       
  2344     {
       
  2345     return *iExtensions;
       
  2346     }
       
  2347 
       
  2348 // -----------------------------------------------------------------------------
       
  2349 // CMceSipSession::MediaAuthorizationToken
       
  2350 // -----------------------------------------------------------------------------
       
  2351 //
       
  2352 HBufC8* CMceSipSession::MediaAuthorizationToken() const
       
  2353     {
       
  2354     return iMediaAuthorizationToken;    
       
  2355     }
       
  2356 
       
  2357 // -------------------------------------------------------------------------------
       
  2358 // CMceSipSession::NoPrackReceived
       
  2359 // -------------------------------------------------------------------------------
       
  2360 //
       
  2361 void CMceSipSession::NoPrackReceived( CSIPServerTransaction& aTransaction )
       
  2362     {
       
  2363     if ( Request() == aTransaction )
       
  2364         {
       
  2365         MCESRV_DEBUG("CMceSipSession::NoPrackReceived");
       
  2366         TMceStateTransitionEvent event( *this, EMceNoPrackReceived );
       
  2367         
       
  2368         TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2369         if ( error != KErrNone )
       
  2370             {
       
  2371             MCESRV_DEBUG_DVALUE(
       
  2372             "SessionClosed: state machine causes ERROR", error );
       
  2373             LocalErrorOccured( KMceStateError, error );
       
  2374             }
       
  2375         MCESRV_DEBUG("CMceSipSession::NoPrackReceived, Exit");              
       
  2376         }
       
  2377     }
       
  2378 
       
  2379 // -------------------------------------------------------------------------------
       
  2380 // CMceSipSession::ReliableFailed
       
  2381 // -------------------------------------------------------------------------------
       
  2382 //
       
  2383 void CMceSipSession::ReliableFailed( CSIPServerTransaction& aTransaction,
       
  2384 									 TInt aError )
       
  2385 	{
       
  2386     MCESRV_DEBUG("CMceSipSession::ReliableFailed, Entry");
       
  2387     MCESRV_DEBUG_DVALUE("error", aError );
       
  2388     
       
  2389     if ( Request() == aTransaction )
       
  2390         {
       
  2391         TMceStateTransitionEvent event( *this, EMceReliableFailed, aError );
       
  2392      
       
  2393         TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2394         if ( error != KErrNone )
       
  2395             {
       
  2396             MCESRV_DEBUG_DVALUE(
       
  2397             "SessionClosed: state machine causes ERROR", error );
       
  2398             LocalErrorOccured( KMceStateError, error );
       
  2399             }
       
  2400         MCESRV_DEBUG("CMceSipSession::ReliableFailed, Exit");       
       
  2401         }              
       
  2402     }
       
  2403     
       
  2404 // -------------------------------------------------------------------------------
       
  2405 // CMceSipSession::SetRSeq 
       
  2406 // -------------------------------------------------------------------------------
       
  2407 //
       
  2408 void CMceSipSession::SetRSeq( TUint aRSeq )
       
  2409     {
       
  2410     if ( aRSeq )
       
  2411         {
       
  2412         iRSeq = aRSeq;        
       
  2413         }
       
  2414     }
       
  2415 
       
  2416 // -------------------------------------------------------------------------------
       
  2417 // CMceSipSession::RSeq  
       
  2418 // -------------------------------------------------------------------------------
       
  2419 //
       
  2420 TInt CMceSipSession::RSeq()
       
  2421     {
       
  2422     return iRSeq;
       
  2423     }
       
  2424 
       
  2425 // -------------------------------------------------------------------------------
       
  2426 // CMceSipSession::DoAutoEventL  
       
  2427 // -------------------------------------------------------------------------------
       
  2428 //    
       
  2429 void CMceSipSession::DoAutoEventL( TMceStateTransitionEvent& aEvent )
       
  2430     {         
       
  2431     CMceMsgBase* msg = &aEvent.ParamClientMessage();
       
  2432     TMceIds emptyIds;
       
  2433     TMceIds* ids = &aEvent.ParamIDs();
       
  2434     ids = ids != NULL ? ids : &emptyIds;
       
  2435     if ( msg )
       
  2436         {
       
  2437         DoServiceL( *ids, static_cast<TMceItcFunctions>( aEvent.Code() ), *msg );
       
  2438         }
       
  2439     else
       
  2440         {
       
  2441         DoServiceL( *ids, static_cast<TMceItcFunctions>( aEvent.Code() ) );
       
  2442         }
       
  2443     }
       
  2444  
       
  2445 // -------------------------------------------------------------------------------
       
  2446 // CMceSipSession::AddRemoteUriL  
       
  2447 // -------------------------------------------------------------------------------
       
  2448 //    
       
  2449 void CMceSipSession::AddRemoteUriL( const CUri8& aRemoteUri )  
       
  2450     {
       
  2451     MCESRV_DEBUG("CMceSipSession::AddRemoveUriL, Entry");       
       
  2452    
       
  2453     TInt uriFound = FindRemoteUri( aRemoteUri );
       
  2454     
       
  2455     User::LeaveIfError( uriFound == KErrNotFound ? KErrNone : KErrAlreadyExists );
       
  2456    
       
  2457     CUri8* remoteUri = CUri8::NewLC( aRemoteUri.Uri() );
       
  2458     iRemoteUri.AppendL( remoteUri ); 	
       
  2459     CleanupStack::Pop();   
       
  2460     RDebug::Print(_L("CMceSipSession::AddRemoveUriL, iRemoteUri.Count()=%d"),iRemoteUri.Count() );
       
  2461 	MCESRV_DEBUG("CMceSipSession::AddRemoveUriL, Exit");       
       
  2462     }
       
  2463 
       
  2464 // -------------------------------------------------------------------------------
       
  2465 // CMceSipSession::FindRemoteUri  
       
  2466 // -------------------------------------------------------------------------------
       
  2467 // 
       
  2468 TInt CMceSipSession::FindRemoteUri( const CUri8& aRemoteUri )
       
  2469     {
       
  2470     MCESRV_DEBUG("CMceSipSession::FindRemoteUri, Entry"); 
       
  2471           
       
  2472     TInt ret = KErrNotFound;
       
  2473     
       
  2474     for( TInt i=0; ( i<iRemoteUri.Count() ) && ( ret==KErrNotFound ); i++ )
       
  2475         {
       
  2476         if( MceSip::CompareUri( aRemoteUri, *iRemoteUri[i] ) == KErrNone )
       
  2477             {
       
  2478             ret = i; 
       
  2479             RDebug::Print(_L("CMceSipSession::FindRemoteUri,i=%d"), i);    
       
  2480             }
       
  2481         }
       
  2482         
       
  2483     MCESRV_DEBUG("CMceSipSession::FindRemoteUri, Exit"); 
       
  2484           
       
  2485     return ret;
       
  2486     }
       
  2487 
       
  2488 // -------------------------------------------------------------------------------
       
  2489 // CMceSipSession::AddRemoteUriFromResponseL
       
  2490 // -------------------------------------------------------------------------------
       
  2491 //  
       
  2492 void CMceSipSession::AddRemoteUriFromResponseL( 
       
  2493     CSIPResponseElements& aResponseElements )
       
  2494     {
       
  2495     MCESRV_DEBUG("CMceSipSession::AddRemoteUriFromResponseL, Entry");       
       
  2496 
       
  2497    	CSIPHeaderBase* contact = MceSip::FindHeader( 
       
  2498    	    aResponseElements.MessageElements(), 
       
  2499    	    SIPStrings::StringF( SipStrConsts::EContactHeader ) );
       
  2500 	
       
  2501     User::LeaveIfError( contact ? KErrNone : KErrNotFound );
       
  2502 
       
  2503     const CUri8& uri = static_cast< CSIPContactHeader* >( contact )->
       
  2504 							SIPAddress()->Uri8();
       
  2505 							
       
  2506     AddRemoteUriL( uri );                            
       
  2507     
       
  2508     MCESRV_DEBUG("CMceSipSession::AddRemoteUriFromResponseL, Exit");       
       
  2509     }
       
  2510 
       
  2511 // -------------------------------------------------------------------------------
       
  2512 // CMceSipSession::ClearRemoteUri
       
  2513 // -------------------------------------------------------------------------------
       
  2514 // 
       
  2515 void CMceSipSession::ClearRemoteUri( const TMceStateIndex aState )
       
  2516     {
       
  2517     MCESRV_DEBUG("CMceSipSession::ClearRemoteUri, Entry");       
       
  2518 
       
  2519     if ( aState == KMceStateEstablished || 
       
  2520          aState == KMceStateTerminated ||
       
  2521          aState == KMceStateUpdated )
       
  2522         {
       
  2523         RDebug::Print(_L("CMceSipSession::ClearRemoteUri, aState=%d"), aState);       
       
  2524         RDebug::Print(_L("CMceSipSession::ClearRemoteUri, iRemoteUri.Count=%d"),
       
  2525         			  iRemoteUri.Count());       
       
  2526 
       
  2527         iRemoteUri.ResetAndDestroy(); 
       
  2528         }
       
  2529     MCESRV_DEBUG("CMceSipSession::ClearRemoteUri, Exit");       
       
  2530     }
       
  2531 
       
  2532 // -----------------------------------------------------------------------------
       
  2533 // CMceSipSession::ForceSDPSendingStatus
       
  2534 // -----------------------------------------------------------------------------
       
  2535 //
       
  2536 TBool CMceSipSession::ForceSDPSendingStatus()
       
  2537 	{
       
  2538 	return 	iForceSDPSending;
       
  2539 	}
       
  2540 
       
  2541 // -----------------------------------------------------------------------------
       
  2542 // CMceSipSession::PrevOfferSafeDelete
       
  2543 // -----------------------------------------------------------------------------
       
  2544 //
       
  2545 void CMceSipSession::PrevOfferSafeDelete()
       
  2546     {
       
  2547     if ( iPrevOffer && iPrevOffer != iOffer )
       
  2548 	    {
       
  2549 	    MCE_DELETE( iPrevOffer );
       
  2550 	    }
       
  2551     }
       
  2552 
       
  2553 // -----------------------------------------------------------------------------
       
  2554 // CMceSipSession::PreviousState
       
  2555 // -----------------------------------------------------------------------------
       
  2556 //
       
  2557 TUint CMceSipSession::PreviousState()    
       
  2558 	{
       
  2559 	return iPreviousState;	
       
  2560 	}   
       
  2561 
       
  2562 // -----------------------------------------------------------------------------
       
  2563 // CMceSipSession::ServerInitializedL
       
  2564 // -----------------------------------------------------------------------------
       
  2565 //
       
  2566 void CMceSipSession::ServerInitializedL()
       
  2567 	{
       
  2568 	TMceStateTransitionEvent event( *this, EMceServerInitialized );
       
  2569     TRAPD( error, iStateMachine->ProcessL( event ) );
       
  2570     if ( error != KErrNone )
       
  2571         {
       
  2572         MCESRV_DEBUG_DVALUE( "ServerInitializedL: state machine causes ERROR",
       
  2573         					 error );
       
  2574         LocalErrorOccured( KMceStateError, error );
       
  2575         }
       
  2576 	}
       
  2577 
       
  2578 // -----------------------------------------------------------------------------
       
  2579 // CMceSipSession::ContinueHandlingIncomingSessionL
       
  2580 // -----------------------------------------------------------------------------
       
  2581 //
       
  2582 void CMceSipSession::ContinueHandlingIncomingSessionL()
       
  2583 	{
       
  2584 	FCActions().PeekFCDocumentL( *Offer() );
       
  2585     Actions().ClientUpdateIncomingSessionL( Request() );
       
  2586 	}
       
  2587 	
       
  2588 // -----------------------------------------------------------------------------
       
  2589 // CMceSipSession::IsSipDialogConfirmed
       
  2590 // -----------------------------------------------------------------------------
       
  2591 //	
       
  2592 TBool CMceSipSession::IsSipDialogConfirmed() const
       
  2593     {
       
  2594     TBool confirmed( EFalse );
       
  2595     if ( Dialog() )
       
  2596         {
       
  2597         confirmed = ( Dialog()->Dialog().State() == CSIPDialog::EConfirmed );
       
  2598         }
       
  2599     return confirmed;
       
  2600     }
       
  2601     
       
  2602 // -----------------------------------------------------------------------------
       
  2603 // CMceSipSession::IsNatSession
       
  2604 // -----------------------------------------------------------------------------
       
  2605 //
       
  2606 TBool CMceSipSession::IsNatSession()
       
  2607     {
       
  2608     return iNatSession;
       
  2609     }
       
  2610 	
       
  2611 TInt CMceSipSession::ForkedDialogsCount()
       
  2612 	{
       
  2613 	return iForkedDialogs.Count();
       
  2614 	}
       
  2615 //  End of File