hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CExprTCPLstn.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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:  IP-Proxy TCP protocol expression for opening listening phone
       
    15 *                side TCP socket.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CExprTCPLstn.h"
       
    23 #include "CommRouterDefinitions.h"
       
    24 #include "MExpressionObserverTCP.h"
       
    25 
       
    26 #define DEBUG_FILENAME "IPProxyEngine.log"
       
    27 #include "DebugPrint.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CExprTCPLstn::CExprTCPLstn
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CExprTCPLstn::CExprTCPLstn( MExpressionObserverTCP* aObserver )
       
    37     : iObserver( aObserver )
       
    38     {
       
    39     __ASSERT_DEBUG( iObserver, User::Invariant() );
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CExprTCPLstn::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CExprTCPLstn* CExprTCPLstn::NewL( MExpressionObserverTCP* aObserver )
       
    47     {
       
    48     CExprTCPLstn* self = CExprTCPLstn::NewLC( aObserver );
       
    49     CleanupStack::Pop();
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CExprTCPLstn::NewLC
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CExprTCPLstn* CExprTCPLstn::NewLC( MExpressionObserverTCP* aObserver )
       
    59     {
       
    60     CExprTCPLstn* self = new( ELeave ) CExprTCPLstn( aObserver );
       
    61     CleanupStack::PushL( self );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // Destructor
       
    67 CExprTCPLstn::~CExprTCPLstn()
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CExprTCPLstn::HandleReceivedDataL()
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 TBool CExprTCPLstn::HandleRecievedMsgL( TDes8& aData, TInt& aStartPos, TInt& aLength )
       
    76     {
       
    77     // Check if the prefix matches
       
    78     aStartPos = aData.Find( KTCPLstnPrefix );
       
    79 
       
    80     if ( aStartPos != KErrNotFound  )
       
    81         {
       
    82         // Found a matching prefix
       
    83         // Let the observer know
       
    84         iObserver->FrameStarted();
       
    85 
       
    86         TPtr8 dataToParse( aData.MidTPtr( aStartPos ) );
       
    87 
       
    88         TInt err = TryParsingL( dataToParse, aLength );
       
    89 
       
    90         if ( err != KErrNone )
       
    91             {
       
    92             // corrupted data in the frame
       
    93             iObserver->ProtocolErrorL( err, aData );
       
    94             // delete the corrupted data
       
    95             aData.SetLength( 0 );
       
    96             }
       
    97 
       
    98         return ETrue;
       
    99         }
       
   100     else
       
   101         {
       
   102         return EFalse;
       
   103         }
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CExprTCPLstn::TryParsingL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 TInt CExprTCPLstn::TryParsingL( TDes8& aData, TInt& aLength )
       
   111     {
       
   112     __ASSERT_ALWAYS( aData.Left( KTCPLstnPrefix().Length() ) == KTCPLstnPrefix,
       
   113         User::Panic( _L("Protocol"), 1 ) );
       
   114 
       
   115     // TCP_LSTN:0123
       
   116     TInt frameOverhead =
       
   117         KTCPLstnPrefix().Length() +
       
   118         KHexDecimalLength;
       
   119 
       
   120     if ( aData.Length() >= frameOverhead )
       
   121         {
       
   122         TPtrC8 portPtr(
       
   123             aData.Mid( KTCPLstnPrefix().Length(), KHexDecimalLength ) );
       
   124 
       
   125         TLex8 portLexer( portPtr );
       
   126         TUint port;
       
   127         if ( portLexer.Val( port, EHex ) != KErrNone )
       
   128             {
       
   129             return KErrCorrupt;
       
   130             }
       
   131 
       
   132         // send parsed results
       
   133         iObserver->OpenListeningTCPConnectionL( port );
       
   134 
       
   135         aLength = frameOverhead;
       
   136 
       
   137         return KErrNone;
       
   138         }
       
   139     return KErrNone;
       
   140     }
       
   141 
       
   142 //  End of File