natfw/tsrc/natfwtestconsoles/natfwtestconsole/src/wrongserversettings.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 "wrongserversettings.h"
       
    22 
       
    23 #include <e32debug.h>
       
    24 #include <unsafprotocolscrkeys.h>
       
    25 #include <cnatfwsettingsapi.h>
       
    26 #include <centralrepository.h>
       
    27 
       
    28 //  CONSTANTS
       
    29 
       
    30 //Settings
       
    31 //Domain spesific settings
       
    32 _LIT8( KWrongAddress, "nokia.stun.com:1" );
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CWrongServerSettings::NewL
       
    37 // -----------------------------------------------------------------------------
       
    38 // 
       
    39 CWrongServerSettings* CWrongServerSettings::NewL(
       
    40     const TDesC8& aDomain )
       
    41     {
       
    42     CWrongServerSettings* self =
       
    43         CWrongServerSettings::NewLC( aDomain );
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CWrongServerSettings::NewL
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CWrongServerSettings* CWrongServerSettings::NewLC(
       
    54     const TDesC8& aDomain )
       
    55     {   
       
    56     CWrongServerSettings* self = new( ELeave ) CWrongServerSettings( );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aDomain );
       
    59     return self;
       
    60     }
       
    61     
       
    62     
       
    63 // -----------------------------------------------------------------------------
       
    64 // CWrongServerSettings::CWrongServerSettings
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CWrongServerSettings::CWrongServerSettings()
       
    68     {
       
    69     }
       
    70     
       
    71     
       
    72 // -----------------------------------------------------------------------------
       
    73 // CWrongServerSettings::~CWrongServerSettings
       
    74 // -----------------------------------------------------------------------------
       
    75 //   
       
    76 CWrongServerSettings::~CWrongServerSettings( )
       
    77     {
       
    78     // delete settings
       
    79     EraseL(  iStunServerAddressKey, 0xffffffff );
       
    80     EraseL(  iTurnServerAddressKey, 0xffffffff );
       
    81     
       
    82     // Restore old server settings
       
    83     
       
    84     // STUN
       
    85     if ( iStoredStunAddress )
       
    86         {
       
    87         StoreL( iStunServerAddressKey, *iStoredStunAddress );
       
    88         delete iStoredStunAddress;
       
    89         }
       
    90     //TURN    
       
    91     if ( iStoredTurnAddress )
       
    92         {
       
    93         StoreL( iTurnServerAddressKey, *iStoredTurnAddress );
       
    94         delete iStoredTurnAddress;
       
    95         }
       
    96         
       
    97  	delete iDomain;
       
    98     }
       
    99     
       
   100     
       
   101 // -----------------------------------------------------------------------------
       
   102 // CWrongServerSettings::ConstructL
       
   103 // -----------------------------------------------------------------------------
       
   104 //    
       
   105 void CWrongServerSettings::ConstructL( const TDesC8& aDomain )
       
   106     {
       
   107     iDomain = aDomain.AllocL();
       
   108     ConstructBaseL();
       
   109     CreateSettingsL();
       
   110     }
       
   111     
       
   112     
       
   113 // -----------------------------------------------------------------------------
       
   114 // CWrongServerSettings::CreateSettingsL
       
   115 // -----------------------------------------------------------------------------
       
   116 //   
       
   117 void CWrongServerSettings::CreateSettingsL()
       
   118     {
       
   119     RDebug::Print( _L( "\nTEST PRINT: CWrongServerSettings::CreateSettingsL - start" ) );
       
   120     TInt err =  ReadDomainSettingsKeyL( *iDomain, iDomainKey );
       
   121     if ( KErrNotFound == err ) 
       
   122         {
       
   123         //Create key for domain settings
       
   124         RDebug::Print( _L("TEST PRINT: CAdditionalStunSettings::CreateSettingsL: Create new domain key\n") );
       
   125         iDomainKey = CreateNewTableKeyL(
       
   126         KUNSAFProtocolsDomainTableMask, KUNSAFProtocolsFieldTypeMask );
       
   127         StoreL( KUNSAFProtocolsDomainMask | iDomainKey, *iDomain );
       
   128         }
       
   129     else if ( KErrNone != err )
       
   130         {
       
   131         User::Leave( err );
       
   132         }
       
   133     else
       
   134         {            
       
   135         }
       
   136     // read server settings keys 
       
   137     CRepository* rep = CRepository::NewLC( KCRUidUNSAFProtocols );
       
   138     RArray<TUint32> array;
       
   139     CleanupClosePushL( array );
       
   140     
       
   141     // stun server  
       
   142     if ( !iStunServerAddressKey )
       
   143         {
       
   144         // readStunserverKey
       
   145         err = rep->FindL( iDomainKey | KUNSAFProtocolsSTUNAddressMask,
       
   146             KUNSAFProtocolsSubTableFieldTypeMask, array );
       
   147         if ( !err )
       
   148             {
       
   149             iStunServerAddressKey = array[0];
       
   150             // store old address
       
   151             ReadL( iStunServerAddressKey, &iStoredStunAddress );
       
   152             }
       
   153         else
       
   154             {
       
   155             //Create key for turn server settings
       
   156             iStunServerAddressKey = CreateNewTableKeyL(
       
   157                 KUNSAFProtocolsSTUNServerTableMask | iDomainKey,
       
   158                 KUNSAFProtocolsSubTableFieldTypeMask );
       
   159                 
       
   160             iStunServerAddressKey |=
       
   161                 KUNSAFProtocolsSTUNServerTableMask | iDomainKey;
       
   162             }
       
   163         array.Reset();
       
   164         }
       
   165     
       
   166     // turn server
       
   167     if ( !iTurnServerAddressKey )
       
   168         {
       
   169         // readTurnServerKey
       
   170         err = rep->FindL( iDomainKey | KUNSAFProtocolsTURNAddressMask,
       
   171             KUNSAFProtocolsSubTableFieldTypeMask, array );
       
   172         if ( !err )
       
   173             {
       
   174             iTurnServerAddressKey = array[0];
       
   175             // store old address
       
   176             ReadL( iTurnServerAddressKey, &iStoredTurnAddress );
       
   177             }
       
   178         else
       
   179             {
       
   180             //Create key for turn server settings
       
   181             iTurnServerAddressKey = CreateNewTableKeyL(
       
   182                 KUNSAFProtocolsTURNServerTableMask | iDomainKey,
       
   183                 KUNSAFProtocolsSubTableFieldTypeMask );
       
   184                 
       
   185             iTurnServerAddressKey |=
       
   186                 KUNSAFProtocolsTURNServerTableMask | iDomainKey;
       
   187             }
       
   188         array.Reset();
       
   189         }
       
   190     CleanupStack::PopAndDestroy( &array );
       
   191     CleanupStack::PopAndDestroy( rep );
       
   192     
       
   193     // store wrong settings
       
   194     // STUN
       
   195     StoreL( iStunServerAddressKey, KWrongAddress );
       
   196     // TURN
       
   197     StoreL( iTurnServerAddressKey, KWrongAddress );
       
   198     
       
   199     RDebug::Print( _L( "\nTEST PRINT: CWrongServerSettings::CreateSettingsL - end" ) );
       
   200     }