natfw/natfwsettings/src/cnatfwserversettings.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 <unsafprotocolscrkeys.h>
       
    22 #include "cnatfwserversettings.h"
       
    23 #include "natsettingslogs.h"
       
    24 #include "cnatfwcenrephandler.h"
       
    25 #include "tnatfwsettingsparser.h"
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CNATFWServerSettings::CNATFWServerSettings
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CNATFWServerSettings::CNATFWServerSettings( TUint aPort,
       
    35     const TBool aSharedSecretEnabled ) :
       
    36     iPort( aPort), iSharedSecretEnabled( aSharedSecretEnabled )
       
    37     {
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CNATFWServerSettings::ConstructL
       
    43 // ---------------------------------------------------------------------------
       
    44 //    
       
    45 void CNATFWServerSettings::ConstructL( const TDesC8& aAddress,
       
    46     const TDesC8& aUsername, const TDesC8& aPassword )
       
    47     {
       
    48     __NATSETTINGS( "CNATFWServerSettings::ConstructL" )
       
    49     iAddress = aAddress.AllocL();
       
    50     iUsername = aUsername.AllocL();
       
    51     iPassword = aPassword.AllocL();
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CNATFWServerSettings::NewL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CNATFWServerSettings* CNATFWServerSettings::NewL(
       
    60     const TDesC8& aAddress,
       
    61     TUint aPort,
       
    62     const TDesC8& aUsername,
       
    63     const TDesC8& aPassword,
       
    64     const TBool aSharedSecretEnabled )
       
    65     {
       
    66     __NATSETTINGS( "CNATFWServerSettings::NewL" )
       
    67     CNATFWServerSettings* self = CNATFWServerSettings::NewLC( aAddress, aPort,
       
    68         aUsername, aPassword, aSharedSecretEnabled );
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CNATFWServerSettings::NewLC
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CNATFWServerSettings* CNATFWServerSettings::NewLC(
       
    79     const TDesC8& aAddress,
       
    80     TUint aPort, 
       
    81     const TDesC8& aUsername,
       
    82     const TDesC8& aPassword,
       
    83     const TBool aSharedSecretEnabled )
       
    84     {
       
    85     __NATSETTINGS( "CNATFWServerSettings::NewLC" )
       
    86     CNATFWServerSettings* self = new( ELeave )CNATFWServerSettings(
       
    87         aPort, aSharedSecretEnabled );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL( aAddress, aUsername, aPassword );
       
    90     return self;    
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CNATFWServerSettings::~CNATFWServerSettings
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CNATFWServerSettings::~CNATFWServerSettings()
       
    99     {
       
   100     delete iAddress;
       
   101     delete iUsername;
       
   102     delete iPassword;
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CNATFWServerSettings::ReadSettingsL
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CNATFWServerSettings::ReadSettingsL( TUint32 aServerSettingsKey,
       
   111     const CNATFWCenRepHandler& aRepHandler )
       
   112     {
       
   113     __NATSETTINGS( "CNATFWServerSettings::ReadSettingsL - start" )
       
   114     
       
   115     const TUint32 KServerAddressMask = 
       
   116         KUNSAFProtocolsSTUNAddressMask & ( ~KUNSAFProtocolsSubKeyMask );
       
   117 
       
   118     const TUint32 KServerUsernameMask = 
       
   119         KUNSAFProtocolsSTUNUsernameMask & ( ~KUNSAFProtocolsSubKeyMask );
       
   120         
       
   121     const TUint32 KServerPasswordMask = 
       
   122         KUNSAFProtocolsSTUNPasswordMask & ( ~KUNSAFProtocolsSubKeyMask );
       
   123         
       
   124     const TUint32 KServerPortMask = 
       
   125         KUNSAFProtocolsSTUNPortMask & ( ~KUNSAFProtocolsSubKeyMask );
       
   126 
       
   127     HBufC8* tempBuffer = NULL;
       
   128     
       
   129     // read port
       
   130     aRepHandler.Read( KServerPortMask | aServerSettingsKey, iPort );
       
   131     
       
   132     // read address and possible port, port is replaced if found
       
   133     tempBuffer = aRepHandler.ReadL(
       
   134         KServerAddressMask | aServerSettingsKey );
       
   135     if ( tempBuffer )
       
   136         {
       
   137         TInt port( 0 );
       
   138         CleanupStack::PushL( tempBuffer );
       
   139         delete iAddress;
       
   140         iAddress = NULL;
       
   141         iAddress = TNATFWSettingsParser::ParseAddressL( *tempBuffer, port );
       
   142         if ( port )
       
   143             {
       
   144             iPort = port;
       
   145             }
       
   146         CleanupStack::PopAndDestroy( tempBuffer );
       
   147         tempBuffer = NULL;
       
   148         }
       
   149     
       
   150     // read username
       
   151     tempBuffer = aRepHandler.ReadL( KServerUsernameMask |
       
   152         aServerSettingsKey );
       
   153     if ( tempBuffer )
       
   154         {
       
   155         delete iUsername;
       
   156         iUsername = tempBuffer;
       
   157         tempBuffer = NULL;
       
   158         }
       
   159     
       
   160     // read password
       
   161     tempBuffer = aRepHandler.ReadL( KServerPasswordMask |
       
   162         aServerSettingsKey );
       
   163     if ( tempBuffer )
       
   164         {
       
   165         delete iPassword;
       
   166         iPassword = tempBuffer;
       
   167         tempBuffer = NULL;
       
   168         }
       
   169 
       
   170     __NATSETTINGS( "CNATFWServerSettings::ReadSettingsL - end" )
       
   171     }
       
   172 
       
   173     
       
   174 // ---------------------------------------------------------------------------
       
   175 // From MNATFWServerSettings
       
   176 // CNATFWServerSettings::Address
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 const TDesC8& CNATFWServerSettings::Address() const
       
   180     {
       
   181     return *iAddress;
       
   182     }
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // From MNATFWServerSettings
       
   187 // CNATFWServerSettings::Port
       
   188 // ---------------------------------------------------------------------------
       
   189 //  
       
   190 TUint CNATFWServerSettings::Port() const
       
   191     {
       
   192     return iPort;
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // From MNATFWServerSettings
       
   198 // CNATFWServerSettings::Username
       
   199 // ---------------------------------------------------------------------------
       
   200 //  
       
   201 const TDesC8& CNATFWServerSettings::Username() const
       
   202     {
       
   203     return *iUsername;
       
   204     }
       
   205 
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // From MNATFWServerSettings
       
   209 // CNATFWServerSettings::Password
       
   210 // ---------------------------------------------------------------------------
       
   211 //  
       
   212 const TDesC8& CNATFWServerSettings::Password() const
       
   213     {
       
   214     return *iPassword;
       
   215     }
       
   216 
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // From MNATFWServerSettings
       
   220 // CNATFWServerSettings::SharedSecretEnabled
       
   221 // ---------------------------------------------------------------------------
       
   222 //      
       
   223 TBool CNATFWServerSettings::SharedSecretEnabled() const
       
   224     {
       
   225     return iSharedSecretEnabled;
       
   226     }