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