tsrc/musenginestub/src/mussipprofilehandler.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     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 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Utilities to get and set profile used with SWIS.
       
    15 *  Part of     : Mus For S60 v3.2
       
    16 *  Description : Utilities to get and set profile used with SWIS.
       
    17 *  Version     : %version: 1 % << Don't touch! Updated by Synergy at check-out.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 // USER
       
    23 #include "mussipprofilehandler.h"
       
    24 #include "musuid.hrh"
       
    25 #include "muslogger.h"
       
    26 #include "mussipprofileuser.h"
       
    27 
       
    28 // SYSTEM
       
    29 #include <sip.h>
       
    30 #include <sipservertransaction.h>
       
    31 #include <sipinvitedialogassoc.h>
       
    32 #include <sipprofile.h>
       
    33 #include <sipprofileregistry.h>
       
    34 #include <sipprofilealrcontroller.h>
       
    35 #include <uri8.h>
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMusSipProfileHandler* CMusSipProfileHandler::NewL( MMusSipProfileUser& aUser )
       
    42     {
       
    43     CMusSipProfileHandler* self = 
       
    44         new (ELeave) CMusSipProfileHandler( aUser );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( self);
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMusSipProfileHandler::CMusSipProfileHandler( MMusSipProfileUser& aUser )
       
    56     : iUser( aUser )
       
    57     {
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CMusSipProfileHandler::ConstructL()
       
    65     {
       
    66     MUS_LOG( "mus: [ENGINE]  -> CMusSipProfileHandler::ConstructL()" )
       
    67     
       
    68     // Use NULL Uid since we do not want to receive any requests.
       
    69     // All requests should be handled by MCE.
       
    70     iSip = CSIP::NewL( TUid::Null(), *this );
       
    71     iProfileRegistry = CSIPProfileRegistry::NewL( *iSip, *this );   
       
    72     iProfileAlrController = 
       
    73         CSipProfileAlrController::NewL( *iProfileRegistry , *this );
       
    74     
       
    75     MUS_LOG( "mus: [ENGINE]  <- CMusSipProfileHandler::ConstructL()" )
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CMusSipProfileHandler::~CMusSipProfileHandler()
       
    83     {
       
    84     delete iProfileAlrController;
       
    85     delete iSipProfile;
       
    86     delete iProfileRegistry;
       
    87     delete iSip;
       
    88     MUS_LOG( "mus: [ENGINE]     CMusSipProfileHandler::~CMusSipProfileHandler()" )
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CMusSipProfileHandler::CreateProfileL( TUint32 aSipProfileId )
       
    96     {
       
    97     CSIPProfile* profile( NULL );
       
    98     if ( aSipProfileId != 0 )
       
    99         {
       
   100         profile = iProfileRegistry->ProfileL( aSipProfileId );
       
   101         }
       
   102     else
       
   103         {
       
   104         profile = iProfileRegistry->DefaultProfileL();
       
   105         }
       
   106        
       
   107     delete iSipProfile;
       
   108     iSipProfile = profile;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CSIPProfile* CMusSipProfileHandler::Profile()
       
   116     {
       
   117     return iSipProfile;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CUri8* CMusSipProfileHandler::UserFromProfileLC()
       
   125     {
       
   126     MUS_LOG( "mus: [ENGINE]  -> CMusSipProfileHandler::UserFromProfileLC()" );
       
   127     
       
   128     __ASSERT_ALWAYS( iSipProfile != NULL, User::Leave( KErrNotReady ) );
       
   129 
       
   130     const MDesC8Array* aors = NULL;
       
   131     User::LeaveIfError( iSipProfile->GetParameter( KSIPRegisteredAors, aors ) );
       
   132     __ASSERT_ALWAYS( aors && aors->MdcaCount() > 0, 
       
   133                      User::Leave( KErrArgument ) );
       
   134     
       
   135     TUriParser8 parser;
       
   136     User::LeaveIfError( parser.Parse( aors->MdcaPoint( 0 ) ) );
       
   137     MUS_LOG( "mus: [ENGINE]  <- CMusSipProfileHandler::UserFromProfileLC()" )
       
   138     
       
   139     return CUri8::NewLC( parser );
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CMusSipProfileHandler::RefreshIapAvailabilities()
       
   148     {
       
   149     TRAP_IGNORE( iProfileAlrController->RefreshIapAvailabilityL( ProfileId() ) )
       
   150     }
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // This function should never be called before creating a profile, but such
       
   155 // a situation will be considered as pending registration.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 TBool CMusSipProfileHandler::IsRegistered()
       
   159     {
       
   160     MUS_LOG( "mus: [ENGINE]  -> CMusSipProfileHandler::IsRegistered()" )
       
   161     
       
   162     TBool profileRegistered = EFalse;   
       
   163     if ( iSipProfile ) 
       
   164         {
       
   165         iSipProfile->GetParameter( KSIPProfileRegistered, profileRegistered  );  
       
   166         }
       
   167     
       
   168     MUS_LOG1( "mus: [ENGINE]  <- CMusSipProfileHandler::IsRegistered( %d )",
       
   169               profileRegistered )
       
   170     
       
   171     return profileRegistered;
       
   172     }
       
   173 
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CMusSipProfileHandler::ProfileRegistryEventOccurred(
       
   180     TUint32 aProfileId,
       
   181     MSIPProfileRegistryObserver::TEvent aEvent )
       
   182     {
       
   183     if ( iSipProfile && aProfileId == ProfileId() )
       
   184         {
       
   185         switch ( aEvent )
       
   186             {
       
   187             case MSIPProfileRegistryObserver::EProfileRegistered:
       
   188                 {
       
   189                 iUser.ProfileRegistered();
       
   190                 break;
       
   191                 }
       
   192             default:
       
   193                 {
       
   194                 break;
       
   195                 }
       
   196             }
       
   197         }
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CMusSipProfileHandler::ProfileRegistryErrorOccurred(
       
   206     TUint32 /*aProfileId*/,
       
   207     TInt /*aError*/)
       
   208     {
       
   209     }
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CMusSipProfileHandler::IncomingRequest( 
       
   217     TUint32 /*aIapId*/,
       
   218     CSIPServerTransaction* aTransaction )
       
   219     {
       
   220     // Ownership transferred, should not ever be called by SIP though
       
   221     delete aTransaction; 
       
   222     }
       
   223 
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CMusSipProfileHandler::TimedOut( 
       
   230     CSIPServerTransaction& /*aTransaction*/ )
       
   231     {
       
   232     }
       
   233 
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CMusSipProfileHandler::IncomingRequest(
       
   240     CSIPServerTransaction* aTransaction )
       
   241     {
       
   242     // Ownership transferred, should not ever be called by SIP though
       
   243     delete aTransaction; 
       
   244     }
       
   245 
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CMusSipProfileHandler::IncomingRequest(
       
   252     CSIPServerTransaction* aTransaction,
       
   253     CSIPDialog& /*aDialog*/)
       
   254     {
       
   255     // Ownership transferred, should not ever be called by SIP though
       
   256     delete aTransaction; 
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CMusSipProfileHandler::IncomingResponse(
       
   264     CSIPClientTransaction& /*aTransaction*/)
       
   265     {
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CMusSipProfileHandler::IncomingResponse( 
       
   273     CSIPClientTransaction& /*aTransaction*/,
       
   274     CSIPDialogAssocBase& /*aDialogAssoc*/)
       
   275     {
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CMusSipProfileHandler::IncomingResponse( 
       
   283     CSIPClientTransaction& /*aTransaction*/,
       
   284     CSIPInviteDialogAssoc* aDialogAssoc)
       
   285     {
       
   286     // Ownership transferred, should not ever be called by SIP though
       
   287     delete aDialogAssoc;     
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CMusSipProfileHandler::IncomingResponse( 
       
   295     CSIPClientTransaction& /*aTransaction*/,
       
   296     CSIPRegistrationBinding& /*aRegistration*/ )
       
   297     {
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CMusSipProfileHandler::ErrorOccured( 
       
   305     TInt /*aError*/,
       
   306     CSIPTransactionBase& /*aTransaction*/ )
       
   307     {
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CMusSipProfileHandler::ErrorOccured( 
       
   315     TInt /*aError*/,
       
   316     CSIPClientTransaction& /*aTransaction*/,
       
   317     CSIPRegistrationBinding& /*aRegistration*/ )
       
   318     {
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CMusSipProfileHandler::ErrorOccured( 
       
   326     TInt /*aError*/,
       
   327     CSIPTransactionBase& /*aTransaction*/,
       
   328     CSIPDialogAssocBase& /*aDialogAssoc*/ )                                     
       
   329     {
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CMusSipProfileHandler::ErrorOccured( 
       
   337     TInt /*aError*/, 
       
   338     CSIPRefresh& /*aSIPRefresh*/ )
       
   339     {
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMusSipProfileHandler::ErrorOccured( 
       
   347     TInt /*aError*/,
       
   348     CSIPRegistrationBinding& /*aRegistration*/ )                                
       
   349     {
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CMusSipProfileHandler::ErrorOccured( 
       
   357     TInt /*aError*/,
       
   358     CSIPDialogAssocBase& /*aDialogAssoc*/ )                
       
   359     {
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CMusSipProfileHandler::InviteCompleted( 
       
   367     CSIPClientTransaction& /*aTransaction*/ )
       
   368     {
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CMusSipProfileHandler::InviteCanceled( 
       
   376     CSIPServerTransaction& /*aTransaction*/ )
       
   377     {
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 void CMusSipProfileHandler::ConnectionStateChanged( 
       
   385     CSIPConnection::TState /*aState*/ )
       
   386     {
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CMusSipProfileHandler::AlrEvent
       
   391 // From MSipProfileAlrObserver
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CMusSipProfileHandler::AlrEvent(
       
   395     MSipProfileAlrObserver::TEvent aEvent,
       
   396     TUint32 aProfileId,
       
   397     TUint32 /*aSnapId*/,
       
   398     TUint32 aIapId )
       
   399     {
       
   400     if ( aEvent == MSipProfileAlrObserver::EIapAvailable )
       
   401         {
       
   402         if ( iSipProfile &&
       
   403              aProfileId == ProfileId() &&
       
   404              !iUser.IsRoamingBetweenAPsAllowed() )
       
   405            {
       
   406            // Disallow roaming only if the profile is used by MuS and
       
   407            // the MuS has an ongoing  session 
       
   408            TRAP_IGNORE( 
       
   409                iProfileAlrController->DisallowMigrationL( aProfileId, aIapId ) )
       
   410            }
       
   411        else
       
   412            {
       
   413            // In all other cases allow roaming
       
   414            TRAP_IGNORE( 
       
   415                iProfileAlrController->AllowMigrationL( aProfileId, aIapId ) )
       
   416            }
       
   417         }
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CMusSipProfileHandler::AlrError
       
   422 // From MSipProfileAlrObserver
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 void CMusSipProfileHandler::AlrError(
       
   426     TInt /*aError*/,
       
   427     TUint32 /*aProfileId*/,
       
   428     TUint32 /*aSnapId*/,
       
   429     TUint32 /*aIapId*/ )
       
   430     {
       
   431     // Ignore ALR related errors as they should not happen 
       
   432     // as migration is not allowed when 
       
   433     // the instance of CMusSipProfileHandler exists
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TUint32 CMusSipProfileHandler::ProfileId() const
       
   441     {
       
   442     TUint32 sipProfileId( 0 );
       
   443     if ( iSipProfile )
       
   444         {
       
   445         iSipProfile->GetParameter( KSIPProfileId, sipProfileId );
       
   446         }
       
   447     return sipProfileId;
       
   448     }