natfw/natfwstunturnclient/src/cstunbindinggetaddress.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005-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 "natfwunsaflog.h"
       
    22 #include "stunassert.h"
       
    23 #include "cstunbindinggetaddress.h"
       
    24 #include "natfwbindingimplementationbase.h"
       
    25 #include "stunutils.h"
       
    26 #include "stunturnclientlogs.h"
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CSTUNBindingGetAddress::CSTUNBindingGetAddress
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CSTUNBindingGetAddress::CSTUNBindingGetAddress()
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CSTUNBindingGetAddress::CSTUNBindingGetAddress
       
    40 // Dummy implementation, as copy constructor is declared private and not used.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CSTUNBindingGetAddress::CSTUNBindingGetAddress(
       
    44     const CSTUNBindingGetAddress& /*aGetAddress*/ ) :
       
    45     CSTUNBindingState()
       
    46     {    
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CSTUNBindingGetAddress::~CSTUNBindingGetAddress
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CSTUNBindingGetAddress::~CSTUNBindingGetAddress()
       
    54     {
       
    55     iErrorBuffer.Close();    
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CSTUNBindingGetAddress::PublicAddressReceivedL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CSTUNBindingGetAddress::PublicAddressReceivedL(
       
    63     CBindingImplementation& aContext,
       
    64     const TInetAddr& aPublicAddress ) const
       
    65     {
       
    66     NATFWUNSAF_ADDRLOG( "STUNBinding public addr", aPublicAddress )
       
    67 
       
    68     aContext.StoreAddressL( aPublicAddress );
       
    69     aContext.ChangeState( *iActive );
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CSTUNBindingGetAddress::PublicAddressReceivedL - overloaded for stun relay
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CSTUNBindingGetAddress::PublicAddressReceivedL(
       
    77     CBindingImplementation& aContext,
       
    78     const TInetAddr& aReflexiveAddr,
       
    79     const TInetAddr& aRelayAddr ) const
       
    80     {
       
    81     NATFWUNSAF_ADDRLOG( "STUNRelayBinding public addr", aReflexiveAddr )
       
    82     NATFWUNSAF_ADDRLOG( "STUNRelayBinding relay addr", aRelayAddr )
       
    83 
       
    84     aContext.StoreAddressL( aReflexiveAddr, aRelayAddr );
       
    85     aContext.ChangeState( *iActive );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CSTUNBindingGetAddress::TransactionError
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void
       
    93 CSTUNBindingGetAddress::TransactionError( CBindingImplementation& aContext,
       
    94                                           TInt aError )
       
    95     {
       
    96     __STUNTURNCLIENT_INT1( 
       
    97         "CSTUNBindingGetAddress::TransactionError Error: ", aError )
       
    98     __STUN_ASSERT_RETURN( aError != KErrNone, KErrArgument );
       
    99     
       
   100     TInt error( KErrNone );
       
   101     TInt found( KErrNotFound );
       
   102     if ( iErrorBuffer.Count() > 0 )
       
   103         {
       
   104         found = iErrorBuffer.Find( aError );
       
   105         if ( KErrNotFound != found )
       
   106             {
       
   107             // Same error happened again, stop error handling
       
   108             __STUNTURNCLIENT( 
       
   109                 "Same error happened again, end processing" )
       
   110             aContext.Terminate( aError );
       
   111             return;
       
   112             }
       
   113         }
       
   114     
       
   115     if ( iErrorBuffer.Count() == 0 || KErrNotFound == found  )
       
   116         {
       
   117         iErrorBuffer.Append( aError );
       
   118         }
       
   119     
       
   120     if ( aContext.HandleTransactionError( aError ) )
       
   121         {
       
   122         if ( STUNUtils::Is5xxResponse( aError ) )
       
   123             {
       
   124             __STUNTURNCLIENT( "Is5xxResponse" )
       
   125             aContext.WaitBeforeRetrying();
       
   126             aContext.ChangeState( *iWaitToRetry );
       
   127             }
       
   128         
       
   129         if ( E430StaleCredentials == aError || E436UnknownUsername == aError ||
       
   130              E432MissingUsername == aError || E434MissingRealm == aError )
       
   131             {
       
   132             aContext.ChangeState( *iGetSharedSecret );
       
   133             TRAP( error, aContext.ClientL().BindingErrorL( 
       
   134                 aContext.Binding(), aError, EFalse ) );
       
   135             
       
   136             if ( KErrNone != error )
       
   137                 {
       
   138                 __STUNTURNCLIENT_INT1( "TransactionError leave ", error )
       
   139                 aContext.Terminate( error );
       
   140                 }
       
   141             }
       
   142         
       
   143         if ( E401Unauthorized == aError )
       
   144             {
       
   145             aContext.ChangeState( *iGetSharedSecret );
       
   146             
       
   147             TRAP( error, aContext.ClientL().BindingErrorL( 
       
   148                 aContext.Binding(), aError, EFalse ) );
       
   149             if ( error != KErrNone )
       
   150                 {
       
   151                 __STUNTURNCLIENT_INT1( "TransactionError 401 LEAVED: ", error )
       
   152                 aContext.Terminate( error );
       
   153                 }
       
   154             }
       
   155         
       
   156         if ( E300TryAlternate == aError )
       
   157             {
       
   158             // last argument is true, because binding cannot be destroyed
       
   159             // before alternate server is read from it.
       
   160             TRAP_IGNORE( aContext.ClientL().BindingErrorL( 
       
   161                 aContext.Binding(), aError, ETrue ) );
       
   162             }
       
   163             
       
   164         else
       
   165             {
       
   166             // this branch will send new request
       
   167             aContext.ChangeState( *iGetSharedSecret );
       
   168             TRAP( error, aContext.GetSharedSecretL() );
       
   169             if ( error != KErrNone )
       
   170                 {
       
   171                 aContext.Terminate( error );
       
   172                 }
       
   173             }
       
   174         }
       
   175     
       
   176     else
       
   177         {
       
   178         aContext.Terminate( aError );
       
   179         }
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CSTUNBindingGetAddress::SendRequestL
       
   184 // No action, since obtaining a binding is already in progress.
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CSTUNBindingGetAddress::SendRequestL(
       
   188     CBindingImplementation& /*aContext*/ ) const
       
   189     {
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CSTUNBindingGetAddress::SetNeighbourStates
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CSTUNBindingGetAddress::SetNeighbourStates(
       
   197     CSTUNBindingState& aGetSharedSecret,
       
   198     CSTUNBindingState& aWaitToRetry,
       
   199     CSTUNBindingState& aActive )
       
   200     {
       
   201     iGetSharedSecret = &aGetSharedSecret;
       
   202     iWaitToRetry = &aWaitToRetry;
       
   203     iActive = &aActive;
       
   204     }