multimediacommsengine/mmcesrv/mmceevent/src/mceeventrefermoestablishingstate.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:    MO refer is sent and waiting for response.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <sipresponseelements.h>
       
    24 #include <sipcseqheader.h>
       
    25 #include <sipsubscribedialogassoc.h>
       
    26 #include "mceeventrefermoestablishingstate.h"
       
    27 #include "mcesipeventhelper.h"
       
    28 #include "mcesip.h"
       
    29 #include "mceeventslogs.h"
       
    30 
       
    31 // ============================= LOCAL FUNCTIONS ===============================
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CMceEventReferMoEstablishingState::CMceEventReferMoEstablishingState
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceEventReferMoEstablishingState::CMceEventReferMoEstablishingState()
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMceEventReferMoEstablishingState::~CMceEventReferMoEstablishingState
       
    47 // Destructor
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CMceEventReferMoEstablishingState::~CMceEventReferMoEstablishingState()
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CMceEventReferMoEstablishingState::ProcessReferStateL
       
    56 // Ápply concrete state.
       
    57 // Be noticed that it will be also update, unRefer
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CMceEventReferMoEstablishingState::HandleL( CMceComEvent& /*aEvent*/ )
       
    61     {
       
    62     User::Leave( KMceEventStateError );
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMceEventReferMoEstablishingState::HandleReceiveRequestL
       
    67 // Ápply concrete state.
       
    68 // Be noticed that it will be also update, unRefer
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CMceEventReferMoEstablishingState::HandleReceiveRequestL(
       
    72 												CMceComEvent& aEvent )
       
    73 	{
       
    74 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishingState::HandleReceiveRequestL, Entry");
       
    75 	
       
    76 	User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
    77         KErrNone : KMceEventStateError );
       
    78 	
       
    79 	CSIPServerTransaction& serverTran = aEvent.SIPEvent().Request();
       
    80 	CSIPServerTransaction* serverTranCheck = &serverTran;
       
    81     User::LeaveIfError( serverTranCheck ? KErrNone : KMceEventStateError );
       
    82     User::LeaveIfError( serverTran.RequestElements() ? KErrNone : KErrCorrupt );	    		 
       
    83 	//Received Notify  form Mt
       
    84 	//Receiving Notify and Send 200
       
    85 	//Check the Notify Subscription state so knows which state should go
       
    86 	//Observer inform the notify received, and Established
       
    87 	const CSIPMessageElements& msgElem = 
       
    88 	    serverTran.RequestElements()->MessageElements();
       
    89     
       
    90     CSIPResponseElements* response = 
       
    91         MCESIPEventHelper::ReferNotifyRequestReceivedLC( aEvent, msgElem );
       
    92         
       
    93     if ( response->StatusCode() == KMceSipOK )
       
    94     	{
       
    95         CDesC8Array* headers = MceSip::UserHeadersToTextArrayL( 
       
    96                                     serverTran, 
       
    97                                     aEvent.SIPEvent().Dialog()->Dialog() );
       
    98         CleanupStack::PushL( headers );
       
    99         HBufC8* contenttype = NULL;
       
   100         if( msgElem.ContentType() )
       
   101     	    {
       
   102     	    contenttype= msgElem.ContentType()->ToTextValueL();
       
   103     	    }
       
   104         CleanupStack::PushL( contenttype );
       
   105         HBufC8* content = msgElem.Content().AllocLC();
       
   106     	aEvent.SIPEvent().NotifyReceivedL( headers,
       
   107     			    					   contenttype,
       
   108     									   content );
       
   109         
       
   110         CleanupStack::Pop( content );
       
   111         CleanupStack::Pop( contenttype );
       
   112         CleanupStack::Pop( headers );
       
   113         
       
   114         serverTran.SendResponseL( response );
       
   115         CleanupStack::Pop( response );		
       
   116        
       
   117         TBool terminated = EFalse;        
       
   118         MCESIPEventHelper::HandleSubscriptionStateHeaderL( msgElem, terminated );
       
   119 
       
   120         if ( terminated )
       
   121             {
       
   122             // when the subscription state is terminated
       
   123             //receive notify send 200 OK
       
   124             //if we sent notify in terminating,if not should go terminated state
       
   125             aEvent.EventContext().SetCurrentStateL( 
       
   126                                             aEvent, 
       
   127                                             KMceTerminatedEventStateIndex );
       
   128             aEvent.SIPEvent().ClientStateChangedL(
       
   129                                                 CMceEvent::ETerminated,
       
   130                                                 EFalse );        
       
   131                     
       
   132             }
       
   133         else
       
   134             {
       
   135             //when subscription state is active
       
   136             aEvent.EventContext().SetCurrentStateL( 
       
   137                                             aEvent, 
       
   138                                             KMceEstablishedEventStateIndex );
       
   139             }      
       
   140       	}
       
   141     else
       
   142       	{
       
   143         //when the notify request is bad, state doesnt change
       
   144         serverTran.SendResponseL( response );
       
   145         CleanupStack::Pop( response );
       
   146         }
       
   147 
       
   148 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishingState::HandleResponseReceivedL, Exit");        
       
   149 	}
       
   150 	
       
   151 // -----------------------------------------------------------------------------
       
   152 // CMceEventReferMoEstablishingState::HandleResponseReceivedL
       
   153 // Ápply concrete state.
       
   154 // Be noticed that it will be also update, unRefer
       
   155 // -----------------------------------------------------------------------------
       
   156 //	
       
   157 void CMceEventReferMoEstablishingState::HandleResponseReceivedL(
       
   158 														CMceComEvent& aEvent)
       
   159 	{
       
   160 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishingState::HandleResponseReceivedL, Entry");
       
   161 	    
       
   162 	CSIPClientTransaction& clientTran = aEvent.SIPEvent().Response();
       
   163 	CSIPClientTransaction* clientTranCheck = &clientTran;
       
   164 	User::LeaveIfError( clientTranCheck ? KErrNone : KMceEventStateError );
       
   165     
       
   166     const CSIPResponseElements* response = clientTran.ResponseElements();
       
   167     User::LeaveIfError( response ? KErrNone : KErrCorrupt );
       
   168     
       
   169     //Checking if getting the error after sending the Refer
       
   170 	User::LeaveIfError( aEvent.PreviousAction() == EMceItcReferEvent ?
       
   171 	    KErrNone : KMceEventStateError );
       
   172 	    
       
   173     aEvent.SetPreviousAction( KErrNotFound ); 
       
   174     
       
   175     TUint statusCode = response->StatusCode();
       
   176     if ( statusCode >= KMceSipOK )
       
   177 		{
       
   178 		// Store the CSeq header value
       
   179 		const CSIPCSeqHeader* cSeq = response->CSeqHeader();
       
   180 		User::LeaveIfError( cSeq ? KErrNone : KErrCorrupt );
       
   181 		aEvent.SetIdValue( cSeq->Seq() );
       
   182 		
       
   183 		TMceEventStateIndex nextState = KMceEstablishedEventStateIndex;
       
   184         CMceRefer::TState nextObsState = CMceRefer::EAccepted;
       
   185         TBool isResponse = ETrue;
       
   186         if ( statusCode < KMceSipMultipleChoices )
       
   187             {
       
   188             if ( aEvent.ReferType() != CMceRefer::ENoSuppression )
       
   189                 {
       
   190                 // For suppressed refer, first notify established state
       
   191                 aEvent.SIPEvent().ClientStateChangedL( nextObsState, isResponse );
       
   192                 isResponse = EFalse;
       
   193                 }
       
   194                 
       
   195             if ( aEvent.ReferType() == CMceRefer::ENoSuppression )
       
   196                 {
       
   197                 // next state is established
       
   198                 nextObsState = CMceRefer::EAccepted;
       
   199                 nextState = KMceEstablishedEventStateIndex;
       
   200                 }
       
   201             else if ( aEvent.ReferType() == CMceRefer::ESuppressed 
       
   202                 && ( MCESIPEventHelper::
       
   203                 ResolveReferTypeL( response->MessageElements() )
       
   204                 == CMceRefer::ENoSuppression ) )
       
   205                 {
       
   206                 // Remote end did not understand suppression.
       
   207                 // Notify terminated state and suppress subscription
       
   208                 // silently.
       
   209                 aEvent.SetSilentSuppressionOn();
       
   210                 nextObsState = CMceRefer::ETerminated;
       
   211                 nextState = KMceEstablishedEventStateIndex;
       
   212         	    }
       
   213             else
       
   214                 {
       
   215                 // suppressed, next state is terminated 
       
   216                 nextObsState = CMceRefer::ETerminated; 
       
   217                 nextState = KMceTerminatedEventStateIndex;
       
   218                 }
       
   219             }
       
   220         else 
       
   221             {
       
   222             nextObsState = CMceRefer::ETerminated; 
       
   223             nextState = KMceTerminatedEventStateIndex;
       
   224             }
       
   225         aEvent.SIPEvent().ClientStateChangedL( nextObsState, isResponse );
       
   226         aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   227         }
       
   228         
       
   229 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishingState::HandleResponseReceivedL, Exit");        
       
   230 	}
       
   231 
       
   232 //  End of File