|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of OMA SUPL WAP Listener |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <utf.h> |
|
21 #include <push/ccontenthandlerbase.h> |
|
22 //#include <push/pushdispatcher.h> for header relocation error |
|
23 |
|
24 #include "epos_comasuplwaplistener.h" |
|
25 |
|
26 _LIT( KReserved, "Reserved" ); |
|
27 _LIT( KPushMsgNull, "NULL PUSH message" ); |
|
28 _LIT( KTraceFileName, "epos_suplwaplistener.cpp" ); |
|
29 _LIT( KSupportedContentType, "application/vnd.omaloc-supl-init"); |
|
30 _LIT( KSupportedBinaryContentType, "0x312"); |
|
31 _LIT( KSupportedBinaryContentType2, "0X312"); |
|
32 |
|
33 //const TUint8 KSupportedHEXContentType = 0x03020312; |
|
34 |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // COMASuplWapListener::COMASuplWapListener() |
|
40 // C++ default constructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 COMASuplWapListener::COMASuplWapListener() |
|
44 : CPushHandlerBase() |
|
45 { |
|
46 iErrCode = KErrNone; |
|
47 CActiveScheduler::Add( this ); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // COMASuplWapListener::NewL |
|
52 // COMASuplWapListener instantiation method. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 COMASuplWapListener* COMASuplWapListener::NewL() |
|
56 { |
|
57 COMASuplWapListener* self = new (ELeave) COMASuplWapListener(); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // COMASuplWapListener::ConstructL |
|
64 // Symbian 2nd phase constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void COMASuplWapListener::ConstructL() |
|
68 { |
|
69 iTrace = COMASuplTrace::NewL(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // COMASuplWapListener::~COMASuplWapListener |
|
74 // Default destructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 COMASuplWapListener::~COMASuplWapListener() |
|
78 { |
|
79 if(iTrace) |
|
80 iTrace->Trace( _L( "COMASuplWapListener::~COMASuplWapListener()" ), KTraceFileName, __LINE__ ); |
|
81 delete iMessage; |
|
82 delete iTrace; |
|
83 Deque(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // COMASuplWapListener::CPushHandlerBase_Reserved1 |
|
88 // Reserved for ECOM for future expansion. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void COMASuplWapListener::CPushHandlerBase_Reserved1() |
|
92 { |
|
93 User::Panic( KReserved, KErrNotSupported ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // COMASuplWapListener::CPushHandlerBase_Reserved2 |
|
98 // Reserved for ECOM for future expansion. |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void COMASuplWapListener::CPushHandlerBase_Reserved2() |
|
102 { |
|
103 User::Panic( KReserved, KErrNotSupported ); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // COMASuplWapListener::HandleMessageL |
|
108 // Handles a push message asynchronously. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void COMASuplWapListener::HandleMessageL( CPushMessage* aPushMsg, TRequestStatus& aStatus ) |
|
112 { |
|
113 __ASSERT_ALWAYS( aPushMsg, User::Panic( KPushMsgNull, KErrUnknown ) ); |
|
114 iTrace->Trace( _L("COMASuplWapListener::HandleMessageL() Async Start"), KTraceFileName, __LINE__ ); |
|
115 iAsyncHandling = ETrue; |
|
116 SetConfirmationStatus(aStatus); |
|
117 HandleMessageL(aPushMsg); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // COMASuplWapListener::HandleMessageL |
|
122 // Handles a push message synchronously. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void COMASuplWapListener::HandleMessageL( CPushMessage* aPushMsg ) |
|
126 { |
|
127 //TBuf<64> contentType; |
|
128 __ASSERT_ALWAYS( aPushMsg, User::Panic( KPushMsgNull, KErrUnknown ) ); |
|
129 iTrace->Trace( _L( "COMASuplWapListener::HandleMessageL() Sync Start" ), KTraceFileName, __LINE__ ); |
|
130 iMessage = aPushMsg; |
|
131 TPtrC receivedContentType; |
|
132 iTrace->Trace( _L("Retriving Content Type:" ), KTraceFileName, __LINE__ ); |
|
133 iMessage->GetContentType(receivedContentType); |
|
134 iTrace->Trace( _L("Received Content Type for WAP ..." ), KTraceFileName, __LINE__ ); |
|
135 iTrace->Trace(receivedContentType, KTraceFileName, __LINE__ ); |
|
136 |
|
137 if(receivedContentType.Compare(KSupportedContentType) == 0 || |
|
138 receivedContentType.Compare(KSupportedBinaryContentType) == 0 || |
|
139 receivedContentType.Compare(KSupportedBinaryContentType2) == 0 ) //can be combined... |
|
140 { |
|
141 iState = EProcess; |
|
142 } |
|
143 else if (CheckBinaryContentType(aPushMsg)) |
|
144 { |
|
145 iState = EProcess; |
|
146 } |
|
147 else |
|
148 { |
|
149 iTrace->Trace( _L("ERROR:Received Content Type is not supported..." ), KTraceFileName, __LINE__ ); |
|
150 iState = EComplete; |
|
151 iErrCode = KErrNotSupported; |
|
152 } |
|
153 IdleComplete(); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // COMASuplWapListener::CancelHandleMessage |
|
158 // Cancels an outstanding HandleMessageL() request. |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void COMASuplWapListener::CancelHandleMessage() |
|
162 { |
|
163 Term( KErrCancel ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // COMASuplWapListener::DoCancel |
|
168 // Inherited from CActive - called to cancel outanding events. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void COMASuplWapListener::DoCancel() |
|
172 { |
|
173 Term( KErrCancel ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // COMASuplWapListener::RunL |
|
178 // Inherited from CActive - called when object is active. |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void COMASuplWapListener::RunL() |
|
182 { |
|
183 iTrace->Trace( _L( "COMASuplWapListener::RunL() Start" ), KTraceFileName, __LINE__ ); |
|
184 |
|
185 switch ( iState ) |
|
186 { |
|
187 case EProcess: |
|
188 ProcessPushMsgL(); |
|
189 break; |
|
190 |
|
191 case EComplete: |
|
192 Term( iErrCode ); |
|
193 break; |
|
194 |
|
195 default: |
|
196 break; |
|
197 } |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // COMASuplWapListener::RunError |
|
202 // Handles the event of leave from the request completion event handler RunL() |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TInt COMASuplWapListener::RunError( TInt aError ) |
|
206 { |
|
207 iState = EComplete; |
|
208 Term( aError ); |
|
209 return KErrNone; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // COMASuplWapListener::ProcessPushMsgL |
|
214 // Extracts the SUPL INIT request from the WAP Push message. |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void COMASuplWapListener::ProcessPushMsgL() |
|
218 { |
|
219 iTrace->Trace( _L( "COMASuplWapListener::ProcessPushMsgL() Start" ), KTraceFileName, __LINE__ ); |
|
220 |
|
221 // Extract SUPL INIT request from the push message |
|
222 TPtrC8 msgPtr; |
|
223 iState = EComplete; |
|
224 TBool exist = iMessage->GetMessageBody( msgPtr ); |
|
225 |
|
226 if (!exist) |
|
227 { |
|
228 iErrCode = KErrNotFound; |
|
229 IdleComplete(); |
|
230 iTrace->Trace( _L( "Unable to extract SUPL payload" ), KTraceFileName, __LINE__ ); |
|
231 return; |
|
232 } |
|
233 |
|
234 TRAP( iErrCode, SendL( msgPtr ) ); |
|
235 IdleComplete(); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // COMASuplWapListener::SendL |
|
240 // Creates an IPC connection with the SUPL gateway, forwards |
|
241 // the request and terminates the connection. |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void COMASuplWapListener::SendL( TPtrC8& aMessage ) |
|
245 { |
|
246 iTrace->Trace( _L( "COMASuplWapListener::SendL() Start" ), KTraceFileName, __LINE__ ); |
|
247 |
|
248 TInt err = KErrNone; |
|
249 |
|
250 // Create IPC session |
|
251 RSuplNetworkServer suplServ; |
|
252 err = suplServ.Connect(); |
|
253 if ( KErrNone != err ) |
|
254 { |
|
255 iTrace->Trace( _L( "Unable to create IPC session with SUPL server" ), KTraceFileName, __LINE__ ); |
|
256 User::Leave(err); |
|
257 } |
|
258 |
|
259 // Forward SUPL payload to SUPL server |
|
260 err = suplServ.ForwardMessage( aMessage ); |
|
261 suplServ.Close(); |
|
262 if ( KErrNone != err ) |
|
263 { |
|
264 iTrace->Trace( _L( "Error sending SUPL payload to server" ), KTraceFileName, __LINE__ ); |
|
265 User::Leave( err ); |
|
266 } |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // COMASuplWapListener::Term |
|
271 // Destroy self. |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void COMASuplWapListener::Term( TInt aError ) |
|
275 { |
|
276 iTrace->Trace( _L( "COMASuplWapListener::Term()" ), KTraceFileName, __LINE__ ); |
|
277 if ( iAsyncHandling ) |
|
278 { |
|
279 SignalConfirmationStatus( aError ); |
|
280 } |
|
281 // Destroy self |
|
282 iPluginKiller->KillPushPlugin(); |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // COMASuplWapListener::IdleComplete |
|
287 // Completes the iRequestStatus with KErrNone. |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void COMASuplWapListener::IdleComplete() |
|
291 { |
|
292 TRequestStatus* pS = &iStatus; |
|
293 User::RequestComplete( pS, KErrNone ); |
|
294 if ( !IsActive() ) |
|
295 { |
|
296 SetActive(); |
|
297 } |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // COMASuplWapListener::CheckBinaryContentType |
|
302 // |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 TBool COMASuplWapListener::CheckBinaryContentType(CPushMessage* aPushMsg) |
|
306 { |
|
307 TPtrC8 field; |
|
308 TBool isHeaderPresent = aPushMsg->GetBinaryHeaderField(EHttpContentType, field); |
|
309 |
|
310 iTrace->Trace( _L( "Received Binary Content Type is:" ), KTraceFileName, __LINE__ ); |
|
311 PrintHex(field, __LINE__); |
|
312 if( isHeaderPresent ) |
|
313 { |
|
314 iTrace->Trace( _L( "Binary Content type present..." ), KTraceFileName, __LINE__ ); |
|
315 TUint8 code = field[0]; |
|
316 |
|
317 //if(code>0x7F && ((code&0x7F) == KSupportedHEXContentType) ) // Content-type-value = Short-integer |
|
318 if (field[1] == 0x03 && field[2] == 0x12) |
|
319 { |
|
320 return ETrue; |
|
321 } |
|
322 } |
|
323 else |
|
324 { |
|
325 iTrace->Trace( _L( "No Binary Content type present..." ), KTraceFileName, __LINE__ ); |
|
326 } |
|
327 return EFalse; |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // COMASuplWapListener::CheckBinaryContentType |
|
332 // |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void COMASuplWapListener::PrintHex(const TDesC8& aBuffer,TInt aLine) |
|
336 { |
|
337 TBuf<256> buffer; |
|
338 TBuf<2> buff; |
|
339 _LIT16(KFormat1,"%02x"); |
|
340 TInt len = aBuffer.Length(); |
|
341 for(TInt i = 0 ; i <len; i++) |
|
342 { |
|
343 buff.Zero(); |
|
344 buff.Format(KFormat1,aBuffer[i]); |
|
345 buffer.Append(buff); |
|
346 buffer.Append(_L(" ")); |
|
347 } |
|
348 |
|
349 iTrace->Trace(buffer, KTraceFileName, aLine); |
|
350 } |