mmsharing/mmshavailability/src/musavasip.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 2005-2006 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 *  Version     : %version:  30.1.4 % << Don't touch! Updated by Synergy at check-out.
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:   This is main SIP class for MusAvailability Plug-in
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "musavasip.h"
       
    23 #include "musavasharedobject.h"
       
    24 #include "musavasipobserver.h"
       
    25 #include "musavasipconnectionobserver.h"
       
    26 #include "musavailabilityplugin.hrh"
       
    27 #include "musavasipprofileregistryobserver.h"
       
    28 #include "muslogger.h"
       
    29 #include "mussettingskeys.h"
       
    30 #include "mussettings.h"
       
    31 #include "musavaclientresolverutil.h"
       
    32 
       
    33 #include <charconv.h>
       
    34 #include <sip.h>
       
    35 #include <sipobserver.h>
       
    36 #include <sipconnectionobserver.h>
       
    37 #include <sipprofile.h>
       
    38 #include <sipprofileregistry.h>
       
    39 #include <utf.h>
       
    40 #include <siperr.h>
       
    41 
       
    42 const TInt KMaxUriLength = 512;
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // C++ destructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMusAvaSip::~CMusAvaSip()
       
    49     {
       
    50     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::~CMusAvaSip()" )
       
    51     // Try to remove client information from CenRep of client resolver.
       
    52     // This functionality is needed in __VOIP enabled builds.
       
    53     // In normal build this will fail because of a lack of needed CenRep 
       
    54     // UID. To avoid branching, we just try to do this and let it fail in 
       
    55     // normal build.
       
    56     MUS_LOG( "mus: [MUSAVA]     Deleting CSIPProfile instance" )
       
    57     if ( iSipProfile && iClientResolverUtil )
       
    58         {
       
    59         TRAP_IGNORE( 
       
    60             iClientResolverUtil->UnRegisterClientWithUserL( *iSipProfile ) )
       
    61         }
       
    62     delete iSipProfile;    
       
    63     delete iClientResolverUtil;
       
    64         
       
    65     MUS_LOG( "mus: [MUSAVA]     Deleting CSIPProfileRegistry instance" )
       
    66     delete iSipProfileRegistry;
       
    67     MUS_LOG( "mus: [MUSAVA]     Deleting SIP registry observer" )
       
    68     delete iSipProfileRegistryObserver;
       
    69     MUS_LOG( "mus: [MUSAVA]     Deleting CSIPConnection instance" )
       
    70     delete iSipConnection;
       
    71     MUS_LOG( "mus: [MUSAVA]     Deleting SIP connection observer" )
       
    72     delete iSipConnectionObserver;
       
    73     MUS_LOG( "mus: [MUSAVA]     Deleting CSIP instance" )
       
    74     delete iSip;
       
    75     delete iSipObserver;
       
    76     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::~CMusAvaSip()" )
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // Two-phased constructor.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CMusAvaSip* CMusAvaSip::NewL()
       
    85     {
       
    86     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::NewL()" )
       
    87     CMusAvaSip* self = new (ELeave) CMusAvaSip();
       
    88     CleanupStack::PushL (self);
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop( self );
       
    91     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::NewL()" )
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // C++ Constructor
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CMusAvaSip::CMusAvaSip()
       
   101     {
       
   102     iSipProfileRegistry = NULL;
       
   103     iSipProfile = NULL;
       
   104     iSipConnection = NULL;
       
   105     }
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // Symbian second-phase constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CMusAvaSip::ConstructL()
       
   113     {
       
   114     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::ConstructL()" )
       
   115     // create observer classes (that are not dependant on actual instances)
       
   116     iSipObserver = CMusAvaSipObserver::NewL();
       
   117     iSipConnectionObserver = CMusAvaSipConnectionObserver::NewL();
       
   118     iSipProfileRegistryObserver = CMusAvaSipProfileRegistryObserver::NewL();
       
   119 
       
   120     TUid KUidMusAva = { 0x1028238D };
       
   121     // create sip instance
       
   122     iSip = CSIP::NewL( KUidMusAva, *iSipObserver );
       
   123     
       
   124     /**
       
   125      * Try to instantiate utility object that handles special client resolving 
       
   126      * in __VOIP enabled terminals. In __VOIP disabled terminals creation of
       
   127      * this object will fail because of missing UID in CenRep and thus this 
       
   128      * pointer can be NULL. If this object does not exist, standard client
       
   129      * resolving will be used.
       
   130      */
       
   131     TRAP_IGNORE( iClientResolverUtil = CMusAvaClientResolverUtil::NewL() )
       
   132 
       
   133     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::ConstructL()" )
       
   134     }
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 void CMusAvaSip::AddAdapterL( MMusAvaSipConnectionAdapter& aAdapter, TInt aIndex )
       
   141     {
       
   142     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   143              AddAdapterL( MMusAvaSipConnectionAdapter& aAdapter )" )
       
   144     iSipConnectionObserver->AddObserverL( aAdapter, aIndex );
       
   145     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::\
       
   146              AddAdapterL( MMusAvaSipConnectionAdapter& aAdapter )" )
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 void CMusAvaSip::RemoveAdapter( MMusAvaSipConnectionAdapter& aAdapter )
       
   154     {
       
   155     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   156              RemoceAdapter( MMusAvaSipConnectionAdapter& aAdapter )" )
       
   157     iSipConnectionObserver->RemoveObserver( aAdapter );
       
   158     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::\
       
   159              RemoceAdapter( MMusAvaSipConnectionAdapter& aAdapter )" )
       
   160     }
       
   161 
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 // -----------------------------------------------------------------------------
       
   166 void CMusAvaSip::AddAdapterL( MMusAvaSipAdapter& aAdapter, TInt aIndex  )
       
   167     {
       
   168     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   169              AddAdapterL( MMusAvaSipAdapter& aAdapter )" )
       
   170     iSipObserver->AddObserverL( aAdapter, aIndex );
       
   171     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::\
       
   172              AddAdapterL( MMusAvaSipAdapter& aAdapter )" )
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 // -----------------------------------------------------------------------------
       
   179 void CMusAvaSip::RemoveAdapter( MMusAvaSipAdapter& aAdapter )
       
   180     {
       
   181     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::RemoveAdapter( MMusAvaSipAdapter& aAdapter )" )
       
   182     iSipObserver->RemoveObserver( aAdapter );
       
   183     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::RemoveAdapter( MMusAvaSipAdapter& aAdapter )" )
       
   184     }
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 // -----------------------------------------------------------------------------
       
   190 void CMusAvaSip::AddAdapterL( MMusAvaSipProfileRegistryAdapter& aAdapter )
       
   191     {
       
   192     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   193              AddAdapterL( MMusAvaSipProfileRegistryAdapter& aAdapter )" )
       
   194     iSipProfileRegistryObserver->AddAdapterL( aAdapter );
       
   195     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::\
       
   196              AddAdapterL( MMusAvaSipProfileRegistryAdapter& aAdapter )" )
       
   197     }
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 // -----------------------------------------------------------------------------
       
   203 void CMusAvaSip::RemoveAdapter( MMusAvaSipProfileRegistryAdapter& aAdapter )
       
   204     {
       
   205     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   206              RemoveAdapter( MMusAvaSipProfileRegistryAdapter& aAdapter )" )
       
   207     iSipProfileRegistryObserver->RemoveAdapter( aAdapter );
       
   208     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::\
       
   209              RemoveAdapter( MMusAvaSipProfileRegistryAdapter& aAdapter )" )
       
   210     }
       
   211   
       
   212     
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 // -----------------------------------------------------------------------------
       
   216 CSIPConnection* CMusAvaSip::ConnectionL( TBool aForceCreation )
       
   217     {
       
   218     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::Connection()" )
       
   219     if ( aForceCreation )
       
   220         {
       
   221         CreateSIPConnectionL();
       
   222         }
       
   223     __ASSERT_ALWAYS( iSipConnection, User::Leave( KErrSIPInvalidRegistrationState ) );
       
   224     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::Connection()" )
       
   225     return iSipConnection;
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 // -----------------------------------------------------------------------------
       
   232 MSIPConnectionObserver& CMusAvaSip::ConnectionObserver()
       
   233     {
       
   234     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::ConnectionObserver()" )
       
   235     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::ConnectionObserver()" )
       
   236     return *iSipConnectionObserver;
       
   237     }
       
   238     
       
   239     
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 // -----------------------------------------------------------------------------
       
   243 TBool CMusAvaSip::CreateProfileL()
       
   244     {
       
   245     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::CreateProfileL()" )
       
   246 
       
   247   	TBool retVal = ETrue;
       
   248   	if ( CreateSipProfile() )
       
   249   		{
       
   250         TInt err = iSipProfile->GetParameter( KSIPAccessPointId, iIapId );
       
   251         if ( err != KErrNone )
       
   252   		    {
       
   253   		    MUS_LOG1( "SIP Access Point not found = %d", err )   
       
   254         	retVal = EFalse;
       
   255   		    }
       
   256   		}
       
   257   	else
       
   258   		{
       
   259   		retVal = EFalse;
       
   260   		}        
       
   261     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateProfileL()" )
       
   262     return retVal;
       
   263     }
       
   264 
       
   265     
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 // -----------------------------------------------------------------------------
       
   269 TBool CMusAvaSip::CreateSipProfile()
       
   270     {
       
   271     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::CreateSipProfile()" )
       
   272     if ( iSipProfile )
       
   273         {
       
   274         MUS_LOG( "mus: [MUSAVA]  Profile is already created" )
       
   275         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateSipProfile()" )
       
   276         return ETrue;
       
   277         }
       
   278     
       
   279     CSIPProfileRegistry* registry = NULL;
       
   280 
       
   281     //get profile registry
       
   282     MUS_LOG( "mus: [MUSAVA]   Fetch profile registry" )
       
   283     TRAPD( error_registry, registry = &ProfileRegistryL() );
       
   284     if( error_registry )
       
   285         {
       
   286         MUS_LOG( "mus: [MUSAVA]    ProfileRegistry is not created" )
       
   287         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateSipProfile()" )
       
   288         return EFalse;
       
   289         }
       
   290     // try to resolve the profile
       
   291     MUS_LOG( "mus: [MUSAVA]   Fetch  SIP Profile" )
       
   292     TRAPD( error_profile, iSipProfile = GetMusProfileL( *registry ) );
       
   293     if( error_profile )
       
   294         {
       
   295         MUS_LOG( "mus: [MUSAVA]    Profile is not found" )
       
   296         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateSipProfile()" )
       
   297         return EFalse;
       
   298         }
       
   299     else
       
   300         {
       
   301         MUS_LOG( "mus: [MUSAVA]  Profile is  created" )
       
   302         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateSipProfile()" )
       
   303         return ETrue;
       
   304         }
       
   305     }
       
   306 
       
   307     
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 // -----------------------------------------------------------------------------
       
   311 CSIPProfile* CMusAvaSip::Profile()
       
   312     {
       
   313     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::Profile()" )
       
   314     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::Profile()" )
       
   315     return iSipProfile;
       
   316     }
       
   317 
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 // -----------------------------------------------------------------------------
       
   322 CSIPProfileRegistry& CMusAvaSip::ProfileRegistryL()
       
   323     {
       
   324     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::ProfileRegistry()" )
       
   325     if ( !iSipProfileRegistry )
       
   326         {
       
   327         MUS_LOG( "mus: [MUSAVA]  create sip profile registry" )
       
   328         // create sip profile registry
       
   329         iSipProfileRegistry = CSIPProfileRegistry::NewL(
       
   330                                     *iSip,
       
   331                                     *iSipProfileRegistryObserver );
       
   332         }
       
   333     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::ProfileRegistry()" )
       
   334     return *iSipProfileRegistry;
       
   335     }
       
   336 
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 // -----------------------------------------------------------------------------
       
   341 HBufC* CMusAvaSip::OwnDomainLC()
       
   342     {
       
   343     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::OwnDomainLC()" )
       
   344     
       
   345     HBufC* domain = KNullDesC().AllocLC();
       
   346     if( iSipProfile )
       
   347         {
       
   348         const MDesC8Array* domainNameArray( NULL );
       
   349         iSipProfile->GetParameter( KSIPRegisteredAors, domainNameArray );
       
   350 
       
   351         if( domainNameArray )
       
   352             {
       
   353             if( domainNameArray->MdcaCount() > 0 )
       
   354                 {
       
   355                 TBuf<KMaxUriLength> domain16;
       
   356                 const TDesC8& domain8 = domainNameArray->MdcaPoint( 0 );
       
   357 
       
   358                 _LIT8( KAt, "@" );
       
   359 
       
   360                 TInt index = domain8.Find( KAt() );
       
   361 
       
   362                 User::LeaveIfError(
       
   363                         CnvUtfConverter::ConvertToUnicodeFromUtf8(
       
   364                                 domain16,
       
   365                                 domain8.Mid( index + KAt().Length() ) ) );
       
   366                 CleanupStack::PopAndDestroy( domain );
       
   367                 domain = domain16.AllocLC();
       
   368                 }
       
   369             }
       
   370         }
       
   371         
       
   372     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::OwnDomainLC()" )
       
   373     return domain;
       
   374     }
       
   375 
       
   376     
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 // -----------------------------------------------------------------------------
       
   380 CSIP& CMusAvaSip::Sip()
       
   381     {
       
   382     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::Sip()" )
       
   383     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::Sip()" )
       
   384     return *iSip;
       
   385     }
       
   386     
       
   387     
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 // -----------------------------------------------------------------------------
       
   391 TInt CMusAvaSip::SipProfileId( TUint32& aSipProfileId )
       
   392     {
       
   393     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::SipProfile()" )
       
   394     //SIP Profile ID 
       
   395     TInt profile_id_err = iSipProfile->GetParameter( KSIPProfileId, aSipProfileId );
       
   396    	MUS_LOG1( "Profile id = %d", profile_id_err )
       
   397     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::SipProfile()" )	
       
   398     return profile_id_err;
       
   399     }
       
   400 
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 // -----------------------------------------------------------------------------
       
   405 CMusAvaClientResolverUtil* CMusAvaSip::ClientResolverUtil() const
       
   406     {
       
   407     return iClientResolverUtil;
       
   408     }
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 // -----------------------------------------------------------------------------
       
   412 void CMusAvaSip::DeleteSIPConnection()
       
   413     {
       
   414     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::DeleteSIPConnection()" )
       
   415         delete iSipConnection; iSipConnection = NULL;
       
   416     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::DeleteSIPConnection()" )
       
   417     }
       
   418 
       
   419     
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 // -----------------------------------------------------------------------------
       
   423 void CMusAvaSip::CreateSIPConnectionL()
       
   424     {
       
   425     MUS_LOG1( "mus: [MUSAVA]  -> CMusAvaSip::CreateSIPConnectionL(), iapid:%d", 
       
   426               iIapId )
       
   427     
       
   428    	if ( !iSipConnection )
       
   429    	    {
       
   430    	    iSipConnection = CSIPConnection::NewL( *iSip,
       
   431                                                iIapId,
       
   432                                                *iSipConnectionObserver );
       
   433         }
       
   434    	                                           
       
   435     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::CreateSIPConnectionL()" )
       
   436     }
       
   437 
       
   438 
       
   439 // ---------------------------------------------------------------------------------
       
   440 // Gets profile to be used with Mus.
       
   441 // ---------------------------------------------------------------------------------
       
   442 //
       
   443 CSIPProfile* CMusAvaSip::GetMusProfileL( CSIPProfileRegistryBase& aRegistry )
       
   444     {
       
   445     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaSip::GetMusProfileL" )
       
   446     CSIPProfile* profile = NULL;
       
   447     TUint32 profileId = KErrNone;
       
   448 
       
   449     // Try to fetch profileId for profile meant to be used with Mus
       
   450     TRAPD( err, profileId =
       
   451             MultimediaSharingSettings::SipProfileSettingL() );
       
   452 
       
   453     if( err != KErrNone || profileId == KErrNone )
       
   454         {
       
   455         MUS_LOG( "mus: [MUSAVA]     Using default profile" )
       
   456         profile = aRegistry.DefaultProfileL();
       
   457         }
       
   458     else if ( (TInt )profileId == KErrNotFound )
       
   459         {
       
   460         MUS_LOG( "mus: [MUSAVA]     Setting: Mus is not allowed to use any \
       
   461             SIP profiles" )
       
   462         MUS_LOG1( "mus: [MUSAVA]     User::Leave( %d )",
       
   463                   KErrNotSupported )
       
   464         User::Leave( KErrNotSupported );
       
   465         }
       
   466     else 
       
   467         {
       
   468         MUS_LOG( "mus: [MUSAVA]     Try to fetch profile meant to be used with Mus" )
       
   469         profile = aRegistry.ProfileL( profileId );
       
   470         err = profile->GetParameter( KSIPProfileId,profileId );
       
   471         if( err != KErrNone)
       
   472             {
       
   473             MUS_LOG1("mus: [MUSAVA]    SIP Profile ID %d",profileId )
       
   474             }  
       
   475         } 
       
   476 
       
   477     // If not possible, use default profile. If not able, leave.
       
   478     if ( !profile )
       
   479         {
       
   480         MUS_LOG( "mus: [MUSAVA]     Not found" )
       
   481         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::GetMusProfileL" )
       
   482         User::Leave( KErrNotFound );
       
   483         }
       
   484     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaSip::GetMusProfileL" )
       
   485     return profile;
       
   486     };
       
   487         
       
   488 
       
   489 
       
   490 
       
   491 
       
   492