natfw/natfwsettings/src/cnatfwicesettings.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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 
       
    20 
       
    21 #include <badesca.h>
       
    22 #include <unsafprotocolscrkeys.h>
       
    23 #include "cnatfwicesettings.h"
       
    24 #include "natfwdefaultsettingsvalues.h"
       
    25 #include "cnatfwcenrephandler.h"
       
    26 #include "tnatfwsettingsparser.h"
       
    27 #include "natsettingslogs.h"
       
    28 
       
    29 const TUint KDefaultGranularity = 2;
       
    30 
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 CNATFWIceSettings::CNATFWIceSettings()
       
    35     {
       
    36 
       
    37     }
       
    38 
       
    39 
       
    40 void CNATFWIceSettings::ConstructL( )
       
    41     {
       
    42     iUtilityPlugins = new ( ELeave ) CDesC8ArrayFlat( KDefaultGranularity );
       
    43     }
       
    44 
       
    45 
       
    46 CNATFWIceSettings* CNATFWIceSettings::NewL()
       
    47     {
       
    48     CNATFWIceSettings* self = CNATFWIceSettings::NewLC();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 CNATFWIceSettings* CNATFWIceSettings::NewLC()
       
    55     {
       
    56     CNATFWIceSettings* self = new( ELeave ) CNATFWIceSettings;
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 CNATFWIceSettings::~CNATFWIceSettings()
       
    64     {
       
    65     delete iUtilityPlugins;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CNATFWIceSettings::SetPreferences
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CNATFWIceSettings::SetPreferences( 
       
    74         const TNATFWIcePreferences& aPreferences )
       
    75     {
       
    76     iPreferences = aPreferences;
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CNATFWIceSettings::SetPrefValue
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 TInt CNATFWIceSettings::SetPrefValue( TPrefSetting aSetting, TInt aValue )
       
    85     {
       
    86     return iPreferences.SetPrefValue( aSetting, aValue );
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CNATFWIceSettings::Preferences
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 const TNATFWIcePreferences& CNATFWIceSettings::Preferences() const
       
    95     {
       
    96     return iPreferences;
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CNATFWIceSettings::SetUtilityPluginsL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CNATFWIceSettings::SetUtilityPluginsL(
       
   105     const CDesC8Array& aUtilityPlugins )
       
   106     {
       
   107     __ASSERT_ALWAYS( &aUtilityPlugins, User::Leave( KErrArgument ) );
       
   108     iUtilityPlugins->Reset();
       
   109     TInt pluginIdCount = aUtilityPlugins.Count();
       
   110     for ( TInt i( 0 ); i < pluginIdCount; ++i )
       
   111         {
       
   112         iUtilityPlugins->AppendL( aUtilityPlugins[ i ] );
       
   113         }
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CNATFWIceSettings::ReadSettingsL
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CNATFWIceSettings::ReadSettingsL( TUint32 aDomainKey,
       
   122     const CNATFWCenRepHandler& aRepHandler )
       
   123     {
       
   124     __NATSETTINGS( "CNATFWIceSettings::ReadSettingsL - start" )
       
   125     
       
   126     //ICE used plug-ins
       
   127     CDesC8Array* utilityPlugindIds( NULL );
       
   128     HBufC8* tempBuffer = aRepHandler.ReadL(
       
   129         KUNSAFProtocolsNATUtilities | aDomainKey );
       
   130     
       
   131     if ( tempBuffer )
       
   132         {
       
   133         CleanupStack::PushL( tempBuffer );
       
   134         utilityPlugindIds =
       
   135             TNATFWSettingsParser::ParseDataToArrayL( *tempBuffer );
       
   136         CleanupStack::PopAndDestroy( tempBuffer );
       
   137         }
       
   138     else
       
   139         {
       
   140         utilityPlugindIds = TNATFWSettingsParser::ParseDataToArrayL(
       
   141             KNATFWDefaultIceUsedPlugins );
       
   142         }
       
   143     CleanupStack::PushL( utilityPlugindIds );
       
   144     SetUtilityPluginsL( *utilityPlugindIds );
       
   145     CleanupStack::PopAndDestroy( utilityPlugindIds );
       
   146     
       
   147     TInt prefValue( 0 );
       
   148     
       
   149     // Host type preference value
       
   150     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsHostPref |
       
   151         aDomainKey, prefValue ) )
       
   152         {
       
   153         prefValue = KNATFWDefaultlHostPref;
       
   154         }
       
   155     SetPrefValue( 
       
   156         MNATFWIceSettings::EPrefHostCandidate, prefValue );
       
   157     
       
   158     // Server-reflexive type preference value
       
   159     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsServerRefPref |
       
   160         aDomainKey, prefValue ) )
       
   161         {
       
   162         prefValue = KNATFWDefaultServerRefPref;
       
   163         }
       
   164     SetPrefValue( 
       
   165         MNATFWIceSettings::EPrefServerReflexiveCandidate, prefValue );
       
   166     
       
   167     // Relay type Preference value
       
   168     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsRelayPref |
       
   169         aDomainKey, prefValue ) )
       
   170         {
       
   171         prefValue = KNATFWDefaultRelayPref;
       
   172         }
       
   173     SetPrefValue( 
       
   174         MNATFWIceSettings::EPrefRelayCandidate, prefValue );
       
   175     
       
   176     // Peer-reflexive type Preference value.
       
   177     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsPeerRefPref |
       
   178         aDomainKey, prefValue ) )
       
   179         {
       
   180         prefValue = KNATFWDefaultPeerRefPref;
       
   181         }
       
   182     SetPrefValue(
       
   183         MNATFWIceSettings::EPrefPeerReflexiveCandidate, prefValue );
       
   184     
       
   185     // IPV4 local preference value
       
   186     if ( KErrNone != aRepHandler.Read(KUNSAFProtocolsIPV4Pref |
       
   187         aDomainKey, prefValue ) )
       
   188         {
       
   189         prefValue = KNATFWDefaultIPV4Pref;
       
   190         }
       
   191     SetPrefValue(
       
   192         MNATFWIceSettings::EPrefIpv4AddrFamily, prefValue );
       
   193     
       
   194     // IPV6 local preference value
       
   195     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsIPV6Pref |
       
   196         aDomainKey, prefValue ) )
       
   197         {
       
   198         prefValue = KNATFWDefaultIPV6Pref;
       
   199         }
       
   200     SetPrefValue(
       
   201         MNATFWIceSettings::EPrefIpv6AddrFamily, prefValue );
       
   202     
       
   203     // VPN local preference value
       
   204     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsVPNPref |
       
   205         aDomainKey, prefValue ) )
       
   206         {
       
   207         prefValue = KNATFWDefaultVPNPref;
       
   208         }
       
   209     SetPrefValue(
       
   210         MNATFWIceSettings::EPrefVpnInterface, prefValue );
       
   211     
       
   212     // UDP transport preference value
       
   213     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsUDPPref |
       
   214         aDomainKey, prefValue ) )
       
   215         {
       
   216         prefValue = KNATFWDefaultUDPPref;
       
   217         }
       
   218     SetPrefValue(
       
   219         MNATFWIceSettings::EPrefUdpTransport, prefValue );
       
   220     
       
   221     // TCP transport preference value
       
   222     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsTCPPref |
       
   223         aDomainKey, prefValue ) )
       
   224         {
       
   225         prefValue = KNATFWDefaultTCPPref;
       
   226         }
       
   227     SetPrefValue(
       
   228         MNATFWIceSettings::EPrefTcpTransport, prefValue );
       
   229     
       
   230     // TCP-active direction preference value
       
   231     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsTCPActivePref |
       
   232         aDomainKey, prefValue ) )
       
   233         {
       
   234         prefValue = KNATFWDefaultTCPActivePref;
       
   235         }
       
   236     SetPrefValue( 
       
   237         MNATFWIceSettings::EPrefTcpDirectionActive, prefValue );
       
   238     
       
   239     // TCP-passive direction preference value
       
   240     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsTCPPassivePref |
       
   241         aDomainKey, prefValue ) )
       
   242         {
       
   243         prefValue = KNATFWDefaultTCPPassivePref;
       
   244         }
       
   245     SetPrefValue( 
       
   246         MNATFWIceSettings::EPrefTcpDirectionPassive, prefValue );
       
   247     
       
   248     // TCP-simultaneous-open direction preference value
       
   249     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsTCPSimultPref |
       
   250         aDomainKey, prefValue ) )
       
   251         {
       
   252         prefValue = KNATFWDefaultTCPSimultPref;
       
   253         }
       
   254     SetPrefValue( 
       
   255         MNATFWIceSettings::EPrefTcpDirectionSimultaneousOpen, prefValue );
       
   256         
       
   257     __NATSETTINGS( "CNATFWIceSettings::ReadSettingsL - end" )
       
   258     }
       
   259     
       
   260     
       
   261 // ---------------------------------------------------------------------------
       
   262 // From class MNATFWIceSettings.
       
   263 // Returns preference value for a specified setting.
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 TInt CNATFWIceSettings::GetPrefValue( 
       
   267         TPrefSetting aSetting, TInt& aValue ) const
       
   268     {
       
   269     return iPreferences.GetPrefValue( aSetting, aValue );
       
   270     }
       
   271 
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // From class MNATFWIceSettings.
       
   275 // Returns array of identifiers of utility plugins available for ICE.
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 const CDesC8Array& CNATFWIceSettings::NatUtilityPlugins() const
       
   279     {
       
   280     return *iUtilityPlugins;
       
   281     }