sipvoipprovider/src/svpmosession.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2006-2010 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:  Representation of SVP Mo session         
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mcesecureoutsession.h>
       
    19 #include <badesca.h>
       
    20 #include <mccpforwardobserver.h>
       
    21 #include <uriutilscommon.h>      // TUriUtilsError
       
    22 #include <sipcodecerr.h>
       
    23 #include <crcseprofileentry.h>
       
    24 #include <crcseprofileregistry.h>
       
    25 
       
    26 #include "svpmosession.h"
       
    27 #include "svpuriparser.h"
       
    28 #include "svpforwardprovider.h"
       
    29 #include "svpsipconsts.h"
       
    30 #include "svplogger.h"
       
    31 #include "svputility.h"
       
    32 #include "svpcleanupresetanddestroy.h"
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CSVPMoSession::CSVPMoSession
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CSVPMoSession::CSVPMoSession( TUint32 aSessionExpires, 
       
    40                               TMceTransactionDataContainer& aContainer,
       
    41                               MSVPSessionObserver& aObserver, 
       
    42                               CSVPUtility& aSVPUtility,
       
    43                               CSVPRtpObserver& aRtpObserver ) 
       
    44     : CSVPSessionBase( aContainer, aObserver, aSVPUtility, aRtpObserver ),
       
    45       iSessionExpires( aSessionExpires )
       
    46     {
       
    47     SVPDEBUG1( "CSVPMoSession::CSVPMoSession In" )
       
    48     SVPDEBUG1( "CSVPMoSession::CSVPMoSession Out" )
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CSVPMoSession::ConstructL
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CSVPMoSession::ConstructL( 
       
    56     CMceManager& aMceManager, 
       
    57     CRCSEProfileEntry& aVoipProfile, 
       
    58     const CCCPCallParameters& aParameters,
       
    59     const TDesC8& aRecipient,
       
    60     TUint32& aSecurityStatus,
       
    61     CDesC8Array* aUserHeaders )
       
    62     {
       
    63     SVPDEBUG1( "CSVPMoSession::ConstructL In" )
       
    64     
       
    65     TBool userEqphone = EFalse;
       
    66     TInt err = KErrNone;
       
    67     
       
    68     __ASSERT_ALWAYS( aVoipProfile.iIds.Count(), User::Leave( KErrArgument ) );
       
    69     iSipProfileId = aVoipProfile.iIds[ 0 ].iProfileId; // save Sip profile id
       
    70     iVoIPProfileId = aVoipProfile.iId; // save VoIP profile id
       
    71     
       
    72     iSecondCallRecipient.Copy( aRecipient ); // save recipient
       
    73     SVPDEBUG2( "CSVPMoSession::ConstructL iSecondCallRecipient length: %d",
       
    74         iSecondCallRecipient.Length() )
       
    75     
       
    76     // Copy call parameters
       
    77      iCallParameters = aParameters.CloneL();
       
    78 
       
    79     // create SIP and ProfileRegistry for URI handling
       
    80     CSIP* sip = CSIP::NewL( KSVPUid, *this );
       
    81     CleanupStack::PushL( sip );
       
    82     SVPDEBUG1( "CSVPMoSession::ConstructL sip CREATED" )
       
    83 
       
    84     CSIPProfileRegistry* sipProfileRegistry = CSIPProfileRegistry::NewL( *sip, *this );
       
    85     CleanupStack::PushL( sipProfileRegistry );
       
    86     SVPDEBUG1( "CSVPMoSession::ConstructL sipProfileRegistry CREATED" )
       
    87 
       
    88     // retrieve SIP profile by using sip profile id
       
    89     CSIPProfile* profile = sipProfileRegistry->ProfileL( iSipProfileId );
       
    90     CleanupStack::PushL( profile );
       
    91 
       
    92     // Not secure call event is sent later according this 
       
    93     iCallEventToBeSent = MCCPCallObserver::ECCPSecureNotSpecified;
       
    94 
       
    95     if ( KSVPStatusNonSecure != aSecurityStatus )
       
    96         {
       
    97         // set secure status to 0 if no security mechanism found from SIP profile
       
    98         iSVPUtility.ResolveSecurityMechanismL( *profile, aSecurityStatus );
       
    99         }
       
   100     
       
   101     // Check CLIR setting and add relevant information in fromheader.
       
   102     HBufC8* fromheader = iSVPUtility.SetMoFromHeaderLC( aSecurityStatus );
       
   103     
       
   104     // check if user=phone needs to be added to outgoing INVITE
       
   105     if ( CRCSEProfileEntry::EOn == aVoipProfile.iUserPhoneUriParameter )
       
   106         {
       
   107         userEqphone = ETrue;
       
   108         }
       
   109     
       
   110     // complete sip uri according to the security status
       
   111     HBufC8* uri = CompleteUriL( aRecipient,
       
   112                                 *profile,
       
   113                                 aSecurityStatus,
       
   114                                 userEqphone );
       
   115     CleanupStack::PushL( uri );
       
   116     
       
   117     // Add P-Preferred-Identity header if CLIR is on  
       
   118     if ( iSVPUtility.IsCLIROnL() )
       
   119         {
       
   120         HBufC8* userAor = NULL;
       
   121         const MDesC8Array* aors( NULL ); // Array of registered address of records
       
   122         
       
   123         TInt result = profile->GetParameter( KSIPRegisteredAors, aors );
       
   124         
       
   125         if ( !aors || aors->MdcaCount() == KErrNone )
       
   126             {
       
   127             SVPDEBUG1( "CSVPMoSession::CompleteUriL - registered aors array empty" )
       
   128             const TDesC8* userAorStr = NULL;
       
   129             User::LeaveIfError( profile->GetParameter( KSIPUserAor, userAorStr ) );
       
   130             SVPDEBUG2( "CSVPMoSession::CompleteUriL - KSIPUserAor result: %d", result )
       
   131             userAor = userAorStr->AllocLC();
       
   132             }
       
   133         else
       
   134             {
       
   135             userAor = aors->MdcaPoint( 0 ).AllocLC();
       
   136             }    
       
   137 
       
   138         iSVPUtility.AddPPreferredIdentityToUserHeadersL( 
       
   139             *aUserHeaders, *userAor );
       
   140         CleanupStack::PopAndDestroy(); //userAor
       
   141         }
       
   142     
       
   143     // create Mce out session 
       
   144     if ( KSVPStatusNonSecure == aSecurityStatus )
       
   145         {
       
   146         // create non-secure session
       
   147         // must be trapped, so that leave code can be changed to KErrArgument
       
   148         // if uri contains error-causing characters
       
   149         TRAP( err, iSession = CMceOutSession::NewL( aMceManager, 
       
   150                 *profile, *uri, fromheader ) );
       
   151         SVPDEBUG2( "CSVPMoSession::ConstructL NonSecure trapped: %d", err )
       
   152         
       
   153         if ( KErrNone == err )
       
   154             {
       
   155             // set iSecured flag so UI can show right icon
       
   156             iSecured = EFalse;
       
   157             }
       
   158         }
       
   159     else if ( KSVPStatusSecurePreferred == aSecurityStatus )
       
   160         {
       
   161         TRAP( err, iSession = CMceSecureOutSession::NewL(
       
   162                 aMceManager, *profile, *uri, fromheader ) );
       
   163         SVPDEBUG2( "CSVPMoSession::ConstructL SecurePreferred trapped: %d", err )
       
   164         
       
   165         if ( KErrNone == err )
       
   166             {
       
   167             // set crypto contexts
       
   168             SetCryptoContextL();
       
   169             // set secured flag to ETrue to indicate that this is secure session
       
   170             SetSecurePreferred( ETrue );
       
   171             // set iSecured flag so UI can show right icon
       
   172             iSecured = ETrue;
       
   173             }
       
   174         }
       
   175     else
       
   176         {
       
   177         TRAP( err, iSession = CMceSecureOutSession::NewL(
       
   178                 aMceManager, *profile, *uri, fromheader ) );
       
   179         SVPDEBUG2( "CSVPMoSession::ConstructL SetSecureMandatory trapped: %d", err )
       
   180         
       
   181         if ( KErrNone == err )
       
   182             {
       
   183             // set crypto contexts
       
   184             SetCryptoContextL();
       
   185             // set secure mandatory flag ETrue, only secure session allowed       
       
   186             SetSecureMandatory( ETrue );
       
   187             // set iSecured flag so UI can show right icon
       
   188             iSecured = ETrue;
       
   189             }
       
   190         }
       
   191     
       
   192     if ( KUriUtilsErrInvalidUserInfo == err ||      // -5016
       
   193          KUriUtilsErrInvalidHost == err     ||      // -5017
       
   194          KUriUtilsErrInvalidPort == err     ||      // -5018
       
   195          KUriUtilsErrInvalidHeaders == err  ||      // -5022
       
   196          KErrSipCodecTokenizer == err       ||      // -17751
       
   197          KErrSipCodecFromOrToParams == err )        // -17775
       
   198         {
       
   199         User::Leave( KErrArgument );
       
   200         }
       
   201     else if ( KErrNone != err )
       
   202         {
       
   203         User::Leave( KErrDisconnected );
       
   204         }
       
   205     else
       
   206         {
       
   207         //For PC-Lint Note: #961
       
   208         }
       
   209     
       
   210     CleanupStack::PopAndDestroy( uri );
       
   211     CleanupStack::Pop( fromheader );
       
   212     
       
   213     // Get keep-alive timer value
       
   214     TUint32 iapId = 0;
       
   215     TBool found = EFalse;
       
   216     
       
   217     profile->GetParameter( KSIPAccessPointId, iapId );
       
   218     TRAPD( errKeepAlive, found = iSVPUtility.GetKeepAliveByIapIdL( iapId, iKeepAliveValue ) );
       
   219     SVPDEBUG3( "CSVPMoSession::ConstructL:GetKeepAliveByIapIdL: errKeepAlive = %d found = %d",
       
   220             errKeepAlive, found )
       
   221     
       
   222     if ( !found )
       
   223         {
       
   224         const TDesC8* aor;
       
   225         profile->GetParameter( KSIPUserAor, aor );
       
   226         TRAP( errKeepAlive, found = iSVPUtility.GetKeepAliveByAORL( *aor, iKeepAliveValue ) );
       
   227         SVPDEBUG3( "CSVPMoSession::ConstructL:GetKeepAliveByAORL: errKeepAlive = %d found = %d",
       
   228                 errKeepAlive, found )
       
   229         }
       
   230     
       
   231     CleanupStack::PopAndDestroy( profile );
       
   232     CleanupStack::PopAndDestroy( sipProfileRegistry );
       
   233     CleanupStack::PopAndDestroy( sip );
       
   234     
       
   235     // constructs audio streams for this session and adds codecs to streams and
       
   236     // streams to session
       
   237     ConstructAudioStreamsL();
       
   238     InitializePropertyWatchingL();
       
   239     
       
   240     // Create forward provider
       
   241     iForwardProvider = CSVPForwardProvider::NewL( *this );
       
   242     iForwardAddressList = new (ELeave) CDesC8ArrayFlat( KSVPContactArrayGranularity );
       
   243     
       
   244     // Cant leave anymore, store heap data
       
   245     iUserHeaders = aUserHeaders; // save userheaders
       
   246     iMceManager = &aMceManager; // not own
       
   247     
       
   248     SVPDEBUG1( "CSVPMoSession::ConstructL Out" )
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CSVPMoSession::NewL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 CSVPMoSession* CSVPMoSession::NewL( 
       
   256     CMceManager& aMceManager,
       
   257     const TDesC8& aRecipient,
       
   258     CRCSEProfileEntry& aVoipProfile,  
       
   259     const CCCPCallParameters& aParameters,
       
   260     TMceTransactionDataContainer& aContainer,                                    
       
   261 	MSVPSessionObserver& aObserver,
       
   262 	CSVPUtility& aSVPUtility,
       
   263 	CSVPRtpObserver& aRtpObserver,
       
   264 	TUint32& aSecurityStatus,
       
   265 	CDesC8Array* aUserHeaders )
       
   266     {
       
   267     CSVPMoSession* self = new( ELeave ) CSVPMoSession(
       
   268     		aVoipProfile.iSIPSessionExpires, aContainer, aObserver,
       
   269     		aSVPUtility, aRtpObserver );
       
   270     CleanupStack::PushL( self );
       
   271     self->ConstructL( aMceManager, 
       
   272                       aVoipProfile,
       
   273                       aParameters, 
       
   274                       aRecipient, 
       
   275                       aSecurityStatus,
       
   276                       aUserHeaders );
       
   277     CleanupStack::Pop( self );
       
   278     return self;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CSVPMoSession::~CSVPMoSession
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 CSVPMoSession::~CSVPMoSession()
       
   286     {
       
   287     SVPDEBUG1( "CSVPMoSession::~CSVPMoSession In" )
       
   288    
       
   289     delete iForwardProvider;
       
   290     
       
   291     if ( iUserHeaders )
       
   292         {
       
   293         iUserHeaders->Reset();
       
   294         delete iUserHeaders;
       
   295         }
       
   296 
       
   297     if ( iForwardAddressList )
       
   298         {
       
   299         iForwardAddressList->Reset();
       
   300         delete iForwardAddressList;
       
   301         }
       
   302     
       
   303     SVPDEBUG1( "CSVPMoSession::~CSVPMoSession Out" )
       
   304     }
       
   305   
       
   306 // ---------------------------------------------------------------------------
       
   307 // CSVPMoSession::CompleteUriL
       
   308 // ---------------------------------------------------------------------------
       
   309 //  
       
   310 HBufC8* CSVPMoSession::CompleteUriL( const TDesC8& aRecipient, 
       
   311                                      const CSIPProfile& aSIPProfile,
       
   312                                      const TUint32& aSecurityStatus,
       
   313                                      TBool aUserEqualsPhoneRequired )
       
   314     {
       
   315     SVPDEBUG1( "CSVPMoSession::CompleteUriL In" )
       
   316 
       
   317     // create instance of uri parser
       
   318     CSVPUriParser* uriParser = CSVPUriParser::NewLC();
       
   319     
       
   320     HBufC8* userAor( NULL );
       
   321     const MDesC8Array* aors( NULL ); // Array of registered address of records
       
   322     
       
   323     TInt result = aSIPProfile.GetParameter( KSIPRegisteredAors, aors );
       
   324     
       
   325     if ( !aors || aors->MdcaCount() == KErrNone )
       
   326         {
       
   327         SVPDEBUG1( "CSVPMoSession::CompleteUriL - registered aors array empty" )
       
   328         const TDesC8* userAorStr = NULL;
       
   329         result = aSIPProfile.GetParameter( KSIPUserAor, userAorStr );
       
   330         SVPDEBUG2( "CSVPMoSession::CompleteUriL - KSIPUserAor result: %d", result )
       
   331         userAor = HBufC8::NewLC( userAorStr->Length() );
       
   332         userAor->Des().Copy( *userAorStr );
       
   333         }
       
   334     else
       
   335         {
       
   336         #ifdef _DEBUG
       
   337             TBuf<KSvpMaxDebugBufferSize> tmpUri;
       
   338             for ( TInt i = 0; i < aors->MdcaCount(); i++ )
       
   339                 {
       
   340                 tmpUri.Copy( aors->MdcaPoint( i ) );
       
   341                 SVPDEBUG3( "CSVPMoSession::CompleteUriL - registered AOR[%d]: %S", i, &tmpUri )
       
   342                 }
       
   343         #endif
       
   344         userAor = HBufC8::NewLC( aors->MdcaPoint( 0 ).Length() );
       
   345         userAor->Des().Copy( aors->MdcaPoint( 0 ) );
       
   346         }
       
   347     // set service id to uri parser, needed for setting user=phone
       
   348     uriParser->SetUserEqualsPhoneRequiredL( aUserEqualsPhoneRequired );
       
   349     
       
   350     // complete URI by security status preference
       
   351     HBufC8* uri = NULL;
       
   352     if ( KSVPStatusNonSecure == aSecurityStatus )
       
   353         {
       
   354         SVPDEBUG1( "CSVPMoSession::CompleteUriL Completing SIP URI..." )
       
   355         
       
   356         // user tries to call to sips: -uri, secpref -> 0
       
   357         // so iTLSNotInUse is set, so that user can be notified
       
   358         // about non secure session
       
   359         if ( KErrNotFound != aRecipient.Find( KSVPSipsPrefix ) )
       
   360         	{
       
   361         	iTLSNotInUse = ETrue;
       
   362         	}
       
   363         uri = uriParser->CompleteSipUriL( aRecipient, *userAor );
       
   364         }
       
   365     else
       
   366         {
       
   367         SVPDEBUG1( "CSVPMoSession::CompleteUriL Completing SIPS URI..." )
       
   368         uri = uriParser->CompleteSecureSipUriL( aRecipient, *userAor );
       
   369         }
       
   370     CleanupStack::PopAndDestroy( userAor );
       
   371     CleanupStack::PopAndDestroy( uriParser );
       
   372     
       
   373     SVPDEBUG1( "CSVPMoSession::CompleteUriL Out" )
       
   374     return uri;
       
   375     }
       
   376     
       
   377 
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CSVPMoSession::CreateNonSecureSessionL
       
   381 // ---------------------------------------------------------------------------
       
   382 //    
       
   383 void CSVPMoSession::CreateNonSecureSessionL( CMceManager& aMceManager )
       
   384     {
       
   385     SVPDEBUG1( "CSVPMoSession::CreateNonSecureSessionL In" )
       
   386     
       
   387     TBool userEqphone = EFalse;
       
   388     
       
   389     // save old secure session first, will be deleted later from SVPController
       
   390     delete iTempSecSession;
       
   391     iTempSecSession = iSession;
       
   392     
       
   393     // set iSecured flag so UI can show right icon
       
   394     iSecured = EFalse;
       
   395 
       
   396     // set correct event to be sent later on.
       
   397     iCallEventToBeSent = MCCPCallObserver::ECCPNotSecureCall;
       
   398 
       
   399     // clear secure preferred flag, needed when deciding whether 
       
   400     // old session should be deleted
       
   401     SetSecurePreferred( EFalse );
       
   402     
       
   403     // create SIP and ProfileRegistry for URI handling
       
   404     CSIP* sip = CSIP::NewL( KSVPUid, *this );
       
   405     CleanupStack::PushL( sip );
       
   406     CSIPProfileRegistry* sipProfileRegistry = 
       
   407         CSIPProfileRegistry::NewL( *sip, *this );
       
   408     CleanupStack::PushL( sipProfileRegistry );
       
   409     
       
   410     // retrieve SIP profile by using sip profile id
       
   411     CSIPProfile* profile = sipProfileRegistry->ProfileL( iSipProfileId );
       
   412     CleanupStack::PushL( profile );
       
   413     
       
   414     // secure preference to 0
       
   415     TUint32 securePreference = 0;
       
   416     
       
   417     RPointerArray< CRCSEProfileEntry > entryArray;
       
   418     CleanupResetAndDestroy< RPointerArray<CRCSEProfileEntry> >::PushL( entryArray );
       
   419     CRCSEProfileRegistry* reg = CRCSEProfileRegistry::NewLC();
       
   420     reg->FindByServiceIdL( iCallParameters->ServiceId(), entryArray ); // Get VoIP profile by service id
       
   421     
       
   422     // Take first entry from array
       
   423     __ASSERT_ALWAYS( entryArray.Count(), User::Leave( KErrArgument ) );
       
   424     CRCSEProfileEntry* entry = entryArray[0];
       
   425     
       
   426     // check if user=phone needs to be added to outgoing INVITE
       
   427     if ( CRCSEProfileEntry::EOn == entry->iUserPhoneUriParameter )
       
   428         {
       
   429         userEqphone = ETrue;
       
   430         }
       
   431     
       
   432     // cleanup
       
   433     CleanupStack::PopAndDestroy( 2, &entryArray );    // reg, entryArray
       
   434     
       
   435     // complete sip uri according to the security status
       
   436     HBufC8* uri = CompleteUriL( iSecondCallRecipient,
       
   437                                 *profile,
       
   438                                 securePreference,
       
   439                                 userEqphone );
       
   440     CleanupStack::PushL( uri );
       
   441     
       
   442     // nullify iSession member, but do not delete
       
   443     iSession = NULL;
       
   444     iSession = CMceOutSession::NewL( aMceManager, *profile, *uri );
       
   445     
       
   446     CleanupStack::PopAndDestroy( uri );
       
   447     CleanupStack::PopAndDestroy( profile );
       
   448     CleanupStack::PopAndDestroy( 2 ); // sip & sipProfileRegistry
       
   449     
       
   450     // constructs audio streams for this Mo session 
       
   451     // adds codecs to streams and streams to session 
       
   452     ConstructAudioStreamsL();
       
   453     
       
   454     // Dial, finally
       
   455     User::LeaveIfError( Dial() );
       
   456     
       
   457     SVPDEBUG1( "CSVPMoSession::CreateNonSecureSessionL Out" )
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CSVPMoSession::Dial
       
   462 // ---------------------------------------------------------------------------
       
   463 //    
       
   464 TInt CSVPMoSession::Dial()
       
   465     {
       
   466     SVPDEBUG1("CSVPMoSession::Dial In" )  
       
   467     
       
   468     TRAPD( errDial, DialL() );
       
   469     
       
   470     SVPDEBUG2("CSVPMoSession::Dial Out return=%d", errDial )
       
   471     return errDial;
       
   472     }
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // CSVPMoSession::DialL
       
   476 // ---------------------------------------------------------------------------
       
   477 //    
       
   478 void CSVPMoSession::DialL()
       
   479     {
       
   480     SVPDEBUG1( "CSVPMoSession::DialL In" )
       
   481     
       
   482     ExecCbCallStateChanged( MCCPCallObserver::ECCPStateDialling );
       
   483     
       
   484     // inform client about non secure session 
       
   485     if ( iTLSNotInUse )
       
   486         {
       
   487         ExecCbCallEventOccurred( MCCPCallObserver::ECCPNotSecureSessionWithSips );
       
   488         }
       
   489 
       
   490     if ( iUserHeaders && iUserHeaders->MdcaCount() )
       
   491         {
       
   492         CDesC8ArrayFlat* userHeaders = new ( ELeave ) CDesC8ArrayFlat( 
       
   493             iUserHeaders->MdcaCount() );
       
   494         CleanupStack::PushL( userHeaders ); // CS:1
       
   495         for ( TInt i = 0; i < iUserHeaders->MdcaCount(); i++ )
       
   496             {
       
   497             userHeaders->AppendL( iUserHeaders->MdcaPoint( i ) );
       
   498             }
       
   499         static_cast<CMceOutSession*>( iSession )->EstablishL( 
       
   500             iSessionExpires, userHeaders, NULL, NULL );
       
   501         CleanupStack::Pop( userHeaders ); // CS:0, ownership transferred
       
   502         }
       
   503     else
       
   504         {
       
   505         static_cast<CMceOutSession*>( iSession )->EstablishL(
       
   506             iSessionExpires, NULL, NULL, NULL );
       
   507         }
       
   508 
       
   509     // start INVITE timer in case remote end does not repond
       
   510     StartTimerL( KSVPInviteTimer, KSVPInviteTimerExpired );
       
   511     
       
   512     SVPDEBUG1( "CSVPMoSession::DialL Out" )
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // CSVPMoSession::Cancel
       
   517 // ---------------------------------------------------------------------------
       
   518 //  
       
   519 TInt CSVPMoSession::Cancel()
       
   520     {
       
   521     SVPDEBUG1( "CSVPMoSession::Cancel() Cancel dial" )
       
   522     TRAPD( cancelErr, static_cast<CMceOutSession*>( iSession )->CancelL() );
       
   523     return cancelErr;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // CSVPMoSession::HangUp
       
   528 // ---------------------------------------------------------------------------
       
   529 //  
       
   530 TInt CSVPMoSession::HangUp()
       
   531     {
       
   532     SVPDEBUG1( "CSVPMoSession::HangUp In" )
       
   533     
       
   534     if ( CMceSession::EOffering == iSession->State() )
       
   535         {
       
   536         SVPDEBUG1( "CSVPMoSession::HangUp CancelL" )
       
   537         TRAPD( err, static_cast<CMceOutSession*>( iSession )->CancelL() );
       
   538         
       
   539         ExecCbCallStateChanged( MCCPCallObserver::ECCPStateDisconnecting );
       
   540         
       
   541         if( !err )
       
   542             {
       
   543             TRAPD( errTimer, StartTimerL( KSVPMoHangupTerminatingTime,
       
   544                     KSVPHangUpTimerExpired ) );
       
   545             
       
   546             if ( errTimer )
       
   547                 {
       
   548                 SVPDEBUG2("CSVPSessionBase::HangUp - timer leave code=%d", errTimer )
       
   549                 ExecCbCallStateChanged( MCCPCallObserver::ECCPStateIdle );
       
   550                 }
       
   551             else
       
   552                 {
       
   553                 iAlreadyTerminating = ETrue;
       
   554                 }
       
   555             }
       
   556         else
       
   557             {
       
   558             ExecCbCallStateChanged( MCCPCallObserver::ECCPStateIdle );
       
   559             }
       
   560         
       
   561         SVPDEBUG2( "CSVPMoSession::HangUp Out return=%d", err )
       
   562         return err;
       
   563         }
       
   564     else
       
   565         {
       
   566         TInt status = CSVPSessionBase::HangUp();
       
   567         SVPDEBUG2( "CSVPMoSession::HangUp Out return=%d", status )
       
   568         return status;
       
   569         }
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------------------------
       
   573 // CSVPMoSession::Release
       
   574 // ---------------------------------------------------------------------------
       
   575 //  
       
   576 TInt CSVPMoSession::Release()
       
   577     {
       
   578     SVPDEBUG1( "CSVPMoSession::Release" )
       
   579     delete this;
       
   580     return KErrNone;
       
   581     }
       
   582     
       
   583 // ---------------------------------------------------------------------------
       
   584 // CSVPMoSession::Hold
       
   585 // ---------------------------------------------------------------------------
       
   586 //  
       
   587 TInt CSVPMoSession::Hold()
       
   588     {
       
   589     SVPDEBUG1( "CSVPMoSession::Hold" )
       
   590     return CSVPSessionBase::Hold();
       
   591     }
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // CSVPMoSession::Resume
       
   595 // ---------------------------------------------------------------------------
       
   596 //  
       
   597 TInt CSVPMoSession::Resume()
       
   598     {
       
   599     SVPDEBUG1( "CSVPMoSession::Resume" )
       
   600     return CSVPSessionBase::Resume();
       
   601     }
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // CSVPMoSession::IsMobileOriginated
       
   605 // ---------------------------------------------------------------------------
       
   606 //  
       
   607 TBool CSVPMoSession::IsMobileOriginated() const
       
   608     {
       
   609     SVPDEBUG1( "CSVPMoSession::IsMobileOriginated = ETrue" )
       
   610     return ETrue;
       
   611     }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // CSVPMoSession::SessionStateChangedL
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 void CSVPMoSession::SessionStateChangedL( TInt aOrigStatus,
       
   618     TCCPError aError, TInt aModStatus )
       
   619     {
       
   620     SVPDEBUG1( "CSVPMoSession::SessionStateChangedL In" )
       
   621     SVPDEBUG2( "CSVPMoSession::SessionStateChangedL aOrigStatus=%d",
       
   622         aOrigStatus )
       
   623     SVPDEBUG2( "CSVPMoSession::SessionStateChangedL aError=%d",
       
   624         aError )
       
   625     SVPDEBUG2( "CSVPMoSession::SessionStateChangedL aModStatus=%d",
       
   626         aModStatus )
       
   627 
       
   628     // Check security level, cancel secure mandatory call if the control path 
       
   629     // is unsecure and the response is 1XX or 2XX
       
   630     CMceSession::TControlPathSecurityLevel secLevel = 
       
   631         iSession->ControlPathSecurityLevel();
       
   632     
       
   633     SVPDEBUG2( "CSVPMoSession::SessionStateChangedL, security level=%d", secLevel )
       
   634     
       
   635     if ( SecureMandatory() && CMceSession::EControlPathUnsecure == secLevel )
       
   636         {
       
   637         switch ( aOrigStatus )
       
   638             {
       
   639             case KSVPRingingVal:
       
   640             case KSVPForwardedVal:
       
   641             case KSVPQueuedVal:
       
   642             case KSVPSessionProgressVal:
       
   643             case KSVPOKVal:
       
   644             case KSVPAcceptedVal:
       
   645                 {
       
   646                 SVPDEBUG1( "CSVPMoSession::SessionStateChangedL, path not secure, cancel call" )
       
   647                 HangUp();
       
   648                 ExecCbErrorOccurred( ECCPSecureCallFailed );
       
   649                 return;
       
   650                 }
       
   651             default:
       
   652                 {
       
   653                 break;
       
   654                 }
       
   655             }
       
   656         }
       
   657     
       
   658     if ( KSVPForwardedVal == aOrigStatus )
       
   659         {
       
   660         SVPDEBUG1( "CSVPMoSession::SessionStateChangedL 181 Call is Being Forwarded received" )
       
   661         
       
   662         if ( iForwardObserver )
       
   663             {
       
   664             iForwardObserver->ForwardEventOccurred(
       
   665                     MCCPForwardObserver::ECCPRemoteForwarding );
       
   666             }
       
   667         }
       
   668     
       
   669     CSVPSessionBase::SessionStateChangedL( aOrigStatus, aError, aModStatus );
       
   670     SVPDEBUG1("CSVPMoSession::SessionStateChangedL Out" )
       
   671     }
       
   672     
       
   673 // ---------------------------------------------------------------------------
       
   674 // CSVPMoSession::ForwardProviderL
       
   675 // ---------------------------------------------------------------------------
       
   676 // 
       
   677 MCCPForwardProvider* CSVPMoSession::ForwardProviderL( const MCCPForwardObserver& aObserver )
       
   678     {
       
   679     SVPDEBUG1( "CSVPMoSession::ForwardProviderL" )
       
   680     iForwardObserver = const_cast< MCCPForwardObserver* >( &aObserver );
       
   681     return iForwardProvider;
       
   682     }
       
   683 
       
   684 // ---------------------------------------------------------------------------
       
   685 // CSVPMoSession::GetForwardAddressChoicesL
       
   686 // ---------------------------------------------------------------------------
       
   687 // 
       
   688 const CDesC8Array& CSVPMoSession::GetForwardAddressChoicesL()
       
   689     {
       
   690     SVPDEBUG1( "CSVPMoSession::GetForwardAddressChoicesL" )
       
   691     return *iForwardAddressList;    
       
   692     }
       
   693     
       
   694 // ---------------------------------------------------------------------------
       
   695 // CSVPMoSession::ForwardToAddressL
       
   696 // ---------------------------------------------------------------------------
       
   697 // 
       
   698 void CSVPMoSession::ForwardToAddressL( const TInt aIndex )
       
   699     {
       
   700     SVPDEBUG1( "CSVPMoSession::ForwardToAddressL In" )
       
   701     SVPDEBUG2( "CSVPMoSession::ForwardToAddressL aIndex=%d", aIndex )
       
   702     
       
   703     if ( iForwardAddressList->MdcaCount() - 1 < aIndex ||
       
   704          KErrNone > aIndex )
       
   705         {
       
   706         SVPDEBUG1( "CSVPMoSession::ForwardToAddressL - Index err! -> Leave!" )
       
   707         User::Leave( KErrArgument );
       
   708         }
       
   709     else
       
   710         {
       
   711         SVPDEBUG1( "CSVPMoSession::ForwardToAddressL - New mce session" )
       
   712 
       
   713         // create SIP and ProfileRegistry for URI handling
       
   714         CSIP* sip = CSIP::NewLC( KSVPUid, *this );
       
   715 
       
   716         CSIPProfileRegistry* sipProfileRegistry = 
       
   717             CSIPProfileRegistry::NewLC( *sip, *this );
       
   718 
       
   719         // retrieve SIP profile by using sip profile id
       
   720         CSIPProfile* profile = sipProfileRegistry->ProfileL( iSipProfileId );
       
   721         CleanupStack::PushL( profile );
       
   722 
       
   723         RPointerArray< CRCSEProfileEntry > entryArray;
       
   724         CleanupResetAndDestroy<
       
   725              RPointerArray<CRCSEProfileEntry> >::PushL( entryArray );
       
   726 
       
   727         CRCSEProfileRegistry* reg = CRCSEProfileRegistry::NewLC();
       
   728         
       
   729         // Get VoIP profile by service id
       
   730         reg->FindByServiceIdL( iCallParameters->ServiceId(), entryArray );
       
   731         
       
   732         // Take first entry from array
       
   733         CRCSEProfileEntry* entry = entryArray[0];
       
   734        
       
   735         // check if user=phone needs to be added to outgoing INVITE     
       
   736         TBool userEqphone = EFalse;
       
   737         if ( CRCSEProfileEntry::EOn == entry->iUserPhoneUriParameter )
       
   738             {
       
   739             userEqphone = ETrue;
       
   740             }
       
   741             
       
   742         // cleanup
       
   743         CleanupStack::PopAndDestroy( 2, &entryArray );    // reg, entryArray
       
   744 
       
   745         // complete sip uri according to the security status
       
   746         HBufC8* uri = CompleteUriL( iForwardAddressList->MdcaPoint( aIndex ),
       
   747                 *profile, SecurePreferred(), userEqphone );
       
   748         CleanupStack::PushL( uri );
       
   749         
       
   750         // Delete old mce session and create a new one
       
   751         if ( iSession )
       
   752             {
       
   753             delete iSession;
       
   754             iSession = NULL;
       
   755             }
       
   756         
       
   757         TRAPD( err, iSession = CMceOutSession::NewL( *iMceManager, *profile, *uri ) );
       
   758         
       
   759         if ( KUriUtilsErrInvalidUserInfo == err ||
       
   760              KUriUtilsErrInvalidHost == err )
       
   761             {
       
   762             SVPDEBUG1( "CSVPMoSession::ForwardToAddressL KSVPBadUriError" )
       
   763             User::Leave( KErrArgument );
       
   764             }
       
   765         if ( err )
       
   766             {
       
   767             SVPDEBUG1( "CSVPMoSession::ForwardToAddressL KErrDisconnected" )
       
   768             User::Leave( KErrDisconnected );
       
   769             }
       
   770 
       
   771         // constructs audio streams for this Mo session 
       
   772         // adds codecs to streams and streams to session 
       
   773         ConstructAudioStreamsL();
       
   774 
       
   775         CleanupStack::PopAndDestroy( 4 ); // uri, profile, sipProfileRegistry, sip
       
   776         
       
   777         User::LeaveIfError( Dial() );
       
   778         
       
   779         SVPDEBUG1( "CSVPMoSession::ForwardToAddressL Out" )
       
   780         }
       
   781     }
       
   782 
       
   783 // ---------------------------------------------------------------------------
       
   784 // CSVPMoSession::AddForwardObserverL
       
   785 // ---------------------------------------------------------------------------
       
   786 // 
       
   787 void CSVPMoSession::AddForwardObserverL( const MCCPForwardObserver& aObserver )
       
   788     {
       
   789     SVPDEBUG1( "CSVPMoSession::AddForwardObserverL" )
       
   790     iForwardObserver = const_cast<MCCPForwardObserver*>( &aObserver );
       
   791     }
       
   792 
       
   793 // ---------------------------------------------------------------------------
       
   794 // CSVPMoSession::RemoveForwardObserver
       
   795 // ---------------------------------------------------------------------------
       
   796 // 
       
   797 TInt CSVPMoSession::RemoveForwardObserver( const MCCPForwardObserver& aObserver )
       
   798     {
       
   799     SVPDEBUG1( "CSVPMoSession::RemoveForwardObserver In" )
       
   800     
       
   801     TInt err = KErrNone;
       
   802     
       
   803     if ( const_cast<MCCPForwardObserver*>( &aObserver ) == iForwardObserver )
       
   804         {
       
   805         iForwardObserver = NULL;
       
   806         }
       
   807     else
       
   808         {
       
   809         err = KErrNotFound;
       
   810         }
       
   811     
       
   812     SVPDEBUG2( "CSVPMoSession::AddForwardObserverL Out return=%d", err )
       
   813     return err;
       
   814     }
       
   815 
       
   816 // ---------------------------------------------------------------------------
       
   817 // CSVPMoSession::NotifyForwardEvent
       
   818 // ---------------------------------------------------------------------------
       
   819 // 
       
   820 void CSVPMoSession::NotifyForwardEvent( TInt aEventCode )
       
   821     {
       
   822     SVPDEBUG1( "CSVPMoSession::NotifyForwardEvent In" )
       
   823     SVPDEBUG2( "CSVPMoSession::NotifyForwardEvent aEventCode=%d", aEventCode )
       
   824     
       
   825     if ( iForwardObserver )
       
   826         {
       
   827         switch ( aEventCode )
       
   828             {
       
   829             case KSVPMultipleChoicesVal:    // 300
       
   830                 {
       
   831                 iForwardObserver->ForwardEventOccurred( 
       
   832                     MCCPForwardObserver::ECCPMultipleChoices );
       
   833                 break;
       
   834                 }
       
   835             case KSVPMovedPermanentlyVal:   // 301
       
   836                 {
       
   837                 iForwardObserver->ForwardEventOccurred( 
       
   838                     MCCPForwardObserver::ECCPMovedPermanentlyEvent );
       
   839                 break;
       
   840                 }
       
   841             case KSVPMovedTemporarilyVal:   // 302
       
   842                 {
       
   843                 iForwardObserver->ForwardEventOccurred( 
       
   844                     MCCPForwardObserver::ECCPMovedTemporarily );
       
   845                 break;
       
   846                 }
       
   847             default:
       
   848                 {
       
   849                 SVPDEBUG1( "CSVPMoSession::NotifyForwardEvent unknown event" )
       
   850                 break;
       
   851                 }
       
   852             }
       
   853         }
       
   854     else
       
   855         {
       
   856         SVPDEBUG1( "CSVPMoSession::NotifyForwardEvent iForwardObserver not exists" )
       
   857         }
       
   858     
       
   859     SVPDEBUG1( "CSVPMoSession::NotifyForwardEvent Out" )
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // CSVPMoSession::AddForwardAddressL
       
   864 // ---------------------------------------------------------------------------
       
   865 // 
       
   866 TInt CSVPMoSession::AddForwardAddressL( const TDesC8& aFwdAddress )
       
   867     {
       
   868     SVPDEBUG1("CSVPMoSession::AddForwardAddressL In" )
       
   869 
       
   870     // On return, result contains count of appended forward addresses 
       
   871     // or an error code
       
   872     TInt result( 0 );
       
   873     TInt count( 0 );
       
   874 
       
   875     // Indicates length of unsearched part of string
       
   876     TInt lenRight( aFwdAddress.Length() );
       
   877     TBool ready( EFalse );
       
   878     
       
   879     while ( !ready )
       
   880         {
       
   881         TPtrC8 remainingBuf = aFwdAddress.Right( lenRight );
       
   882         
       
   883         // Search comma
       
   884         TInt offset = remainingBuf.Find( KSVPComma );
       
   885 
       
   886         if ( KErrNotFound != offset )
       
   887             {
       
   888             lenRight -= offset + 1; // Remove comma from remaining string
       
   889             }
       
   890         else
       
   891             {
       
   892             // Only one forward address remains
       
   893             offset = lenRight;
       
   894             ready = ETrue;
       
   895             }
       
   896 
       
   897         // Remove unnecessary spaces from the string
       
   898         HBufC8* address = remainingBuf.Left( offset ).AllocLC();
       
   899         TPtr8 modAddress = address->Des();
       
   900         modAddress.TrimAll();
       
   901 
       
   902         iForwardAddressList->AppendL( *address );
       
   903         CleanupStack::PopAndDestroy( address );
       
   904 
       
   905         count++;
       
   906         result = count;
       
   907         }
       
   908     
       
   909     SVPDEBUG2( "CSVPMoSession::AddForwardAddressL Out return=%d", result )
       
   910     return result;
       
   911     }
       
   912 
       
   913 // ---------------------------------------------------------------------------
       
   914 // CSVPMoSession::ResetForwardAddressChoices
       
   915 // ---------------------------------------------------------------------------
       
   916 // 
       
   917 void CSVPMoSession::ResetForwardAddressChoices()
       
   918     {
       
   919     SVPDEBUG1( "CSVPMoSession::ResetForwardAddressChoices" )
       
   920     iForwardAddressList->Reset();
       
   921     }
       
   922 
       
   923 // SIP
       
   924 
       
   925 // ---------------------------------------------------------------------------
       
   926 // CSVPMoSession::IncomingRequest
       
   927 // ---------------------------------------------------------------------------
       
   928 //  
       
   929 void CSVPMoSession::IncomingRequest( TUint32 /*aIapId*/, 
       
   930         CSIPServerTransaction* /*aTransaction*/ )
       
   931     {
       
   932     SVPDEBUG1( "CSVPMoSession::IncomingRequest" )
       
   933     }
       
   934 
       
   935 // ---------------------------------------------------------------------------
       
   936 // CSVPMoSession::TimedOut
       
   937 // ---------------------------------------------------------------------------
       
   938 //                               
       
   939 void CSVPMoSession::TimedOut( CSIPServerTransaction& /*aSIPServerTransaction*/ )
       
   940     {
       
   941     SVPDEBUG1( "CSVPMoSession::TimedOut SIPServerTransaction timed out" )
       
   942     }
       
   943 
       
   944 // ---------------------------------------------------------------------------
       
   945 // CSVPMoSession::ProfileRegistryErrorOccurred
       
   946 // ---------------------------------------------------------------------------
       
   947 //  
       
   948 void CSVPMoSession::ProfileRegistryErrorOccurred( TUint32 /*aSIPProfileId*/,
       
   949         TInt /*aError*/ )
       
   950     {
       
   951     SVPDEBUG1( "CSVPMoSession::ProfileRegistryErrorOccurred" )
       
   952     }
       
   953 
       
   954 // ---------------------------------------------------------------------------
       
   955 // CSVPMoSession::ProfileRegistryEventOccurred
       
   956 // ---------------------------------------------------------------------------
       
   957 //  
       
   958 void CSVPMoSession::ProfileRegistryEventOccurred( TUint32 /*aProfileId*/,
       
   959         TEvent /*aEvent*/ )
       
   960     {
       
   961     SVPDEBUG1( "CSVPMoSession::ProfileRegistryEventOccurred" )
       
   962     }
       
   963