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