multimediacommsengine/mmcesrv/mmceevent/src/mceeventrefermoestablishedstate.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 MO refer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "mceeventrefermoestablishedstate.h"
       
    23 #include "mcesipeventhelper.h"
       
    24 #include "mcesip.h"
       
    25 #include "mceeventslogs.h"
       
    26 #include <sipcontenttypeheader.h>
       
    27 #include <sipdialogassocbase.h>
       
    28 #include <sipdialog.h>
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceEventReferMoEstablishedState::CMceEventReferMoEstablishedState
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMceEventReferMoEstablishedState::CMceEventReferMoEstablishedState()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CMceEventReferMoEstablishedState::~CMceEventReferMoEstablishedState
       
    44 // Destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMceEventReferMoEstablishedState::~CMceEventReferMoEstablishedState()
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMceEventReferMoEstablishedState::ProcessReferStateL
       
    53 // Ápply concrete state.
       
    54 // Be noticed that it will be also update, unRefer
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CMceEventReferMoEstablishedState::HandleL( CMceComEvent& aEvent )
       
    58     {
       
    59     if(aEvent.PreviousAction() == EMceItcTerminateEvent)
       
    60 		{
       
    61 		// TBD: terminate REFER with SUBSCRIBE
       
    62 		}
       
    63 	else
       
    64 	    {
       
    65 	    // Other actions not supported.
       
    66 	    User::Leave( KMceEventStateError );
       
    67 	    }
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMceEventReferMoEstablishedState::HandleReceiveRequestL
       
    72 // Ápply concrete state.
       
    73 // Be noticed that it will be also Refer/Bye or Refer/Invite(update)
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CMceEventReferMoEstablishedState::HandleReceiveRequestL( 
       
    77 														CMceComEvent& aEvent )
       
    78 	{
       
    79 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishedState::HandleReceiveRequestL, Entry");
       
    80 	User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
    81 	    KErrNone : KMceEventStateError );
       
    82 	    
       
    83 	CSIPServerTransaction& serverTran = aEvent.SIPEvent().Request();
       
    84 	CSIPServerTransaction* serverTranCheck = &serverTran;
       
    85 	User::LeaveIfError( serverTranCheck ? KErrNone : KMceEventStateError );
       
    86 		 
       
    87 	//Received Notify for MO, there is no action in the previous action
       
    88     User::LeaveIfError( aEvent.PreviousAction() == KErrNotFound ?
       
    89         KErrNone : KMceEventStateError );
       
    90     
       
    91      User::LeaveIfError( CSIPDialog::EConfirmed ==
       
    92 	        aEvent.SIPEvent().Dialog()->Dialog().State() ?
       
    93 	        KErrNone : KMceEventStateError );
       
    94 	
       
    95 	User::LeaveIfError( serverTran.RequestElements() ? KErrNone : KErrCorrupt );
       
    96 	
       
    97 	//Receiving Notify and Send 200
       
    98 	//Check the Notify Subscription state so knows which state should go
       
    99 	//Observer inform the notify received, and Established
       
   100 	const CSIPMessageElements& msgElem = 
       
   101 	    serverTran.RequestElements()->MessageElements();
       
   102     
       
   103     CSIPResponseElements* response = 
       
   104         MCESIPEventHelper::ReferNotifyRequestReceivedLC( aEvent, msgElem );
       
   105     if ( response->StatusCode() == KMceSipOK )
       
   106 		{
       
   107 		if ( !aEvent.SilentSuppression() )
       
   108 		    {
       
   109 		    // Do not notify the observer, is silent suppression is on
       
   110 		    CDesC8Array* headers = 
       
   111 		        MceSip::UserHeadersToTextArrayL( 
       
   112 		                            serverTran, 
       
   113 		                            aEvent.SIPEvent().Dialog()->Dialog() );
       
   114     		CleanupStack::PushL( headers );
       
   115             HBufC8* contenttype= NULL;
       
   116             if( msgElem.ContentType() )
       
   117     	        {
       
   118     	        contenttype = msgElem.ContentType()->ToTextValueL();	
       
   119     	        }
       
   120     		
       
   121             CleanupStack::PushL( contenttype );
       
   122             HBufC8* content = msgElem.Content().AllocLC();
       
   123 
       
   124             aEvent.SIPEvent().NotifyReceivedL( headers,
       
   125     					                       contenttype,
       
   126 						                       content );
       
   127             CleanupStack::Pop( content );
       
   128 	        CleanupStack::Pop( contenttype );
       
   129 	        CleanupStack::Pop( headers );		
       
   130             }
       
   131 		TBool terminated = EFalse;
       
   132         MCESIPEventHelper::HandleSubscriptionStateHeaderL( msgElem,
       
   133                                                            terminated );
       
   134         serverTran.SendResponseL( response );
       
   135         CleanupStack::Pop( response );
       
   136         if ( terminated )
       
   137             {
       
   138             // when the subscription state is terminated
       
   139             //receive notify send 200 OK
       
   140             aEvent.EventContext().SetCurrentStateL( 
       
   141                                         aEvent, 
       
   142                                         KMceTerminatedEventStateIndex );
       
   143             //Go Terminated directly        
       
   144             if ( !aEvent.SilentSuppression() )
       
   145 		        {
       
   146 		        // Do not notify the observer, is silent suppression is on
       
   147                 aEvent.SIPEvent().ClientStateChangedL(
       
   148                                                     CMceRefer::ETerminated,
       
   149                                                     EFalse );
       
   150 		        }
       
   151             }
       
   152         else
       
   153             {
       
   154             //when subscription state is active
       
   155             aEvent.EventContext().SetCurrentStateL( 
       
   156                     	                aEvent, 
       
   157                     	                KMceEstablishedEventStateIndex );
       
   158             }
       
   159         }
       
   160 	 else
       
   161         {
       
   162             //when the notify request is bad, state doesn't change
       
   163         serverTran.SendResponseL( response );
       
   164         CleanupStack::Pop( response );
       
   165         }	
       
   166 	MCEEVENTS_DEBUG("CMceEventReferMoEstablishedState::HandleReceiveRequestL, Exit");        
       
   167 	}
       
   168 	
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMceEventReferMoEstablishedState::HandleResponseReceivedL
       
   171 // Ápply concrete state.
       
   172 // Be noticed that it will be also update, unRefer
       
   173 // -----------------------------------------------------------------------------
       
   174 //	
       
   175 void CMceEventReferMoEstablishedState::HandleResponseReceivedL( 
       
   176 												CMceComEvent& aEvent )
       
   177 	{
       
   178 	MCEEVENTS_DEBUG(
       
   179 		"CMceEventReferMoEstablishedState::HandleResponseReceivedL, Entry");
       
   180 
       
   181 	User::LeaveIfError( &aEvent.SIPEvent().Response() ?
       
   182 	    KErrNone : KMceEventStateError );
       
   183     
       
   184     const CSIPResponseElements& response = 
       
   185         *aEvent.SIPEvent().Response().ResponseElements();
       
   186     const CSIPResponseElements* responseCheck = &response;
       
   187     
       
   188     User::LeaveIfError( responseCheck ? KErrNone : KErrCorrupt );
       
   189 
       
   190     TUint statusCode = response.StatusCode();
       
   191 
       
   192 	// Only case when we should come here is when REFER's 200 OK response
       
   193 	// and the first NOTIFY message have swapped
       
   194     if ( statusCode >= KMceSipOK && statusCode < KMceSipMultipleChoices )
       
   195 	    {
       
   196         aEvent.SetPreviousAction( KErrNotFound ); 	    	
       
   197 	    }
       
   198 	else 
       
   199 		{ // Other cases are not allowed
       
   200 		MCEEVENTS_DEBUG(
       
   201 			"CMceEventReferMoEstablishedState::HandleResponseReceivedL, LEAVE!");        
       
   202 		User::Leave( KMceEventStateError );	
       
   203 		}
       
   204 	MCEEVENTS_DEBUG(
       
   205 		"CMceEventReferMoEstablishedState::HandleResponseReceivedL, Exit");   
       
   206     }
       
   207     
       
   208 //  End of File