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: IPProxy TCP protocol expression for closing phone side TCP |
|
15 * connection. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CExprTCPClose.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 // CExprTCPClose::CExprTCPClose |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CExprTCPClose::CExprTCPClose( MExpressionObserverTCP* aObserver ) |
|
37 : iObserver( aObserver ) |
|
38 { |
|
39 __ASSERT_DEBUG( iObserver, User::Invariant() ); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CExprTCPClose::NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CExprTCPClose* CExprTCPClose::NewL( MExpressionObserverTCP* aObserver ) |
|
47 { |
|
48 CExprTCPClose* self = CExprTCPClose::NewLC( aObserver ); |
|
49 CleanupStack::Pop(); |
|
50 |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CExprTCPClose::NewLC |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CExprTCPClose* CExprTCPClose::NewLC( MExpressionObserverTCP* aObserver ) |
|
59 { |
|
60 CExprTCPClose* self = new( ELeave ) CExprTCPClose( aObserver ); |
|
61 CleanupStack::PushL( self ); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // Destructor |
|
68 CExprTCPClose::~CExprTCPClose() |
|
69 { |
|
70 } |
|
71 |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CExprTCPClose::HandleReceivedDataL() |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TBool CExprTCPClose::HandleRecievedMsgL( TDes8& aData, TInt& aStartPos, |
|
78 TInt& aLength ) |
|
79 { |
|
80 // Check if the prefix matches |
|
81 aStartPos = aData.Find( KTCPClosePrefix ); |
|
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 = TryParsingL( 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 // CExprTCPClose::TryParsing |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TInt CExprTCPClose::TryParsingL( TDes8& aData, TInt& aLength ) |
|
114 { |
|
115 __ASSERT_ALWAYS( aData.Left( KTCPClosePrefix().Length() ) == KTCPClosePrefix, |
|
116 User::Panic( _L("Protocol"), 1 ) ); |
|
117 |
|
118 // TCP_CLOSE:0fff |
|
119 TInt frameOverhead = |
|
120 KTCPClosePrefix().Length() + |
|
121 KHexDecimalLength; |
|
122 |
|
123 if ( aData.Length() >= frameOverhead ) |
|
124 { |
|
125 TPtrC8 portPtr( |
|
126 aData.Mid( KTCPClosePrefix().Length(), KHexDecimalLength ) ); |
|
127 |
|
128 TLex8 portLexer( portPtr ); |
|
129 TUint port; |
|
130 if ( portLexer.Val( port, EHex ) != KErrNone ) |
|
131 { |
|
132 return KErrCorrupt; |
|
133 } |
|
134 |
|
135 // send parsed results |
|
136 iObserver->CloseTCPConnectionL( port ); |
|
137 |
|
138 aLength = frameOverhead; |
|
139 |
|
140 return KErrNone; |
|
141 } |
|
142 return KErrNone; |
|
143 } |
|
144 |
|
145 // End of File |
|