hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CExprTCPCloseAll.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 closing all phone side
       
    15 *                sockets.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CExprTCPCloseAll.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 // CExprTCPCloseAll::CExprTCPCloseAll
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CExprTCPCloseAll::CExprTCPCloseAll( MExpressionObserverTCP* aObserver )
       
    37     : iObserver( aObserver )
       
    38     {
       
    39     __ASSERT_DEBUG( iObserver, User::Invariant() );
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CExprTCPCloseAll::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CExprTCPCloseAll* CExprTCPCloseAll::NewL( MExpressionObserverTCP* aObserver )
       
    47     {
       
    48     CExprTCPCloseAll* self = CExprTCPCloseAll::NewLC( aObserver );
       
    49     CleanupStack::Pop();
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CExprTCPCloseAll::NewLC
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CExprTCPCloseAll* CExprTCPCloseAll::NewLC( MExpressionObserverTCP* aObserver )
       
    59     {
       
    60     CExprTCPCloseAll* self = new( ELeave ) CExprTCPCloseAll( aObserver );
       
    61     CleanupStack::PushL( self );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 
       
    67 // Destructor
       
    68 CExprTCPCloseAll::~CExprTCPCloseAll()
       
    69     {
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CExprTCPCloseAll::HandleReceivedDataL()
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TBool CExprTCPCloseAll::HandleRecievedMsgL( TDes8& aData, TInt& aStartPos,
       
    78                                          TInt& aLength  )
       
    79     {
       
    80     // Check if the prefix matches
       
    81     aStartPos = aData.Find( KTCPCloseAllPrefix );
       
    82 
       
    83     if ( aStartPos != KErrNotFound  )
       
    84         {
       
    85         // Found a matching prefix
       
    86         // Let the observer know
       
    87         iObserver->FrameStarted();
       
    88 
       
    89         TPtr8 dataToParse( aData.MidTPtr( aStartPos ) );
       
    90 
       
    91         TInt err = TryParsing( dataToParse, aLength );
       
    92 
       
    93         if ( err != KErrNone )
       
    94             {
       
    95             // corrupted data in the frame
       
    96             iObserver->ProtocolErrorL( err, aData );
       
    97             // delete the corrupted data
       
    98             aData.SetLength( 0 );
       
    99             }
       
   100 
       
   101         return ETrue;
       
   102         }
       
   103     else
       
   104         {
       
   105         return EFalse;
       
   106         }
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CExprTCPOpen::TryParsing
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TInt CExprTCPCloseAll::TryParsing( TDes8& aData, TInt& aLength )
       
   114     {
       
   115     __ASSERT_ALWAYS( aData.Left( KTCPCloseAllPrefix().Length() ) == KTCPCloseAllPrefix,
       
   116         User::Panic( _L("Protocol"), 1 ) );
       
   117 
       
   118     // TCP_CLOSEALL:
       
   119     TInt frameOverhead = KTCPCloseAllPrefix().Length();
       
   120 
       
   121     if ( aData.Length() >= frameOverhead )
       
   122         {
       
   123         // send parsed results
       
   124         iObserver->CloseAllTCPConnections();
       
   125 
       
   126         aLength = frameOverhead;
       
   127         }
       
   128     return KErrNone;
       
   129     }
       
   130 
       
   131 //  End of File