commsconfig/cscsipvoipcleanupplugin/src/cscsvcpluginhandler.cpp
changeset 0 a4daefaec16c
child 11 6134b5029079
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <spproperty.h>
       
    20 #include <spsettings.h>
       
    21 #include <cmmanagerext.h>
       
    22 #include <XdmSettingsApi.h>
       
    23 #include <pressettingsapi.h>
       
    24 #include <cmpluginwlandef.h>
       
    25 #include <cmdestinationext.h>
       
    26 #include <XdmSettingsCollection.h>
       
    27 
       
    28 #include "cscsvcpluginlogger.h"
       
    29 #include "cscsvcpluginhandler.h"
       
    30 #include "cscsvcpluginsiphandler.h"
       
    31 #include "cscsvcpluginrcsehandler.h"
       
    32 #include "cscsvcplugincenrephandler.h"
       
    33 
       
    34 // At-character in SIP profile public username.
       
    35 _LIT8( KSvcPluginAtCharacter, "@" );
       
    36 
       
    37 // Maximum lengths of the setting values.
       
    38 const TInt KSvcPluginSettingLength = 256;
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CCSCSvcPluginHandler::CCSCSvcPluginHandler()
       
    47     {    
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CCSCSvcPluginHandler::ConstructL()
       
    55     {
       
    56     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::ConstructL - begin");
       
    57         
       
    58     iRcseHandler = CCSCSvcPluginRcseHandler::NewL();
       
    59     iSipHandler = CCSCSvcPluginSipHandler::NewL();
       
    60     iCenRepHandler = CCSCSvcPluginCenrepHandler::NewL();
       
    61     
       
    62     // Create descriptor array for domain names.
       
    63     iDomainNames = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
    64     
       
    65     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::ConstructL - end");
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CCSCSvcPluginHandler* CCSCSvcPluginHandler::NewL()
       
    73     {
       
    74     CCSCSvcPluginHandler* self = new (ELeave) CCSCSvcPluginHandler;
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CCSCSvcPluginHandler::~CCSCSvcPluginHandler()
       
    86     {
       
    87     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::~CCSCSvcPluginHandler - begin");
       
    88     
       
    89     iIapIds.Close();
       
    90     iSipProfileIds.Close();
       
    91 
       
    92     if ( iDomainNames )
       
    93         {
       
    94         iDomainNames->Reset();
       
    95         }
       
    96     delete iDomainNames;
       
    97     delete iRcseHandler;
       
    98     delete iSipHandler;
       
    99     delete iCenRepHandler;
       
   100     
       
   101     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::~CCSCSvcPluginHandler - end");
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // For settings removation.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CCSCSvcPluginHandler::RemoveSettingsL( TUint32 aServiceId )
       
   110     {
       
   111     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::RemoveSettingsL - begin");
       
   112     
       
   113     // Search data based on service id
       
   114     SearchSettingsDataL( aServiceId );
       
   115         
       
   116     // Unregister. (SIP profiles are set to when needed mode.)
       
   117     for ( TInt i = 0; i < iSipProfileIds.Count(); i++ )
       
   118         {
       
   119         iSipHandler->SetRegistrationModeL( iSipProfileIds[ i ], EFalse );
       
   120         }
       
   121     
       
   122     // Remove all profiles/settings.
       
   123     RemoveProfilesL( aServiceId );
       
   124     
       
   125     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::RemoveSettingsL - end");
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Searches all settings data from databases. 
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CCSCSvcPluginHandler::SearchSettingsDataL( TUint32 aServiceId )
       
   133     {
       
   134     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::SearchSettingsDataL - begin");
       
   135     
       
   136     // Reset member variables to default values.
       
   137     iVoIPProfileId = KErrNone;
       
   138     iSNAPId = KErrNone;
       
   139     iPresenceId = KErrNone;
       
   140     iSipProfileIds.Reset();
       
   141     iIapIds.Reset();
       
   142     iDomainNames->Reset();
       
   143        
       
   144     // Get SNAP ID from service table
       
   145     CSPSettings* spSettings = CSPSettings::NewLC();
       
   146     CSPProperty* property = CSPProperty::NewLC();
       
   147     
       
   148     TInt err =  spSettings->FindPropertyL( 
       
   149         aServiceId, ESubPropertyVoIPPreferredSNAPId, *property );
       
   150     
       
   151     if ( !err )
       
   152         {
       
   153         property->GetValue( iSNAPId );
       
   154         }
       
   155     
       
   156     TInt err2( KErrNone );
       
   157     err2 =  spSettings->FindPropertyL( 
       
   158         aServiceId, ESubPropertyPresenceSettingsId, *property );
       
   159     
       
   160     if ( !err2 )
       
   161         {
       
   162         property->GetValue( iPresenceId );
       
   163         }
       
   164         
       
   165     CleanupStack::PopAndDestroy( property );
       
   166     CleanupStack::PopAndDestroy( spSettings );
       
   167         
       
   168     // Get VoIP profile id and SIP reference ids from RCSE handler.
       
   169     iRcseHandler->GetProfileIdsL( 
       
   170         aServiceId,
       
   171         iVoIPProfileId,
       
   172         iSipProfileIds );
       
   173     
       
   174     for ( TInt i = 0; i < iSipProfileIds.Count(); i++ )
       
   175         {
       
   176         // Get Access Point Id from SIP profile and append it to id array.
       
   177         TUint32 accessPointId = 0;
       
   178         iSipHandler->GetApIdL( iSipProfileIds[ i ], accessPointId );
       
   179         
       
   180         if ( accessPointId )
       
   181             {
       
   182             iIapIds.Append( ( TUint32 ) accessPointId );
       
   183             }
       
   184             
       
   185         // Get Domain name from SIP profile and append it to desc array.
       
   186         TBuf8<KSvcPluginSettingLength> publicUsername( KNullDesC8 );
       
   187         iSipHandler->GetUserAorL( iSipProfileIds[ i ], publicUsername );
       
   188 
       
   189         TInt location = publicUsername.Find( KSvcPluginAtCharacter );
       
   190         
       
   191         if ( KErrNotFound != location )
       
   192             {
       
   193             iDomainNames->AppendL( publicUsername.Mid( location + 1 ) );
       
   194             }
       
   195         }
       
   196     
       
   197     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::SearchSettingsDataL - end");
       
   198     }
       
   199     
       
   200 // ---------------------------------------------------------------------------
       
   201 // Removes settings.
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CCSCSvcPluginHandler::RemoveProfilesL( TUint32 aServiceId )
       
   205     {
       
   206     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::RemoveProfilesL - begin");
       
   207         
       
   208     // Destroy VoIP profile from RCSE. 
       
   209     iRcseHandler->RemoveProfileL( iVoIPProfileId );
       
   210     
       
   211     // Remove entry from service table
       
   212     CSPSettings* spSettings = CSPSettings::NewLC();
       
   213     spSettings->DeleteEntryL( aServiceId );
       
   214     CleanupStack::PopAndDestroy( spSettings );
       
   215           
       
   216     // Destroy SIP profiles from SIP Stack.
       
   217     for ( TInt i = 0; i < iSipProfileIds.Count(); i++ )
       
   218         {
       
   219         iSipHandler->RemoveProfileL( iSipProfileIds[ i ] );
       
   220         }
       
   221     
       
   222     // Destroy IAP specific NAT/FW settings.
       
   223     for ( TInt i = 0; i < iIapIds.Count(); i++ )
       
   224         {
       
   225         // Trapped, because function leaves 
       
   226         // if iap spesific keys wasn't found from repostiory.
       
   227         TRAP_IGNORE( iCenRepHandler->RemoveIapSpecificNatfwSettingsL( 
       
   228             iIapIds[ i ] ) );
       
   229         }
       
   230       
       
   231     // Destroy Domain specific NAT/FW settings.
       
   232     for ( TInt i = 0; i < iDomainNames->Count(); i++ )
       
   233         {
       
   234         // Trapped, because function leaves 
       
   235         // if domain spesific keys wasn't found from repostiory.
       
   236         TRAP_IGNORE( iCenRepHandler->RemoveDomainSpecificNatfwSettingsL( 
       
   237             iDomainNames->MdcaPoint( i ) ) );
       
   238         }
       
   239     
       
   240      // Delete SNAP
       
   241     if ( iSNAPId )
       
   242         {
       
   243         RCmManagerExt manager;
       
   244         CleanupClosePushL( manager );
       
   245         manager.OpenL();     
       
   246         RCmDestinationExt dest;
       
   247         CleanupClosePushL( dest );
       
   248         dest = manager.DestinationL ( iSNAPId );
       
   249         
       
   250         // Delete SNAP only if itīs not Internet SNAP.
       
   251         TUint32 internetSnapId( KErrNone );
       
   252         internetSnapId = dest.MetadataL( CMManager::ESnapMetadataInternet );
       
   253         if( internetSnapId == KErrNone )
       
   254             {
       
   255             dest.DeleteLD();
       
   256             }
       
   257         
       
   258         CleanupStack::PopAndDestroy( &dest );        
       
   259         CleanupStack::PopAndDestroy( &manager );
       
   260         
       
   261         CSCSVCPLUGINDEBUG( 
       
   262             "CEgpSettingsController::RemoveProfilesL SNAP deleted" );
       
   263         }
       
   264     
       
   265      // Delete presence and xdm settings
       
   266     if ( iPresenceId )
       
   267         {
       
   268         TPresSettingsSet presSettingSet;
       
   269                 
       
   270         // Delete xmd settings
       
   271         PresSettingsApi::SettingsSetL( iPresenceId, presSettingSet );        
       
   272         TXdmSettingsApi::RemoveCollectionL( presSettingSet.iXDMSetting );
       
   273               
       
   274         // Delete presence settings
       
   275         TInt err = PresSettingsApi::RemoveSetL( iPresenceId );
       
   276         
       
   277         CSCSVCPLUGINDEBUG2( 
       
   278          "CCSCSvcPluginHandler::RemoveProfilesL presence and xdm deleted, ERR=%d", err );
       
   279         }
       
   280     
       
   281     CSCSVCPLUGINDEBUG("CCSCSvcPluginHandler::RemoveProfilesL - begin");
       
   282     }