natfw/natfwsettings/src/cnatfwturnsettings.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 "cnatfwturnsettings.h"
       
    24 #include "cnatfwserversettings.h" 
       
    25 #include <mnatfwserversettings.h>
       
    26 #include "cnatfwcenrephandler.h"
       
    27 #include "tnatfwsettingsparser.h"
       
    28 #include "natfwdefaultsettingsvalues.h"
       
    29 #include "natsettingslogs.h"
       
    30 
       
    31 const TUint KDefaultGranularity = 2;
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 CNATFWTurnSettings::CNATFWTurnSettings()
       
    36     {
       
    37 
       
    38     }
       
    39 
       
    40 
       
    41 void CNATFWTurnSettings::ConstructL( )
       
    42     {
       
    43     iServerArray = new ( ELeave )
       
    44         CArrayPtrFlat<CNATFWServerSettings>( KDefaultGranularity );
       
    45     iLatestConnectedServerAddr = KNullDesC8().AllocL();
       
    46     }
       
    47 
       
    48 
       
    49 CNATFWTurnSettings* CNATFWTurnSettings::NewL()
       
    50     {
       
    51     CNATFWTurnSettings* self = CNATFWTurnSettings::NewLC();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 CNATFWTurnSettings* CNATFWTurnSettings::NewLC()
       
    58     {
       
    59     CNATFWTurnSettings* self = new( ELeave ) CNATFWTurnSettings;
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 CNATFWTurnSettings::~CNATFWTurnSettings()
       
    67     {
       
    68     if ( iServerArray )
       
    69         {
       
    70         iServerArray->ResetAndDestroy();
       
    71         }
       
    72     delete iServerArray;
       
    73     delete iLatestConnectedServerAddr;
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CNATFWTurnSettings::SetTurnServersL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CNATFWTurnSettings::SetTurnServersL(
       
    82     CArrayPtr<CNATFWServerSettings>* aServers )
       
    83     {
       
    84     __ASSERT_ALWAYS( NULL != aServers, User::Leave( KErrArgument ) );
       
    85     iServerArray->ResetAndDestroy();
       
    86     delete iServerArray;
       
    87     iServerArray = NULL;
       
    88     iServerArray = aServers;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CNATFWTurnSettings::SetLatestConnectedServerAddrL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CNATFWTurnSettings::SetLatestConnectedServerAddrL
       
    97     ( const TDesC8& aServerAddr )
       
    98     {
       
    99     delete iLatestConnectedServerAddr;
       
   100     iLatestConnectedServerAddr = NULL;
       
   101     iLatestConnectedServerAddr = aServerAddr.AllocL();
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CNATFWTurnSettings::SetLatestConnectedServerPort
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CNATFWTurnSettings::SetLatestConnectedServerPort( TInt aServerPort )
       
   110     {
       
   111     iLatestConnectedServerPort = aServerPort;
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CNATFWTurnSettings::SetRetransmissionTimeout
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CNATFWTurnSettings::SetRetransmissionTimeout( TUint aRto )
       
   120     {
       
   121     iRto = aRto;
       
   122     }
       
   123     
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CNATFWTurnSettings::ReadSettingsL
       
   127 // ---------------------------------------------------------------------------
       
   128 //  
       
   129 void CNATFWTurnSettings::ReadSettingsL( TUint32 aDomainKey,
       
   130     const CNATFWCenRepHandler& aRepHandler )
       
   131     {
       
   132     __NATSETTINGS( "CNATFWTurnSettings::ReadSettingsL" )
       
   133     
       
   134     RArray<TUint32> serverKeys;
       
   135     CleanupClosePushL( serverKeys );
       
   136     
       
   137     TBool sharedSecretNotEnabled;
       
   138     TBool sharedSecretEnabled;
       
   139     
       
   140     // read sharedsecret enabled
       
   141     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsDomainSharedSecretNotSupported |
       
   142         aDomainKey, sharedSecretNotEnabled ) )
       
   143         {
       
   144         sharedSecretEnabled = KNATFWDefaultUseSharedSecret;
       
   145         }
       
   146     else
       
   147         {
       
   148         sharedSecretEnabled = !sharedSecretNotEnabled;
       
   149         }
       
   150             
       
   151     // read server settings
       
   152     TInt err = aRepHandler.FindServerKeys(
       
   153         KUNSAFProtocolsTURNServerTableMask | aDomainKey, serverKeys );
       
   154         
       
   155     TInt serverCount = serverKeys.Count();
       
   156     
       
   157     if ( KErrNone == err && serverCount > 0 )
       
   158         {
       
   159         for( TInt i( 0 ); i < serverCount; i++ )
       
   160             {
       
   161             CNATFWServerSettings* serverSettings = CNATFWServerSettings::NewLC(
       
   162                 KNullDesC8,
       
   163                 KNATFWDefaultTURNServerPort,
       
   164                 KNullDesC8,
       
   165                 KNullDesC8,
       
   166                 sharedSecretEnabled );
       
   167                 
       
   168             TUint32 key = serverKeys[i] | aDomainKey;
       
   169             serverSettings->ReadSettingsL( key, aRepHandler );
       
   170             iServerArray->AppendL( serverSettings );
       
   171             CleanupStack::Pop( serverSettings );
       
   172             }
       
   173         }
       
   174     else
       
   175         {
       
   176         if ( KErrNotFound == err )
       
   177             {
       
   178              __NATSETTINGS( "Server settings not found" )
       
   179             }
       
   180         else
       
   181             {
       
   182             User::Leave( err );
       
   183             }
       
   184         }
       
   185     CleanupStack::PopAndDestroy( &serverKeys );
       
   186     
       
   187     // read LatestConnectedTurnServerAddress and possible port
       
   188     TInt port = 0;
       
   189 
       
   190     HBufC8* tempBufPointer = aRepHandler.ReadL(
       
   191         KUNSAFProtocolsLatestConnectedTURNServerAddressMask | aDomainKey );
       
   192     if ( tempBufPointer ) 
       
   193         {
       
   194         CleanupStack::PushL( tempBufPointer );
       
   195         HBufC8* addr = TNATFWSettingsParser::ParseAddressLC(
       
   196             *tempBufPointer, port );
       
   197         SetLatestConnectedServerAddrL( *addr );
       
   198         SetLatestConnectedServerPort( port );
       
   199         CleanupStack::PopAndDestroy( addr );
       
   200         CleanupStack::PopAndDestroy( tempBufPointer );
       
   201         }
       
   202     else
       
   203         {
       
   204         SetLatestConnectedServerAddrL( KNullDesC8 );
       
   205         SetLatestConnectedServerPort( port );
       
   206         }
       
   207     
       
   208     // Read LatestConnectedStunServerPort, replaces previous data if found
       
   209     if ( KErrNone == aRepHandler.Read( KUNSAFProtocolsLatestConnectedTURNServerPortMask |
       
   210         aDomainKey, port ) )
       
   211         {
       
   212         SetLatestConnectedServerPort( port );
       
   213         }
       
   214 
       
   215     // read retransmission timeout
       
   216     if ( KErrNone != aRepHandler.Read( KUNSAFProtocolsTurnRetransmissionTimeoutMask |
       
   217         aDomainKey, iRto ) )
       
   218         {
       
   219         iRto = KNATFWDefaultRtoValue;
       
   220         }
       
   221     }
       
   222 
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // From class MNATFWTurnSettings.
       
   226 // CNATFWTurnSettings::GetTurnServerArrayL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CNATFWTurnSettings::GetTurnServerArrayL(
       
   230     RPointerArray<MNATFWServerSettings>& aServers ) const
       
   231     {
       
   232     TInt count = iServerArray->Count();
       
   233     
       
   234     for ( TInt i( 0 ); i < count; i++ )
       
   235         {
       
   236         aServers.AppendL( iServerArray->At( i ) );
       
   237         }
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // From class MNATFWTurnSettings.
       
   243 // CNATFWServerSettings::RetransmissionTimeout
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 TUint CNATFWTurnSettings::RetransmissionTimeout() const
       
   247     {
       
   248     return iRto;
       
   249     }
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // From class MNATFWTurnSettings.
       
   254 // CNATFWTurnSettings::LatestConnectedServerAddr
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257  const TDesC8& CNATFWTurnSettings::LatestConnectedServerAddr() const
       
   258     {
       
   259     return *iLatestConnectedServerAddr;
       
   260     }
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // From class MNATFWTurnSettings.
       
   265 // CNATFWTurnSettings::LatestConnectedServerPort
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 TInt CNATFWTurnSettings::LatestConnectedServerPort() const
       
   269     {
       
   270     return iLatestConnectedServerPort;
       
   271     }