multimediacommsengine/mmcesrv/mmceevent/src/mceeventrefermtestablishedstate.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    State for established MT refer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <sipnotifydialogassoc.h>
       
    23 #include <sipsubscriptionstateheader.h>
       
    24 #include <sipdialog.h>
       
    25 #include "mceeventrefermtestablishedstate.h"
       
    26 #include "mcesipeventhelper.h"
       
    27 #include "mcesip.h"
       
    28 #include "mceeventslogs.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceEventReferMtEstablishedState::CMceEventReferMtEstablishedState
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMceEventReferMtEstablishedState::CMceEventReferMtEstablishedState()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CMceEventReferMtEstablishedState::~CMceEventReferMtEstablishedState
       
    44 // Destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMceEventReferMtEstablishedState::~CMceEventReferMtEstablishedState()
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMceEventReferMtEstablishedState::ProcessReferStateL
       
    53 // Ápply concrete state.
       
    54 // Be noticed that it will be also update, unRefer
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CMceEventReferMtEstablishedState::HandleL( CMceComEvent& aEvent )
       
    58     {
       
    59     MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleL, Entry");
       
    60     //For Mt
       
    61     User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
    62         KErrNone : KMceEventStateError );
       
    63         
       
    64     User::LeaveIfError( aEvent.SIPEvent().Dialog()->Type() 
       
    65         == SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
    66         KErrNone : KMceEventStateError );
       
    67     
       
    68     // set subscription state and parameters
       
    69 	TMceEventStateIndex nextState = KErrNotFound;
       
    70 	CSIPSubscriptionStateHeader& subStateHeader = 
       
    71 				( static_cast< CSIPNotifyDialogAssoc* >
       
    72 				( aEvent.SIPEvent().Dialog() ) )->SubscriptionState();
       
    73 		
       
    74     switch ( aEvent.PreviousAction() )
       
    75         {
       
    76         case EMceItcNotify:
       
    77             {
       
    78             MCESIPEventHelper::SetSubsStateHeaderValueAndParamsL( 
       
    79             									aEvent, 
       
    80             								   	SipStrConsts::ENotify,
       
    81             								   	subStateHeader,	
       
    82             									KStateActive, 
       
    83             									aEvent.RefreshInterval(),
       
    84             									EFalse );
       
    85            
       
    86              
       
    87             nextState = KMceEstablishingEventStateIndex;
       
    88             break;
       
    89             }
       
    90         case EMceItcTerminateEvent:
       
    91             {
       
    92              
       
    93             MCESIPEventHelper::SetSubsStateHeaderValueAndParamsL( 
       
    94             									aEvent, 
       
    95             								   SipStrConsts::ENotify,
       
    96             								   subStateHeader,	
       
    97             								   KStateTerminated,
       
    98             								   NULL );
       
    99          
       
   100             
       
   101            
       
   102             nextState = KMceTerminatingEventStateIndex;
       
   103             break;
       
   104             }
       
   105         default:
       
   106             {
       
   107             User::Leave( KMceEventStateError );
       
   108             break;
       
   109             }
       
   110         }
       
   111     
       
   112     // message elements
       
   113     CSIPMessageElements* message = 
       
   114 	    MCESIPEventHelper::CreateMessageElementsLC( aEvent,
       
   115 	                                                SipStrConsts::ENotify );
       
   116 	
       
   117 	// send Notify
       
   118 	
       
   119     CSIPClientTransaction* transaction = 
       
   120 		( static_cast< CSIPNotifyDialogAssoc* >
       
   121 		( aEvent.SIPEvent().Dialog() ) )->SendNotifyL( message );		
       
   122 		
       
   123     CleanupStack::Pop( message );
       
   124 	CleanupStack::PushL( transaction );
       
   125 	
       
   126 	aEvent.SIPEvent().SetPendingTransactionL( transaction );
       
   127 	CleanupStack::Pop( transaction );
       
   128 	
       
   129 	aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   130 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleL, Exit");
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMceEventReferMtEstablishedState::HandleReceiveRequestL
       
   135 // Ápply concrete state.
       
   136 // Be noticed that it will be also Refer/Bye or Refer/Invite(update)
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CMceEventReferMtEstablishedState::HandleReceiveRequestL( 
       
   140 														CMceComEvent& aEvent )
       
   141 	{
       
   142 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleReceiveRequestL, Entry");
       
   143 	User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
   144 	    KErrNone : KMceEventStateError );
       
   145         
       
   146 	User::LeaveIfError( aEvent.SIPEvent().Dialog()->Type() 
       
   147         == SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
   148         KErrNone : KMceEventStateError );
       
   149     
       
   150     CSIPServerTransaction& serverTran = aEvent.SIPEvent().Request();
       
   151     CSIPServerTransaction* serverTranCheck = &serverTran;
       
   152 	User::LeaveIfError( serverTranCheck ? KErrNone : KMceEventStateError );
       
   153 	
       
   154 	//Received Subscribe from Mo there is no action in the previous action
       
   155 	User::LeaveIfError( aEvent.PreviousAction() == KErrNotFound ?
       
   156 	    KErrNone : KMceEventStateError );
       
   157 	
       
   158     User::LeaveIfError( CSIPDialog::EConfirmed ==
       
   159         aEvent.SIPEvent().Dialog()->Dialog().State() ?
       
   160         KErrNone : KMceEventStateError );
       
   161     
       
   162     User::LeaveIfError( serverTran.RequestElements() ? KErrNone : KErrCorrupt) ;
       
   163 					
       
   164 	const CSIPMessageElements& subscribeMsg = 
       
   165 	    serverTran.RequestElements()->MessageElements();
       
   166 			
       
   167 	TBool terminated = EFalse;
       
   168     CSIPResponseElements* response = 
       
   169         MCESIPEventHelper::SubscribeRequestReceivedLC( aEvent, subscribeMsg );
       
   170     
       
   171     if ( response->StatusCode() == KMceSipOK )
       
   172 		{
       
   173 
       
   174 		MCESIPEventHelper::HandleExpireHeaderL(
       
   175         								subscribeMsg,
       
   176         								terminated ); 
       
   177    
       
   178         aEvent.SIPEvent().Request().SendResponseL( response );
       
   179         
       
   180         CleanupStack::Pop( response );
       
   181         //then send Notify
       
   182 
       
   183 		CSIPNotifyDialogAssoc* dialogAssoc = 
       
   184     			static_cast <CSIPNotifyDialogAssoc* >
       
   185     			(aEvent.SIPEvent().Dialog()); 
       
   186 
       
   187 		CSIPMessageElements* notifyMsg = 
       
   188 	        MCESIPEventHelper::CreateReferNotifyMessageElementsLC( aEvent );
       
   189 		
       
   190 		CSIPSubscriptionStateHeader& subscrState = 
       
   191 		    dialogAssoc->SubscriptionState();
       
   192 		
       
   193 		TInt nextState = KErrNotFound;		
       
   194         if ( terminated )
       
   195             {
       
   196 			subscrState.SetSubStateValueL( KStateTerminated );
       
   197 			RStringF expires = SIPStrings::StringF( SipStrConsts::EExpires );
       
   198             subscrState.DeleteParam( expires );
       
   199             nextState = KMceTerminatingEventStateIndex;
       
   200             }
       
   201         else
       
   202             {
       
   203             //when subscription state is active
       
   204             subscrState.SetSubStateValueL( KStateActive );
       
   205 			subscrState.SetExpiresParameterL(aEvent.RefreshInterval());
       
   206             nextState = KMceEstablishedEventStateIndex;
       
   207 			}
       
   208         
       
   209         CSIPClientTransaction* tx = dialogAssoc->SendNotifyL( notifyMsg );
       
   210 		CleanupStack::Pop( notifyMsg );
       
   211 	    CleanupStack::PushL( tx );
       
   212 		aEvent.SIPEvent().SetPendingTransactionL( tx );
       
   213 		CleanupStack::Pop( tx );	
       
   214 		
       
   215         aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   216         }
       
   217 	else
       
   218 	  	{
       
   219 	  	// bad request
       
   220 	    aEvent.SIPEvent().Request().SendResponseL( response );
       
   221 	    CleanupStack::Pop( response );
       
   222 	    }
       
   223 
       
   224 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleReceiveRequestL, Exit");
       
   225 	}
       
   226 	
       
   227 // -----------------------------------------------------------------------------
       
   228 // CMceEventReferMtEstablishedState::HandleResponseReceivedL
       
   229 // Ápply concrete state.
       
   230 // Be noticed that it will be also update, unRefer
       
   231 // -----------------------------------------------------------------------------
       
   232 //	
       
   233 void CMceEventReferMtEstablishedState::HandleResponseReceivedL( 
       
   234 												CMceComEvent& aEvent )
       
   235     {
       
   236     MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleResponseReceivedL, Entry");
       
   237     CSIPClientTransaction& clientTran = aEvent.SIPEvent().Response();
       
   238     CSIPClientTransaction* clientTranCheck = &clientTran;;
       
   239 	User::LeaveIfError( clientTranCheck ? KErrNone : KMceEventStateError );
       
   240 		 
       
   241     User::LeaveIfError( 
       
   242         clientTran.ResponseElements() ? KErrNone : KErrCorrupt );
       
   243 	
       
   244 	// Response for first Notify comes here.
       
   245     aEvent.SetPreviousAction( KErrNotFound ); 
       
   246     TUint statusCode = clientTran.ResponseElements()->StatusCode();
       
   247     if ( statusCode >= KMceSipOK )
       
   248 		{
       
   249 		CMceRefer::TState nextClientState = CMceRefer::EPending;
       
   250 		TMceEventStateIndex nextState = KErrNotFound;
       
   251         if ( statusCode < KMceSipMultipleChoices )
       
   252             {
       
   253             nextClientState = CMceRefer::EAccepted;
       
   254             nextState = KMceEstablishedEventStateIndex;
       
   255             }
       
   256         else 
       
   257             {
       
   258             nextClientState = CMceRefer::ETerminated;
       
   259             nextState = KMceTerminatedEventStateIndex;
       
   260             }
       
   261         aEvent.SIPEvent().ClientStateChangedL( nextClientState, ETrue );
       
   262         aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   263         }
       
   264 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishedState::HandleResponseReceivedL, Exit");        
       
   265     }
       
   266     
       
   267 //  End of File