|
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: UDP protocol implementation for IP proxy |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProtocolUDP.h" |
|
22 #include "CExprUDPMsg.h" |
|
23 #include "MSocketWriter.h" |
|
24 #include "MProtocolObserverUDP.h" |
|
25 #include "CommRouterDefinitions.h" |
|
26 |
|
27 #define DEBUG_FILENAME "IPProxyEngine.log" |
|
28 #include "DebugPrint.h" |
|
29 |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CProtocolUDP::CProtocolUDP |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CProtocolUDP::CProtocolUDP( MProtocolObserverUDP* aObserver ) |
|
38 : iObserver( aObserver ) |
|
39 { |
|
40 __ASSERT_DEBUG( iObserver, User::Invariant() ); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CProtocolUDP::ConstructL |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CProtocolUDP::ConstructL() |
|
48 { |
|
49 // Add all the expressions for UDP |
|
50 iExpressionArray = new (ELeave) CArrayPtrFlat<MBPExpression> ( 3 ); |
|
51 |
|
52 CExprUDPMsg* UDPMsg = CExprUDPMsg::NewL( this ); |
|
53 iExpressionArray->AppendL( UDPMsg ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CProtocolUDP::NewL |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CProtocolUDP* CProtocolUDP::NewL( MProtocolObserverUDP* aObserver ) |
|
61 { |
|
62 CProtocolUDP* self = CProtocolUDP::NewLC( aObserver ); |
|
63 CleanupStack::Pop(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CProtocolUDP::NewLC |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CProtocolUDP* CProtocolUDP::NewLC( MProtocolObserverUDP* aObserver ) |
|
73 { |
|
74 CProtocolUDP* self = new( ELeave ) CProtocolUDP( aObserver ); |
|
75 CleanupStack::PushL( self ); |
|
76 |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CProtocolUDP::~CProtocolUDP |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CProtocolUDP::~CProtocolUDP() |
|
87 { |
|
88 if ( iExpressionArray ) |
|
89 { |
|
90 iExpressionArray->ResetAndDestroy(); |
|
91 delete iExpressionArray; |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CProtocolUDP::FrameStarted |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CProtocolUDP::FrameStarted() |
|
100 { |
|
101 iObserver->FrameStarted(); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CProtocolUDP::FrameParsedL |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CProtocolUDP::FrameParsedL( TUint aPort, const TDesC8& aData ) |
|
109 { |
|
110 iObserver->UDPFrameParsedL( aPort, aData ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CProtocolUDP::ProtocolErrorL |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CProtocolUDP::ProtocolErrorL( |
|
118 TInt aErrorCode, const TDesC8& aReceivedData ) |
|
119 { |
|
120 iObserver->ProtocolErrorL( aErrorCode, aReceivedData ); |
|
121 } |
|
122 |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CProtocolUDP::WriteFrameL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CProtocolUDP::WriteFrameL( MSocketWriter& aSocketWriter, |
|
129 TUint aPeerPort, TUint aOriginalPort, const TDesC8& aData ) const |
|
130 { |
|
131 DEBUG_PRINT( DEBUG_STRING( |
|
132 "CProtocolUDP::WriteFrameL(), peer port=%d, original port=%d" ), |
|
133 aPeerPort, aOriginalPort ); |
|
134 |
|
135 aSocketWriter.WriteL( KUDPPrefix ); |
|
136 |
|
137 TBuf8<KHexDecimalLength> portBuf; |
|
138 portBuf.Format( KHexFormat, aPeerPort ); |
|
139 aSocketWriter.WriteL( portBuf ); |
|
140 aSocketWriter.WriteL( KPortSuffix ); |
|
141 |
|
142 TBuf8<KHexDecimalLength> lengthBuf; |
|
143 lengthBuf.Format( KHexFormat, aData.Length() ); |
|
144 aSocketWriter.WriteL( lengthBuf ); |
|
145 |
|
146 aSocketWriter.WriteL( KLengthSuffix ); |
|
147 aSocketWriter.WriteL( aData ); |
|
148 aSocketWriter.WriteL( KDataSuffix ); |
|
149 |
|
150 aSocketWriter.WriteL( KMessageSuffix ); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CProtocolUDP::HandleReceivedDataL |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CProtocolUDP::HandleReceivedDataL( TDes8& aData, TInt& aStartPos, |
|
158 TInt& aLength ) |
|
159 { |
|
160 TBool msgHandled = EFalse; |
|
161 TInt protCount = iExpressionArray->Count(); |
|
162 |
|
163 for ( TInt i = 0; i < protCount; i++ ) |
|
164 { |
|
165 msgHandled = iExpressionArray->At( i )->HandleRecievedMsgL( aData, |
|
166 aStartPos, |
|
167 aLength); |
|
168 if ( msgHandled ) |
|
169 { |
|
170 break; |
|
171 } |
|
172 } |
|
173 |
|
174 return msgHandled; |
|
175 } |
|
176 // End of File |