mmsharing/mmshavailability/src/musavaoptionhandler.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:   Provide interface for the client requestin availability class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musavaoptionhandler.h"
       
    20 
       
    21 #include <escapeutils.h>
       
    22 #include <siperr.h>
       
    23 #include "musunittesting.h"
       
    24 #include "musavasharedobject.h"
       
    25 #include "muslogger.h"
       
    26 #include "musavasip.h"
       
    27 #include "musavasettingsimp.h"
       
    28 #include "musavacapabilitysipagent.h"
       
    29 #include "musavacapabilityexchange.h"
       
    30 #include "musavacapabilityquery.h"
       
    31 #include "musavacapability.h"
       
    32 #include "musavacapabilityquerybase.h"
       
    33 #include "musavaterminal.h"
       
    34 #include "mussettingskeys.h"
       
    35 #include "mussettings.h"
       
    36 #include "mussesseioninformationapi.h"
       
    37 
       
    38 
       
    39 _LIT( KMusSipPrefix, "sip:" );
       
    40 _LIT( KMusTelPrefix, "tel:" );
       
    41 _LIT( KMusPlusSign, "+" );
       
    42 
       
    43 const TInt KMaxUriLength = 512;
       
    44 const TInt KMusMinDigitCountInTelNumber = 7;
       
    45 
       
    46 const TInt KMusOptionsHandlerIndex = 1;
       
    47 
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // 
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMusAvaOptionHandler* CMusAvaOptionHandler::NewL(
       
    54     MMusAvaAvailabilityObserver& aObserver,
       
    55     CMusAvaSettingsImp& aSettings )
       
    56     {
       
    57     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::NewL()" )
       
    58     CMusAvaOptionHandler* self = CMusAvaOptionHandler::NewLC(
       
    59         aObserver,
       
    60         aSettings );
       
    61     CleanupStack::Pop( self );
       
    62 
       
    63     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::NewL()" )
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // 
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CMusAvaOptionHandler* CMusAvaOptionHandler::NewLC(
       
    73     MMusAvaAvailabilityObserver& aObserver,
       
    74     CMusAvaSettingsImp& aSettings  )
       
    75     {
       
    76     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::NewLC()" )
       
    77     CMusAvaOptionHandler* self = new( ELeave ) CMusAvaOptionHandler(
       
    78         aObserver,
       
    79         aSettings );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82 
       
    83     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::NewLC()" )
       
    84     return self;
       
    85     }
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CMusAvaOptionHandler::~CMusAvaOptionHandler()
       
    93     {
       
    94     MUS_LOG(
       
    95         "mus: [MUSAVA] -> CMusAvaOptionHandler::~CMusAvaOptionHandler()" )
       
    96     if (iSharedObj )
       
    97         {
       
    98         iSharedObj->DeleteSingleton();
       
    99         }
       
   100     delete iCapabilityExchange;
       
   101     iCapabilityExchange = NULL;
       
   102     delete iSipAgent;
       
   103     iSipAgent = NULL;
       
   104 
       
   105     MUS_LOG(
       
   106         "mus: [MUSAVA] <- CMusAvaOptionHandler::~CMusAvaOptionHandler()" )
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CMusAvaOptionHandler::CMusAvaOptionHandler(
       
   115     MMusAvaAvailabilityObserver& aObserver,
       
   116     CMusAvaSettingsImp& aSettings )
       
   117     :CMusAvaAvailability( aObserver ),
       
   118     iSettings( aSettings )
       
   119     {
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // 
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CMusAvaOptionHandler::ConstructL()
       
   128     {
       
   129     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaOptionHandler::ConstructL()" )
       
   130 
       
   131     //construct capability exchange
       
   132     ConstructCapabilityExchangeL();
       
   133 
       
   134     iSharedObj = CMusAvaSharedObject::GetSingletonL();
       
   135     iSipAgent = CMusAvaCapabilitySipAgent::NewL( *iCapabilityExchange,
       
   136                                                 *iSharedObj,
       
   137                                                 iObserver );
       
   138     iSharedObj->MusAvaSip().AddAdapterL(
       
   139                             ( MMusAvaSipConnectionAdapter& ) *iSipAgent,
       
   140                             KMusOptionsHandlerIndex );
       
   141     iSharedObj->MusAvaSip().AddAdapterL(
       
   142                             ( MMusAvaSipAdapter& ) *iSipAgent, 
       
   143                             KMusOptionsHandlerIndex ); 
       
   144     
       
   145     MUS_LOG( "mus: [MUSAVA]     Check fast mode capability" )
       
   146     
       
   147     TRAPD( err,
       
   148     iFastModeCapable = 
       
   149         MultimediaSharingSettings::FastStartupModeL() == MusSettingsKeys::EFastModeOn  && 
       
   150         MultimediaSharingSettings::VideoDirectionL() == MusSettingsKeys::ETwoWayVideo &&
       
   151         MultimediaSharingSettings::CapabilityQuerySettingL() == MusSettingsKeys::EParallel );
       
   152     if ( err == KErrNoMemory )
       
   153         {
       
   154         User::Leave( err );
       
   155         }
       
   156     
       
   157     MUS_LOG2( "mus: [MUSAVA]     Fast mode check, err:%d, capable:%d", 
       
   158               err, iFastModeCapable )
       
   159     
       
   160     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::ConstructL()" )
       
   161     }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // 
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TBool CMusAvaOptionHandler::CapabilityQueryAnswered( TBool aAnswered )
       
   169     {
       
   170     MUS_LOG1( "mus: [MUSAVA]  <-> CMusAvaOptionHandler::CapabilityQueryAnswered():%d", 
       
   171               aAnswered )
       
   172     
       
   173     iCapabilityQueryAnswered = aAnswered ? aAnswered : iCapabilityQueryAnswered;
       
   174     
       
   175     HandleFastModeQueryAnswered();
       
   176     
       
   177     return iCapabilityQueryAnswered;
       
   178         
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // 
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CMusAvaOptionHandler::ConstructCapabilityExchangeL()
       
   186     {
       
   187     MUS_LOG(
       
   188     "mus: [MUSAVA]  -> CMusAvaOptionHandler::ConstructCapabilityExchangeL()" )
       
   189     HBufC8* terminalId = ConstructTerminalIdL();
       
   190     CleanupStack::PushL( terminalId );
       
   191 
       
   192     //create capability exchange
       
   193     iCapabilityExchange =
       
   194         CMusAvaCapabilityExchange::NewL( *terminalId, *this );
       
   195 
       
   196     //create SWIS capability
       
   197     CMusAvaCapability* capability = CMusAvaCapability::NewL(
       
   198                                                     *iCapabilityExchange );
       
   199     CleanupStack::PushL( capability );
       
   200     iCapabilityExchange->AddCapabilityL( capability );
       
   201     CleanupStack::Pop( capability );
       
   202 
       
   203     iSwisCapability = capability;
       
   204 
       
   205     CleanupStack::PopAndDestroy( terminalId );
       
   206     MUS_LOG(
       
   207     "mus: [MUSAVA]  <- CMusAvaOptionHandler::ConstructCapabilityExchangeL()" )
       
   208     }
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // @TODO: Currently terminal id is not in use i.e User-Agent header is not
       
   213 // sent in request nor response.
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 HBufC8* CMusAvaOptionHandler::ConstructTerminalIdL()
       
   217     {
       
   218     return KNullDesC8().AllocL();
       
   219     }
       
   220        	
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 //  Starts the loopy execution.
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CMusAvaOptionHandler::DoExecuteL()
       
   227     {
       
   228     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaOptionHandler::DoExecuteL()" )
       
   229     
       
   230     MusSettingsKeys::TOperatorVariant variantSetting = 
       
   231         MultimediaSharingSettings::OperatorVariantSettingL();
       
   232     
       
   233     /*
       
   234      Do not resent the OPTIONS request in the below scenario
       
   235      i) Options Sent and waiting for Response.
       
   236      ii) We already sent OPTIONS and got positive response.So we know that
       
   237          other device is VS capable.
       
   238      iii) We already sent OPTIONS and got negative response.So we know that
       
   239          other device is VS incapable.
       
   240 
       
   241     Also OPTIONS should be sent only once if it matches to VS Call criteria.
       
   242     */
       
   243     MUS_LOG1( "mus: [MUSAVA]  - Current State %d",State() )
       
   244 
       
   245     if ( State() == MMusAvaObserver::EMusAvaStatusOptionsSent ||
       
   246          State() == MMusAvaObserver::EMusAvaStatusAvailable ||
       
   247          State() == MMusAvaObserver::EMusAvaOptionNotAvailable )
       
   248         {
       
   249         return;
       
   250         }
       
   251         
       
   252     if ( variantSetting == MusSettingsKeys::EOperatorSpecific 
       
   253         && iSettings.CallDirection() == 2 && !iCapabilitiesRequestAnswered )
       
   254         { // terminated party 
       
   255         DoSetState( MMusAvaObserver::EMusAvaStatusOptionsNotSent );
       
   256         }
       
   257     else if ( MusSettingsKeys::ESequential ==  
       
   258      	        MultimediaSharingSettings::CapabilityQuerySettingL()
       
   259         && iSettings.CallDirection() == 2 && !iCapabilitiesRequestAnswered )
       
   260         { // terminated party 
       
   261         DoSetState( MMusAvaObserver::EMusAvaStatusOptionsNotSent );
       
   262         }
       
   263     else
       
   264         {
       
   265         if ( MusSettingsKeys::EOperatorSpecific == variantSetting ||
       
   266              MusSettingsKeys::EParallel ==  
       
   267      	     	MultimediaSharingSettings::CapabilityQuerySettingL() || 
       
   268      	     MusSettingsKeys::ESequential ==  
       
   269      	        MultimediaSharingSettings::CapabilityQuerySettingL() )
       
   270     	    {
       
   271     	    const MDesCArray& addresses = iSettings.SipAddresses();
       
   272 
       
   273     	    TInt addressesCount = addresses.MdcaCount();
       
   274     	    MUS_LOG1( "mus: [MUSAVA]    addresses.MdcaCount() %d", 
       
   275     	        addressesCount )
       
   276     	    if( addressesCount )
       
   277     	        {
       
   278     	        const TDesC& sipAddress = addresses.MdcaPoint( 0 );
       
   279     	        MUS_LOG_TDESC( "mus: [MUSAVA]       SIP Address: ", 
       
   280     	            sipAddress )
       
   281     	     	TRAPD( err, iSipAgent->ExecuteCapabilityQueryL( 
       
   282     	     	    *iSwisCapability, sipAddress ) );                               
       
   283 	    	    // set status available and report to the observer
       
   284     		    if ( err == KErrNone )
       
   285     		    	{
       
   286     	    	    HBufC8* sipAddress8 = 
       
   287     	    	        EscapeUtils::ConvertFromUnicodeToUtf8L( sipAddress );
       
   288                     CleanupStack::PushL( sipAddress8 );
       
   289                     if ( iCapabilityExchange->
       
   290                         TerminalL( sipAddress8->Des() ).QueryExecuting() )
       
   291                         {
       
   292                         DoSetState( MMusAvaObserver::EMusAvaStatusOptionsSent );
       
   293                         }
       
   294     		    	else
       
   295     		    	    {
       
   296     		    	    DoSetState( MMusAvaObserver::EMusAvaStatusAvailable );	
       
   297     		            }
       
   298     		        CleanupStack::PopAndDestroy( sipAddress8 );
       
   299     		    	}
       
   300                 // when profile is in when needed mode and registration still on
       
   301                 // going we get this error and wait untill registration is successful
       
   302                 // since we did not send any options set the state EMusAvaStatusNotExecuted.
       
   303                 else if( err == KErrSIPInvalidRegistrationState )
       
   304                     {
       
   305                     DoSetState( MMusAvaObserver::EMusAvaStatusNotExecuted );
       
   306                     }
       
   307                 // anything other than this should be considered default , means options sent
       
   308                 // and was not successful.
       
   309     		    else
       
   310     		        {
       
   311     		        DoSetState( MMusAvaObserver::EMusAvaOptionNotAvailable );
       
   312     		        }
       
   313     	        }
       
   314     	    else
       
   315     	    	{
       
   316     	    	DoSetState( MMusAvaObserver::EMusAvaStatusOptionsNotSent );	
       
   317     	    	}
       
   318         	}
       
   319         else
       
   320         	{
       
   321         	// option sending not needed 
       
   322         	DoSetState( MMusAvaObserver::EMusAvaStatusOptionsNotSent );
       
   323         	}  
       
   324         }
       
   325     
       
   326     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::DoExecuteL()" )
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 //  Stops executing availability.
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CMusAvaOptionHandler::Stop()
       
   335     {
       
   336     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaOptionHandler::Stop()" )
       
   337     // TBD
       
   338     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::Stop()" )
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 //  Returns name of *this* availability.
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 MMusAvaObserver::TAvailabilityName CMusAvaOptionHandler::Name()
       
   347     {
       
   348     return MMusAvaObserver::EMusAvaOptionHandler;
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 void CMusAvaOptionHandler::PrepareForReceivedInviteL()
       
   356     {
       
   357     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaOptionHandler::PrepareForReceivedInviteL()" )
       
   358     
       
   359     if ( iFastModeAvailabilityDelayed )
       
   360         {
       
   361         MUS_LOG( "mus: [MUSAVA]     Set delayed availability" )
       
   362         SetState( MMusAvaObserver::EMusAvaStatusAvailable );
       
   363         iFastModeAvailabilityDelayed = EFalse;
       
   364         }
       
   365     
       
   366     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::PrepareForReceivedInviteL()" )
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // 
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CMusAvaOptionHandler::CapabilitiesResolved(
       
   374                             const CMusAvaCapabilityQueryBase& aSentQuery )
       
   375     {
       
   376     MUS_LOG(
       
   377         "mus: [MUSAVA]  -> CMusAvaOptionHandler::CapabilitiesResolved()" )
       
   378     if ( aSentQuery.Result() == KCapabilityCapabilitesReady )
       
   379         {
       
   380         // tell the upper layer that
       
   381         // query was succesfull. VS is available
       
   382         DoSetState( MMusAvaObserver::EMusAvaStatusAvailable );
       
   383         }
       
   384     else if ( aSentQuery.Result() == KCapabilityCapabilitiesForbidden )
       
   385         {
       
   386         // query returned with response "403 Forbidden". VS is NOT available
       
   387         DoSetState( MMusAvaObserver::EMusAvaFailureCode );
       
   388         }
       
   389     else
       
   390         {
       
   391         //query failed. VS is NOT available
       
   392         DoSetState( MMusAvaObserver::EMusAvaOptionNotAvailable );
       
   393         }
       
   394 
       
   395     MUS_LOG(
       
   396         "mus: [MUSAVA]  <- CMusAvaOptionHandler::CapabilitiesResolved()" )
       
   397     }
       
   398 
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // 
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 void CMusAvaOptionHandler::CapabilitiesResolvedL( const TDesC& aUri )
       
   405     {
       
   406     MUS_LOG(
       
   407         "mus: [MUSAVA]  -> CMusAvaOptionHandler::CapabilitiesResolvedL()" )
       
   408     if ( aUri.Length() > 0 )
       
   409         {
       
   410         // Set the sip address resolved from succesfull OPTIONS response
       
   411         // Old adress(es) are destroyed
       
   412         CDesCArrayFlat* sipAddresses = new( ELeave ) CDesCArrayFlat( 1 );
       
   413         CleanupStack::PushL( sipAddresses );
       
   414          
       
   415         sipAddresses->AppendL( aUri );
       
   416         iSettings.SetSipAddressesL( *sipAddresses );
       
   417         
       
   418         MUS_LOG_TDESC( "mus: [MUSAVA]       SIP Address: ", aUri )       
       
   419         
       
   420         sipAddresses->Reset();
       
   421         CleanupStack::PopAndDestroy( sipAddresses );
       
   422         }
       
   423 
       
   424     MUS_LOG(
       
   425         "mus: [MUSAVA]  <- CMusAvaOptionHandler::CapabilitiesResolvedL()" )
       
   426     }
       
   427 
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // 
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 void CMusAvaOptionHandler::SetCapabilitiesResolvedForCingular()
       
   434     {
       
   435     MUS_LOG(
       
   436         "mus: [MUSAVA]  -> CMusAvaOptionHandler::\
       
   437         SetCapabilitiesResolvedForCingular()" )
       
   438     iCapabilitiesRequestAnswered = ETrue;
       
   439     
       
   440     TRAPD( error, DoExecuteL() );
       
   441     if ( error )
       
   442         {
       
   443         MUS_LOG1( "mus: [MUSAVA]  <- CMusAvaOptionHandler::\
       
   444         SetCapabilitiesResolvedForCingular() leave code = %d", error )
       
   445         }
       
   446     else
       
   447         {
       
   448         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaOptionHandler::\
       
   449         SetCapabilitiesResolvedForCingular()" )
       
   450         }
       
   451     }
       
   452 
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // 
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 TBool CMusAvaOptionHandler::CapabilitiesResolvedForCingular()
       
   459     {
       
   460     MUS_LOG(
       
   461     "mus: [MUSAVA]  CMusAvaOptionHandler::CapabilitiesResolvedForCingular()" )
       
   462     return iCapabilitiesRequestAnswered;
       
   463     }
       
   464 
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // 
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 void CMusAvaOptionHandler::SipHeadersL(
       
   471                                    const MDesCArray& aHeaders,
       
   472                                    SipStrConsts::TStrings aHeaderType)
       
   473     {
       
   474     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::SipHeadersL()" )        
       
   475 
       
   476     // if header type is to then store in iSettings , so then future
       
   477     // request will be send there.
       
   478     if(aHeaderType == SipStrConsts::EToHeader)
       
   479         {        
       
   480         // All addresses received should be valid, so choose just one to avoid
       
   481         // situation where user has to choose one from equal addresses.
       
   482         // Prefer SIP URI, but accept also TEL URI.
       
   483         
       
   484         TBuf<KMaxUriLength> sipUri;
       
   485         TBuf<KMaxUriLength> telUri;
       
   486 
       
   487         for ( TInt i = 0; i < aHeaders.MdcaCount(); ++i )
       
   488             {
       
   489             if ( aHeaders.MdcaPoint( i ).FindF( KMusSipPrefix ) != 
       
   490                  KErrNotFound )
       
   491     	    	{
       
   492     	    	sipUri.Copy( aHeaders.MdcaPoint( i ) );
       
   493     	    	}
       
   494     	    else if ( aHeaders.MdcaPoint(i).FindF( KMusTelPrefix ) != 
       
   495     	              KErrNotFound )
       
   496     	        {
       
   497     	    	telUri.Copy( aHeaders.MdcaPoint( i ) );
       
   498     	    	}
       
   499     	    else
       
   500     	        {
       
   501     	        // NOP
       
   502     	        }
       
   503             }
       
   504         
       
   505         CDesCArray* addresses = new( ELeave ) CDesCArrayFlat( 1 );
       
   506         CleanupStack::PushL( addresses );
       
   507         
       
   508         if ( telUri.Length() > 0 )
       
   509             {
       
   510             telUri.Trim();
       
   511             addresses->AppendL( telUri );
       
   512             // Check if TEL URI conforms to phone number currently hold.
       
   513             // If they do not match, we replace phone number with one parsed
       
   514             // out of received from P-Asserted-Identity header. Since in this 
       
   515             // scenario we cannot be sure about validity of contact name either, 
       
   516             // we empty the contact name. This is only not to show incorrect 
       
   517             // information, but this solution does not show possibly existing 
       
   518             // contact name.
       
   519             
       
   520             // We compare last seven digits, since that is the minimum amount
       
   521             // that can make up a valid telephone number. 
       
   522             // Variable telUri holds also prefix, but that does not affect the
       
   523             // righthand comparison.
       
   524             
       
   525             MUS_LOG_TDESC( "mus: [MUSUI ]       iSettings.TelNumber(): ",
       
   526                            iSettings.TelNumber() )
       
   527             MUS_LOG_TDESC( "mus: [MUSUI ]       telUri: ", telUri )
       
   528             
       
   529             TPtrC16 telUriWithoutPrefix = 
       
   530                     telUri.Right( telUri.Length() - KMusTelPrefix().Length() );
       
   531             
       
   532             TPtrC16 numberPartOfTelUri = 
       
   533                     telUriWithoutPrefix.Find( KMusPlusSign ) == 0 ?
       
   534                     telUriWithoutPrefix.Right( telUriWithoutPrefix.Length() - 1 ) :
       
   535                     telUriWithoutPrefix;
       
   536                     
       
   537             if  ( !( iSettings.TelNumber().Length() >= KMusMinDigitCountInTelNumber && 
       
   538                      numberPartOfTelUri.Length() >= KMusMinDigitCountInTelNumber &&
       
   539                      iSettings.TelNumber().Right( KMusMinDigitCountInTelNumber ) ==
       
   540                             telUri.Right( KMusMinDigitCountInTelNumber ) ) )
       
   541                 {
       
   542                 iSettings.SetTelNumberL( telUriWithoutPrefix );
       
   543                 iSettings.SetContactNameL( KNullDesC() );
       
   544                 iSettings.SetContactId( KErrNotFound );              
       
   545                 }
       
   546             }
       
   547             
       
   548         if ( sipUri.Length() > 0 )
       
   549             {
       
   550             // Replace possibly existing TEL URI with SIP URI
       
   551             addresses->Reset();
       
   552             addresses->AppendL( sipUri );
       
   553             }
       
   554             
       
   555         iSettings.SetSipAddressesL( addresses ); // Transfers ownership
       
   556         CleanupStack::Pop( addresses );  
       
   557         }
       
   558     else
       
   559         {
       
   560         // should go for future need if any.
       
   561         }    
       
   562     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::SipHeadersL()" )
       
   563     }
       
   564 
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // 
       
   568 // -----------------------------------------------------------------------------
       
   569 //
       
   570 void CMusAvaOptionHandler::VideoCodecsResolvedL( const MDesCArray& aVideoCodecs )
       
   571     {
       
   572     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::VideoCodecsResolvedL()" )
       
   573     
       
   574     iSettings.SetVideoCodecsL( aVideoCodecs );
       
   575     
       
   576     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::VideoCodecsResolvedL()" )
       
   577     }
       
   578 
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // If MO side fast mode negotiation has failed, cannot change the value anymore
       
   582 // as it is very likely that automatic invitation fails as well.
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 void CMusAvaOptionHandler::FastModeResolved( MusSettingsKeys::TFastMode aMode )
       
   586     {
       
   587     MUS_LOG1("mus: [MUSAVA]  -> CMusAvaOptionHandler::FastModeResolved():%d", 
       
   588         aMode )
       
   589     
       
   590     if ( FastModeNegotiationFailedMO() )
       
   591         {
       
   592         MUS_LOG("mus: [MUSAVA]  Ignore setting as failed already" )
       
   593         }
       
   594     else
       
   595         {
       
   596         iSettings.SetFastMode( aMode );
       
   597         }
       
   598     
       
   599     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::FastModeResolved()" )
       
   600     }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // 
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 TInt CMusAvaOptionHandler::DoSetState( MMusAvaObserver::TAvailabilityStatus aNewState )
       
   607     {
       
   608     MUS_LOG1( "mus: [MUSAVA]  -> CMusAvaOptionHandler::DoSetState() state:%d", 
       
   609               aNewState )
       
   610     TInt err( KErrNone );
       
   611     
       
   612     if ( iFastModeCapable )
       
   613         {
       
   614         TRAP( err, aNewState = HandleFastModeL( aNewState  ) );
       
   615         }
       
   616     
       
   617     SetState( aNewState );
       
   618     
       
   619     MUS_LOG1("mus: [MUSAVA]  <- CMusAvaOptionHandler::DoSetState(), err:%d", err )
       
   620     
       
   621     return err;
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 // -----------------------------------------------------------------------------
       
   627 //
       
   628 MMusAvaObserver::TAvailabilityStatus CMusAvaOptionHandler::HandleFastModeL(
       
   629     MMusAvaObserver::TAvailabilityStatus aNewState )
       
   630     {
       
   631     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::HandleFastModeL()" )
       
   632     
       
   633     switch ( aNewState )
       
   634         {
       
   635         case MMusAvaObserver::EMusAvaOptionNotAvailable:
       
   636             {
       
   637             aNewState = HandleFastModeOptionNotAvailableL( aNewState );
       
   638             break;
       
   639             }
       
   640         case MMusAvaObserver::EMusAvaStatusOptionsNotSent:
       
   641             {
       
   642             aNewState = HandleFastModeOptionsNotSentL( aNewState );
       
   643             break;
       
   644             }
       
   645         case MMusAvaObserver::EMusAvaStatusAvailable:
       
   646             {
       
   647             aNewState = HandleFastModeAvailableL( aNewState );
       
   648             break;
       
   649             }
       
   650         default:
       
   651             {
       
   652             break;
       
   653             }
       
   654         }
       
   655     
       
   656     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::HandleFastModeL()" )
       
   657     
       
   658     return aNewState;
       
   659     }
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // If fast mode and call originator, application is started
       
   663 // automatically at background with two-way MO use case. If fast mode is
       
   664 // negotiated, availability publishing is delayed at MT side until invitation
       
   665 // is received (as MO will send invite automatically).
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 MMusAvaObserver::TAvailabilityStatus CMusAvaOptionHandler::HandleFastModeAvailableL(
       
   669     MMusAvaObserver::TAvailabilityStatus aNewState )
       
   670     {
       
   671     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::HandleFastModeAvailableL()" )
       
   672     
       
   673     __ASSERT_ALWAYS( iSettings.Observer(), User::Leave( KErrNotReady ) );
       
   674     
       
   675     if ( State() != MMusAvaObserver::EMusAvaStatusAvailable &&
       
   676          iSettings.FastMode() == MusSettingsKeys::EFastModeOn )
       
   677         {
       
   678         if ( iSettings.CallDirection() == NMusSessionInformationApi::ECallOrginated )
       
   679             {
       
   680             MUS_LOG("mus: [MUSAVA]      Starting application at background" )
       
   681             iSettings.Observer()->StartApplicationL( MultimediaSharing::EMusTwoWayVideo );
       
   682             }
       
   683         else
       
   684             {
       
   685             MUS_LOG("mus: [MUSAVA]      Delay availability publishing" )
       
   686             iFastModeAvailabilityDelayed = ETrue;
       
   687             aNewState = State();
       
   688             }
       
   689         }
       
   690     
       
   691     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::HandleFastModeAvailableL()" )
       
   692     
       
   693     return aNewState;
       
   694     }
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // If fast mode and call terminated side, answering to 200 ok is already enough
       
   698 // to set us available in delayed manner as other end can start sending
       
   699 // invitation already after getting fast mode information in answer. 
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 void CMusAvaOptionHandler::HandleFastModeQueryAnswered()
       
   703     {
       
   704     if ( FastModeNegotiatedByAnswerMT() )
       
   705         {
       
   706         MUS_LOG( "mus: [MUSAVA]     Set fastmode available already as answered" )
       
   707         
       
   708         // Will result delayed availability handling
       
   709         DoSetState( MMusAvaObserver::EMusAvaStatusOptionsNotSent );
       
   710         }
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // If options wasn't sent because of missing information, state can be set to
       
   715 // available immediately as MT cannot start waiting for invite unless it is
       
   716 // sure that other end is about to send it.
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 MMusAvaObserver::TAvailabilityStatus 
       
   720 CMusAvaOptionHandler::HandleFastModeOptionsNotSentL(
       
   721     MMusAvaObserver::TAvailabilityStatus aNewState )
       
   722     {
       
   723     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::HandleFastModeOptionsNotSentL()" )
       
   724     
       
   725     if ( FastModeNegotiatedByAnswerMT() )
       
   726         {
       
   727         MUS_LOG("mus: [MUSAVA]      Answered already, set available" )
       
   728         // Make available but start waiting for invitation
       
   729         aNewState = HandleFastModeAvailableL( MMusAvaObserver::EMusAvaStatusAvailable );
       
   730         }
       
   731     
       
   732     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::HandleFastModeOptionsNotSentL()" )
       
   733     
       
   734     return aNewState;
       
   735     }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 // -----------------------------------------------------------------------------
       
   740 //
       
   741 MMusAvaObserver::TAvailabilityStatus 
       
   742 CMusAvaOptionHandler::HandleFastModeOptionNotAvailableL(
       
   743     MMusAvaObserver::TAvailabilityStatus aNewState )
       
   744     {
       
   745     MUS_LOG("mus: [MUSAVA]  -> CMusAvaOptionHandler::HandleFastModeOptionNotAvailableL()" )
       
   746     
       
   747     if ( iFastModeAvailabilityDelayed || 
       
   748          State() == MMusAvaObserver::EMusAvaStatusAvailable )
       
   749         {
       
   750         MUS_LOG("mus: [MUSAVA]  In delayed mode or available, ignore" )
       
   751         aNewState = State();
       
   752         }
       
   753     
       
   754     MUS_LOG("mus: [MUSAVA]  <- CMusAvaOptionHandler::HandleFastModeOptionNotAvailableL()" )
       
   755     
       
   756     return aNewState;
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 //
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 TBool CMusAvaOptionHandler::FastModeNegotiatedByAnswerMT()
       
   764     {
       
   765     return ( iFastModeCapable && 
       
   766              iCapabilityQueryAnswered && 
       
   767              iSettings.FastMode() == MusSettingsKeys::EFastModeOn &&
       
   768              iSettings.CallDirection() == NMusSessionInformationApi::ECallTerminated );
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 TBool CMusAvaOptionHandler::FastModeNegotiationFailedMO()
       
   776     {
       
   777     return ( iFastModeCapable && 
       
   778              iSettings.FastMode() != MusSettingsKeys::EFastModeOn &&
       
   779              iSettings.CallDirection() == NMusSessionInformationApi::ECallOrginated &&
       
   780              State() != MMusAvaObserver::EMusAvaStatusAvailable && 
       
   781              State() != MMusAvaObserver::EMusAvaStatusOptionsSent );
       
   782     }
       
   783 
       
   784 // End of file